MGnifyR: An R package for accessing MGnify microbiome data

Wednesday, October 8, 2025

Contents

  1. Bioconductor
  2. MGnifyR R package
  3. mia (Microbiome Analysis) within Bioconductor

Bioconductor

  • Community-driven open-source project
  • High-quality, tested statistical methods
  • Well-documented
Bioconductor logo.

SummarizedExperiment

(Huber et al. 2015)

SummarizedExperiment class

MGnify

MGnifyR

  • Fetch data from MGnify directly to SummarizedExperiment format
  • Bridges the gap between data resources and tools

Demonstration

library("MGnifyR")

mg <- MgnifyClient(
    useCache = TRUE,
    cacheDir = file.path("home", "training", "course_dir", "data_dir")
)

analysis_id <- searchAnalysis(
    mg,
    type = "studies",
    accession = "MGYS00005154"
)

metadata <- getMetadata(mg, accession = analysis_id)

# Get logical vector specifying whether the utilized pipeline was
# the latest one
latest_pipeline <- metadata[["analysis_pipeline-version"]] == "5.0"

# Subset the metadata by selecting only analyses from the
# latest pipeline
metadata <- metadata[latest_pipeline, ]

# Get the IDs
selected_ids <- metadata[["analysis_accession"]]

tse <- getResult(
    mg,
    accession = selected_ids,
    get.func = FALSE
)
tse
class: TreeSummarizedExperiment 
dim: 19216 26 
metadata(0):
assays(1): counts
rownames(19216): 549322 522457 ... 200359 271582
rowData names(7): Kingdom Phylum ... Genus Species
colnames(26): CL3 CC1 ... Even2 Even3
colData names(7): X.SampleID Primer ... SampleType Description
reducedDimNames(0):
mainExpName: NULL
altExpNames(0):
rowLinks: a LinkDataFrame (19216 rows)
rowTree: 1 phylo tree(s) (19216 leaves)
colLinks: NULL
colTree: NULL

References

Huber, W., V. J. Carey, R. Gentleman, S. Anders, M. Carlson, B. S. Carvalho, H. C. Bravo, et al. 2015. Orchestrating High-Throughput Genomic Analysis with Bioconductor.” Nature Methods 12 (2): 115–21. http://www.nature.com/nmeth/journal/v12/n2/full/nmeth.3252.html.