Skip to content

Commit d9ab5ff

Browse files
committed
ENH: add jc distance app
1 parent 4eeb06d commit d9ab5ff

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ test = ["pytest", "pytest-cov", "nox"]
4646
piqtree_phylo = "piqtree2._app:piqtree_phylo"
4747
piqtree_fit = "piqtree2._app:piqtree_fit"
4848
piqtree_random_trees = "piqtree2._app:piqtree_random_trees"
49+
piqtree_jc_distances = "piqtree2._app:piqtree_jc_distances"
4950
piqtree_nj = "piqtree2._app:piqtree_nj"
5051

5152
[tool.setuptools.dynamic]

src/piqtree2/_app/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
from cogent3.app import composable
66
from cogent3.util.misc import extend_docstring_from
77

8-
from piqtree2 import TreeGenMode, build_tree, fit_tree, nj_tree, random_trees
8+
from piqtree2 import (
9+
TreeGenMode,
10+
build_tree,
11+
fit_tree,
12+
jc_distances,
13+
nj_tree,
14+
random_trees,
15+
)
916
from piqtree2.model import Model
1017

1118

@@ -76,6 +83,14 @@ def piqtree_random_trees(
7683
return random_trees(num_taxa, tree_mode, num_trees, rand_seed)
7784

7885

86+
@composable.define_app
87+
@extend_docstring_from(nj_tree)
88+
def piqtree_jc_distances(
89+
aln: cogent3.Alignment | cogent3.ArrayAlignment,
90+
) -> c3_types.PairwiseDistanceType:
91+
return jc_distances(aln)
92+
93+
7994
@composable.define_app
8095
@extend_docstring_from(nj_tree)
8196
def piqtree_nj(dists: c3_types.PairwiseDistanceType) -> cogent3.PhyloNode:
@@ -86,5 +101,6 @@ def piqtree_nj(dists: c3_types.PairwiseDistanceType) -> cogent3.PhyloNode:
86101
"piqtree_phylo",
87102
"piqtree_fit",
88103
"piqtree_random_trees",
104+
"piqtree_jc_distances",
89105
"piqtree_nj",
90106
]

tests/test_app/test_app.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ def test_piqtree_random_trees(
4242
assert len(tree.tips()) == num_taxa
4343

4444

45+
def test_piqtree_jc_distances(five_otu: ArrayAlignment) -> None:
46+
app = get_app("piqtree_jc_distances")
47+
dists = app(five_otu)
48+
49+
assert (
50+
dists["Human", "Chimpanzee"] < dists["Human", "Dugong"]
51+
) # chimpanzee closer than rhesus
52+
assert (
53+
dists["Human", "Rhesus"] < dists["Human", "Manatee"]
54+
) # rhesus closer than manatee
55+
assert (
56+
dists["Human", "Rhesus"] < dists["Human", "Dugong"]
57+
) # rhesus closer than dugong
58+
59+
assert (
60+
dists["Chimpanzee", "Rhesus"] < dists["Chimpanzee", "Manatee"]
61+
) # rhesus closer than manatee
62+
assert (
63+
dists["Chimpanzee", "Rhesus"] < dists["Chimpanzee", "Dugong"]
64+
) # rhesus closer than dugong
65+
66+
assert (
67+
dists["Manatee", "Dugong"] < dists["Manatee", "Rhesus"]
68+
) # dugong closer than rhesus
69+
70+
4571
def test_piqtree_nj(five_otu: ArrayAlignment) -> None:
4672
dists = jc_distances(five_otu)
4773

0 commit comments

Comments
 (0)