Compare shotgun profilers
Bracken and MetaPhlAn assign different meanings to relative abundance. Bracken redistributes classified fragments using database expectations, while MetaPhlAn estimates organism abundance from clade specific markers. Agreement between the two therefore depends on the database, taxonomic definitions, genome lengths, and detection limits.
The Bracken method describes read reestimation. The MetaPhlAn documentation describes marker based abundance and its output format. Neither profile alone provides absolute microbial cell counts.
Align taxa without changing the denominator
Section titled “Align taxa without changing the denominator”Use the participants selected in the human shotgun cohort. The preparation script retains bacterial and archaeal species from both tools. It uses the Kraken2 hierarchy to identify those branches in Bracken and the clade paths in MetaPhlAn. It excludes other domains and aggregates MetaPhlAn species entries that share a valid terminal NCBI taxonomic identifier.
Every sample has a row for every species observed anywhere in its profiler’s archived table. An unreported entry becomes an arithmetic zero. This rule makes a group mean include every selected participant, including participants whose profile does not report that species. It does not prove biological absence.
Each profile is normalized over its full retained bacterial and archaeal table. The intersection of NCBI species identifiers then defines shared coverage. The code does not renormalize that intersection to 100 percent, which would conceal profiler specific assignments. Species without an NCBI identifier remain in the MetaPhlAn denominator but cannot join the shared identifier set.
Compare complete and conditional means
Section titled “Compare complete and conditional means”Segatella copri has NCBI identifier 165179. Older references call it Prevotella copri. The example prints its mean across all selected participants in each diagnosis and the conditional mean among positive profile entries. These answer different questions. Use the complete mean when describing the average profile of a diagnosis group.
Both tabs run in the companion microbiome:0.1.0 container. The
cohort page
explains fixture access and the archived primary run.
The archived read analyses use 30 public runs from the Lloyd-Price and colleagues IBDMDB study, covered by the INSDC data policy. The original iHMP data-use policy also permits use of the clinical metadata; its publication moratorium ended by fall 2018. These data were supplied by Ramnik Xavier and Curtis Huttenhower through the HMP program with NIH Common Fund grant 8U54DK102557.
The archived profiles were produced by MetaPhlAn 4.1.1 with the mpa_vJan25_CHOCOPhlAnSGB_202503 marker database. The bioBakery database policy permits ChocoPhlAn databases with their associated software. This example compares abundance outputs and does not redistribute or modify the marker database. The retained policy notice states the database restrictions. The method credit belongs to Blanco-Míguez and colleagues, MetaPhlAn 4.
library(ggplot2)library(jsonlite)
metadata <- read.delim("/fixtures/ibdmdb_metadata.tsv", row.names = 1, check.names = FALSE)metadata <- metadata[metadata$selected == "True", ]counts <- t(as.matrix(read.delim("/fixtures/ibdmdb_bracken_counts.tsv", row.names = 1, check.names = FALSE)))counts <- counts[rownames(metadata), , drop = FALSE]stopifnot(identical(rownames(counts), rownames(metadata)))stopifnot(!anyDuplicated(metadata$subject_id), all(rowSums(counts) > 0))groups <- c("nonIBD", "CD", "UC")metadata$diagnosis <- factor(metadata$diagnosis, levels = groups)dir.create("outputs", showWarnings = FALSE)
metaphlan <- t(as.matrix(read.delim("/fixtures/ibdmdb_metaphlan_percent.tsv", row.names = 1, check.names = FALSE)))metaphlan <- metaphlan[rownames(metadata), , drop = FALSE]stopifnot(all(rowSums(metaphlan) > 0))bracken <- counts / rowSums(counts)metaphlan <- metaphlan / rowSums(metaphlan)shared <- sort(intersect(colnames(bracken), colnames(metaphlan)))bracken_mass <- rowSums(bracken[, shared, drop = FALSE])metaphlan_mass <- rowSums(metaphlan[, shared, drop = FALSE])cat(sprintf("Shared NCBI species IDs: %d\n", length(shared)))cat(sprintf("Median shared mass, Bracken: %.6f\n", median(bracken_mass)))cat(sprintf("Median shared mass, MetaPhlAn: %.6f\n", median(metaphlan_mass)))copri <- "165179"stopifnot(copri %in% shared)means <- data.frame()for (group in groups) { selected <- metadata$diagnosis == group values <- 100 * metaphlan[selected, copri] complete_mean <- mean(values) positive_mean <- NA_real_ if (any(values > 0)) { positive_mean <- mean(values[values > 0]) } cat(sprintf("%s copri: %d/%d reported; all=%.6f%%; positive=%.6f%%\n", group, sum(values > 0), length(values), complete_mean, positive_mean)) means <- rbind(means, data.frame(diagnosis = group, bracken = 100 * mean(bracken[selected, copri]), metaphlan = complete_mean))}write.table(means, "outputs/copri_means_r.tsv", sep = "\t", row.names = FALSE, quote = FALSE)plot_data <- data.frame(bracken = 100 * bracken[, copri], metaphlan = 100 * metaphlan[, copri], diagnosis = metadata$diagnosis)figure <- ggplot(plot_data, aes(bracken, metaphlan, color = diagnosis)) + geom_abline(slope = 1, intercept = 0, color = "gray", linetype = "dashed") + geom_point(size = 2.7) + coord_equal(xlim = c(0, 100), ylim = c(0, 100)) + scale_color_manual(values = c("#287d8e", "#c95d35", "#8462ab")) + theme_bw(base_size = 11) + labs(x = "Bracken microbial fragment share (%)", y = "MetaPhlAn microbial organism share (%)", color = "Diagnosis", title = "Segatella copri: matched species ID 165179")ggsave("outputs/shotgun_tool_comparison_r.png", figure, width = 7, height = 5, dpi = 160)write_json(list(shared = length(shared), bracken_mass = median(bracken_mass), metaphlan_mass = median(metaphlan_mass), nonibd_copri = means$metaphlan[1], cd_copri = means$metaphlan[2], uc_copri = means$metaphlan[3]), "outputs/metrics_r.json", auto_unbox = TRUE, digits = 16)Shared NCBI species IDs: 163Median shared mass, Bracken: 0.934260Median shared mass, MetaPhlAn: 0.821527nonIBD copri: 4/9 reported; all=24.820718%; positive=55.846616%CD copri: 1/10 reported; all=0.012442%; positive=0.124420%UC copri: 1/7 reported; all=8.066254%; positive=56.463780%
import jsonfrom pathlib import Path
import matplotlib.pyplot as pltimport numpy as npimport pandas as pdfrom scipy import stats
metadata = pd.read_csv("/fixtures/ibdmdb_metadata.tsv", sep="\t", index_col=0, dtype={"selected": str})metadata = metadata.loc[metadata["selected"].eq("True")]counts = pd.read_csv("/fixtures/ibdmdb_bracken_counts.tsv", sep="\t", index_col=0).T.loc[metadata.index]assert counts.index.equals(metadata.index)assert metadata["subject_id"].is_uniqueassert (counts.sum(axis=1) > 0).all()groups = ["nonIBD", "CD", "UC"]output = Path("outputs")output.mkdir(exist_ok=True)
metaphlan = pd.read_csv("/fixtures/ibdmdb_metaphlan_percent.tsv", sep="\t", index_col=0).T.loc[metadata.index]counts.columns = counts.columns.astype(str)metaphlan.columns = metaphlan.columns.astype(str)assert (metaphlan.sum(axis=1) > 0).all()bracken = counts.div(counts.sum(axis=1), axis=0)metaphlan = metaphlan.div(metaphlan.sum(axis=1), axis=0)shared = sorted(set(bracken.columns) & set(metaphlan.columns))bracken_mass = bracken[shared].sum(axis=1)metaphlan_mass = metaphlan[shared].sum(axis=1)print(f"Shared NCBI species IDs: {len(shared)}")print(f"Median shared mass, Bracken: {bracken_mass.median():.6f}")print(f"Median shared mass, MetaPhlAn: {metaphlan_mass.median():.6f}")copri = "165179"assert copri in sharedmeans = []for group in groups: selected = metadata["diagnosis"].eq(group) values = 100 * metaphlan.loc[selected, copri] complete_mean = values.mean() positive_mean = values.loc[values > 0].mean() print(f"{group} copri: {(values > 0).sum()}/{len(values)} reported; " f"all={complete_mean:.6f}%; positive={positive_mean:.6f}%") means.append({"diagnosis": group, "bracken": 100 * bracken.loc[selected, copri].mean(), "metaphlan": complete_mean})pd.DataFrame(means).to_csv(output / "copri_means_python.tsv", sep="\t", index=False)figure, axis = plt.subplots(figsize=(7, 5))for group, color in zip(groups, ["#287d8e", "#c95d35", "#8462ab"]): selected = metadata["diagnosis"].eq(group) axis.scatter(100 * bracken.loc[selected, copri], 100 * metaphlan.loc[selected, copri], label=group, color=color)axis.plot([0, 100], [0, 100], color="gray", linestyle="--")axis.set(xlim=(0, 100), ylim=(0, 100), aspect="equal", xlabel="Bracken microbial fragment share (%)", ylabel="MetaPhlAn microbial organism share (%)", title="Segatella copri: matched species ID 165179")axis.legend(title="Diagnosis")figure.tight_layout()figure.savefig(output / "shotgun_tool_comparison_python.png", dpi=160)plt.close(figure)metrics = {"shared": len(shared), "bracken_mass": bracken_mass.median(), "metaphlan_mass": metaphlan_mass.median()}for row, key in zip(means, ["nonibd_copri", "cd_copri", "uc_copri"]): metrics[key] = row["metaphlan"](output / "metrics_python.json").write_text(json.dumps(metrics))Shared NCBI species IDs: 163Median shared mass, Bracken: 0.934260Median shared mass, MetaPhlAn: 0.821527nonIBD copri: 4/9 reported; all=24.820718%; positive=55.846616%CD copri: 1/10 reported; all=0.012442%; positive=0.124420%UC copri: 1/7 reported; all=8.066254%; positive=56.463780%
Read the disagreement
Section titled “Read the disagreement”Each point represents the same participant in both profilers. The diagonal shows numerical equality, although the axes measure different abundance targets. Several participants overlap near zero, so visible points do not count participants. Distance from that line is not an error rate. This cohort has no independent species abundance measurement with which to score accuracy.
The shared mass calculation also has a narrow meaning. A shared identifier appears somewhere in both archived feature sets; it need not be reported by both tools in every sample. The two database releases can split or merge taxa differently even when some identifiers match. A broader benchmark needs a documented taxonomy crosswalk and an independent reference.
Keep Bracken’s estimated counts and MetaPhlAn’s abundance percentages separate. Multiplying a marker based percentage by library size does not recover observed species counts. The cohort statistics lesson states which profile defines each analysis.
Further reading
Section titled “Further reading”-
The original documentation explains how database and read length distributions redistribute classified reads. These estimates retain a different target from marker based organismal abundance.
-
The documentation describes clade specific markers, organismal relative abundance, and taxonomically unidentified species bins. Those distinctions explain why a shared identifier set does not define equal profiler coverage.