Skip to content

Commit

Permalink
fixed bug in lca-reconstruct of ambiguous states
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjones315 committed Mar 7, 2024
1 parent bb2fd4f commit faf7467
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cassiopeia/data/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def get_lca_characters(
else:
lca_vec[i] = all_states[0]
else:
all_ambiguous = np.all([is_ambiguous_state(s) for s in all_states])
chars = set.intersection(
*map(
set,
Expand All @@ -83,6 +84,10 @@ def get_lca_characters(
)
if len(chars) == 1:
lca_vec[i] = list(chars)[0]
if all_ambiguous:
# if we only have ambiguous states, we set the LCA state
# to be the intersection.
lca_vec[i] = tuple(chars)
return lca_vec


Expand Down
11 changes: 11 additions & 0 deletions test/data_tests/data_utilities_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,17 @@ def test_lca_characters_ambiguous(self):
)
self.assertEqual(ret_vec, [1, 2, 3, 0, 5])

def test_lca_characters_ambiguous2(self):

s1 = [(4, 62), (3, 10), (3, 10, 16), (0, 3), (0, 2, 3), (0, 2, 3), (0, 4, 7), (0, 2, 23), (0, 1, 4, 44)]
s2 = [4, 3, -1, 0, 0, 0, (0, 7), (0, 2), (0, 4)]

expected_reconstruction = [4, 3, (3, 10, 16), 0, 0, 0, (0, 7), (0, 2), (0, 4)]
ret_vec = data_utilities.get_lca_characters(
[s1, s2], missing_state_indicator=-1
)
self.assertEqual(ret_vec, expected_reconstruction)

def test_lca_characters_ambiguous_and_missing(self):
vecs = [
[(1, 1), (0, 2), (3, 0), (4,), (5,)],
Expand Down

0 comments on commit faf7467

Please sign in to comment.