Skip to content

Commit c691ecf

Browse files
committed
Testing/Less Cooked
Adding tests and not sorting every attribute as only INFO fields were sensitive to header ordering.
1 parent 0aa8f88 commit c691ecf

File tree

6 files changed

+68
-8
lines changed

6 files changed

+68
-8
lines changed

bio2zarr/vcf2zarr/icf.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,24 @@ class VcfPartition:
116116
)
117117

118118

119-
@dataclasses.dataclass(order=True)
119+
@dataclasses.dataclass
120120
class Contig:
121121
id: str
122122
length: int = None
123123

124124

125-
@dataclasses.dataclass(order=True)
125+
@dataclasses.dataclass
126126
class Sample:
127127
id: str
128128

129129

130-
@dataclasses.dataclass(order=True)
130+
@dataclasses.dataclass
131131
class Filter:
132132
id: str
133133
description: str = ""
134134

135135

136-
@dataclasses.dataclass(order=True)
136+
@dataclasses.dataclass
137137
class IcfMetadata(core.JsonDataclass):
138138
samples: list
139139
contigs: list
@@ -195,10 +195,12 @@ def fromdict(d):
195195
def __eq__(self, other):
196196
if not isinstance(other, IcfMetadata):
197197
return NotImplemented
198-
return (sorted(self.samples) == sorted(other.samples) and
199-
sorted(self.contigs) == sorted(other.contigs) and
200-
sorted(self.filters) == sorted(other.filters) and
201-
sorted(self.fields) == sorted(other.fields))
198+
return (
199+
self.samples == other.samples and
200+
self.contigs == other.contigs and
201+
self.filters == other.filters and
202+
sorted(self.fields) == sorted(other.fields)
203+
)
202204

203205

204206
def fixed_vcf_field_definitions():
563 Bytes
Binary file not shown.
96 Bytes
Binary file not shown.
553 Bytes
Binary file not shown.
97 Bytes
Binary file not shown.

tests/test_vcf_examples.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,3 +1100,61 @@ def test_missing_filter(tmp_path):
11001100
zarr_path = tmp_path / "zarr"
11011101
with pytest.raises(ValueError, match="Filter 'q10' was not defined in the header"):
11021102
vcf2zarr.convert([path], zarr_path)
1103+
1104+
class TestOutOfOrderFields:
1105+
data_paths = ["tests/data/vcf/out_of_order_fields/input1.bcf",
1106+
"tests/data/vcf/out_of_order_fields/input2.bcf"]
1107+
1108+
@pytest.fixture(scope="class")
1109+
def ds(self, tmp_path_factory):
1110+
out = tmp_path_factory.mktemp("data") / "ooo_example.vcf.zarr"
1111+
vcf2zarr.convert(self.data_paths, out)
1112+
return sg.load_dataset(out)
1113+
1114+
def test_filters(self, ds):
1115+
nt.assert_array_equal(ds["filter_id"], ["PASS", "FAIL"])
1116+
nt.assert_array_equal(
1117+
ds["variant_filter"],
1118+
[
1119+
[True, False],
1120+
[False, True],
1121+
[True, False],
1122+
],
1123+
)
1124+
1125+
def test_source(self, ds):
1126+
assert ds.attrs["source"] == f"bio2zarr-{provenance.__version__}"
1127+
1128+
def test_contigs(self, ds):
1129+
nt.assert_array_equal(ds["contig_id"], ["chr20", "chr21"])
1130+
nt.assert_array_equal(ds['contig_length'], [64444167., 46709983.])
1131+
nt.assert_array_equal(ds["variant_contig"], [0, 1, 1])
1132+
1133+
def test_position(self, ds):
1134+
nt.assert_array_equal(ds["variant_position"], [63971, 64506, 64507])
1135+
1136+
def test_length(self, ds):
1137+
nt.assert_array_equal(ds["variant_length"], [11, 1, 1])
1138+
1139+
def test_info_fields(self, ds):
1140+
nt.assert_array_equal(
1141+
ds["variant_QNAME"],
1142+
['cluster19_000000F', '.', 'cluster19_000000F'],
1143+
)
1144+
nt.assert_array_equal(ds["variant_QSTART"], [25698928, 25698928, -1])
1145+
1146+
def test_allele(self, ds):
1147+
fill = constants.STR_FILL
1148+
nt.assert_array_equal(
1149+
ds["variant_allele"].values.tolist(),
1150+
[
1151+
['TTCCATTCCAC', 'T'],
1152+
['C', 'CTCCAT'],
1153+
['G', 'A']
1154+
]
1155+
)
1156+
assert ds["variant_allele"].dtype == "O"
1157+
1158+
def test_call_DPs(self, ds):
1159+
nt.assert_array_equal(ds["call_DP"], [[5], [-1], [5]])
1160+
nt.assert_array_equal(ds["call_DP2"], [[1], [1], [-1]])

0 commit comments

Comments
 (0)