Skip to content

Commit db0af0c

Browse files
committed
Backward and forward-compatible changes to support zarr-python v3
1 parent 0e18357 commit db0af0c

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

dev.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def main(root):
5656
# we avoid retrieving stuff we don't need.
5757
format_fields = {}
5858
info_fields = {}
59-
for name, array in root.items():
59+
for name, array in root.arrays():
6060
if name.startswith("call_") and not name.startswith("call_genotype"):
6161
vcf_name = name[len("call_") :]
6262
format_fields[vcf_name] = array.blocks[v_chunk]

vcztools/filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _compose_comparison_evaluator(self, parse_results: pp.ParseResults) -> Calla
113113

114114
def evaluator(root, variant_chunk_index: int) -> np.ndarray:
115115
vcf_name = parse_results[0]
116-
vcz_names = set(name for name, _array in root.items())
116+
vcz_names = set(root.keys())
117117
vcz_name = vcf_name_to_vcz_name(vcz_names, vcf_name)
118118
zarray = root[vcz_name]
119119
variant_chunk_len = zarray.chunks[0]

vcztools/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _compose_tag_generator(
130130
return self._compose_gt_generator()
131131

132132
def generate(root):
133-
vcz_names = set(name for name, _zarray in root.items())
133+
vcz_names = set(root.keys())
134134
vcz_name = vcf_name_to_vcz_name(vcz_names, tag)
135135
zarray = root[vcz_name]
136136
contig_ids = root["contig_id"][:] if tag == "CHROM" else None

vcztools/regions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ def create_index(vcz) -> None:
4747
root.array(
4848
"region_index",
4949
data=index,
50+
shape=index.shape,
51+
dtype=index.dtype,
5052
compressor=numcodecs.Blosc("zstd", clevel=9, shuffle=0),
51-
overwrite=True,
5253
)
5354

55+
# consolidate to ensure region_index is found
56+
zarr.consolidate_metadata(vcz)
57+
5458

5559
def parse_region_string(region: str) -> tuple[str, int | None, int | None]:
5660
"""Return the contig, start position and end position from a region string."""

vcztools/vcf_writer.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,17 @@ def c_chunk_to_vcf(
292292
drop_genotypes,
293293
no_update,
294294
):
295-
chrom = contigs[get_vchunk_array(root.variant_contig, v_chunk, v_mask_chunk)]
295+
chrom = contigs[get_vchunk_array(root["variant_contig"], v_chunk, v_mask_chunk)]
296296
# TODO check we don't truncate silently by doing this
297-
pos = get_vchunk_array(root.variant_position, v_chunk, v_mask_chunk).astype(
297+
pos = get_vchunk_array(root["variant_position"], v_chunk, v_mask_chunk).astype(
298298
np.int32
299299
)
300-
id = get_vchunk_array(root.variant_id, v_chunk, v_mask_chunk).astype("S")
301-
alleles = get_vchunk_array(root.variant_allele, v_chunk, v_mask_chunk)
300+
id = get_vchunk_array(root["variant_id"], v_chunk, v_mask_chunk).astype("S")
301+
alleles = get_vchunk_array(root["variant_allele"], v_chunk, v_mask_chunk)
302302
ref = alleles[:, 0].astype("S")
303303
alt = alleles[:, 1:].astype("S")
304-
qual = get_vchunk_array(root.variant_quality, v_chunk, v_mask_chunk)
305-
filter_ = get_vchunk_array(root.variant_filter, v_chunk, v_mask_chunk)
304+
qual = get_vchunk_array(root["variant_quality"], v_chunk, v_mask_chunk)
305+
filter_ = get_vchunk_array(root["variant_filter"], v_chunk, v_mask_chunk)
306306

307307
num_variants = len(pos)
308308
if len(id.shape) == 1:
@@ -313,7 +313,7 @@ def c_chunk_to_vcf(
313313
format_fields = {}
314314
info_fields = {}
315315
num_samples = len(samples_selection) if samples_selection is not None else None
316-
for name, array in root.items():
316+
for name, array in root.arrays():
317317
if (
318318
name.startswith("call_")
319319
and not name.startswith("call_genotype")
@@ -417,7 +417,8 @@ def _generate_header(ds, original_header, sample_ids, *, no_version: bool = Fals
417417
# GT must be the first field if present, per the spec (section 1.6.2)
418418
format_fields.append("GT")
419419

420-
for var, arr in ds.items():
420+
for var in sorted(ds.keys()):
421+
arr = ds[var]
421422
if (
422423
var.startswith("variant_")
423424
and not var.endswith("_fill")

0 commit comments

Comments
 (0)