"""J Exp Med 2021, doi 10.1084/jem.20200650 (GSE158896), mouse C57BL/6: spleen CD4+ CD44+ T cells sorted with the LCMV GP66-77:I-Ab tetramer,
LCMV Armstrong day 10, 5 mice (M1 to M5, one Cell Ranger contig file each, 10x 5' VDJ). Filters: is_cell, high_confidence, productive; chains TRA and TRB
only (Multi, IG and TRG/TRD contigs dropped). Donor = mouse. Every cell is tetramer-positive by construction (the sort), so no antigen-negative records.
Specificity level is "antigen": the tetramer gate defines the peptide:MHC but no peptide is mapped per clonotype, so `epitope` is left empty (README rule).
Lineage (Th1 / Tfh) from the GEX files is not used."""
import pandas as pd
from atlas import SRC, pair_contigs, clones

TRUE = lambda s: s.astype(str).str.lower().eq("true")


def parse():
    out = []
    for f in sorted((SRC / "Khatun2021").glob("*_filtered_contig_annotations.csv.gz")):
        c = pd.read_csv(f, low_memory=False)
        c = c[TRUE(c.is_cell) & TRUE(c.high_confidence) & TRUE(c.productive)]
        out.append(clones(pair_contigs(c, ["barcode"]).assign(donor=f.name.split("_")[1]), ["donor"]))
    return pd.concat(out).assign(source="Khatun 2021 (J Exp Med)", study="doi:10.1084/jem.20200650", species="mouse", cd4_evidence="sorted CD4+ (CD44+ GP66-77 tetramer+)",
                                 restriction="H2-IAb", antigen="LCMV glycoprotein GP66-77", organism="LCMV Armstrong", context="C57BL/6, LCMV Armstrong day 10, spleen",
                                 specificity_evidence="peptide:MHC tetramer", annotation_level="antigen")
