Skip to content

ENH: Add JC Distance App #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2024
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test = ["pytest", "pytest-cov", "nox"]
piqtree_phylo = "piqtree2._app:piqtree_phylo"
piqtree_fit = "piqtree2._app:piqtree_fit"
piqtree_random_trees = "piqtree2._app:piqtree_random_trees"
piqtree_jc_distances = "piqtree2._app:piqtree_jc_distances"
piqtree_nj = "piqtree2._app:piqtree_nj"

[tool.setuptools.dynamic]
Expand Down
18 changes: 17 additions & 1 deletion src/piqtree2/_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
from cogent3.app import composable
from cogent3.util.misc import extend_docstring_from

from piqtree2 import TreeGenMode, build_tree, fit_tree, nj_tree, random_trees
from piqtree2 import (
TreeGenMode,
build_tree,
fit_tree,
jc_distances,
nj_tree,
random_trees,
)
from piqtree2.model import Model


Expand Down Expand Up @@ -76,6 +83,14 @@ def piqtree_random_trees(
return random_trees(num_taxa, tree_mode, num_trees, rand_seed)


@composable.define_app
@extend_docstring_from(nj_tree)
def piqtree_jc_distances(
aln: cogent3.Alignment | cogent3.ArrayAlignment,
) -> c3_types.PairwiseDistanceType:
return jc_distances(aln)


@composable.define_app
@extend_docstring_from(nj_tree)
def piqtree_nj(dists: c3_types.PairwiseDistanceType) -> cogent3.PhyloNode:
Expand All @@ -86,5 +101,6 @@ def piqtree_nj(dists: c3_types.PairwiseDistanceType) -> cogent3.PhyloNode:
"piqtree_phylo",
"piqtree_fit",
"piqtree_random_trees",
"piqtree_jc_distances",
"piqtree_nj",
]
26 changes: 26 additions & 0 deletions tests/test_app/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ def test_piqtree_random_trees(
assert len(tree.tips()) == num_taxa


def test_piqtree_jc_distances(five_otu: ArrayAlignment) -> None:
app = get_app("piqtree_jc_distances")
dists = app(five_otu)

assert (
dists["Human", "Chimpanzee"] < dists["Human", "Dugong"]
) # chimpanzee closer than rhesus
assert (
dists["Human", "Rhesus"] < dists["Human", "Manatee"]
) # rhesus closer than manatee
assert (
dists["Human", "Rhesus"] < dists["Human", "Dugong"]
) # rhesus closer than dugong

assert (
dists["Chimpanzee", "Rhesus"] < dists["Chimpanzee", "Manatee"]
) # rhesus closer than manatee
assert (
dists["Chimpanzee", "Rhesus"] < dists["Chimpanzee", "Dugong"]
) # rhesus closer than dugong

assert (
dists["Manatee", "Dugong"] < dists["Manatee", "Rhesus"]
) # dugong closer than rhesus


def test_piqtree_nj(five_otu: ArrayAlignment) -> None:
dists = jc_distances(five_otu)

Expand Down