Skip to content

ENH: define cogent3 apps and add test stub #15

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
Jul 2, 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
13 changes: 12 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@
),
]

setup(ext_modules=ext_modules, cmdclass={"build_ext": build_ext}, zip_safe=False)
setup(
ext_modules=ext_modules,
cmdclass={"build_ext": build_ext},
zip_safe=False,
entry_points={
"cogent3.app": [
"piqtree_phylo = piqtree2._app:piqtree_phylo",
"piqtree_fit = piqtree2._app:piqtree_fit",
"piqtree_random_trees = piqtree2._app:piqtree_random_trees",
]
},
)
6 changes: 6 additions & 0 deletions src/piqtree2/_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from piqtree2 import _iq_wrappers as iqtree
from cogent3.app.composable import define_app

piqtree_phylo = define_app(iqtree.build_tree)
piqtree_fit = define_app(iqtree.fit_tree)
piqtree_random_trees = define_app(iqtree.random_trees)
4 changes: 3 additions & 1 deletion src/piqtree2/_iq_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def _rename_iq_tree(tree: cogent3.PhyloNode, names: list[str]) -> None:


def build_tree(
aln: cogent3.Alignment, model: str, rand_seed: int | None = None
aln: cogent3.Alignment | cogent3.ArrayAlignment,
model: str,
rand_seed: int | None = None,
) -> cogent3.PhyloNode:
if rand_seed is None:
rand_seed = 0 # The default rand_seed in IQ-TREE
Expand Down
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pathlib

import pytest


@pytest.fixture(scope="session")
def DATA_DIR():
return pathlib.Path(__file__).parent / "data"


@pytest.fixture(scope="function")
def tmp_dir(tmp_path_factory):
return tmp_path_factory.mktemp("cli")
File renamed without changes.
18 changes: 18 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
from cogent3 import get_app, load_aligned_seqs, make_tree


@pytest.fixture
def three_otu(DATA_DIR):
aln = load_aligned_seqs(DATA_DIR / "example.fasta", moltype="dna")
aln = aln.take_seqs(["Human", "Rhesus", "Mouse"])
return aln.omit_gap_pos(allowed_gap_frac=0)


def test_piqtree_fit(three_otu):
tree = make_tree(tip_names=three_otu.names)
app = get_app("model", "JC69", tree=tree)
expect = app(three_otu)
piphylo = get_app("piqtree_fit", tree=tree, model="JC")
got = piphylo(three_otu)
assert got.lnL == expect.lnL