Getting MGnify datasets#

The MGnify API provides access to MGnify analyses datasets and important metadata such as biome, sample, study, run, analysis details.


# uncomment below if colab
#!pip install mgnipy

🎯 The Goal: Retrieve taxonomic datasets of tomato rhizosphere studies#

Let’s request tomato rhizosphere datasets and metadata from MGnify API.

Recall the typical workflow (from What is MGni.Py? ):

  1. Start up a mgnipy.MGnipy client with your desired configuration

  2. Search in MGnify resources using a MGnifier glass

  3. Receive a MGazine of MGnify datasets

which we will follow in this notebook

from mgnipy import MGnipy

# 1. init with default config
MG = MGnipy(
    cache_dir="downloads"
)

# 2.a) setup studies mgnifier (build queries)
tomato_studies = MG.studies(
    biome_lineage="root:Host-associated:Plants:Rhizosphere", search="tomato"
)
with MG: 
    # 2.b) execute the list query (get the study list)
    tomato_studies.get_all()

    # 2.c) get the study list (execute all detail queries)
    tomato_studies.enrich_details()

# take a look at the studies details results as a pandas df
tomato_studies.metadata.to_pandas(expand_nested_dicts=True)

Hide code cell output

accession ena_accessions title updated_at downloads first_accession biome__biome_name biome__lineage
0 MGYS00010296 [ERP166137, PRJEB82448] Microbiome-mediated tolerance of wild tomato t... 2026-05-28T15:46:48.615000+00:00 [] ERP166137 Rhizosphere root:Host-associated:Plants:Rhizosphere
1 MGYS00010297 [SRP333165, PRJNA755742] Tomato rhizosphere microbiome in the pot exper... 2026-05-28T15:46:48.649000+00:00 [] SRP333165 Rhizosphere root:Host-associated:Plants:Rhizosphere
2 MGYS00006231 [ERP139927, PRJEB55060] EMG produced TPA metagenomics assembly of PRJN... 2026-05-28T15:46:58.486000+00:00 [{'file_type': 'tsv', 'download_type': 'Taxono... ERP139927 Rhizosphere root:Host-associated:Plants:Rhizosphere
3 MGYS00006204 [ERP140102, PRJEB55219] EMG produced TPA metagenomics assembly of PRJN... 2026-05-28T15:47:01.715000+00:00 [{'file_type': 'tsv', 'download_type': 'Taxono... ERP140102 Rhizosphere root:Host-associated:Plants:Rhizosphere
4 MGYS00006205 [ERP140107, PRJEB55224] EMG produced TPA metagenomics assembly of PRJN... 2026-05-28T15:47:01.734000+00:00 [{'file_type': 'tsv', 'download_type': 'Taxono... ERP140107 Rhizosphere root:Host-associated:Plants:Rhizosphere
5 MGYS00006208 [ERP140115, PRJEB55232] EMG produced TPA metagenomics assembly of PRJN... 2026-05-28T15:47:01.747000+00:00 [{'file_type': 'tsv', 'download_type': 'Taxono... ERP140115 Rhizosphere root:Host-associated:Plants:Rhizosphere
6 MGYS00006230 [ERP139923, PRJEB55057] EMG produced TPA metagenomics assembly of PRJN... 2026-05-28T15:47:01.755000+00:00 [{'file_type': 'tsv', 'download_type': 'Taxono... ERP139923 Rhizosphere root:Host-associated:Plants:Rhizosphere
7 MGYS00010257 [SRP456588, PRJNA1004080] Combined effect of microplastics and fungicide... 2026-05-28T15:46:48.538000+00:00 [] SRP456588 Soil root:Host-associated:Plants:Rhizosphere:Soil
8 MGYS00010264 [PRJEB91717] Metagenome assembly of PRJNA1127303 data set (... 2026-05-28T15:46:48.743000+00:00 [] PRJEB91717 Soil root:Host-associated:Plants:Rhizosphere:Soil
9 MGYS00010251 [SRP338795, PRJNA766489] Culture-independent analysis of rhizosphere mi... 2026-05-28T15:46:48.756000+00:00 [] SRP338795 Soil root:Host-associated:Plants:Rhizosphere:Soil
10 MGYS00010245 [PRJEB82447, ERP166136] Unveiling diversity and adaptations of the wil... 2026-05-28T15:46:48.558000+00:00 [] ERP166136 Soil root:Host-associated:Plants:Rhizosphere:Soil
11 MGYS00010324 [PRJEB95772] Metagenome assembly of PRJNA777724 data set (T... 2026-05-28T15:46:48.576000+00:00 [] PRJEB95772 Soil root:Host-associated:Plants:Rhizosphere:Soil
12 MGYS00010258 [SRP517058, PRJNA1127303] Metagenomic data of rhizosphere soil during to... 2026-05-28T15:46:48.578000+00:00 [] SRP517058 Soil root:Host-associated:Plants:Rhizosphere:Soil
13 MGYS00010298 [PRJNA777724, SRP344777] Tomato heritable microbiome 2026-05-28T15:46:48.670000+00:00 [] SRP344777 Soil root:Host-associated:Plants:Rhizosphere:Soil
14 MGYS00010262 [PRJEB91684] Metagenome assembly of PRJNA1004080 data set (... 2026-05-28T15:46:48.688000+00:00 [] PRJEB91684 Soil root:Host-associated:Plants:Rhizosphere:Soil
15 MGYS00010250 [PRJNA755741, SRP333163] Tomato rhizosphere microbiome in the belowgrou... 2026-05-28T15:46:48.730000+00:00 [] SRP333163 Soil root:Host-associated:Plants:Rhizosphere:Soil
16 MGYS00010253 [PRJNA789467, SRP351203] Disentangling the genetic basis of rhizosphere... 2026-05-28T15:46:48.818000+00:00 [] SRP351203 Soil root:Host-associated:Plants:Rhizosphere:Soil

3. Accessing the MGazine of datasets#

  • study details have a mgnipy.MGazine which allow us to download and interact with study-level datasets outputed from MGnify.

  • We can use mgnipy.MGazine to download the datasets onto disk or read them into our notebook.

  • To access the study’s mgazine use .datasets

  • the str representaiton of mgazine gives us a peak into the pipeline versions within, number of downloads and the short_description categories

# access study mgazine
MZ = tomato_studies.datasets

# print for more info
print(MZ)

# also can view more as df
MZ.downloads_df()

Hide code cell output

MGazine containing:
- MGnify pipeline versions: ['v5']
- Number of downloads: 35
- Short descriptions: ['Complete GO annotation',
 'GO slim annotation',
 'InterPro matches',
 'Phylum level taxonomies LSU',
 'Phylum level taxonomies SSU',
 'Taxonomic assignments LSU',
 'Taxonomic assignments SSU']
- Nonempty metadata sets: .mgnify_studies
file_type download_type short_description long_description alias download_group file_size_bytes index_files url accession pipeline_version
0 tsv Taxonomic analysis Phylum level taxonomies SSU Phylum level taxonomies SSU (TSV) ERP139927_phylum_taxonomy_abundances_SSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_ssu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006231 v5
1 tsv Taxonomic analysis Taxonomic assignments SSU Taxonomic assignments SSU (TSV) ERP139927_taxonomy_abundances_SSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_ssu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006231 v5
2 tsv Taxonomic analysis Phylum level taxonomies LSU Phylum level taxonomies LSU (TSV) ERP139927_phylum_taxonomy_abundances_LSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_lsu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006231 v5
3 tsv Taxonomic analysis Taxonomic assignments LSU Taxonomic assignments LSU (TSV) ERP139927_taxonomy_abundances_LSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_lsu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006231 v5
4 tsv Functional analysis InterPro matches InterPro matches (TSV) ERP139927_IPR_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006231 v5
5 tsv Functional analysis GO slim annotation GO slim annotation ERP139927_GO-slim_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006231 v5
6 tsv Functional analysis Complete GO annotation Complete GO annotation ERP139927_GO_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006231 v5
7 tsv Taxonomic analysis Phylum level taxonomies SSU Phylum level taxonomies SSU (TSV) ERP140102_phylum_taxonomy_abundances_SSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_ssu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006204 v5
8 tsv Taxonomic analysis Taxonomic assignments SSU Taxonomic assignments SSU (TSV) ERP140102_taxonomy_abundances_SSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_ssu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006204 v5
9 tsv Taxonomic analysis Phylum level taxonomies LSU Phylum level taxonomies LSU (TSV) ERP140102_phylum_taxonomy_abundances_LSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_lsu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006204 v5
10 tsv Taxonomic analysis Taxonomic assignments LSU Taxonomic assignments LSU (TSV) ERP140102_taxonomy_abundances_LSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_lsu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006204 v5
11 tsv Functional analysis InterPro matches InterPro matches (TSV) ERP140102_IPR_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006204 v5
12 tsv Functional analysis GO slim annotation GO slim annotation ERP140102_GO-slim_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006204 v5
13 tsv Functional analysis Complete GO annotation Complete GO annotation ERP140102_GO_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006204 v5
14 tsv Taxonomic analysis Phylum level taxonomies SSU Phylum level taxonomies SSU (TSV) ERP140107_phylum_taxonomy_abundances_SSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_ssu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006205 v5
15 tsv Taxonomic analysis Taxonomic assignments SSU Taxonomic assignments SSU (TSV) ERP140107_taxonomy_abundances_SSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_ssu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006205 v5
16 tsv Taxonomic analysis Phylum level taxonomies LSU Phylum level taxonomies LSU (TSV) ERP140107_phylum_taxonomy_abundances_LSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_lsu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006205 v5
17 tsv Taxonomic analysis Taxonomic assignments LSU Taxonomic assignments LSU (TSV) ERP140107_taxonomy_abundances_LSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_lsu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006205 v5
18 tsv Functional analysis InterPro matches InterPro matches (TSV) ERP140107_IPR_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006205 v5
19 tsv Functional analysis GO slim annotation GO slim annotation ERP140107_GO-slim_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006205 v5
20 tsv Functional analysis Complete GO annotation Complete GO annotation ERP140107_GO_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006205 v5
21 tsv Taxonomic analysis Phylum level taxonomies SSU Phylum level taxonomies SSU (TSV) ERP140115_phylum_taxonomy_abundances_SSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_ssu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006208 v5
22 tsv Taxonomic analysis Taxonomic assignments SSU Taxonomic assignments SSU (TSV) ERP140115_taxonomy_abundances_SSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_ssu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006208 v5
23 tsv Taxonomic analysis Phylum level taxonomies LSU Phylum level taxonomies LSU (TSV) ERP140115_phylum_taxonomy_abundances_LSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_lsu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006208 v5
24 tsv Taxonomic analysis Taxonomic assignments LSU Taxonomic assignments LSU (TSV) ERP140115_taxonomy_abundances_LSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_lsu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006208 v5
25 tsv Functional analysis InterPro matches InterPro matches (TSV) ERP140115_IPR_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006208 v5
26 tsv Functional analysis GO slim annotation GO slim annotation ERP140115_GO-slim_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006208 v5
27 tsv Functional analysis Complete GO annotation Complete GO annotation ERP140115_GO_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006208 v5
28 tsv Taxonomic analysis Phylum level taxonomies SSU Phylum level taxonomies SSU (TSV) ERP139923_phylum_taxonomy_abundances_SSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_ssu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006230 v5
29 tsv Taxonomic analysis Taxonomic assignments SSU Taxonomic assignments SSU (TSV) ERP139923_taxonomy_abundances_SSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_ssu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006230 v5
30 tsv Taxonomic analysis Phylum level taxonomies LSU Phylum level taxonomies LSU (TSV) ERP139923_phylum_taxonomy_abundances_LSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_lsu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006230 v5
31 tsv Taxonomic analysis Taxonomic assignments LSU Taxonomic assignments LSU (TSV) ERP139923_taxonomy_abundances_LSU_v5.0.tsv study_summary.v5.0.taxonomic_analysis_lsu_rrna None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006230 v5
32 tsv Functional analysis InterPro matches InterPro matches (TSV) ERP139923_IPR_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006230 v5
33 tsv Functional analysis GO slim annotation GO slim annotation ERP139923_GO-slim_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006230 v5
34 tsv Functional analysis Complete GO annotation Complete GO annotation ERP139923_GO_abundances_v5.0.tsv study_summary.v5.0.functional_analysis None None https://ftp.ebi.ac.uk/pub/databases/metagenomi... MGYS00006230 v5

You can read in whole or stream in chunks a dataset by passing its alias or url to MGazine.stream()

MZ.stream(
    alias = MZ.aliases[5],
    chunksize=None, # default to read in all, set int for chunked reading
).head()
GO description category ERZ12343720 ERZ12343730 ERZ12343740 ERZ12343750 ERZ12343760 ERZ12343770 ERZ12343780 ... ERZ12590947 ERZ12593067 ERZ12590878 ERZ12590908 ERZ12590968 ERZ12590988 ERZ12590849 ERZ12590879 ERZ12590889 ERZ12590909
0 GO:0000015 phosphopyruvate hydratase complex cellular component 106 77 69 106 96 88 102 ... 107 103 57 84 70 76 97 79 148 94
1 GO:0000150 recombinase activity molecular function 152 111 112 126 137 154 178 ... 146 165 97 117 123 136 167 123 283 135
2 GO:0000160 phosphorelay signal transduction system biological process 5337 4117 4340 5774 5273 5160 5794 ... 5912 5731 2975 4728 4834 4776 5820 4669 8623 5539
3 GO:0000166 nucleotide binding molecular function 27506 23975 22572 28502 28606 25597 30817 ... 28526 31371 16457 25486 26749 23192 28760 24531 43168 29333
4 GO:0003674 molecular function molecular function 3919 3307 3217 4040 3915 3621 4337 ... 4138 4391 2305 3594 3695 3329 4124 3479 6271 4144

5 rows × 117 columns

You can filter by short descriptioins by passing them as you would an index into square brackets i..e, getitem

ssu = MZ['Taxonomic assignments SSU']
print(ssu)

# now with additional taxonomic helpers
tax = ssu.taxonomic
MGazine containing:
- MGnify pipeline versions: ['v5']
- Number of downloads: 5
- Short descriptions: ['Taxonomic assignments SSU']
- Nonempty metadata sets: .mgnify_studies

TaxaMGazine containing:
- MGnify pipeline versions: ['v5']
- Number of downloads: 5
- Short descriptions: ['Taxonomic assignments SSU']
- Nonempty metadata sets: .mgnify_studies
-----------------------
Next steps: Use `.load()` to initialize.

The MGazine informtion page also delves into how to download as well as other options for reading in the files

We will carry on with our filtered TaxaMGazine given our goal for now.

for example, we can also combine the taxonomic assignment results into one dataframe e.g. .to_pandas(), .to_polars, .X()

# first loading
tax.load()

# accessing the 5 datasets in one df
tax.to_polars().head()

Hide code cell output

shape: (5, 150)
taxonomyERZ12343720ERZ12343730ERZ12343740ERZ12343750ERZ12343760ERZ12343770ERZ12343780ERZ12343721ERZ12343731ERZ12343741ERZ12343751ERZ12343761ERZ12343771ERZ12343781ERZ12343712ERZ12343722ERZ12343732ERZ12343742ERZ12343752ERZ12343762ERZ12343772ERZ12343782ERZ12343713ERZ12343723ERZ12343733ERZ12343743ERZ12343753ERZ12343763ERZ12343773ERZ12343783ERZ12343714ERZ12343724ERZ12343734ERZ12343744ERZ12343754ERZ12343764ERZ12590889ERZ12590909ERZ12633490ERZ12633491ERZ12633492ERZ12633493ERZ12633494ERZ12633495ERZ12633496ERZ12633497ERZ12633488ERZ12633498ERZ12633489ERZ12633499ERZ12633510ERZ12633501ERZ12633502ERZ12633503ERZ12633504ERZ12633505ERZ12633506ERZ12633507ERZ12633517ERZ12633508ERZ12633518ERZ12633509ERZ12633580ERZ12633581ERZ12633572ERZ12633582ERZ12633573ERZ12633574ERZ12633594ERZ12633576ERZ12633579ERZ12590661ERZ12590669
stri64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64i64
"sk__Archaea"00000000000000000000000000000000000010010000001000302301200301nullnullnullnullnullnullnullnullnull02
"sk__Archaea;k__;p__Crenarchaeo…00000000000000000000000000000000000000nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
"sk__Archaea;k__;p__Crenarchaeo…00000000000000000000000000000000000000nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
"sk__Archaea;k__;p__Thaumarchae…00000000000000000000000000000000000000nullnullnullnullnullnullnullnullnullnullnullnull100000000000nullnullnullnullnullnullnullnullnullnullnull
"sk__Archaea;k__;p__Thaumarchae…0100000111011100101120021101011100110123412132221222412432532311111111233
# also as an annotated dataframe (AnnData)
tax.to_anndata()
AnnData object with n_obs × n_vars = 149 × 558
    var: 'Superkingdom', 'Kingdom', 'Phylum', 'Class', 'Order', 'Family', 'Genus', 'Species'

We can see that only the var or features (taxonomy) are annotated. The obs or observations (runs/samples) are not yet annotated because we did not collect their metadata.

From here we could use a MGnetizer to collect all the detailed metadata for the .runs_accession in our MGazine. See the following notebooks for more information

# tidying up cache
MG.clear_subcaches()

Wrap Up:#

This page was a quick start demonstration of:

  1. ✅ Start up a mgnipy.MGnipy client with your desired configuration

  2. ✅ Search in MGnify resources using a MGnifier glass

  3. ✅ Receive a MGazine of MGnify datasets