The workflow and the datasets
Microbiome analysis has two distinct starting points. Amplicon reads measure a selected marker, while shotgun reads sample DNA across genomes. Both routes produce feature tables, but an ASV count, a classified read count, and a marker based abundance estimate have different meanings.
Keep the four data sources separate
Section titled “Keep the four data sources separate”| Dataset | Role | Limit |
|---|---|---|
| mothur MiSeq SOP | Demonstrate nf-core/ampliseq on public mouse 16S reads and a mock sample | Repeated samples from one mouse do not provide independent animals |
| SRR12324253 | Demonstrate nf-core/taxprofiler on a declared subset of Zymo mock reads | A mock sample supports a technical comparison, not a clinical group comparison |
| Kostic colorectal study | Compare tumor tissue with matched normal tissue | Adjacent normal tissue comes from cancer patients, not independent healthy controls |
| IBDMDB, PRJNA398089 | Compare archived human shotgun profiles across diagnoses | One selected sample per participant supports a small cross sectional teaching comparison |
The cohort tables come from the phyloseq example archive. Its metadata identify each patient and tissue. The preparation script retains patients with exactly one normal sample and one tumor sample, each with at least 1,000 reads. This is a teaching selection rule, not a universal quality threshold. The original archive and the prepared subset have recorded checksums.
The cohort contains older reference OTUs from 16S pyrosequencing. The section does not describe them as newly inferred ASVs or as results from taxprofiler.
The human shotgun case study uses a separate set of archived Bracken and MetaPhlAn profiles. It verifies diagnoses against official IBDMDB metadata and selects independent participants. Its R and Python analyses rerun locally; the archived primary AWS pipeline does not run again in this case study.
Run this example
Section titled “Run this example”The code below inspects the prepared Kostic colorectal cohort. Counts, taxonomy, and metadata come from the same public archive. The original features are reference OTUs, separate from the ampliseq demonstration.
The companion repository
is private and requires access. Its microbiome:0.1.0 container provides the
packages, and the runner mounts the prepared tables at /fixtures.
Run each language’s blocks in order. The container runs without network access.
Read the data and calculate the result
Section titled “Read the data and calculate the result”The checks align sample identifiers before any arithmetic. A matching number of rows alone cannot establish that metadata and counts describe the same samples. The histogram shows sequencing effort, and the pair table checks the experimental unit.
The paired counts and metadata come from Kostic and colleagues, distributed in the pinned phyloseq example archive. McMurdie and Holmes distribute that package under AGPL-3. The source notice records the exact archive, the 76-subject selection, and the applicable package terms.
library(ggplot2)library(jsonlite)
counts <- read.delim( "/fixtures/cohort_counts.tsv", row.names = 1, check.names = FALSE)counts <- t(as.matrix(counts))metadata <- read.delim("/fixtures/cohort_metadata.tsv")metadata <- metadata[match(rownames(counts), metadata$sample_id), ]stopifnot(identical(rownames(counts), metadata$sample_id))stopifnot(all(counts >= 0), all(counts == floor(counts)))dir.create("outputs", showWarnings = FALSE)
pair_table <- table(metadata$subject_id, metadata$tissue)stopifnot(all(pair_table == 1), ncol(pair_table) == 2)library_size <- rowSums(counts)cat("Samples:", nrow(counts), "\n")cat("Patients:", nrow(pair_table), "\n")cat("Reference OTUs:", ncol(counts), "\n")cat("Read count range:", min(library_size), max(library_size), "\n")plot_data <- data.frame(reads = library_size, tissue = metadata$tissue)figure <- ggplot(plot_data, aes(reads, fill = tissue)) + geom_histogram(bins = 20, alpha = 0.65, position = "identity") + scale_x_log10() + theme_minimal(base_size = 12) + labs(x = "Reads per sample, log10 scale", y = "Samples", fill = "Tissue")ggsave("outputs/overview_r.png", figure, width = 6, height = 4, dpi = 160)write_json(list(samples = nrow(counts), patients = nrow(pair_table), features = ncol(counts), reads = sum(counts)), "outputs/metrics_r.json", auto_unbox = TRUE, digits = 16)Samples: 152Patients: 76Reference OTUs: 2505Read count range: 1018 11187
import jsonfrom pathlib import Path
import matplotlib.pyplot as pltimport numpy as npimport pandas as pdfrom scipy import statsfrom scipy.spatial.distance import pdist, squareform
counts = pd.read_csv( "/fixtures/cohort_counts.tsv", sep="\t", index_col=0).Tmetadata = pd.read_csv( "/fixtures/cohort_metadata.tsv", sep="\t", index_col=0).loc[counts.index]assert counts.index.equals(metadata.index)assert (counts.to_numpy() >= 0).all()assert (counts.to_numpy() == np.floor(counts.to_numpy())).all()output = Path("outputs")output.mkdir(exist_ok=True)
pair_table = pd.crosstab(metadata["subject_id"], metadata["tissue"])assert pair_table.shape[1] == 2 and (pair_table.to_numpy() == 1).all()library_size = counts.sum(axis=1)print(f"Samples: {counts.shape[0]}")print(f"Patients: {len(pair_table)}")print(f"Reference OTUs: {counts.shape[1]}")print(f"Read count range: {library_size.min()} {library_size.max()}")figure, axis = plt.subplots(figsize=(6, 4))bins = np.geomspace(library_size.min(), library_size.max(), 21)for tissue in ["normal", "tumor"]: axis.hist(library_size[metadata["tissue"] == tissue], bins=bins, alpha=0.65, label=tissue)axis.set(xscale="log", xlabel="Reads per sample, log10 scale", ylabel="Samples")axis.legend(title="Tissue")figure.tight_layout()figure.savefig(output / "overview_python.png", dpi=160)plt.close(figure)metrics = {"samples": counts.shape[0], "patients": len(pair_table), "features": counts.shape[1], "reads": int(counts.to_numpy().sum())}(output / "metrics_python.json").write_text(json.dumps(metrics))Samples: 152Patients: 76Reference OTUs: 2505Read count range: 1018 11187
Follow the sample identifier
Section titled “Follow the sample identifier”The patient provides the independent biological unit for the tissue comparison. Both tissues contribute information, and their shared patient identity belongs in the model. Splitting paired tissues into unrelated groups loses that design.
Continue with QC and contamination. The experimental design page explains the controls and metadata a new study should collect.
Further reading
Section titled “Further reading”-
Pinned phyloseq Kostic archive
The archive contains the reference OTU table and sample mapping file used for the paired cohort. Its metadata support patient and tissue alignment before the teaching selection.
-
The tutorial follows mouse MiSeq SOP libraries through inference and read retention. It explains the separate amplicon source rather than the older colorectal reference OTUs.
-
Lloyd-Price and colleagues, IBDMDB study
The original study explains the separate longitudinal human cohort and its public data deposits. Its study design differs from the matched colorectal tissues.