Metagenomic Evaluation of Resistance, Identity & Diversity through Integrated Analysis of Nanopore sequencing
A config-driven, reproducible workflow for taxonomic profiling and resistome, virulome, and mobilome characterisation from ONT long reads โ
from raw Kraken2 / Bracken / ABRicate reports to a publication-ready HTML report in one command.
Running a metagenomics study shouldn't mean hand-editing 30โ50 R scripts
every time the metadata changes. Absolute paths, sample IDs pasted into
select() calls, manual row-index taxonomy fixes, copy-pasted chunks
between projects โ it adds up to days of error-prone work per study.
MERIDIAN replaces that workflow with a single config.yaml per study
and one command to run every analysis block, from decontamination to the
final HTML report.
Upstream inputs (Kraken2 / Bracken taxonomy, ABRicate gene-element hits
against CARD / VFDB / PlasmidFinder, Re-centrifuge contamination tags,
and the study metadata) feed a single config.yaml. From there the
numbered R/NN_*.R modules cover decontamination, TPM normalisation,
community analyses (taxonomy / relative abundance / ฮฑ + ฮฒ diversity /
ALDEx2 differential abundance), functional profiling (resistome /
virulome / mobilome), and the tripartite network. The run ends with a
Quarto HTML dashboard, a kind-tagged manifest.json catalogue, and the
publication outputs (composite TIFFs + supplementary XLSX).
- ๐งพ One config per study. Everything that varies between studies (metadata file, grouping columns, controls, filter thresholds) lives in a single YAML file. The code never changes.
- ๐งฉ Modular stages. Each analysis block is its own R module; toggle any stage on/off with a flag.
- ๐ก๏ธ Reproducible methodology. Mirrors the methods used in peer-reviewed long-read metagenomics studies (Kraken2 + Bracken + ABRicate + Re-centrifuge + ALDEx2 + vegan).
- ๐ Publication-ready figures. Violin plots, PCoA ordinations, Venn diagrams, pHeatmaps, Sankey and chord diagrams, tripartite networks.
- ๐ฅ๏ธ Single-command HTML report. Quarto renders everything into a
self-contained
pipeline_report.html. - ๐ Transparent logs. Every run writes a timestamped log with the statistics produced at each stage.
Rows are listed in execution order. The Module column matches the
file name under R/; R/14_manifest.R runs after R/13_panels.R by
design so the manifest catalogues the rendered composites.
| Module | Block | Icon | Tool / method |
|---|---|---|---|
R/00_setup.R |
Setup | ๐ ๏ธ | Paths, logging, config loader (sourced at startup; not a toggleable stage) |
R/01_load_inputs.R |
Load inputs | ๐ฅ | Kraken2, Bracken, ABRicate, Re-centrifuge raw reports |
R/02_clean_data.R |
Clean & decontaminate | ๐งผ | Merge reports, control subtraction, taxid fixes |
R/03_normalisation.R |
Normalisation | โ๏ธ | TPM per gene element (GE) |
R/04_taxonomy.R |
Taxonomy | ๐ฟ | Venn + pHeatmap across treatment groups |
R/05_relative_abundance.R |
Relative abundance | ๐ | Stacked bar + stream plots (phylum โ species) + plotly HTML |
R/06_alpha_diversity.R |
Alpha diversity | ๐ป | Richness, Shannon, Simpson, โฆ; KruskalโWallis, violin plots |
R/07_beta_diversity.R |
Beta diversity | ๐งญ | BrayโCurtis โ PCoA; PERMANOVA (adonis2, 9999 permutations) |
R/08_differential_abundance.R |
Differential abundance | ๐งฎ | ALDEx2 โ 128 MC Dirichlet instances, CLR pairwise tests |
R/09_resistome.R |
Resistome | ๐ | ABRicate + CARD โ ARG profile |
R/10_virulome.R |
Virulome | ๐ฆ | ABRicate + VFDB โ virulence factor profile |
R/11_mobilome.R |
Mobilome | ๐งฌ | ABRicate + PlasmidFinder โ MGE profile |
R/12_network.R |
Network | ๐ธ๏ธ | Tripartite Treatment ร taxa ร GE; igraph + Gephi-ready edges; chord + Sankey |
templates/report.qmd |
Report | ๐ | Quarto โ single self-contained HTML dashboard per study |
R/13_panels.R |
Panels | ๐ผ๏ธ | Composite multi-panel figures (TIFF / PNG / PDF) + supplementary_tables.xlsx |
R/14_manifest.R |
Manifest | ๐๏ธ | Kind-tagged manifest.json catalogue โ stable JSON contract for downstream agents |
Methodology reproduced from a peer-review-stage long-read metagenomics manuscript. See
reference_methodology/chicken_batch1_methods.mdfor tool versions, parameters and direct quotes.
Prerequisites
- R โฅ 4.5
- Quarto โฅ 1.4
- Git
Clone and restore the pinned R environment with renv
git clone https://github.com/Julio92-C/Metagenomics_pipeline_automation.git
cd Metagenomics_pipeline_automation
# Launch R in the project and restore the locked package versions.
# renv::restore() reads renv.lock and installs the exact versions used
# to develop the pipeline (including ALDEx2 from Bioconductor 3.22).
Rscript -e 'if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv", repos = "https://cloud.r-project.org"); renv::restore(prompt = FALSE)'The lockfile records R 4.5.0 + 180 packages (CRAN + Bioconductor). To bump
a package later: install the new version, then run renv::snapshot().
Note on ggalluvial vs ggplot2. The sankey PNGs in R/12_network.R
require ggalluvial. The lock pairs ggalluvial 0.12.6 with ggplot2 4.0.3 โ 0.12.6 calls a gg_par() internal that does not exist in
ggplot2 โค 3.5.x. If your local environment is still on ggplot2 3.5.x
(i.e. you have not yet renv::restore()-d to the locked 4.0.3), install
the prior ggalluvial 0.12.5 from a date-pinned snapshot instead:
install.packages("ggalluvial",
repos = "https://packagemanager.posit.co/cran/2025-09-15")Otherwise the sankey render aborts with could not find function "gg_par".
-
Copy the config template and point it at your study:
cp config/config_template.yaml projects/my_study/config.yaml
-
Edit
projects/my_study/config.yamlโ setproject_root, the metadata file path,sample_id_col,group_colsand your control sample IDs. Nothing else needs to change. -
Run the pipeline:
Rscript run_pipeline.R projects/my_study/config.yaml
-
Open the report at
<project_root>/Reports/pipeline_report.html. ๐
Each stage can be skipped by flipping a flag under stages: in the config.
For reproducibility (a citable image tag pins the exact analysis behind the
manuscript) and HPC / collaborator portability, MERIDIAN ships a Dockerfile
that bundles the R + Quarto analysis layer with the pinned renv environment.
Scope. The image contains the analysis/reporting layer only โ
run_pipeline.Rโ theR/NN_*.Rmodules โ the Quarto report. The upstream classification tools (basecalling, wf-metagenomics, Kraken2 / Bracken, ABRicate, Re-centrifuge) are not included; the pipeline consumes their pre-computed CSV/text outputs. Study data and per-study configs are supplied at runtime via bind mounts, not baked into the image.
Runtime contract. Mount your study directory into the container, point
MERIDIAN_PROJECT_ROOT at that container path, and pass a config path as the
argument. The override wins over the config's own project_root: value, so the
same config.yaml runs unchanged natively and in-container.
Build:
docker build -t meridian:v1.3.1 .Reproduce a bundled study (config baked into the image):
docker run --rm \
-e MERIDIAN_PROJECT_ROOT=/data \
-v /host/path/to/study_dir:/data \
meridian:v1.3.1 projects/chicken_batch1/config.yamlNew study (mount your own config too):
docker run --rm \
-e MERIDIAN_PROJECT_ROOT=/data \
-v /host/study_dir:/data \
-v /host/my_config.yaml:/project/config.yaml \
meridian:v1.3.1 /project/config.yamlOutputs land under the mounted study dir on the host (manifest JSON, panel figures, and the Quarto HTML report).
Docker is the single source of truth; convert to a .sif on the cluster.
# 1. Build on a machine with Docker (your workstation).
docker build -t meridian:v1.3.1 .
# 2. Export to a tar and copy it to the HPC (scp/rsync).
docker save meridian:v1.3.1 -o meridian_v1.3.1.tar
# 3. Convert to a .sif on the HPC (rootless; Docker usually unavailable there).
apptainer build meridian_v1.3.1.sif docker-archive://meridian_v1.3.1.tar
# 4. Run against a real study (SLURM job script example).
apptainer run \
--env MERIDIAN_PROJECT_ROOT=/data \
--bind /scratch/$USER/study_dir:/data \
meridian_v1.3.1.sif projects/chicken_batch1/config.yamlA zero exit code plus the expected artifacts under the bound study dir (manifest JSON, panel PNGs, Quarto HTML report) constitutes a passing full run.
.
โโโ ๐ R/ function library (sourced by run_pipeline.R)
โ โโโ 00_setup.R paths, logging, config loader
โ โโโ 01_load_inputs.R Kraken2 / Bracken / ABRicate / Re-centrifuge
โ โโโ 02_clean_data.R merge + decontamination
โ โโโ 03_normalisation.R TPM
โ โโโ 04_taxonomy.R Venn + heatmap
โ โโโ 05_relative_abundance.R stacked bars + plotly
โ โโโ 06_alpha_diversity.R richness, Shannon, KruskalโWallis
โ โโโ 07_beta_diversity.R BrayโCurtis, PCoA, PERMANOVA
โ โโโ 08_differential_abundance.R ALDEx2
โ โโโ 09_resistome.R CARD / ARGs
โ โโโ 10_virulome.R VFDB / VFs
โ โโโ 11_mobilome.R PlasmidFinder / MGEs
โ โโโ 12_network.R tripartite + topology metrics
โ โโโ 13_panels.R composite TIFF/PNG figures + supp tables XLSX
โ โโโ 14_manifest.R kind-tagged manifest.json catalogue
โ โโโ utils_*.R shared helpers (palette, taxa, GE profile, โฆ)
โโโ ๐ config/ schema + annotated template
โโโ ๐ projects/ one subfolder per study, each with config.yaml
โโโ ๐ templates/ Quarto report template + panel slot YAML
โโโ ๐ scripts/ panels_only.R (~45s re-render), smoke_panels.R
โโโ ๐ reference_methodology/ methods extracted from reference papers
โโโ ๐ docs/ conversation log, manuscript drafts, schematic
โโโ ๐ run_pipeline.R master entry point
โโโ ๐ README.md
| Manual pattern in old scripts | Replaced by |
|---|---|
"C:/Users/.../Study_X/Reports/..." hardcoded paths |
project_root + relative paths in config.yaml |
select("PO4B4", "PO5B4", ...) sample ID lists |
Sample IDs read dynamically from metadata |
noncontaminants_list[26, 4] <- "Escherichia coli O157" |
Metadata/taxid_fixes.csv lookup table |
| Re-running 30+ scripts by hand | One Rscript run_pipeline.R <config> command |
| Paper-ready figure assembly in PowerPoint | Quarto HTML report with every figure embedded |
Contributions are very welcome โ bug reports, methodology improvements, support for new databases, extra analysis blocks.
- Fork the repo and create a feature branch (
git checkout -b feature/awesome). - Keep each R module self-contained and driven by
cfg. - Add a short section to
docs/conversation_log.mddescribing the design choice (the repo keeps a running design journal, not just code). - Open a pull request with a short demo config that shows the change.
For larger changes (new pipeline stage, breaking config schema change), please open an issue first so we can discuss the design.
If you use this pipeline in your research, please cite the upstream methodology papers:
- Wood, D. E., Lu, J. & Langmead, B. (2019). Improved metagenomic analysis with Kraken 2. Genome Biology, 20, 257.
- Lu, J. et al. (2022). Metagenome analysis using the Kraken software suite. Nature Protocols, 17, 2815โ2839.
- Fernandes, A. D. et al. (2014). Unifying the analysis of high-throughput sequencing datasetsโฆ ALDEx2. Microbiome, 2, 15.
- Oksanen, J. et al. vegan: Community Ecology Package (R package).
Citation details for the reference manuscripts will be added once the papers are accepted.
๐ค Julio C. Ortega Cambara
๐ PhD Candidate โ Computational Bioinformatics
๐๏ธ School of Biomedical Sciences, University of West London
๐ St Mary's Rd, London W5 5RF
โ๏ธ Email: 32104617@student.uwl.ac.uk
GPL-3.0 โ see LICENSE.
Made with โ, ๐งฌ, and a lot of Rscript.
