Skip to content

Bump iqtree2 from ea7a080 to da38244 #120

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 4 commits into from
Dec 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
2 changes: 1 addition & 1 deletion iqtree2
21 changes: 16 additions & 5 deletions src/piqtree2/_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,22 @@ def piqtree_random_trees(


@composable.define_app
@extend_docstring_from(jc_distances)
def piqtree_jc_dists(
aln: c3_types.AlignedSeqsType,
) -> c3_types.PairwiseDistanceType:
return jc_distances(aln)
class piqtree_jc_dists:
@extend_docstring_from(jc_distances)
def __init__(
self,
num_threads: int | None = None,
) -> None:
self._num_threads = num_threads

def main(
self,
aln: c3_types.AlignedSeqsType,
) -> cogent3.PhyloNode | cogent3.app.typing.SerialisableType:
return jc_distances(
aln,
num_threads=self._num_threads,
)


@composable.define_app
Expand Down
3 changes: 2 additions & 1 deletion src/piqtree2/_libiqtree/_piqtree2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ extern string modelfinder(vector<string>& names,
* j-th sequence, where n is the number of sequences
*/
extern vector<double> build_distmatrix(vector<string>& names,
vector<string>& seqs);
vector<string>& seqs,
int num_thres);

/*
* Using Rapid-NJ to build tree from a distance matrix
Expand Down
10 changes: 9 additions & 1 deletion src/piqtree2/iqtree/_jc_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,30 @@ def _dists_to_distmatrix(

def jc_distances(
aln: c3_types.AlignedSeqsType,
num_threads: int | None = None,
) -> c3_types.PairwiseDistanceType:
"""Compute pairwise JC distances for a given alignemnt.

Parameters
----------
aln : c3_types.AlignedSeqsType
alignment to compute pairwise JC distances for.
num_threads: int | None, optional
Number of threads for IQ-TREE 2 to use, by default None (all available threads).

Returns
-------
c3_types.PairwiseDistanceType
Pairwise JC distance matrix.

"""
if num_threads is None:
num_threads = 0

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

distances = np.array(iq_jc_distances(names, seqs)).reshape((len(names), len(names)))
distances = np.array(iq_jc_distances(names, seqs, num_threads)).reshape(
(len(names), len(names)),
)
return _dists_to_distmatrix(distances, names)
2 changes: 2 additions & 0 deletions src/piqtree2/iqtree/_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def build_tree(
At least 1000 is required to perform bootstrapping.
num_threads: int | None, optional
Number of threads for IQ-TREE 2 to use, by default None (single-threaded).
If 0 is specified, IQ-TREE attempts to find the optimal number of threads.

Returns
-------
Expand Down Expand Up @@ -281,6 +282,7 @@ def fit_tree(
The random seed - 0 or None means no seed, by default None.
num_threads: int | None, optional
Number of threads for IQ-TREE 2 to use, by default None (single-threaded).
If 0 is specified, IQ-TREE attempts to find the optimal number of threads.

Returns
-------
Expand Down
12 changes: 6 additions & 6 deletions tests/test_app/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@ def test_piqtree_jc_distances(five_otu: ArrayAlignment) -> None:
dists = app(five_otu)

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

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

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


Expand Down
12 changes: 6 additions & 6 deletions tests/test_iqtree/test_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ def test_jc_distance(five_otu: ArrayAlignment) -> None:
dists = jc_distances(five_otu)

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

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

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