Skip to content

Commit

Permalink
Remove requirement that alleles are < num_alleles
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromekelleher committed Nov 6, 2024
1 parent 9545f8d commit 7522bcc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
5 changes: 0 additions & 5 deletions lib/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,6 @@ test_tsb_errors(void)
CU_ASSERT_EQUAL_FATAL(ret, TSI_ERR_BAD_ANCESTRAL_STATE);
tree_sequence_builder_free(&tsb);

ancestral_state = 2;
ret = tree_sequence_builder_alloc(&tsb, 1, &num_alleles, &ancestral_state, 1, 1, 0);
CU_ASSERT_EQUAL_FATAL(ret, TSI_ERR_BAD_ANCESTRAL_STATE);
tree_sequence_builder_free(&tsb);

num_alleles = 2;
ret = tree_sequence_builder_alloc(&tsb, 1, &num_alleles, NULL, 1, 1, 0);
/* Add two nodes so we can test adding paths */
Expand Down
5 changes: 2 additions & 3 deletions lib/tree_sequence_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ tree_sequence_builder_alloc(tree_sequence_builder_t *self, size_t num_sites,
self->sites.num_alleles[j] = num_alleles[j];
}
if (ancestral_state != NULL) {
if (ancestral_state[j] < 0
|| ancestral_state[j] >= (allele_t) num_alleles[j]) {
if (ancestral_state[j] < 0) {
ret = TSI_ERR_BAD_ANCESTRAL_STATE;
goto out;
}
Expand Down Expand Up @@ -418,7 +417,7 @@ tree_sequence_builder_add_mutation(
ret = TSI_ERR_BAD_MUTATION_SITE;
goto out;
}
if (derived_state < 0 || derived_state >= (allele_t) self->sites.num_alleles[site]) {
if (derived_state < 0) {
ret = TSI_ERR_BAD_MUTATION_DERIVED_STATE;
goto out;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_low_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def test_bad_ancestral_state(self):
for bad_array in [None, "serf", [[], []], ["asdf"], {}]:
with pytest.raises(ValueError):
_tsinfer.TreeSequenceBuilder([2], ancestral_state=bad_array)
with pytest.raises(_tsinfer.LibraryError, match="Bad ancestral state"):
for bad_ancestral_state in [-1, 2, 100]:
for bad_ancestral_state in [-1, -2]:
with pytest.raises(_tsinfer.LibraryError, match="Bad ancestral state"):
_tsinfer.TreeSequenceBuilder([2], ancestral_state=[bad_ancestral_state])

with pytest.raises(ValueError, match="ancestral state array wrong size"):
Expand Down

0 comments on commit 7522bcc

Please sign in to comment.