Skip to content

Commit

Permalink
Handle case where GT is defined in header, but not used in FORMAT
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite committed Jul 8, 2024
1 parent ada71fa commit 399cdc6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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)
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

0 comments on commit 399cdc6

Please sign in to comment.