Generate Krona charts from Taxa Barplots

I have written a python script to generate Krona charts from taxa barplots, and I would like to share it.

Krona charts are interactive pie charts, and I think they are useful because it visualizes samples one by one very good.

But the problem is we need to change our OTU/ASV tables to a tsv file which Krona likes.

Krona tsv format is like this: krona-format.tsv (64 Bytes)

An example Krona tsv: O5.tsv (15.4 KB)

An example Krona chart (upload as zip since it is not allowed to upload html): Krona.zip (50.8 KB)

To get started we need to install Krona. Here is the github page : https://github.com/marbl/Krona/wiki

After the install I do not recomment to run update scripts in KronaTools because we won’t use them and it will start a huge download.

We need to be able to call Krona from bash so make sure that ktImportText command works.

After that, we just need a taxa-bar-plots.qzv file to work with this Python script: generate-krona.py (2.1 KB)

Simply, the script extracts level-7.csv from taxa-bar-plots.qzv, creates tsv files for krona, generates krona file as html, removes anthing unnecessary in the process.

You can read the comments to make changes in the script. Script is written to work with python3.

Have fun.

(First time posting a tutorial, I need all the criticism and suggestions to improve it. )

3 Likes

Awesome work @the_dummy! I am looking forward to giving this a spin!

Looks like you are just a stone’s-throw away from writing your own QIIME 2 plugin… interested in giving that a try? We can point you in the right direction!

#extract level-7.csv from taxa barplots

Why extract from the barplot.qzv? Why not accept a feature table and taxonomy file (or a feature table that has been collapsed to a specific level) as input? That would be the first step toward making this a little more plugin-like and efficient.

3 Likes

Well, now I will look into how the plugins work.

Why extract from the barplot.qzv? Why not accept a feature table and taxonomy file (or a feature table that has been collapsed to a specific level) as input? That would be the first step toward making this a little more plugin-like and efficient.

This is a very good idea. With this, you won’t need to visualize everything if you want a limit to a level.

Now, with argparse, I have added some tricks to the script.

As @Nicholas_Bokulich suggested I tried to use collapsed table, and it extracts metadata.tsv from collapsed taxa visualization (a qzv file).

I didn’t want to deal with a feature-table.biom because I don’t know the nature of the file.

This script has input, output, exclude, regex options now!

krona-arg.py (2.3 KB)

Let’s hear out how it can be improved much more…

2 Likes

Another good reason to write this as a QIIME 2 plugin — you can take a FeatureTable[Frequency] artifact as input, QIIME 2 will validate the input type and transform it into a pandas.DataFrame for manipulating and saving as a TSV for krona. No need to figure out the biom-format API (which while useful for many other things is not needed here since you are really just formatting the table for krona)

1 Like