phykit 2.3.0__tar.gz → 2.4.1__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 (155) hide show
  1. {phykit-2.3.0 → phykit-2.4.1}/PKG-INFO +1 -1
  2. {phykit-2.3.0 → phykit-2.4.1}/phykit/cli_registry.py +63 -1
  3. {phykit-2.3.0 → phykit-2.4.1}/phykit/errors.py +3 -0
  4. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/json_output.py +44 -10
  5. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/trait_parsing.py +52 -2
  6. {phykit-2.3.0 → phykit-2.4.1}/phykit/phykit.py +180 -25
  7. {phykit-2.3.0 → phykit-2.4.1}/phykit/service_factories.py +1 -0
  8. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/__init__.py +1 -0
  9. phykit-2.4.1/phykit/services/alignment/alignment_outlier_regions.py +591 -0
  10. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/alignment_subsample.py +70 -65
  11. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/codon_dnds.py +25 -1
  12. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/create_concatenation_matrix.py +106 -15
  13. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/dna_threader.py +39 -87
  14. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/pairwise_identity.py +1 -1
  15. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/phylo_gwas.py +2 -0
  16. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/variable_sites.py +4 -1
  17. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/base.py +279 -19
  18. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/character_map.py +84 -3
  19. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/covarying_evolutionary_rates.py +135 -19
  20. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/network_signal.py +98 -0
  21. phykit-2.4.1/phykit/services/tree/spurious_sequence.py +691 -0
  22. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/threshold_model.py +31 -18
  23. phykit-2.4.1/phykit/version.py +1 -0
  24. {phykit-2.3.0 → phykit-2.4.1}/phykit.egg-info/PKG-INFO +1 -1
  25. {phykit-2.3.0 → phykit-2.4.1}/phykit.egg-info/SOURCES.txt +1 -0
  26. {phykit-2.3.0 → phykit-2.4.1}/phykit.egg-info/entry_points.txt +89 -0
  27. {phykit-2.3.0 → phykit-2.4.1}/setup.py +9 -7
  28. phykit-2.3.0/phykit/services/tree/spurious_sequence.py +0 -231
  29. phykit-2.3.0/phykit/version.py +0 -1
  30. {phykit-2.3.0 → phykit-2.4.1}/LICENSE.md +0 -0
  31. {phykit-2.3.0 → phykit-2.4.1}/README.md +0 -0
  32. {phykit-2.3.0 → phykit-2.4.1}/phykit/__init__.py +0 -0
  33. {phykit-2.3.0 → phykit-2.4.1}/phykit/__main__.py +0 -0
  34. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/__init__.py +0 -0
  35. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/boolean_argument_parsing.py +0 -0
  36. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/caching.py +0 -0
  37. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/circular_layout.py +0 -0
  38. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/color_annotations.py +0 -0
  39. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/discrete_models.py +0 -0
  40. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/files.py +0 -0
  41. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/geological_timescale.py +0 -0
  42. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/parallel.py +0 -0
  43. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/parsimony_utils.py +0 -0
  44. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/pgls_utils.py +0 -0
  45. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/plot_config.py +0 -0
  46. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/quartet_utils.py +0 -0
  47. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/stats_summary.py +0 -0
  48. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/streaming.py +0 -0
  49. {phykit-2.3.0 → phykit-2.4.1}/phykit/helpers/tree_paths.py +0 -0
  50. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/__init__.py +0 -0
  51. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/_fasta.py +0 -0
  52. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/alignment_entropy.py +0 -0
  53. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/alignment_length.py +0 -0
  54. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/alignment_length_no_gaps.py +0 -0
  55. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/alignment_outlier_taxa.py +0 -0
  56. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/alignment_recoding.py +0 -0
  57. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/base.py +0 -0
  58. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/column_score.py +0 -0
  59. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/composition_per_taxon.py +0 -0
  60. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/compositional_bias_per_site.py +0 -0
  61. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/dfoil.py +0 -0
  62. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/dstatistic.py +0 -0
  63. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/evolutionary_rate_per_site.py +0 -0
  64. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/faidx.py +0 -0
  65. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/gc_content.py +0 -0
  66. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/identity_matrix.py +0 -0
  67. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/mask_alignment.py +0 -0
  68. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/occupancy_filter.py +0 -0
  69. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/occupancy_per_taxon.py +0 -0
  70. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/parsimony_informative_sites.py +0 -0
  71. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/plot_alignment_qc.py +0 -0
  72. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/rcv.py +0 -0
  73. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/rcvt.py +0 -0
  74. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/rename_fasta_entries.py +0 -0
  75. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/sum_of_pairs_score.py +0 -0
  76. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/alignment/taxon_groups.py +0 -0
  77. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/base.py +0 -0
  78. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/__init__.py +0 -0
  79. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/ancestral_reconstruction.py +0 -0
  80. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/bipartition_support_stats.py +0 -0
  81. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/branch_length_multiplier.py +0 -0
  82. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/chronogram.py +0 -0
  83. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/collapse_branches.py +0 -0
  84. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/concordance_asr.py +0 -0
  85. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/consensus_network.py +0 -0
  86. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/consensus_tree.py +0 -0
  87. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/cont_map.py +0 -0
  88. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/cophylo.py +0 -0
  89. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/density_map.py +0 -0
  90. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/discordance_asymmetry.py +0 -0
  91. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/dtt.py +0 -0
  92. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/dvmc.py +0 -0
  93. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/evo_tempo_map.py +0 -0
  94. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/evolutionary_rate.py +0 -0
  95. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/faiths_pd.py +0 -0
  96. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/fit_continuous.py +0 -0
  97. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/fit_discrete.py +0 -0
  98. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/hidden_paralogy_check.py +0 -0
  99. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/hybridization.py +0 -0
  100. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/independent_contrasts.py +0 -0
  101. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/internal_branch_stats.py +0 -0
  102. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/internode_labeler.py +0 -0
  103. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/kf_distance.py +0 -0
  104. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/last_common_ancestor_subtree.py +0 -0
  105. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/lb_score.py +0 -0
  106. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/ltt.py +0 -0
  107. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/monophyly_check.py +0 -0
  108. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/nearest_neighbor_interchange.py +0 -0
  109. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/neighbor_net.py +0 -0
  110. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/ou_shift_detection.py +0 -0
  111. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/ouwie.py +0 -0
  112. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/parsimony_score.py +0 -0
  113. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/patristic_distances.py +0 -0
  114. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phenogram.py +0 -0
  115. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phylo_anova.py +0 -0
  116. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phylo_heatmap.py +0 -0
  117. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phylo_impute.py +0 -0
  118. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phylo_logistic.py +0 -0
  119. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phylo_path.py +0 -0
  120. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phylogenetic_glm.py +0 -0
  121. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phylogenetic_ordination.py +0 -0
  122. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phylogenetic_regression.py +0 -0
  123. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phylogenetic_signal.py +0 -0
  124. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/phylomorphospace.py +0 -0
  125. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/polytomy_test.py +0 -0
  126. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/print_tree.py +0 -0
  127. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/prune_tree.py +0 -0
  128. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/quartet_network.py +0 -0
  129. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/quartet_pie.py +0 -0
  130. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/rate_heterogeneity.py +0 -0
  131. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/relative_rate_test.py +0 -0
  132. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/rename_tree_tips.py +0 -0
  133. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/rf_distance.py +0 -0
  134. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/root_tree.py +0 -0
  135. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/saturation.py +0 -0
  136. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/simmap_summary.py +0 -0
  137. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/spectral_discordance.py +0 -0
  138. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/spr.py +0 -0
  139. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/stochastic_character_map.py +0 -0
  140. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/terminal_branch_stats.py +0 -0
  141. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/tip_labels.py +0 -0
  142. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/tip_to_tip_distance.py +0 -0
  143. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/tip_to_tip_node_distance.py +0 -0
  144. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/total_tree_length.py +0 -0
  145. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/trait_correlation.py +0 -0
  146. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/trait_rate_map.py +0 -0
  147. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/transfer_annotations.py +0 -0
  148. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/tree_space.py +0 -0
  149. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/treeness.py +0 -0
  150. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/treeness_over_rcv.py +0 -0
  151. {phykit-2.3.0 → phykit-2.4.1}/phykit/services/tree/vcv_utils.py +0 -0
  152. {phykit-2.3.0 → phykit-2.4.1}/phykit.egg-info/dependency_links.txt +0 -0
  153. {phykit-2.3.0 → phykit-2.4.1}/phykit.egg-info/requires.txt +0 -0
  154. {phykit-2.3.0 → phykit-2.4.1}/phykit.egg-info/top_level.txt +0 -0
  155. {phykit-2.3.0 → phykit-2.4.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: phykit
3
- Version: 2.3.0
3
+ Version: 2.4.1
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.
@@ -19,6 +21,8 @@ ALIAS_TO_HANDLER: dict[str, str] = {
19
21
  "recode": "alignment_recoding",
20
22
  "outlier_taxa": "alignment_outlier_taxa",
21
23
  "aot": "alignment_outlier_taxa",
24
+ "outlier_regions": "alignment_outlier_regions",
25
+ "aor": "alignment_outlier_regions",
22
26
  "dtt": "dtt",
23
27
  "disparity_through_time": "dtt",
24
28
  "dstat": "dstatistic",
@@ -240,3 +244,61 @@ ALIAS_TO_HANDLER: dict[str, str] = {
240
244
  "pal2nal": "thread_dna",
241
245
  "p2n": "thread_dna",
242
246
  }
247
+
248
+
249
+ # Most canonical command names are also handler names. These five retain their
250
+ # established descriptive command names while dispatching to legacy handlers.
251
+ _CANONICAL_NAME_BY_HANDLER = {
252
+ "dvmc": "degree_of_violation_of_a_molecular_clock",
253
+ "lb_score": "long_branch_score",
254
+ "rcv": "relative_composition_variability",
255
+ "rcvt": "relative_composition_variability_taxon",
256
+ "rf_distance": "robinson_foulds_distance",
257
+ }
258
+
259
+
260
+ @dataclass(frozen=True)
261
+ class CommandIdentity:
262
+ """Stable public identity for one command implementation."""
263
+
264
+ canonical: str
265
+ handler: str
266
+ aliases: tuple[str, ...]
267
+
268
+ @property
269
+ def entry_points(self) -> tuple[str, ...]:
270
+ """Return every standalone ``pk_*`` executable for the command."""
271
+
272
+ return tuple(f"pk_{name}" for name in (self.canonical, *self.aliases))
273
+
274
+
275
+ def _build_command_identities() -> tuple[CommandIdentity, ...]:
276
+ handlers = sorted(set(ALIAS_TO_HANDLER.values()))
277
+ identities = []
278
+ for handler in handlers:
279
+ canonical = _CANONICAL_NAME_BY_HANDLER.get(handler, handler)
280
+ public_names = {
281
+ name for name, mapped_handler in ALIAS_TO_HANDLER.items()
282
+ if mapped_handler == handler
283
+ }
284
+ public_names.add(handler)
285
+ public_names.discard(canonical)
286
+ identities.append(
287
+ CommandIdentity(
288
+ canonical=canonical,
289
+ handler=handler,
290
+ aliases=tuple(sorted(public_names)),
291
+ )
292
+ )
293
+ return tuple(identities)
294
+
295
+
296
+ COMMAND_IDENTITIES = _build_command_identities()
297
+
298
+ # Complete command surface used by packaging and documentation. Keep
299
+ # ALIAS_TO_HANDLER as the dispatch-only compatibility mapping.
300
+ PUBLIC_COMMAND_TO_HANDLER = {
301
+ name: identity.handler
302
+ for identity in COMMAND_IDENTITIES
303
+ for name in (identity.canonical, *identity.aliases)
304
+ }
@@ -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:
@@ -540,6 +540,8 @@ class Phykit:
540
540
  symmetric phylogeny
541
541
  alignment_outlier_taxa (alias: outlier_taxa; aot)
542
542
  - identify potential outlier taxa and why they were flagged
543
+ alignment_outlier_regions (alias: outlier_regions; aor)
544
+ - detect localized nonhomologous or erroneous sequence regions
543
545
  column_score (alias: cs)
544
546
  - calculate column score between a reference and query alignment
545
547
  compositional_bias_per_site (alias: comp_bias_per_site; cbps)
@@ -1237,6 +1239,92 @@ class Phykit:
1237
1239
  _add_json_argument(parser)
1238
1240
  _run_service(parser, argv, AlignmentOutlierTaxa)
1239
1241
 
1242
+ @staticmethod
1243
+ def alignment_outlier_regions(argv):
1244
+ parser = _new_parser(
1245
+ description=_dedent(
1246
+ f"""\
1247
+ {help_header}
1248
+
1249
+ Detect localized outlier regions in a multiple sequence alignment.
1250
+
1251
+ This command uses a TAPER-inspired two-dimensional method. It scores
1252
+ residues relative to their alignment columns, detects unusually high
1253
+ scores within each sequence at multiple window sizes, and smooths
1254
+ window calls into contiguous regions. Only residues belonging to a
1255
+ flagged taxon-region are reported or masked; complete alignment
1256
+ columns are not removed.
1257
+
1258
+ Citation:
1259
+ Zhang C, Zhao Y, Braun EL, and Mirarab S. 2021. TAPER:
1260
+ Pinpointing errors in multiple sequence alignments despite varying
1261
+ rates of evolution. Methods in Ecology and Evolution 12:2145-2158.
1262
+ doi:10.1111/2041-210X.13696
1263
+
1264
+ Aliases:
1265
+ alignment_outlier_regions, outlier_regions, aor
1266
+ Command line interfaces:
1267
+ pk_alignment_outlier_regions, pk_outlier_regions, pk_aor
1268
+
1269
+ Usage:
1270
+ phykit alignment_outlier_regions <alignment>
1271
+ [--cutoff <float>] [--report <path>]
1272
+ [--mask-output <path>] [--mask-character <character>]
1273
+ [--json]
1274
+
1275
+ Options
1276
+ =====================================================
1277
+ <alignment> multiple sequence alignment
1278
+
1279
+ --cutoff minimum divergence score used
1280
+ to control detection sensitivity;
1281
+ must be >1 (default: 3.0)
1282
+
1283
+ --report optional path for the region
1284
+ report; defaults to standard output
1285
+
1286
+ --mask-output optional path for a FASTA alignment
1287
+ with flagged residues masked
1288
+
1289
+ --mask-character single ambiguity character used in
1290
+ the masked alignment (default: ?)
1291
+
1292
+ --json output the report as JSON
1293
+ """
1294
+ ),
1295
+ )
1296
+ parser.add_argument("alignment", type=str, help=SUPPRESS)
1297
+ parser.add_argument(
1298
+ "--cutoff",
1299
+ type=float,
1300
+ default=3.0,
1301
+ required=False,
1302
+ help=SUPPRESS,
1303
+ )
1304
+ parser.add_argument(
1305
+ "--report",
1306
+ type=str,
1307
+ default=None,
1308
+ required=False,
1309
+ help=SUPPRESS,
1310
+ )
1311
+ parser.add_argument(
1312
+ "--mask-output",
1313
+ type=str,
1314
+ default=None,
1315
+ required=False,
1316
+ help=SUPPRESS,
1317
+ )
1318
+ parser.add_argument(
1319
+ "--mask-character",
1320
+ type=str,
1321
+ default="?",
1322
+ required=False,
1323
+ help=SUPPRESS,
1324
+ )
1325
+ _add_json_argument(parser)
1326
+ _run_service(parser, argv, AlignmentOutlierRegions)
1327
+
1240
1328
  @staticmethod
1241
1329
  def column_score(argv):
1242
1330
  if (
@@ -3211,7 +3299,8 @@ class Phykit:
3211
3299
  )
3212
3300
  parser.add_argument(
3213
3301
  "--optimization", type=str, default="acctran",
3214
- required=False, help=SUPPRESS, metavar=""
3302
+ choices=("acctran", "deltran"), required=False,
3303
+ help=SUPPRESS, metavar=""
3215
3304
  )
3216
3305
  parser.add_argument(
3217
3306
  "--phylogram", action="store_true", required=False, help=SUPPRESS
@@ -3961,23 +4050,24 @@ class Phykit:
3961
4050
  Genes that have covarying evolutionary histories tend to have
3962
4051
  similar functions and expression levels.
3963
4052
 
3964
- Input two phylogenies and calculate the correlation among relative
3965
- evolutionary rates between the two phylogenies. The two input trees
3966
- do not have to have the same taxa. This function will first prune both
3967
- trees to have the same tips. To transform branch lengths into relative
3968
- rates, PhyKIT uses the putative species tree's branch lengths, which is
3969
- inputted by the user. As recommended by the original method developers,
3970
- outlier branche lengths are removed. Outlier branches have a relative
3971
- evolutionary rate greater than five.
4053
+ Input two gene phylogenies and calculate the Pearson correlation among
4054
+ their relative evolutionary rates. PhyKIT first prunes both gene trees
4055
+ and the reference tree to their shared taxa. The three rooted trees must
4056
+ then have the same topology. Each gene-tree branch length is divided by
4057
+ the corresponding reference-tree branch length. Branch pairs are removed
4058
+ if either relative rate is greater than five, and the remaining rates are
4059
+ Z-transformed before correlation.
3972
4060
 
3973
4061
  PhyKIT reports two tab delimited values:
3974
4062
  col1: correlation coefficient
3975
4063
  col2: p-value
3976
4064
 
3977
- Method is empirically evaluated by Clark et al., Genome Research
3978
- (2012), doi: 10.1101/gr.132647.111. Normalization method using a
3979
- species tree follows Sato et al., Bioinformatics (2005), doi:
3980
- 10.1093/bioinformatics/bti564.
4065
+ This CovER calculation is described by Steenwyk et al., Science
4066
+ Advances (2022), doi: 10.1126/sciadv.abn0105, and is based on the
4067
+ mirror-tree principle developed by Sato et al., Bioinformatics (2005),
4068
+ doi: 10.1093/bioinformatics/bti564. ERC2.0 and RERconverge use a
4069
+ different residual-based rate normalization and are not expected to
4070
+ return the same coefficient from the same trees.
3981
4071
 
3982
4072
 
3983
4073
  Aliases:
@@ -6973,9 +7063,9 @@ class Phykit:
6973
7063
  (Default: majority)
6974
7064
 
6975
7065
  --missing-taxa how to handle mismatched
6976
- taxa across trees:
6977
- error or shared
6978
- (Default: error)
7066
+ taxa across trees: allow,
7067
+ error, or shared
7068
+ (Default: allow)
6979
7069
 
6980
7070
  --json optional argument to output
6981
7071
  results as JSON
@@ -8532,21 +8622,36 @@ class Phykit:
8532
8622
  f"""\
8533
8623
  {help_header}
8534
8624
 
8535
- Determines potentially spurious homologs using branch lengths.
8625
+ Determines potentially spurious homologs using branch lengths
8626
+ or topology-aware tree-diameter impact.
8536
8627
 
8537
8628
  Identifies potentially spurious sequences and reports
8538
8629
  tips in the phylogeny that could possibly be removed
8539
8630
  from the associated multiple sequence alignment. PhyKIT
8540
- does so by identifying and reporting long terminal branches
8541
- defined as branches that are equal to or 20 times the median
8542
- length of all branches.
8543
-
8544
- PhyKIT reports the following information
8631
+ By default, PhyKIT identifies and reports long terminal
8632
+ branches defined as branches that are at least 20 times the
8633
+ median terminal-branch length. The diameter-impact method
8634
+ instead searches tree-diameter endpoints, measures the
8635
+ reduction caused by removing each selected endpoint, and
8636
+ reports statistically extreme log reductions.
8637
+
8638
+ Median-factor output reports the following information
8545
8639
  col1: name of tip that is a putatively spurious sequence
8546
8640
  col2: length of branch leading to putatively spurious sequence
8547
8641
  col3: threshold used to identify putatively spurious sequences
8548
8642
  col4: median branch length in the phylogeny
8549
8643
 
8644
+ Diameter-impact output for one tree reports
8645
+ col1: name of tip that is a putatively spurious sequence
8646
+ col2: log reduction in tree diameter
8647
+ col3: upper-tail p-value
8648
+ col4: removal rank
8649
+ col5: terminal branch length
8650
+ col6: tree diameter before removal
8651
+ col7: tree diameter after removal
8652
+
8653
+ With --tree-list, the tree path is prepended as column 1.
8654
+
8550
8655
  If there are no putatively spurious sequences, "None" is reported.
8551
8656
 
8552
8657
  Using this method to identify potentially spurious sequences
@@ -8560,6 +8665,10 @@ class Phykit:
8560
8665
 
8561
8666
  Usage:
8562
8667
  phykit spurious_sequence <file> [-f 20] [--json]
8668
+ phykit spurious_sequence <file> --method diameter-impact
8669
+ [--alpha 0.05] [--max-remove <count>] [--json]
8670
+ phykit spurious_sequence <tree_list> --method diameter-impact
8671
+ --tree-list [--per-species] [--alpha 0.05] [--json]
8563
8672
 
8564
8673
  Options
8565
8674
  =====================================================
@@ -8572,6 +8681,25 @@ class Phykit:
8572
8681
  the threshold of long branches.
8573
8682
  (Default: 20)
8574
8683
 
8684
+ --method detection method: median-factor
8685
+ or diameter-impact.
8686
+ (Default: median-factor)
8687
+
8688
+ --alpha upper-tail significance level for
8689
+ diameter-impact detection.
8690
+ (Default: 0.05)
8691
+
8692
+ --max-remove maximum number of diameter
8693
+ endpoints to evaluate. By default,
8694
+ uses min(n/4, 5*sqrt(n)).
8695
+
8696
+ --tree-list interpret <file> as a line-delimited
8697
+ list of tree paths and calibrate
8698
+ signatures across all trees.
8699
+
8700
+ --per-species with --tree-list, calibrate each
8701
+ taxon's signatures separately.
8702
+
8575
8703
  --json optional argument to output
8576
8704
  results as JSON
8577
8705
  """
@@ -8579,6 +8707,16 @@ class Phykit:
8579
8707
  )
8580
8708
  parser.add_argument("tree", type=str, help=SUPPRESS)
8581
8709
  parser.add_argument("-f", "--factor", type=float, required=False, help=SUPPRESS)
8710
+ parser.add_argument(
8711
+ "--method",
8712
+ choices=("median-factor", "diameter-impact"),
8713
+ default="median-factor",
8714
+ help=SUPPRESS,
8715
+ )
8716
+ parser.add_argument("--alpha", type=float, default=0.05, help=SUPPRESS)
8717
+ parser.add_argument("--max-remove", type=int, default=None, help=SUPPRESS)
8718
+ parser.add_argument("--tree-list", action="store_true", help=SUPPRESS)
8719
+ parser.add_argument("--per-species", action="store_true", help=SUPPRESS)
8582
8720
  _add_json_argument(parser)
8583
8721
  _run_service(parser, argv, SpuriousSequence)
8584
8722
 
@@ -10046,7 +10184,15 @@ class Phykit:
10046
10184
  """
10047
10185
  ),
10048
10186
  )
10049
- parser.add_argument("-a", "--alignment_list", type=str, help=SUPPRESS)
10187
+ parser.add_argument(
10188
+ "-a",
10189
+ "--alignment",
10190
+ "--alignment-list",
10191
+ "--alignment_list",
10192
+ dest="alignment_list",
10193
+ type=str,
10194
+ help=SUPPRESS,
10195
+ )
10050
10196
  parser.add_argument("-p", "--prefix", type=str, help=SUPPRESS)
10051
10197
  parser.add_argument("--threshold", type=float, required=False, default=0, help=SUPPRESS)
10052
10198
  parser.add_argument("--plot-occupancy", action="store_true", required=False, help=SUPPRESS)
@@ -10087,7 +10233,7 @@ class Phykit:
10087
10233
  pk_thread_dna, pk_pal2nal, pk_p2n
10088
10234
 
10089
10235
  Usage:
10090
- phykit thread_dna -p <file> -n <file> [-c/--clipkit_log_file
10236
+ phykit thread_dna -p <file> -n <file> [-c/--clipkit-log-file
10091
10237
  <clipkit outputted log file> -s] [--json]
10092
10238
 
10093
10239
  Options
@@ -10096,7 +10242,7 @@ class Phykit:
10096
10242
 
10097
10243
  -n/--nucleotide nucleotide sequence file
10098
10244
 
10099
- -c/--clipkit_log clipkit outputted log file
10245
+ -c/--clipkit-log-file ClipKIT output log file
10100
10246
 
10101
10247
  -s/--stop boolean for whether or not
10102
10248
  stop codons should be kept.
@@ -10112,6 +10258,7 @@ class Phykit:
10112
10258
  parser.add_argument("-n", "--nucleotide", type=str, help=SUPPRESS)
10113
10259
  parser.add_argument(
10114
10260
  "-c",
10261
+ "--clipkit-log-file",
10115
10262
  "--clipkit_log_file",
10116
10263
  type=str,
10117
10264
  required=False,
@@ -10146,10 +10293,18 @@ def alignment_entropy(argv=None):
10146
10293
  Phykit.alignment_entropy(sys.argv[1:])
10147
10294
 
10148
10295
 
10296
+ def alignment_recoding(argv=None):
10297
+ Phykit.alignment_recoding(sys.argv[1:])
10298
+
10299
+
10149
10300
  def alignment_outlier_taxa(argv=None):
10150
10301
  Phykit.alignment_outlier_taxa(sys.argv[1:])
10151
10302
 
10152
10303
 
10304
+ def alignment_outlier_regions(argv=None):
10305
+ Phykit.alignment_outlier_regions(sys.argv[1:])
10306
+
10307
+
10153
10308
  def column_score(argv=None):
10154
10309
  Phykit.column_score(sys.argv[1:])
10155
10310
 
@@ -23,6 +23,7 @@ AlignmentEntropy = _LazyServiceFactory("phykit.services.alignment.alignment_entr
23
23
  AlignmentRecoding = _LazyServiceFactory("phykit.services.alignment.alignment_recoding", "AlignmentRecoding")
24
24
  AlignmentSubsample = _LazyServiceFactory("phykit.services.alignment.alignment_subsample", "AlignmentSubsample")
25
25
  AlignmentOutlierTaxa = _LazyServiceFactory("phykit.services.alignment.alignment_outlier_taxa", "AlignmentOutlierTaxa")
26
+ AlignmentOutlierRegions = _LazyServiceFactory("phykit.services.alignment.alignment_outlier_regions", "AlignmentOutlierRegions")
26
27
  ColumnScore = _LazyServiceFactory("phykit.services.alignment.column_score", "ColumnScore")
27
28
  CompositionalBiasPerSite = _LazyServiceFactory("phykit.services.alignment.compositional_bias_per_site", "CompositionalBiasPerSite")
28
29
  CompositionPerTaxon = _LazyServiceFactory("phykit.services.alignment.composition_per_taxon", "CompositionPerTaxon")
@@ -7,6 +7,7 @@ _EXPORTS = {
7
7
  "AlignmentLengthNoGaps": "alignment_length_no_gaps",
8
8
  "AlignmentEntropy": "alignment_entropy",
9
9
  "AlignmentRecoding": "alignment_recoding",
10
+ "AlignmentOutlierRegions": "alignment_outlier_regions",
10
11
  "ColumnScore": "column_score",
11
12
  "CompositionalBiasPerSite": "compositional_bias_per_site",
12
13
  "CompositionPerTaxon": "composition_per_taxon",