MetaPhlAn Visualization using stacked barplot
Entering edit mode
2.4 years ago

Hey everyone,

So I've been doing some analysis using MetaPhlAn for 8 datasets and has merged them into a single merged file using the script.

I want to do a Stacked barplot visualization using ggplot2. Could anyone here please advise me as to how to proceed? I'm fairly new to this field.

I did try the first few set of codes mentioned in the link below, but I'm confused when i reached the middle.

I did up to the 'Importing the data' step.

Many many thanks in advance!

stacked_barplot ggplot2 MetaPhlAn3 R_programming • 1.5k views
Entering edit mode
2.4 years ago
acvill ▴ 340

The ID column of the merged table includes multiple annotation levels. For example, the row where ID is k__Bacteria gives the proportion of reads for each sample that can be assigned to the kingdom Bacteria, and the row where ID is k__Bacteria|p__Actinobacteria|c__Actinobacteria|o__Bifidobacteriales gives the proportion of reads for each sample that can be assigned to the order Bifidobacteriales. Stacked barplots only make sense if you are considering a single taxonomic level. This is why the first step after data import is filtering rows by ID values that end with g__, which gives all genus-level annotations in your dataset. You can repeat this process to subset tables for any taxonomic level.

You've used MetaPhlAn to do you taxonomic profiling of your metagenomic data. If you ever decide to try Kraken instead, I made a shiny app to go directly from merged abundance tables to stacked barplots.

Entering edit mode

Hii, yes thank you for the clarification!

I tried doing the pre-processing part and received an error. Could you please tell what's wrong here! Copy pasting the output here:

Traceback (most recent call last): File "/home/axv183/miniconda3/lib/python3.8/site-packages/pandas/core/indexes/", line 3621, in get_loc return self._engine.get_loc(casted_key) File "pandas/_libs/index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'NCBI_tax_id'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "", line 9, in <module> df_k_genus = df_k[df_k['NCBI_tax_id'].str.contains(r'\g__[^|]*$')] File "/home/axv183/miniconda3/lib/python3.8/site-packages/pandas/core/", line 3506, in __getitem__ indexer = self.columns.get_loc(key) File "/home/axv183/miniconda3/lib/python3.8/site-packages/pandas/core/indexes/", line 3623, in get_loc raise KeyError(key) from err KeyError: 'NCBI_tax_id'

The command i gave was:

df_k = pd.read_table("merged_output.txt", sep='\t') print(df_k.head())

df_k_genus = df_k[df_k['NCBI_tax_id'].str.contains(r'\g__[^|]*$')] df_k_genus.reset.index(drop=True,inplace=True)




Login before adding your answer.

Traffic: 1739 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6