dokdo icon indicating copy to clipboard operation
dokdo copied to clipboard

Use of taxa_names in taxa_abundance_bar_plot

Open mishkb opened this issue 2 years ago • 4 comments

HI @sbslee ,

I'm trying to use the 'taxa_names' flag in 'taxa_abundance_bar_plot'. Without the 'taxa_names' I can show different taxa levels from my barplot.qzv file without issue. However, I would like to show just the class level from a specific taxa - e.g. show %abundance from classes from just k__Bacteria;_p__Proteobacteria.

I have tried a few different things with syntax etc (including putting the taxon='k__Bacteria;p__Proteobacteria' just below the file inputs), but get errors including:

KeyError: "['k__Bacteria;p__Proteobacteria'] not found in axis"

Could you please advise if what I am trying to achieve is possible? Or correct my syntax? I can upload the files if that is helpful.

Here what I'm running in Jupyter:

qzv_file = '/home/nano/Alert4_MVP/taxa-bar-plots-no-Unassigned.qzv'
metadata_file = '/home/nano/Alert4_MVP/TFP_C4BD_metadata.tsv'
taxon = 'k__Bacteria;p__Proteobacteria'

fig, [ax1, ax2] = plt.subplots(1, 2, figsize=(14, 7), gridspec_kw={'width_ratios': [9, 1]})
ax = dokdo.taxa_abundance_bar_plot(qzv_file,
                              metadata=metadata_file,     
                              ax=ax1,
                              level=3,
                              taxa_names=['k__Bacteria;p__Proteobacteria'], 
                             label_columns=['SampleName'],
                              cmap_name='tab20')

for ticklabel in ax.get_xticklabels():
    ticklabel.set_rotation(45)
ax.set_xlabel("Sample", fontsize = 12)  

dokdo.taxa_abundance_bar_plot(qzv_file,
                              ax=ax2,
                              level=3,
                              taxa_names=['k__Bacteria;p__Proteobacteria'],
                              cmap_name='tab20',
                              legend_short=True,
                              pname_kws=dict(levels=[3])
                              )

handles, labels = ax2.get_legend_handles_labels()
ax2.clear()
ax2.legend(handles[::-1], labels[::-1], loc='center left')
ax2.axis('off')

    
plt.tight_layout()

Thanks!

mishkb avatar Sep 09 '21 00:09 mishkb