phylogenie 1.0.0__tar.gz → 1.0.2__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 (46) hide show
  1. phylogenie-1.0.2/LICENSE.txt +22 -0
  2. phylogenie-1.0.2/PKG-INFO +120 -0
  3. phylogenie-1.0.2/README.md +100 -0
  4. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/backend/remaster/generate.py +5 -5
  5. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/backend/remaster/reactions.py +23 -23
  6. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/backend/treesimulator.py +6 -6
  7. phylogenie-1.0.2/phylogenie/core/configs.py +40 -0
  8. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/context/factories.py +5 -8
  9. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/dataset.py +6 -6
  10. phylogenie-1.0.2/phylogenie/core/factories.py +255 -0
  11. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/msas/alisim.py +2 -2
  12. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/msas/base.py +3 -3
  13. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/trees/remaster/configs.py +3 -3
  14. phylogenie-1.0.2/phylogenie/core/trees/remaster/factories.py +26 -0
  15. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/trees/remaster/generator.py +57 -47
  16. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/trees/treesimulator.py +18 -16
  17. phylogenie-1.0.2/phylogenie/core/typeguards.py +27 -0
  18. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/skyline/__init__.py +14 -4
  19. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/skyline/matrix.py +45 -55
  20. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/skyline/parameter.py +29 -20
  21. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/skyline/vector.py +42 -51
  22. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/typeguards.py +10 -8
  23. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/typings.py +8 -7
  24. {phylogenie-1.0.0 → phylogenie-1.0.2}/pyproject.toml +3 -3
  25. phylogenie-1.0.0/PKG-INFO +0 -31
  26. phylogenie-1.0.0/README.md +0 -11
  27. phylogenie-1.0.0/phylogenie/core/configs.py +0 -35
  28. phylogenie-1.0.0/phylogenie/core/factories.py +0 -178
  29. phylogenie-1.0.0/phylogenie/core/trees/remaster/factories.py +0 -30
  30. phylogenie-1.0.0/phylogenie/core/typeguards.py +0 -35
  31. phylogenie-1.0.0/phylogenie/core/typings.py +0 -10
  32. phylogenie-1.0.0/phylogenie/utils.py +0 -20
  33. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/__init__.py +0 -0
  34. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/backend/__init__.py +0 -0
  35. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/backend/remaster/__init__.py +0 -0
  36. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/configs.py +0 -0
  37. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/__init__.py +0 -0
  38. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/context/__init__.py +0 -0
  39. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/context/configs.py +0 -0
  40. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/context/distributions.py +0 -0
  41. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/msas/__init__.py +0 -0
  42. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/trees/__init__.py +0 -0
  43. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/trees/base.py +0 -0
  44. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/core/trees/remaster/__init__.py +0 -0
  45. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/main.py +0 -0
  46. {phylogenie-1.0.0 → phylogenie-1.0.2}/phylogenie/py.typed +0 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 GABRIELE MARINO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,120 @@
1
+ Metadata-Version: 2.1
2
+ Name: phylogenie
3
+ Version: 1.0.2
4
+ Summary: Generate phylogenetic datasets with minimal setup effort
5
+ Author: Gabriele Marino
6
+ Author-email: gabmarino.8601@gmail.com
7
+ Requires-Python: >=3.10,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Requires-Dist: joblib (>=1.4.2,<2.0.0)
13
+ Requires-Dist: pandas (>=2.2.2,<3.0.0)
14
+ Requires-Dist: pydantic (>=2.11.5,<3.0.0)
15
+ Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
16
+ Requires-Dist: tqdm (>=4.66.4,<5.0.0)
17
+ Requires-Dist: treesimulator (>=0.2.15,<0.3.0)
18
+ Description-Content-Type: text/markdown
19
+
20
+ <p align="center">
21
+ <img src="https://raw.githubusercontent.com/gabriele-marino/phylogenie/main/logo.png" style="width:100%; height:auto;"/>
22
+ </p>
23
+
24
+ ---
25
+
26
+ [![TreeSimulator](https://img.shields.io/badge/Powered%20by-TreeSimulator-green?style=flat-square)](https://github.com/evolbioinfo/treesimulator)
27
+ [![Remaster](https://img.shields.io/badge/Powered%20by-Remaster-blue?style=flat-square)](https://tgvaughan.github.io/remaster/)
28
+ [![AliSim](https://img.shields.io/badge/Powered%20by-AliSim-orange?style=flat-square)](https://iqtree.github.io/doc/AliSim)
29
+
30
+ Phylogenie is a [Python](https://www.python.org/) package designed to easily simulate phylogenetic datasets—such as trees and multiple sequence alignments (MSAs)—with minimal setup effort. Simply specify the distributions from which your parameters should be sampled, and Phylogenie will handle the rest!
31
+
32
+ ## ✨ Features
33
+
34
+ Phylogenie comes packed with useful features, including:
35
+
36
+ - **Simulate tree and multiple sequence alignment (MSA) datasets from parameter distributions** 🌳🧬
37
+ Define distributions over your parameters and sample a different combination of parameters for each dataset sample.
38
+
39
+ - **Automatic metadata management** 🗂️
40
+ Phylogenie stores each parameter combination sampled during dataset generation in a `.csv` file.
41
+
42
+ - **Generalizable configurations** 🔄
43
+ Easily apply the same configuration across multiple dataset splits (e.g., train, validation, test).
44
+
45
+ - **Multiprocessing support** ⚙️💻
46
+ Simply specify the number of cores to use, and Phylogenie handles multiprocessing automatically.
47
+
48
+ - **Pre-implemented parameterizations** 🎯
49
+ Include canonical, fossilized birth-death, epidemiological, birth-death with exposed-infectious (BDEI), contact-tracing (CT), and more.
50
+
51
+ - **Skyline parameter support** 🪜
52
+ Support for piece-wise constant parameters.
53
+
54
+ - **Arithmetic operations on parameters** 🧮
55
+ Perform flexible arithmetic operations between parameters directly within the config file.
56
+
57
+ - **Support for common phylogenetic simulation tools** 🛠️
58
+ Compatible backends include ReMASTER, TreeSimulator, and AliSim.
59
+
60
+ - **Modular and extendible architecture** 🧩
61
+ Easily add new simulation backends as needed.
62
+
63
+ ## 📦 Installation
64
+ Phylogenie requires [Python](https://www.python.org/) 3.10 to be installed on your system. There are several ways to install Python and managing different Python versions. One popular option is to use [pyenv](https://github.com/pyenv/pyenv).
65
+
66
+ Once you have Python set up, you can install Phylogenie directly from PyPI:
67
+
68
+ ```bash
69
+ pip install phylogenie
70
+ ```
71
+
72
+ Or install from source:
73
+ ```bash
74
+ git clone https://github.com/gabriele-marino/phylogenie.git
75
+ cd phylogenie
76
+ pip install .
77
+ ```
78
+
79
+ ## 🛠 Backend dependencies
80
+
81
+ Phylogenie works with the following simulation backends:
82
+
83
+ - **[TreeSimulator](https://github.com/evolbioinfo/treesimulator)**
84
+ A [Python](https://www.python.org/) package for simulating phylogenetic trees. It is automatically installed with Phylogenie, so you can use it right away.
85
+
86
+ - **[ReMASTER](https://tgvaughan.github.io/remaster/)**
87
+ A [BEAST2](https://www.beast2.org/) package designed for tree simulation. To use ReMASTER as a backend, you need to install it separately.
88
+
89
+ - **[AliSim](https://iqtree.github.io/doc/AliSim)**
90
+ A tool for simulating multiple sequence alignments (MSAs). It is distributed with [IQ-TREE](https://iqtree.github.io/) and also requires separate installation if you wish to use it as a backend.
91
+
92
+ ## 🚀 Quick Start
93
+
94
+ Once you have installed Phylogenie, check out the [examples](https://github.com/gabriele-marino/phylogenie/tree/main/examples) folder.
95
+ It includes a collection of thoroughly commented configuration files, organized as a step-by-step tutorial. These examples will help you understand how to use Phylogenie in practice and can be easily adapted to fit your own workflow.
96
+
97
+ For quick start, pick your favorite config file and run Phylogenie with:
98
+ ```bash
99
+ phylogenie examples/<config_file>.yaml
100
+ ```
101
+ This command will create the output dataset in the folder specified inside the configuration file, including data directories and metadata files for each dataset split defined in the config.
102
+
103
+ >❗ *Tip*: Can’t choose just one config file?
104
+ You can run them all at once by pointing Phylogenie to the folder! Just use: `phylogenie examples`. In this mode, Phylogenie will automatically find all `.yaml` files in the folder you specified and run for each of them!
105
+
106
+ ## 📖 Documentation
107
+
108
+ - The [examples](https://github.com/gabriele-marino/phylogenie/tree/main/examples) folder contains many ready-to-use, extensively commented configuration files that serve as a step-by-step tutorial to guide you through using Phylogenie. You can explore them to learn how it works or adapt them directly to your own workflows.
109
+ - A complete user guide and API reference are under development. In the meantime, feel free to [reach out](mailto:gabmarino.8601@email.com) if you have any questions about integrating Phylogenie into your workflows.
110
+
111
+ ## 📄 License
112
+
113
+ This project is licensed under [MIT License](https://raw.githubusercontent.com/gabriele-marino/phylogenie/main/LICENSE.txt).
114
+
115
+ ## 📫 Contact
116
+
117
+ For questions, bug reports, or feature requests, please, consider opening an [issue on GitHub](https://github.com/gabriele-marino/phylogenie/issues), or [contact me directly](mailto:gabmarino.8601@email.com).
118
+
119
+ If you need help with the configuration files, feel free to reach out — I am always very available and happy to assist!
120
+
@@ -0,0 +1,100 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/gabriele-marino/phylogenie/main/logo.png" style="width:100%; height:auto;"/>
3
+ </p>
4
+
5
+ ---
6
+
7
+ [![TreeSimulator](https://img.shields.io/badge/Powered%20by-TreeSimulator-green?style=flat-square)](https://github.com/evolbioinfo/treesimulator)
8
+ [![Remaster](https://img.shields.io/badge/Powered%20by-Remaster-blue?style=flat-square)](https://tgvaughan.github.io/remaster/)
9
+ [![AliSim](https://img.shields.io/badge/Powered%20by-AliSim-orange?style=flat-square)](https://iqtree.github.io/doc/AliSim)
10
+
11
+ Phylogenie is a [Python](https://www.python.org/) package designed to easily simulate phylogenetic datasets—such as trees and multiple sequence alignments (MSAs)—with minimal setup effort. Simply specify the distributions from which your parameters should be sampled, and Phylogenie will handle the rest!
12
+
13
+ ## ✨ Features
14
+
15
+ Phylogenie comes packed with useful features, including:
16
+
17
+ - **Simulate tree and multiple sequence alignment (MSA) datasets from parameter distributions** 🌳🧬
18
+ Define distributions over your parameters and sample a different combination of parameters for each dataset sample.
19
+
20
+ - **Automatic metadata management** 🗂️
21
+ Phylogenie stores each parameter combination sampled during dataset generation in a `.csv` file.
22
+
23
+ - **Generalizable configurations** 🔄
24
+ Easily apply the same configuration across multiple dataset splits (e.g., train, validation, test).
25
+
26
+ - **Multiprocessing support** ⚙️💻
27
+ Simply specify the number of cores to use, and Phylogenie handles multiprocessing automatically.
28
+
29
+ - **Pre-implemented parameterizations** 🎯
30
+ Include canonical, fossilized birth-death, epidemiological, birth-death with exposed-infectious (BDEI), contact-tracing (CT), and more.
31
+
32
+ - **Skyline parameter support** 🪜
33
+ Support for piece-wise constant parameters.
34
+
35
+ - **Arithmetic operations on parameters** 🧮
36
+ Perform flexible arithmetic operations between parameters directly within the config file.
37
+
38
+ - **Support for common phylogenetic simulation tools** 🛠️
39
+ Compatible backends include ReMASTER, TreeSimulator, and AliSim.
40
+
41
+ - **Modular and extendible architecture** 🧩
42
+ Easily add new simulation backends as needed.
43
+
44
+ ## 📦 Installation
45
+ Phylogenie requires [Python](https://www.python.org/) 3.10 to be installed on your system. There are several ways to install Python and managing different Python versions. One popular option is to use [pyenv](https://github.com/pyenv/pyenv).
46
+
47
+ Once you have Python set up, you can install Phylogenie directly from PyPI:
48
+
49
+ ```bash
50
+ pip install phylogenie
51
+ ```
52
+
53
+ Or install from source:
54
+ ```bash
55
+ git clone https://github.com/gabriele-marino/phylogenie.git
56
+ cd phylogenie
57
+ pip install .
58
+ ```
59
+
60
+ ## 🛠 Backend dependencies
61
+
62
+ Phylogenie works with the following simulation backends:
63
+
64
+ - **[TreeSimulator](https://github.com/evolbioinfo/treesimulator)**
65
+ A [Python](https://www.python.org/) package for simulating phylogenetic trees. It is automatically installed with Phylogenie, so you can use it right away.
66
+
67
+ - **[ReMASTER](https://tgvaughan.github.io/remaster/)**
68
+ A [BEAST2](https://www.beast2.org/) package designed for tree simulation. To use ReMASTER as a backend, you need to install it separately.
69
+
70
+ - **[AliSim](https://iqtree.github.io/doc/AliSim)**
71
+ A tool for simulating multiple sequence alignments (MSAs). It is distributed with [IQ-TREE](https://iqtree.github.io/) and also requires separate installation if you wish to use it as a backend.
72
+
73
+ ## 🚀 Quick Start
74
+
75
+ Once you have installed Phylogenie, check out the [examples](https://github.com/gabriele-marino/phylogenie/tree/main/examples) folder.
76
+ It includes a collection of thoroughly commented configuration files, organized as a step-by-step tutorial. These examples will help you understand how to use Phylogenie in practice and can be easily adapted to fit your own workflow.
77
+
78
+ For quick start, pick your favorite config file and run Phylogenie with:
79
+ ```bash
80
+ phylogenie examples/<config_file>.yaml
81
+ ```
82
+ This command will create the output dataset in the folder specified inside the configuration file, including data directories and metadata files for each dataset split defined in the config.
83
+
84
+ >❗ *Tip*: Can’t choose just one config file?
85
+ You can run them all at once by pointing Phylogenie to the folder! Just use: `phylogenie examples`. In this mode, Phylogenie will automatically find all `.yaml` files in the folder you specified and run for each of them!
86
+
87
+ ## 📖 Documentation
88
+
89
+ - The [examples](https://github.com/gabriele-marino/phylogenie/tree/main/examples) folder contains many ready-to-use, extensively commented configuration files that serve as a step-by-step tutorial to guide you through using Phylogenie. You can explore them to learn how it works or adapt them directly to your own workflows.
90
+ - A complete user guide and API reference are under development. In the meantime, feel free to [reach out](mailto:gabmarino.8601@email.com) if you have any questions about integrating Phylogenie into your workflows.
91
+
92
+ ## 📄 License
93
+
94
+ This project is licensed under [MIT License](https://raw.githubusercontent.com/gabriele-marino/phylogenie/main/LICENSE.txt).
95
+
96
+ ## 📫 Contact
97
+
98
+ For questions, bug reports, or feature requests, please, consider opening an [issue on GitHub](https://github.com/gabriele-marino/phylogenie/issues), or [contact me directly](mailto:gabmarino.8601@email.com).
99
+
100
+ If you need help with the configuration files, feel free to reach out — I am always very available and happy to assist!
@@ -11,7 +11,6 @@ from phylogenie.backend.remaster.reactions import (
11
11
  Reaction,
12
12
  )
13
13
  from phylogenie.skyline import skyline_parameter
14
- from phylogenie.utils import vectorify1D
15
14
 
16
15
  TREE_ID = "Tree"
17
16
 
@@ -75,12 +74,12 @@ def _generate_config_file(
75
74
  attrs = {
76
75
  "spec": "PunctualReaction",
77
76
  "value": punctual_reaction.value,
78
- "times": " ".join(map(str, vectorify1D(punctual_reaction.times))),
77
+ "times": " ".join(map(str, punctual_reaction.times)),
79
78
  }
80
79
  if punctual_reaction.p is not None:
81
- attrs["p"] = " ".join(map(str, vectorify1D(punctual_reaction.p)))
80
+ attrs["p"] = " ".join(map(str, punctual_reaction.p))
82
81
  if punctual_reaction.n is not None:
83
- attrs["n"] = " ".join(map(str, vectorify1D(punctual_reaction.n)))
82
+ attrs["n"] = " ".join(map(str, punctual_reaction.n))
84
83
  trajectory.append(Element("reaction", attrs))
85
84
 
86
85
  simulate.append(trajectory)
@@ -151,6 +150,7 @@ def generate_trees(
151
150
  output_xml_file: str | None = None,
152
151
  n_simulations: int = 1,
153
152
  seed: int | None = None,
153
+ beast_path: str = "beast",
154
154
  ) -> None:
155
155
  if isinstance(populations, str):
156
156
  populations = [populations]
@@ -175,7 +175,7 @@ def generate_trees(
175
175
  n_simulations=n_simulations,
176
176
  )
177
177
 
178
- cmd = ["beast"]
178
+ cmd = [beast_path]
179
179
  if seed is not None:
180
180
  cmd.extend(["-seed", str(seed)])
181
181
  cmd.append(xml_file)
@@ -2,9 +2,9 @@ from dataclasses import dataclass
2
2
 
3
3
  import phylogenie.typings as pgt
4
4
  from phylogenie.skyline import (
5
- SkylineMatrixLike,
5
+ SkylineMatrixCoercible,
6
6
  SkylineParameterLike,
7
- SkylineVectorLike,
7
+ SkylineVectorCoercible,
8
8
  skyline_matrix,
9
9
  skyline_vector,
10
10
  )
@@ -21,21 +21,21 @@ class Reaction:
21
21
 
22
22
  @dataclass
23
23
  class PunctualReaction:
24
- times: pgt.OneOrManyScalars
24
+ times: pgt.ManyScalars
25
25
  value: str
26
- p: pgt.OneOrManyScalars | None = None
27
- n: pgt.OneOrMany[int] | None = None
26
+ p: pgt.ManyScalars | None = None
27
+ n: pgt.Many[int] | None = None
28
28
 
29
29
 
30
30
  def get_canonical_reactions(
31
31
  populations: str | list[str] = DEFAULT_POPULATION,
32
32
  sample_population: str = SAMPLE_POPULATION,
33
- birth_rates: SkylineVectorLike = 0,
34
- death_rates: SkylineVectorLike = 0,
35
- sampling_rates: SkylineVectorLike = 0,
36
- removal_probabilities: SkylineVectorLike = 0,
37
- migration_rates: SkylineMatrixLike = 0,
38
- birth_rates_among_demes: SkylineMatrixLike = 0,
33
+ birth_rates: SkylineVectorCoercible = 0,
34
+ death_rates: SkylineVectorCoercible = 0,
35
+ sampling_rates: SkylineVectorCoercible = 0,
36
+ removal_probabilities: SkylineVectorCoercible = 0,
37
+ migration_rates: SkylineMatrixCoercible = 0,
38
+ birth_rates_among_demes: SkylineMatrixCoercible = 0,
39
39
  ) -> list[Reaction]:
40
40
  if isinstance(populations, str):
41
41
  populations = [populations]
@@ -84,12 +84,12 @@ def get_canonical_reactions(
84
84
  def get_epidemiological_reactions(
85
85
  populations: str | list[str] = DEFAULT_POPULATION,
86
86
  sample_population: str = SAMPLE_POPULATION,
87
- reproduction_numbers: SkylineVectorLike = 0,
88
- become_uninfectious_rates: SkylineVectorLike = 0,
89
- sampling_proportions: SkylineVectorLike = 0,
90
- removal_probabilities: SkylineVectorLike = 0,
91
- migration_rates: SkylineMatrixLike = 0,
92
- reproduction_numbers_among_demes: SkylineMatrixLike = 0,
87
+ reproduction_numbers: SkylineVectorCoercible = 0,
88
+ become_uninfectious_rates: SkylineVectorCoercible = 0,
89
+ sampling_proportions: SkylineVectorCoercible = 0,
90
+ removal_probabilities: SkylineVectorCoercible = 0,
91
+ migration_rates: SkylineMatrixCoercible = 0,
92
+ reproduction_numbers_among_demes: SkylineMatrixCoercible = 0,
93
93
  ) -> list[Reaction]:
94
94
  if isinstance(populations, str):
95
95
  populations = [populations]
@@ -125,12 +125,12 @@ def get_epidemiological_reactions(
125
125
  def get_FBD_reactions(
126
126
  populations: str | list[str] = DEFAULT_POPULATION,
127
127
  sample_population: str = SAMPLE_POPULATION,
128
- diversification: SkylineVectorLike = 0,
129
- turnover: SkylineVectorLike = 0,
130
- sampling_proportions: SkylineVectorLike = 0,
131
- removal_probabilities: SkylineVectorLike = 0,
132
- migration_rates: SkylineMatrixLike = 0,
133
- diversification_between_types: SkylineMatrixLike = 0,
128
+ diversification: SkylineVectorCoercible = 0,
129
+ turnover: SkylineVectorCoercible = 0,
130
+ sampling_proportions: SkylineVectorCoercible = 0,
131
+ removal_probabilities: SkylineVectorCoercible = 0,
132
+ migration_rates: SkylineMatrixCoercible = 0,
133
+ diversification_between_types: SkylineMatrixCoercible = 0,
134
134
  ):
135
135
  if isinstance(populations, str):
136
136
  populations = [populations]
@@ -6,9 +6,9 @@ from treesimulator.generator import generate
6
6
  from treesimulator.mtbd_models import CTModel, Model
7
7
 
8
8
  from phylogenie.skyline import (
9
- SkylineMatrixLike,
9
+ SkylineMatrixCoercible,
10
10
  SkylineParameterLike,
11
- SkylineVectorLike,
11
+ SkylineVectorCoercible,
12
12
  skyline_matrix,
13
13
  skyline_parameter,
14
14
  skyline_vector,
@@ -22,10 +22,10 @@ EXPOSED_POPULATION = "E"
22
22
  @dataclass
23
23
  class TreeParams:
24
24
  populations: str | list[str] = DEFAULT_POPULATION
25
- transition_rates: SkylineMatrixLike = 0
26
- transmission_rates: SkylineMatrixLike = 0
27
- removal_rates: SkylineVectorLike = 0
28
- sampling_proportions: SkylineVectorLike = 0
25
+ transition_rates: SkylineMatrixCoercible = 0
26
+ transmission_rates: SkylineMatrixCoercible = 0
27
+ removal_rates: SkylineVectorCoercible = 0
28
+ sampling_proportions: SkylineVectorCoercible = 0
29
29
 
30
30
 
31
31
  def generate_tree(
@@ -0,0 +1,40 @@
1
+ import phylogenie.typings as pgt
2
+ from phylogenie.configs import StrictBaseModel
3
+
4
+ IntConfig = str | int
5
+ ScalarConfig = str | pgt.Scalar
6
+ ManyIntsConfig = str | list[IntConfig]
7
+ ManyScalarsConfig = str | list[ScalarConfig]
8
+ OneOrManyScalarsConfig = ScalarConfig | list[ScalarConfig]
9
+ OneOrMany2DScalarsConfig = ScalarConfig | list[list[ScalarConfig]]
10
+
11
+
12
+ class SkylineParameterValueModel(StrictBaseModel):
13
+ value: ManyScalarsConfig
14
+ change_times: ManyScalarsConfig
15
+
16
+
17
+ SkylineParameterLikeConfig = ScalarConfig | SkylineParameterValueModel
18
+
19
+
20
+ class SkylineVectorValueModel(StrictBaseModel):
21
+ value: str | list[OneOrManyScalarsConfig]
22
+ change_times: ManyScalarsConfig
23
+
24
+
25
+ SkylineVectorCoercibleConfig = (
26
+ str | pgt.Scalar | list[SkylineParameterLikeConfig] | SkylineVectorValueModel
27
+ )
28
+ SkylineVectorLikeConfig = (
29
+ str | list[SkylineParameterLikeConfig] | SkylineVectorValueModel
30
+ )
31
+
32
+
33
+ class SkylineMatrixValueModel(StrictBaseModel):
34
+ value: str | list[OneOrMany2DScalarsConfig]
35
+ change_times: ManyScalarsConfig
36
+
37
+
38
+ SkylineMatrixCoercibleConfig = (
39
+ str | pgt.Scalar | list[SkylineVectorLikeConfig] | SkylineMatrixValueModel
40
+ )
@@ -3,18 +3,15 @@ from numpy.random import Generator
3
3
  import phylogenie.core.context.configs as cfg
4
4
  import phylogenie.typings as pgt
5
5
  from phylogenie.core.context import distributions
6
- from phylogenie.core.typings import Data
7
6
 
8
7
 
9
- def _sample_vector1D(
10
- x: distributions.Scalar, N: int, rng: Generator
11
- ) -> list[pgt.Scalar]:
8
+ def _sample_vector1D(x: distributions.Scalar, N: int, rng: Generator) -> pgt.Vector1D:
12
9
  return [x.sample(rng) for _ in range(N)]
13
10
 
14
11
 
15
12
  def _sample_vector2D(
16
13
  x: distributions.Scalar, N: int, zero_diagonal: bool, rng: Generator
17
- ) -> list[list[pgt.Scalar]]:
14
+ ) -> pgt.Vector2D:
18
15
  v = [_sample_vector1D(x, N, rng) for _ in range(N)]
19
16
  if zero_diagonal:
20
17
  for i in range(N):
@@ -24,12 +21,12 @@ def _sample_vector2D(
24
21
 
25
22
  def _sample_vector3D(
26
23
  x: distributions.Scalar, N: int, T: int, zero_diagonal: bool, rng: Generator
27
- ) -> list[list[list[pgt.Scalar]]]:
24
+ ) -> pgt.Vector3D:
28
25
  return [_sample_vector2D(x, N, zero_diagonal, rng) for _ in range(T)]
29
26
 
30
27
 
31
- def context_factory(x: cfg.ContextConfig, rng: Generator) -> Data:
32
- data: Data = {}
28
+ def context_factory(x: cfg.ContextConfig, rng: Generator) -> pgt.Data:
29
+ data: pgt.Data = {}
33
30
  for key, value in x.items():
34
31
  if isinstance(value, distributions.Distribution):
35
32
  data[key] = value.sample(rng)
@@ -7,9 +7,9 @@ import pandas as pd
7
7
  from numpy.random import Generator, default_rng
8
8
  from tqdm import tqdm
9
9
 
10
+ import phylogenie.typings as pgt
10
11
  from phylogenie.configs import StrictBaseModel
11
12
  from phylogenie.core.context import ContextConfig, context_factory
12
- from phylogenie.core.typings import Data
13
13
 
14
14
 
15
15
  class DataType(str, Enum):
@@ -19,18 +19,18 @@ class DataType(str, Enum):
19
19
 
20
20
  class DatasetGenerator(ABC, StrictBaseModel):
21
21
  output_dir: str = "phylogenie-out"
22
+ data_dir: str = "data"
23
+ metadata_filename: str = "metadata.csv"
22
24
  n_samples: int | dict[str, int] = 1
23
- context: ContextConfig | None = None
24
25
  n_jobs: int = -1
25
26
  seed: int | None = None
26
- data_dir: str = "data"
27
- metadata_filename: str = "metadata.csv"
27
+ context: ContextConfig | None = None
28
28
 
29
29
  @abstractmethod
30
- def _generate_one(self, filename: str, rng: Generator, data: Data) -> None: ...
30
+ def _generate_one(self, filename: str, rng: Generator, data: pgt.Data) -> None: ...
31
31
 
32
32
  def generate_one(
33
- self, filename: str, data: Data | None = None, seed: int | None = None
33
+ self, filename: str, data: pgt.Data | None = None, seed: int | None = None
34
34
  ) -> None:
35
35
  data = {} if data is None else data
36
36
  self._generate_one(filename=filename, rng=default_rng(seed), data=data)