phykit 2.2.1__tar.gz → 2.4.0__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.
Files changed (154) hide show
  1. {phykit-2.2.1 → phykit-2.4.0}/PKG-INFO +1 -1
  2. {phykit-2.2.1 → phykit-2.4.0}/phykit/cli_registry.py +65 -1
  3. {phykit-2.2.1 → phykit-2.4.0}/phykit/errors.py +3 -0
  4. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/json_output.py +44 -10
  5. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/trait_parsing.py +52 -2
  6. {phykit-2.2.1 → phykit-2.4.0}/phykit/phykit.py +187 -13
  7. {phykit-2.2.1 → phykit-2.4.0}/phykit/service_factories.py +1 -0
  8. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/__init__.py +1 -0
  9. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/alignment_subsample.py +70 -65
  10. phykit-2.4.0/phykit/services/alignment/codon_dnds.py +424 -0
  11. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/create_concatenation_matrix.py +106 -15
  12. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/dna_threader.py +39 -87
  13. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/variable_sites.py +4 -1
  14. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/base.py +279 -19
  15. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/character_map.py +84 -3
  16. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/network_signal.py +98 -0
  17. phykit-2.4.0/phykit/services/tree/spurious_sequence.py +691 -0
  18. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/threshold_model.py +31 -18
  19. phykit-2.4.0/phykit/version.py +1 -0
  20. {phykit-2.2.1 → phykit-2.4.0}/phykit.egg-info/PKG-INFO +1 -1
  21. {phykit-2.2.1 → phykit-2.4.0}/phykit.egg-info/SOURCES.txt +1 -0
  22. {phykit-2.2.1 → phykit-2.4.0}/phykit.egg-info/entry_points.txt +90 -0
  23. {phykit-2.2.1 → phykit-2.4.0}/setup.py +9 -7
  24. phykit-2.2.1/phykit/services/tree/spurious_sequence.py +0 -231
  25. phykit-2.2.1/phykit/version.py +0 -1
  26. {phykit-2.2.1 → phykit-2.4.0}/LICENSE.md +0 -0
  27. {phykit-2.2.1 → phykit-2.4.0}/README.md +0 -0
  28. {phykit-2.2.1 → phykit-2.4.0}/phykit/__init__.py +0 -0
  29. {phykit-2.2.1 → phykit-2.4.0}/phykit/__main__.py +0 -0
  30. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/__init__.py +0 -0
  31. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/boolean_argument_parsing.py +0 -0
  32. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/caching.py +0 -0
  33. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/circular_layout.py +0 -0
  34. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/color_annotations.py +0 -0
  35. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/discrete_models.py +0 -0
  36. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/files.py +0 -0
  37. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/geological_timescale.py +0 -0
  38. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/parallel.py +0 -0
  39. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/parsimony_utils.py +0 -0
  40. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/pgls_utils.py +0 -0
  41. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/plot_config.py +0 -0
  42. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/quartet_utils.py +0 -0
  43. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/stats_summary.py +0 -0
  44. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/streaming.py +0 -0
  45. {phykit-2.2.1 → phykit-2.4.0}/phykit/helpers/tree_paths.py +0 -0
  46. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/__init__.py +0 -0
  47. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/_fasta.py +0 -0
  48. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/alignment_entropy.py +0 -0
  49. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/alignment_length.py +0 -0
  50. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/alignment_length_no_gaps.py +0 -0
  51. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/alignment_outlier_taxa.py +0 -0
  52. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/alignment_recoding.py +0 -0
  53. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/base.py +0 -0
  54. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/column_score.py +0 -0
  55. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/composition_per_taxon.py +0 -0
  56. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/compositional_bias_per_site.py +0 -0
  57. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/dfoil.py +0 -0
  58. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/dstatistic.py +0 -0
  59. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/evolutionary_rate_per_site.py +0 -0
  60. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/faidx.py +0 -0
  61. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/gc_content.py +0 -0
  62. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/identity_matrix.py +0 -0
  63. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/mask_alignment.py +0 -0
  64. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/occupancy_filter.py +0 -0
  65. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/occupancy_per_taxon.py +0 -0
  66. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/pairwise_identity.py +0 -0
  67. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/parsimony_informative_sites.py +0 -0
  68. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/phylo_gwas.py +0 -0
  69. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/plot_alignment_qc.py +0 -0
  70. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/rcv.py +0 -0
  71. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/rcvt.py +0 -0
  72. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/rename_fasta_entries.py +0 -0
  73. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/sum_of_pairs_score.py +0 -0
  74. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/alignment/taxon_groups.py +0 -0
  75. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/base.py +0 -0
  76. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/__init__.py +0 -0
  77. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/ancestral_reconstruction.py +0 -0
  78. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/bipartition_support_stats.py +0 -0
  79. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/branch_length_multiplier.py +0 -0
  80. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/chronogram.py +0 -0
  81. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/collapse_branches.py +0 -0
  82. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/concordance_asr.py +0 -0
  83. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/consensus_network.py +0 -0
  84. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/consensus_tree.py +0 -0
  85. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/cont_map.py +0 -0
  86. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/cophylo.py +0 -0
  87. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/covarying_evolutionary_rates.py +0 -0
  88. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/density_map.py +0 -0
  89. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/discordance_asymmetry.py +0 -0
  90. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/dtt.py +0 -0
  91. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/dvmc.py +0 -0
  92. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/evo_tempo_map.py +0 -0
  93. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/evolutionary_rate.py +0 -0
  94. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/faiths_pd.py +0 -0
  95. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/fit_continuous.py +0 -0
  96. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/fit_discrete.py +0 -0
  97. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/hidden_paralogy_check.py +0 -0
  98. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/hybridization.py +0 -0
  99. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/independent_contrasts.py +0 -0
  100. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/internal_branch_stats.py +0 -0
  101. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/internode_labeler.py +0 -0
  102. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/kf_distance.py +0 -0
  103. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/last_common_ancestor_subtree.py +0 -0
  104. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/lb_score.py +0 -0
  105. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/ltt.py +0 -0
  106. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/monophyly_check.py +0 -0
  107. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/nearest_neighbor_interchange.py +0 -0
  108. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/neighbor_net.py +0 -0
  109. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/ou_shift_detection.py +0 -0
  110. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/ouwie.py +0 -0
  111. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/parsimony_score.py +0 -0
  112. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/patristic_distances.py +0 -0
  113. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phenogram.py +0 -0
  114. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phylo_anova.py +0 -0
  115. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phylo_heatmap.py +0 -0
  116. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phylo_impute.py +0 -0
  117. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phylo_logistic.py +0 -0
  118. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phylo_path.py +0 -0
  119. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phylogenetic_glm.py +0 -0
  120. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phylogenetic_ordination.py +0 -0
  121. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phylogenetic_regression.py +0 -0
  122. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phylogenetic_signal.py +0 -0
  123. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/phylomorphospace.py +0 -0
  124. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/polytomy_test.py +0 -0
  125. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/print_tree.py +0 -0
  126. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/prune_tree.py +0 -0
  127. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/quartet_network.py +0 -0
  128. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/quartet_pie.py +0 -0
  129. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/rate_heterogeneity.py +0 -0
  130. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/relative_rate_test.py +0 -0
  131. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/rename_tree_tips.py +0 -0
  132. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/rf_distance.py +0 -0
  133. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/root_tree.py +0 -0
  134. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/saturation.py +0 -0
  135. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/simmap_summary.py +0 -0
  136. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/spectral_discordance.py +0 -0
  137. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/spr.py +0 -0
  138. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/stochastic_character_map.py +0 -0
  139. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/terminal_branch_stats.py +0 -0
  140. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/tip_labels.py +0 -0
  141. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/tip_to_tip_distance.py +0 -0
  142. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/tip_to_tip_node_distance.py +0 -0
  143. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/total_tree_length.py +0 -0
  144. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/trait_correlation.py +0 -0
  145. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/trait_rate_map.py +0 -0
  146. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/transfer_annotations.py +0 -0
  147. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/tree_space.py +0 -0
  148. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/treeness.py +0 -0
  149. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/treeness_over_rcv.py +0 -0
  150. {phykit-2.2.1 → phykit-2.4.0}/phykit/services/tree/vcv_utils.py +0 -0
  151. {phykit-2.2.1 → phykit-2.4.0}/phykit.egg-info/dependency_links.txt +0 -0
  152. {phykit-2.2.1 → phykit-2.4.0}/phykit.egg-info/requires.txt +0 -0
  153. {phykit-2.2.1 → phykit-2.4.0}/phykit.egg-info/top_level.txt +0 -0
  154. {phykit-2.2.1 → phykit-2.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: phykit
3
- Version: 2.2.1
3
+ Version: 2.4.0
4
4
  Home-page: https://github.com/jlsteenwyk/phykit
5
5
  Author: Jacob L. Steenwyk
6
6
  Author-email: jlsteenwyk@gmail.com
@@ -1,4 +1,6 @@
1
- """Declarative CLI alias registry."""
1
+ """Declarative registry for PhyKIT commands and aliases."""
2
+
3
+ from dataclasses import dataclass
2
4
 
3
5
 
4
6
  # Map user-facing aliases (and a few long-form synonyms) to Phykit handler names.
@@ -46,6 +48,10 @@ ALIAS_TO_HANDLER: dict[str, str] = {
46
48
  "seqid": "identity_matrix",
47
49
  "comp_taxon": "composition_per_taxon",
48
50
  "comp_tax": "composition_per_taxon",
51
+ "codon_dnds": "codon_dnds",
52
+ "dnds": "codon_dnds",
53
+ "dn_ds": "codon_dnds",
54
+ "kaks": "codon_dnds",
49
55
  "pis": "parsimony_informative_sites",
50
56
  "rel_comp_var": "rcv",
51
57
  "relative_composition_variability": "rcv",
@@ -236,3 +242,61 @@ ALIAS_TO_HANDLER: dict[str, str] = {
236
242
  "pal2nal": "thread_dna",
237
243
  "p2n": "thread_dna",
238
244
  }
245
+
246
+
247
+ # Most canonical command names are also handler names. These five retain their
248
+ # established descriptive command names while dispatching to legacy handlers.
249
+ _CANONICAL_NAME_BY_HANDLER = {
250
+ "dvmc": "degree_of_violation_of_a_molecular_clock",
251
+ "lb_score": "long_branch_score",
252
+ "rcv": "relative_composition_variability",
253
+ "rcvt": "relative_composition_variability_taxon",
254
+ "rf_distance": "robinson_foulds_distance",
255
+ }
256
+
257
+
258
+ @dataclass(frozen=True)
259
+ class CommandIdentity:
260
+ """Stable public identity for one command implementation."""
261
+
262
+ canonical: str
263
+ handler: str
264
+ aliases: tuple[str, ...]
265
+
266
+ @property
267
+ def entry_points(self) -> tuple[str, ...]:
268
+ """Return every standalone ``pk_*`` executable for the command."""
269
+
270
+ return tuple(f"pk_{name}" for name in (self.canonical, *self.aliases))
271
+
272
+
273
+ def _build_command_identities() -> tuple[CommandIdentity, ...]:
274
+ handlers = sorted(set(ALIAS_TO_HANDLER.values()))
275
+ identities = []
276
+ for handler in handlers:
277
+ canonical = _CANONICAL_NAME_BY_HANDLER.get(handler, handler)
278
+ public_names = {
279
+ name for name, mapped_handler in ALIAS_TO_HANDLER.items()
280
+ if mapped_handler == handler
281
+ }
282
+ public_names.add(handler)
283
+ public_names.discard(canonical)
284
+ identities.append(
285
+ CommandIdentity(
286
+ canonical=canonical,
287
+ handler=handler,
288
+ aliases=tuple(sorted(public_names)),
289
+ )
290
+ )
291
+ return tuple(identities)
292
+
293
+
294
+ COMMAND_IDENTITIES = _build_command_identities()
295
+
296
+ # Complete command surface used by packaging and documentation. Keep
297
+ # ALIAS_TO_HANDLER as the dispatch-only compatibility mapping.
298
+ PUBLIC_COMMAND_TO_HANDLER = {
299
+ name: identity.handler
300
+ for identity in COMMAND_IDENTITIES
301
+ for name in (identity.canonical, *identity.aliases)
302
+ }
@@ -7,3 +7,6 @@ class PhykitUserError(SystemExit):
7
7
  def __init__(self, messages, code: int = 2):
8
8
  self.messages: list[str] = list(messages)
9
9
  super().__init__(code)
10
+
11
+ def __reduce__(self):
12
+ return type(self), (self.messages, self.code)
@@ -1,10 +1,18 @@
1
+ from math import isfinite
2
+
3
+
1
4
  _JSON_SCALAR_TYPES = (str, int, float, bool)
2
5
  _LARGE_DICT_COPY_THRESHOLD = 50_000
3
6
  _JSON_DUMPS = None
4
7
 
5
8
 
6
9
  def to_builtin_json_types(value):
7
- if value is None or type(value) in _JSON_SCALAR_TYPES:
10
+ value_type = type(value)
11
+ if value is None:
12
+ return value
13
+ if value_type is float:
14
+ return value if isfinite(value) else None
15
+ if value_type in _JSON_SCALAR_TYPES:
8
16
  return value
9
17
  if isinstance(value, dict):
10
18
  converted = None
@@ -12,7 +20,12 @@ def to_builtin_json_types(value):
12
20
  type(value) is dict and len(value) >= _LARGE_DICT_COPY_THRESHOLD
13
21
  )
14
22
  for key, sub_value in value.items():
15
- if sub_value is None or type(sub_value) in _JSON_SCALAR_TYPES:
23
+ sub_value_type = type(sub_value)
24
+ if sub_value_type is float:
25
+ converted_value = (
26
+ sub_value if isfinite(sub_value) else None
27
+ )
28
+ elif sub_value is None or sub_value_type in _JSON_SCALAR_TYPES:
16
29
  converted_value = sub_value
17
30
  else:
18
31
  converted_value = to_builtin_json_types(sub_value)
@@ -32,7 +45,12 @@ def to_builtin_json_types(value):
32
45
  if isinstance(value, list):
33
46
  converted = None
34
47
  for index, sub_value in enumerate(value):
35
- if sub_value is None or type(sub_value) in _JSON_SCALAR_TYPES:
48
+ sub_value_type = type(sub_value)
49
+ if sub_value_type is float:
50
+ converted_value = (
51
+ sub_value if isfinite(sub_value) else None
52
+ )
53
+ elif sub_value is None or sub_value_type in _JSON_SCALAR_TYPES:
36
54
  converted_value = sub_value
37
55
  else:
38
56
  converted_value = to_builtin_json_types(sub_value)
@@ -45,7 +63,12 @@ def to_builtin_json_types(value):
45
63
  if isinstance(value, tuple):
46
64
  converted = None
47
65
  for index, sub_value in enumerate(value):
48
- if sub_value is None or type(sub_value) in _JSON_SCALAR_TYPES:
66
+ sub_value_type = type(sub_value)
67
+ if sub_value_type is float:
68
+ converted_value = (
69
+ sub_value if isfinite(sub_value) else None
70
+ )
71
+ elif sub_value is None or sub_value_type in _JSON_SCALAR_TYPES:
49
72
  converted_value = sub_value
50
73
  else:
51
74
  converted_value = to_builtin_json_types(sub_value)
@@ -61,7 +84,7 @@ def to_builtin_json_types(value):
61
84
  if hasattr(value, "tolist"):
62
85
  return to_builtin_json_types(value.tolist())
63
86
  if hasattr(value, "item"):
64
- return value.item()
87
+ return to_builtin_json_types(value.item())
65
88
  if hasattr(value, "tolist") and value.__class__.__name__ == "ndarray":
66
89
  return [to_builtin_json_types(sub_value) for sub_value in value.tolist()]
67
90
  return value
@@ -91,11 +114,22 @@ def print_json(payload, sort_keys=True):
91
114
  _JSON_DUMPS = dumps
92
115
 
93
116
  try:
94
- output = dumps(
95
- payload,
96
- sort_keys=sort_keys,
97
- default=_json_default,
98
- )
117
+ try:
118
+ output = dumps(
119
+ payload,
120
+ sort_keys=sort_keys,
121
+ default=_json_default,
122
+ allow_nan=False,
123
+ )
124
+ except ValueError as error:
125
+ if "Out of range float values" not in str(error):
126
+ raise
127
+ output = dumps(
128
+ to_builtin_json_types(payload),
129
+ sort_keys=sort_keys,
130
+ default=_json_default,
131
+ allow_nan=False,
132
+ )
99
133
  print(output)
100
134
  except BrokenPipeError:
101
135
  pass
@@ -5,11 +5,16 @@ Provides a single implementation for parsing tab-delimited multi-trait
5
5
  files with a header row, used across phylogenetic regression, signal,
6
6
  ordination, path analysis, ANOVA, and other comparative methods.
7
7
  """
8
+ from math import isfinite
8
9
  import sys
9
10
 
10
11
  from ..errors import PhykitUserError
11
12
 
12
13
 
14
+ def _split_tsv_line(line: str) -> list[str]:
15
+ return [part.strip() for part in line.rstrip("\r\n").split("\t")]
16
+
17
+
13
18
  def _parse_float_values_detailed(
14
19
  value_parts: list[str],
15
20
  trait_names: list[str],
@@ -61,7 +66,7 @@ def parse_multi_trait_file(
61
66
  stripped = line.strip()
62
67
  if not stripped or stripped[0] == "#":
63
68
  continue
64
- header_parts = stripped.split("\t")
69
+ header_parts = _split_tsv_line(line)
65
70
  break
66
71
 
67
72
  if header_parts is None:
@@ -81,8 +86,27 @@ def parse_multi_trait_file(
81
86
  )
82
87
  trait_names = header_parts[1:]
83
88
  trait_count = len(trait_names)
89
+ trait_columns = {}
90
+ for column, trait_name in enumerate(trait_names, start=2):
91
+ if not trait_name:
92
+ raise PhykitUserError(
93
+ [
94
+ f"Trait header is blank in column {column} on line 1."
95
+ ],
96
+ code=2,
97
+ )
98
+ if trait_name in trait_columns:
99
+ raise PhykitUserError(
100
+ [
101
+ f"Duplicate trait header '{trait_name}' in columns "
102
+ f"{trait_columns[trait_name]} and {column} on line 1."
103
+ ],
104
+ code=2,
105
+ )
106
+ trait_columns[trait_name] = column
84
107
 
85
108
  traits = {}
109
+ taxon_lines = {}
86
110
  saw_data = False
87
111
  data_line_idx = 2
88
112
  to_float = float
@@ -91,7 +115,7 @@ def parse_multi_trait_file(
91
115
  if not stripped or stripped[0] == "#":
92
116
  continue
93
117
  saw_data = True
94
- parts = stripped.split("\t")
118
+ parts = _split_tsv_line(line)
95
119
  if len(parts) != n_cols:
96
120
  raise PhykitUserError(
97
121
  [
@@ -102,6 +126,19 @@ def parse_multi_trait_file(
102
126
  code=2,
103
127
  )
104
128
  taxon = parts[0]
129
+ if not taxon:
130
+ raise PhykitUserError(
131
+ [f"Taxon name is blank on line {data_line_idx}."],
132
+ code=2,
133
+ )
134
+ if taxon in taxon_lines:
135
+ raise PhykitUserError(
136
+ [
137
+ f"Duplicate taxon '{taxon}' on line {data_line_idx}; "
138
+ f"first seen on line {taxon_lines[taxon]}."
139
+ ],
140
+ code=2,
141
+ )
105
142
  try:
106
143
  if trait_count == 1:
107
144
  values = [to_float(parts[1])]
@@ -129,7 +166,20 @@ def parse_multi_trait_file(
129
166
  taxon,
130
167
  data_line_idx,
131
168
  )
169
+ for trait_name, raw_value, value in zip(
170
+ trait_names, parts[1:], values
171
+ ):
172
+ if not isfinite(value):
173
+ raise PhykitUserError(
174
+ [
175
+ f"Non-finite trait value '{raw_value}' for taxon "
176
+ f"'{taxon}' (trait '{trait_name}') on line "
177
+ f"{data_line_idx}."
178
+ ],
179
+ code=2,
180
+ )
132
181
  traits[taxon] = values
182
+ taxon_lines[taxon] = data_line_idx
133
183
  data_line_idx += 1
134
184
 
135
185
  if not saw_data:
@@ -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(
@@ -3103,7 +3211,8 @@ class Phykit:
3103
3211
  )
3104
3212
  parser.add_argument(
3105
3213
  "--optimization", type=str, default="acctran",
3106
- required=False, help=SUPPRESS, metavar=""
3214
+ choices=("acctran", "deltran"), required=False,
3215
+ help=SUPPRESS, metavar=""
3107
3216
  )
3108
3217
  parser.add_argument(
3109
3218
  "--phylogram", action="store_true", required=False, help=SUPPRESS
@@ -6865,9 +6974,9 @@ class Phykit:
6865
6974
  (Default: majority)
6866
6975
 
6867
6976
  --missing-taxa how to handle mismatched
6868
- taxa across trees:
6869
- error or shared
6870
- (Default: error)
6977
+ taxa across trees: allow,
6978
+ error, or shared
6979
+ (Default: allow)
6871
6980
 
6872
6981
  --json optional argument to output
6873
6982
  results as JSON
@@ -8424,21 +8533,36 @@ class Phykit:
8424
8533
  f"""\
8425
8534
  {help_header}
8426
8535
 
8427
- Determines potentially spurious homologs using branch lengths.
8536
+ Determines potentially spurious homologs using branch lengths
8537
+ or topology-aware tree-diameter impact.
8428
8538
 
8429
8539
  Identifies potentially spurious sequences and reports
8430
8540
  tips in the phylogeny that could possibly be removed
8431
8541
  from the associated multiple sequence alignment. PhyKIT
8432
- does so by identifying and reporting long terminal branches
8433
- defined as branches that are equal to or 20 times the median
8434
- length of all branches.
8435
-
8436
- PhyKIT reports the following information
8542
+ By default, PhyKIT identifies and reports long terminal
8543
+ branches defined as branches that are at least 20 times the
8544
+ median terminal-branch length. The diameter-impact method
8545
+ instead searches tree-diameter endpoints, measures the
8546
+ reduction caused by removing each selected endpoint, and
8547
+ reports statistically extreme log reductions.
8548
+
8549
+ Median-factor output reports the following information
8437
8550
  col1: name of tip that is a putatively spurious sequence
8438
8551
  col2: length of branch leading to putatively spurious sequence
8439
8552
  col3: threshold used to identify putatively spurious sequences
8440
8553
  col4: median branch length in the phylogeny
8441
8554
 
8555
+ Diameter-impact output for one tree reports
8556
+ col1: name of tip that is a putatively spurious sequence
8557
+ col2: log reduction in tree diameter
8558
+ col3: upper-tail p-value
8559
+ col4: removal rank
8560
+ col5: terminal branch length
8561
+ col6: tree diameter before removal
8562
+ col7: tree diameter after removal
8563
+
8564
+ With --tree-list, the tree path is prepended as column 1.
8565
+
8442
8566
  If there are no putatively spurious sequences, "None" is reported.
8443
8567
 
8444
8568
  Using this method to identify potentially spurious sequences
@@ -8452,6 +8576,10 @@ class Phykit:
8452
8576
 
8453
8577
  Usage:
8454
8578
  phykit spurious_sequence <file> [-f 20] [--json]
8579
+ phykit spurious_sequence <file> --method diameter-impact
8580
+ [--alpha 0.05] [--max-remove <count>] [--json]
8581
+ phykit spurious_sequence <tree_list> --method diameter-impact
8582
+ --tree-list [--per-species] [--alpha 0.05] [--json]
8455
8583
 
8456
8584
  Options
8457
8585
  =====================================================
@@ -8464,6 +8592,25 @@ class Phykit:
8464
8592
  the threshold of long branches.
8465
8593
  (Default: 20)
8466
8594
 
8595
+ --method detection method: median-factor
8596
+ or diameter-impact.
8597
+ (Default: median-factor)
8598
+
8599
+ --alpha upper-tail significance level for
8600
+ diameter-impact detection.
8601
+ (Default: 0.05)
8602
+
8603
+ --max-remove maximum number of diameter
8604
+ endpoints to evaluate. By default,
8605
+ uses min(n/4, 5*sqrt(n)).
8606
+
8607
+ --tree-list interpret <file> as a line-delimited
8608
+ list of tree paths and calibrate
8609
+ signatures across all trees.
8610
+
8611
+ --per-species with --tree-list, calibrate each
8612
+ taxon's signatures separately.
8613
+
8467
8614
  --json optional argument to output
8468
8615
  results as JSON
8469
8616
  """
@@ -8471,6 +8618,16 @@ class Phykit:
8471
8618
  )
8472
8619
  parser.add_argument("tree", type=str, help=SUPPRESS)
8473
8620
  parser.add_argument("-f", "--factor", type=float, required=False, help=SUPPRESS)
8621
+ parser.add_argument(
8622
+ "--method",
8623
+ choices=("median-factor", "diameter-impact"),
8624
+ default="median-factor",
8625
+ help=SUPPRESS,
8626
+ )
8627
+ parser.add_argument("--alpha", type=float, default=0.05, help=SUPPRESS)
8628
+ parser.add_argument("--max-remove", type=int, default=None, help=SUPPRESS)
8629
+ parser.add_argument("--tree-list", action="store_true", help=SUPPRESS)
8630
+ parser.add_argument("--per-species", action="store_true", help=SUPPRESS)
8474
8631
  _add_json_argument(parser)
8475
8632
  _run_service(parser, argv, SpuriousSequence)
8476
8633
 
@@ -9938,7 +10095,15 @@ class Phykit:
9938
10095
  """
9939
10096
  ),
9940
10097
  )
9941
- parser.add_argument("-a", "--alignment_list", type=str, help=SUPPRESS)
10098
+ parser.add_argument(
10099
+ "-a",
10100
+ "--alignment",
10101
+ "--alignment-list",
10102
+ "--alignment_list",
10103
+ dest="alignment_list",
10104
+ type=str,
10105
+ help=SUPPRESS,
10106
+ )
9942
10107
  parser.add_argument("-p", "--prefix", type=str, help=SUPPRESS)
9943
10108
  parser.add_argument("--threshold", type=float, required=False, default=0, help=SUPPRESS)
9944
10109
  parser.add_argument("--plot-occupancy", action="store_true", required=False, help=SUPPRESS)
@@ -9979,7 +10144,7 @@ class Phykit:
9979
10144
  pk_thread_dna, pk_pal2nal, pk_p2n
9980
10145
 
9981
10146
  Usage:
9982
- phykit thread_dna -p <file> -n <file> [-c/--clipkit_log_file
10147
+ phykit thread_dna -p <file> -n <file> [-c/--clipkit-log-file
9983
10148
  <clipkit outputted log file> -s] [--json]
9984
10149
 
9985
10150
  Options
@@ -9988,7 +10153,7 @@ class Phykit:
9988
10153
 
9989
10154
  -n/--nucleotide nucleotide sequence file
9990
10155
 
9991
- -c/--clipkit_log clipkit outputted log file
10156
+ -c/--clipkit-log-file ClipKIT output log file
9992
10157
 
9993
10158
  -s/--stop boolean for whether or not
9994
10159
  stop codons should be kept.
@@ -10004,6 +10169,7 @@ class Phykit:
10004
10169
  parser.add_argument("-n", "--nucleotide", type=str, help=SUPPRESS)
10005
10170
  parser.add_argument(
10006
10171
  "-c",
10172
+ "--clipkit-log-file",
10007
10173
  "--clipkit_log_file",
10008
10174
  type=str,
10009
10175
  required=False,
@@ -10038,6 +10204,10 @@ def alignment_entropy(argv=None):
10038
10204
  Phykit.alignment_entropy(sys.argv[1:])
10039
10205
 
10040
10206
 
10207
+ def alignment_recoding(argv=None):
10208
+ Phykit.alignment_recoding(sys.argv[1:])
10209
+
10210
+
10041
10211
  def alignment_outlier_taxa(argv=None):
10042
10212
  Phykit.alignment_outlier_taxa(sys.argv[1:])
10043
10213
 
@@ -10082,6 +10252,10 @@ def pairwise_identity(argv=None):
10082
10252
  Phykit.pairwise_identity(sys.argv[1:])
10083
10253
 
10084
10254
 
10255
+ def codon_dnds(argv=None):
10256
+ Phykit.codon_dnds(sys.argv[1:])
10257
+
10258
+
10085
10259
  def identity_matrix(argv=None):
10086
10260
  Phykit.identity_matrix(sys.argv[1:])
10087
10261
 
@@ -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",