Skip to content

Commit 598c441

Browse files
Will-Tylerjeromekelleher
authored andcommitted
Implement %SAMPLE tag in vcztools query
1 parent 5aa10a2 commit 598c441

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

tests/test_bcftools_validation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ def test_vcf_output_with_output_option(tmp_path, args, vcf_file):
131131
(r"query -f '%POS\n' -e 'POS=112'", "sample.vcf.gz"),
132132
(r"query -f '[%CHROM\t]\n'", "sample.vcf.gz"),
133133
(r"query -f '[%CHROM\t]\n' -i 'POS=112'", "sample.vcf.gz"),
134-
(r"query -f '%CHROM\t%POS\t%REF\t%ALT[\t%GT]\n'", "sample.vcf.gz"),
134+
(r"query -f '%CHROM\t%POS\t%REF\t%ALT[\t%SAMPLE=%GT]\n'", "sample.vcf.gz"),
135135
(r"query -f 'GQ:[ %GQ] \t GT:[ %GT]\n'", "sample.vcf.gz"),
136-
(r"query -f '[%CHROM:%POS %GT\n]'", "sample.vcf.gz"),
137-
(r"query -f '[%GT %DP\n]'", "sample.vcf.gz"),
136+
(r"query -f '[%CHROM:%POS %SAMPLE %GT\n]'", "sample.vcf.gz"),
137+
(r"query -f '[%SAMPLE %GT %DP\n]'", "sample.vcf.gz"),
138138
],
139139
)
140140
def test_output(tmp_path, args, vcf_name):

vcztools/query.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ def stringify(gt_and_phase: tuple):
120120

121121
return generate
122122

123+
def _compose_sample_ids_generator(self) -> Callable:
124+
def generate(root):
125+
variant_count = root["variant_position"].shape[0]
126+
sample_ids = root["sample_id"][:].tolist()
127+
yield from itertools.repeat(sample_ids, variant_count)
128+
129+
return generate
130+
123131
def _compose_tag_generator(
124132
self, tag: str, *, subfield=False, sample_loop=False
125133
) -> Callable:
@@ -129,6 +137,9 @@ def _compose_tag_generator(
129137
if tag == "GT":
130138
return self._compose_gt_generator()
131139

140+
if tag == "SAMPLE":
141+
return self._compose_sample_ids_generator()
142+
132143
def generate(root):
133144
vcz_names = set(name for name, _zarray in root.items())
134145
vcz_name = vcf_name_to_vcz_name(vcz_names, tag)

0 commit comments

Comments
 (0)