{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6ce71bbc",
   "metadata": {},
   "source": [
    "# Getting started — Infant Gut Shotgun-Metagenome Catalog (v1.2.1)\n",
    "Load the wide table, define the catalog scope on `age_scope`, filter by confidence and route, look at Sandpiper taxonomy columns, join runs, and plot coverage. Files are expected in the same folder as this notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7eeed610",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(154206, 147) (389, 117)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>sample_key</th>\n",
       "      <td>SAMD00002748</td>\n",
       "      <td>SAMD00002749</td>\n",
       "      <td>SAMD00002750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>study_accession</th>\n",
       "      <td>PRJDA72415</td>\n",
       "      <td>PRJDA72415</td>\n",
       "      <td>PRJDA72415</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>secondary_sample</th>\n",
       "      <td>DRS012463</td>\n",
       "      <td>DRS012478</td>\n",
       "      <td>DRS012449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sample_title</th>\n",
       "      <td>TYMC108-feces_Distant</td>\n",
       "      <td>TYMC116-feces_Acute</td>\n",
       "      <td>TYMC101-feces_Distant</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>body_site_class</th>\n",
       "      <td>primary</td>\n",
       "      <td>primary</td>\n",
       "      <td>primary</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>collection_date</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_gold_heldout</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>probiotic_exposure</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>preterm_status</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>gestational_age_weeks</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>delivery_mode</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>feeding_mode</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>antibiotic_exposure</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>age_at_collection_days</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>birth_weight_grams</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>country</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>maternal_antibiotics</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>hmo_supplementation</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>nec_status</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>health_condition</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>multiple_birth</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sibling_in_study</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>geo_subregion</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>timepoint_label</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>subject_id</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>probiotic_exposure__confidence</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>preterm_status__confidence</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>gestational_age_weeks__confidence</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>delivery_mode__confidence</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "                                                       0                    1                      2\n",
       "sample_key                                  SAMD00002748         SAMD00002749           SAMD00002750\n",
       "study_accession                               PRJDA72415           PRJDA72415             PRJDA72415\n",
       "secondary_sample                               DRS012463            DRS012478              DRS012449\n",
       "sample_title                       TYMC108-feces_Distant  TYMC116-feces_Acute  TYMC101-feces_Distant\n",
       "body_site_class                                  primary              primary                primary\n",
       "collection_date                                      NaN                  NaN                    NaN\n",
       "is_gold_heldout                                    False                False                  False\n",
       "probiotic_exposure                                   NaN                  NaN                    NaN\n",
       "preterm_status                                       NaN                  NaN                    NaN\n",
       "gestational_age_weeks                                NaN                  NaN                    NaN\n",
       "delivery_mode                                        NaN                  NaN                    NaN\n",
       "feeding_mode                                         NaN                  NaN                    NaN\n",
       "antibiotic_exposure                                  NaN                  NaN                    NaN\n",
       "age_at_collection_days                               NaN                  NaN                    NaN\n",
       "birth_weight_grams                                   NaN                  NaN                    NaN\n",
       "country                                              NaN                  NaN                    NaN\n",
       "maternal_antibiotics                                 NaN                  NaN                    NaN\n",
       "hmo_supplementation                                  NaN                  NaN                    NaN\n",
       "nec_status                                           NaN                  NaN                    NaN\n",
       "health_condition                                     NaN                  NaN                    NaN\n",
       "multiple_birth                                       NaN                  NaN                    NaN\n",
       "sibling_in_study                                     NaN                  NaN                    NaN\n",
       "geo_subregion                                        NaN                  NaN                    NaN\n",
       "sex                                                  NaN                  NaN                    NaN\n",
       "timepoint_label                                      NaN                  NaN                    NaN\n",
       "subject_id                                           NaN                  NaN                    NaN\n",
       "probiotic_exposure__confidence                       NaN                  NaN                    NaN\n",
       "preterm_status__confidence                           NaN                  NaN                    NaN\n",
       "gestational_age_weeks__confidence                    NaN                  NaN                    NaN\n",
       "delivery_mode__confidence                            NaN                  NaN                    NaN"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd, matplotlib\n",
    "matplotlib.use('Agg')\n",
    "import matplotlib.pyplot as plt\n",
    "wide = pd.read_parquet('sample_metadata_wide.parquet')\n",
    "studies = pd.read_parquet('study_metadata_wide.parquet')\n",
    "print(wide.shape, studies.shape)\n",
    "wide.head(3).T.head(30)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7aad9cfc",
   "metadata": {},
   "source": [
    "## 1. Scope: age-evidenced infant samples\n",
    "`age_scope ∈ {infant_evidenced, study_all_infant}` is the age scope; `catalog_scope` additionally requires a gut/unknown body site (`body_site_class ∈ {primary, unknown}`) and is the headline scope. `adult_flagged` means an over-range age (> 1,100 d, includes children)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "13bc1093",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "age_scope\n",
      "infant_evidenced                 67598\n",
      "age_unknown_no_study_estimate    49556\n",
      "age_unknown_mixed_study          14410\n",
      "adult_flagged                     9559\n",
      "study_all_infant                  7097\n",
      "non_infant_role                   5986\n",
      "74695 age-scope infant samples; 71795 catalog-scope (age ∧ body site)\n",
      "46861 with per-sample age from archive/table evidence\n"
     ]
    }
   ],
   "source": [
    "print(wide.age_scope.value_counts().to_string())\n",
    "age_infant = wide[wide.age_scope.isin(['infant_evidenced', 'study_all_infant'])]\n",
    "infant = wide[wide.catalog_scope]\n",
    "print(len(age_infant), 'age-scope infant samples;', len(infant), 'catalog-scope (age ∧ body site)')\n",
    "aged = infant[infant.age_at_collection_days.notna() & infant['age_at_collection_days__route'].isin(['R1', 'R2'])]\n",
    "print(len(aged), 'with per-sample age from archive/table evidence')\n",
    "fig, ax = plt.subplots(figsize=(6, 3))\n",
    "aged.age_at_collection_days.clip(upper=1100).plot.hist(bins=60, ax=ax); ax.set_xlabel('age at collection (days)')\n",
    "fig.tight_layout(); fig.savefig('getting_started_age_hist.png', dpi=100); plt.close(fig)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b426dca",
   "metadata": {},
   "source": [
    "## 2. A study-level view: which cohorts have delivery mode AND feeding for most samples?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "52e92bf4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>study_accession</th>\n",
       "      <th>study_title</th>\n",
       "      <th>n_sample_rows</th>\n",
       "      <th>n_catalog_scope</th>\n",
       "      <th>cov_age_at_collection_days</th>\n",
       "      <th>cov_delivery_mode</th>\n",
       "      <th>cov_feeding_mode</th>\n",
       "      <th>cohort_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>PRJEB32631</td>\n",
       "      <td>Early_life_microbiota_colonisation</td>\n",
       "      <td>1679</td>\n",
       "      <td>1679</td>\n",
       "      <td>0.998213</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.807624</td>\n",
       "      <td>Shao 2019 UK</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>PRJEB62690</td>\n",
       "      <td>Infant stool, 5-HMO supplemented formula vs. control formula vs. breastfed</td>\n",
       "      <td>1110</td>\n",
       "      <td>1110</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>singleton study PRJEB62690</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>195</th>\n",
       "      <td>PRJNA1404625</td>\n",
       "      <td>Investigating the role of the infant gut microbiome in rotavirus vaccine efficacy</td>\n",
       "      <td>835</td>\n",
       "      <td>835</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.990419</td>\n",
       "      <td>0.928144</td>\n",
       "      <td>singleton study PRJNA1404625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>PRJEB39610</td>\n",
       "      <td>Longitudinal metagenomic analysis of the gut microbiome in preterm infants diagnosed with necrotising enterocolitis and matched controls</td>\n",
       "      <td>644</td>\n",
       "      <td>644</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.972050</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>339</th>\n",
       "      <td>PRJNA807448</td>\n",
       "      <td>The Antibiotics and Immune Responses Study</td>\n",
       "      <td>459</td>\n",
       "      <td>459</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.993464</td>\n",
       "      <td>Ryan 2025 Australia</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>266</th>\n",
       "      <td>PRJNA489090</td>\n",
       "      <td>Human infant gut metagenome, infant shotgun sequencing</td>\n",
       "      <td>429</td>\n",
       "      <td>429</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.927739</td>\n",
       "      <td>singleton study PRJNA489090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>259</th>\n",
       "      <td>PRJNA473126</td>\n",
       "      <td>Infant Diet and Maternal Gestational Weight Gain Influence Functional Maturation of the Infant Gut Microbiome</td>\n",
       "      <td>402</td>\n",
       "      <td>402</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>Baumann-Dudenhoeffer 2018 USA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>PRJNA396794</td>\n",
       "      <td>preterm infant gut metagenomes (NIH Y4 Cohort)</td>\n",
       "      <td>305</td>\n",
       "      <td>305</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.996721</td>\n",
       "      <td>0.993443</td>\n",
       "      <td>NIH Y4 Cohort</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>282</th>\n",
       "      <td>PRJNA549787</td>\n",
       "      <td>South African HIV-exposed, uninfected infant gut microbiomes</td>\n",
       "      <td>165</td>\n",
       "      <td>165</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.993939</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>D'Souza 2020 South Africa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>224</th>\n",
       "      <td>PRJNA294605</td>\n",
       "      <td>Metagenomes from 11 human infant fecal samples hospitalized in the same intensive care unit</td>\n",
       "      <td>158</td>\n",
       "      <td>158</td>\n",
       "      <td>0.892405</td>\n",
       "      <td>0.892405</td>\n",
       "      <td>0.892405</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>PRJEB74322</td>\n",
       "      <td>Spanish mother and infants metagenomes of stool and milk samples</td>\n",
       "      <td>155</td>\n",
       "      <td>155</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>PRJEB97976</td>\n",
       "      <td>Infant gut microbiome maturation during weaning</td>\n",
       "      <td>108</td>\n",
       "      <td>108</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>Milkome</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>161</th>\n",
       "      <td>PRJNA1222487</td>\n",
       "      <td>Gut microbiome signatures and reduced Faecalibacterium and Roseburia in infants with early allergic conditions</td>\n",
       "      <td>95</td>\n",
       "      <td>95</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>Nunez 2026 USA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>PRJNA1055141</td>\n",
       "      <td>Infant stool shallow shotgun sequencing (ANTIBIO)</td>\n",
       "      <td>94</td>\n",
       "      <td>94</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>van Tilburg Bernardes 2026 Canada</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>163</th>\n",
       "      <td>PRJNA1227883</td>\n",
       "      <td>Metagenomes from mother-infant fecal and breastmilk samples of the MAMI cohort Metagenome</td>\n",
       "      <td>112</td>\n",
       "      <td>80</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.962500</td>\n",
       "      <td>0.962500</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "    study_accession                                                                                                                               study_title  n_sample_rows  n_catalog_scope  cov_age_at_collection_days  cov_delivery_mode  cov_feeding_mode                        cohort_name\n",
       "38       PRJEB32631                                                                                                        Early_life_microbiota_colonisation           1679             1679                    0.998213           1.000000          0.807624                       Shao 2019 UK\n",
       "73       PRJEB62690                                                                Infant stool, 5-HMO supplemented formula vs. control formula vs. breastfed           1110             1110                    1.000000           1.000000          1.000000         singleton study PRJEB62690\n",
       "195    PRJNA1404625                                                         Investigating the role of the infant gut microbiome in rotavirus vaccine efficacy            835              835                    1.000000           0.990419          0.928144       singleton study PRJNA1404625\n",
       "44       PRJEB39610  Longitudinal metagenomic analysis of the gut microbiome in preterm infants diagnosed with necrotising enterocolitis and matched controls            644              644                    1.000000           1.000000          0.972050                                NaN\n",
       "339     PRJNA807448                                                                                                The Antibiotics and Immune Responses Study            459              459                    1.000000           1.000000          0.993464                Ryan 2025 Australia\n",
       "266     PRJNA489090                                                                                    Human infant gut metagenome, infant shotgun sequencing            429              429                    1.000000           1.000000          0.927739        singleton study PRJNA489090\n",
       "259     PRJNA473126                             Infant Diet and Maternal Gestational Weight Gain Influence Functional Maturation of the Infant Gut Microbiome            402              402                    1.000000           1.000000          1.000000      Baumann-Dudenhoeffer 2018 USA\n",
       "248     PRJNA396794                                                                                            preterm infant gut metagenomes (NIH Y4 Cohort)            305              305                    1.000000           0.996721          0.993443                      NIH Y4 Cohort\n",
       "282     PRJNA549787                                                                              South African HIV-exposed, uninfected infant gut microbiomes            165              165                    1.000000           0.993939          1.000000          D'Souza 2020 South Africa\n",
       "224     PRJNA294605                                               Metagenomes from 11 human infant fecal samples hospitalized in the same intensive care unit            158              158                    0.892405           0.892405          0.892405                                NaN\n",
       "84       PRJEB74322                                                                          Spanish mother and infants metagenomes of stool and milk samples            155              155                    1.000000           1.000000          1.000000                                NaN\n",
       "104      PRJEB97976                                                                                           Infant gut microbiome maturation during weaning            108              108                    0.000000           1.000000          1.000000                            Milkome\n",
       "161    PRJNA1222487                            Gut microbiome signatures and reduced Faecalibacterium and Roseburia in infants with early allergic conditions             95               95                    1.000000           1.000000          1.000000                     Nunez 2026 USA\n",
       "116    PRJNA1055141                                                                                         Infant stool shallow shotgun sequencing (ANTIBIO)             94               94                    1.000000           1.000000          1.000000  van Tilburg Bernardes 2026 Canada\n",
       "163    PRJNA1227883                                                 Metagenomes from mother-infant fecal and breastmilk samples of the MAMI cohort Metagenome            112               80                    0.000000           0.962500          0.962500                                NaN"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "good = studies[(studies.cov_delivery_mode >= 0.8) & (studies.cov_feeding_mode >= 0.8)][['study_accession', 'study_title', 'n_sample_rows', 'n_catalog_scope', 'cov_age_at_collection_days', 'cov_delivery_mode', 'cov_feeding_mode', 'cohort_name']]\n",
    "good.sort_values('n_catalog_scope', ascending=False).head(15)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6660448a",
   "metadata": {},
   "source": [
    "## 3. Build an analysis slice and export it\n",
    "Example: term, vaginally born, exclusively breastfed infants sampled before 6 months, with confidence ≥ 0.7 on every field used."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9fa16fe1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1181 samples in 16 studies\n"
     ]
    }
   ],
   "source": [
    "sl = infant[(infant.preterm_status == 'term') & (infant.delivery_mode == 'vaginal') & (infant.feeding_mode == 'exclusive_breast') & (infant.age_at_collection_days < 183)]\n",
    "for f in ['preterm_status', 'delivery_mode', 'feeding_mode', 'age_at_collection_days']:\n",
    "    sl = sl[sl[f + '__confidence'] >= 0.7]\n",
    "print(len(sl), 'samples in', sl.study_accession.nunique(), 'studies')\n",
    "sl[['sample_key', 'study_accession', 'run_accessions', 'age_at_collection_days', 'delivery_mode', 'feeding_mode']].to_csv('my_slice.csv', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a524575",
   "metadata": {},
   "source": [
    "## 4. Sandpiper taxonomy (SingleM community profiles, GTDB R232)\n",
    "`sp_profiled` marks samples with a profile; `sp_ra_*` are fractions of prokaryotic coverage (≈ cell proportions). Genus indicators include GTDB alphabetic-suffix genera (e.g. Enterococcus_B = E. faecium). Exclude `sp_low_depth` rows for composition statistics."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c9779a91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "41290 profiled catalog-scope samples with adequate depth in 181 studies\n",
      "median Bifidobacterium RA: 0.093\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sample_key</th>\n",
       "      <th>sp_ra_g_Bifidobacterium</th>\n",
       "      <th>sp_ra_enterobacterales_core</th>\n",
       "      <th>sp_shannon_genus</th>\n",
       "      <th>sandpiper_url</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>18396</th>\n",
       "      <td>SAMEA115454978</td>\n",
       "      <td>0.931955</td>\n",
       "      <td>0.011937</td>\n",
       "      <td>0.365845</td>\n",
       "      <td>https://sandpiper.qut.edu.au/run/ERR12814313</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18397</th>\n",
       "      <td>SAMEA115454979</td>\n",
       "      <td>0.955924</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.240661</td>\n",
       "      <td>https://sandpiper.qut.edu.au/run/ERR12812857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18408</th>\n",
       "      <td>SAMEA115454991</td>\n",
       "      <td>0.943853</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.267136</td>\n",
       "      <td>https://sandpiper.qut.edu.au/run/ERR12814168</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18412</th>\n",
       "      <td>SAMEA115454995</td>\n",
       "      <td>0.040936</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.729486</td>\n",
       "      <td>https://sandpiper.qut.edu.au/run/ERR12812864</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18417</th>\n",
       "      <td>SAMEA115455000</td>\n",
       "      <td>0.746375</td>\n",
       "      <td>0.001359</td>\n",
       "      <td>0.950627</td>\n",
       "      <td>https://sandpiper.qut.edu.au/run/ERR12814353</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "           sample_key  sp_ra_g_Bifidobacterium  sp_ra_enterobacterales_core  sp_shannon_genus                                 sandpiper_url\n",
       "18396  SAMEA115454978                 0.931955                     0.011937          0.365845  https://sandpiper.qut.edu.au/run/ERR12814313\n",
       "18397  SAMEA115454979                 0.955924                     0.000000          0.240661  https://sandpiper.qut.edu.au/run/ERR12812857\n",
       "18408  SAMEA115454991                 0.943853                     0.000000          0.267136  https://sandpiper.qut.edu.au/run/ERR12814168\n",
       "18412  SAMEA115454995                 0.040936                     0.000000          3.729486  https://sandpiper.qut.edu.au/run/ERR12812864\n",
       "18417  SAMEA115455000                 0.746375                     0.001359          0.950627  https://sandpiper.qut.edu.au/run/ERR12814353"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prof = infant[infant.sp_profiled & ~infant.sp_low_depth.fillna(False).astype(bool)]\n",
    "print(len(prof), 'profiled catalog-scope samples with adequate depth in', prof.study_accession.nunique(), 'studies')\n",
    "print('median Bifidobacterium RA:', round(prof.sp_ra_g_Bifidobacterium.median(), 3))\n",
    "fig, ax = plt.subplots(figsize=(6, 3))\n",
    "prof.sp_ra_g_Bifidobacterium.plot.hist(bins=40, ax=ax); ax.set_xlabel('Bifidobacterium relative abundance (fraction of prokaryotic coverage)')\n",
    "fig.tight_layout(); fig.savefig('getting_started_bifido_hist.png', dpi=100); plt.close(fig)\n",
    "sl_prof = sl[sl.sp_profiled]\n",
    "sl_prof[['sample_key', 'sp_ra_g_Bifidobacterium', 'sp_ra_enterobacterales_core', 'sp_shannon_genus', 'sandpiper_url']].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edf59413",
   "metadata": {},
   "source": [
    "## 5. Trace a value back to its evidence"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "515d529c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>field_name</th>\n",
       "      <th>value_normalized</th>\n",
       "      <th>confidence</th>\n",
       "      <th>route</th>\n",
       "      <th>evidence_source</th>\n",
       "      <th>evidence_locator</th>\n",
       "      <th>evidence_quote</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>61731</th>\n",
       "      <td>age_at_collection_days</td>\n",
       "      <td>8</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC11183301/mmc2.xlsx/Tab1!timepoint_months:57</td>\n",
       "      <td>timepoint_months=0.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61732</th>\n",
       "      <td>antibiotic_exposure</td>\n",
       "      <td>no</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC12222458/41467_2025_61154_MOESM8_ESM.xlsx/metadata_infants!AB_BB:112</td>\n",
       "      <td>AB_BB=no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61733</th>\n",
       "      <td>birth_weight_grams</td>\n",
       "      <td>3150</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC11183301/mmc2.xlsx/Tab1!birth_weight (Kg):57</td>\n",
       "      <td>birth_weight (Kg)=3.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61734</th>\n",
       "      <td>country</td>\n",
       "      <td>ES</td>\n",
       "      <td>0.90</td>\n",
       "      <td>R1</td>\n",
       "      <td>biosample_attr</td>\n",
       "      <td>country</td>\n",
       "      <td>Spain</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61735</th>\n",
       "      <td>delivery_mode</td>\n",
       "      <td>vaginal</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC11183301/mmc2.xlsx/Tab1!delivery:57</td>\n",
       "      <td>delivery=vaginal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61736</th>\n",
       "      <td>feeding_mode</td>\n",
       "      <td>exclusive_breast</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC11183301/mmc2.xlsx/Tab1!feeding_cat:57</td>\n",
       "      <td>feeding_cat=Breastfeeding</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61737</th>\n",
       "      <td>gestational_age_weeks</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC11183301/mmc2.xlsx/Tab1!gestational_age:57</td>\n",
       "      <td>gestational_age=39.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61738</th>\n",
       "      <td>maternal_antibiotics</td>\n",
       "      <td>no</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC11183301/mmc2.xlsx/Tab1!intrapartum_ATB:57</td>\n",
       "      <td>intrapartum_ATB=0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61739</th>\n",
       "      <td>multiple_birth</td>\n",
       "      <td>singleton</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC11183301/mmc2.xlsx/Tab1!Twin:57</td>\n",
       "      <td>Twin=0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61740</th>\n",
       "      <td>preterm_status</td>\n",
       "      <td>term</td>\n",
       "      <td>0.80</td>\n",
       "      <td>R3</td>\n",
       "      <td>paper.fulltext.methods</td>\n",
       "      <td>PMC12222458/methods</td>\n",
       "      <td>66 of healthy, full-term mother-infant pairs</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61741</th>\n",
       "      <td>probiotic_exposure</td>\n",
       "      <td>no</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC12222458/41467_2025_61154_MOESM8_ESM.xlsx/metadata_infants!Probiotic:112</td>\n",
       "      <td>Probiotic=no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61742</th>\n",
       "      <td>sex</td>\n",
       "      <td>female</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC11183301/mmc2.xlsx/Tab1!sex:57</td>\n",
       "      <td>sex=Female</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61743</th>\n",
       "      <td>timepoint_label</td>\n",
       "      <td>7days</td>\n",
       "      <td>0.85</td>\n",
       "      <td>R2</td>\n",
       "      <td>paper.supp.table</td>\n",
       "      <td>PMC12222458/41467_2025_61154_MOESM8_ESM.xlsx/metadata_infants!Time:112</td>\n",
       "      <td>Time=7days</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "                   field_name  value_normalized  confidence route         evidence_source                                                             evidence_locator                                evidence_quote\n",
       "61731  age_at_collection_days                 8        0.85    R2        paper.supp.table                               PMC11183301/mmc2.xlsx/Tab1!timepoint_months:57                         timepoint_months=0.25\n",
       "61732     antibiotic_exposure                no        0.85    R2        paper.supp.table      PMC12222458/41467_2025_61154_MOESM8_ESM.xlsx/metadata_infants!AB_BB:112                                      AB_BB=no\n",
       "61733      birth_weight_grams              3150        0.85    R2        paper.supp.table                              PMC11183301/mmc2.xlsx/Tab1!birth_weight (Kg):57                        birth_weight (Kg)=3.15\n",
       "61734                 country                ES        0.90    R1          biosample_attr                                                                      country                                         Spain\n",
       "61735           delivery_mode           vaginal        0.85    R2        paper.supp.table                                       PMC11183301/mmc2.xlsx/Tab1!delivery:57                              delivery=vaginal\n",
       "61736            feeding_mode  exclusive_breast        0.85    R2        paper.supp.table                                    PMC11183301/mmc2.xlsx/Tab1!feeding_cat:57                     feeding_cat=Breastfeeding\n",
       "61737   gestational_age_weeks              39.0        0.85    R2        paper.supp.table                                PMC11183301/mmc2.xlsx/Tab1!gestational_age:57                          gestational_age=39.0\n",
       "61738    maternal_antibiotics                no        0.85    R2        paper.supp.table                                PMC11183301/mmc2.xlsx/Tab1!intrapartum_ATB:57                           intrapartum_ATB=0.0\n",
       "61739          multiple_birth         singleton        0.85    R2        paper.supp.table                                           PMC11183301/mmc2.xlsx/Tab1!Twin:57                                      Twin=0.0\n",
       "61740          preterm_status              term        0.80    R3  paper.fulltext.methods                                                          PMC12222458/methods  66 of healthy, full-term mother-infant pairs\n",
       "61741      probiotic_exposure                no        0.85    R2        paper.supp.table  PMC12222458/41467_2025_61154_MOESM8_ESM.xlsx/metadata_infants!Probiotic:112                                  Probiotic=no\n",
       "61742                     sex            female        0.85    R2        paper.supp.table                                            PMC11183301/mmc2.xlsx/Tab1!sex:57                                    sex=Female\n",
       "61743         timepoint_label             7days        0.85    R2        paper.supp.table       PMC12222458/41467_2025_61154_MOESM8_ESM.xlsx/metadata_infants!Time:112                                    Time=7days"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "det = pd.read_parquet('sample_determinations.parquet')\n",
    "k = sl.sample_key.iloc[0]\n",
    "det[det.sample_key == k][['field_name', 'value_normalized', 'confidence', 'route', 'evidence_source', 'evidence_locator', 'evidence_quote']]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99e05f84",
   "metadata": {},
   "source": [
    "## 6. Coverage per field (age-scope and catalog-scope denominators)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9aa5536f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coverage_age_scope_infant</th>\n",
       "      <th>coverage_catalog_scope</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>field</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>probiotic_exposure</th>\n",
       "      <td>0.037</td>\n",
       "      <td>0.037</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>preterm_status</th>\n",
       "      <td>0.434</td>\n",
       "      <td>0.451</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>gestational_age_weeks</th>\n",
       "      <td>0.165</td>\n",
       "      <td>0.171</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>delivery_mode</th>\n",
       "      <td>0.314</td>\n",
       "      <td>0.321</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>feeding_mode</th>\n",
       "      <td>0.158</td>\n",
       "      <td>0.158</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>antibiotic_exposure</th>\n",
       "      <td>0.174</td>\n",
       "      <td>0.175</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>age_at_collection_days</th>\n",
       "      <td>0.718</td>\n",
       "      <td>0.733</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>birth_weight_grams</th>\n",
       "      <td>0.140</td>\n",
       "      <td>0.145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>country</th>\n",
       "      <td>0.960</td>\n",
       "      <td>0.958</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>maternal_antibiotics</th>\n",
       "      <td>0.112</td>\n",
       "      <td>0.116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>hmo_supplementation</th>\n",
       "      <td>0.017</td>\n",
       "      <td>0.018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>nec_status</th>\n",
       "      <td>0.071</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>health_condition</th>\n",
       "      <td>0.087</td>\n",
       "      <td>0.089</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>multiple_birth</th>\n",
       "      <td>0.065</td>\n",
       "      <td>0.067</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sibling_in_study</th>\n",
       "      <td>0.048</td>\n",
       "      <td>0.046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>geo_subregion</th>\n",
       "      <td>0.374</td>\n",
       "      <td>0.370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <td>0.442</td>\n",
       "      <td>0.451</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>timepoint_label</th>\n",
       "      <td>0.376</td>\n",
       "      <td>0.378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>subject_id</th>\n",
       "      <td>0.601</td>\n",
       "      <td>0.599</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "                        coverage_age_scope_infant  coverage_catalog_scope\n",
       "field                                                                    \n",
       "probiotic_exposure                          0.037                   0.037\n",
       "preterm_status                              0.434                   0.451\n",
       "gestational_age_weeks                       0.165                   0.171\n",
       "delivery_mode                               0.314                   0.321\n",
       "feeding_mode                                0.158                   0.158\n",
       "antibiotic_exposure                         0.174                   0.175\n",
       "age_at_collection_days                      0.718                   0.733\n",
       "birth_weight_grams                          0.140                   0.145\n",
       "country                                     0.960                   0.958\n",
       "maternal_antibiotics                        0.112                   0.116\n",
       "hmo_supplementation                         0.017                   0.018\n",
       "nec_status                                  0.071                   0.074\n",
       "health_condition                            0.087                   0.089\n",
       "multiple_birth                              0.065                   0.067\n",
       "sibling_in_study                            0.048                   0.046\n",
       "geo_subregion                               0.374                   0.370\n",
       "sex                                         0.442                   0.451\n",
       "timepoint_label                             0.376                   0.378\n",
       "subject_id                                  0.601                   0.599"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cov = pd.read_csv('field_coverage_summary.csv', index_col=0)\n",
    "fig, ax = plt.subplots(figsize=(6, 4))\n",
    "cov[['coverage_age_scope_infant', 'coverage_catalog_scope']].sort_values('coverage_catalog_scope').plot.barh(ax=ax); ax.set_xlabel('fraction of samples with a value')\n",
    "fig.tight_layout(); fig.savefig('getting_started_coverage.png', dpi=100); plt.close(fig)\n",
    "cov[['coverage_age_scope_infant', 'coverage_catalog_scope']].round(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce760660",
   "metadata": {},
   "source": [
    "## 7. Get the runs for download (e.g. `fasterq-dump` / ENA FTP)\n",
    "Join on `biosample_accession` for BioSample units and on `run_accession` for run units (`sample_unit = 'run'`)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7a194728",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1181 runs for 1181 samples\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>run_accession</th>\n",
       "      <th>sample_accession</th>\n",
       "      <th>study_accession</th>\n",
       "      <th>library_layout</th>\n",
       "      <th>instrument_model</th>\n",
       "      <th>read_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9587</th>\n",
       "      <td>ERR12812864</td>\n",
       "      <td>SAMEA115454995</td>\n",
       "      <td>PRJEB74322</td>\n",
       "      <td>PAIRED</td>\n",
       "      <td>Illumina HiSeq 2500</td>\n",
       "      <td>18122268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9595</th>\n",
       "      <td>ERR12813208</td>\n",
       "      <td>SAMEA115455060</td>\n",
       "      <td>PRJEB74322</td>\n",
       "      <td>PAIRED</td>\n",
       "      <td>Illumina HiSeq 2500</td>\n",
       "      <td>32203140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9596</th>\n",
       "      <td>ERR12813219</td>\n",
       "      <td>SAMEA115455027</td>\n",
       "      <td>PRJEB74322</td>\n",
       "      <td>PAIRED</td>\n",
       "      <td>Illumina HiSeq 2500</td>\n",
       "      <td>23039418</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9597</th>\n",
       "      <td>ERR12814168</td>\n",
       "      <td>SAMEA115454991</td>\n",
       "      <td>PRJEB74322</td>\n",
       "      <td>PAIRED</td>\n",
       "      <td>Illumina HiSeq 2500</td>\n",
       "      <td>16857338</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9598</th>\n",
       "      <td>ERR12814185</td>\n",
       "      <td>SAMEA115455030</td>\n",
       "      <td>PRJEB74322</td>\n",
       "      <td>PAIRED</td>\n",
       "      <td>Illumina HiSeq 2500</td>\n",
       "      <td>23809548</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "     run_accession sample_accession study_accession library_layout     instrument_model read_count\n",
       "9587   ERR12812864   SAMEA115454995      PRJEB74322         PAIRED  Illumina HiSeq 2500   18122268\n",
       "9595   ERR12813208   SAMEA115455060      PRJEB74322         PAIRED  Illumina HiSeq 2500   32203140\n",
       "9596   ERR12813219   SAMEA115455027      PRJEB74322         PAIRED  Illumina HiSeq 2500   23039418\n",
       "9597   ERR12814168   SAMEA115454991      PRJEB74322         PAIRED  Illumina HiSeq 2500   16857338\n",
       "9598   ERR12814185   SAMEA115455030      PRJEB74322         PAIRED  Illumina HiSeq 2500   23809548"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "runs = pd.read_parquet('runs.parquet')\n",
    "bs_units = sl[sl.sample_unit == 'biosample'].biosample_accession\n",
    "run_units = sl[sl.sample_unit == 'run'].run_accession\n",
    "my_runs = runs[runs.sample_accession.isin(bs_units) | runs.run_accession.isin(run_units)]\n",
    "print(len(my_runs), 'runs for', len(sl), 'samples')\n",
    "my_runs[['run_accession', 'sample_accession', 'study_accession', 'library_layout', 'instrument_model', 'read_count']].head()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
