command or tool to shorten the very long labels in viewer from taxa-bar-plots.qzv

When I make plots from taxa-bar-plots.qzv at level-7 the labels are huge and unreadable because of the first 6 levels.

eg: “D_0__Bacteria;D_1__Firmicutes;D_2__Bacilli;D_3__Bacillales;D_4__Bacillaceae;D_5__Aquibacillus;D_6__Aquibacillus salifodinae”

I found that the data used to plot is stored in level-7.csv and level-7.jsonp.

Before I start to make my own code

  • Is there a tool that can process this file and remove level-1:6 labels to keep only the species label?

leaving only “Aquibacillus salifodinae” in my example above

  • Does replacing the long strings in level-7.csv / level-7.jsonp by a shorter one keep the resulting qzv file valid for the online viewer?

  • is there a local CLI version (or better a R package) of the viewer of is the webpage the only tool for producing and customising plots?

Thanks in advance

Thanks

Hi @splaisan,

No. I would recommend doing this in python or R.

As long as you (a) do not alter the feature IDs and (b) the altered taxonomy is all at even levels this should still work just fine. But I would recommend altering the taxonomy you are using on input to qiime taxa barplot, not the files in the QZV.

q2view is actually run locally even though it is browser-based (try disconnecting from the internet and run qiime tools view to see for yourself!). Is that your concern, that you want to have view access when offline?

I hope that helps!

1 Like

that helped a lot, thanks !
especially the part < But I would recommend altering the taxonomy you are using on input to qiime taxa barplot , not the files in the QZV. > which I will try next.
It is a bit weird that everybody else can live with such long and ugly labels on such a nice plot though :slight_smile: I guess they all make their own pots in R ggplot2 from the csv output which is probably where I will go too to speedup and not have to dig in the qz zip structure

1 Like

you do not need to dig around in the zip structure, since this is just a matter of adjusting your taxonomy file:

  1. use qiime tools export to export from QZA to tab-delimited text
  2. modify however you like, e.g., an R or bash script will do
  3. re-import the modified taxonomy to QIIME 2 with qiime tools import
  4. use the modified taxonomy as your input to barplot
1 Like

Cool! I try this tomorrow and will post any success back here for others

2 Likes

Hi Nicholas,

I am almost there but have a structure error in my data which I do not get. :face_with_thermometer:

Next is a part of my attempt which can be seen in whole on my git page

Could you please point me to a way to correct this !

head taxonomy_export/taxonomy.tsv taxonomy_genus/taxonomy.tsv taxonomy_species/taxonomy.tsv 
==> taxonomy_export/taxonomy.tsv <==
Feature ID	Taxon	Consensus
00020107f579a17c6029b07351bf5744479bd7c8	D_0__Bacteria;D_1__Firmicutes;D_2__Bacilli;D_3__Bacillales;D_4__Bacillaceae;D_5__Bacillus;D_6__Bacillus subtilis	1.0
0003ba2cd3d636339b5bbf188964c6be168b2cf4	D_0__Bacteria;D_1__Firmicutes;D_2__Bacilli;D_3__Bacillales;D_4__Bacillaceae;D_5__Bacillus;D_6__Streptococcus pneumoniae	1.0
00044aa9825d55df21182e70982a97c1c9968184	D_0__Bacteria;D_1__Firmicutes;D_2__Bacilli;D_3__Bacillales;D_4__Bacillaceae;D_5__Bacillus;D_6__Bacillus subtilis	1.0
00052864db9eb0e8e141c725007d9daf9a8be86d	D_0__Bacteria;D_1__Proteobacteria;D_2__Gammaproteobacteria;D_3__Pseudomonadales;D_4__Pseudomonadaceae;D_5__Pseudomonas;D_6__metagenome	1.0
0009f868d18c2d64177c453b36b5b3fbcd2bbff2	D_0__Bacteria;D_1__Firmicutes;D_2__Bacilli;D_3__Bacillales;D_4__Staphylococcaceae;D_5__Staphylococcus;D_6__Staphylococcus aureus DAR3919	1.0
000a914ffaaeefe4cc5c5ba7d5fc0d8c2069acbf	D_0__Bacteria;D_1__Firmicutes;D_2__Bacilli;D_3__Lactobacillales;D_4__Lactobacillaceae;D_5__Lactobacillus;D_6__Lactobacillus fermentum	1.0
000b7d774410671c26231e4b674fc1b4a2f80e6c	D_0__Bacteria;D_1__Firmicutes;D_2__Bacilli;D_3__Bacillales;D_4__Bacillaceae;D_5__Bacillus;D_6__Bacillus subtilis	1.0
0012ee985d6dd440a583ea2e93ae082a00ddcb7f	D_0__Bacteria;D_1__Firmicutes;D_2__Bacilli;D_3__Bacillales;D_4__Listeriaceae;D_5__Listeria;D_6__Listeria monocytogenes	1.0
00138ad4bbf960cdcb83de0eb76429344015b90d	D_0__Bacteria;D_1__Firmicutes;D_2__Bacilli;D_3__Lactobacillales;D_4__Enterococcaceae;D_5__Enterococcus;D_6__uncultured bacterium	1.0

==> taxonomy_genus/taxonomy.tsv <==
Feature ID	Taxon	Consensus
00020107f579a17c6029b07351bf5744479bd7c8	Bacillus	1.0
0003ba2cd3d636339b5bbf188964c6be168b2cf4	Bacillus	1.0
00044aa9825d55df21182e70982a97c1c9968184	Bacillus	1.0
00052864db9eb0e8e141c725007d9daf9a8be86d	Pseudomonas	1.0
0009f868d18c2d64177c453b36b5b3fbcd2bbff2	Staphylococcus	1.0
000a914ffaaeefe4cc5c5ba7d5fc0d8c2069acbf	Lactobacillus	1.0
000b7d774410671c26231e4b674fc1b4a2f80e6c	Bacillus	1.0
0012ee985d6dd440a583ea2e93ae082a00ddcb7f	Listeria	1.0
00138ad4bbf960cdcb83de0eb76429344015b90d	Enterococcus	1.0

==> taxonomy_species/taxonomy.tsv <==
Feature ID	Taxon	Consensus
00020107f579a17c6029b07351bf5744479bd7c8	D_6__Bacillus subtilis	1.0
0003ba2cd3d636339b5bbf188964c6be168b2cf4	D_6__Streptococcus pneumoniae	1.0
00044aa9825d55df21182e70982a97c1c9968184	D_6__Bacillus subtilis	1.0
00052864db9eb0e8e141c725007d9daf9a8be86d	D_6__metagenome	1.0
0009f868d18c2d64177c453b36b5b3fbcd2bbff2	D_6__Staphylococcus aureus	1.0
000a914ffaaeefe4cc5c5ba7d5fc0d8c2069acbf	D_6__Lactobacillus fermentum	1.0
000b7d774410671c26231e4b674fc1b4a2f80e6c	D_6__Bacillus subtilis	1.0
0012ee985d6dd440a583ea2e93ae082a00ddcb7f	D_6__Listeria monocytogenes	1.0
00138ad4bbf960cdcb83de0eb76429344015b90d	D_6__uncultured bacterium	1.0

In the scase of species, I left the leading ‘D_6__’ but the error below remains when also removing this prefix

I ran the command below both with the original table.qza, the table-no-unassigned.qza OR the new <genus|species>-table-no-unassigned.qza without change in the error.

It seems that the simplified taxonomy_species.qza data is not structurally correct anymore to generate the plot

qiime taxa barplot --i-table table-no-unassigned.qza --i-taxonomy taxonomy_species.qza --m-metadata-file $SAMPLE_METADATA --o-visualization species-taxa-bar-plots.qzv
Plugin error from taxa:

  'float' object has no attribute 'split'

Debug info has been saved to /tmp/qiime2-q2cli-err-ufm_ty_p.log
(MetONTIIME_env) [email protected]:/data2/analyses/MetONTIIME_4smpl_silva$ cat /tmp/qiime2-q2cli-err-ufm_ty_p.log
Traceback (most recent call last):
  File "/opt/biotools/miniconda3/envs/MetONTIIME_env/lib/python3.6/site-packages/q2cli/commands.py", line 327, in __call__
    results = action(**arguments)
  File "</opt/biotools/miniconda3/envs/MetONTIIME_env/lib/python3.6/site-packages/decorator.py:decorator-gen-144>", line 2, in barplot
  File "/opt/biotools/miniconda3/envs/MetONTIIME_env/lib/python3.6/site-packages/qiime2/sdk/action.py", line 240, in bound_callable
    output_types, provenance)
  File "/opt/biotools/miniconda3/envs/MetONTIIME_env/lib/python3.6/site-packages/qiime2/sdk/action.py", line 445, in _callable_executor_
    ret_val = self._callable(output_dir=temp_dir, **view_args)
  File "/opt/biotools/miniconda3/envs/MetONTIIME_env/lib/python3.6/site-packages/q2_taxa/_visualizer.py", line 34, in barplot
    collapsed_tables = _extract_to_level(taxonomy, table)
  File "/opt/biotools/miniconda3/envs/MetONTIIME_env/lib/python3.6/site-packages/q2_taxa/_util.py", line 37, in _extract_to_level
    max_obs_lvl = _get_max_level(taxonomy)
  File "/opt/biotools/miniconda3/envs/MetONTIIME_env/lib/python3.6/site-packages/q2_taxa/_util.py", line 11, in _get_max_level
    return taxonomy.apply(lambda x: len(x.split(';'))).max()
  File "/opt/biotools/miniconda3/envs/MetONTIIME_env/lib/python3.6/site-packages/pandas/core/series.py", line 3591, in apply
    mapped = lib.map_infer(values, f, convert=convert_dtype)
  File "pandas/_libs/lib.pyx", line 2217, in pandas._libs.lib.map_infer
  File "/opt/biotools/miniconda3/envs/MetONTIIME_env/lib/python3.6/site-packages/q2_taxa/_util.py", line 11, in <lambda>
    return taxonomy.apply(lambda x: len(x.split(';'))).max()
AttributeError: 'float' object has no attribute 'split'
1 Like

I found it, there is need for at least one ';' in the taxon column, I kept both genus and species and now it works.

Before:

After:

all details of the transformation

2 Likes

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.