"""Mucosal Immunol 2022, doi 10.1038/s41385-022-00497-9 (GSE161938), mouse BALB/c: lung M2e-tetramer+ CD4+ TCRb+ T cells after intranasal M2e
immunisation (CTA1-3M2e-DD) and influenza A infection, day 3 and day 8 (one Cell Ranger contig file each, 5 pooled mice per file). Filters: is_cell,
high_confidence, productive; TRA and TRB only. Donor = the pooled sample (day 3 or day 8 file). Antigen = influenza M2 ectodomain (M2e).
`restriction` is EMPTY on purpose: the MHC molecule of the tetramer is not verified (BALB/c would imply I-Ad, unconfirmed in the paper passages read).
Level "antigen" (tetramer gate, no peptide mapped per clonotype)."""
import pandas as pd
from atlas import SRC, pair_contigs, clones

TRUE = lambda s: s.astype(str).str.lower().eq("true")
DAY = {"1": 3, "2": 8}


def parse():
    out = []
    for f in sorted((SRC / "Omokanye2022").glob("*_filtered_contig_annotations.csv.gz")):
        day = DAY[f.name.split("SampleID_")[1][0]]
        c = pd.read_csv(f, low_memory=False)
        c = c[TRUE(c.is_cell) & TRUE(c.high_confidence) & TRUE(c.productive)]
        d = pair_contigs(c, ["barcode"]).assign(donor=f"day {day} pool (5 mice)", context=f"BALB/c, lung, influenza day {day} after intranasal M2e immunisation")
        out.append(clones(d, ["donor", "context"]))
    return pd.concat(out).assign(source="Omokanye 2022 (Mucosal Immunol)", study="doi:10.1038/s41385-022-00497-9", species="mouse", cd4_evidence="sorted CD4+ (M2e tetramer+)",
                                 antigen="influenza M2 ectodomain (M2e)", organism="Influenza A virus", specificity_evidence="peptide:MHC tetramer (MHC molecule not verified)",
                                 annotation_level="antigen")
