Collecting more metadata#

In MGni.py there are helpers for collecting metdata from MGnify or BioSamples for a list of MGnify accessions.

On this page we will learn how to:

  • Collect metadata from MGnify using mgnipy.collect.MGnetizer

  • Collect metadata from BioSamples using mgnipy.collect.BioSampler

This is especially useful if you already know the list of MGnify items that you would like the detailed metadata for such as a list of study accessions. Additionally, when you already have a MGnify dataset of samples and would like to get more metadata starting from the Run accessions which we will demonstrate below.


# uncomment below if colab
#!pip install mgnipy

We’ll pick up from the previous page where we had downloaded the “ERP014435_GO-slim_abundances_v3.0.tsv” dataset from MGnify.

import pandas as pd

# read in GO-slim abundances file
df_go = pd.read_csv("downloads/ERP014435_GO-slim_abundances_v3.0.tsv", sep="\t")

# get run accessions as a list
run_ids = df_go.columns[3:].to_list()

# sanity check
df_go.head()

Hide code cell output

GO description category ERR1299314 ERR1299315 ERR1299316 ERR1299317 ERR1299319 ERR1299320 ERR1299321 ERR1299323 ERR1299324 ERR1299325 ERR1299326 ERR1299330 ERR1299331 ERR1299333
0 GO:0000015 phosphopyruvate hydratase complex cellular component 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 GO:0000150 recombinase activity molecular function 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2 GO:0000160 phosphorelay signal transduction system biological process 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 GO:0000166 nucleotide binding molecular function 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 GO:0003674 molecular function molecular function 0 0 0 0 0 0 0 0 0 0 0 0 0 0

The MGnetizer#

The run accessions/ids can be passed to a MGnetizer to collect their detailed metadata. MGnetizer’s are a lot like MGnifiers:

  • they can be accessed as attributes from MGnipy client, inheriting the configuration

  • they build the set of queries lazily which you can explore via .explain() before executing them

from mgnipy import MGnipy

# init client
MG = MGnipy(cache_dir=None)

# init mgnetizer
mnet = MG.mgnetizer(resource="run", all_ids=run_ids)

# check out query set
mnet.explain()

Hide code cell output

https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299314
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299315
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299316
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299317
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299319
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299320
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299321
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299323
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299324
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299325
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299326
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299330
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299331
https://www.ebi.ac.uk/metagenomics/api/v2/runs/ERR1299333

now actually executing the above with .enrich() or .aenrich()

with mnet:
    mnet.enrich()

again we can access the metadata via .metadata

# as df
run_md = mnet.metadata.to_pandas(expand_nested_dicts=False)
# check it out
run_md.head()

Hide code cell output

experiment_type instrument_model instrument_platform sample study accession sample_accession study_accession
0 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA {'accession': 'SAMEA3886583', 'ena_accessions'... {'accession': 'MGYS00001374', 'ena_accessions'... ERR1299314 SAMEA3886583 MGYS00001374
1 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA {'accession': 'SAMEA3886584', 'ena_accessions'... {'accession': 'MGYS00001374', 'ena_accessions'... ERR1299315 SAMEA3886584 MGYS00001374
2 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA {'accession': 'SAMEA3886585', 'ena_accessions'... {'accession': 'MGYS00001374', 'ena_accessions'... ERR1299316 SAMEA3886585 MGYS00001374
3 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA {'accession': 'SAMEA3886586', 'ena_accessions'... {'accession': 'MGYS00001374', 'ena_accessions'... ERR1299317 SAMEA3886586 MGYS00001374
4 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA {'accession': 'SAMEA3886588', 'ena_accessions'... {'accession': 'MGYS00001374', 'ena_accessions'... ERR1299319 SAMEA3886588 MGYS00001374

The BioSampler#

The above sample accessions can be passed to a BioSampler to collect even more metadata from the BioSamples database.

BioSamplers can also be accessed from the MGnipy instance, inheriting config.

bios = MG.biosampler(sample_ids=run_md["sample_accession"].to_list())
print(bios)
BioSampler with 14 sample_ids. 
Progress: 0 ids. 
Cache directory: None

Note: if wanting to pass runs accessions above instead (e.g., MG.biosampler(sample_ids=run_ids)) then .enrich(incl_ena=True)

now that we have built the queries we can execute them

with bios:
    bios.enrich()
bios.metadata.to_pandas(expand_nested_dicts=False).head()

Hide code cell output

GivenID SampleID RunID SRA accession name taxid ENA-CHECKLIST ENA-FIRST-PUBLIC ENA-LAST-UPDATE External Id ... geographic location (latitude) geographic location (longitude) investigation type organism project name scientific_name sequencing method soil environmental package title description
0 SAMEA3886583 SAMEA3886583 None ERS1073717 I9 256318 ERC000022 2016-03-06T17:05:13Z 2016-10-21T09:34:22Z SAMEA3886583 ... 62.182784 50.550976 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch NaN
1 SAMEA3886584 SAMEA3886584 None ERS1073718 I10 256318 ERC000022 2016-03-06T17:05:13Z 2016-10-21T09:34:22Z SAMEA3886584 ... 62.182784 50.550976 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample
2 SAMEA3886585 SAMEA3886585 None ERS1073719 I7 256318 ERC000022 2016-03-06T17:05:13Z 2016-10-21T09:34:22Z SAMEA3886585 ... 62.182785 50.550977 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch NaN
3 SAMEA3886586 SAMEA3886586 None ERS1073720 I8 256318 ERC000022 2016-03-06T17:05:13Z 2016-10-21T09:34:22Z SAMEA3886586 ... 62.182785 50.550977 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample
4 SAMEA3886588 SAMEA3886588 None ERS1073722 I12 256318 ERC000022 2016-03-06T17:05:13Z 2016-10-21T09:34:22Z SAMEA3886588 ... 62.152829 50.392303 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample

5 rows × 32 columns

From here of course you can take over to merge the sets of MGnify metadata and Biosamples metadata.

However mgnipy has a helper class that combines a MGnify dataset with its metadata:


MTG MGic (the) Gatherer#

The MGic gatherer (MTG) takes a dataset as pandas or polars dataframe and MGnify or BioSamples metadata and combines them into a single object.

MTG can be used to enrich the dataset with metadata, and to convert the dataset into different formats such as pandas, polars, or anndata.

MTG = MG.mtg(
    dataset=df_go,
    var_cols=["description", "category"],
    var_index="GO",
    obs_index="name_of_your_chosing",
    # mgnify_runs=mnet.metadata.to_list() #can pass here or assign the sets later
)

# can assign the sets at any time after init
MTG.mgnify_runs = mnet.metadata.to_list()
MTG.biosamples_metadata = bios.metadata.to_list()

# info
print(MTG)
MTG containing:
- Dataset type: <class 'pandas.core.frame.DataFrame'>
- var_cols: ['description', 'category']
- var_index: 'GO'
- obs_index: 'name_of_your_chosing'
- Nonempty metadata sets: .mgnify_runs, .biosamples_metadata

Example 1. to polars#

# the original but as a polars df
# MTG.to_polars()

# the feature matrix
# MTG.X(df_engine="polars") # default is pandas

# the features metadata
# MTG.var_metadata(df_engine="polars")

# the obs (samples) metadata
MTG.obs_metadata(df_engine="polars")

Hide code cell output

shape: (14, 48)
name_of_your_chosingexperiment_typeinstrument_modelinstrument_platformsample_accessionstudy_accessionsample__accessionsample__ena_accessionssample__sample_titlesample__biomesample__updated_atstudy__accessionstudy__ena_accessionsstudy__titlestudy__updated_atstudy__biome.biome_namestudy__biome.lineageGivenIDRunIDSRA accessionnametaxidENA-CHECKLISTENA-FIRST-PUBLICENA-LAST-UPDATEExternal IdINSDC center nameINSDC first publicINSDC last updateINSDC statusSubmitter Idcollection datedepthenvironment (biome)environment (feature)environment (material)geographic location (country and/or sea)geographic location (elevation)geographic location (latitude)geographic location (longitude)investigation typeorganismproject namescientific_namesequencing methodsoil environmental packagetitledescription
strstrstrstrstrstrstrlist[str]strstrstrstrlist[str]strstrstrstrstrstrstrstri64strstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstr
"ERR1299314""Metatranscriptomic""Illumina HiSeq 2000""ILLUMINA""SAMEA3886583""MGYS00001374""SAMEA3886583"["ERS1073717", "SAMEA3886583"]"Birch"null"2026-04-28T04:56:14.026000+00:…"MGYS00001374"["ERP014435", "PRJEB12905"]"Ectomycorrhizal and fine root …"2026-05-28T15:46:51.301000+00:…"Forest soil""root:Host-associated:Plants:Rh…"SAMEA3886583"null"ERS1073717""I9"256318"ERC000022""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""SAMEA3886583""UNIVERSITY OF TARTU""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""public""I9""2009""0.2""forest""birch stand""soil""Russia""130""62.182784""50.550976""metagenome""metagenome""PRJEB12905""metagenome""Illumina 2000""soil""Birch"null
"ERR1299315""Metatranscriptomic""Illumina HiSeq 2000""ILLUMINA""SAMEA3886584""MGYS00001374""SAMEA3886584"["SAMEA3886584", "ERS1073718"]"Birch"null"2026-04-28T04:56:11.949000+00:…"MGYS00001374"["ERP014435", "PRJEB12905"]"Ectomycorrhizal and fine root …"2026-05-28T15:46:51.301000+00:…"Forest soil""root:Host-associated:Plants:Rh…"SAMEA3886584"null"ERS1073718""I10"256318"ERC000022""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""SAMEA3886584""UNIVERSITY OF TARTU""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""public""I10""2009""0.2""forest""birch stand""soil""Russia""130""62.182784""50.550976""metagenome""metagenome""PRJEB12905""metagenome""Illumina 2000""soil""Birch""Rhizosphere sample"
"ERR1299316""Metatranscriptomic""Illumina HiSeq 2000""ILLUMINA""SAMEA3886585""MGYS00001374""SAMEA3886585"["ERS1073719", "SAMEA3886585"]"Birch"null"2026-04-28T04:56:13.206000+00:…"MGYS00001374"["ERP014435", "PRJEB12905"]"Ectomycorrhizal and fine root …"2026-05-28T15:46:51.301000+00:…"Forest soil""root:Host-associated:Plants:Rh…"SAMEA3886585"null"ERS1073719""I7"256318"ERC000022""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""SAMEA3886585""UNIVERSITY OF TARTU""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""public""I7""2009""0.2""forest""birch stand""soil""Russia""130""62.182785""50.550977""metagenome""metagenome""PRJEB12905""metagenome""Illumina 2000""soil""Birch"null
"ERR1299317""Metatranscriptomic""Illumina HiSeq 2000""ILLUMINA""SAMEA3886586""MGYS00001374""SAMEA3886586"["SAMEA3886586", "ERS1073720"]"Birch"null"2026-04-28T04:56:17.200000+00:…"MGYS00001374"["ERP014435", "PRJEB12905"]"Ectomycorrhizal and fine root …"2026-05-28T15:46:51.301000+00:…"Forest soil""root:Host-associated:Plants:Rh…"SAMEA3886586"null"ERS1073720""I8"256318"ERC000022""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""SAMEA3886586""UNIVERSITY OF TARTU""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""public""I8""2009""0.2""forest""birch stand""soil""Russia""130""62.182785""50.550977""metagenome""metagenome""PRJEB12905""metagenome""Illumina 2000""soil""Birch""Rhizosphere sample"
"ERR1299319""Metatranscriptomic""Illumina HiSeq 2000""ILLUMINA""SAMEA3886588""MGYS00001374""SAMEA3886588"["ERS1073722", "SAMEA3886588"]"Birch"null"2026-04-28T04:56:14.818000+00:…"MGYS00001374"["ERP014435", "PRJEB12905"]"Ectomycorrhizal and fine root …"2026-05-28T15:46:51.301000+00:…"Forest soil""root:Host-associated:Plants:Rh…"SAMEA3886588"null"ERS1073722""I12"256318"ERC000022""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""SAMEA3886588""UNIVERSITY OF TARTU""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""public""I12""2009""0.2""forest""birch stand""soil""Russia""130""62.152829""50.392303""metagenome""metagenome""PRJEB12905""metagenome""Illumina 2000""soil""Birch""Rhizosphere sample"
"ERR1299325""Metatranscriptomic""Illumina HiSeq 2000""ILLUMINA""SAMEA3886594""MGYS00001374""SAMEA3886594"["ERS1073728", "SAMEA3886594"]"Birch"null"2026-04-28T04:56:11.534000+00:…"MGYS00001374"["ERP014435", "PRJEB12905"]"Ectomycorrhizal and fine root …"2026-05-28T15:46:51.301000+00:…"Forest soil""root:Host-associated:Plants:Rh…"SAMEA3886594"null"ERS1073728""I28"256318"ERC000022""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""SAMEA3886594""UNIVERSITY OF TARTU""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""public""I28""2009""0.2""forest""birch stand""soil""Finland""8""61.1359""21.283455""metagenome""metagenome""PRJEB12905""metagenome""Illumina 2000""soil""Birch""Rhizosphere sample"
"ERR1299326""Metatranscriptomic""Illumina HiSeq 2000""ILLUMINA""SAMEA3886595""MGYS00001374""SAMEA3886595"["ERS1073729", "SAMEA3886595"]"Birch"null"2026-04-28T04:56:16.798000+00:…"MGYS00001374"["ERP014435", "PRJEB12905"]"Ectomycorrhizal and fine root …"2026-05-28T15:46:51.301000+00:…"Forest soil""root:Host-associated:Plants:Rh…"SAMEA3886595"null"ERS1073729""I17"256318"ERC000022""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""SAMEA3886595""UNIVERSITY OF TARTU""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""public""I17""2009""0.2""forest""birch stand""soil""Estonia""50""58.3342912""27.0532964""metagenome""metagenome""PRJEB12905""metagenome""Illumina 2000""soil""Birch"null
"ERR1299330""Metatranscriptomic""Illumina HiSeq 2000""ILLUMINA""SAMEA3886599""MGYS00001374""SAMEA3886599"["SAMEA3886599", "ERS1073733"]"Birch"null"2026-04-28T04:56:11.119000+00:…"MGYS00001374"["ERP014435", "PRJEB12905"]"Ectomycorrhizal and fine root …"2026-05-28T15:46:51.301000+00:…"Forest soil""root:Host-associated:Plants:Rh…"SAMEA3886599"null"ERS1073733""I19"256318"ERC000022""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""SAMEA3886599""UNIVERSITY OF TARTU""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""public""I19""2009""0.2""forest""birch stand""soil""Estonia""87""57.582051""26.560674""metagenome""metagenome""PRJEB12905""metagenome""Illumina 2000""soil""Birch"null
"ERR1299331""Metatranscriptomic""Illumina HiSeq 2000""ILLUMINA""SAMEA3886600""MGYS00001374""SAMEA3886600"["ERS1073734", "SAMEA3886600"]"Birch"null"2026-04-28T04:56:15.213000+00:…"MGYS00001374"["ERP014435", "PRJEB12905"]"Ectomycorrhizal and fine root …"2026-05-28T15:46:51.301000+00:…"Forest soil""root:Host-associated:Plants:Rh…"SAMEA3886600"null"ERS1073734""I20"256318"ERC000022""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""SAMEA3886600""UNIVERSITY OF TARTU""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""public""I20""2009""0.2""forest""birch stand""soil""Estonia""87""57.582051""26.560674""metagenome""metagenome""PRJEB12905""metagenome""Illumina 2000""soil""Birch""Rhizosphere sample"
"ERR1299333""Metatranscriptomic""Illumina HiSeq 2000""ILLUMINA""SAMEA3886602""MGYS00001374""SAMEA3886602"["SAMEA3886602", "ERS1073736"]"Birch"null"2026-04-28T04:56:12.370000+00:…"MGYS00001374"["ERP014435", "PRJEB12905"]"Ectomycorrhizal and fine root …"2026-05-28T15:46:51.301000+00:…"Forest soil""root:Host-associated:Plants:Rh…"SAMEA3886602"null"ERS1073736""I6"256318"ERC000022""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""SAMEA3886602""UNIVERSITY OF TARTU""2016-03-06T17:05:13Z""2016-10-21T09:34:22Z""public""I6""2009""0.2""forest""birch stand""soil""United Kingdom""22""53.252619""-2.301752""metagenome""metagenome""PRJEB12905""metagenome""Illumina 2000""soil""Birch""Rhizosphere sample"

Example 2. to anndata#

as an annotated dataframe which keeps data matrices aligned with the corresponding metadata – even when transforming the data so that there are added matrix layers.

# to anndata object
an_df = MTG.to_anndata()

# the feature matrix
# an_df.to_df() # or an_df.X

# the features metadata
# an_df.var

# the obs (samples) metadata
an_df.obs

Hide code cell output

experiment_type instrument_model instrument_platform sample_accession study_accession sample__accession sample__ena_accessions sample__sample_title sample__biome sample__updated_at ... geographic location (latitude) geographic location (longitude) investigation type organism project name scientific_name sequencing method soil environmental package title description
name_of_your_chosing
ERR1299314 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886583 MGYS00001374 SAMEA3886583 [ERS1073717, SAMEA3886583] Birch None 2026-04-28T04:56:14.026000+00:00 ... 62.182784 50.550976 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch None
ERR1299315 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886584 MGYS00001374 SAMEA3886584 [SAMEA3886584, ERS1073718] Birch None 2026-04-28T04:56:11.949000+00:00 ... 62.182784 50.550976 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample
ERR1299316 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886585 MGYS00001374 SAMEA3886585 [ERS1073719, SAMEA3886585] Birch None 2026-04-28T04:56:13.206000+00:00 ... 62.182785 50.550977 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch None
ERR1299317 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886586 MGYS00001374 SAMEA3886586 [SAMEA3886586, ERS1073720] Birch None 2026-04-28T04:56:17.200000+00:00 ... 62.182785 50.550977 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample
ERR1299319 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886588 MGYS00001374 SAMEA3886588 [ERS1073722, SAMEA3886588] Birch None 2026-04-28T04:56:14.818000+00:00 ... 62.152829 50.392303 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample
ERR1299320 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886589 MGYS00001374 SAMEA3886589 [ERS1073723, SAMEA3886589] Birch None 2026-04-28T04:56:16.012000+00:00 ... 66.2 26.4 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch None
ERR1299321 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886590 MGYS00001374 SAMEA3886590 [ERS1073724, SAMEA3886590] Birch None 2026-04-28T04:56:09.828000+00:00 ... 66.2 26.4 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample
ERR1299323 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886592 MGYS00001374 SAMEA3886592 [SAMEA3886592, ERS1073726] Birch None 2026-04-28T04:56:14.425000+00:00 ... 61.49 29.19 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample
ERR1299324 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886593 MGYS00001374 SAMEA3886593 [ERS1073727, SAMEA3886593] Birch None 2026-04-28T04:56:15.602000+00:00 ... 61.1359 21.283455 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch None
ERR1299325 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886594 MGYS00001374 SAMEA3886594 [ERS1073728, SAMEA3886594] Birch None 2026-04-28T04:56:11.534000+00:00 ... 61.1359 21.283455 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample
ERR1299326 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886595 MGYS00001374 SAMEA3886595 [ERS1073729, SAMEA3886595] Birch None 2026-04-28T04:56:16.798000+00:00 ... 58.3342912 27.0532964 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch None
ERR1299330 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886599 MGYS00001374 SAMEA3886599 [SAMEA3886599, ERS1073733] Birch None 2026-04-28T04:56:11.119000+00:00 ... 57.582051 26.560674 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch None
ERR1299331 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886600 MGYS00001374 SAMEA3886600 [ERS1073734, SAMEA3886600] Birch None 2026-04-28T04:56:15.213000+00:00 ... 57.582051 26.560674 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample
ERR1299333 Metatranscriptomic Illumina HiSeq 2000 ILLUMINA SAMEA3886602 MGYS00001374 SAMEA3886602 [SAMEA3886602, ERS1073736] Birch None 2026-04-28T04:56:12.370000+00:00 ... 53.252619 -2.301752 metagenome metagenome PRJEB12905 metagenome Illumina 2000 soil Birch Rhizosphere sample

14 rows × 47 columns

# exporting to h5ad file
fname = "example_collectors.h5ad"
an_df.obs = an_df.obs.astype(
    str
)  # workaround for h5ad export issue with mixed types in obs
an_df.write_h5ad(fname)
import anndata as ad

# read in data
back = ad.read_h5ad(fname)
# check it out
back
AnnData object with n_obs × n_vars = 14 × 116
    obs: 'experiment_type', 'instrument_model', 'instrument_platform', 'sample_accession', 'study_accession', 'sample__accession', 'sample__ena_accessions', 'sample__sample_title', 'sample__biome', 'sample__updated_at', 'study__accession', 'study__ena_accessions', 'study__title', 'study__updated_at', 'study__biome.biome_name', 'study__biome.lineage', 'GivenID', 'RunID', 'SRA accession', 'name', 'taxid', 'ENA-CHECKLIST', 'ENA-FIRST-PUBLIC', 'ENA-LAST-UPDATE', 'External Id', 'INSDC center name', 'INSDC first public', 'INSDC last update', 'INSDC status', 'Submitter Id', 'collection date', 'depth', 'environment (biome)', 'environment (feature)', 'environment (material)', 'geographic location (country and/or sea)', 'geographic location (elevation)', 'geographic location (latitude)', 'geographic location (longitude)', 'investigation type', 'organism', 'project name', 'scientific_name', 'sequencing method', 'soil environmental package', 'title', 'description'
    var: 'description', 'category'

Wrap Up:#

We started with only a MGnify dataset that included a list of run accessions.

This page was a quick start demonstration of:

  1. ✅ Using MGnetizers to collect metadata from MGnify

  2. ✅ Collecting even more metadata from BioSamples with BioSampler

  3. ✅ Merging the dataset with the rich metadata using MTG