phylogenie 2.0.10__tar.gz → 2.0.12__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 phylogenie might be problematic. Click here for more details.

Files changed (29) hide show
  1. {phylogenie-2.0.10 → phylogenie-2.0.12}/PKG-INFO +1 -1
  2. phylogenie-2.0.12/phylogenie/generators/configs.py +39 -0
  3. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/generators/dataset.py +11 -8
  4. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/generators/factories.py +3 -8
  5. phylogenie-2.0.12/phylogenie/generators/typeguards.py +25 -0
  6. {phylogenie-2.0.10 → phylogenie-2.0.12}/pyproject.toml +1 -1
  7. phylogenie-2.0.10/phylogenie/generators/configs.py +0 -46
  8. phylogenie-2.0.10/phylogenie/generators/typeguards.py +0 -28
  9. {phylogenie-2.0.10 → phylogenie-2.0.12}/LICENSE.txt +0 -0
  10. {phylogenie-2.0.10 → phylogenie-2.0.12}/README.md +0 -0
  11. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/__init__.py +0 -0
  12. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/generators/__init__.py +0 -0
  13. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/generators/alisim.py +0 -0
  14. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/generators/trees.py +0 -0
  15. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/io.py +0 -0
  16. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/main.py +0 -0
  17. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/msa.py +0 -0
  18. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/py.typed +0 -0
  19. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/skyline/__init__.py +0 -0
  20. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/skyline/matrix.py +0 -0
  21. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/skyline/parameter.py +0 -0
  22. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/skyline/vector.py +0 -0
  23. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/tree.py +0 -0
  24. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/treesimulator/__init__.py +0 -0
  25. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/treesimulator/events.py +0 -0
  26. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/treesimulator/gillespie.py +0 -0
  27. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/treesimulator/model.py +0 -0
  28. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/typeguards.py +0 -0
  29. {phylogenie-2.0.10 → phylogenie-2.0.12}/phylogenie/typings.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: phylogenie
3
- Version: 2.0.10
3
+ Version: 2.0.12
4
4
  Summary: Generate phylogenetic datasets with minimal setup effort
5
5
  Author: Gabriele Marino
6
6
  Author-email: gabmarino.8601@gmail.com
@@ -0,0 +1,39 @@
1
+ from pydantic import BaseModel, ConfigDict
2
+
3
+ import phylogenie.typings as pgt
4
+
5
+
6
+ class Distribution(BaseModel):
7
+ type: str
8
+ model_config = ConfigDict(extra="allow")
9
+
10
+
11
+ Integer = str | int
12
+ Scalar = str | pgt.Scalar
13
+ ManyScalars = str | pgt.Many[Scalar]
14
+ OneOrManyScalars = Scalar | pgt.Many[Scalar]
15
+ OneOrMany2DScalars = Scalar | pgt.Many2D[Scalar]
16
+
17
+
18
+ class StrictBaseModel(BaseModel):
19
+ model_config = ConfigDict(extra="forbid")
20
+
21
+
22
+ class SkylineParameterModel(StrictBaseModel):
23
+ value: ManyScalars
24
+ change_times: ManyScalars
25
+
26
+
27
+ class SkylineVectorModel(StrictBaseModel):
28
+ value: str | pgt.Many[OneOrManyScalars]
29
+ change_times: ManyScalars
30
+
31
+
32
+ class SkylineMatrixModel(StrictBaseModel):
33
+ value: str | pgt.Many[OneOrMany2DScalars]
34
+ change_times: ManyScalars
35
+
36
+
37
+ SkylineParameter = Scalar | SkylineParameterModel
38
+ SkylineVector = str | pgt.Scalar | pgt.Many[SkylineParameter] | SkylineVectorModel
39
+ SkylineMatrix = str | pgt.Scalar | pgt.Many[SkylineVector] | SkylineMatrixModel | None
@@ -41,21 +41,24 @@ class DatasetGenerator(ABC, cfg.StrictBaseModel):
41
41
  self._generate_one(filename=filename, rng=default_rng(seed), data=data)
42
42
 
43
43
  def _generate(self, rng: Generator, n_samples: int, output_dir: str) -> None:
44
+ if os.path.exists(output_dir):
45
+ print(f"Output directory {output_dir} already exists. Skipping.")
46
+ return
47
+
48
+ data_dir = (
49
+ output_dir
50
+ if self.context is None
51
+ else os.path.join(output_dir, DATA_DIRNAME)
52
+ )
53
+ os.makedirs(data_dir)
54
+
44
55
  data: list[dict[str, Any]] = [{} for _ in range(n_samples)]
45
56
  if self.context is not None:
46
- data_dir = os.path.join(output_dir, DATA_DIRNAME)
47
57
  for d, (k, v) in product(data, self.context.items()):
48
58
  args = v.model_extra if v.model_extra is not None else {}
49
59
  d[k] = np.array(getattr(rng, v.type)(**args)).tolist()
50
60
  df = pd.DataFrame([{"file_id": str(i), **d} for i, d in enumerate(data)])
51
61
  df.to_csv(os.path.join(output_dir, METADATA_FILENAME), index=False)
52
- else:
53
- data_dir = output_dir
54
-
55
- if os.path.exists(data_dir):
56
- print(f"Output directory {data_dir} already exists. Skipping.")
57
- return
58
- os.makedirs(data_dir)
59
62
 
60
63
  joblib.Parallel(n_jobs=self.n_jobs)(
61
64
  joblib.delayed(self.generate_one)(
@@ -80,8 +80,6 @@ def one_or_many_scalars(
80
80
  def skyline_parameter(
81
81
  x: cfg.SkylineParameter, data: dict[str, Any]
82
82
  ) -> SkylineParameterLike:
83
- if isinstance(x, SkylineParameter):
84
- return x
85
83
  if isinstance(x, cfg.Scalar):
86
84
  return scalar(x, data)
87
85
  return SkylineParameter(
@@ -93,8 +91,6 @@ def skyline_parameter(
93
91
  def skyline_vector(
94
92
  x: cfg.SkylineVector, data: dict[str, Any]
95
93
  ) -> SkylineVectorCoercible:
96
- if isinstance(x, SkylineVector):
97
- return x
98
94
  if isinstance(x, str):
99
95
  e = _eval_expression(x, data)
100
96
  if tg.is_one_or_many_scalars(e):
@@ -104,7 +100,7 @@ def skyline_vector(
104
100
  )
105
101
  if isinstance(x, pgt.Scalar):
106
102
  return x
107
- if ctg.is_list_of_skyline_parameter_configs(x):
103
+ if ctg.is_many_skyline_parameter_configs(x):
108
104
  return [skyline_parameter(p, data) for p in x]
109
105
 
110
106
  assert isinstance(x, cfg.SkylineVectorModel)
@@ -155,8 +151,7 @@ def skyline_matrix(
155
151
  ) -> SkylineMatrixCoercible | None:
156
152
  if x is None:
157
153
  return None
158
- if isinstance(x, SkylineMatrix):
159
- return x
154
+
160
155
  if isinstance(x, str):
161
156
  e = _eval_expression(x, data)
162
157
  if tg.is_one_or_many_2D_scalars(e):
@@ -166,7 +161,7 @@ def skyline_matrix(
166
161
  )
167
162
  if isinstance(x, pgt.Scalar):
168
163
  return x
169
- if ctg.is_list_of_skyline_vector_configs(x):
164
+ if ctg.is_many_skyline_vector_configs(x):
170
165
  return [skyline_vector(v, data) for v in x]
171
166
 
172
167
  assert isinstance(x, cfg.SkylineMatrixModel)
@@ -0,0 +1,25 @@
1
+ from typing import Any, TypeGuard
2
+
3
+ import phylogenie.generators.configs as cfg
4
+ import phylogenie.typeguards as tg
5
+ import phylogenie.typings as pgt
6
+
7
+
8
+ def is_many_scalar_configs(x: Any) -> TypeGuard[pgt.Many[cfg.Scalar]]:
9
+ return tg.is_many(x) and all(isinstance(v, cfg.Scalar) for v in x)
10
+
11
+
12
+ def is_many_skyline_parameter_configs(
13
+ x: Any,
14
+ ) -> TypeGuard[pgt.Many[cfg.SkylineParameter]]:
15
+ return tg.is_many(x) and all(isinstance(v, cfg.SkylineParameter) for v in x)
16
+
17
+
18
+ def is_skyline_vector_config(x: Any) -> TypeGuard[cfg.SkylineVector]:
19
+ return isinstance(
20
+ x, str | pgt.Scalar | cfg.SkylineVectorModel
21
+ ) or is_many_skyline_parameter_configs(x)
22
+
23
+
24
+ def is_many_skyline_vector_configs(x: Any) -> TypeGuard[pgt.Many[cfg.SkylineVector]]:
25
+ return tg.is_many(x) and all(is_skyline_vector_config(v) for v in x)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "phylogenie"
3
- version = "2.0.10"
3
+ version = "2.0.12"
4
4
  description = "Generate phylogenetic datasets with minimal setup effort"
5
5
  authors = ["Gabriele Marino <gabmarino.8601@gmail.com>"]
6
6
  readme = "README.md"
@@ -1,46 +0,0 @@
1
- from pydantic import BaseModel, ConfigDict
2
-
3
- import phylogenie.typings as pgt
4
- from phylogenie.skyline import SkylineMatrix as _SkylineMatrix
5
- from phylogenie.skyline import SkylineParameter as _SkylineParameter
6
- from phylogenie.skyline import SkylineVector as _SkylineVector
7
-
8
-
9
- class Distribution(BaseModel):
10
- type: str
11
- model_config = ConfigDict(extra="allow")
12
-
13
-
14
- Integer = str | int
15
- Scalar = str | pgt.Scalar
16
- ManyScalars = str | list[Scalar]
17
- OneOrManyScalars = Scalar | list[Scalar]
18
- OneOrMany2DScalars = Scalar | list[list[Scalar]]
19
-
20
-
21
- class StrictBaseModel(BaseModel):
22
- model_config = ConfigDict(extra="forbid")
23
-
24
-
25
- class SkylineParameterModel(StrictBaseModel):
26
- value: ManyScalars
27
- change_times: ManyScalars
28
-
29
-
30
- class SkylineVectorModel(StrictBaseModel):
31
- value: str | list[OneOrManyScalars]
32
- change_times: ManyScalars
33
-
34
-
35
- class SkylineMatrixModel(StrictBaseModel):
36
- value: str | list[OneOrMany2DScalars]
37
- change_times: ManyScalars
38
-
39
-
40
- SkylineParameter = Scalar | SkylineParameterModel | _SkylineParameter
41
- SkylineVector = (
42
- str | pgt.Scalar | list[SkylineParameter] | SkylineVectorModel | _SkylineVector
43
- )
44
- SkylineMatrix = (
45
- str | pgt.Scalar | list[SkylineVector] | SkylineMatrixModel | None | _SkylineMatrix
46
- )
@@ -1,28 +0,0 @@
1
- from typing import Any, TypeGuard
2
-
3
- import phylogenie.generators.configs as cfg
4
- import phylogenie.typings as pgt
5
-
6
-
7
- def is_list(x: Any) -> TypeGuard[list[Any]]:
8
- return isinstance(x, list)
9
-
10
-
11
- def is_list_of_scalar_configs(x: Any) -> TypeGuard[list[cfg.Scalar]]:
12
- return is_list(x) and all(isinstance(v, cfg.Scalar) for v in x)
13
-
14
-
15
- def is_list_of_skyline_parameter_configs(
16
- x: Any,
17
- ) -> TypeGuard[list[cfg.SkylineParameter]]:
18
- return is_list(x) and all(isinstance(v, cfg.SkylineParameter) for v in x)
19
-
20
-
21
- def is_skyline_vector_config(x: Any) -> TypeGuard[cfg.SkylineVector]:
22
- return isinstance(
23
- x, str | pgt.Scalar | cfg.SkylineVectorModel
24
- ) or is_list_of_skyline_parameter_configs(x)
25
-
26
-
27
- def is_list_of_skyline_vector_configs(x: Any) -> TypeGuard[list[cfg.SkylineVector]]:
28
- return is_list(x) and all(is_skyline_vector_config(v) for v in x)
File without changes
File without changes