descriptron-core 2.1.3__tar.gz → 2.3.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 (144) hide show
  1. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/PKG-INFO +1 -2
  2. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/pyproject.toml +1 -1
  3. descriptron_core-2.3.0/src/descriptron_core/tools/descriptron_phylo.py +410 -0
  4. descriptron_core-2.3.0/src/descriptron_core/tools/descriptron_trait_stats.py +528 -0
  5. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/run_full_pipeline_v2.py +161 -5
  6. descriptron_core-2.3.0/src/descriptron_core/tools/validate_phylo_published_waldron2025.py +116 -0
  7. descriptron_core-2.3.0/src/descriptron_core/tools/validate_phylo_real_tree.py +155 -0
  8. descriptron_core-2.3.0/src/descriptron_core/tools/validate_phylo_traits.py +186 -0
  9. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/validate_semilandmarks_vs_geomorph.py +5 -0
  10. descriptron_core-2.3.0/src/descriptron_core/tools/validate_trait_stats.py +134 -0
  11. descriptron_core-2.1.3/NOTICE.bak_pre_212_20260929_1100 +0 -59
  12. descriptron_core-2.1.3/pyproject.toml.bak_pre_203_20260924_145320 +0 -81
  13. descriptron_core-2.1.3/pyproject.toml.bak_pre_204_20260924_165335 +0 -82
  14. descriptron_core-2.1.3/pyproject.toml.bak_pre_210_20260925_103754 +0 -82
  15. descriptron_core-2.1.3/pyproject.toml.bak_pre_211_20260925_114912 +0 -82
  16. descriptron_core-2.1.3/pyproject.toml.bak_pre_213_20260929_1414 +0 -82
  17. descriptron_core-2.1.3/pyproject.toml.bak_pre_keys_20260924_165335 +0 -81
  18. descriptron_core-2.1.3/src/descriptron_core/cli.py.bak_pre_keys_20260924_165335 +0 -98
  19. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/.gitignore +0 -0
  20. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/LICENSE +0 -0
  21. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/NOTICE +0 -0
  22. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/README.md +0 -0
  23. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/__init__.py +0 -0
  24. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/cli.py +0 -0
  25. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/biorag_system_prompts_v1.txt +0 -0
  26. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/biorag_system_prompts_v2.txt +0 -0
  27. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/diaphorina_user_prompts.txt +0 -0
  28. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/ontologies/aism.obo +0 -0
  29. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/ontologies/pato.obo +0 -0
  30. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/sdd_1.1/SDD.xsd +0 -0
  31. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/sdd_1.1/SDD_EnumLib.xsd +0 -0
  32. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/sdd_1.1/SDD_TypeLib.xsd +0 -0
  33. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/sdd_1.1/UBIF_BasePattern.xsd +0 -0
  34. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/sdd_1.1/UBIF_CoreExtensions.xsd +0 -0
  35. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/sdd_1.1/UBIF_CoreOntology.xsd +0 -0
  36. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/sdd_1.1/UBIF_EnumLib.xsd +0 -0
  37. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/sdd_1.1/UBIF_LinneanCore.xsd +0 -0
  38. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/sdd_1.1/UBIF_TypeLib.xsd +0 -0
  39. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/sdd_1.1/w3c-schemata/xml.xsd +0 -0
  40. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/taxpub/sample_treatment_deposit_example.xml +0 -0
  41. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/taxpub/sample_zookeys_26056_tp.xml +0 -0
  42. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/schemas/taxpub/tax-treatment-NS0-v1_flat.dtd +0 -0
  43. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/taxon_profiles/TEMPLATE_taxon_profile.yaml +0 -0
  44. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/data/biorag_prompts/taxon_profiles/diaphorina_taxon_profile.yaml +0 -0
  45. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/FHS_and_CLAHE_V21.py +0 -0
  46. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_add_discrete_characters_v1.py +0 -0
  47. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_annotation_reorient_v1.py +0 -0
  48. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_annotation_screen_v1.py +0 -0
  49. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_autapomorphy_v1.py +0 -0
  50. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_calibrate_v1.py +0 -0
  51. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_calibration_figures_v1.py +0 -0
  52. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_character_gate_v1.py +0 -0
  53. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_character_reliability_v1.py +0 -0
  54. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_character_robustness_v1.py +0 -0
  55. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_collaborator_forms_v1.py +0 -0
  56. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_computed_sets_v1.py +0 -0
  57. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_confabulation_checker_v2.py +0 -0
  58. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_congruence_compare_v1.py +0 -0
  59. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_description_refiner_v1.py +0 -0
  60. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_descriptive_scoring_v1.py +0 -0
  61. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_feature_policy.py +0 -0
  62. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_frame_orientation_calibrate_v1.py +0 -0
  63. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_frame_orientation_v1.py +0 -0
  64. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_gate_compare_v1.py +0 -0
  65. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_graph_identify_v1.py +0 -0
  66. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_graph_support_figure_v1.py +0 -0
  67. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_homology_frame_v1.py +0 -0
  68. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_instrument_compare_v3.py +0 -0
  69. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_key_builder_v1.py +0 -0
  70. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_key_feature_filter_v2.py +0 -0
  71. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_key_fuzzy_figures_v1.py +0 -0
  72. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_key_fuzzy_v1.py +0 -0
  73. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_key_holdout_v1.py +0 -0
  74. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_key_jackknife_support_v1.py +0 -0
  75. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_label_conflict_check_v1.py +0 -0
  76. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_llm_backend.py +0 -0
  77. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_make_taxon_profile_v1.py +0 -0
  78. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_methods_summary_figure_v1.py +0 -0
  79. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_novelty_score_v1.py +0 -0
  80. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_ontology_annotator_v2.py +0 -0
  81. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_outgroup_batch_check_v1.py +0 -0
  82. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_outline_shape_v1.py +0 -0
  83. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/biorag_system_prompts_v1.txt +0 -0
  84. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/biorag_system_prompts_v2.txt +0 -0
  85. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/diaphorina_user_prompts.txt +0 -0
  86. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/ontologies/aism.obo +0 -0
  87. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/ontologies/pato.obo +0 -0
  88. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/sdd_1.1/SDD.xsd +0 -0
  89. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/sdd_1.1/SDD_EnumLib.xsd +0 -0
  90. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/sdd_1.1/SDD_TypeLib.xsd +0 -0
  91. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/sdd_1.1/UBIF_BasePattern.xsd +0 -0
  92. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/sdd_1.1/UBIF_CoreExtensions.xsd +0 -0
  93. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/sdd_1.1/UBIF_CoreOntology.xsd +0 -0
  94. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/sdd_1.1/UBIF_EnumLib.xsd +0 -0
  95. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/sdd_1.1/UBIF_LinneanCore.xsd +0 -0
  96. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/sdd_1.1/UBIF_TypeLib.xsd +0 -0
  97. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/sdd_1.1/w3c-schemata/xml.xsd +0 -0
  98. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/taxpub/sample_treatment_deposit_example.xml +0 -0
  99. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/taxpub/sample_zookeys_26056_tp.xml +0 -0
  100. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/schemas/taxpub/tax-treatment-NS0-v1_flat.dtd +0 -0
  101. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/taxon_profiles/TEMPLATE_taxon_profile.yaml +0 -0
  102. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_prompts/taxon_profiles/diaphorina_taxon_profile.yaml +0 -0
  103. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_provenance_v1.py +0 -0
  104. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_rebuild_downstream_v1.sh +0 -0
  105. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_reliability_figures_v1.py +0 -0
  106. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_rename_species_v1.py +0 -0
  107. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_rerun_descriptive_tables_v1.sh +0 -0
  108. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_retest_compare_v1.py +0 -0
  109. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_specimen_id.py +0 -0
  110. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_subjective_checks_v1.py +0 -0
  111. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_type_material_v1.py +0 -0
  112. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_vlm_characters_v1.py +0 -0
  113. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_vlm_heatmap_figures_v1.py +0 -0
  114. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_vlm_reliability_figure_v1.py +0 -0
  115. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biorag_vlm_roi_figures_v1.py +0 -0
  116. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biosyslit_rag_retrieval.py +0 -0
  117. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/biosyslit_rag_retrieval_v2.py +0 -0
  118. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/build_monograph_exports_v1.py +0 -0
  119. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/build_species_treatment_docx_v2.py +0 -0
  120. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/coco_combiner_V13.py +0 -0
  121. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/coco_converter_v24.py +0 -0
  122. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/color_extraction_with_names-v8.py +0 -0
  123. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/color_phenomics_homology_v2_1.py +0 -0
  124. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/compile_specimen_data.py +0 -0
  125. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/descriptron_centerline.py +0 -0
  126. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/descriptron_coco_tools.py +0 -0
  127. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/descriptron_convert.py +0 -0
  128. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/descriptron_credentials.py +0 -0
  129. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/descriptron_joints.py +0 -0
  130. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/descriptron_metadata.py +0 -0
  131. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/descriptron_rosetta.py +0 -0
  132. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/descriptron_shape_stats.py +0 -0
  133. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/landmark_gpa_V1.py +0 -0
  134. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/landmark_gpa_V2.py +0 -0
  135. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/make_reproducibility_bundle.py +0 -0
  136. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/semi_landmark_and_kpts_procrustesV34_GPA.py +0 -0
  137. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/semi_landmark_and_kpts_procrustesV42_GPA.py +0 -0
  138. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/texture_phenomics_from_coco.py +0 -0
  139. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/texture_phenomics_homology.py +0 -0
  140. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/validate_centerline_lengths.py +0 -0
  141. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/validate_pipeline_gm_vs_geomorph.py +0 -0
  142. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/validate_shape_stats_vs_geomorph.py +0 -0
  143. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/validate_shape_stats_vs_rrpp.py +0 -0
  144. {descriptron_core-2.1.3 → descriptron_core-2.3.0}/src/descriptron_core/tools/validate_texture_glcm.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: descriptron-core
3
- Version: 2.1.3
3
+ Version: 2.3.0
4
4
  Summary: Evidence-tiered species descriptions, keys and audits from phenomic matrices
5
5
  Project-URL: Homepage, https://github.com/alexrvandam/Descriptron
6
6
  Project-URL: Repository, https://github.com/alexrvandam/Descriptron
@@ -9,7 +9,6 @@ Author: Alex R. Van Dam
9
9
  License: Apache-2.0
10
10
  License-File: LICENSE
11
11
  License-File: NOTICE
12
- License-File: NOTICE.bak_pre_212_20260929_1100
13
12
  Keywords: COCO,morphometrics,phenomics,species description,taxonomy
14
13
  Classifier: Intended Audience :: Science/Research
15
14
  Classifier: License :: OSI Approved :: Apache Software License
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "descriptron-core"
7
- version = "2.1.3"
7
+ version = "2.3.0"
8
8
  description = "Evidence-tiered species descriptions, keys and audits from phenomic matrices"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -0,0 +1,410 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ descriptron_phylo.py - phylogenetic comparative analyses of any continuous Descriptron traits
4
+ =============================================================================================
5
+
6
+ Given a Newick tree and one or more trait tables (landmark shape, linear measurements, colour pattern, texture, or
7
+ any other continuous features), computes on species means:
8
+
9
+ signal multivariate phylogenetic signal Kmult (Adams 2014), permutation P and effect size Z,
10
+ as geomorph::physignal
11
+ pgls phylogenetic regression of a trait set on a predictor (for example log centroid size: phylogenetic
12
+ allometry) by generalised least squares under Brownian motion, SS / R2 / F with residual
13
+ randomisation, as geomorph::procD.pgls
14
+ morphospace principal components of the species means with ancestral states estimated under Brownian motion
15
+ (generalised least squares) projected into the same space and the tree drawn through them, as
16
+ geomorph::gm.prcomp(phy = )
17
+
18
+ Trait tables: CSV with one row per specimen (or per species) and numeric columns. The species of each row comes
19
+ from a column (--species_col) or from a regular expression applied to an id column (--species_regex). Rows of the
20
+ same species are averaged. Species absent from the tree, or tree tips without data, are dropped (the tree is pruned).
21
+
22
+ python descriptron_phylo.py --tree tree.nwk --out_dir phylo/ \
23
+ --traits shape=landmark_gpa/forewing/forewing_procrustes_coords.csv \
24
+ --traits colour=color_homology/whole_wing/color_homology_features_whole_wing.csv \
25
+ --species_regex "morph_([A-Za-z]+\\d*?)_?\\d+_" --scale colour=standardize \
26
+ --pgls shape~logCS --analyses signal pgls morphospace
27
+
28
+ Scaling (--scale NAME=none|standardize|log): Kmult and the PGLS statistics weight every column by its variance, so a
29
+ set that mixes units (millimetres with ratios, colour channels with entropies) should be standardised; Procrustes
30
+ shape coordinates are analysed as they are (the default for a set whose columns look like x/y coordinates).
31
+
32
+ Validated against geomorph 4.1.1 and ape on geomorph's plethspecies data (validation/validate_phylo_real_tree.py).
33
+ """
34
+ from __future__ import annotations
35
+
36
+ import argparse
37
+ import csv
38
+ import json
39
+ import re
40
+ import sys
41
+ from pathlib import Path
42
+ from typing import Dict, List, Optional, Tuple
43
+
44
+ import numpy as np
45
+
46
+ # ============================================================================ tree
47
+ class Node:
48
+ __slots__ = ("name", "length", "kids", "parent", "depth", "idx")
49
+
50
+ def __init__(self, name="", length=0.0):
51
+ self.name, self.length, self.kids, self.parent, self.depth, self.idx = name, length, [], None, 0.0, -1
52
+
53
+
54
+ def parse_newick(s: str) -> Node:
55
+ s = s.strip().rstrip(";")
56
+ pos = 0
57
+
58
+ def node() -> Node:
59
+ nonlocal pos
60
+ n = Node()
61
+ if s[pos] == "(":
62
+ pos += 1
63
+ n.kids.append(node())
64
+ while s[pos] == ",":
65
+ pos += 1
66
+ n.kids.append(node())
67
+ pos += 1 # ')'
68
+ m = re.match(r"([^:,();\[]*)(?:\[[^\]]*\])?(?::([0-9.eE+\-]+))?", s[pos:])
69
+ pos += m.end()
70
+ n.name = m.group(1).strip().strip("'\"")
71
+ n.length = float(m.group(2) or 0.0)
72
+ for k in n.kids:
73
+ k.parent = n
74
+ return n
75
+
76
+ root = node()
77
+ root.length = 0.0 # the root's own branch does not count
78
+ _set_depths(root)
79
+ return root
80
+
81
+
82
+ def _set_depths(n: Node, d: float = 0.0):
83
+ n.depth = d
84
+ for k in n.kids:
85
+ _set_depths(k, d + k.length)
86
+
87
+
88
+ def tips_of(n: Node) -> List[Node]:
89
+ return [n] if not n.kids else [t for k in n.kids for t in tips_of(k)]
90
+
91
+
92
+ def internal_nodes(n: Node) -> List[Node]:
93
+ return ([n] if n.kids else []) + [x for k in n.kids for x in internal_nodes(k)]
94
+
95
+
96
+ def prune(root: Node, keep: set) -> Node:
97
+ """Drop tips not in `keep`; collapse nodes left with one child (their branch lengths add up)."""
98
+ def rec(n: Node) -> Optional[Node]:
99
+ if not n.kids:
100
+ return n if n.name in keep else None
101
+ kids = [c for c in (rec(k) for k in n.kids) if c is not None]
102
+ if not kids:
103
+ return None
104
+ if len(kids) == 1:
105
+ kids[0].length += n.length
106
+ return kids[0]
107
+ n.kids = kids
108
+ for k in kids:
109
+ k.parent = n
110
+ return n
111
+
112
+ r = rec(root)
113
+ r.length, r.parent = 0.0, None
114
+ _set_depths(r)
115
+ return r
116
+
117
+
118
+ def mrca_depth(a: Node, b: Node) -> float:
119
+ anc = set()
120
+ x = a
121
+ while x is not None:
122
+ anc.add(id(x)); x = x.parent
123
+ y = b
124
+ while id(y) not in anc:
125
+ y = y.parent
126
+ return y.depth
127
+
128
+
129
+ def vcv(nodes_a: List[Node], nodes_b: List[Node]) -> np.ndarray:
130
+ """Brownian-motion covariance: shared path length from the root (tips and internal nodes alike)."""
131
+ return np.array([[mrca_depth(a, b) for b in nodes_b] for a in nodes_a])
132
+
133
+
134
+ # ============================================================================ statistics
135
+ def _whiten(C: np.ndarray) -> np.ndarray:
136
+ """P with P'P = C^-1 (any such P gives the same GLS sums of squares)."""
137
+ return np.linalg.inv(np.linalg.cholesky(C))
138
+
139
+
140
+ def kmult(Y: np.ndarray, C: np.ndarray) -> float:
141
+ """Adams (2014) multivariate K, as geomorph::physignal."""
142
+ n = len(Y)
143
+ Ci = np.linalg.inv(C)
144
+ one = np.ones((n, 1))
145
+ a = np.linalg.solve(one.T @ Ci @ one, one.T @ Ci @ Y)
146
+ R = Y - one @ a
147
+ obs = np.trace(R.T @ R) / np.trace(R.T @ Ci @ R)
148
+ expct = (np.trace(C) - n / Ci.sum()) / (n - 1)
149
+ return float(obs / expct)
150
+
151
+
152
+ def effect_size(obs: float, rand: np.ndarray) -> float:
153
+ r = np.r_[obs, rand]
154
+ sd = r.std(ddof=1)
155
+ return float((obs - r.mean()) / sd) if sd > 0 else float("nan")
156
+
157
+
158
+ def phylo_signal(Y, C, iters, rng) -> Dict:
159
+ K = kmult(Y, C)
160
+ rand = np.array([kmult(Y[rng.permutation(len(Y))], C) for _ in range(iters)])
161
+ return {"Kmult": K, "P": float((1 + (rand >= K - 1e-12).sum()) / (iters + 1)), "Z": effect_size(K, rand)}
162
+
163
+
164
+ def pgls(Y: np.ndarray, x: np.ndarray, C: np.ndarray, iters: int, rng) -> Dict:
165
+ """Y ~ x under Brownian motion by GLS; SS from the whitened data, residual randomisation of the null model
166
+ (intercept only), as RRPP / geomorph::procD.pgls with a single predictor."""
167
+ n = len(Y)
168
+ P = _whiten(C)
169
+ Yt = P @ Y
170
+ X0 = P @ np.ones((n, 1))
171
+ X1 = P @ np.column_stack([np.ones(n), x])
172
+
173
+ def rss(X, Yy):
174
+ B, *_ = np.linalg.lstsq(X, Yy, rcond=None)
175
+ R = Yy - X @ B
176
+ return float((R ** 2).sum())
177
+
178
+ B0, *_ = np.linalg.lstsq(X0, Yt, rcond=None)
179
+ fit0, res0 = X0 @ B0, Yt - X0 @ B0
180
+ ss_tot, ss_res = rss(X0, Yt), rss(X1, Yt)
181
+ ss = ss_tot - ss_res
182
+ df, dfr = 1, n - 2
183
+ F = (ss / df) / (ss_res / dfr)
184
+ rand = []
185
+ for _ in range(iters):
186
+ Yp = fit0 + res0[rng.permutation(n)]
187
+ s_t, s_r = rss(X0, Yp), rss(X1, Yp)
188
+ rand.append(((s_t - s_r) / df) / (s_r / dfr))
189
+ rand = np.array(rand)
190
+ return {"Df": df, "SS": ss, "MS": ss / df, "Rsq": ss / ss_tot, "F": F, "Z": effect_size(F, rand),
191
+ "P": float((1 + (rand >= F - 1e-12).sum()) / (iters + 1)), "SS_residual": ss_res, "SS_total": ss_tot}
192
+
193
+
194
+ def ancestral_states(Y: np.ndarray, tips: List[Node], nodes: List[Node]) -> np.ndarray:
195
+ """Ancestral states under Brownian motion by GLS: a = mu + C_nt C_tt^-1 (Y - 1 mu), with mu the GLS root state."""
196
+ Ctt = vcv(tips, tips)
197
+ Cnt = vcv(nodes, tips)
198
+ Ci = np.linalg.inv(Ctt)
199
+ one = np.ones((len(tips), 1))
200
+ mu = np.linalg.solve(one.T @ Ci @ one, one.T @ Ci @ Y)
201
+ return mu + Cnt @ Ci @ (Y - one @ mu)
202
+
203
+
204
+ # ============================================================================ data
205
+ def _is_number(v: str) -> bool:
206
+ try:
207
+ float(v); return True
208
+ except ValueError:
209
+ return False
210
+
211
+
212
+ def _key_forms(s: str) -> List[str]:
213
+ """an id with and without Descriptron's annotation suffix ("x.png_3") and extension."""
214
+ s = str(s).strip(); base = re.sub(r"\.(png|jpe?g|tiff?|bmp)_\d+$", r".\1", s, flags=re.I)
215
+ stem = re.sub(r"\.(png|jpe?g|tiff?|bmp)$", "", base, flags=re.I)
216
+ return [s, base, stem, Path(stem).name]
217
+
218
+
219
+ def load_group_map(path: str, group_col: Optional[str] = None) -> Dict[str, str]:
220
+ """group labels CSV (filename + group_label/species): id -> species."""
221
+ rows = list(csv.DictReader(open(path, newline=""), delimiter="\t" if str(path).endswith(".tsv") else ","))
222
+ lc = {c.strip().lower(): c for c in rows[0]}
223
+ fcol = lc.get("filename") or lc.get("file") or lc.get("specimen") or list(rows[0])[0]
224
+ gcol = group_col or lc.get("group_label") or lc.get("species") or list(rows[0])[1]
225
+ m: Dict[str, str] = {}
226
+ for r in rows:
227
+ for k in _key_forms(r[fcol]):
228
+ m.setdefault(k, r[gcol])
229
+ return m
230
+
231
+
232
+ def load_traits(path: str, species_col: Optional[str], species_regex: Optional[str], id_col: Optional[str],
233
+ groups: Optional[Dict[str, str]] = None):
234
+ rows = list(csv.DictReader(open(path, newline="")))
235
+ if not rows:
236
+ sys.exit(f"{path}: no rows")
237
+ cols = list(rows[0])
238
+ if groups is not None and not (species_col and species_col in cols): # species from a group-labels file
239
+ idc = id_col or next((c for c in ("filename", "specimen_id", "specimen", "image", "id", "file") if c in cols), cols[0])
240
+ sp = [next((groups[k] for k in _key_forms(r[idc]) if k in groups), None) for r in rows]
241
+ species_col = idc # the id column is not a trait
242
+ elif species_col and species_col in cols:
243
+ sp = [r[species_col] for r in rows]
244
+ else:
245
+ idc = id_col or next((c for c in ("filename", "specimen_id", "specimen", "image", "id", "file") if c in cols), cols[0])
246
+ if not species_regex:
247
+ sys.exit(f"{path}: give --species_col or --species_regex (no species column found)")
248
+ rx = re.compile(species_regex)
249
+ sp = []
250
+ for r in rows:
251
+ m = rx.search(r[idc])
252
+ sp.append(m.group(1) if m else None)
253
+ num = [c for c in cols if c != species_col and all(_is_number(r[c]) or r[c] == "" for r in rows)
254
+ and any(r[c] != "" for r in rows)]
255
+ M = np.array([[float(r[c]) if r[c] != "" else np.nan for c in num] for r in rows])
256
+ by: Dict[str, List[int]] = {}
257
+ for i, s in enumerate(sp):
258
+ if s:
259
+ by.setdefault(s, []).append(i)
260
+ species = sorted(by)
261
+ means = np.array([np.nanmean(M[by[s]], axis=0) for s in species])
262
+ keep = ~np.isnan(means).any(axis=0) # drop columns missing for any species
263
+ return species, [c for c, k in zip(num, keep) if k], means[:, keep], {s: len(v) for s, v in by.items()}
264
+
265
+
266
+ def scale(M: np.ndarray, how: str) -> np.ndarray:
267
+ if how == "standardize":
268
+ sd = M.std(axis=0, ddof=1)
269
+ ok = sd > 0
270
+ return (M[:, ok] - M[:, ok].mean(0)) / sd[ok]
271
+ if how == "log":
272
+ if (M <= 0).any():
273
+ sys.exit("--scale log needs positive values")
274
+ return np.log(M)
275
+ return M
276
+
277
+
278
+ # ============================================================================ plot
279
+ def plot_morphospace(pc_tips, pc_nodes, tips, nodes, ev, path, title):
280
+ import matplotlib
281
+ matplotlib.use("Agg")
282
+ import matplotlib.pyplot as plt
283
+ pos = {id(t): pc_tips[i] for i, t in enumerate(tips)}
284
+ pos.update({id(n): pc_nodes[i] for i, n in enumerate(nodes)})
285
+ fig, ax = plt.subplots(figsize=(6.5, 5.5))
286
+ for n in nodes:
287
+ for k in n.kids:
288
+ a, b = pos[id(n)], pos[id(k)]
289
+ ax.plot([a[0], b[0]], [a[1], b[1]], color="#6b7780", lw=0.9, zorder=1)
290
+ ax.scatter(pc_nodes[:, 0], pc_nodes[:, 1], s=14, color="white", edgecolor="#6b7780", zorder=2, label="ancestral states")
291
+ ax.scatter(pc_tips[:, 0], pc_tips[:, 1], s=30, color="#0072B2", zorder=3, label="species means")
292
+ for i, t in enumerate(tips):
293
+ ax.annotate(t.name, pc_tips[i, :2], xytext=(3, 3), textcoords="offset points", fontsize=7)
294
+ ax.set_xlabel(f"PC1 ({100 * ev[0]:.1f}%)"); ax.set_ylabel(f"PC2 ({100 * ev[1]:.1f}%)")
295
+ ax.set_title(title, fontsize=10); ax.legend(fontsize=7, frameon=False)
296
+ fig.tight_layout(); fig.savefig(path, dpi=200); plt.close(fig)
297
+
298
+
299
+ # ============================================================================ main
300
+ def main(argv=None):
301
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
302
+ ap.add_argument("--tree", required=True, help="Newick tree whose tips are species names")
303
+ ap.add_argument("--traits", action="append", required=True, metavar="NAME=CSV",
304
+ help="a trait table; repeat for several sets (shape, measurements, colour, texture, ...)")
305
+ ap.add_argument("--species_col", default=None, help="column holding the species (default: use --species_regex)")
306
+ ap.add_argument("--species_regex", default=None, help="regex with one group extracting the species from the id column")
307
+ ap.add_argument("--groups", default=None, help="group labels CSV (filename + group_label/species) giving each "
308
+ "specimen's species, as for the rest of the pipeline (instead of --species_col/--species_regex)")
309
+ ap.add_argument("--id_col", default=None, help="id column for --species_regex (default: filename/specimen_id/...)")
310
+ ap.add_argument("--columns", action="append", default=[], metavar="NAME=REGEX",
311
+ help="keep only the columns of trait set NAME that match REGEX")
312
+ ap.add_argument("--scale", action="append", default=[], metavar="NAME=none|standardize|log")
313
+ ap.add_argument("--size_col", default=r"centroid|csize",
314
+ help="regex for a size column kept out of the trait set and used as the logCS predictor")
315
+ ap.add_argument("--pgls", action="append", default=[], metavar="SET~PREDICTOR",
316
+ help="PREDICTOR is logCS (from a set's centroid-size column) or SET2:COLUMN")
317
+ ap.add_argument("--analyses", nargs="+", default=["signal", "morphospace"], choices=["signal", "pgls", "morphospace"])
318
+ ap.add_argument("--iterations", type=int, default=999); ap.add_argument("--seed", type=int, default=1)
319
+ ap.add_argument("--out_dir", required=True)
320
+ a = ap.parse_args(argv)
321
+ out = Path(a.out_dir); out.mkdir(parents=True, exist_ok=True)
322
+ rng = np.random.default_rng(a.seed)
323
+ root = parse_newick(Path(a.tree).read_text())
324
+ colsel = dict(x.split("=", 1) for x in a.columns)
325
+ gmap = load_group_map(a.groups) if a.groups else None
326
+ scales = dict(x.split("=", 1) for x in a.scale)
327
+
328
+ sets = {}
329
+ for spec in a.traits:
330
+ name, path = spec.split("=", 1)
331
+ sp, cols, M, counts = load_traits(path, a.species_col, a.species_regex, a.id_col, gmap)
332
+ if name in colsel:
333
+ rx = re.compile(colsel[name]); k = [i for i, c in enumerate(cols) if rx.search(c)]
334
+ cols, M = [cols[i] for i in k], M[:, k]
335
+ # a size column (centroid size) is kept aside: it is a predictor (logCS), not part of the trait set
336
+ szi = [i for i, c in enumerate(cols) if re.search(a.size_col, c, re.I)]
337
+ size = M[:, szi[0]] if szi else None
338
+ keep = [i for i in range(len(cols)) if i not in szi]
339
+ sets[name] = {"species": sp, "cols": [cols[i] for i in keep], "raw": M[:, keep], "size": size,
340
+ "counts": counts}
341
+
342
+ report = ["# Phylogenetic comparative analyses", "", f"Tree: {a.tree}", ""]
343
+ signal_rows, pgls_rows = [], []
344
+ for name, S in sets.items():
345
+ tipnames = {t.name for t in tips_of(root)}
346
+ common = [s for s in S["species"] if s in tipnames]
347
+ if len(common) < 4:
348
+ report.append(f"{name}: only {len(common)} species match the tree - skipped"); continue
349
+ tree = prune(parse_newick(Path(a.tree).read_text()), set(common))
350
+ tips = tips_of(tree)
351
+ idx = [S["species"].index(t.name) for t in tips]
352
+ how = scales.get(name, "none")
353
+ Y = scale(S["raw"][idx], how)
354
+ if Y.shape[1] == 0 or not np.isfinite(Y).all() or float(Y.var(axis=0).sum()) == 0:
355
+ report += [f"## {name}", "no variable differs among the species (for example empty homology cells) - skipped", ""]
356
+ continue
357
+ C = vcv(tips, tips)
358
+ S.update(tree=tree, tips=tips, Y=Y, C=C, idx=idx)
359
+ dropped = sorted(set(S["species"]) - set(common))
360
+ report += [f"## {name}", f"{len(tips)} species, {Y.shape[1]} variables (scale: {how})"
361
+ + (f"; not in the tree: {', '.join(dropped)}" if dropped else ""), ""]
362
+ if "signal" in a.analyses:
363
+ r = phylo_signal(Y, C, a.iterations, rng)
364
+ signal_rows.append({"trait_set": name, "n_species": len(tips), "n_variables": Y.shape[1], "scale": how, **r})
365
+ report.append(f"Phylogenetic signal: Kmult = {r['Kmult']:.4f}, P = {r['P']:.4f}, Z = {r['Z']:.2f}")
366
+ if "morphospace" in a.analyses and Y.shape[1] < 2:
367
+ report.append("Phylomorphospace: fewer than two variables - not drawn")
368
+ elif "morphospace" in a.analyses:
369
+ nodes = internal_nodes(tree)
370
+ anc = ancestral_states(Y, tips, nodes)
371
+ mu = Y.mean(0)
372
+ U, sv, Vt = np.linalg.svd(Y - mu, full_matrices=False)
373
+ ev = sv ** 2 / (sv ** 2).sum()
374
+ pc_t, pc_n = (Y - mu) @ Vt.T, (anc - mu) @ Vt.T
375
+ np.savetxt(out / f"{name}_morphospace_tips.csv", pc_t[:, :min(5, pc_t.shape[1])], delimiter=",",
376
+ header=",".join(f"PC{i + 1}" for i in range(min(5, pc_t.shape[1]))), comments="")
377
+ plot_morphospace(pc_t, pc_n, tips, nodes, ev, out / f"{name}_phylomorphospace.png",
378
+ f"{name}: phylomorphospace ({len(tips)} species)")
379
+ report.append(f"Phylomorphospace: {name}_phylomorphospace.png (PC1 {100 * ev[0]:.1f}%, PC2 {100 * ev[1]:.1f}%)")
380
+ report.append("")
381
+
382
+ if "pgls" in a.analyses:
383
+ for f in a.pgls:
384
+ ys, pred = [x.strip() for x in f.split("~")]
385
+ S = sets.get(ys)
386
+ if S is None or "Y" not in S:
387
+ report.append(f"PGLS {f}: trait set {ys} not analysed - skipped"); continue
388
+ if pred == "logCS":
389
+ if S["size"] is None:
390
+ report.append(f"PGLS {f}: no size column in {ys} (--size_col) - skipped"); continue
391
+ xv = np.log(np.array([S["size"][S["species"].index(t.name)] for t in S["tips"]]))
392
+ else:
393
+ s2, cc = pred.split(":", 1); src = sets.get(s2)
394
+ if src is None or cc not in src["cols"]:
395
+ report.append(f"PGLS {f}: predictor column not found - skipped"); continue
396
+ xv = np.array([src["raw"][src["species"].index(t.name), src["cols"].index(cc)] for t in S["tips"]])
397
+ r = pgls(S["Y"], xv, S["C"], a.iterations, rng)
398
+ pgls_rows.append({"model": f, **r})
399
+ report.append(f"PGLS {f}: R2 = {r['Rsq']:.4f}, F = {r['F']:.3f}, P = {r['P']:.4f}")
400
+
401
+ for fn, rows in (("phylogenetic_signal.csv", signal_rows), ("pgls.csv", pgls_rows)):
402
+ if rows:
403
+ with open(out / fn, "w", newline="") as fh:
404
+ w = csv.DictWriter(fh, fieldnames=list(rows[0])); w.writeheader(); w.writerows(rows)
405
+ (out / "phylo_report.md").write_text("\n".join(report) + "\n")
406
+ print("\n".join(report))
407
+
408
+
409
+ if __name__ == "__main__":
410
+ main()