"""Front Immunol 2019, doi 10.3389/fimmu.2019.01516: paired alpha/beta single-cell TCR of CD4 T cells from 7 healthy donors, `Carter2019_CD4_sequences.csv` (70,108 rows, CD4 file only),
derived from the authors' GitHub pickle (see MANIFEST_repertoires.md). V and J are gene numbers without prefix, TRAV/TRAJ/TRBV/TRBJ is added. `Subject` 0 to 6 = paper Subjects 1 to 7 (donor "S1" to "S7").
V names such as TRAV14DV4 are written TRAV14/DV4 (IMGT). Subjects 1 and 3 were run by two methods (`Method` Juno = AbVitro, and 10x): same donor label, method in `context`; a clonotype seen by both stays two records (possibly the same cells, not verifiable).
The file has no barcode, count, tissue or subset: one row is taken as one cell, `cells` counts rows per donor, method and TCR. CD4 identity: bead enrichment (EasySep) or FACS before 10x per the methods;
for the AbVitro subjects the CD4/CD8 separation comes from Grigaityte et al. and is not verified (manifest). Subjects 6 and 7 are ATCC PBMC (manifest); tissue of the others is not stated."""
import pandas as pd
from atlas import SRC, clones


def parse():
    d = pd.read_csv(SRC / "Carter2019/Carter2019_CD4_sequences.csv", dtype=str)
    for col, p in (("Va", "TRAV"), ("Ja", "TRAJ"), ("Vb", "TRBV"), ("Jb", "TRBJ")):
        d[p] = p + d[col]
    d["TRAV"] = d.TRAV.str.replace(r"^(TRAV\d+(?:-\d+)?)DV(\d)", r"\1/DV\2", regex=True)
    d["donor"] = "S" + (d.Subject.astype(int) + 1).astype(str)
    d["context"] = "healthy donor, CD4 T cells, " + d.Method.map({"Juno": "AbVitro (Juno)", "10x": "10x Genomics"})
    d = clones(d, ["donor", "context"])
    return d.assign(source="Carter 2019 (Front Immunol)", study="doi:10.3389/fimmu.2019.01516", species="human", cd4_evidence="sorted CD4+ (bead enrichment or FACS; AbVitro subjects per Grigaityte, not verified)",
                    specificity_evidence="none", annotation_level="none")
