Python Tutorial: Data Visualization with Dokdo API

Thanks so much for your feedback! I created a GitHub issue for tracking the addition of the rank abundance curve plot. I will let you know in the comment once it's added. Please let me know if you have other feature requests.

1 Like

Quick question: Does the dokdo.taxa_abundance_box_plot method give you the plot you want?

import dokdo
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()

qzv_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/taxa-bar-plots.qzv'
dokdo.taxa_abundance_box_plot(
    qzv_file,
    level=2,
    figsize=(8, 7)
)
plt.tight_layout()

1 Like

@sbslee Kind off. It is usually a point or line plot, with relative abundance on log scale (y-axis) and the rank order on the x-axis. But the taxa_abundance_box_plot is similar in a way. I actually make this boxplot type in my workflow but with horizontal orientation.

Thanks for the explanation. I will search for more papers that have such plot before devising a new plotting method. If you're a Python programmer yourself, you're more than welcome to create a PR :slight_smile:

2 Likes

Dokdo 1.15.0 is available now, but the tutorial will not be updated anymore for the reasons stated in the edited post above.

3 Likes

Dear sbslee,

I'll read more about dokdo cause it seems georgous!! I'm still a begginer in the bioinformatic world... Is it possible to collapse all minority phyla in "others" just with dokdo?? I'm really interested in this scrip...

Thank you in advance!!

@Anuka,

I'm glad you find Dokdo useful! As for your question, it depends. For example, if your end goal is to create a bar plot showing relative abundance of microbiome and you want to collapse less abundant bacteria as "Others", that's really easy to do with the dokdo.taxa_abundance_bar_plot method. Please take a look at the method's documentation and examples. If you have further questions, please feel free to reply here or leave an issue at the GitHub repository.

Steven

Thank you Steven. I installed dokdo in ubuntu, with qiime2. But I'm founding troubles to run the program, since it always says "command not found". Maybe in linux is different than in python??

Thank you in advance!

@Anuka,

I will need more information to properly assist you:

  1. Are you sure you installed Dokdo in the same environment as QIIME 2 (i.e. did you activate the QIIME 2 environment before installing Dokdo)? Can you show me the output of:
$ conda list
  1. How did you install Dokdo exactly? Did you follow the installation guide on the website?
$ conda activate qiime2-2022.8
$ git clone https://github.com/sbslee/dokdo
$ cd dokdo
$ pip install .

This is the output:

output.txt (4.0 KB)

Yes, That's the script I followed... and I used python -c "import dokdo" and there were no error, but it was after use python -c "%matplotlib inline"...

I think I understand what's going on.

Although it's true you can use Dokdo in the command-line interface (CLI), in your case you probably want to use it in the application programming interface (API). If you're not familiar with CLI and API, just know that the former means running a program in the terminal and the latter means using a program as library.

In order for you to use Dokdo in API, as I suggest in the Dokdo API page, I strongly recommend that you learn how to use Jupyter Notebook first. Codes like %matplotlib inline are not meant to be run in the terminal but rather in Jupyter Notebook.

When you installed QIIME 2, you actually already installed Jupyter Notebook. If you are unsure how to open a notebook, you can use Anaconda Navigator which is the desktop graphical user interface (GUI) for Anaconda: Anaconda Navigator > Environments > qiime2-2022.8 > Open with Jupyter Notebook.

Hope this helps.

Oh thank you!! I create the jupyter notebook and I'm working on it. I've no problem until trying to execute this command:

dokdo.taxa_abundance_bar_plot(
qzv_file,
figsize=(10, 7)
)

When I got the next error:

"module 'dokdo' has no attribute 'taxa_abundance_bar_plot'

How can I fix it??

Thank you in advance, and so sorry for the inconvenience caused...

@Anuka, I will DM you so that we don't overwhelm this post with our replies.

1 Like

Dokdo 1.16.0 is available now, but the tutorial will not be updated anymore for the reasons stated in the edited post above.

1 Like

Hi @sbslee,

I have the same issues ("module 'dokdo' has no attribute 'taxa_abundance_bar_plot').

How can I fix it?

Thank you

1 Like

@Jin_PK,

Did you install Dokdo using pip or conda? If so, you probably installed a different dokdo program. Mine can only be installed locally. See the installation page for details. If you indeed installed locally, please show me the output of the command $ conda list in your QIIME 2 environment.

I install it with "import python" and run on Jupyter Notebook. I have some problems when calling "dokdo.taxa_abundance_bar_plot". It shows "module 'dokdo' has no attribute 'taxa_abundance_bar_plot'.

Thank you in advance.

@Jin_PK,

Like I said in the reply, if you installed Dokdo via conda you likely installed an incorrect program that happens to have the same name, because I never uploaded Dokdo to pip or conda. Please follow the instruction I've linked in the previous reply:

$ git clone https://github.com/sbslee/dokdo
$ cd dokdo
$ pip install .

Hello , Do you know how I can add a P-value to the box plots ?

@nadia10639,

You can use the dokdo.addsig method (see the docs):

import dokdo
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
vector_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/faith_pd_vector.qza'
metadata_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/sample-metadata.tsv'
ax = dokdo.alpha_diversity_plot(vector_file, metadata_file, 'body-site', figsize=(8, 5))
dokdo.addsig(0, 1, 20, t='***', ax=ax)
dokdo.addsig(1, 2, 26, t='ns', ax=ax)
plt.tight_layout()

addsig

2 Likes