phykit 2.1.93__tar.gz → 2.1.94__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {phykit-2.1.93 → phykit-2.1.94}/PKG-INFO +18 -2
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/discrete_models.py +55 -14
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/monophyly_check.py +28 -11
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phylogenetic_signal.py +28 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/trait_correlation.py +28 -0
- phykit-2.1.94/phykit/version.py +1 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit.egg-info/PKG-INFO +18 -2
- phykit-2.1.93/phykit/version.py +0 -1
- {phykit-2.1.93 → phykit-2.1.94}/LICENSE.md +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/README.md +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/__init__.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/__main__.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/cli_registry.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/errors.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/__init__.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/boolean_argument_parsing.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/caching.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/circular_layout.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/color_annotations.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/files.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/geological_timescale.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/json_output.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/parallel.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/parsimony_utils.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/pgls_utils.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/plot_config.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/quartet_utils.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/stats_summary.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/streaming.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/helpers/trait_parsing.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/phykit.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/service_factories.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/__init__.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/__init__.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/alignment_entropy.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/alignment_length.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/alignment_length_no_gaps.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/alignment_outlier_taxa.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/alignment_recoding.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/alignment_subsample.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/base.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/column_score.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/composition_per_taxon.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/compositional_bias_per_site.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/create_concatenation_matrix.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/dfoil.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/dna_threader.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/dstatistic.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/evolutionary_rate_per_site.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/faidx.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/gc_content.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/identity_matrix.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/mask_alignment.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/occupancy_filter.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/occupancy_per_taxon.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/pairwise_identity.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/parsimony_informative_sites.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/phylo_gwas.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/plot_alignment_qc.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/rcv.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/rcvt.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/rename_fasta_entries.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/sum_of_pairs_score.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/taxon_groups.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/alignment/variable_sites.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/base.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/__init__.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/ancestral_reconstruction.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/base.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/bipartition_support_stats.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/branch_length_multiplier.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/character_map.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/chronogram.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/collapse_branches.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/concordance_asr.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/consensus_network.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/consensus_tree.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/cont_map.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/cophylo.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/covarying_evolutionary_rates.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/density_map.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/discordance_asymmetry.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/dtt.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/dvmc.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/evo_tempo_map.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/evolutionary_rate.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/faiths_pd.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/fit_continuous.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/fit_discrete.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/hidden_paralogy_check.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/hybridization.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/independent_contrasts.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/internal_branch_stats.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/internode_labeler.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/kf_distance.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/last_common_ancestor_subtree.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/lb_score.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/ltt.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/nearest_neighbor_interchange.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/neighbor_net.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/network_signal.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/ou_shift_detection.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/ouwie.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/parsimony_score.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/patristic_distances.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phenogram.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phylo_anova.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phylo_heatmap.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phylo_impute.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phylo_logistic.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phylo_path.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phylogenetic_glm.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phylogenetic_ordination.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phylogenetic_regression.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/phylomorphospace.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/polytomy_test.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/print_tree.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/prune_tree.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/quartet_network.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/quartet_pie.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/rate_heterogeneity.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/relative_rate_test.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/rename_tree_tips.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/rf_distance.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/root_tree.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/saturation.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/simmap_summary.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/spectral_discordance.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/spr.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/spurious_sequence.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/stochastic_character_map.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/terminal_branch_stats.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/threshold_model.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/tip_labels.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/tip_to_tip_distance.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/tip_to_tip_node_distance.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/total_tree_length.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/trait_rate_map.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/transfer_annotations.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/tree_space.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/treeness.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/treeness_over_rcv.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit/services/tree/vcv_utils.py +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit.egg-info/SOURCES.txt +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit.egg-info/dependency_links.txt +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit.egg-info/entry_points.txt +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit.egg-info/requires.txt +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/phykit.egg-info/top_level.txt +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/setup.cfg +0 -0
- {phykit-2.1.93 → phykit-2.1.94}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: phykit
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.94
|
|
4
4
|
Home-page: https://github.com/jlsteenwyk/phykit
|
|
5
5
|
Author: Jacob L. Steenwyk
|
|
6
6
|
Author-email: jlsteenwyk@gmail.com
|
|
@@ -15,6 +15,22 @@ Classifier: Topic :: Scientific/Engineering
|
|
|
15
15
|
Requires-Python: >=3.10
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE.md
|
|
18
|
+
Requires-Dist: biopython>=1.82
|
|
19
|
+
Requires-Dist: matplotlib>=3.7.0
|
|
20
|
+
Requires-Dist: numpy>=1.24.0
|
|
21
|
+
Requires-Dist: scipy>=1.11.3
|
|
22
|
+
Requires-Dist: scikit-learn>=1.4.2
|
|
23
|
+
Requires-Dist: umap-learn>=0.5.0
|
|
24
|
+
Requires-Dist: tqdm>=4.65.0
|
|
25
|
+
Dynamic: author
|
|
26
|
+
Dynamic: author-email
|
|
27
|
+
Dynamic: classifier
|
|
28
|
+
Dynamic: description
|
|
29
|
+
Dynamic: description-content-type
|
|
30
|
+
Dynamic: home-page
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
Dynamic: requires-dist
|
|
33
|
+
Dynamic: requires-python
|
|
18
34
|
|
|
19
35
|
<p align="center">
|
|
20
36
|
<a href="https://github.com/jlsteenwyk/phykit">
|
|
@@ -66,6 +66,39 @@ def matrix_exp(Q: np.ndarray, t: float) -> np.ndarray:
|
|
|
66
66
|
return expm(Q * t)
|
|
67
67
|
|
|
68
68
|
|
|
69
|
+
def make_transition_probability_fn(Q: np.ndarray):
|
|
70
|
+
"""Return a callable t -> P(t) = exp(Q * t).
|
|
71
|
+
|
|
72
|
+
The transition probabilities for many branch lengths are needed for every
|
|
73
|
+
likelihood evaluation, so eigendecompose Q once and reconstruct
|
|
74
|
+
P(t) = V @ diag(exp(w * t)) @ V_inv per branch. This is mathematically
|
|
75
|
+
equivalent to scipy's expm but avoids recomputing a full matrix
|
|
76
|
+
exponential (scaling-and-squaring Pade) for every branch, which dominates
|
|
77
|
+
runtime for multi-state models.
|
|
78
|
+
|
|
79
|
+
Falls back to expm when the eigendecomposition is numerically unreliable
|
|
80
|
+
(e.g. a defective / ill-conditioned eigenvector matrix), so results are
|
|
81
|
+
unchanged.
|
|
82
|
+
"""
|
|
83
|
+
try:
|
|
84
|
+
w, V = np.linalg.eig(Q)
|
|
85
|
+
V_inv = np.linalg.inv(V)
|
|
86
|
+
if not (np.all(np.isfinite(V)) and np.all(np.isfinite(V_inv))):
|
|
87
|
+
raise np.linalg.LinAlgError("non-finite eigendecomposition")
|
|
88
|
+
if np.linalg.cond(V) > 1e12:
|
|
89
|
+
raise np.linalg.LinAlgError("ill-conditioned eigenvectors")
|
|
90
|
+
|
|
91
|
+
def P(t: float) -> np.ndarray:
|
|
92
|
+
return np.real((V * np.exp(w * t)) @ V_inv)
|
|
93
|
+
|
|
94
|
+
return P
|
|
95
|
+
except (np.linalg.LinAlgError, ValueError):
|
|
96
|
+
def P(t: float) -> np.ndarray:
|
|
97
|
+
return expm(Q * t)
|
|
98
|
+
|
|
99
|
+
return P
|
|
100
|
+
|
|
101
|
+
|
|
69
102
|
def felsenstein_pruning(
|
|
70
103
|
tree, tip_states: Dict[str, str], Q: np.ndarray,
|
|
71
104
|
pi: np.ndarray, states: List[str]
|
|
@@ -79,6 +112,9 @@ def felsenstein_pruning(
|
|
|
79
112
|
state_idx = {s: i for i, s in enumerate(states)}
|
|
80
113
|
cond_liks = {}
|
|
81
114
|
|
|
115
|
+
# Eigendecompose Q once and reuse it for every branch length.
|
|
116
|
+
transition_probability = make_transition_probability_fn(Q)
|
|
117
|
+
|
|
82
118
|
for clade in tree.find_clades(order="postorder"):
|
|
83
119
|
if clade.is_terminal():
|
|
84
120
|
lik = np.zeros(k)
|
|
@@ -89,7 +125,7 @@ def felsenstein_pruning(
|
|
|
89
125
|
lik = np.ones(k)
|
|
90
126
|
for child in clade.clades:
|
|
91
127
|
t = child.branch_length if child.branch_length else 1e-8
|
|
92
|
-
P =
|
|
128
|
+
P = transition_probability(t)
|
|
93
129
|
child_lik = cond_liks[id(child)]
|
|
94
130
|
lik *= P @ child_lik
|
|
95
131
|
cond_liks[id(clade)] = lik
|
|
@@ -130,27 +166,32 @@ def fit_q_matrix(
|
|
|
130
166
|
best_negll = np.inf
|
|
131
167
|
best_params = np.ones(n_params) * 0.1
|
|
132
168
|
|
|
169
|
+
# Gradient-based multi-start: L-BFGS-B from each starting value is cheap
|
|
170
|
+
# and finds the optimum's basin. Running Nelder-Mead from every start as
|
|
171
|
+
# well is what makes multi-state models (many parameters) slow, since
|
|
172
|
+
# Nelder-Mead needs O(n_params) function evaluations per step; a single
|
|
173
|
+
# Nelder-Mead refinement of the best L-BFGS-B result (below) recovers the
|
|
174
|
+
# same optimum at a fraction of the cost.
|
|
133
175
|
for sv in starting_values:
|
|
134
176
|
x0 = np.ones(n_params) * sv
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
# Refine best result
|
|
177
|
+
try:
|
|
178
|
+
result = minimize(
|
|
179
|
+
neg_loglik, x0, method="L-BFGS-B", bounds=bounds
|
|
180
|
+
)
|
|
181
|
+
if result.fun < best_negll:
|
|
182
|
+
best_negll = result.fun
|
|
183
|
+
best_params = np.abs(result.x)
|
|
184
|
+
except (ValueError, np.linalg.LinAlgError):
|
|
185
|
+
continue
|
|
186
|
+
|
|
187
|
+
# Refine the best result with Nelder-Mead (gradient-free polish).
|
|
148
188
|
try:
|
|
149
189
|
result = minimize(
|
|
150
190
|
neg_loglik, best_params, method="Nelder-Mead",
|
|
151
191
|
options={"maxiter": 10000, "xatol": 1e-10, "fatol": 1e-10},
|
|
152
192
|
)
|
|
153
193
|
if result.fun < best_negll:
|
|
194
|
+
best_negll = result.fun
|
|
154
195
|
best_params = np.abs(result.x)
|
|
155
196
|
except (ValueError, np.linalg.LinAlgError):
|
|
156
197
|
pass
|
|
@@ -64,13 +64,19 @@ class MonophylyCheck(Tree):
|
|
|
64
64
|
def get_bootstrap_statistics(
|
|
65
65
|
self,
|
|
66
66
|
clade: Newick.Clade
|
|
67
|
-
) -> Dict[str, Union[int, float]]:
|
|
67
|
+
) -> Union[Dict[str, Union[int, float]], None]:
|
|
68
68
|
# Use generator for memory efficiency
|
|
69
69
|
bs_vals = [
|
|
70
70
|
terminal.confidence for terminal in clade.get_nonterminals()
|
|
71
71
|
if terminal.confidence is not None
|
|
72
72
|
]
|
|
73
73
|
|
|
74
|
+
# No internal support values to summarize (e.g., a time tree or a
|
|
75
|
+
# tree with no bootstrap labels); return None so callers report "NA"
|
|
76
|
+
# support rather than failing to subscript a missing result.
|
|
77
|
+
if not bs_vals:
|
|
78
|
+
return None
|
|
79
|
+
|
|
74
80
|
return calculate_summary_statistics_from_arr(bs_vals)
|
|
75
81
|
|
|
76
82
|
def populate_res_arr(
|
|
@@ -85,25 +91,36 @@ class MonophylyCheck(Tree):
|
|
|
85
91
|
temp.append("monophyletic")
|
|
86
92
|
else:
|
|
87
93
|
temp.append("not_monophyletic")
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
# stats is None when the tree has no internal support values to
|
|
95
|
+
# summarize; monophyly is still well-defined, so report the status
|
|
96
|
+
# with "NA" support fields rather than crashing.
|
|
97
|
+
if stats is None:
|
|
98
|
+
temp.extend([None, None, None, None])
|
|
99
|
+
else:
|
|
100
|
+
temp.append(stats["mean"])
|
|
101
|
+
temp.append(stats["maximum"])
|
|
102
|
+
temp.append(stats["minimum"])
|
|
103
|
+
temp.append(stats["standard_deviation"])
|
|
92
104
|
temp.append(diff_tips_between_clade_and_curr_tree)
|
|
93
105
|
res_arr.append(temp)
|
|
94
106
|
|
|
95
107
|
return res_arr
|
|
96
108
|
|
|
109
|
+
@staticmethod
|
|
110
|
+
def _fmt_support(value: Union[int, float, None]) -> Union[int, float, str]:
|
|
111
|
+
"""Format a support value, rendering a missing (None) value as "NA"."""
|
|
112
|
+
return "NA" if value is None else round(value, 4)
|
|
113
|
+
|
|
97
114
|
def print_results(self, res_arr: List[List[Union[str, int, float]]]) -> None:
|
|
98
115
|
if self.json_output:
|
|
99
116
|
rows = []
|
|
100
117
|
for res in res_arr:
|
|
101
118
|
row = dict(status=res[0])
|
|
102
119
|
if len(res) > 1:
|
|
103
|
-
row["mean_support"] = round(res[1], 4)
|
|
104
|
-
row["max_support"] = round(res[2], 4)
|
|
105
|
-
row["min_support"] = round(res[3], 4)
|
|
106
|
-
row["stdev_support"] = round(res[4], 4)
|
|
120
|
+
row["mean_support"] = None if res[1] is None else round(res[1], 4)
|
|
121
|
+
row["max_support"] = None if res[2] is None else round(res[2], 4)
|
|
122
|
+
row["min_support"] = None if res[3] is None else round(res[3], 4)
|
|
123
|
+
row["stdev_support"] = None if res[4] is None else round(res[4], 4)
|
|
107
124
|
row["offending_taxa"] = sorted(res[5]) if len(res) > 5 and res[5] else []
|
|
108
125
|
rows.append(row)
|
|
109
126
|
print_json(dict(rows=rows, results=rows))
|
|
@@ -114,11 +131,11 @@ class MonophylyCheck(Tree):
|
|
|
114
131
|
if res[5]:
|
|
115
132
|
res[5].sort()
|
|
116
133
|
print(
|
|
117
|
-
f"{res[0]}\t{
|
|
134
|
+
f"{res[0]}\t{self._fmt_support(res[1])}\t{self._fmt_support(res[2])}\t{self._fmt_support(res[3])}\t{self._fmt_support(res[4])}\t{';'.join(res[5])}"
|
|
118
135
|
)
|
|
119
136
|
else:
|
|
120
137
|
print(
|
|
121
|
-
f"{res[0]}\t{
|
|
138
|
+
f"{res[0]}\t{self._fmt_support(res[1])}\t{self._fmt_support(res[2])}\t{self._fmt_support(res[3])}\t{self._fmt_support(res[4])}"
|
|
122
139
|
)
|
|
123
140
|
except IndexError:
|
|
124
141
|
print(f"{res[0]}")
|
|
@@ -95,6 +95,34 @@ class PhylogeneticSignal(Tree):
|
|
|
95
95
|
|
|
96
96
|
x = np.array([traits[name] for name in ordered_names])
|
|
97
97
|
|
|
98
|
+
if np.var(x) < 1e-12:
|
|
99
|
+
note = (
|
|
100
|
+
"Trait has zero variance across the shared taxa; "
|
|
101
|
+
"phylogenetic signal is undefined."
|
|
102
|
+
)
|
|
103
|
+
print(f"Warning: {note}", file=sys.stderr)
|
|
104
|
+
if self.method == "blombergs_k":
|
|
105
|
+
if self.json_output:
|
|
106
|
+
print_json(
|
|
107
|
+
dict(K=None, p_value=None, r_squared_phylo=None, note=note)
|
|
108
|
+
)
|
|
109
|
+
else:
|
|
110
|
+
print("NA\tNA\tNA")
|
|
111
|
+
else:
|
|
112
|
+
if self.json_output:
|
|
113
|
+
print_json(
|
|
114
|
+
dict(
|
|
115
|
+
lambda_value=None,
|
|
116
|
+
log_likelihood=None,
|
|
117
|
+
p_value=None,
|
|
118
|
+
r_squared_phylo=None,
|
|
119
|
+
note=note,
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
else:
|
|
123
|
+
print("NA\tNA\tNA\tNA")
|
|
124
|
+
return
|
|
125
|
+
|
|
98
126
|
r2_phylo = self._compute_r2_phylo(x, vcv)
|
|
99
127
|
|
|
100
128
|
if self.method == "blombergs_k":
|
|
@@ -3,6 +3,7 @@ Phylogenetic trait correlation: compute phylogenetic correlations between
|
|
|
3
3
|
all pairs of traits and display them as a heatmap with significance
|
|
4
4
|
indicators.
|
|
5
5
|
"""
|
|
6
|
+
import sys
|
|
6
7
|
from typing import Dict, List
|
|
7
8
|
|
|
8
9
|
import numpy as np
|
|
@@ -58,6 +59,33 @@ class TraitCorrelation(Tree):
|
|
|
58
59
|
|
|
59
60
|
Y = np.array([[traits[name][j] for j in range(p)] for name in ordered_names])
|
|
60
61
|
|
|
62
|
+
# Drop invariant (zero-variance) traits: their correlations are
|
|
63
|
+
# undefined (division by a zero standard deviation), which yields
|
|
64
|
+
# NaNs that propagate into the heatmap and crash hierarchical
|
|
65
|
+
# clustering. Warn and continue with the variable traits.
|
|
66
|
+
col_var = np.var(Y, axis=0)
|
|
67
|
+
invariant = [trait_names[j] for j in range(p) if col_var[j] < 1e-12]
|
|
68
|
+
if invariant:
|
|
69
|
+
keep = [j for j in range(p) if col_var[j] >= 1e-12]
|
|
70
|
+
print(
|
|
71
|
+
f"Warning: dropping {len(invariant)} invariant trait(s) "
|
|
72
|
+
f"(zero variance): {', '.join(invariant)}",
|
|
73
|
+
file=sys.stderr,
|
|
74
|
+
)
|
|
75
|
+
Y = Y[:, keep]
|
|
76
|
+
trait_names = [trait_names[j] for j in keep]
|
|
77
|
+
p = len(trait_names)
|
|
78
|
+
if p < 2:
|
|
79
|
+
raise PhykitUserError(
|
|
80
|
+
[
|
|
81
|
+
"Fewer than 2 variable traits remain after dropping "
|
|
82
|
+
"invariant traits.",
|
|
83
|
+
"Trait correlation requires at least 2 traits with "
|
|
84
|
+
"non-zero variance.",
|
|
85
|
+
],
|
|
86
|
+
code=2,
|
|
87
|
+
)
|
|
88
|
+
|
|
61
89
|
# GLS-centered data
|
|
62
90
|
C_inv = np.linalg.inv(vcv)
|
|
63
91
|
ones = np.ones(n)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.1.94"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: phykit
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.94
|
|
4
4
|
Home-page: https://github.com/jlsteenwyk/phykit
|
|
5
5
|
Author: Jacob L. Steenwyk
|
|
6
6
|
Author-email: jlsteenwyk@gmail.com
|
|
@@ -15,6 +15,22 @@ Classifier: Topic :: Scientific/Engineering
|
|
|
15
15
|
Requires-Python: >=3.10
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE.md
|
|
18
|
+
Requires-Dist: biopython>=1.82
|
|
19
|
+
Requires-Dist: matplotlib>=3.7.0
|
|
20
|
+
Requires-Dist: numpy>=1.24.0
|
|
21
|
+
Requires-Dist: scipy>=1.11.3
|
|
22
|
+
Requires-Dist: scikit-learn>=1.4.2
|
|
23
|
+
Requires-Dist: umap-learn>=0.5.0
|
|
24
|
+
Requires-Dist: tqdm>=4.65.0
|
|
25
|
+
Dynamic: author
|
|
26
|
+
Dynamic: author-email
|
|
27
|
+
Dynamic: classifier
|
|
28
|
+
Dynamic: description
|
|
29
|
+
Dynamic: description-content-type
|
|
30
|
+
Dynamic: home-page
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
Dynamic: requires-dist
|
|
33
|
+
Dynamic: requires-python
|
|
18
34
|
|
|
19
35
|
<p align="center">
|
|
20
36
|
<a href="https://github.com/jlsteenwyk/phykit">
|
phykit-2.1.93/phykit/version.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.1.93"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|