| Title: | R interface to EBI MGnify metagenomics resource |
|---|---|
| Description: | MGnifyR is an R interface to MGnify, EBI's resource for the analysis of metagenomic, metatranscriptomic and amplicon data. It searches MGnify studies, samples and analyses with MGnify API v2, and fetches their taxonomic and functional profiles together with sample metadata. The data is returned as TreeSummarizedExperiment or MultiAssayExperiment, so that it can be analysed directly with Bioconductor microbiome tools. |
| Authors: | Tuomas Borman [aut, cre] (ORCID: <https://orcid.org/0000-0002-8563-8884>), Ben Allen [aut], Leo Lahti [aut] (ORCID: <https://orcid.org/0000-0001-5537-637X>) |
| Maintainer: | Tuomas Borman <[email protected]> |
| License: | Artistic-2.0 |
| Version: | 1.99.0 |
| Built: | 2026-11-07 22:58:22 UTC |
| Source: | https://github.com/bioc/MGnifyR |
MGnifyR Package.MGnifyR fetches data from the EBI MGnify database into R. Browse
studies with searchStudies and fetch their taxonomic profiles
as TreeSummarizedExperiment with fetchStudies. See the
vignette for an introduction,
About MGnify for general
MGnify information, and
API documentation for
details about MGnify API v2.
Maintainer: Tuomas Borman [email protected] (ORCID)
Authors:
Tuomas Borman [email protected] (ORCID)
Ben Allen [email protected]
Leo Lahti [email protected] (ORCID)
Deprecated and defunct functions
MgnifyClient( username = NULL, password = NULL, useCache = FALSE, cacheDir = tempdir(), ... ) getResult( x, accession, get.taxa = "SSU", get.func = TRUE, output = "TreeSE", ... ) searchAnalysis(x, type, accession, ...) getMetadata(x, accession, ...) doQuery( x, type = "studies", accession = NULL, as.df = TRUE, max.hits = 200, ... ) getData(x, type, accession.type = NULL, accession = NULL, as.df = TRUE, ...) searchFile( x, accession, type = c("studies", "samples", "analyses", "assemblies", "genomes", "run"), ... ) getFile(x, url, file = NULL, read.func = NULL, ...) databaseUrl(...) authTok(...) useCache(...) cacheDir(...) showWarnings(...) clearCache(...) verbose(...) databaseUrl(x) <- value authTok(x) <- value useCache(x) <- value cacheDir(x) <- value showWarnings(x) <- value clearCache(x) <- value verbose(x) <- value mgnify_client(...) mgnify_query(...) mgnify_analyses_from_samples(...) mgnify_analyses_from_studies(...) mgnify_get_download_urls(...) mgnify_download(...) mgnify_get_analyses_results(...) mgnify_get_analyses_phyloseq(...) mgnify_get_analyses_metadata(...) mgnify_retrieve_json(...)MgnifyClient( username = NULL, password = NULL, useCache = FALSE, cacheDir = tempdir(), ... ) getResult( x, accession, get.taxa = "SSU", get.func = TRUE, output = "TreeSE", ... ) searchAnalysis(x, type, accession, ...) getMetadata(x, accession, ...) doQuery( x, type = "studies", accession = NULL, as.df = TRUE, max.hits = 200, ... ) getData(x, type, accession.type = NULL, accession = NULL, as.df = TRUE, ...) searchFile( x, accession, type = c("studies", "samples", "analyses", "assemblies", "genomes", "run"), ... ) getFile(x, url, file = NULL, read.func = NULL, ...) databaseUrl(...) authTok(...) useCache(...) cacheDir(...) showWarnings(...) clearCache(...) verbose(...) databaseUrl(x) <- value authTok(x) <- value useCache(x) <- value cacheDir(x) <- value showWarnings(x) <- value clearCache(x) <- value verbose(x) <- value mgnify_client(...) mgnify_query(...) mgnify_analyses_from_samples(...) mgnify_analyses_from_studies(...) mgnify_get_download_urls(...) mgnify_download(...) mgnify_get_analyses_results(...) mgnify_get_analyses_phyloseq(...) mgnify_get_analyses_metadata(...) mgnify_retrieve_json(...)
username, password
|
Webin credentials for |
useCache, cacheDir
|
If |
... |
In |
x |
Ignored. Formerly a |
accession |
A character vector of accessions. |
get.taxa |
Taxonomy to fetch, e.g., |
get.func, output
|
Not supported anymore. |
type |
The type of accessions in |
as.df |
Whether to return a |
max.hits |
The maximum number of results, or |
accession.type |
The type of accessions in |
url |
The URL of the file. |
file |
|
read.func |
|
value |
Ignored. |
MGnify API v1 is frozen, and MGnifyR now uses MGnify API v2. The functions of the earlier versions of MGnifyR are deprecated, and they will be removed in a future release. Where possible, they use the new functions:
MgnifyClient: a client is not needed anymore. Log in with
mgnifyLogin to access private data, and set
options(MGnifyR.cache = "path") to keep the cache between
sessions. For compatibility, MgnifyClient does these, and returns
NULL. The x argument of the other deprecated functions is
ignored.
getResult: use fetchAnalyses. Only taxonomic
profiles are returned, as TreeSummarizedExperiment.
searchAnalysis and getMetadata: use
searchAnalyses.
doQuery and getData: use searchStudies,
searchSamples or searchAnalyses. These query
any endpoint of
MGnify API v2, but
the endpoints and filters differ from API v1.
searchFile and getFile: list and download the files
of studies, samples or analyses.
The accessors of MgnifyClient, such as useCache, and the
functions with mgnify_ prefix are defunct.
See the replacing functions. doQuery, getData and
searchFile return a data.frame, and getFile returns
the path of the file or the result of read.func.
# Instead of getResult(), use fetchAnalyses() tse <- fetchAnalyses("MGYA00383350")# Instead of getResult(), use fetchAnalyses() tse <- fetchAnalyses("MGYA00383350")
Fetch taxonomic and functional profiles
fetchStudies( study.ids, type = "SSU", samples = FALSE, biosamples = FALSE, studies = FALSE, analyses = FALSE, assemblies = FALSE, qc = FALSE ) fetchAnalyses( analysis.ids, type = "SSU", samples = FALSE, biosamples = FALSE, studies = FALSE, analyses = FALSE, assemblies = FALSE, qc = FALSE )fetchStudies( study.ids, type = "SSU", samples = FALSE, biosamples = FALSE, studies = FALSE, analyses = FALSE, assemblies = FALSE, qc = FALSE ) fetchAnalyses( analysis.ids, type = "SSU", samples = FALSE, biosamples = FALSE, studies = FALSE, analyses = FALSE, assemblies = FALSE, qc = FALSE )
study.ids |
A character vector specifying study accessions, e.g.,
|
type |
A character vector specifying the profiles to fetch, e.g.,
|
samples |
|
biosamples |
|
studies |
|
analyses |
|
assemblies |
|
qc |
|
analysis.ids |
A character vector specifying analysis accessions, e.g.,
|
fetchStudies fetches all the analyses of the given studies, and
fetchAnalyses fetches specific analyses, e.g., a filtered result of
searchAnalyses. Columns are analyses and rows are taxa or,
in functional profiles, functions, e.g., GO terms. Taxa are matched across
studies by their taxonomy lineage.
type tells which profile is fetched. Only analyses that have the
type are fetched.
Taxonomic profiles: "SSU" and "LSU" (small and
large subunit rRNA), "mOTUs" (marker genes of metagenomes and
metatranscriptomes, pipelines v5-v6), "UNITE" and
"ITSoneDB" (fungal ITS), "PR2" (eukaryotes),
"DADA2-SILVA" and "DADA2-PR2"
(amplicon sequence variants, pipeline v6), and "contigs"
(number of contigs per taxon in assemblies, pipeline v6). Pipelines
v1-v3 have a single profile, which is fetched with "SSU".
Functional profiles of metagenomes, metatranscriptomes and
assemblies: "InterPro", "GO" and "GO-slim"
(pipelines v1-v6), "Pfam" and "KO" (KEGG orthologs,
pipelines v5-v6), and "antiSMASH" (biosynthetic gene clusters of
assemblies, pipelines v5-v6). In pipeline v6, only assemblies have
functional profiles.
Profiles of different pipeline versions are based on different reference
databases, so they might not be directly comparable. To fetch a single
pipeline version, subset the result of searchAnalyses by
pipeline_version. Data is cached for the R session; to keep it
between sessions, set options(MGnifyR.cache = "path/to/cache").
The arguments samples, biosamples, studies,
analyses, assemblies and qc choose the metadata in
colData, as in searchAnalyses. In
fetchAnalyses, they are used only if analysis.ids are
accessions; for a data.frame, give them to
searchAnalyses instead.
For a single type, a TreeSummarizedExperiment with
assay: "counts"
colData: the columns of searchAnalyses, i.e.,
the metadata of the analyses, their studies and samples
rowData: taxonomy ranks, or the descriptions of the rows of
functional profiles
For multiple types, a MultiAssayExperiment with a
TreeSummarizedExperiment for each type that has data. The profiles
are linked by sample, e.g., the SSU profile of an amplicon analysis and
the GO profile of a metagenomic analysis of the same sample.
NULL is returned if no data could be fetched.
# Fetch all analyses of a study tse <- fetchStudies("MGYS00005116") tse # Select analyses and fetch them analyses <- searchAnalyses("MGYS00005116") analyses <- analyses[analyses[["pipeline_version"]] == "V5", ] tse <- fetchAnalyses(analyses) # Fetch a functional profile of a study tse <- fetchStudies("MGYS00005610", type = "GO-slim") # Fetch taxonomic and functional profiles into MultiAssayExperiment mae <- fetchStudies("MGYS00005610", type = c("SSU", "GO-slim")) # Browse studies and fetch them studies <- searchStudies(biome = "root:Host-associated:Human", max.hits = 5) tse <- fetchStudies(studies)# Fetch all analyses of a study tse <- fetchStudies("MGYS00005116") tse # Select analyses and fetch them analyses <- searchAnalyses("MGYS00005116") analyses <- analyses[analyses[["pipeline_version"]] == "V5", ] tse <- fetchAnalyses(analyses) # Fetch a functional profile of a study tse <- fetchStudies("MGYS00005610", type = "GO-slim") # Fetch taxonomic and functional profiles into MultiAssayExperiment mae <- fetchStudies("MGYS00005610", type = c("SSU", "GO-slim")) # Browse studies and fetch them studies <- searchStudies(biome = "root:Host-associated:Human", max.hits = 5) tse <- fetchStudies(studies)
Log in to MGnify to access private data
mgnifyLogin(username, password)mgnifyLogin(username, password)
username |
A single character value specifying the Webin username,
e.g., |
password |
A single character value specifying the password. |
Most MGnify data is public and can be fetched without logging in. To access
private data, log in with your ENA Webin credentials. The login lasts for
the R session, and it is used by all the functions that fetch data from
MGnify API v2, such as searchStudies and
fetchStudies.
TRUE invisibly, if login was successful.
# Wrong credentials give an error try(mgnifyLogin("Webin-0", "wrong")) # With your own ENA Webin credentials, log in and fetch private data # mgnifyLogin("Webin-1122334", "SecretPassword") # tse <- fetchStudies("MGYS00000001")# Wrong credentials give an error try(mgnifyLogin("Webin-0", "wrong")) # With your own ENA Webin credentials, log in and fetch private data # mgnifyLogin("Webin-1122334", "SecretPassword") # tse <- fetchStudies("MGYS00000001")
Search MGnify studies, samples and analyses
searchStudies( biome = NULL, pipeline.version = NULL, search = NULL, order = NULL, max.hits = NULL ) searchSamples( study.ids = NULL, biome = NULL, search = NULL, order = NULL, max.hits = NULL ) searchAnalyses( study.ids, samples = FALSE, biosamples = FALSE, studies = FALSE, analyses = FALSE, assemblies = FALSE, qc = FALSE )searchStudies( biome = NULL, pipeline.version = NULL, search = NULL, order = NULL, max.hits = NULL ) searchSamples( study.ids = NULL, biome = NULL, search = NULL, order = NULL, max.hits = NULL ) searchAnalyses( study.ids, samples = FALSE, biosamples = FALSE, studies = FALSE, analyses = FALSE, assemblies = FALSE, qc = FALSE )
biome |
|
pipeline.version |
|
search |
|
order |
|
max.hits |
|
study.ids |
A character vector specifying study accessions, e.g.,
|
samples |
|
biosamples |
|
studies |
|
analyses |
|
assemblies |
|
qc |
|
Browse studies with searchStudies and fetch their data with
fetchStudies. To select specific analyses, e.g., by sample
metadata or pipeline version, filter the result of searchAnalyses
and give it to fetchAnalyses.
searchAnalyses returns one row per analysis with the accessions,
pipeline version, experiment type, sequencing instrument, and the other
fields of the analysis in the list of analyses of its study. The other
sources are added with separate arguments, as each needs its own requests.
By default, none of them is added, which is the fastest. The data is
cached, so a later search with more sources fetches only the new data:
samples: sample metadata in MGnify (sample_*),
one request per 100 samples
biosamples: all attributes of the samples in
BioSamples
(biosamples_*), including study-specific variables, e.g.,
biosamples_disease_status, one request per 100 samples
studies: details and publications of the studies
(study_*), two requests per study
analyses: details of the analyses (analysis_*),
e.g., the quality control of pipeline v6, one request per analysis
assemblies: details of the assemblies
(assembly_*), one request per assembly
qc: quality control files of pipelines v1-v5
(analysis_*), several files per analysis, and the details of
the analyses
These are the same columns as in the
colData of fetchAnalyses. Values are as in the
database. Lists, e.g., the publications of a study
(study_publications), are JSON text that can be read with
jsonlite::fromJSON().
In MGnify, a study has samples, a sample has runs, i.e., sequencings of
the sample, and an analysis is a run or an assembly processed with an
MGnify pipeline. A sample can have multiple runs, e.g., an amplicon and a
metagenome, and a run can be analysed with multiple pipeline versions, so
a sample can have multiple analyses. An analysis usually has one run, but
some have multiple runs, e.g., "ERR1, ERR2", and analyses of
assemblies can have no run in run_accession.
Results are cached for the R session; to keep them between sessions, set
options(MGnifyR.cache = "path/to/cache"). To access private data,
log in first with mgnifyLogin.
A data.frame where each row is a study, sample or analysis.
# Search studies of aquatic environments studies <- searchStudies(biome = "root:Environmental:Aquatic", max.hits = 10) # Get samples and analyses of a study samples <- searchSamples("MGYS00005116") analyses <- searchAnalyses("MGYS00005116") analyses <- analyses[analyses[["pipeline_version"]] == "V6", ]# Search studies of aquatic environments studies <- searchStudies(biome = "root:Environmental:Aquatic", max.hits = 10) # Get samples and analyses of a study samples <- searchSamples("MGYS00005116") analyses <- searchAnalyses("MGYS00005116") analyses <- analyses[analyses[["pipeline_version"]] == "V6", ]