"""eLife 2022, doi 10.7554/eLife.80079 (GSE201730), mouse C57BL/6: spleen CD4+ T cells sorted with the LCMV GP66-77:I-Ab tetramer, LCMV clone 13
(chronic) day 10, 2 mice (M1, M2; one Cell Ranger contig file each). Same conventions as khatun2021.py: filters is_cell, high_confidence, productive;
TRA and TRB only; donor = mouse; all cells tetramer-positive by construction; 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")


def parse():
    out = []
    for f in sorted((SRC / "Zander2022").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("_")[3]), ["donor"]))
    return pd.concat(out).assign(source="Zander 2022 (eLife)", study="doi:10.7554/eLife.80079", species="mouse", cd4_evidence="sorted CD4+ (GP66-77 tetramer+)",
                                 restriction="H2-IAb", antigen="LCMV glycoprotein GP66-77", organism="LCMV clone 13", context="C57BL/6, LCMV clone 13 day 10, spleen",
                                 specificity_evidence="peptide:MHC tetramer", annotation_level="antigen")
