Skip to content
Julio92-CPublic

About

A config-driven R workflow for long-read shotgun metagenomics analysis

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

205 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฌ MERIDIAN

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.

R Quarto Platform License Version Status


โœจ Why this exists

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.


๐Ÿ—บ๏ธ Pipeline roadmap

Pipeline roadmap

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).


๐Ÿš€ Features

  • ๐Ÿงพ 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.

๐Ÿงช Analysis blocks

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.md for tool versions, parameters and direct quotes.


๐Ÿ“ฆ Installation

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".


โšก Quickstart

  1. Copy the config template and point it at your study:

    cp config/config_template.yaml projects/my_study/config.yaml
  2. Edit projects/my_study/config.yaml โ€” set project_root, the metadata file path, sample_id_col, group_cols and your control sample IDs. Nothing else needs to change.

  3. Run the pipeline:

    Rscript run_pipeline.R projects/my_study/config.yaml
  4. Open the report at <project_root>/Reports/pipeline_report.html. ๐ŸŽ‰

Each stage can be skipped by flipping a flag under stages: in the config.


๐Ÿณ Running in a container

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 โ†’ the R/NN_*.R modules โ†’ 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.yaml

New 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.yaml

Outputs land under the mounted study dir on the host (manifest JSON, panel figures, and the Quarto HTML report).

HPC (Apptainer / Singularity)

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.yaml

A zero exit code plus the expected artifacts under the bound study dir (manifest JSON, panel PNGs, Quarto HTML report) constitutes a passing full run.


๐Ÿ—‚๏ธ Repository layout

.
โ”œโ”€โ”€ ๐Ÿ“ 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

๐Ÿง  How it replaces manual work

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

๐Ÿค Contributing

Contributions are very welcome โ€” bug reports, methodology improvements, support for new databases, extra analysis blocks.

  1. Fork the repo and create a feature branch (git checkout -b feature/awesome).
  2. Keep each R module self-contained and driven by cfg.
  3. Add a short section to docs/conversation_log.md describing the design choice (the repo keeps a running design journal, not just code).
  4. 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.


๐Ÿ“š Citation

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.


๐Ÿ“ฌ Contact

๐Ÿ‘ค 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


๐Ÿ“œ License

GPL-3.0 โ€” see LICENSE.


Made with โ˜•, ๐Ÿงฌ, and a lot of Rscript.

About

A config-driven R workflow for long-read shotgun metagenomics analysis

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages