Skip to content

Commit 7c2bc45

Browse files
committed
chore(call): add strkitCommand vcf header entry
also refactor VCF header command a bit in prep for merge command
1 parent 70c803a commit 7c2bc45

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

docs/output_formats.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ VCF meta fields (non-exhaustive):
144144
* `phasing`: present and set to `partial` if using SNV/HP phasing
145145
* `reference`: absolute file URI to FASTA reference (`file://<...>`)
146146
* `strkitVersion`: STRkit version used to generate the file
147+
* `strkitCommand`: STRkit subcommand used to generate the VCF (`call`)
147148
* `strkitCatalogNumLoci`: Number of total loci in the catalog used for genotyping
148149
* `strkitCatalogHash`: SHA256 hash of the loci loaded from the catalog
149150

strkit/call/call_sample.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from operator import itemgetter
4+
from pathlib import Path
45
from typing import TYPE_CHECKING
56

67
if TYPE_CHECKING: # For type hinting only
@@ -307,8 +308,9 @@ def call_sample(
307308
vf: VariantFile | None = None
308309
if vcf_path is not None:
309310
vh = build_vcf_header(
310-
sample_id_str,
311-
params.reference_file,
311+
"call",
312+
(sample_id_str,),
313+
Path(params.reference_file),
312314
partial_phasing=params.snv_vcf is not None or params.use_hp,
313315
num_loci=num_loci,
314316
loci_hash=loci_hash,

strkit/call/output/vcf.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ def iter_to_upper(x: Iterable[str]) -> Iterable[str]:
5555

5656

5757
def build_vcf_header(
58-
sample_id: str, reference_file: str, partial_phasing: bool, num_loci: int, loci_hash: str
58+
command: str, sample_ids: tuple[str, ...],
59+
reference_file: Path | str, # if Path, turn into file URI. Otherwise, treat "as-is".
60+
partial_phasing: bool,
61+
num_loci: int,
62+
loci_hash: str
5963
) -> VariantHeader:
6064
vh = VariantHeader() # automatically sets VCF version to 4.2
6165

@@ -70,17 +74,23 @@ def build_vcf_header(
7074
if partial_phasing:
7175
vh.add_meta("phasing", "partial")
7276

73-
# Add an absolute path to the reference genome
74-
vh.add_meta("reference", f"file://{str(Path(reference_file).resolve().absolute())}")
77+
# Add an absolute path to the reference genome. If we're passed a string (from merge), assume this is already a file
78+
# URI.
79+
vh.add_meta(
80+
"reference",
81+
f"file://{str(reference_file.resolve().absolute())}" if isinstance(reference_file, Path) else reference_file
82+
)
7583

7684
# Add all contigs from the reference genome file + lengths
77-
with FastaFile(reference_file) as rf:
85+
with FastaFile(str(reference_file)) as rf:
7886
for contig in rf.references:
7987
vh.contigs.add(contig, length=rf.get_reference_length(contig))
8088

8189
# Add STRkit-specific fields:
8290
# - marking version
8391
vh.add_meta("strkitVersion", str(__version__))
92+
# - the subcommand being used to generate this VCF (call|merge)
93+
vh.add_meta("strkitCommand", command)
8494
# - indicating number of loci provided (i.e., catalogue size)
8595
vh.add_meta("strkitCatalogNumLoci", str(num_loci))
8696
# - indicating hash of STRkitLocus objects (for checking catalogue sameness)
@@ -128,8 +138,9 @@ def build_vcf_header(
128138
# for iv in VCF_TR_INFO_RECORDS:
129139
# vh.info.add(*iv)
130140

131-
# Add the sample
132-
vh.add_sample(sample_id)
141+
# Add the sample(s)
142+
for sample_id in sample_ids:
143+
vh.add_sample(sample_id)
133144

134145
return vh
135146

0 commit comments

Comments
 (0)