phylogenie 2.1.28__py3-none-any.whl → 2.1.30__py3-none-any.whl
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.
- phylogenie/io/fasta.py +2 -1
- phylogenie/io/newick.py +3 -2
- phylogenie/io/nexus.py +5 -3
- phylogenie/treesimulator/gillespie.py +17 -17
- {phylogenie-2.1.28.dist-info → phylogenie-2.1.30.dist-info}/METADATA +1 -1
- {phylogenie-2.1.28.dist-info → phylogenie-2.1.30.dist-info}/RECORD +9 -9
- {phylogenie-2.1.28.dist-info → phylogenie-2.1.30.dist-info}/LICENSE.txt +0 -0
- {phylogenie-2.1.28.dist-info → phylogenie-2.1.30.dist-info}/WHEEL +0 -0
- {phylogenie-2.1.28.dist-info → phylogenie-2.1.30.dist-info}/entry_points.txt +0 -0
phylogenie/io/fasta.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
from pathlib import Path
|
|
1
2
|
from typing import Callable
|
|
2
3
|
|
|
3
4
|
from phylogenie.msa import MSA, Sequence
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
def load_fasta(
|
|
7
|
-
fasta_file: str, extract_time_from_id: Callable[[str], float] | None = None
|
|
8
|
+
fasta_file: str | Path, extract_time_from_id: Callable[[str], float] | None = None
|
|
8
9
|
) -> MSA:
|
|
9
10
|
sequences: list[Sequence] = []
|
|
10
11
|
with open(fasta_file, "r") as f:
|
phylogenie/io/newick.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import re
|
|
2
|
+
from pathlib import Path
|
|
2
3
|
|
|
3
4
|
from phylogenie.tree import Tree
|
|
4
5
|
|
|
@@ -66,7 +67,7 @@ def parse_newick(newick: str, translations: dict[str, str] | None = None) -> Tre
|
|
|
66
67
|
i += 1
|
|
67
68
|
|
|
68
69
|
|
|
69
|
-
def load_newick(filepath: str) -> Tree | list[Tree]:
|
|
70
|
+
def load_newick(filepath: str | Path) -> Tree | list[Tree]:
|
|
70
71
|
with open(filepath, "r") as file:
|
|
71
72
|
trees = [parse_newick(newick) for newick in file]
|
|
72
73
|
return trees[0] if len(trees) == 1 else trees
|
|
@@ -95,7 +96,7 @@ def to_newick(tree: Tree) -> str:
|
|
|
95
96
|
return newick
|
|
96
97
|
|
|
97
98
|
|
|
98
|
-
def dump_newick(trees: Tree | list[Tree], filepath: str) -> None:
|
|
99
|
+
def dump_newick(trees: Tree | list[Tree], filepath: str | Path) -> None:
|
|
99
100
|
if isinstance(trees, Tree):
|
|
100
101
|
trees = [trees]
|
|
101
102
|
with open(filepath, "w") as file:
|
phylogenie/io/nexus.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import re
|
|
2
2
|
from collections.abc import Iterator
|
|
3
|
+
from pathlib import Path
|
|
3
4
|
|
|
4
5
|
from phylogenie.io.newick import parse_newick
|
|
5
6
|
from phylogenie.tree import Tree
|
|
@@ -8,12 +9,13 @@ from phylogenie.tree import Tree
|
|
|
8
9
|
def _parse_translate_block(lines: Iterator[str]) -> dict[str, str]:
|
|
9
10
|
translations: dict[str, str] = {}
|
|
10
11
|
for line in lines:
|
|
11
|
-
|
|
12
|
+
line = line.strip()
|
|
13
|
+
match = re.match(r"(\d+)\s+['\"]?([^'\",;]+)['\"]?", line)
|
|
12
14
|
if match is None:
|
|
13
15
|
if ";" in line:
|
|
14
16
|
return translations
|
|
15
17
|
else:
|
|
16
|
-
raise ValueError(f"Invalid translate line: {line
|
|
18
|
+
raise ValueError(f"Invalid translate line: {line}")
|
|
17
19
|
translations[match.group(1)] = match.group(2)
|
|
18
20
|
raise ValueError("Translate block not terminated with ';'")
|
|
19
21
|
|
|
@@ -35,7 +37,7 @@ def _parse_trees_block(lines: Iterator[str]) -> dict[str, Tree]:
|
|
|
35
37
|
return trees
|
|
36
38
|
|
|
37
39
|
|
|
38
|
-
def load_nexus(nexus_file: str) -> dict[str, Tree]:
|
|
40
|
+
def load_nexus(nexus_file: str | Path) -> dict[str, Tree]:
|
|
39
41
|
with open(nexus_file, "r") as f:
|
|
40
42
|
for line in f:
|
|
41
43
|
if line.strip().upper() == "BEGIN TREES;":
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import os
|
|
2
1
|
import time
|
|
3
2
|
from collections.abc import Iterable, Sequence
|
|
3
|
+
from pathlib import Path
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
6
|
import joblib
|
|
@@ -106,7 +106,7 @@ def simulate_tree(
|
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
def generate_trees(
|
|
109
|
-
output_dir: str,
|
|
109
|
+
output_dir: str | Path,
|
|
110
110
|
n_trees: int,
|
|
111
111
|
events: Sequence[Event],
|
|
112
112
|
min_tips: int = 1,
|
|
@@ -119,7 +119,13 @@ def generate_trees(
|
|
|
119
119
|
n_jobs: int = -1,
|
|
120
120
|
timeout: float = np.inf,
|
|
121
121
|
) -> pd.DataFrame:
|
|
122
|
-
|
|
122
|
+
if isinstance(output_dir, str):
|
|
123
|
+
output_dir = Path(output_dir)
|
|
124
|
+
if output_dir.exists():
|
|
125
|
+
raise FileExistsError(f"Output directory {output_dir} already exists")
|
|
126
|
+
output_dir.mkdir(parents=True)
|
|
127
|
+
|
|
128
|
+
def _simulate_tree(i: int, seed: int) -> dict[str, Any]:
|
|
123
129
|
while True:
|
|
124
130
|
try:
|
|
125
131
|
tree, metadata = simulate_tree(
|
|
@@ -132,27 +138,21 @@ def generate_trees(
|
|
|
132
138
|
seed=seed,
|
|
133
139
|
timeout=timeout,
|
|
134
140
|
)
|
|
141
|
+
metadata["file_id"] = i
|
|
135
142
|
if node_features is not None:
|
|
136
143
|
set_features(tree, node_features)
|
|
137
|
-
|
|
144
|
+
dump_newick(tree, output_dir / f"{i}.nwk")
|
|
145
|
+
return metadata
|
|
138
146
|
except TimeoutError:
|
|
139
147
|
print("Simulation timed out, retrying with a different seed...")
|
|
140
148
|
seed += 1
|
|
141
149
|
|
|
142
|
-
if os.path.exists(output_dir):
|
|
143
|
-
raise FileExistsError(f"Output directory {output_dir} already exists")
|
|
144
|
-
os.makedirs(output_dir)
|
|
145
|
-
|
|
146
150
|
rng = default_rng(seed)
|
|
147
151
|
jobs = joblib.Parallel(n_jobs=n_jobs, return_as="generator_unordered")(
|
|
148
|
-
joblib.delayed(_simulate_tree)(seed=int(rng.integers(2**32)))
|
|
149
|
-
for
|
|
152
|
+
joblib.delayed(_simulate_tree)(i=i, seed=int(rng.integers(2**32)))
|
|
153
|
+
for i in range(n_trees)
|
|
150
154
|
)
|
|
151
155
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
):
|
|
156
|
-
df.append({"file_id": i} | metadata)
|
|
157
|
-
dump_newick(tree, os.path.join(output_dir, f"{i}.nwk"))
|
|
158
|
-
return pd.DataFrame(df)
|
|
156
|
+
return pd.DataFrame(
|
|
157
|
+
[md for md in tqdm(jobs, f"Generating trees in {output_dir}...", n_trees)]
|
|
158
|
+
)
|
|
@@ -8,9 +8,9 @@ phylogenie/generators/factories.py,sha256=qSz-s7ltQwUf7R6TPZ-5xFyOnnSHkKn0u5Iuke
|
|
|
8
8
|
phylogenie/generators/trees.py,sha256=zsmL3_YUUwtn-_NrGSvwZVSGIm9kpf8SPHxoQCIT_hE,10168
|
|
9
9
|
phylogenie/generators/typeguards.py,sha256=yj4VkhOaUXJ2OrY-6zhOeY9C4yKIQxjZtk2d-vIxttQ,828
|
|
10
10
|
phylogenie/io/__init__.py,sha256=gtRYtDdZSTlWCj3I4vmMJSAs93jdz5RySkCakD3sxlQ,214
|
|
11
|
-
phylogenie/io/fasta.py,sha256=
|
|
12
|
-
phylogenie/io/newick.py,sha256=
|
|
13
|
-
phylogenie/io/nexus.py,sha256=
|
|
11
|
+
phylogenie/io/fasta.py,sha256=CUFO06m7wClprarsMheZojM4Os2NQf3ALYUXSWzfNL0,869
|
|
12
|
+
phylogenie/io/newick.py,sha256=4j7m9B11erVJijye0GfpbWomk2ttlBXdyHNoBc_fvIg,3435
|
|
13
|
+
phylogenie/io/nexus.py,sha256=wxY8YN0glHUU_OJyR5cN7n7wvWyNrelLOW2FcET6Mxw,1600
|
|
14
14
|
phylogenie/main.py,sha256=vtvSpQxBNlYABoFQ25czl-l3fIr4QRo3svWVd-jcArw,1170
|
|
15
15
|
phylogenie/models.py,sha256=pCg9ob0RpLUHwM49x4knKxL4FNPr3-EU_6zMXsvxtAg,370
|
|
16
16
|
phylogenie/msa.py,sha256=JDGyZUsAq6-m-SQjoCDjAkAZIxfgyl_PDIhdYn5HOow,2064
|
|
@@ -27,13 +27,13 @@ phylogenie/treesimulator/events/contact_tracing.py,sha256=QqinLfQmBBi6qF3nFE_Qsi
|
|
|
27
27
|
phylogenie/treesimulator/events/core.py,sha256=bhgQgi5L-oaHsoWJmUOsTTzWxi0POYxVLoF-KrC8AGQ,8179
|
|
28
28
|
phylogenie/treesimulator/events/mutations.py,sha256=fGxxeXhiFrMAaS-s_vd42aVBZ6XQiRjpW9uJUATNk1E,3752
|
|
29
29
|
phylogenie/treesimulator/features.py,sha256=nNfv0kPudAZnrnufIVuFCR_VEJSP-6fZ2L-VG5_-Fqo,1366
|
|
30
|
-
phylogenie/treesimulator/gillespie.py,sha256=
|
|
30
|
+
phylogenie/treesimulator/gillespie.py,sha256=3xPeqkSitP71Qa2a8d8vMkdV4CCdLy1rRCdDsNctAug,5732
|
|
31
31
|
phylogenie/treesimulator/model.py,sha256=lhDwmBFQ8Qh8qVGZPgED0vehtPC3DE7_CgCV_8rPB-A,4641
|
|
32
32
|
phylogenie/typeguards.py,sha256=JtqmbEWJZBRHbWgCvcl6nrWm3VcBfzRbklbTBYHItn0,1325
|
|
33
33
|
phylogenie/typings.py,sha256=p694PBe_tk25A6N8vGGWxuqoDtt3nHFUsIYJrwR_76Y,494
|
|
34
34
|
phylogenie/utils.py,sha256=ehVk_2kvjW8Q_EyM2kxBPHYiK-KlPmZQx7JeVN6Fh-E,5419
|
|
35
|
-
phylogenie-2.1.
|
|
36
|
-
phylogenie-2.1.
|
|
37
|
-
phylogenie-2.1.
|
|
38
|
-
phylogenie-2.1.
|
|
39
|
-
phylogenie-2.1.
|
|
35
|
+
phylogenie-2.1.30.dist-info/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
|
|
36
|
+
phylogenie-2.1.30.dist-info/METADATA,sha256=XRaW1c5BiitXB68zfaDGGVF3sO3-ZGACutgsgDf8BCs,5477
|
|
37
|
+
phylogenie-2.1.30.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
38
|
+
phylogenie-2.1.30.dist-info/entry_points.txt,sha256=Rt6_usN0FkBX1ZfiqCirjMN9FKOgFLG8rydcQ8kugeE,51
|
|
39
|
+
phylogenie-2.1.30.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|