Skip to content

Misc changes #101

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 7 commits into from
Nov 19, 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
6 changes: 5 additions & 1 deletion build_tools/before_all_mac.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
brew update
# Check if running in GitHub Actions
if [ "$GITHUB_ACTIONS" = "true" ]; then
brew update
fi

brew install eigen boost

bash build_tools/build_iqtree.sh
6 changes: 5 additions & 1 deletion src/piqtree2/_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
*,
invariant_sites: bool = False,
rand_seed: int | None = None,
bootstrap_reps: int | None = None,
) -> None:
self._model = Model(
substitution_model=substitution_model,
Expand All @@ -35,12 +36,15 @@ def __init__(
freq_type=freq_type,
)
self._rand_seed = rand_seed
self._bootstrap_reps = bootstrap_reps

def main(
self,
aln: cogent3.Alignment | cogent3.ArrayAlignment,
) -> cogent3.PhyloNode | cogent3.app.typing.SerialisableType:
return build_tree(aln, self._model, self._rand_seed)
return build_tree(
aln, self._model, self._rand_seed, bootstrap_replicates=self._bootstrap_reps
)


@composable.define_app
Expand Down
7 changes: 6 additions & 1 deletion src/piqtree2/iqtree/_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,16 @@ def _process_tree_yaml(

_rename_iq_tree(tree, names)

tree.name_unnamed_nodes()

return tree


def build_tree(
aln: cogent3.Alignment | cogent3.ArrayAlignment,
model: Model,
rand_seed: int | None = None,
bootstrap_replicates: int = 0,
bootstrap_replicates: int | None = 0,
) -> cogent3.PhyloNode:
"""Reconstruct a phylogenetic tree.

Expand Down Expand Up @@ -224,6 +226,9 @@ def build_tree(
if rand_seed is None:
rand_seed = 0 # The default rand_seed in IQ-TREE

if bootstrap_replicates is None:
bootstrap_replicates = 0

names = aln.names
seqs = [str(seq) for seq in aln.iter_seqs(names)]

Expand Down
7 changes: 5 additions & 2 deletions src/piqtree2/model/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ def _make_models(model_type: type[SubstitutionModel]) -> dict[str, list[str]]:
return data


def available_models(model_type: str | None = None) -> _Table:
def available_models(model_type: str | None = None, show_all: bool = True) -> _Table:
"""Return a table showing available substitution models.

Parameters
----------
model_type
either "nucleotide", "protein" or None. If None, all models are returned.

show_all
if True, the representation of the table shows all records
"""
template = "Available {}substitution models"
if model_type == "dna":
Expand All @@ -61,6 +62,8 @@ def available_models(model_type: str | None = None) -> _Table:
title=template.format(""),
)

if show_all:
table.set_repr_policy(head=table.shape[0])
return table


Expand Down
11 changes: 11 additions & 0 deletions tests/test_app/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ def test_piqtree_phylo(four_otu: ArrayAlignment) -> None:
assert expected.same_topology(got)


def test_piqtree_phylo_support(four_otu: ArrayAlignment) -> None:
app = get_app("piqtree_phylo", substitution_model="JC", bootstrap_reps=1000)
got = app(four_otu)
supports = [
node.params.get("support", None)
for node in got.postorder()
if not node.is_tip() and node.name != "root"
]
assert all(supports)


def test_piqtree_fit(three_otu: ArrayAlignment) -> None:
tree = make_tree(tip_names=three_otu.names)
app = get_app("model", "JC69", tree=tree)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_iqtree/test_build_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ def test_build_tree_inadequate_bootstrapping(four_otu: ArrayAlignment) -> None:

def test_build_tree_bootstrapping(four_otu: ArrayAlignment) -> None:
tree = piqtree2.build_tree(four_otu, Model(DnaModel.GTR), bootstrap_replicates=1000)
tree.name_unnamed_nodes()
# internal nodes are now named by default
supported_node = tree.get_node_matching_name("node1")
assert "support" in supported_node.params
6 changes: 6 additions & 0 deletions tests/test_model/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def test_num_available_models(
)
assert total_models > 0
assert table.shape[0] == total_models
assert table._repr_policy["head"] == table.shape[0]


def test_num_available_models_not_show_all() -> None:
table = available_models(show_all=False)
assert table._repr_policy["head"] != table.shape[0]


@pytest.mark.parametrize(
Expand Down