Predicting Metagenomic Contributions
PICRUSt has the ability to go from gene abundances to taxonomic contributions for each KO. With this data, you can plot which taxa maybe contributing the most to a particular function or KO gene. The first part of this tutorial will use PICRUSt, while the second part will use R for plotting
Step 1: Run metagenomic contributions on metagenomic predictions table. There are tow ways in which you can specify which KO's you are interested in. You can type each KO identifier out using the
-l command, or you can use the
-f command which can use functional identifiers as an input.
# By individual KO's metagenomic_contributions.py \ -i closed_otu_table_json_normalized.biom \ -o metagenomic_contrib_KO1231.txt \ -l K10995,K01231,K02313
Step 2: Once the table has been generated, it must be imported into R for further analysis and plotting.
# Install new packages if not already installed install.packages('devtools') install.packages('ggplot2') # Install btools devtools::install_github('twbattaglia/btools') # Load required libraries library(ggplot2) library(btools)
Step 3: Run the function that will revert OTU's to taxa and add metadata to the table.
contributions <- analyze_contributions(contributions_fp = "metagenomic_contributions.tab", mappingfile_fp = "mapping_file.txt")
Step 4: Plot your results
contributions %>% group_by(Gene, Treatment) %>% mutate(Contribution_perc = ContributionPercentOfAllSamples * 100) %>% filter(Contribution_perc >= 0) %>% select(Gene, family, Contribution_perc) %>% mutate(Contribution = Contribution_perc/sum(Contribution_perc) * 100) %>% ggplot(arrange(pp_pathway_norm, family), aes(x = Treatment, y = Contribution, fill = family)) + geom_bar(stat = "identity") + theme(axis.text.x = element_text(size = 6)) + scale_y_continuous(expand = c(0, 0), limits = c(0, 100)) + theme_light(base_size = 18) + scale_fill_brewer(palette = "Set1") + facet_grid(~Gene)