Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle case where GT is defined in header, but not used in FORMAT #270

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bio2zarr/vcf2zarr/icf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,11 @@ def process_partition(self, partition_index):
for field in info_fields:
tcw.append(field.full_name, variant.INFO.get(field.name, None))
if has_gt:
tcw.append("FORMAT/GT", variant.genotype.array())
if variant.genotype is None:
val = None
else:
val = variant.genotype.array()
tcw.append("FORMAT/GT", val)
for field in format_fields:
val = variant.format(field.name)
tcw.append(field.full_name, val)
Expand Down
10 changes: 7 additions & 3 deletions bio2zarr/vcf2zarr/vcz.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def fixed_field_spec(
array_specs.append(spec_from_field(field))

if gt_field is not None:
ploidy = gt_field.summary.max_number - 1
ploidy = max(gt_field.summary.max_number - 1, 1)
jeromekelleher marked this conversation as resolved.
Show resolved Hide resolved
shape = [m, n]
chunks = [variants_chunk_size, samples_chunk_size]
dimensions = ["variants", "samples"]
Expand Down Expand Up @@ -728,9 +728,13 @@ def encode_genotypes_partition(self, partition_index):
source_field = self.icf.fields["FORMAT/GT"]
for value in source_field.iter_values(partition.start, partition.stop):
j = gt.next_buffer_row()
icf.sanitise_value_int_2d(gt.buff, j, value[:, :-1])
icf.sanitise_value_int_2d(
gt.buff, j, value[:, :-1] if value is not None else None
)
j = gt_phased.next_buffer_row()
icf.sanitise_value_int_1d(gt_phased.buff, j, value[:, -1])
icf.sanitise_value_int_1d(
gt_phased.buff, j, value[:, -1] if value is not None else None
)
# TODO check is this the correct semantics when we are padding
# with mixed ploidies?
j = gt_mask.next_buffer_row()
Expand Down
2 changes: 1 addition & 1 deletion bio2zarr/vcf2zarr/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def verify(vcf_path, zarr_path, show_progress=False):
chrom = root["contig_id"][:][root["variant_contig"][:]]
vid = root["variant_id"][:]
call_genotype = None
if "call_genotype" in root:
if "call_genotype" in root and root["call_genotype"].size > 0:
call_genotype = iter(root["call_genotype"])

vcf = cyvcf2.VCF(vcf_path)
Expand Down
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def test_5_chunk_1(self, n, expected):
# It works in CI on Linux, but it'll probably break at some point.
# It's also necessary to update these numbers each time a new data
# file gets added
("tests/data", 4973751),
("tests/data/vcf", 4961614),
("tests/data", 4974951),
("tests/data/vcf", 4962814),
("tests/data/vcf/sample.vcf.gz", 1089),
],
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_vcf_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ def test_duplicate_paths(self, tmp_path):
"sample.vcf.gz",
"sample_old_tabix.vcf.gz",
"sample_no_genotypes.vcf.gz",
"sample_no_genotypes_with_gt_header.vcf.gz",
"1kg_2020_chrM.vcf.gz",
"field_type_combos.vcf.gz",
"out_of_order_contigs.vcf.gz",
Expand Down
Loading