phylogenie 3.1.7__py3-none-any.whl → 3.1.8__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/draw.py CHANGED
@@ -10,7 +10,12 @@ from matplotlib.axes import Axes
10
10
  from matplotlib.colors import Colormap
11
11
  from mpl_toolkits.axes_grid1.inset_locator import inset_axes # pyright: ignore
12
12
 
13
- from phylogenie.treesimulator import Tree, get_node_depth_levels, get_node_depths
13
+ from phylogenie.treesimulator import (
14
+ Tree,
15
+ get_node_ages,
16
+ get_node_depth_levels,
17
+ get_node_depths,
18
+ )
14
19
 
15
20
 
16
21
  @dataclass
@@ -54,13 +59,12 @@ def draw_tree(
54
59
  colors = {node: colors for node in tree}
55
60
 
56
61
  xs = (
57
- get_node_depth_levels(tree)
62
+ get_node_ages(tree)
63
+ if backward_time
64
+ else get_node_depth_levels(tree)
58
65
  if any(node.branch_length is None for node in tree.iter_descendants())
59
66
  else get_node_depths(tree)
60
67
  )
61
- if backward_time:
62
- max_x = max(xs.values())
63
- xs = {node: max_x - x for node, x in xs.items()}
64
68
 
65
69
  ys: dict[Tree, float] = {node: i for i, node in enumerate(tree.get_leaves())}
66
70
  for node in tree.postorder_traversal():
@@ -27,11 +27,14 @@ from phylogenie.treesimulator.utils import (
27
27
  compute_sackin_index,
28
28
  get_distance,
29
29
  get_mrca,
30
+ get_node_ages,
30
31
  get_node_depth_levels,
31
32
  get_node_depths,
32
33
  get_node_height_levels,
33
34
  get_node_heights,
34
35
  get_node_leaf_counts,
36
+ get_node_times,
37
+ get_path,
35
38
  )
36
39
 
37
40
  __all__ = [
@@ -65,9 +68,12 @@ __all__ = [
65
68
  "compute_sackin_index",
66
69
  "get_distance",
67
70
  "get_mrca",
71
+ "get_node_ages",
68
72
  "get_node_depth_levels",
69
73
  "get_node_depths",
70
74
  "get_node_height_levels",
71
75
  "get_node_heights",
72
76
  "get_node_leaf_counts",
77
+ "get_node_times",
78
+ "get_path",
73
79
  ]
@@ -5,11 +5,13 @@ from phylogenie.treesimulator.events.mutations import get_mutation_id
5
5
  from phylogenie.treesimulator.model import get_node_state
6
6
  from phylogenie.treesimulator.tree import Tree
7
7
  from phylogenie.treesimulator.utils import (
8
+ get_node_ages,
8
9
  get_node_depth_levels,
9
10
  get_node_depths,
10
11
  get_node_height_levels,
11
12
  get_node_heights,
12
13
  get_node_leaf_counts,
14
+ get_node_times,
13
15
  )
14
16
 
15
17
 
@@ -22,6 +24,7 @@ def _get_mutations(tree: Tree) -> dict[Tree, int]:
22
24
 
23
25
 
24
26
  class Feature(str, Enum):
27
+ AGE = "age"
25
28
  DEPTH = "depth"
26
29
  DEPTH_LEVEL = "depth_level"
27
30
  HEIGHT = "height"
@@ -29,9 +32,11 @@ class Feature(str, Enum):
29
32
  MUTATION = "mutation"
30
33
  N_LEAVES = "n_leaves"
31
34
  STATE = "state"
35
+ TIME = "time"
32
36
 
33
37
 
34
38
  FEATURES_EXTRACTORS = {
39
+ Feature.AGE: get_node_ages,
35
40
  Feature.DEPTH: get_node_depths,
36
41
  Feature.DEPTH_LEVEL: get_node_depth_levels,
37
42
  Feature.HEIGHT: get_node_heights,
@@ -39,6 +44,7 @@ FEATURES_EXTRACTORS = {
39
44
  Feature.MUTATION: _get_mutations,
40
45
  Feature.N_LEAVES: get_node_leaf_counts,
41
46
  Feature.STATE: _get_states,
47
+ Feature.TIME: get_node_times,
42
48
  }
43
49
 
44
50
 
@@ -153,6 +153,16 @@ class Tree(MetadataMixin):
153
153
  child.branch_length_or_raise() + child.height for child in self.children
154
154
  )
155
155
 
156
+ @property
157
+ def time(self) -> float:
158
+ return self.depth
159
+
160
+ @property
161
+ def age(self) -> float:
162
+ if self.parent is None:
163
+ return self.height
164
+ return self.parent.age - self.branch_length_or_raise()
165
+
156
166
  # -------------
157
167
  # Miscellaneous
158
168
  # -------------
@@ -51,6 +51,17 @@ def get_node_heights(tree: Tree) -> dict[Tree, float]:
51
51
  return heights
52
52
 
53
53
 
54
+ def get_node_times(tree: Tree) -> dict[Tree, float]:
55
+ return get_node_depths(tree)
56
+
57
+
58
+ def get_node_ages(tree: Tree) -> dict[Tree, float]:
59
+ ages: dict[Tree, float] = {tree: tree.height}
60
+ for node in tree.iter_descendants():
61
+ ages[node] = ages[node.parent] - node.branch_length # pyright: ignore
62
+ return ages
63
+
64
+
54
65
  def get_mrca(node1: Tree, node2: Tree) -> Tree:
55
66
  node1_ancestors = set(node1.iter_upward())
56
67
  for node2_ancestor in node2.iter_upward():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: phylogenie
3
- Version: 3.1.7
3
+ Version: 3.1.8
4
4
  Summary: Generate phylogenetic datasets with minimal setup effort
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -1,5 +1,5 @@
1
1
  phylogenie/__init__.py,sha256=redo-SdvWwQPlyqOfdSW0TkkZf-aP98kLRCUIg4pB8c,3304
2
- phylogenie/draw.py,sha256=djG0cG9mmNFZ7vf3jo8Ei3bNBJVqujp6gtZtwPxyfSY,23341
2
+ phylogenie/draw.py,sha256=J_ijON8O848f-r2VnOu8MbSR_vAcvO8zPq5u5Vq5J_U,23323
3
3
  phylogenie/main.py,sha256=ry3B3HiwibZG3_qB58T5UhWy5dp6neYUtSqzL9LrSkA,1698
4
4
  phylogenie/mixins.py,sha256=wMwqP6zkqME9eMyzx5FS6-p9X8yW09jIC8jge8pHlkk,907
5
5
  phylogenie/msa.py,sha256=JDGyZUsAq6-m-SQjoCDjAkAZIxfgyl_PDIhdYn5HOow,2064
@@ -19,12 +19,12 @@ phylogenie/skyline/__init__.py,sha256=7pF4CUb4ZCLzNYJNhOjpuTOLTRhlK7L6ugfccNqjIG
19
19
  phylogenie/skyline/matrix.py,sha256=v4SitY7VbXprqlqQckjWTzW5hwRmCyIF595R6IJMxWw,9268
20
20
  phylogenie/skyline/parameter.py,sha256=TVqkqirGXNN-VP8hnIJACPkOxUan6LkGa5o_JcPfwbY,4834
21
21
  phylogenie/skyline/vector.py,sha256=60jtp7PieiEaEH0Tp6zNjNKjyzpN_nT5uwBUXbgeATk,7261
22
- phylogenie/treesimulator/__init__.py,sha256=Qz__cFookXuEjq8AUp1A6XRON0qQ_xX-q2Q5ixP4XUg,1791
23
- phylogenie/treesimulator/features.py,sha256=XbuwGw8xjGs2lNhJvvUUvXVtheSTBaSN6qj39tWYEro,1391
22
+ phylogenie/treesimulator/__init__.py,sha256=D4VX2JLEcmuSVpANCRXyZvEfZ13LrFY5YElPxU1Wx-w,1903
23
+ phylogenie/treesimulator/features.py,sha256=x1Gp1IpQeW-gJ6etdnXPgeJQ1_qsKoefIuqjzwAINDg,1530
24
24
  phylogenie/treesimulator/gillespie.py,sha256=ey2hdpJOSpNW88duwK7wTAdYSTnSuTSZ_yhZv9MlNHo,5323
25
25
  phylogenie/treesimulator/model.py,sha256=L0RsL6H1ynFDPecULniSs4Cs8dvz87ovviQOXFy5Qt0,4580
26
- phylogenie/treesimulator/tree.py,sha256=DEdzCh4vABq2f095beh3tD3_aee7EyXPDSjcyHKgKLg,6064
27
- phylogenie/treesimulator/utils.py,sha256=OxZwVHxN004Jf-kYZ_GfJgIY0beo-0tYq80CuFGQt-M,3416
26
+ phylogenie/treesimulator/tree.py,sha256=1slBjrlggWiQiQgVg45Xuklhmq-n4H5obEAhPvWEi8c,6303
27
+ phylogenie/treesimulator/utils.py,sha256=-8_HG2FICsJ2eBPomtQSZUaHH1QE-r2s0UsGC3Zb5Yk,3744
28
28
  phylogenie/treesimulator/events/__init__.py,sha256=w2tJ0D2WB5AiCbr3CsKN6vdADueiAEMzd_ve0rpa4zg,939
29
29
  phylogenie/treesimulator/events/base.py,sha256=JQKYUZmhB2Q-WQOy2ULGKQiabsMz-JvwMVfDoa3ZKyo,1170
30
30
  phylogenie/treesimulator/events/contact_tracing.py,sha256=t64omKEO2d-DfN_dhDJlXp_Kg9egy2ZE346yWjV3ZrA,5148
@@ -33,9 +33,9 @@ phylogenie/treesimulator/events/mutations.py,sha256=8Nqa2fg7fwaVNe5XSkGDSwp9pIKQ
33
33
  phylogenie/treesimulator/io/__init__.py,sha256=rfP-zp8SP8baq5_4dPAr10WH0W6KfoMCxdTZDCSXtzE,185
34
34
  phylogenie/treesimulator/io/newick.py,sha256=8Pr_jixByPOaVch18w-rFt62HYy0U97YMu0H-QSwIy0,3449
35
35
  phylogenie/treesimulator/io/nexus.py,sha256=zqT9dzj413z_s0hqp3Cdq5NMO6lv-zuuaJlaqzaqaB8,1847
36
- phylogenie-3.1.7.dist-info/licenses/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
37
- phylogenie-3.1.7.dist-info/METADATA,sha256=qnvdSWDQUd2fJa7RHSByFdCKvDgYqaPP_2QeCD2F-eg,5194
38
- phylogenie-3.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
39
- phylogenie-3.1.7.dist-info/entry_points.txt,sha256=BBH8LoReHnNFnvq4sROEsVFegfkKJ6c_oHZ7bgK7Jl4,52
40
- phylogenie-3.1.7.dist-info/top_level.txt,sha256=1YGZJhKA9tN9qI0Hcj6Cn_sOoDpba0HQlNcgQTjMD-8,11
41
- phylogenie-3.1.7.dist-info/RECORD,,
36
+ phylogenie-3.1.8.dist-info/licenses/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
37
+ phylogenie-3.1.8.dist-info/METADATA,sha256=0lQMRPORgVWh0cp4OYt1RjCkYtCdy2P3ugiBmqB2oHQ,5194
38
+ phylogenie-3.1.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
39
+ phylogenie-3.1.8.dist-info/entry_points.txt,sha256=BBH8LoReHnNFnvq4sROEsVFegfkKJ6c_oHZ7bgK7Jl4,52
40
+ phylogenie-3.1.8.dist-info/top_level.txt,sha256=1YGZJhKA9tN9qI0Hcj6Cn_sOoDpba0HQlNcgQTjMD-8,11
41
+ phylogenie-3.1.8.dist-info/RECORD,,