diff --git a/tests/oracle/test_p6_vcf.py b/tests/oracle/test_p6_vcf.py index 211cd83..ac85a2f 100644 --- a/tests/oracle/test_p6_vcf.py +++ b/tests/oracle/test_p6_vcf.py @@ -178,18 +178,24 @@ def test_info_and_extra_format_match_gtc2vcf(tmp_path: Path) -> None: # OUT-012 ) # fmt: skip assert res.exit_code == 0, res.output env = dict(os.environ, BCFTOOLS_PLUGINS=str(plugin.parent)) - g2v = subprocess.run( - [str(BCFTOOLS), "+gtc2vcf", "--no-version", "-t", "GT,X,Y,NORMX,NORMY,THETA,R", "-b", str(GSA_BPM), "-c", - str(GSA_CSV), "-e", str(GSA_EGT), "-f", str(FASTA), "-g", str(gtcs), "-O", "v"], - capture_output=True, text=True, env=env, check=True, - ).stdout # fmt: skip - ref = {} - for line in g2v.splitlines(): - if line.startswith("#"): - continue - c = line.split("\t") - info = dict(kv.split("=", 1) for kv in c[7].split(";") if "=" in kv) - ref[c[2]] = (info, dict(zip(c[8].split(":"), c[9].split(":"), strict=True))) + g2v = tmp_path / "g2v.vcf" + with g2v.open("w") as fh: # streamed: the text of ~700 000 records would cost GBs held as dicts + subprocess.run( + [str(BCFTOOLS), "+gtc2vcf", "--no-version", "-t", "GT,X,Y,NORMX,NORMY,THETA,R", "-b", str(GSA_BPM), "-c", + str(GSA_CSV), "-e", str(GSA_EGT), "-f", str(FASTA), "-g", str(gtcs), "-O", "v"], + stdout=fh, env=env, check=True, + ) # fmt: skip + keys = ("X", "Y", "NORMX", "NORMY", "THETA", "R") + ref: dict[str, tuple[str, ...]] = {} # id → (ASSAY_TYPE, GenTrain_Score, Cluster_Sep, *keys) + with g2v.open() as fh: + for line in fh: + if line.startswith("#"): + continue + c = line.rstrip("\n").split("\t") + info = dict(kv.split("=", 1) for kv in c[7].split(";") if "=" in kv) + fmt = dict(zip(c[8].split(":"), c[9].split(":"), strict=True)) + ref[c[2]] = (info["ASSAY_TYPE"], info["GenTrain_Score"], info["Cluster_Sep"], *(fmt[k] for k in keys)) + g2v.unlink() def close(a: str, b: str) -> bool: na, nb = a in (".", "") or "nan" in a.lower(), b in (".", "") or "nan" in b.lower() @@ -207,9 +213,10 @@ def test_info_and_extra_format_match_gtc2vcf(tmp_path: Path) -> None: # OUT-012 continue info = dict(kv.split("=", 1) for kv in c[7].split(";")) fmt = dict(zip(c[8].split(":"), c[9].split(":"), strict=True)) - ri, rf = ref[c[2]] - assert info["ASSAY_TYPE"] == ri["ASSAY_TYPE"] - assert close(info["GENTRAIN"], ri["GenTrain_Score"]) and close(info["CLUSTER_SEP"], ri["Cluster_Sep"]) + at, gt_score, sep, *vals = ref[c[2]] + rf = dict(zip(keys, vals, strict=True)) + assert info["ASSAY_TYPE"] == at + assert close(info["GENTRAIN"], gt_score) and close(info["CLUSTER_SEP"], sep) for k in ("X", "Y", "NORMX", "NORMY"): assert close(fmt[k], rf[k]), (c[2], k, fmt[k], rf[k]) if fmt["NORMX"] == "0" and fmt["NORMY"] == "0":