Skip to content

Commit 4c8649d

Browse files
Switch Zarr DirectoryStore to zarr.open() for v2/v3 compat
1 parent a0fedac commit 4c8649d

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

bio2zarr/plink.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def encode_genotypes_slice(bed_path, zarr_path, start, stop):
1717
# the correct approach is, but it is important to note that the
1818
# 0th allele is *not* necessarily the REF for these datasets.
1919
bed = bed_reader.open_bed(bed_path, num_threads=1, count_A1=False)
20-
store = zarr.DirectoryStore(zarr_path)
21-
root = zarr.group(store=store)
20+
root = zarr.open(store=zarr_path, mode="a")
2221
gt = core.BufferedArray(root["call_genotype"], start)
2322
gt_mask = core.BufferedArray(root["call_genotype_mask"], start)
2423
gt_phased = core.BufferedArray(root["call_genotype_phased"], start)
@@ -73,8 +72,7 @@ def convert(
7372
if variants_chunk_size is None:
7473
variants_chunk_size = 10_000
7574

76-
store = zarr.DirectoryStore(zarr_path)
77-
root = zarr.group(store=store, overwrite=True)
75+
root = zarr.open(store=zarr_path, mode="w")
7876

7977
ploidy = 2
8078
shape = [m, n]
@@ -171,8 +169,7 @@ def convert(
171169
# FIXME do this more efficiently - currently reading the whole thing
172170
# in for convenience, and also comparing call-by-call
173171
def validate(bed_path, zarr_path):
174-
store = zarr.DirectoryStore(zarr_path)
175-
root = zarr.group(store=store)
172+
root = zarr.open(store=zarr_path, mode="r")
176173
call_genotype = root["call_genotype"][:]
177174

178175
bed = bed_reader.open_bed(bed_path, count_A1=False, num_threads=1)

bio2zarr/vcf2zarr/vcz.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,7 @@ def init(
532532
)
533533

534534
self.path.mkdir()
535-
store = zarr.DirectoryStore(self.path)
536-
root = zarr.group(store=store)
535+
root = zarr.open(store=self.path, mode="a")
537536
root.attrs.update(
538537
{
539538
"vcf_zarr_version": "0.2",
@@ -549,8 +548,7 @@ def init(
549548
self.wip_path.mkdir()
550549
self.arrays_path.mkdir()
551550
self.partitions_path.mkdir()
552-
store = zarr.DirectoryStore(self.arrays_path)
553-
root = zarr.group(store=store)
551+
root = zarr.open(store=self.arrays_path, mode="a")
554552

555553
total_chunks = 0
556554
for field in self.schema.fields:
@@ -690,8 +688,7 @@ def init_partition_array(self, partition_index, name):
690688
# Overwrite any existing WIP files
691689
wip_path = self.wip_partition_array_path(partition_index, name)
692690
shutil.copytree(src, wip_path, dirs_exist_ok=True)
693-
store = zarr.DirectoryStore(self.wip_partition_path(partition_index))
694-
wip_root = zarr.group(store=store)
691+
wip_root = zarr.open(store=self.wip_partition_path(partition_index), mode="a")
695692
array = wip_root[name]
696693
logger.debug(f"Opened empty array {array.name} <{array.dtype}> @ {wip_path}")
697694
return array

bio2zarr/vcf2zarr/verification.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ def assert_format_val_equal(vcf_val, zarr_val, vcf_type, vcf_number):
145145

146146

147147
def verify(vcf_path, zarr_path, show_progress=False):
148-
store = zarr.DirectoryStore(zarr_path)
149-
150-
root = zarr.group(store=store)
148+
root = zarr.open(store=zarr_path, mode="r")
151149
pos = root["variant_position"][:]
152150
allele = root["variant_allele"][:]
153151
chrom = root["contig_id"][:][root["variant_contig"][:]]

0 commit comments

Comments
 (0)