sbslee / dokdo

A Python package for microbiome sequencing analysis with QIIME 2
https://dokdo.readthedocs.io
MIT License
43 stars 12 forks source link

Add taxon name in the pcoa biplot #50

Closed rupesh-sinha closed 1 year ago

rupesh-sinha commented 1 year ago

Hi @sbslee I have plotted a pcoa biplot using this;

pcoa_results = dokdo.ordinate(qza_file, biplot=True, number_of_dimensions=10)

ax = dokdo.beta_2d_plot(
    pcoa_results,
    metadata=metadata_file,
    hue='body-site',
    figsize=(8, 8)
)

dokdo.addbiplot(pcoa_results, ax=ax, count=7)

plt.tight_layout()

image

I was wondering if there is a way to display taxon names instead of ASV ID on the biplot?

I tried using dokdo.api.common.pname(name, levels=None, delimiter=';') in the function like this:

pcoa_results = dokdo.ordinate(qza_file, biplot=True, number_of_dimensions=10)

ax = dokdo.beta_2d_plot(
    pcoa_results,
    metadata=metadata_file,
    hue='body-site',
    figsize=(8, 8)
)

dokdo.addbiplot(pcoa_results, ax=ax, count=7)

dokdo.api.common.pname(name, levels=3, delimiter=';')

plt.tight_layout()

But returned with NameError: name 'name' is not defined

Could you please help with this.

Thanks for your help and improving dokdo.

Thanks

sbslee commented 1 year ago

@rupesh-sinha,

If you read the addbiplot function's documentation carefully, it gives you an example where you can give actual taxa names instead of ASV IDs. I will copy and paste the relevant section for you:

taxonomy_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/taxonomy.qza'
ax = dokdo.beta_3d_plot(pcoa_results,
                        hue='body-site',
                        metadata=metadata_file,
                        figsize=(8, 8))
dokdo.addbiplot(pcoa_results,
                ax=ax,
                count=3,
                dim=3,
                taxonomy=taxonomy_file,
                name_type='taxon',
                level=6)
plt.tight_layout()

Screen Shot 2022-12-02 at 11 24 11 AM