Skip to content
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
14 changes: 10 additions & 4 deletions bio2zarr/vcz.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def init(
# Doing this synchronously - this is fine surely
self.encode_samples(root)
if self.source.filters is not None:
self.encode_filter_id(root)
self.encode_filters(root)
if self.source.contigs is not None:
self.encode_contigs(root)

Expand Down Expand Up @@ -581,9 +581,7 @@ def encode_contigs(self, root):
)
array.attrs["_ARRAY_DIMENSIONS"] = ["contigs"]

def encode_filter_id(self, root):
# TODO need a way to store description also
# https://github.com/sgkit-dev/vcf-zarr-spec/issues/19
def encode_filters(self, root):
filters = self.source.filters
array = root.array(
"filter_id",
Expand All @@ -593,6 +591,14 @@ def encode_filter_id(self, root):
compressor=DEFAULT_ZARR_COMPRESSOR,
)
array.attrs["_ARRAY_DIMENSIONS"] = ["filters"]
array = root.array(
"filter_description",
data=[filt.description for filt in filters],
shape=len(filters),
dtype="str",
compressor=DEFAULT_ZARR_COMPRESSOR,
)
array.attrs["_ARRAY_DIMENSIONS"] = ["filters"]

def init_array(self, root, array_spec, variants_dim_size):
kwargs = dict(zarr_utils.ZARR_FORMAT_KWARGS)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_vcf_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def ds(self, tmp_path_factory):

def test_filters(self, ds):
nt.assert_array_equal(ds["filter_id"], ["PASS", "s50", "q10"])
nt.assert_array_equal(
ds["filter_description"],
[
"All filters passed",
"Less than 50% of samples have data",
"Quality below 10",
],
)
nt.assert_array_equal(
ds["variant_filter"],
[
Expand Down Expand Up @@ -957,6 +965,7 @@ def test_info_fields(self, ds):
"contig_id",
"contig_length",
"filter_id",
"filter_description",
"region_index",
"sample_id",
]
Expand Down
1 change: 1 addition & 0 deletions tests/test_vcz.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ def test_vcz(self, zarr_path):
"/sample_id",
"/variant_id_mask",
"/filter_id",
"/filter_description",
"/contig_id",
]
nt.assert_array_equal(sorted(df["name"]), sorted(fields))
Expand Down
Loading