phykit 2.2.0__py2.py3-none-any.whl → 2.2.1__py2.py3-none-any.whl
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/helpers/parsimony_utils.py +145 -0
- phykit/phykit.py +32 -3
- phykit/services/tree/character_map.py +172 -29
- phykit/version.py +1 -1
- {phykit-2.2.0.dist-info → phykit-2.2.1.dist-info}/METADATA +1 -1
- {phykit-2.2.0.dist-info → phykit-2.2.1.dist-info}/RECORD +10 -10
- {phykit-2.2.0.dist-info → phykit-2.2.1.dist-info}/WHEEL +0 -0
- {phykit-2.2.0.dist-info → phykit-2.2.1.dist-info}/entry_points.txt +0 -0
- {phykit-2.2.0.dist-info → phykit-2.2.1.dist-info}/licenses/LICENSE.md +0 -0
- {phykit-2.2.0.dist-info → phykit-2.2.1.dist-info}/top_level.txt +0 -0
|
@@ -480,6 +480,151 @@ def _mask_to_state_set(states: tuple[str, ...], mask: int):
|
|
|
480
480
|
)
|
|
481
481
|
|
|
482
482
|
|
|
483
|
+
def sankoff_downpass(
|
|
484
|
+
tree,
|
|
485
|
+
tip_states: dict[str, list[str]],
|
|
486
|
+
) -> tuple[
|
|
487
|
+
dict[int, list[tuple[int, ...]]],
|
|
488
|
+
list[tuple[str, ...]],
|
|
489
|
+
list[int],
|
|
490
|
+
]:
|
|
491
|
+
"""Calculate exact unordered-parsimony costs on any tree topology.
|
|
492
|
+
|
|
493
|
+
Unlike the optimized Fitch path, this dynamic program handles nodes with
|
|
494
|
+
any number of children without introducing arbitrary binary resolutions.
|
|
495
|
+
Missing states (``?`` and ``-``) are compatible with every observed state.
|
|
496
|
+
"""
|
|
497
|
+
n_chars = len(next(iter(tip_states.values())))
|
|
498
|
+
wildcard = {"?", "-"}
|
|
499
|
+
observed_states = [set() for _ in range(n_chars)]
|
|
500
|
+
for states in tip_states.values():
|
|
501
|
+
for index, state in enumerate(states):
|
|
502
|
+
if state not in wildcard:
|
|
503
|
+
observed_states[index].add(state)
|
|
504
|
+
|
|
505
|
+
states_by_char = [
|
|
506
|
+
tuple(sorted(states)) if states else ("?",)
|
|
507
|
+
for states in observed_states
|
|
508
|
+
]
|
|
509
|
+
state_indexes = [
|
|
510
|
+
{state: index for index, state in enumerate(states)}
|
|
511
|
+
for states in states_by_char
|
|
512
|
+
]
|
|
513
|
+
|
|
514
|
+
clades = _postorder_clades_direct(tree)
|
|
515
|
+
if clades is None:
|
|
516
|
+
clades = list(tree.find_clades(order="postorder"))
|
|
517
|
+
unreachable = len(clades) + 1
|
|
518
|
+
node_costs: dict[int, list[tuple[int, ...]]] = {}
|
|
519
|
+
|
|
520
|
+
for clade in clades:
|
|
521
|
+
cid = id(clade)
|
|
522
|
+
children = clade.clades
|
|
523
|
+
if not children:
|
|
524
|
+
costs_by_char = []
|
|
525
|
+
for index, state in enumerate(tip_states[clade.name]):
|
|
526
|
+
state_count = len(states_by_char[index])
|
|
527
|
+
if state in wildcard:
|
|
528
|
+
costs_by_char.append((0,) * state_count)
|
|
529
|
+
continue
|
|
530
|
+
|
|
531
|
+
observed_index = state_indexes[index][state]
|
|
532
|
+
costs_by_char.append(
|
|
533
|
+
tuple(
|
|
534
|
+
0 if candidate == observed_index else unreachable
|
|
535
|
+
for candidate in range(state_count)
|
|
536
|
+
)
|
|
537
|
+
)
|
|
538
|
+
node_costs[cid] = costs_by_char
|
|
539
|
+
continue
|
|
540
|
+
|
|
541
|
+
child_costs = [node_costs[id(child)] for child in children]
|
|
542
|
+
costs_by_char = []
|
|
543
|
+
for char_index, states in enumerate(states_by_char):
|
|
544
|
+
state_count = len(states)
|
|
545
|
+
parent_costs = []
|
|
546
|
+
for parent_index in range(state_count):
|
|
547
|
+
total = 0
|
|
548
|
+
for child in child_costs:
|
|
549
|
+
child_char_costs = child[char_index]
|
|
550
|
+
total += min(
|
|
551
|
+
cost + (child_index != parent_index)
|
|
552
|
+
for child_index, cost in enumerate(child_char_costs)
|
|
553
|
+
)
|
|
554
|
+
parent_costs.append(total)
|
|
555
|
+
costs_by_char.append(tuple(parent_costs))
|
|
556
|
+
node_costs[cid] = costs_by_char
|
|
557
|
+
|
|
558
|
+
root_costs = node_costs[id(tree.root)]
|
|
559
|
+
scores = [min(costs) for costs in root_costs]
|
|
560
|
+
return node_costs, states_by_char, scores
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
def sankoff_uppass(
|
|
564
|
+
tree,
|
|
565
|
+
node_costs: dict[int, list[tuple[int, ...]]],
|
|
566
|
+
states_by_char: list[tuple[str, ...]],
|
|
567
|
+
parent_map: dict[int, object],
|
|
568
|
+
optimization: str = "acctran",
|
|
569
|
+
) -> dict[int, list[str]]:
|
|
570
|
+
"""Trace back one deterministic, globally optimal reconstruction.
|
|
571
|
+
|
|
572
|
+
DELTRAN prefers inheriting the parent state when a tie permits delaying a
|
|
573
|
+
change. ACCTRAN prefers a different child state when a tie permits moving
|
|
574
|
+
that change toward the root. Root ties use lexical state order for stable
|
|
575
|
+
output independent of child order.
|
|
576
|
+
"""
|
|
577
|
+
node_states: dict[int, list[str]] = {}
|
|
578
|
+
root = tree.root
|
|
579
|
+
root_costs = node_costs[id(root)]
|
|
580
|
+
node_states[id(root)] = [
|
|
581
|
+
states[min_costs.index(min(min_costs))]
|
|
582
|
+
for states, min_costs in zip(states_by_char, root_costs)
|
|
583
|
+
]
|
|
584
|
+
|
|
585
|
+
clades = _preorder_clades_direct(tree)
|
|
586
|
+
if clades is None:
|
|
587
|
+
clades = list(tree.find_clades(order="preorder"))
|
|
588
|
+
|
|
589
|
+
delay_changes = optimization == "deltran"
|
|
590
|
+
for clade in clades:
|
|
591
|
+
if clade == root:
|
|
592
|
+
continue
|
|
593
|
+
|
|
594
|
+
cid = id(clade)
|
|
595
|
+
parent_states = node_states[id(parent_map[cid])]
|
|
596
|
+
costs_by_char = node_costs[cid]
|
|
597
|
+
assigned = []
|
|
598
|
+
for states, costs, parent_state in zip(
|
|
599
|
+
states_by_char,
|
|
600
|
+
costs_by_char,
|
|
601
|
+
parent_states,
|
|
602
|
+
):
|
|
603
|
+
transition_costs = [
|
|
604
|
+
cost + (state != parent_state)
|
|
605
|
+
for state, cost in zip(states, costs)
|
|
606
|
+
]
|
|
607
|
+
best_cost = min(transition_costs)
|
|
608
|
+
candidates = [
|
|
609
|
+
state
|
|
610
|
+
for state, cost in zip(states, transition_costs)
|
|
611
|
+
if cost == best_cost
|
|
612
|
+
]
|
|
613
|
+
if delay_changes and parent_state in candidates:
|
|
614
|
+
assigned.append(parent_state)
|
|
615
|
+
continue
|
|
616
|
+
|
|
617
|
+
changed_candidates = [
|
|
618
|
+
state for state in candidates if state != parent_state
|
|
619
|
+
]
|
|
620
|
+
assigned.append(
|
|
621
|
+
changed_candidates[0] if changed_candidates else candidates[0]
|
|
622
|
+
)
|
|
623
|
+
node_states[cid] = assigned
|
|
624
|
+
|
|
625
|
+
return node_states
|
|
626
|
+
|
|
627
|
+
|
|
483
628
|
def fitch_uppass_acctran(
|
|
484
629
|
tree,
|
|
485
630
|
node_state_sets: dict[int, list[set[str]]],
|
phykit/phykit.py
CHANGED
|
@@ -3011,7 +3011,7 @@ class Phykit:
|
|
|
3011
3011
|
{help_header}
|
|
3012
3012
|
|
|
3013
3013
|
Map discrete character changes onto a phylogenetic tree
|
|
3014
|
-
using
|
|
3014
|
+
using unordered parsimony, classifying each change as a
|
|
3015
3015
|
synapomorphy, convergence, or reversal.
|
|
3016
3016
|
|
|
3017
3017
|
Two optimization strategies are supported:
|
|
@@ -3023,7 +3023,11 @@ class Phykit:
|
|
|
3023
3023
|
Output is a cladogram (default) or phylogram (with
|
|
3024
3024
|
--phylogram) annotated with colored circles indicating
|
|
3025
3025
|
character state changes on each branch. Polytomies are
|
|
3026
|
-
|
|
3026
|
+
retained and analyzed directly.
|
|
3027
|
+
|
|
3028
|
+
Tree and matrix taxon labels are matched exactly and are
|
|
3029
|
+
case-sensitive. Mismatches are errors unless
|
|
3030
|
+
--allow-taxon-mismatch is specified.
|
|
3027
3031
|
|
|
3028
3032
|
Summary statistics include tree length (total parsimony
|
|
3029
3033
|
steps), consistency index (CI), and retention index (RI).
|
|
@@ -3036,7 +3040,9 @@ class Phykit:
|
|
|
3036
3040
|
Usage:
|
|
3037
3041
|
phykit character_map -t <tree> -d <data> -o <output>
|
|
3038
3042
|
[--optimization acctran|deltran] [--phylogram]
|
|
3039
|
-
[--characters 0,1,3] [--
|
|
3043
|
+
[--characters 0,1,3] [--allow-taxon-mismatch]
|
|
3044
|
+
[--change-marker-size <float>] [--change-fontsize <float>]
|
|
3045
|
+
[--verbose] [--json]
|
|
3040
3046
|
[--fig-width <float>] [--fig-height <float>]
|
|
3041
3047
|
[--dpi <int>] [--no-title] [--title <str>]
|
|
3042
3048
|
[--legend-position <str>]
|
|
@@ -3067,6 +3073,17 @@ class Phykit:
|
|
|
3067
3073
|
plot (e.g., 0,1,3); all
|
|
3068
3074
|
characters shown by default
|
|
3069
3075
|
|
|
3076
|
+
--allow-taxon-mismatch warn and analyze only taxa shared
|
|
3077
|
+
by the tree and character matrix;
|
|
3078
|
+
mismatches are errors by default
|
|
3079
|
+
|
|
3080
|
+
--change-marker-size character-change circle size in
|
|
3081
|
+
points squared; must be positive
|
|
3082
|
+
|
|
3083
|
+
--change-fontsize font size for character indices
|
|
3084
|
+
and state transitions; must be
|
|
3085
|
+
positive
|
|
3086
|
+
|
|
3070
3087
|
--verbose print per-character details
|
|
3071
3088
|
including CI/RI and changes
|
|
3072
3089
|
|
|
@@ -3095,6 +3112,18 @@ class Phykit:
|
|
|
3095
3112
|
"--characters", type=str, default=None,
|
|
3096
3113
|
required=False, help=SUPPRESS, metavar=""
|
|
3097
3114
|
)
|
|
3115
|
+
parser.add_argument(
|
|
3116
|
+
"--allow-taxon-mismatch", action="store_true",
|
|
3117
|
+
required=False, help=SUPPRESS,
|
|
3118
|
+
)
|
|
3119
|
+
parser.add_argument(
|
|
3120
|
+
"--change-marker-size", type=float, default=None,
|
|
3121
|
+
required=False, help=SUPPRESS, metavar="",
|
|
3122
|
+
)
|
|
3123
|
+
parser.add_argument(
|
|
3124
|
+
"--change-fontsize", type=float, default=None,
|
|
3125
|
+
required=False, help=SUPPRESS, metavar="",
|
|
3126
|
+
)
|
|
3098
3127
|
parser.add_argument(
|
|
3099
3128
|
"--verbose", action="store_true", required=False, help=SUPPRESS
|
|
3100
3129
|
)
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Character mapping on a phylogenetic tree.
|
|
3
3
|
|
|
4
|
-
Performs
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
Performs unordered parsimony reconstruction on a discrete character matrix,
|
|
5
|
+
using optimized Fitch reconstruction for binary trees and exact Sankoff costs
|
|
6
|
+
for multifurcations. Classifies changes as synapomorphies, convergences, or
|
|
7
|
+
reversals and produces a phylogram/cladogram plot with annotated changes.
|
|
7
8
|
|
|
8
9
|
Uses the generalized parsimony utilities in phykit.helpers.parsimony_utils.
|
|
9
10
|
"""
|
|
@@ -39,10 +40,6 @@ def build_parent_map(*args, **kwargs):
|
|
|
39
40
|
return _parsimony_utils().build_parent_map(*args, **kwargs)
|
|
40
41
|
|
|
41
42
|
|
|
42
|
-
def resolve_polytomies(*args, **kwargs):
|
|
43
|
-
return _parsimony_utils().resolve_polytomies(*args, **kwargs)
|
|
44
|
-
|
|
45
|
-
|
|
46
43
|
def fitch_downpass(*args, **kwargs):
|
|
47
44
|
return _parsimony_utils().fitch_downpass(*args, **kwargs)
|
|
48
45
|
|
|
@@ -55,6 +52,14 @@ def fitch_uppass_deltran(*args, **kwargs):
|
|
|
55
52
|
return _parsimony_utils().fitch_uppass_deltran(*args, **kwargs)
|
|
56
53
|
|
|
57
54
|
|
|
55
|
+
def sankoff_downpass(*args, **kwargs):
|
|
56
|
+
return _parsimony_utils().sankoff_downpass(*args, **kwargs)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def sankoff_uppass(*args, **kwargs):
|
|
60
|
+
return _parsimony_utils().sankoff_uppass(*args, **kwargs)
|
|
61
|
+
|
|
62
|
+
|
|
58
63
|
def detect_changes(*args, **kwargs):
|
|
59
64
|
return _parsimony_utils().detect_changes(*args, **kwargs)
|
|
60
65
|
|
|
@@ -76,6 +81,9 @@ class CharacterMap(Tree):
|
|
|
76
81
|
self.optimization = parsed["optimization"]
|
|
77
82
|
self.phylogram = parsed["phylogram"]
|
|
78
83
|
self.characters_filter = parsed["characters_filter"]
|
|
84
|
+
self.allow_taxon_mismatch = parsed["allow_taxon_mismatch"]
|
|
85
|
+
self.change_marker_size = parsed["change_marker_size"]
|
|
86
|
+
self.change_fontsize = parsed["change_fontsize"]
|
|
79
87
|
self.verbose = parsed["verbose"]
|
|
80
88
|
self.json_output = parsed["json_output"]
|
|
81
89
|
self.plot_config = parsed["plot_config"]
|
|
@@ -89,6 +97,18 @@ class CharacterMap(Tree):
|
|
|
89
97
|
if chars_str is not None:
|
|
90
98
|
characters_filter = [int(c.strip()) for c in chars_str.split(",")]
|
|
91
99
|
|
|
100
|
+
change_marker_size = getattr(args, "change_marker_size", None)
|
|
101
|
+
change_fontsize = getattr(args, "change_fontsize", None)
|
|
102
|
+
for option, value in (
|
|
103
|
+
("--change-marker-size", change_marker_size),
|
|
104
|
+
("--change-fontsize", change_fontsize),
|
|
105
|
+
):
|
|
106
|
+
if value is not None and value <= 0:
|
|
107
|
+
raise PhykitUserError(
|
|
108
|
+
[f"{option} must be greater than 0."],
|
|
109
|
+
code=2,
|
|
110
|
+
)
|
|
111
|
+
|
|
92
112
|
return dict(
|
|
93
113
|
tree_file_path=args.tree,
|
|
94
114
|
data_path=args.data,
|
|
@@ -96,6 +116,9 @@ class CharacterMap(Tree):
|
|
|
96
116
|
optimization=getattr(args, "optimization", "acctran"),
|
|
97
117
|
phylogram=getattr(args, "phylogram", False),
|
|
98
118
|
characters_filter=characters_filter,
|
|
119
|
+
allow_taxon_mismatch=getattr(args, "allow_taxon_mismatch", False),
|
|
120
|
+
change_marker_size=change_marker_size,
|
|
121
|
+
change_fontsize=change_fontsize,
|
|
99
122
|
verbose=getattr(args, "verbose", False),
|
|
100
123
|
json_output=getattr(args, "json", False),
|
|
101
124
|
plot_config=PlotConfig.from_args(args),
|
|
@@ -111,6 +134,7 @@ class CharacterMap(Tree):
|
|
|
111
134
|
shared_count, tips_to_prune, tip_states = self._shared_character_taxa_setup(
|
|
112
135
|
tree_tip_names,
|
|
113
136
|
tip_states,
|
|
137
|
+
allow_taxon_mismatch=self.allow_taxon_mismatch,
|
|
114
138
|
)
|
|
115
139
|
if shared_count < 3:
|
|
116
140
|
raise PhykitUserError(
|
|
@@ -122,26 +146,20 @@ class CharacterMap(Tree):
|
|
|
122
146
|
)
|
|
123
147
|
|
|
124
148
|
preorder_clades = list(self._iter_preorder(tree.root))
|
|
125
|
-
|
|
149
|
+
has_multifurcation = any(
|
|
126
150
|
len(clade.clades) > 2 for clade in preorder_clades
|
|
127
151
|
)
|
|
128
152
|
needs_branch_length_fill = any(
|
|
129
153
|
clade.branch_length is None for clade in preorder_clades
|
|
130
154
|
)
|
|
131
155
|
needs_working_copy = bool(tips_to_prune) or (
|
|
132
|
-
|
|
133
|
-
or needs_branch_length_fill
|
|
134
|
-
or self.plot_config.ladderize
|
|
156
|
+
needs_branch_length_fill or self.plot_config.ladderize
|
|
135
157
|
)
|
|
136
158
|
if needs_working_copy:
|
|
137
159
|
tree = self._fast_copy(tree)
|
|
138
160
|
if tips_to_prune:
|
|
139
161
|
tree = self.prune_tree_using_taxa_list(tree, tips_to_prune)
|
|
140
162
|
|
|
141
|
-
# Resolve polytomies
|
|
142
|
-
if needs_polytomy_resolution:
|
|
143
|
-
resolve_polytomies(tree)
|
|
144
|
-
|
|
145
163
|
# Ladderize if requested
|
|
146
164
|
if self.plot_config.ladderize:
|
|
147
165
|
tree.ladderize()
|
|
@@ -155,14 +173,33 @@ class CharacterMap(Tree):
|
|
|
155
173
|
# Build parent map
|
|
156
174
|
parent_map = build_parent_map(tree)
|
|
157
175
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
node_states =
|
|
176
|
+
if has_multifurcation:
|
|
177
|
+
node_costs, states_by_char, scores = sankoff_downpass(
|
|
178
|
+
tree,
|
|
179
|
+
tip_states,
|
|
180
|
+
)
|
|
181
|
+
node_states = sankoff_uppass(
|
|
182
|
+
tree,
|
|
183
|
+
node_costs,
|
|
184
|
+
states_by_char,
|
|
185
|
+
parent_map,
|
|
186
|
+
optimization=self.optimization,
|
|
187
|
+
)
|
|
164
188
|
else:
|
|
165
|
-
|
|
189
|
+
# Keep the optimized Fitch implementation for binary trees.
|
|
190
|
+
node_state_sets, scores = fitch_downpass(tree, tip_states)
|
|
191
|
+
if self.optimization == "deltran":
|
|
192
|
+
node_states = fitch_uppass_deltran(
|
|
193
|
+
tree,
|
|
194
|
+
node_state_sets,
|
|
195
|
+
parent_map,
|
|
196
|
+
)
|
|
197
|
+
else:
|
|
198
|
+
node_states = fitch_uppass_acctran(
|
|
199
|
+
tree,
|
|
200
|
+
node_state_sets,
|
|
201
|
+
parent_map,
|
|
202
|
+
)
|
|
166
203
|
|
|
167
204
|
# Detect and classify changes
|
|
168
205
|
branch_changes = detect_changes(tree, node_states, parent_map)
|
|
@@ -219,21 +256,98 @@ class CharacterMap(Tree):
|
|
|
219
256
|
)
|
|
220
257
|
|
|
221
258
|
@staticmethod
|
|
222
|
-
def _shared_character_taxa_setup(
|
|
223
|
-
|
|
259
|
+
def _shared_character_taxa_setup(
|
|
260
|
+
tree_tip_names: list[str],
|
|
261
|
+
tip_states: dict,
|
|
262
|
+
allow_taxon_mismatch: bool = False,
|
|
263
|
+
):
|
|
264
|
+
"""Validate taxa and optionally return their shared subset."""
|
|
224
265
|
state_count = len(tip_states)
|
|
225
266
|
if state_count >= 3 and len(tree_tip_names) == state_count:
|
|
226
267
|
if tree_tip_names[0] == next(iter(tip_states)):
|
|
227
268
|
if tree_tip_names[-1] == next(reversed(tip_states)):
|
|
228
269
|
state_names = list(tip_states)
|
|
229
270
|
if state_names == tree_tip_names:
|
|
271
|
+
# Matrix parsing has already rejected empty and duplicate
|
|
272
|
+
# labels, so an exact ordered match proves the tree labels
|
|
273
|
+
# have those properties as well.
|
|
230
274
|
return state_count, [], tip_states
|
|
231
275
|
|
|
276
|
+
unnamed_tips = sum(
|
|
277
|
+
1
|
|
278
|
+
for name in tree_tip_names
|
|
279
|
+
if not isinstance(name, str) or not name.strip()
|
|
280
|
+
)
|
|
281
|
+
if unnamed_tips:
|
|
282
|
+
raise PhykitUserError(
|
|
283
|
+
[
|
|
284
|
+
f"Tree contains {unnamed_tips} empty or unnamed taxon labels.",
|
|
285
|
+
"Every tree tip must have a unique, non-empty name.",
|
|
286
|
+
],
|
|
287
|
+
code=2,
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
duplicate_tree_tips = sorted(
|
|
291
|
+
name
|
|
292
|
+
for name, count in Counter(tree_tip_names).items()
|
|
293
|
+
if count > 1
|
|
294
|
+
)
|
|
295
|
+
if duplicate_tree_tips:
|
|
296
|
+
raise PhykitUserError(
|
|
297
|
+
[
|
|
298
|
+
f"Tree contains duplicate taxon labels: "
|
|
299
|
+
f"{', '.join(duplicate_tree_tips)}",
|
|
300
|
+
"Every tree tip must have a unique name.",
|
|
301
|
+
],
|
|
302
|
+
code=2,
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
empty_matrix_taxa = [
|
|
306
|
+
name
|
|
307
|
+
for name in tip_states
|
|
308
|
+
if not isinstance(name, str) or not name.strip()
|
|
309
|
+
]
|
|
310
|
+
if empty_matrix_taxa:
|
|
311
|
+
raise PhykitUserError(
|
|
312
|
+
["Character matrix contains an empty taxon label."],
|
|
313
|
+
code=2,
|
|
314
|
+
)
|
|
315
|
+
|
|
232
316
|
tree_tips = set(tree_tip_names)
|
|
233
317
|
matrix_taxa = set(tip_states)
|
|
234
318
|
shared = tree_tips & matrix_taxa
|
|
319
|
+
tree_only = tree_tips - matrix_taxa
|
|
320
|
+
matrix_only = matrix_taxa - tree_tips
|
|
321
|
+
if not tree_only and not matrix_only:
|
|
322
|
+
return len(shared), [], tip_states
|
|
323
|
+
|
|
324
|
+
tree_only_text = ", ".join(sorted(tree_only)) if tree_only else "none"
|
|
325
|
+
matrix_only_text = ", ".join(sorted(matrix_only)) if matrix_only else "none"
|
|
326
|
+
tree_taxon_word = "taxon" if len(tree_only) == 1 else "taxa"
|
|
327
|
+
matrix_taxon_word = "taxon" if len(matrix_only) == 1 else "taxa"
|
|
328
|
+
difference_messages = [
|
|
329
|
+
"Taxon labels differ between the tree and character matrix.",
|
|
330
|
+
f"{len(tree_only)} {tree_taxon_word} in tree but not in character matrix: "
|
|
331
|
+
f"{tree_only_text}",
|
|
332
|
+
f"{len(matrix_only)} {matrix_taxon_word} in character matrix but not in tree: "
|
|
333
|
+
f"{matrix_only_text}",
|
|
334
|
+
]
|
|
335
|
+
if not allow_taxon_mismatch:
|
|
336
|
+
difference_messages.append(
|
|
337
|
+
"Use --allow-taxon-mismatch to analyze only shared taxa."
|
|
338
|
+
)
|
|
339
|
+
raise PhykitUserError(difference_messages, code=2)
|
|
340
|
+
|
|
341
|
+
import sys
|
|
342
|
+
|
|
343
|
+
for message in difference_messages[1:]:
|
|
344
|
+
print(f"Warning: {message}", file=sys.stderr)
|
|
235
345
|
tips_to_prune = [tip for tip in tree_tip_names if tip not in shared]
|
|
236
|
-
filtered_states = {
|
|
346
|
+
filtered_states = {
|
|
347
|
+
taxon: states
|
|
348
|
+
for taxon, states in tip_states.items()
|
|
349
|
+
if taxon in shared
|
|
350
|
+
}
|
|
237
351
|
return len(shared), tips_to_prune, filtered_states
|
|
238
352
|
|
|
239
353
|
@staticmethod
|
|
@@ -515,6 +629,19 @@ class CharacterMap(Tree):
|
|
|
515
629
|
fields = line.rstrip("\n\r").split("\t")
|
|
516
630
|
taxon = fields[0]
|
|
517
631
|
states = fields[1:]
|
|
632
|
+
if not taxon.strip():
|
|
633
|
+
raise PhykitUserError(
|
|
634
|
+
[f"Row {row_num} has an empty taxon label."],
|
|
635
|
+
code=2,
|
|
636
|
+
)
|
|
637
|
+
if taxon in tip_states:
|
|
638
|
+
raise PhykitUserError(
|
|
639
|
+
[
|
|
640
|
+
f"Row {row_num} contains duplicate taxon label "
|
|
641
|
+
f"'{taxon}'."
|
|
642
|
+
],
|
|
643
|
+
code=2,
|
|
644
|
+
)
|
|
518
645
|
if len(states) != n_expected:
|
|
519
646
|
raise PhykitUserError(
|
|
520
647
|
[
|
|
@@ -822,8 +949,16 @@ class CharacterMap(Tree):
|
|
|
822
949
|
|
|
823
950
|
# Character change circles on branches
|
|
824
951
|
# Smaller markers in circular mode — radial branches are shorter
|
|
825
|
-
marker_size =
|
|
826
|
-
|
|
952
|
+
marker_size = (
|
|
953
|
+
self.change_marker_size
|
|
954
|
+
if self.change_marker_size is not None
|
|
955
|
+
else max(10, min(50, 300 / max(n_tips, 1)))
|
|
956
|
+
)
|
|
957
|
+
change_fontsize = (
|
|
958
|
+
self.change_fontsize
|
|
959
|
+
if self.change_fontsize is not None
|
|
960
|
+
else max(3.0, min(5.0, 6.0 - n_tips * 0.03))
|
|
961
|
+
)
|
|
827
962
|
|
|
828
963
|
filter_set = set(self.characters_filter) if self.characters_filter else None
|
|
829
964
|
change_x = []
|
|
@@ -993,8 +1128,16 @@ class CharacterMap(Tree):
|
|
|
993
1128
|
# Character change circles on branches
|
|
994
1129
|
# Use scatter (marker size in points²) so circles stay round
|
|
995
1130
|
# regardless of axis aspect ratio.
|
|
996
|
-
marker_size =
|
|
997
|
-
|
|
1131
|
+
marker_size = (
|
|
1132
|
+
self.change_marker_size
|
|
1133
|
+
if self.change_marker_size is not None
|
|
1134
|
+
else max(15, min(80, 600 / max(n_tips, 1)))
|
|
1135
|
+
)
|
|
1136
|
+
change_fontsize = (
|
|
1137
|
+
self.change_fontsize
|
|
1138
|
+
if self.change_fontsize is not None
|
|
1139
|
+
else max(3.0, min(6.0, 7.0 - n_tips * 0.03))
|
|
1140
|
+
)
|
|
998
1141
|
|
|
999
1142
|
# Filter characters if requested
|
|
1000
1143
|
filter_set = set(self.characters_filter) if self.characters_filter else None
|
phykit/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.2.
|
|
1
|
+
__version__ = "2.2.1"
|
|
@@ -2,9 +2,9 @@ phykit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
2
2
|
phykit/__main__.py,sha256=MzdAR5Hr3qbi9RHclUC5FbmVRmANm4sq8G61awiBsnQ,102
|
|
3
3
|
phykit/cli_registry.py,sha256=OCr_nOYKNdz3l49R5X8hgS9ZxzZFtBfE7aFNhyvaM9Q,8345
|
|
4
4
|
phykit/errors.py,sha256=-FalnuOuQPFDo-Dz7CcqGlF7FpT4ka-gMVC_ikd8n8A,295
|
|
5
|
-
phykit/phykit.py,sha256=
|
|
5
|
+
phykit/phykit.py,sha256=_q7C3TyyOv1WX1imWcjnX2j833AYhmYP4EdiPDSOo8g,425404
|
|
6
6
|
phykit/service_factories.py,sha256=J5HRZGDPlWV23NuyZYVmHi19-Yd4dNOgxSdSLOwL_Tw,11236
|
|
7
|
-
phykit/version.py,sha256=
|
|
7
|
+
phykit/version.py,sha256=4dqvKTDgbqeyzbWj6hYiNdzxsI8j1YOKSLM8vF6a0j4,22
|
|
8
8
|
phykit/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
phykit/helpers/boolean_argument_parsing.py,sha256=t55jJae5CjBH9PvyCH88NqJrlQPE6tGG_XSqi-DL8-4,303
|
|
10
10
|
phykit/helpers/caching.py,sha256=te2f0tiTbZ_R4tg9qM5YPcbII9di17ozq0P2bFNXgNI,7296
|
|
@@ -15,7 +15,7 @@ phykit/helpers/files.py,sha256=D-lCSN29JM9S_i13Pqb0DNOW_q8AU0Nn1pLUmmZNhLw,7633
|
|
|
15
15
|
phykit/helpers/geological_timescale.py,sha256=4KwvmTvOym_gbebSIXy37BhaqGiC_UwvSOXb4qyifLw,3381
|
|
16
16
|
phykit/helpers/json_output.py,sha256=YRrNnVwOGMVv9iVmORzw9MzaoY5d41swkHRXWUfo56Q,3712
|
|
17
17
|
phykit/helpers/parallel.py,sha256=3uC7T2tPnTJqWLtxfwHn8lqz5vFEPl5Kq5m37roGXcw,11481
|
|
18
|
-
phykit/helpers/parsimony_utils.py,sha256=
|
|
18
|
+
phykit/helpers/parsimony_utils.py,sha256=l3H1CkIl4N5XvzYRdx3L39XUseN099Cy-c0SEWnsguE,32709
|
|
19
19
|
phykit/helpers/pgls_utils.py,sha256=TZItP1_9Pt18kwsHYhmmA56glTdgbHKC2h-7QmOdK2Y,9914
|
|
20
20
|
phykit/helpers/plot_config.py,sha256=hyO0oVGWNnoU0wZ2lXjP5XCXupKu2fdrZxZLJ9e0Yuw,23463
|
|
21
21
|
phykit/helpers/quartet_utils.py,sha256=tID4u0DrgMYvHcoqZ4hUmoVk0VeN_Z9yFOs7Cuuvx0Y,9051
|
|
@@ -63,7 +63,7 @@ phykit/services/tree/ancestral_reconstruction.py,sha256=PTDDz9NBUzk95unaefx7HmZH
|
|
|
63
63
|
phykit/services/tree/base.py,sha256=cMUxPtdNwIQl6qNLTX9wAMuMW4VzZQNrwW4G3Xz5pZE,44568
|
|
64
64
|
phykit/services/tree/bipartition_support_stats.py,sha256=M-eAK8NwLDpVtVfXmFyv20xUz8tleXUFHA38osr0gAQ,17556
|
|
65
65
|
phykit/services/tree/branch_length_multiplier.py,sha256=gOZ1s2r6KCjkK2CSu-GwvDaPd1PVFomdVZE6lJwXUhM,3787
|
|
66
|
-
phykit/services/tree/character_map.py,sha256=
|
|
66
|
+
phykit/services/tree/character_map.py,sha256=FO_i36sMq1PRmwdYYaoJRdnLggIK9MyXiGgieHycapE,47000
|
|
67
67
|
phykit/services/tree/chronogram.py,sha256=yS-YG66B5Y4fGuGxcxt2uK7HN6Xdbpf6NIvZ5SZJBX4,32636
|
|
68
68
|
phykit/services/tree/collapse_branches.py,sha256=frW0velnxqGLROZCLtkyAiY1m9YitkRmeKr70RpgeAM,5230
|
|
69
69
|
phykit/services/tree/concordance_asr.py,sha256=BvCLkVBkV2vHeO94xzwLZ8lDnlWxvm98It6If6CTm4s,51326
|
|
@@ -138,9 +138,9 @@ phykit/services/tree/tree_space.py,sha256=lyaGbGZ4M7Gxf0bD2tmHihvwQ4dwUM7VgOJ44I
|
|
|
138
138
|
phykit/services/tree/treeness.py,sha256=rQ1lTRYeVIC5SYDJeZkD-RJUX4BJn88aYy3FeShr3qg,1276
|
|
139
139
|
phykit/services/tree/treeness_over_rcv.py,sha256=S3RemfNPCh7XDmh3ln7PSPtUFBM0VNXeEt42d2_-IOU,1833
|
|
140
140
|
phykit/services/tree/vcv_utils.py,sha256=ZoighEYpNpnnB25zD4fIHpdt-JGqBnpSNgvCYa4teV0,25102
|
|
141
|
-
phykit-2.2.
|
|
142
|
-
phykit-2.2.
|
|
143
|
-
phykit-2.2.
|
|
144
|
-
phykit-2.2.
|
|
145
|
-
phykit-2.2.
|
|
146
|
-
phykit-2.2.
|
|
141
|
+
phykit-2.2.1.dist-info/licenses/LICENSE.md,sha256=S5sMP_xz_OTEdzTX7xK9cLnSzcSjv3asDzo17b4sPZ4,1078
|
|
142
|
+
phykit-2.2.1.dist-info/METADATA,sha256=oJ9FRwx2HP5dyRUX7aT-OH9TlrxLC-x4ysfWLTU7arM,5479
|
|
143
|
+
phykit-2.2.1.dist-info/WHEEL,sha256=qWEHOWeXof9kJLXAXJ1hukQ_MvVtaV9UUAew6N7Y99E,109
|
|
144
|
+
phykit-2.2.1.dist-info/entry_points.txt,sha256=3OtpVc-na-sO3M7KBiUafBrCARjhST5PKjZJGZvKSq0,10155
|
|
145
|
+
phykit-2.2.1.dist-info/top_level.txt,sha256=bOMmJQrzcB3UDlMLE7OeP__Ek0x3D6KlKUI4XhDw-0U,7
|
|
146
|
+
phykit-2.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|