phykit 2.2.0__py2.py3-none-any.whl → 2.3.0__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/cli_registry.py CHANGED
@@ -46,6 +46,10 @@ ALIAS_TO_HANDLER: dict[str, str] = {
46
46
  "seqid": "identity_matrix",
47
47
  "comp_taxon": "composition_per_taxon",
48
48
  "comp_tax": "composition_per_taxon",
49
+ "codon_dnds": "codon_dnds",
50
+ "dnds": "codon_dnds",
51
+ "dn_ds": "codon_dnds",
52
+ "kaks": "codon_dnds",
49
53
  "pis": "parsimony_informative_sites",
50
54
  "rel_comp_var": "rcv",
51
55
  "relative_composition_variability": "rcv",
@@ -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
@@ -546,6 +546,9 @@ class Phykit:
546
546
  - detects site-wise compositional biases in an alignment
547
547
  composition_per_taxon (alias: comp_taxon; comp_tax)
548
548
  - calculates sequence composition per taxon
549
+ codon_dnds (alias: dnds; dn_ds; kaks)
550
+ - estimate pairwise nonsynonymous and synonymous
551
+ substitution rates from a codon alignment
549
552
  create_concatenation_matrix (alias: create_concat; cc)
550
553
  - create concatenation matrix from a set of alignments
551
554
  evolutionary_rate_per_site (alias: evo_rate_per_site; erps)
@@ -1994,6 +1997,111 @@ class Phykit:
1994
1997
  _add_json_argument(parser)
1995
1998
  _run_service(parser, argv, PairwiseIdentity)
1996
1999
 
2000
+ @staticmethod
2001
+ def codon_dnds(argv):
2002
+ parser = _new_parser(
2003
+ description=_dedent(
2004
+ f"""\
2005
+ {help_header}
2006
+
2007
+ Estimate pairwise nonsynonymous substitutions per
2008
+ nonsynonymous site (dN), synonymous substitutions per
2009
+ synonymous site (dS), and omega (dN/dS) from an
2010
+ in-frame codon alignment.
2011
+
2012
+ Available estimators are Nei-Gojobori 1986 (NG86),
2013
+ Li-Wu-Luo 1985 (LWL85), Yang-Nielsen 2000 (YN00),
2014
+ and Goldman-Yang 1994 maximum likelihood (ML). NG86
2015
+ is the default. ML can be substantially slower for
2016
+ alignments containing many taxa.
2017
+
2018
+ Alignment length must be divisible by three. Gaps
2019
+ must occupy complete codons (---). Codons containing
2020
+ gaps or ambiguous bases are excluded independently
2021
+ for each sequence pair. Terminal stop codons are
2022
+ excluded. Internal stops fail by default.
2023
+
2024
+ Summary statistics are printed by default. Use
2025
+ --verbose to print one TSV row per pair. Omega is a
2026
+ descriptive pairwise estimate; this command does not
2027
+ perform a branch- or site-selection significance test.
2028
+
2029
+ Aliases:
2030
+ codon_dnds, dnds, dn_ds, kaks
2031
+ Command line interfaces:
2032
+ pk_codon_dnds, pk_dnds, pk_dn_ds, pk_kaks
2033
+
2034
+ Usage:
2035
+ phykit codon_dnds <alignment>
2036
+ [--method NG86|LWL85|YN00|ML]
2037
+ [--genetic-code <int>] [--kappa <float>]
2038
+ [--codon-frequency F1x4|F3x4|F61]
2039
+ [--stop-policy error|skip] [--reference <taxon>]
2040
+ [-v/--verbose] [--json]
2041
+
2042
+ Options
2043
+ =====================================================
2044
+ <alignment> in-frame nucleotide
2045
+ alignment
2046
+
2047
+ --method dN/dS estimator
2048
+ (default: NG86)
2049
+
2050
+ --genetic-code NCBI genetic-code ID
2051
+ (default: 1)
2052
+
2053
+ --kappa transition/transversion
2054
+ ratio used by NG86
2055
+ (default: 1.0)
2056
+
2057
+ --codon-frequency codon-frequency model used
2058
+ by ML (default: F3x4)
2059
+
2060
+ --stop-policy fail on internal stops or
2061
+ exclude them pairwise
2062
+ (default: error)
2063
+
2064
+ --reference estimate only pairs that
2065
+ include this exact taxon ID
2066
+
2067
+ -v/--verbose print pairwise TSV results
2068
+
2069
+ --json output structured JSON
2070
+ """
2071
+ ),
2072
+ )
2073
+ parser.add_argument("alignment", type=str, help=SUPPRESS)
2074
+ parser.add_argument(
2075
+ "--method",
2076
+ type=str.upper,
2077
+ choices=("NG86", "LWL85", "YN00", "ML"),
2078
+ default="NG86",
2079
+ help=SUPPRESS,
2080
+ )
2081
+ parser.add_argument(
2082
+ "--genetic-code", type=int, default=1, help=SUPPRESS
2083
+ )
2084
+ parser.add_argument("--kappa", type=float, default=1.0, help=SUPPRESS)
2085
+ parser.add_argument(
2086
+ "--codon-frequency",
2087
+ type=str.upper,
2088
+ choices=("F1X4", "F3X4", "F61"),
2089
+ default="F3X4",
2090
+ help=SUPPRESS,
2091
+ )
2092
+ parser.add_argument(
2093
+ "--stop-policy",
2094
+ choices=("error", "skip"),
2095
+ default="error",
2096
+ help=SUPPRESS,
2097
+ )
2098
+ parser.add_argument("--reference", type=str, default=None, help=SUPPRESS)
2099
+ parser.add_argument(
2100
+ "-v", "--verbose", action="store_true", required=False, help=SUPPRESS
2101
+ )
2102
+ _add_json_argument(parser)
2103
+ _run_service(parser, argv, CodonDnDs)
2104
+
1997
2105
  @staticmethod
1998
2106
  def identity_matrix(argv):
1999
2107
  parser = _new_parser(
@@ -3011,7 +3119,7 @@ class Phykit:
3011
3119
  {help_header}
3012
3120
 
3013
3121
  Map discrete character changes onto a phylogenetic tree
3014
- using Fitch parsimony, classifying each change as a
3122
+ using unordered parsimony, classifying each change as a
3015
3123
  synapomorphy, convergence, or reversal.
3016
3124
 
3017
3125
  Two optimization strategies are supported:
@@ -3023,7 +3131,11 @@ class Phykit:
3023
3131
  Output is a cladogram (default) or phylogram (with
3024
3132
  --phylogram) annotated with colored circles indicating
3025
3133
  character state changes on each branch. Polytomies are
3026
- automatically resolved by adding zero-length branches.
3134
+ retained and analyzed directly.
3135
+
3136
+ Tree and matrix taxon labels are matched exactly and are
3137
+ case-sensitive. Mismatches are errors unless
3138
+ --allow-taxon-mismatch is specified.
3027
3139
 
3028
3140
  Summary statistics include tree length (total parsimony
3029
3141
  steps), consistency index (CI), and retention index (RI).
@@ -3036,7 +3148,9 @@ class Phykit:
3036
3148
  Usage:
3037
3149
  phykit character_map -t <tree> -d <data> -o <output>
3038
3150
  [--optimization acctran|deltran] [--phylogram]
3039
- [--characters 0,1,3] [--verbose] [--json]
3151
+ [--characters 0,1,3] [--allow-taxon-mismatch]
3152
+ [--change-marker-size <float>] [--change-fontsize <float>]
3153
+ [--verbose] [--json]
3040
3154
  [--fig-width <float>] [--fig-height <float>]
3041
3155
  [--dpi <int>] [--no-title] [--title <str>]
3042
3156
  [--legend-position <str>]
@@ -3067,6 +3181,17 @@ class Phykit:
3067
3181
  plot (e.g., 0,1,3); all
3068
3182
  characters shown by default
3069
3183
 
3184
+ --allow-taxon-mismatch warn and analyze only taxa shared
3185
+ by the tree and character matrix;
3186
+ mismatches are errors by default
3187
+
3188
+ --change-marker-size character-change circle size in
3189
+ points squared; must be positive
3190
+
3191
+ --change-fontsize font size for character indices
3192
+ and state transitions; must be
3193
+ positive
3194
+
3070
3195
  --verbose print per-character details
3071
3196
  including CI/RI and changes
3072
3197
 
@@ -3095,6 +3220,18 @@ class Phykit:
3095
3220
  "--characters", type=str, default=None,
3096
3221
  required=False, help=SUPPRESS, metavar=""
3097
3222
  )
3223
+ parser.add_argument(
3224
+ "--allow-taxon-mismatch", action="store_true",
3225
+ required=False, help=SUPPRESS,
3226
+ )
3227
+ parser.add_argument(
3228
+ "--change-marker-size", type=float, default=None,
3229
+ required=False, help=SUPPRESS, metavar="",
3230
+ )
3231
+ parser.add_argument(
3232
+ "--change-fontsize", type=float, default=None,
3233
+ required=False, help=SUPPRESS, metavar="",
3234
+ )
3098
3235
  parser.add_argument(
3099
3236
  "--verbose", action="store_true", required=False, help=SUPPRESS
3100
3237
  )
@@ -10053,6 +10190,10 @@ def pairwise_identity(argv=None):
10053
10190
  Phykit.pairwise_identity(sys.argv[1:])
10054
10191
 
10055
10192
 
10193
+ def codon_dnds(argv=None):
10194
+ Phykit.codon_dnds(sys.argv[1:])
10195
+
10196
+
10056
10197
  def identity_matrix(argv=None):
10057
10198
  Phykit.identity_matrix(sys.argv[1:])
10058
10199
 
@@ -26,6 +26,7 @@ AlignmentOutlierTaxa = _LazyServiceFactory("phykit.services.alignment.alignment_
26
26
  ColumnScore = _LazyServiceFactory("phykit.services.alignment.column_score", "ColumnScore")
27
27
  CompositionalBiasPerSite = _LazyServiceFactory("phykit.services.alignment.compositional_bias_per_site", "CompositionalBiasPerSite")
28
28
  CompositionPerTaxon = _LazyServiceFactory("phykit.services.alignment.composition_per_taxon", "CompositionPerTaxon")
29
+ CodonDnDs = _LazyServiceFactory("phykit.services.alignment.codon_dnds", "CodonDnDs")
29
30
  CreateConcatenationMatrix = _LazyServiceFactory("phykit.services.alignment.create_concatenation_matrix", "CreateConcatenationMatrix")
30
31
  DNAThreader = _LazyServiceFactory("phykit.services.alignment.dna_threader", "DNAThreader")
31
32
  Dtt = _LazyServiceFactory("phykit.services.tree.dtt", "Dtt")
@@ -10,6 +10,7 @@ _EXPORTS = {
10
10
  "ColumnScore": "column_score",
11
11
  "CompositionalBiasPerSite": "compositional_bias_per_site",
12
12
  "CompositionPerTaxon": "composition_per_taxon",
13
+ "CodonDnDs": "codon_dnds",
13
14
  "CreateConcatenationMatrix": "create_concatenation_matrix",
14
15
  "DNAThreader": "dna_threader",
15
16
  "Dstatistic": "dstatistic",
@@ -0,0 +1,400 @@
1
+ from __future__ import annotations
2
+
3
+ import itertools
4
+ import math
5
+ import statistics
6
+
7
+ from .base import Alignment
8
+ from ...errors import PhykitUserError
9
+
10
+
11
+ _DNA_SYMBOLS = frozenset("ACGTRYSWKMBDHVN-?.U")
12
+ _UNAMBIGUOUS_DNA = frozenset("ACGT")
13
+ _CALCULATE_DN_DS = None
14
+ _BIO_ALIGNMENT = None
15
+ _BIO_SEQ = None
16
+ _CODON_TABLES = None
17
+
18
+
19
+ def print_json(*args, **kwargs):
20
+ from ...helpers.json_output import print_json as _print_json
21
+
22
+ return _print_json(*args, **kwargs)
23
+
24
+
25
+ def _load_codon_api():
26
+ global _CALCULATE_DN_DS, _BIO_ALIGNMENT, _BIO_SEQ, _CODON_TABLES
27
+
28
+ if _CALCULATE_DN_DS is None:
29
+ from Bio.Align import Alignment as BioAlignment
30
+ from Bio.Align import analysis
31
+ from Bio.Data import CodonTable
32
+ from Bio.Seq import Seq
33
+
34
+ _CALCULATE_DN_DS = analysis.calculate_dn_ds
35
+ _BIO_ALIGNMENT = BioAlignment
36
+ _BIO_SEQ = Seq
37
+ _CODON_TABLES = CodonTable.unambiguous_dna_by_id
38
+
39
+ return _CALCULATE_DN_DS, _BIO_ALIGNMENT, _BIO_SEQ, _CODON_TABLES
40
+
41
+
42
+ def _mean(values):
43
+ return statistics.fmean(values) if values else None
44
+
45
+
46
+ def _median(values):
47
+ return statistics.median(values) if values else None
48
+
49
+
50
+ def _format_number(value):
51
+ if value is None:
52
+ return "NA"
53
+ return f"{value:.8g}"
54
+
55
+
56
+ class CodonDnDs(Alignment):
57
+ """Estimate pairwise dN, dS, and omega from a codon alignment."""
58
+
59
+ def __init__(self, args) -> None:
60
+ parsed = self.process_args(args)
61
+ super().__init__(alignment_file_path=parsed["alignment_file_path"])
62
+ self.method = parsed["method"]
63
+ self.genetic_code = parsed["genetic_code"]
64
+ self.kappa = parsed["kappa"]
65
+ self.codon_frequency = parsed["codon_frequency"]
66
+ self.stop_policy = parsed["stop_policy"]
67
+ self.reference = parsed["reference"]
68
+ self.verbose = parsed["verbose"]
69
+ self.json_output = parsed["json_output"]
70
+ self._validate_options()
71
+
72
+ @staticmethod
73
+ def process_args(args) -> dict:
74
+ method = getattr(args, "method", "NG86").upper()
75
+ codon_frequency = getattr(args, "codon_frequency", "F3X4").upper()
76
+ return dict(
77
+ alignment_file_path=args.alignment,
78
+ method=method,
79
+ genetic_code=getattr(args, "genetic_code", 1),
80
+ kappa=getattr(args, "kappa", 1.0),
81
+ codon_frequency=codon_frequency.replace("X", "x"),
82
+ stop_policy=getattr(args, "stop_policy", "error"),
83
+ reference=getattr(args, "reference", None),
84
+ verbose=getattr(args, "verbose", False),
85
+ json_output=getattr(args, "json", False),
86
+ )
87
+
88
+ def _validate_options(self) -> None:
89
+ if self.method not in {"NG86", "LWL85", "YN00", "ML"}:
90
+ raise PhykitUserError(
91
+ [f"Unknown dN/dS method: {self.method}. Use NG86, LWL85, YN00, or ML."]
92
+ )
93
+ if not math.isfinite(self.kappa) or self.kappa <= 0.0:
94
+ raise PhykitUserError(["--kappa must be a finite value greater than 0."])
95
+ if self.codon_frequency not in {"F1x4", "F3x4", "F61"}:
96
+ raise PhykitUserError(
97
+ ["--codon-frequency must be F1x4, F3x4, or F61."]
98
+ )
99
+ if self.stop_policy not in {"error", "skip"}:
100
+ raise PhykitUserError(["--stop-policy must be error or skip."])
101
+
102
+ def run(self) -> None:
103
+ alignment, _, is_protein = self.get_alignment_and_format()
104
+ codon_table = self._get_codon_table()
105
+ records = self._validate_alignment(alignment, is_protein, codon_table)
106
+ pairs = self._select_pairs(records)
107
+ results = [
108
+ self._estimate_pair(left, right, codon_table) for left, right in pairs
109
+ ]
110
+ summary = self._summarize(results)
111
+
112
+ if self.json_output:
113
+ payload = {
114
+ "method": self.method,
115
+ "genetic_code": self.genetic_code,
116
+ "kappa": self.kappa,
117
+ "codon_frequency": (
118
+ self.codon_frequency if self.method == "ML" else None
119
+ ),
120
+ "reference": self.reference,
121
+ "summary": summary,
122
+ }
123
+ if self.verbose:
124
+ payload["pairs"] = results
125
+ print_json(payload)
126
+ return
127
+
128
+ if self.verbose:
129
+ self._print_pairs(results)
130
+ else:
131
+ self._print_summary(summary)
132
+
133
+ def _get_codon_table(self):
134
+ _, _, _, tables = _load_codon_api()
135
+ try:
136
+ return tables[self.genetic_code]
137
+ except KeyError:
138
+ available = ", ".join(str(code) for code in sorted(tables))
139
+ raise PhykitUserError(
140
+ [
141
+ f"Unknown NCBI genetic code: {self.genetic_code}.",
142
+ f"Available genetic-code IDs: {available}",
143
+ ]
144
+ )
145
+
146
+ def _validate_alignment(self, alignment, is_protein, codon_table):
147
+ if is_protein:
148
+ raise PhykitUserError(
149
+ ["Codon dN/dS analysis requires a nucleotide alignment."]
150
+ )
151
+ if len(alignment) < 2:
152
+ raise PhykitUserError(
153
+ ["Codon dN/dS analysis requires at least two sequences."]
154
+ )
155
+
156
+ alignment_length = alignment.get_alignment_length()
157
+ if alignment_length == 0:
158
+ raise PhykitUserError(["Codon alignment is empty."])
159
+ if alignment_length % 3:
160
+ raise PhykitUserError(
161
+ [
162
+ f"Codon alignment length ({alignment_length}) is not divisible by 3.",
163
+ "The alignment must begin at the first codon position and preserve frame.",
164
+ ]
165
+ )
166
+
167
+ stop_codons = frozenset(codon_table.stop_codons)
168
+ last_codon_start = alignment_length - 3
169
+ seen_ids = set()
170
+ records = []
171
+ for record in alignment:
172
+ taxon = record.id
173
+ if not taxon:
174
+ raise PhykitUserError(["Codon alignment contains an empty taxon ID."])
175
+ if taxon in seen_ids:
176
+ raise PhykitUserError(
177
+ [f"Codon alignment contains duplicate taxon ID: {taxon}"]
178
+ )
179
+ seen_ids.add(taxon)
180
+
181
+ sequence = str(record.seq).upper().replace("U", "T").replace(".", "-")
182
+ if len(sequence) != alignment_length:
183
+ raise PhykitUserError(
184
+ [
185
+ f"Sequence {taxon!r} has length {len(sequence)}, but the alignment length is {alignment_length}.",
186
+ "All codon-alignment sequences must have equal length.",
187
+ ]
188
+ )
189
+ invalid = sorted(set(sequence) - _DNA_SYMBOLS)
190
+ if invalid:
191
+ symbols = ", ".join(repr(symbol) for symbol in invalid)
192
+ raise PhykitUserError(
193
+ [f"Sequence {taxon!r} contains invalid DNA symbol(s): {symbols}"]
194
+ )
195
+
196
+ for start in range(0, alignment_length, 3):
197
+ codon = sequence[start : start + 3]
198
+ if "-" in codon and codon != "---":
199
+ raise PhykitUserError(
200
+ [
201
+ f"Sequence {taxon!r} has a frame-disrupting gap in codon {start // 3 + 1}: {codon}",
202
+ "Codon-alignment gaps must occupy complete codons (---).",
203
+ ]
204
+ )
205
+ if (
206
+ start != last_codon_start
207
+ and set(codon) <= _UNAMBIGUOUS_DNA
208
+ and codon in stop_codons
209
+ and self.stop_policy == "error"
210
+ ):
211
+ raise PhykitUserError(
212
+ [
213
+ f"Sequence {taxon!r} contains an internal stop codon at codon {start // 3 + 1}: {codon}",
214
+ "Use --stop-policy skip only when internal stops should be excluded pairwise.",
215
+ ]
216
+ )
217
+
218
+ records.append((taxon, sequence))
219
+ return records
220
+
221
+ def _select_pairs(self, records):
222
+ if self.reference is None:
223
+ return itertools.combinations(records, 2)
224
+
225
+ reference_record = None
226
+ for record in records:
227
+ if record[0] == self.reference:
228
+ reference_record = record
229
+ break
230
+ if reference_record is None:
231
+ raise PhykitUserError(
232
+ [f"Reference taxon {self.reference!r} is not present in the alignment."]
233
+ )
234
+ return (
235
+ (reference_record, record)
236
+ for record in records
237
+ if record is not reference_record
238
+ )
239
+
240
+ @staticmethod
241
+ def _prepare_pair(sequence_a, sequence_b, stop_codons):
242
+ clean_a = []
243
+ clean_b = []
244
+ skipped = 0
245
+ for start in range(0, len(sequence_a), 3):
246
+ codon_a = sequence_a[start : start + 3]
247
+ codon_b = sequence_b[start : start + 3]
248
+ if (
249
+ set(codon_a) <= _UNAMBIGUOUS_DNA
250
+ and set(codon_b) <= _UNAMBIGUOUS_DNA
251
+ and codon_a not in stop_codons
252
+ and codon_b not in stop_codons
253
+ ):
254
+ clean_a.append(codon_a)
255
+ clean_b.append(codon_b)
256
+ else:
257
+ skipped += 1
258
+ return "".join(clean_a), "".join(clean_b), skipped
259
+
260
+ def _estimate_pair(self, left, right, codon_table):
261
+ taxon_a, sequence_a = left
262
+ taxon_b, sequence_b = right
263
+ clean_a, clean_b, skipped = self._prepare_pair(
264
+ sequence_a, sequence_b, frozenset(codon_table.stop_codons)
265
+ )
266
+ codons_used = len(clean_a) // 3
267
+ result = {
268
+ "taxon_a": taxon_a,
269
+ "taxon_b": taxon_b,
270
+ "dN": None,
271
+ "dS": None,
272
+ "omega": None,
273
+ "codons_used": codons_used,
274
+ "codons_skipped": skipped,
275
+ "status": "no_valid_codons",
276
+ }
277
+ if not clean_a:
278
+ return result
279
+
280
+ calculate_dn_ds, bio_alignment, bio_seq, _ = _load_codon_api()
281
+ pair_alignment = bio_alignment([bio_seq(clean_a), bio_seq(clean_b)])
282
+ kwargs = {
283
+ "method": self.method,
284
+ "codon_table": codon_table,
285
+ }
286
+ if self.method == "NG86":
287
+ kwargs["k"] = self.kappa
288
+ elif self.method == "ML":
289
+ kwargs["cfreq"] = self.codon_frequency
290
+
291
+ try:
292
+ d_n, d_s = calculate_dn_ds(pair_alignment, **kwargs)
293
+ d_n = float(d_n)
294
+ d_s = float(d_s)
295
+ except (ArithmeticError, FloatingPointError, RuntimeError, ValueError) as err:
296
+ result["status"] = "estimation_failed"
297
+ result["message"] = str(err) or err.__class__.__name__
298
+ return result
299
+
300
+ valid_d_n = math.isfinite(d_n) and d_n >= 0.0
301
+ valid_d_s = math.isfinite(d_s) and d_s >= 0.0
302
+ if valid_d_n:
303
+ result["dN"] = d_n
304
+ if valid_d_s:
305
+ result["dS"] = d_s
306
+
307
+ if not valid_d_n or not valid_d_s:
308
+ result["status"] = "saturated_or_undefined"
309
+ elif d_s == 0.0:
310
+ result["status"] = "zero_synonymous_distance"
311
+ else:
312
+ omega = d_n / d_s
313
+ if math.isfinite(omega):
314
+ result["omega"] = omega
315
+ result["status"] = "ok"
316
+ else:
317
+ result["status"] = "saturated_or_undefined"
318
+ return result
319
+
320
+ @staticmethod
321
+ def _summarize(results):
322
+ d_n_values = [row["dN"] for row in results if row["dN"] is not None]
323
+ d_s_values = [row["dS"] for row in results if row["dS"] is not None]
324
+ omega_values = [
325
+ row["omega"] for row in results if row["omega"] is not None
326
+ ]
327
+ jointly_estimated = [
328
+ row
329
+ for row in results
330
+ if row["dN"] is not None
331
+ and row["dS"] is not None
332
+ and row["dS"] > 0.0
333
+ ]
334
+ joint_mean_d_n = _mean([row["dN"] for row in jointly_estimated])
335
+ joint_mean_d_s = _mean([row["dS"] for row in jointly_estimated])
336
+ ratio_of_means = None
337
+ if joint_mean_d_s is not None and joint_mean_d_s > 0.0:
338
+ ratio_of_means = joint_mean_d_n / joint_mean_d_s
339
+
340
+ status_counts = {}
341
+ for row in results:
342
+ status = row["status"]
343
+ status_counts[status] = status_counts.get(status, 0) + 1
344
+
345
+ return {
346
+ "pairs_total": len(results),
347
+ "pairs_with_dN": len(d_n_values),
348
+ "pairs_with_dS": len(d_s_values),
349
+ "pairs_with_omega": len(omega_values),
350
+ "mean_dN": _mean(d_n_values),
351
+ "median_dN": _median(d_n_values),
352
+ "mean_dS": _mean(d_s_values),
353
+ "median_dS": _median(d_s_values),
354
+ "mean_omega": _mean(omega_values),
355
+ "median_omega": _median(omega_values),
356
+ "ratio_of_mean_dN_to_mean_dS": ratio_of_means,
357
+ "status_counts": status_counts,
358
+ }
359
+
360
+ @staticmethod
361
+ def _print_pairs(results):
362
+ try:
363
+ print(
364
+ "taxon_a\ttaxon_b\tdN\tdS\tomega\tcodons_used\t"
365
+ "codons_skipped\tstatus"
366
+ )
367
+ for row in results:
368
+ print(
369
+ f"{row['taxon_a']}\t{row['taxon_b']}\t"
370
+ f"{_format_number(row['dN'])}\t"
371
+ f"{_format_number(row['dS'])}\t"
372
+ f"{_format_number(row['omega'])}\t"
373
+ f"{row['codons_used']}\t{row['codons_skipped']}\t"
374
+ f"{row['status']}"
375
+ )
376
+ except BrokenPipeError:
377
+ pass
378
+
379
+ def _print_summary(self, summary):
380
+ try:
381
+ lines = [
382
+ f"method: {self.method}",
383
+ f"genetic code: {self.genetic_code}",
384
+ f"sequence pairs: {summary['pairs_total']}",
385
+ f"pairs with omega: {summary['pairs_with_omega']}",
386
+ f"mean dN: {_format_number(summary['mean_dN'])}",
387
+ f"mean dS: {_format_number(summary['mean_dS'])}",
388
+ "dN/dS (ratio of means): "
389
+ f"{_format_number(summary['ratio_of_mean_dN_to_mean_dS'])}",
390
+ f"mean pairwise omega: {_format_number(summary['mean_omega'])}",
391
+ f"median pairwise omega: {_format_number(summary['median_omega'])}",
392
+ "pair statuses: "
393
+ + ", ".join(
394
+ f"{status}={count}"
395
+ for status, count in sorted(summary["status_counts"].items())
396
+ ),
397
+ ]
398
+ print("\n".join(lines))
399
+ except BrokenPipeError:
400
+ pass
@@ -1,9 +1,10 @@
1
1
  """
2
2
  Character mapping on a phylogenetic tree.
3
3
 
4
- Performs Fitch parsimony reconstruction on a discrete character matrix,
5
- classifies changes as synapomorphies, convergences, or reversals, and
6
- produces a phylogram/cladogram plot with annotated character changes.
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
- needs_polytomy_resolution = any(
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
- needs_polytomy_resolution
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
- # Fitch downpass
159
- node_state_sets, scores = fitch_downpass(tree, tip_states)
160
-
161
- # Uppass: ACCTRAN or DELTRAN
162
- if self.optimization == "deltran":
163
- node_states = fitch_uppass_deltran(tree, node_state_sets, parent_map)
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
- node_states = fitch_uppass_acctran(tree, node_state_sets, parent_map)
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(tree_tip_names: list[str], tip_states: dict):
223
- """Return shared count, tree tips to prune, and filtered states."""
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 = {taxon: tip_states[taxon] for taxon in shared}
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 = max(10, min(50, 300 / max(n_tips, 1)))
826
- change_fontsize = max(3.0, min(5.0, 6.0 - n_tips * 0.03))
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 = max(15, min(80, 600 / max(n_tips, 1)))
997
- change_fontsize = max(3.0, min(6.0, 7.0 - n_tips * 0.03))
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.0"
1
+ __version__ = "2.3.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: phykit
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Home-page: https://github.com/jlsteenwyk/phykit
5
5
  Author: Jacob L. Steenwyk
6
6
  Author-email: jlsteenwyk@gmail.com
@@ -1,10 +1,10 @@
1
1
  phykit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  phykit/__main__.py,sha256=MzdAR5Hr3qbi9RHclUC5FbmVRmANm4sq8G61awiBsnQ,102
3
- phykit/cli_registry.py,sha256=OCr_nOYKNdz3l49R5X8hgS9ZxzZFtBfE7aFNhyvaM9Q,8345
3
+ phykit/cli_registry.py,sha256=S6OiY2mbV2SKerZEgo_F0drh1sI45Mt_yPN0BkmfMgw,8456
4
4
  phykit/errors.py,sha256=-FalnuOuQPFDo-Dz7CcqGlF7FpT4ka-gMVC_ikd8n8A,295
5
- phykit/phykit.py,sha256=oJJAshmfRixDrdDX9Y4hwXhrnQwYjcTGdg_iIyHXtpc,424072
6
- phykit/service_factories.py,sha256=J5HRZGDPlWV23NuyZYVmHi19-Yd4dNOgxSdSLOwL_Tw,11236
7
- phykit/version.py,sha256=DKk-1b-rZsJFxFi1JoJ7TmEvIEQ0rf-C9HAZWwvjuM0,22
5
+ phykit/phykit.py,sha256=i3WxumdzQXYRd-px8S9uKKq0zYyze8Lsfu0IZLmIxWY,429894
6
+ phykit/service_factories.py,sha256=SezOXhYfBgs_MMmMsIMnKbXC7YO7_-_5p3Buj4yVcwU,11321
7
+ phykit/version.py,sha256=CpK8IH_dCUAwg9tqv7zm9FxbBFkxCnED1JUiRe7cftU,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=XIkuEDeHQNoy3hnDScfysu7VteORbEqf1tBy7qYCTF4,27686
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
@@ -25,7 +25,7 @@ phykit/helpers/trait_parsing.py,sha256=ZfNqiKyTNqjdm24xsEBEkpUQ07yb27VumRAImWa0h
25
25
  phykit/helpers/tree_paths.py,sha256=-LicDcryxHM6_EX715XNWGuPlQOAYSN3A-eIZWebr4M,3527
26
26
  phykit/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  phykit/services/base.py,sha256=zF6ililMmxTYXPrIpVs6Mvn27Clf0ue3k0NZr9svpqM,183
28
- phykit/services/alignment/__init__.py,sha256=s4HvOPynjsyq-J7M8CnJUPufZFjDrElxCSTOxk9d4tQ,1567
28
+ phykit/services/alignment/__init__.py,sha256=mRLjt8ZrsbzGDFuIXVblKmSBQGyBHwHy81V32AmLBBk,1598
29
29
  phykit/services/alignment/_fasta.py,sha256=XaRNjp5q-jJtHjiMqUKBKP1jDlk8d5iwLWjQ_O3IJI4,6582
30
30
  phykit/services/alignment/alignment_entropy.py,sha256=D1y4aj7sO6W5klrDvBvxhN5Bv2oAchID_O4f4vqlubQ,16116
31
31
  phykit/services/alignment/alignment_length.py,sha256=jFJIYnIIedPJ5bt6MzFr_ezN71npNYyjG9t2OOw9YJo,3215
@@ -34,6 +34,7 @@ phykit/services/alignment/alignment_outlier_taxa.py,sha256=WKoLLBw2aLGu1XSpjdJWT
34
34
  phykit/services/alignment/alignment_recoding.py,sha256=x3k7v9VDlPCv-riYP55H7nrn9U4dfoiX660BXMnXZG8,4517
35
35
  phykit/services/alignment/alignment_subsample.py,sha256=VXv7JEECRB1SIMaOzo_jNyX_1kRd_04IAoc4B-ZkcEU,15570
36
36
  phykit/services/alignment/base.py,sha256=v_4jY2XIZ6V76eDS4itdaNaxtT9Stg3TGBcSGXqsddI,9405
37
+ phykit/services/alignment/codon_dnds.py,sha256=5grG2xe4QU2RNB2R3eIKJFw8WFQ1WSaF4nXYT0SUbQQ,14690
37
38
  phykit/services/alignment/column_score.py,sha256=a0YNwE8jgtgLH26xkDABt1fblEHobmcI1biZU2qKN_Q,12848
38
39
  phykit/services/alignment/composition_per_taxon.py,sha256=wzv5BWyUspU410EpQYbQ-yl4Vlfx6rH6diRuvuzixzA,19060
39
40
  phykit/services/alignment/compositional_bias_per_site.py,sha256=74xedqCXJWzgzL51D5aMMsdgYNU1H7agxPLgmMRzXIY,24124
@@ -63,7 +64,7 @@ phykit/services/tree/ancestral_reconstruction.py,sha256=PTDDz9NBUzk95unaefx7HmZH
63
64
  phykit/services/tree/base.py,sha256=cMUxPtdNwIQl6qNLTX9wAMuMW4VzZQNrwW4G3Xz5pZE,44568
64
65
  phykit/services/tree/bipartition_support_stats.py,sha256=M-eAK8NwLDpVtVfXmFyv20xUz8tleXUFHA38osr0gAQ,17556
65
66
  phykit/services/tree/branch_length_multiplier.py,sha256=gOZ1s2r6KCjkK2CSu-GwvDaPd1PVFomdVZE6lJwXUhM,3787
66
- phykit/services/tree/character_map.py,sha256=0jll2xJZ6GMkZwKkc6YJI6IaCpcDPBCmu9oHcAnjzGE,41596
67
+ phykit/services/tree/character_map.py,sha256=FO_i36sMq1PRmwdYYaoJRdnLggIK9MyXiGgieHycapE,47000
67
68
  phykit/services/tree/chronogram.py,sha256=yS-YG66B5Y4fGuGxcxt2uK7HN6Xdbpf6NIvZ5SZJBX4,32636
68
69
  phykit/services/tree/collapse_branches.py,sha256=frW0velnxqGLROZCLtkyAiY1m9YitkRmeKr70RpgeAM,5230
69
70
  phykit/services/tree/concordance_asr.py,sha256=BvCLkVBkV2vHeO94xzwLZ8lDnlWxvm98It6If6CTm4s,51326
@@ -138,9 +139,9 @@ phykit/services/tree/tree_space.py,sha256=lyaGbGZ4M7Gxf0bD2tmHihvwQ4dwUM7VgOJ44I
138
139
  phykit/services/tree/treeness.py,sha256=rQ1lTRYeVIC5SYDJeZkD-RJUX4BJn88aYy3FeShr3qg,1276
139
140
  phykit/services/tree/treeness_over_rcv.py,sha256=S3RemfNPCh7XDmh3ln7PSPtUFBM0VNXeEt42d2_-IOU,1833
140
141
  phykit/services/tree/vcv_utils.py,sha256=ZoighEYpNpnnB25zD4fIHpdt-JGqBnpSNgvCYa4teV0,25102
141
- phykit-2.2.0.dist-info/licenses/LICENSE.md,sha256=S5sMP_xz_OTEdzTX7xK9cLnSzcSjv3asDzo17b4sPZ4,1078
142
- phykit-2.2.0.dist-info/METADATA,sha256=ClAqtM2hkW3b5lfpFsiOQ3Y5ZVgKvsBsqpcn_jCpOys,5479
143
- phykit-2.2.0.dist-info/WHEEL,sha256=qWEHOWeXof9kJLXAXJ1hukQ_MvVtaV9UUAew6N7Y99E,109
144
- phykit-2.2.0.dist-info/entry_points.txt,sha256=3OtpVc-na-sO3M7KBiUafBrCARjhST5PKjZJGZvKSq0,10155
145
- phykit-2.2.0.dist-info/top_level.txt,sha256=bOMmJQrzcB3UDlMLE7OeP__Ek0x3D6KlKUI4XhDw-0U,7
146
- phykit-2.2.0.dist-info/RECORD,,
142
+ phykit-2.3.0.dist-info/licenses/LICENSE.md,sha256=S5sMP_xz_OTEdzTX7xK9cLnSzcSjv3asDzo17b4sPZ4,1078
143
+ phykit-2.3.0.dist-info/METADATA,sha256=eoCLLKwVVmrW4HS-eV5LWcc-DXzzjWdz2-rJ6z9cxuc,5479
144
+ phykit-2.3.0.dist-info/WHEEL,sha256=qWEHOWeXof9kJLXAXJ1hukQ_MvVtaV9UUAew6N7Y99E,109
145
+ phykit-2.3.0.dist-info/entry_points.txt,sha256=BZEGPGwng2uLvvq9LRr8tMevvV6_3Jn_3pvoLVh74pI,10302
146
+ phykit-2.3.0.dist-info/top_level.txt,sha256=bOMmJQrzcB3UDlMLE7OeP__Ek0x3D6KlKUI4XhDw-0U,7
147
+ phykit-2.3.0.dist-info/RECORD,,
@@ -25,6 +25,7 @@ pk_chrono = phykit.phykit:chronogram
25
25
  pk_chronogram = phykit.phykit:chronogram
26
26
  pk_clan_check = phykit.phykit:hidden_paralogy_check
27
27
  pk_cmap = phykit.phykit:cont_map
28
+ pk_codon_dnds = phykit.phykit:codon_dnds
28
29
  pk_collapse = phykit.phykit:collapse_branches
29
30
  pk_comp_bias_per_site = phykit.phykit:compositional_bias_per_site
30
31
  pk_comp_tax = phykit.phykit:composition_per_taxon
@@ -48,6 +49,8 @@ pk_dimreduce = phykit.phykit:phylogenetic_ordination
48
49
  pk_disc_asym = phykit.phykit:discordance_asymmetry
49
50
  pk_disparity_through_time = phykit.phykit:dtt
50
51
  pk_dmap = phykit.phykit:density_map
52
+ pk_dn_ds = phykit.phykit:codon_dnds
53
+ pk_dnds = phykit.phykit:codon_dnds
51
54
  pk_dstat = phykit.phykit:dstatistic
52
55
  pk_dtt = phykit.phykit:dtt
53
56
  pk_entropy = phykit.phykit:alignment_entropy
@@ -76,6 +79,7 @@ pk_identity_matrix = phykit.phykit:identity_matrix
76
79
  pk_il = phykit.phykit:internode_labeler
77
80
  pk_impute = phykit.phykit:phylo_impute
78
81
  pk_is_monophyletic = phykit.phykit:monophyly_check
82
+ pk_kaks = phykit.phykit:codon_dnds
79
83
  pk_kf = phykit.phykit:kf_distance
80
84
  pk_kf_dist = phykit.phykit:kf_distance
81
85
  pk_kuhner_felsenstein_distance = phykit.phykit:kf_distance
File without changes