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
2 changes: 2 additions & 0 deletions python/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ In development

**Bugfixes**

- Validate zero positions in VCF output using the converted Boolean
site mask. (:user:`rpinho`, :pr:`3512`)
- Apply ``node_labels`` to sequence alignments when exporting NEXUS.
(:user:`rpinho`, :pr:`3514`)

Expand Down
17 changes: 17 additions & 0 deletions python/tests/test_vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,23 @@ def test_site_0_masked(self):
)
assert drop_header(actual) == expected

@pytest.mark.parametrize(
"mask",
[
[True, False, False, False],
np.array([1, 0, 0, 0]),
np.array([True, False, False, False]),
],
)
def test_array_like_mask_skips_position_zero(self, mask):
actual = self.ts().as_vcf(site_mask=mask)
records = [line.split("\t") for line in actual.splitlines() if line[0] != "#"]
assert [record[1] for record in records] == ["2", "4", "6"]

def test_integer_mask_rejects_unmasked_position_zero(self):
with pytest.raises(ValueError, match="A variant position of 0"):
self.ts().as_vcf(site_mask=np.array([0, 1, 0, 0]))

def test_site_0_masked_triploid(self):
s = """\
#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\ttsk_0
Expand Down
2 changes: 1 addition & 1 deletion python/tskit/vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(
# The VCF spec does not allow for positions to be 0, so we error if one of the
# transformed positions is 0 and allow_position_zero is False.
if not allow_position_zero and np.any(
vcf_model.transformed_positions[~site_mask] == 0
vcf_model.transformed_positions[~self.site_mask] == 0
):
raise ValueError(
"A variant position of 0 was found in the VCF output, this is not "
Expand Down
Loading