"""Sci Rep 2025, doi 10.1038/s41598-025-07008-3 (GSE307781): primary Sjogren's disease, 2 patients (T513, T522), bulk TCR beta (MiXCR-like clonotype tables, no alpha) of blood CD4 subsets
Th1, Th17, Treg, Tfh1, Tfh2, Tfh17 (12 files `*_Blood_*`). The minor salivary gland files (`*_SG_All`, whole tissue, not CD4-sorted) are NOT loaded. The surface-marker definition of each subset
is not in the files: the subset name is kept as given. `count` is not documented as a cell count (could be reads or molecules), so `cells` is left empty. One record per patient, subset and
clonotype (CDR3, V, J); the same CDR3 in two subsets stays two records. Patient 522 files are named `T522P1` (a second library, per the manifest not verified); treated as patient T522. No antigen."""
import pandas as pd
from atlas import SRC


def parse():
    out = []
    for f in sorted((SRC / "Abe2025").glob("GSE307781_T5*_Blood_*.txt.gz")):
        _, pat, _, subset = f.name.removesuffix(".txt.gz").split("_")
        d = pd.read_csv(f, sep="\t", usecols=["cdr3aa", "v", "j"]).rename(columns={"cdr3aa": "CDR3b", "v": "TRBV", "j": "TRBJ"})
        d["donor"] = pat[:4]
        d["context"] = f"primary Sjogren's disease, blood {subset} (CD4 subset)"
        out.append(d)
    return pd.concat(out).drop_duplicates().assign(
        source="Abe 2025 (Sci Rep)", study="GEO:GSE307781", species="human", cd4_evidence="sorted CD4+ subset", specificity_evidence="none", annotation_level="none")
