Skip to content

Commit 53a5360

Browse files
committed
fix VCF exporter allele decoding and add validation test
1 parent d2e4994 commit 53a5360

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

malariagen_data/anoph/to_vcf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ def snp_calls_to_vcf(
119119
alleles = allele_chunk[j]
120120
ref = (
121121
alleles[0].decode()
122-
if isinstance(alleles[0], bytes)
122+
if hasattr(alleles[0], "decode")
123123
else str(alleles[0])
124124
)
125125
alt_alleles = []
126126
for a in alleles[1:]:
127-
s = a.decode() if isinstance(a, bytes) else str(a)
127+
s = a.decode() if hasattr(a, "decode") else str(a)
128128
if s:
129129
alt_alleles.append(s)
130130
alt = ",".join(alt_alleles) if alt_alleles else "."

tests/anoph/test_vcf_exporter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ def test_vcf_exporter(fixture, api: VcfExporter, tmp_path):
110110
ds_positions = sorted(ds["variant_position"].values.tolist())
111111
assert vcf_positions == ds_positions
112112

113+
# Allele values are clean strings, not byte-string representations.
114+
for line in data_lines:
115+
fields = line.split("\t")
116+
ref, alt = fields[3], fields[4]
117+
assert "b'" not in ref and "b'" not in alt, (
118+
f"byte-string repr in REF/ALT: REF={ref!r} ALT={alt!r}"
119+
)
120+
113121

114122
@parametrize_with_cases("fixture,api", cases=".")
115123
def test_vcf_exporter_overwrite(fixture, api: VcfExporter, tmp_path):

0 commit comments

Comments
 (0)