MGnify API in Python

Find a study, explore its analyses, and read a result table.

Edit and run the cells below, in order. The first visit may take a minute to load. Copy any code you want to keep before leaving or reloading the page.

Set up

The study accession comes from the box above.

Get a study

A study groups related samples and analyses. Retrieve its title and biome:

List its analyses

List responses contain items and a total count. Fetch the first 20 analyses; change page=1 to page=2 to get the next page.

Inspect an analysis

Choose the first analysis, or replace ANALYSIS with another accession from the list. Its detail record includes the available result files.

Read a result table

For this analysis, load the Pfam domain-count summary into pandas. Other analyses may have different files; use the descriptions above to choose a result.

The download is a gzip-compressed TSV. compression="gzip" decompresses it before pandas reads the columns. Choose small summaries when working in your browser.

Explore the counts

Show the ten most frequent Pfam domains. Try changing 10 to 20.

Running this code in your own environment

Install the packages from a terminal:

python -m pip install pandas requests

Copy the Python cells into a notebook or script, replacing STUDY = study_accession with STUDY = "MGYS00010393" (or your chosen accession).