Skip to content

Repository files navigation

aRchiteutis aRchiteutis

R-CMD-check R-package License: MIT

R package for Kraken2, Kaiju and Bracken reports: read them into a tidy table, or start from an abundance matrix, a phyloseq object, or a table exported from Python, then plot composition, diversity and ordination.

Install

# install.packages("remotes")
remotes::install_github("dsmutin/aRchiteutis")
library(aRchiteutis)

Report

archi_report() reads a directory of Kraken, Kaiju or QIIME 2 profiles (or a taxid abundance table), builds a phyloseq object with a taxonomy tree, and drops samples that fall below a read floor or whose rarefaction curve is still rising. Each requested plot is written with a one-line method caption. The HTML and the MultiQC section both end by stating that this is a preliminary report, not a final analysis.

path   <- system.file("extdata", package = "aRchiteutis")
legend <- system.file("extdata", "legend.csv", package = "aRchiteutis")
archi_report(
  path, legend, outdir = "report",
  pattern = "_k2\\.txt$", trim_char = "_", target = "stage",
  plots = c("composition", "donut", "alpha", "beta", "rarefaction")
)

source is "auto", "kraken", "kaiju", "qza" or "abundance". plots may also include barplot, heattree, upset and difftree. beta_method is any name from archi_beta_methods().

A rendered PDF of that report on the bundled Kraken2 profiles is examples/kraken2-report.pdf.

Skills

Agent skills in skills/ only call package functions. Start with skills/aRchiteutis/SKILL.md.

Step Skills
Load a tidy table aRchiteutis-load-kraken, aRchiteutis-load-abundance, aRchiteutis-load-phyloseq, aRchiteutis-load-python
Import to phyloseq aRchiteutis-import-kraken, aRchiteutis-import-kaiju, aRchiteutis-import-qza, aRchiteutis-import-abundance, aRchiteutis-taxonomy-tree
Trim and reshape aRchiteutis-transform
Plot aRchiteutis-plot-composition, aRchiteutis-plot-diversity, aRchiteutis-plot-rarefaction, aRchiteutis-plot-difftree, aRchiteutis-plot-heattree, aRchiteutis-plot-ordination
Preliminary report aRchiteutis-report

The same files are mirrored under .cursor/skills/ for the editor.

Load data

Kraken2 reports (example files ship in the package):

path   <- system.file("extdata", package = "aRchiteutis")
legend <- system.file("extdata", "legend.csv", package = "aRchiteutis")
df <- get_counts(path, pattern = "decont_b", legend = legend, trim_char = "_")

Other inputs, same plotting functions:

df <- from_abundance(count_matrix, clade = "G")   # taxa in rows, samples in columns
df <- from_phyloseq(physeq, taxa_rank = "Genus")
df <- python2r("abundance.csv", clade = "G")      # CSV from inst/python/python2r.py

The table is long: taxa, clade, sample, N, amount, amount_cl, plus legend columns. df_untidy() turns it into a taxa-by-sample matrix. Trim with df_taxa_trim() or df_get_top_taxa() before plotting. Argument details and a second copy of every figure are in vignettes.md.

Plots

Figures below are rendered from the bundled honey-bee brood reports.

Composition

df2donut() — mean composition.

Donut of mean composition

df2composition() — stacked bars per sample. Samples are ordered by the first principal component (order_samples = "fpc"). hclust, abundance, alpha and none are the other orders.

Stacked composition bars

df2barplot() — amount per taxon. style = "raincloud" draws a ggviolinbox raincloud.

df2composition_tree() — fan cladogram from ggtree (Yu et al. 2017) with a ggtreeExtra boxplot of relative abundance (Xu et al. 2021). Tips and boxes are coloured by phylum when a rank table is available.

Fan tree of composition

Raincloud of taxon amounts

Diversity

df2alpha_summary() — alpha-diversity indices. split_by is a legend column (here, brood stage).

Alpha-diversity summary

df2alpha() — Shannon and Simpson. style = "raincloud" uses the same raincloud geometry.

Raincloud of Shannon and Simpson

df2rarefaction() — observed richness, Shannon and Simpson against sequencing depth. One thin line per sample, a smooth by group.

Alpha rarefaction curves

df2beta() — Bray–Curtis distances between samples. Point colour is brood stage. method accepts any name from archi_beta_methods(), including "aitchison".

Beta-diversity heatmap

df2beta_pcoa() — PCoA of that distance, with group ellipses.

Beta-diversity PCoA

Taxonomy

df2heattree() — metacoder heat tree. Node size is the number of taxa, colour is mean relative abundance. Empty ranks are dropped and their children reattached, so the taxonomy is one tree. The function stops when \pkg{metacoder} is not installed.

Taxonomic heat tree

df2difftree() — log2 fold change between two groups on a ggtree layout. The default fruit is a heatmap of relative abundance; tip colour is the fold change. fruit = "bar" draws the fold change as a column. With more than two groups, pass contrast. engine = "metacoder" draws metacoder::heat_tree and stops when that package is not installed. engine = "microbiota" runs MicrobiotaProcess mp_diff_analysis and stops when that package is not installed.

Differential abundance tree

engine = "microbiota" draws the MicrobiotaProcess biomarker tree (radial ggtree, phylum highlight, abundance stars, LDA and FDR) when that package is installed.

MicrobiotaProcess differential tree

df2upset() — taxon presence as a ComplexUpset plot. The function stops when \pkg{ComplexUpset} is not installed.

UpSet of taxon presence

Clustering and correlation

df2cluster() — dendrogram of taxa or of samples. Leaf colour is the cluster.

Taxon dendrogramSample dendrogram

df2clust2d() — mean abundance in two groups on a log10 scale (pupa vs larvae).

Two-group cluster scatter

df2heatmap() — taxa by sample.

Taxon heatmap

df2corrplot() — correlations between taxa.

Taxon correlation plot

Ordination and group differences

df2chord() — circular co-occurrence graph.

Chord plot of taxon correlations

df2tsne() — t-SNE of taxa.

t-SNE of taxa

df2volcano() — ANCOM-BC2 log2 fold change against adjusted q. The first legend_detect pattern is the reference group. The function stops when \pkg{ANCOMBC} is not installed.

Volcano plot

df2pca_sample() — PCA of samples. df2pca_sp() — PCA of taxa.

PCA of samplesPCA of taxa

Cite

citation("aRchiteutis")

The record lives in inst/CITATION: Smutin, Taldaev, Lebedev & Adonin, International Journal of Molecular Sciences 25(2):741, 2024. https://doi.org/10.3390/ijms25020741

About

metagenomic R visualization

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages