Skip to content

Commit

Permalink
Merge branch 'master' into single-thread-hybrid
Browse files Browse the repository at this point in the history
  • Loading branch information
colganwi authored Feb 5, 2024
2 parents 2717576 + b4d6208 commit d2596e6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cassiopeia/data/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def ete3_to_networkx(tree: ete3.Tree) -> nx.DiGraph:
if n.is_root():
continue

g.add_edge(n.up.name, n.name)
g.add_edge(n.up.name, n.name, length=n.dist)

return g

Expand Down
32 changes: 32 additions & 0 deletions test/data_tests/cassiopeia_tree_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ def test_newick_to_networkx(self):
for e in test_edges:
self.assertIn(e, expected_edges)

def test_newick_to_networkx_with_branch_lengths(self):

nwk = "(node1:0.2,node2:0.3)node0;"

network = data_utilities.newick_to_networkx(nwk)

test_edges = network.edges(data=True)
expected_edges = [
("node0", "node1", {"length": 0.2}),
("node0", "node2", {"length": 0.3}),
]
for e in test_edges:
self.assertIn(e, expected_edges)

def test_newick_constructor(self):

tree = cas.data.CassiopeiaTree(
Expand Down Expand Up @@ -181,6 +195,24 @@ def test_newick_constructor(self):
for n in obs_nodes:
self.assertIn(n, expected_nodes)

def test_newick_constructor_with_branch_lengths(self):

nwk = "(node1:0.2,node2:0.3)node0;"

tree = cas.data.CassiopeiaTree(tree = nwk)

network = tree.get_tree_topology()
test_edges = network.edges(data=True)
expected_edges = [
("node0", "node1", {"length": 0.2}),
("node0", "node2", {"length": 0.3}),
]
for e in test_edges:
self.assertIn(e, expected_edges)

expected_times = {"node0": 0.0, "node1": 0.2, "node2": 0.3}
self.assertEqual(tree.get_times(), expected_times)

def test_networkx_constructor(self):

tree = cas.data.CassiopeiaTree(
Expand Down

0 comments on commit d2596e6

Please sign in to comment.