bella-companion 0.0.44__tar.gz → 0.0.46__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.

Potentially problematic release.


This version of bella-companion might be problematic. Click here for more details.

Files changed (124) hide show
  1. {bella_companion-0.0.44 → bella_companion-0.0.46}/PKG-INFO +3 -3
  2. bella_companion-0.0.46/bella_companion/__pycache__/__init__.cpython-310.pyc +0 -0
  3. bella_companion-0.0.46/bella_companion/__pycache__/cli.cpython-310.pyc +0 -0
  4. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/cli.py +9 -4
  5. bella_companion-0.0.46/bella_companion/eucovid/__pycache__/__init__.cpython-310.pyc +0 -0
  6. bella_companion-0.0.46/bella_companion/eucovid/__pycache__/run_beast.cpython-310.pyc +0 -0
  7. bella_companion-0.0.46/bella_companion/eucovid/run_beast.py +118 -0
  8. bella_companion-0.0.46/bella_companion/platyrrhine/__init__.py +5 -0
  9. bella_companion-0.0.46/bella_companion/platyrrhine/__pycache__/__init__.cpython-310.pyc +0 -0
  10. bella_companion-0.0.46/bella_companion/platyrrhine/__pycache__/results.cpython-310.pyc +0 -0
  11. bella_companion-0.0.46/bella_companion/platyrrhine/__pycache__/run_beast.cpython-310.pyc +0 -0
  12. bella_companion-0.0.46/bella_companion/platyrrhine/__pycache__/summarize.cpython-310.pyc +0 -0
  13. bella_companion-0.0.46/bella_companion/platyrrhine/__pycache__/summarize_logs.cpython-310.pyc +0 -0
  14. bella_companion-0.0.46/bella_companion/platyrrhine/results.py +191 -0
  15. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/platyrrhine/run_beast.py +12 -11
  16. bella_companion-0.0.44/bella_companion/platyrrhine/summarize_logs.py → bella_companion-0.0.46/bella_companion/platyrrhine/summarize.py +6 -6
  17. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/__init__.py +2 -2
  18. bella_companion-0.0.46/bella_companion/simulations/__pycache__/__init__.cpython-310.pyc +0 -0
  19. bella_companion-0.0.46/bella_companion/simulations/__pycache__/features.cpython-310.pyc +0 -0
  20. bella_companion-0.0.46/bella_companion/simulations/__pycache__/generate_data.cpython-310.pyc +0 -0
  21. bella_companion-0.0.46/bella_companion/simulations/__pycache__/generate_figures.cpython-310.pyc +0 -0
  22. bella_companion-0.0.46/bella_companion/simulations/__pycache__/metrics.cpython-310.pyc +0 -0
  23. bella_companion-0.0.46/bella_companion/simulations/__pycache__/run_beast.cpython-310.pyc +0 -0
  24. bella_companion-0.0.46/bella_companion/simulations/__pycache__/summarize.cpython-310.pyc +0 -0
  25. bella_companion-0.0.46/bella_companion/simulations/__pycache__/summarize_logs.cpython-310.pyc +0 -0
  26. bella_companion-0.0.46/bella_companion/simulations/figures/__pycache__/__init__.cpython-310.pyc +0 -0
  27. bella_companion-0.0.46/bella_companion/simulations/figures/__pycache__/epi_multitype.cpython-310.pyc +0 -0
  28. bella_companion-0.0.46/bella_companion/simulations/figures/__pycache__/epi_skyline.cpython-310.pyc +0 -0
  29. bella_companion-0.0.46/bella_companion/simulations/figures/__pycache__/fbd_2traits.cpython-310.pyc +0 -0
  30. bella_companion-0.0.46/bella_companion/simulations/figures/__pycache__/fbd_no_traits.cpython-310.pyc +0 -0
  31. bella_companion-0.0.46/bella_companion/simulations/figures/__pycache__/scenarios.cpython-310.pyc +0 -0
  32. bella_companion-0.0.46/bella_companion/simulations/figures/__pycache__/utils.cpython-310.pyc +0 -0
  33. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/figures/epi_multitype.py +3 -3
  34. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/figures/epi_skyline.py +1 -1
  35. bella_companion-0.0.46/bella_companion/simulations/figures/explain/__pycache__/__init__.cpython-310.pyc +0 -0
  36. bella_companion-0.0.46/bella_companion/simulations/figures/explain/__pycache__/pdp.cpython-310.pyc +0 -0
  37. bella_companion-0.0.46/bella_companion/simulations/figures/explain/__pycache__/shap.cpython-310.pyc +0 -0
  38. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/figures/fbd_2traits.py +3 -3
  39. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/figures/fbd_no_traits.py +1 -3
  40. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/generate_figures.py +0 -9
  41. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/metrics.py +1 -1
  42. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/run_beast.py +5 -1
  43. bella_companion-0.0.46/bella_companion/simulations/scenarios/__pycache__/__init__.cpython-310.pyc +0 -0
  44. bella_companion-0.0.46/bella_companion/simulations/scenarios/__pycache__/common.cpython-310.pyc +0 -0
  45. bella_companion-0.0.46/bella_companion/simulations/scenarios/__pycache__/epi_multitype.cpython-310.pyc +0 -0
  46. bella_companion-0.0.46/bella_companion/simulations/scenarios/__pycache__/epi_skyline.cpython-310.pyc +0 -0
  47. bella_companion-0.0.46/bella_companion/simulations/scenarios/__pycache__/fbd_2traits.cpython-310.pyc +0 -0
  48. bella_companion-0.0.46/bella_companion/simulations/scenarios/__pycache__/fbd_no_traits.cpython-310.pyc +0 -0
  49. bella_companion-0.0.46/bella_companion/simulations/scenarios/__pycache__/scenario.cpython-310.pyc +0 -0
  50. bella_companion-0.0.44/bella_companion/simulations/summarize_logs.py → bella_companion-0.0.46/bella_companion/simulations/summarize.py +2 -2
  51. bella_companion-0.0.46/bella_companion/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  52. bella_companion-0.0.46/bella_companion/utils/__pycache__/beast.cpython-310.pyc +0 -0
  53. bella_companion-0.0.46/bella_companion/utils/__pycache__/explain.cpython-310.pyc +0 -0
  54. bella_companion-0.0.46/bella_companion/utils/__pycache__/slurm.cpython-310.pyc +0 -0
  55. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion.egg-info/PKG-INFO +3 -3
  56. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion.egg-info/SOURCES.txt +41 -3
  57. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion.egg-info/requires.txt +1 -1
  58. {bella_companion-0.0.44 → bella_companion-0.0.46}/pyproject.toml +4 -3
  59. bella_companion-0.0.44/bella_companion/eucovid/run_beast.py +0 -111
  60. bella_companion-0.0.44/bella_companion/platyrrhine/__init__.py +0 -5
  61. bella_companion-0.0.44/bella_companion/platyrrhine/results.py +0 -69
  62. {bella_companion-0.0.44 → bella_companion-0.0.46}/README.md +0 -0
  63. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/BELLA.jar +0 -0
  64. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/__init__.py +0 -0
  65. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/__init__.py +0 -0
  66. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/beast_configs/GLM.xml +0 -0
  67. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/beast_configs/MLP.xml +0 -0
  68. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/beast_configs/Nonparametric.xml +0 -0
  69. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/case_data.tsv +0 -0
  70. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/change_dates.tsv +0 -0
  71. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/msa.fasta +0 -0
  72. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/osi.tsv +0 -0
  73. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/all/closedborders_7e_nt.tsv +0 -0
  74. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/all/dist_7e_ls.tsv +0 -0
  75. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/all/flight_7e_ls.tsv +0 -0
  76. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/all/flight_pop_x_7e_ls.tsv +0 -0
  77. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/all/osi_x_7e_ls.tsv +0 -0
  78. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/all/osi_y_7e_ls.tsv +0 -0
  79. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/all/pop_x_7e_ls.tsv +0 -0
  80. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/all/pop_y_7e_ls.tsv +0 -0
  81. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/all/sharedborders_7e_nt.tsv +0 -0
  82. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/changetimes_all_7e.tsv +0 -0
  83. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/changetimes_flights_4e.tsv +0 -0
  84. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/eucovid/data/predictors/flight_pop_x_4e_ls.tsv +0 -0
  85. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/platyrrhine/beast_config.xml +0 -0
  86. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/platyrrhine/data/change_times.csv +0 -0
  87. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/platyrrhine/data/traits.csv +0 -0
  88. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/platyrrhine/data/trees.nwk +0 -0
  89. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/epi-multitype/GLM.xml +0 -0
  90. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/epi-multitype/MLP.xml +0 -0
  91. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/epi-multitype/Nonparametric.xml +0 -0
  92. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/epi-skyline/GLM.xml +0 -0
  93. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/epi-skyline/MLP.xml +0 -0
  94. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/epi-skyline/Nonparametric.xml +0 -0
  95. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/fbd-2traits/GLM.xml +0 -0
  96. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/fbd-2traits/MLP.xml +0 -0
  97. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/fbd-2traits/Nonparametric.xml +0 -0
  98. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/fbd-no-traits/GLM.xml +0 -0
  99. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/fbd-no-traits/MLP.xml +0 -0
  100. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/beast_configs/fbd-no-traits/Nonparametric.xml +0 -0
  101. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/features.py +0 -0
  102. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/figures/__init__.py +0 -0
  103. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/figures/explain/__init__.py +0 -0
  104. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/figures/explain/pdp.py +0 -0
  105. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/figures/explain/shap.py +0 -0
  106. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/figures/scenarios.py +0 -0
  107. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/figures/utils.py +0 -0
  108. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/generate_data.py +0 -0
  109. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/scenarios/__init__.py +0 -0
  110. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/scenarios/common.py +0 -0
  111. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/scenarios/epi_multitype.py +0 -0
  112. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/scenarios/epi_skyline.py +0 -0
  113. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/scenarios/fbd_2traits.py +0 -0
  114. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/scenarios/fbd_no_traits.py +0 -0
  115. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/simulations/scenarios/scenario.py +0 -0
  116. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/utils/__init__.py +0 -0
  117. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/utils/beast.py +0 -0
  118. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/utils/explain.py +0 -0
  119. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/utils/slurm.py +0 -0
  120. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion/version.xml +0 -0
  121. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion.egg-info/dependency_links.txt +0 -0
  122. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion.egg-info/entry_points.txt +0 -0
  123. {bella_companion-0.0.44 → bella_companion-0.0.46}/bella_companion.egg-info/top_level.txt +0 -0
  124. {bella_companion-0.0.44 → bella_companion-0.0.46}/setup.cfg +0 -0
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bella-companion
3
- Version: 0.0.44
4
- Summary: Add your description here
3
+ Version: 0.0.46
4
+ Summary: Bayesian Evolutionary Layered Learning Architectures (BELLA) companion
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
7
7
  Requires-Dist: arviz>=0.22.0
8
8
  Requires-Dist: bella-lumiere>=0.0.14
9
9
  Requires-Dist: dotenv>=0.9.9
10
- Requires-Dist: phylogenie>=3.1.2
10
+ Requires-Dist: phylogenie>=3.1.4
11
11
  Requires-Dist: poetry>=2.2.1
12
12
  Requires-Dist: seaborn>=0.13.2
@@ -2,15 +2,16 @@ import argparse
2
2
  import os
3
3
  from pathlib import Path
4
4
 
5
+ import matplotlib.pyplot as plt
5
6
  from dotenv import load_dotenv
6
7
 
7
8
  from bella_companion.eucovid import run_beast as run_eucovid_beast
8
9
  from bella_companion.platyrrhine import plot_platyrrhine_results
9
10
  from bella_companion.platyrrhine import run_beast as run_platyrrhine
10
- from bella_companion.platyrrhine import summarize_logs as summarize_platyrrhine
11
+ from bella_companion.platyrrhine import summarize as summarize_platyrrhine
11
12
  from bella_companion.simulations import generate_data, generate_figures, print_metrics
12
13
  from bella_companion.simulations import run_beast as run_simulations
13
- from bella_companion.simulations import summarize_logs as summarize_simulations
14
+ from bella_companion.simulations import summarize as summarize_simulations
14
15
 
15
16
 
16
17
  def main():
@@ -21,12 +22,16 @@ def main():
21
22
  os.getenv("JAVA_OPTIONS", ""),
22
23
  f"-jar {Path(__file__).parent / 'BELLA.jar'}",
23
24
  f"-version_file {Path(__file__).parent / 'version.xml'}",
24
- "-seed 42",
25
25
  "-overwrite",
26
26
  "-statefile /tmp/state",
27
- "-DFout /dev/null",
28
27
  ]
29
28
  )
29
+ plt.rcParams["pdf.fonttype"] = 42
30
+ plt.rcParams["xtick.labelsize"] = 14
31
+ plt.rcParams["ytick.labelsize"] = 14
32
+ plt.rcParams["font.size"] = 14
33
+ plt.rcParams["figure.constrained_layout.use"] = True
34
+ plt.rcParams["lines.linewidth"] = 3
30
35
 
31
36
  parser = argparse.ArgumentParser(
32
37
  prog="bella",
@@ -0,0 +1,118 @@
1
+ import os
2
+ from glob import glob
3
+ from pathlib import Path
4
+
5
+ from bella_companion.utils import submit_job
6
+
7
+
8
+ def run_beast():
9
+ base_output_dir = Path(os.environ["BELLA_BEAST_OUTPUT_DIR"])
10
+ output_dir = base_output_dir / "eucovid"
11
+ os.makedirs(output_dir, exist_ok=True)
12
+
13
+ base_log_dir = Path(os.environ["BELLA_SBATCH_LOG_DIR"]) / "eucovid"
14
+
15
+ data_dir = Path(__file__).parent / "data"
16
+ beast_configs_dir = Path(__file__).parent / "beast_configs"
17
+ msa_file = data_dir / "msa.fasta"
18
+
19
+ predictors_dir = data_dir / "predictors"
20
+ all_predictor_files = ",".join(glob(str(predictors_dir / "all" / "*.tsv")))
21
+ all_predictors_data = " ".join(
22
+ [
23
+ f"-D msa_file={msa_file}",
24
+ f"-D changeTimesFile={predictors_dir / 'changetimes_all_7e.tsv'}",
25
+ f"-D predictorFiles={all_predictor_files}",
26
+ ]
27
+ )
28
+ flight_predictor_data = " ".join(
29
+ [
30
+ f"-D msa_file={msa_file}",
31
+ f"-D changeTimesFile={predictors_dir / 'changetimes_flights_4e.tsv'}",
32
+ f"-D predictorFiles={predictors_dir / 'flight_pop_x_4e_ls.tsv'}",
33
+ ]
34
+ )
35
+
36
+ for seed in range(1, 3):
37
+ run_beast_cmd = [os.environ["BELLA_RUN_BEAST_CMD"], f"-seed {42 + seed}"]
38
+
39
+ """
40
+ os.makedirs(output_dir / "Nonparametric", exist_ok=True)
41
+ submit_job(
42
+ " ".join(
43
+ [
44
+ *run_beast_cmd,
45
+ f"-D aligned_fasta={msa_file}",
46
+ f"-prefix {output_dir / 'Nonparametric'}{os.sep}{seed}-",
47
+ str(beast_configs_dir / "Nonparametric.xml"),
48
+ ]
49
+ ),
50
+ base_log_dir / "Nonparametric" / str(seed),
51
+ cpus=128,
52
+ mem_per_cpu=12000,
53
+ )
54
+ """
55
+
56
+ os.makedirs(output_dir / "all-predictors-GLM", exist_ok=True)
57
+ submit_job(
58
+ " ".join(
59
+ [
60
+ *run_beast_cmd,
61
+ all_predictors_data,
62
+ f"-prefix {output_dir / 'all-predictors-GLM'}{os.sep}{seed}-",
63
+ str(beast_configs_dir / "GLM.xml"),
64
+ ]
65
+ ),
66
+ base_log_dir / "Nonparametric" / str(seed),
67
+ cpus=128,
68
+ mem_per_cpu=12000,
69
+ )
70
+ """
71
+ os.makedirs(output_dir / "flights-GLM", exist_ok=True)
72
+ submit_job(
73
+ " ".join(
74
+ [
75
+ *run_beast_cmd,
76
+ flight_predictor_data,
77
+ f"-prefix {output_dir / 'flights-GLM'}{os.sep}{seed}-",
78
+ str(beast_configs_dir / "GLM.xml"),
79
+ ]
80
+ ),
81
+ base_log_dir / "Nonparametric" / str(seed),
82
+ cpus=128,
83
+ mem_per_cpu=12000,
84
+ )
85
+ """
86
+
87
+ os.makedirs(output_dir / "all-predictors-MLP", exist_ok=True)
88
+ submit_job(
89
+ " ".join(
90
+ [
91
+ *run_beast_cmd,
92
+ '-D layersRange="0,1,2",nodes="16 8"',
93
+ all_predictors_data,
94
+ f"-prefix {output_dir / 'all-predictors-MLP'}{os.sep}{seed}-",
95
+ str(beast_configs_dir / "MLP.xml"),
96
+ ]
97
+ ),
98
+ base_log_dir / "Nonparametric" / str(seed),
99
+ cpus=128,
100
+ mem_per_cpu=12000,
101
+ )
102
+ """
103
+ os.makedirs(output_dir / "flights-MLP", exist_ok=True)
104
+ submit_job(
105
+ " ".join(
106
+ [
107
+ *run_beast_cmd,
108
+ '-D layersRange="0,1,2",nodes="16 8"',
109
+ flight_predictor_data,
110
+ f"-prefix {output_dir / 'flights-MLP'}{os.sep}{seed}-",
111
+ str(beast_configs_dir / "MLP.xml"),
112
+ ]
113
+ ),
114
+ base_log_dir / "Nonparametric" / str(seed),
115
+ cpus=128,
116
+ mem_per_cpu=12000,
117
+ )
118
+ """
@@ -0,0 +1,5 @@
1
+ from bella_companion.platyrrhine.results import plot_platyrrhine_results
2
+ from bella_companion.platyrrhine.run_beast import run_beast
3
+ from bella_companion.platyrrhine.summarize import summarize
4
+
5
+ __all__ = ["plot_platyrrhine_results", "run_beast", "summarize"]
@@ -0,0 +1,191 @@
1
+ import os
2
+ from pathlib import Path
3
+
4
+ import matplotlib.pyplot as plt
5
+ import numpy as np
6
+ import polars as pl
7
+ from matplotlib.colors import LinearSegmentedColormap, ListedColormap
8
+ from numpy.typing import NDArray
9
+ from phylogenie import draw_tree, get_node_depths, load_newick, load_nexus
10
+
11
+ DATA_DIR = Path(__file__).parent / "data"
12
+ CHANGE_TIMES = (
13
+ pl.read_csv(DATA_DIR / "change_times.csv", has_header=False).to_series().to_list()
14
+ )
15
+
16
+
17
+ def _plot_marginal_rates(output_dir: Path, trees_file: str | Path):
18
+ trees = load_newick(trees_file)
19
+ all_node_depths = [get_node_depths(tree) for tree in trees]
20
+ max_time = max(max(node_depths.values()) for node_depths in all_node_depths)
21
+ time_bins = np.array(list(reversed([0.0, *CHANGE_TIMES, max_time])))
22
+ for tree in trees:
23
+ for node in tree:
24
+ node["diversificationRateSP"] = node["birthRateSP"] - node["deathRateSP"]
25
+
26
+ for i, rate in enumerate(["birthRateSP", "deathRateSP", "diversificationRateSP"]):
27
+ marginal_rates: list[list[float]] = [[] for _ in range(len(CHANGE_TIMES) + 1)]
28
+ for tree, node_depths in zip(trees, all_node_depths):
29
+ root_age = tree.height
30
+ for node in tree:
31
+ if node.parent is None:
32
+ marginal_rates[0].append(node[rate])
33
+ continue
34
+ parent_age = root_age - node_depths[node.parent] # pyright: ignore
35
+ node_age = root_age - node_depths[node]
36
+ t1 = np.where(time_bins >= parent_age)[0][-1]
37
+ t2 = np.where(time_bins > node_age)[0][-1]
38
+ for t in range(t1, t2 + 1):
39
+ marginal_rates[t].append(node[rate])
40
+
41
+ median = [float(np.median(rates)) for rates in marginal_rates]
42
+ lower = [float(np.percentile(rates, 2.5)) for rates in marginal_rates]
43
+ upper = [float(np.percentile(rates, 97.5)) for rates in marginal_rates]
44
+ plt.step( # pyright: ignore
45
+ time_bins, [median[0], *median], color=f"C{i}", label=type
46
+ )
47
+ plt.fill_between( # pyright: ignore
48
+ time_bins,
49
+ [lower[0], *lower],
50
+ [upper[0], *upper],
51
+ color=f"C{i}",
52
+ alpha=0.2,
53
+ step="pre",
54
+ )
55
+
56
+ plt.gca().invert_xaxis()
57
+ plt.xlabel("Time (mya)") # pyright: ignore
58
+ plt.ylabel( # pyright: ignore
59
+ r"$\lambda$"
60
+ if rate == "birthRateSP"
61
+ else r"$\mu$"
62
+ if rate == "deathRateSP"
63
+ else r"$d$"
64
+ )
65
+ plt.savefig(output_dir / f"marginal-{rate}.svg") # pyright: ignore
66
+ plt.close()
67
+
68
+
69
+ def _plot_tree(output_dir: Path, tree_file: str | Path):
70
+ sample_trees = load_nexus(tree_file)
71
+ trees = [sample_trees[f"STATE_{i * 100_000}"] for i in range(11, 101)]
72
+
73
+ for tree in trees:
74
+ for node in tree:
75
+ if node.parent is not None and not node.branch_length:
76
+ node.parent.remove_child(node)
77
+
78
+ avg_tree = trees[0].copy()
79
+ for node in avg_tree:
80
+ node.clear()
81
+ for avg_node, nodes in zip(avg_tree, zip(*trees)):
82
+ avg_node["birthRateSP"] = np.mean([n["birthRateSP"] for n in nodes])
83
+ avg_node["deathRateSP"] = np.mean([n["deathRateSP"] for n in nodes])
84
+ avg_node["diversificationRateSP"] = (
85
+ avg_node["birthRateSP"] - avg_node["deathRateSP"]
86
+ )
87
+ avg_node["type"] = int(np.median([int(n["type"]) for n in nodes]))
88
+
89
+ avg_tree.ladderize()
90
+ cmaps: dict[str, LinearSegmentedColormap] = {
91
+ "birthRateSP": plt.cm.Blues, # pyright: ignore
92
+ "deathRateSP": plt.cm.Oranges, # pyright: ignore
93
+ "diversificationRateSP": plt.cm.Greens, # pyright: ignore
94
+ "type": plt.cm.Purples, # pyright: ignore
95
+ }
96
+ for color_by, cm in cmaps.items():
97
+ ax = plt.gca()
98
+ if color_by == "type":
99
+ cmap = ListedColormap(cm(np.linspace(0.3, 1, 4))) # pyright: ignore
100
+ draw_tree(
101
+ avg_tree,
102
+ ax,
103
+ color_by=color_by,
104
+ legend_kwargs={"title": "Body mass", "loc": "upper left"},
105
+ colormap=cmap,
106
+ )
107
+ else:
108
+ cmap = LinearSegmentedColormap.from_list(
109
+ "cmap",
110
+ cm(np.linspace(0.2, 1, 256)), # pyright: ignore
111
+ )
112
+ draw_tree(
113
+ avg_tree,
114
+ ax,
115
+ color_by=color_by,
116
+ hist_axes_kwargs={
117
+ "loc": "upper left",
118
+ "bbox_to_anchor": (0.06, 0, 1, 1),
119
+ "bbox_transform": ax.transAxes,
120
+ },
121
+ colormap=cmap,
122
+ )
123
+ height = avg_tree.height
124
+ ticks = np.arange(height, 0, -10)
125
+ ax.set_xticks(ticks, [str(round(height - t)) for t in ticks]) # pyright: ignore
126
+ ax.set_xlabel("Time (mya)") # pyright: ignore
127
+ plt.savefig(output_dir / f"{color_by}-tree.svg") # pyright: ignore
128
+ plt.close()
129
+
130
+
131
+ def _plot_predictions(output_dir: Path, log_summary_file: str | Path):
132
+ log_summary = pl.read_csv(log_summary_file)
133
+
134
+ max_time = max(
135
+ max(get_node_depths(tree).values())
136
+ for tree in load_newick(DATA_DIR / "trees.nwk")
137
+ )
138
+ time_bins = list(reversed([0.0, *CHANGE_TIMES, max_time]))
139
+
140
+ gradient = np.linspace(0.4, 0.9, 4)
141
+ colors: dict[str, NDArray[np.floating]] = {
142
+ "birthRateSP": plt.cm.Blues(gradient), # pyright: ignore
143
+ "deathRateSP": plt.cm.Oranges(gradient), # pyright: ignore
144
+ "diversificationRateSP": plt.cm.Greens(gradient), # pyright: ignore
145
+ }
146
+ for rate in colors:
147
+ for type in [0, 1, 2, 3]:
148
+ if rate == "diversificationRateSP":
149
+ estimates = log_summary.select(
150
+ [
151
+ pl.col(f"birthRateSPi{i}_{type}_median")
152
+ - pl.col(f"deathRateSPi{i}_{type}_median")
153
+ for i in range(len(CHANGE_TIMES) + 1)
154
+ ]
155
+ ).to_numpy()
156
+ else:
157
+ estimates = log_summary.select(
158
+ [
159
+ pl.col(f"{rate}i{i}_{type}_median")
160
+ for i in range(len(CHANGE_TIMES) + 1)
161
+ ]
162
+ ).to_numpy()
163
+ median = np.median(estimates, axis=0)
164
+ color = colors[rate][type]
165
+ plt.step( # pyright: ignore
166
+ time_bins, [median[0], *median], color=color, label=type
167
+ )
168
+
169
+ plt.gca().invert_xaxis()
170
+ plt.legend(title="Body mass") # pyright: ignore
171
+ plt.xlabel("Time (mya)") # pyright: ignore
172
+ plt.ylabel( # pyright: ignore
173
+ r"$\lambda$"
174
+ if rate == "birthRateSP"
175
+ else r"$\mu$"
176
+ if rate == "deathRateSP"
177
+ else r"$d$"
178
+ )
179
+ if rate in ["birthRateSP", "deathRateSP"]:
180
+ plt.ylim(0, 0.4) # pyright: ignore
181
+ plt.savefig(output_dir / f"{rate}-predictions.svg") # pyright: ignore
182
+ plt.close()
183
+
184
+
185
+ def plot_platyrrhine_results():
186
+ summaries_dir = Path(os.environ["BELLA_SUMMARIES_DIR"]) / "platyrrhine"
187
+ output_dir = Path(os.environ["BELLA_FIGURES_DIR"]) / "platyrrhine"
188
+ os.makedirs(output_dir, exist_ok=True)
189
+ _plot_predictions(output_dir, summaries_dir / "MLP.csv")
190
+ _plot_tree(output_dir, summaries_dir / "sample-trees.nexus")
191
+ _plot_marginal_rates(output_dir, summaries_dir / "trees.nwk")
@@ -39,22 +39,23 @@ def run_beast():
39
39
  command = " ".join(
40
40
  [
41
41
  os.environ["BELLA_RUN_BEAST_CMD"],
42
+ "-seed 42",
42
43
  f'-D types="{",".join(types)}"',
43
- f'-D startTypePriorProbs="0.25 0.25 0.25 0.25"',
44
- f"-D birthRateUpper=5",
45
- f"-D deathRateUpper=5",
46
- f'-D samplingChangeTimes="2.58 5.333 23.03"',
47
- f"-D samplingRateUpper=5",
48
- f'-D samplingRateInit="2.5 2.5 2.5 2.5"',
49
- f"-D migrationRateUpper=5",
50
- f'-D migrationRateInit="2.5 0 0 2.5 2.5 0 0 2.5 2.5 0 0 2.5"',
51
- f'-D nodes="16 8"',
52
- f'-D layersRange="0,1,2"',
44
+ '-D startTypePriorProbs="0.25 0.25 0.25 0.25"',
45
+ "-D birthRateUpper=5",
46
+ "-D deathRateUpper=5",
47
+ '-D samplingChangeTimes="2.58 5.333 23.03"',
48
+ "-D samplingRateUpper=5",
49
+ '-D samplingRateInit="2.5 2.5 2.5 2.5"',
50
+ "-D migrationRateUpper=5",
51
+ '-D migrationRateInit="2.5 0 0 2.5 2.5 0 0 2.5 2.5 0 0 2.5"',
52
+ '-D nodes="16 8"',
53
+ '-D layersRange="0,1,2"',
53
54
  f"-D treeFile={tree_file}",
54
55
  f"-D treeIndex={i}",
55
56
  f"-D changeTimesFile={change_times_file}",
56
57
  f"-D traitsFile={traits_file}",
57
- f"-D traitValueCol=3",
58
+ "-D traitValueCol=3",
58
59
  f"-D processLength={process_length}",
59
60
  f'-D timePredictor="{time_predictor}"',
60
61
  f'-D log10BMPredictor="{log10BM_predictor}"',
@@ -5,13 +5,13 @@ from pathlib import Path
5
5
 
6
6
  import joblib
7
7
  import polars as pl
8
- from phylogenie import Tree, load_nexus
8
+ from phylogenie import Tree, dump_newick, load_nexus
9
9
  from tqdm import tqdm
10
10
 
11
11
  from bella_companion.utils import read_weights_dir, summarize_logs_dir
12
12
 
13
13
 
14
- def summarize_logs():
14
+ def summarize():
15
15
  data_dir = Path(__file__).parent / "data"
16
16
  change_times = pl.read_csv(data_dir / "change_times.csv", has_header=False)
17
17
  n_time_bins = len(change_times) + 1
@@ -28,14 +28,14 @@ def summarize_logs():
28
28
  )
29
29
  weights = read_weights_dir(logs_dir)
30
30
 
31
- summaries_dir = Path(os.environ["BELLA_LOG_SUMMARIES_DIR"], "platyrrhine")
31
+ summaries_dir = Path(os.environ["BELLA_SUMMARIES_DIR"], "platyrrhine")
32
32
  os.makedirs(summaries_dir, exist_ok=True)
33
33
  summaries.write_csv(summaries_dir / "MLP.csv")
34
34
  joblib.dump(weights, summaries_dir / "MLP.weights.pkl")
35
35
 
36
36
  trees: list[Tree] = []
37
37
  for tree_file in tqdm(glob(str(logs_dir / "*.trees")), "Summarizing trees"):
38
- trees.extend(list(load_nexus(tree_file).values())[:-10])
39
- joblib.dump(trees, summaries_dir / "trees.pkl")
38
+ trees.extend(list(load_nexus(tree_file).values())[-10:])
39
+ dump_newick(trees, summaries_dir / "trees.nwk")
40
40
 
41
- shutil.copy(logs_dir / "0.trees", summaries_dir / "sample-tree.nexus")
41
+ shutil.copy(logs_dir / "0.trees", summaries_dir / "sample-trees.nexus")
@@ -2,12 +2,12 @@ from bella_companion.simulations.generate_data import generate_data
2
2
  from bella_companion.simulations.generate_figures import generate_figures
3
3
  from bella_companion.simulations.metrics import print_metrics
4
4
  from bella_companion.simulations.run_beast import run_beast
5
- from bella_companion.simulations.summarize_logs import summarize_logs
5
+ from bella_companion.simulations.summarize import summarize
6
6
 
7
7
  __all__ = [
8
8
  "generate_data",
9
9
  "generate_figures",
10
10
  "print_metrics",
11
11
  "run_beast",
12
- "summarize_logs",
12
+ "summarize",
13
13
  ]
@@ -58,10 +58,10 @@ def plot_epi_multitype_results():
58
58
  output_dir = Path(os.environ["BELLA_FIGURES_DIR"]) / "epi-multitype"
59
59
  os.makedirs(output_dir, exist_ok=True)
60
60
 
61
- log_dir = Path(os.environ["BELLA_LOG_SUMMARIES_DIR"]) / "epi-multitype"
61
+ summaries_dir = Path(os.environ["BELLA_SUMMARIES_DIR"]) / "epi-multitype"
62
62
  model = "MLP-32_16"
63
- log_summary = pl.read_csv(log_dir / f"{model}.csv")
64
- weights = joblib.load(log_dir / f"{model}.weights.pkl")
63
+ log_summary = pl.read_csv(summaries_dir / f"{model}.csv")
64
+ weights = joblib.load(summaries_dir / f"{model}.weights.pkl")
65
65
  weights = [w["migrationRate"] for w in weights]
66
66
 
67
67
  _plot_predictions(log_summary, output_dir)
@@ -17,7 +17,7 @@ def plot_epi_skyline_results():
17
17
  base_output_dir = Path(os.environ["BELLA_FIGURES_DIR"]) / "epi-skyline"
18
18
 
19
19
  for i, reproduction_number in enumerate(REPRODUCTION_NUMBERS, start=1):
20
- summaries_dir = Path(os.environ["BELLA_LOG_SUMMARIES_DIR"]) / f"epi-skyline_{i}"
20
+ summaries_dir = Path(os.environ["BELLA_SUMMARIES_DIR"]) / f"epi-skyline_{i}"
21
21
  logs_summaries = {
22
22
  "Nonparametric": pl.read_csv(summaries_dir / "Nonparametric.csv"),
23
23
  "GLM": pl.read_csv(summaries_dir / "GLM.csv"),
@@ -58,10 +58,10 @@ def _plot_predictions(log_summary: pl.DataFrame, output_dir: Path):
58
58
  def plot_fbd_2traits_results():
59
59
  output_dir = Path(os.environ["BELLA_FIGURES_DIR"]) / "fbd-2traits"
60
60
 
61
- log_dir = Path(os.environ["BELLA_LOG_SUMMARIES_DIR"]) / "fbd-2traits"
61
+ summaries_dir = Path(os.environ["BELLA_SUMMARIES_DIR"]) / "fbd-2traits"
62
62
  model = "MLP-32_16"
63
- log_summary = pl.read_csv(log_dir / f"{model}.csv")
64
- weights = joblib.load(log_dir / f"{model}.weights.pkl")
63
+ log_summary = pl.read_csv(summaries_dir / f"{model}.csv")
64
+ weights = joblib.load(summaries_dir / f"{model}.weights.pkl")
65
65
 
66
66
  for rate in RATES:
67
67
  os.makedirs(output_dir / rate, exist_ok=True)
@@ -17,9 +17,7 @@ def plot_fbd_no_traits_results():
17
17
  base_output = Path(os.environ["BELLA_FIGURES_DIR"]) / "fbd-no-traits"
18
18
 
19
19
  for i, rates in enumerate(RATES, start=1):
20
- summaries_dir = (
21
- Path(os.environ["BELLA_LOG_SUMMARIES_DIR"]) / f"fbd-no-traits_{i}"
22
- )
20
+ summaries_dir = Path(os.environ["BELLA_SUMMARIES_DIR"]) / f"fbd-no-traits_{i}"
23
21
  logs_summaries = {
24
22
  "Nonparametric": pl.read_csv(summaries_dir / "Nonparametric.csv"),
25
23
  "GLM": pl.read_csv(summaries_dir / "GLM.csv"),
@@ -1,5 +1,3 @@
1
- import matplotlib.pyplot as plt
2
-
3
1
  from bella_companion.simulations.figures import (
4
2
  plot_epi_multitype_results,
5
3
  plot_epi_skyline_results,
@@ -10,13 +8,6 @@ from bella_companion.simulations.figures import (
10
8
 
11
9
 
12
10
  def generate_figures():
13
- plt.rcParams["pdf.fonttype"] = 42
14
- plt.rcParams["xtick.labelsize"] = 14
15
- plt.rcParams["ytick.labelsize"] = 14
16
- plt.rcParams["font.size"] = 14
17
- plt.rcParams["figure.constrained_layout.use"] = True
18
- plt.rcParams["lines.linewidth"] = 3
19
-
20
11
  plot_scenarios()
21
12
  plot_epi_skyline_results()
22
13
  plot_epi_multitype_results()
@@ -36,7 +36,7 @@ def _avg_ci_width(summary: pl.DataFrame, true_values: dict[str, float]) -> float
36
36
 
37
37
 
38
38
  def print_metrics():
39
- base_summaries_dir = Path(os.environ["BELLA_LOG_SUMMARIES_DIR"])
39
+ base_summaries_dir = Path(os.environ["BELLA_SUMMARIES_DIR"])
40
40
  metrics = {}
41
41
  for name, scenario in SCENARIOS.items():
42
42
  summaries_dir = base_summaries_dir / name
@@ -56,7 +56,11 @@ def run_beast():
56
56
  f"-D lastSampleTime={max(get_node_depths(tree).values())}"
57
57
  )
58
58
 
59
- base_command = [os.environ["BELLA_RUN_BEAST_CMD"], *beast_args]
59
+ base_command = [
60
+ os.environ["BELLA_RUN_BEAST_CMD"],
61
+ "-seed 42",
62
+ *beast_args,
63
+ ]
60
64
  if model in ["Nonparametric", "GLM"]:
61
65
  command = " ".join(
62
66
  [*base_command, str(inference_configs_dir / f"{model}.xml")]