phylogenie 2.1.14__py3-none-any.whl → 2.1.16__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.

Potentially problematic release.


This version of phylogenie might be problematic. Click here for more details.

phylogenie/plot.py CHANGED
@@ -6,7 +6,7 @@ import matplotlib.pyplot as plt
6
6
  from matplotlib.axes import Axes
7
7
 
8
8
  from phylogenie.tree import Tree
9
- from phylogenie.utils import get_node_depths
9
+ from phylogenie.utils import get_node_depth_levels, get_node_depths
10
10
 
11
11
 
12
12
  class Coloring(str, Enum):
@@ -22,15 +22,14 @@ def plot_tree(
22
22
  coloring: str | Coloring | None = None,
23
23
  cmap: str | None = None,
24
24
  show_legend: bool = True,
25
- x_feature: str | None = None,
26
25
  ) -> Axes:
27
26
  if ax is None:
28
27
  ax = plt.gca()
29
28
 
30
29
  xs = (
31
- get_node_depths(tree)
32
- if x_feature is None
33
- else {node: node.get(x_feature) for node in tree}
30
+ get_node_depth_levels(tree)
31
+ if any(node.branch_length is None for node in tree)
32
+ else get_node_depths(tree)
34
33
  )
35
34
  ys = {node: i for i, node in enumerate(tree.inorder_traversal())}
36
35
 
phylogenie/tree.py CHANGED
@@ -1,4 +1,5 @@
1
- from collections.abc import Iterator
1
+ from collections import deque
2
+ from collections.abc import Callable, Iterator
2
3
  from typing import Any
3
4
 
4
5
 
@@ -55,6 +56,10 @@ class Tree:
55
56
  return 0
56
57
  return 1 + max(child.height_level for child in self.children)
57
58
 
59
+ @property
60
+ def n_leaves(self) -> int:
61
+ return len(self.get_leaves())
62
+
58
63
  def set(self, key: str, value: Any) -> None:
59
64
  self._features[key] = value
60
65
 
@@ -102,6 +107,13 @@ class Tree:
102
107
  yield from child.postorder_traversal()
103
108
  yield self
104
109
 
110
+ def breadth_first_traversal(self) -> Iterator["Tree"]:
111
+ queue: deque["Tree"] = deque([self])
112
+ while queue:
113
+ node = queue.popleft()
114
+ yield node
115
+ queue.extend(node.children)
116
+
105
117
  def get_node(self, name: str) -> "Tree":
106
118
  for node in self:
107
119
  if node.name == name:
@@ -114,10 +126,10 @@ class Tree:
114
126
  def get_leaves(self) -> tuple["Tree", ...]:
115
127
  return tuple(node for node in self if node.is_leaf())
116
128
 
117
- def ladderize(self, feature: str) -> None:
118
- self._children.sort(key=lambda x: x.get(feature))
129
+ def ladderize(self, criterion: Callable[["Tree"], Any]) -> None:
130
+ self._children.sort(key=criterion)
119
131
  for child in self.children:
120
- child.ladderize(feature)
132
+ child.ladderize(criterion)
121
133
 
122
134
  def copy(self):
123
135
  new_tree = Tree(self.name, self.branch_length)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: phylogenie
3
- Version: 2.1.14
3
+ Version: 2.1.16
4
4
  Summary: Generate phylogenetic datasets with minimal setup effort
5
5
  Author: Gabriele Marino
6
6
  Author-email: gabmarino.8601@gmail.com
@@ -10,13 +10,13 @@ phylogenie/io.py,sha256=nwy8DOknt0HqF9qMeFZHrCmSXpM5AGrU5oajwTtD6vY,3973
10
10
  phylogenie/main.py,sha256=vtvSpQxBNlYABoFQ25czl-l3fIr4QRo3svWVd-jcArw,1170
11
11
  phylogenie/models.py,sha256=pCg9ob0RpLUHwM49x4knKxL4FNPr3-EU_6zMXsvxtAg,370
12
12
  phylogenie/msa.py,sha256=JDGyZUsAq6-m-SQjoCDjAkAZIxfgyl_PDIhdYn5HOow,2064
13
- phylogenie/plot.py,sha256=5InWceLwjZV2qVYv2jaTJPs_0gfAEaKYGQt_jnLpaz0,3615
13
+ phylogenie/plot.py,sha256=I1QH7bZ09t7KtI4LleQlph9YZZeyCwu_Jr-YH2JKrW0,3618
14
14
  phylogenie/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  phylogenie/skyline/__init__.py,sha256=7pF4CUb4ZCLzNYJNhOjpuTOLTRhlK7L6ugfccNqjIGo,620
16
16
  phylogenie/skyline/matrix.py,sha256=Gl8OgKjtieG0NwPYiPimKI36gefV8fm_OeorjdXxPTs,9146
17
17
  phylogenie/skyline/parameter.py,sha256=EM9qlPt0JhMBy3TbztM0dj24BaGNEy8KWKdTObDKhbI,4644
18
18
  phylogenie/skyline/vector.py,sha256=bJP7_FNX_Klt6wXqsyfj0KX3VNj6-dIhzCKSJuQcOV0,7115
19
- phylogenie/tree.py,sha256=PjyfsjYWadvIQSOxyIO0oaRVN2pecXEnUR-k1mM4Vic,4159
19
+ phylogenie/tree.py,sha256=MTMm_MyJt-ExJwJXu-WUCZPZ3U_YvF4XLNqRb50cgPI,4516
20
20
  phylogenie/treesimulator/__init__.py,sha256=yqS2vtYMhdWSXc9RAnX1dd4zAqSQweMLyVKTnJLfGTU,1106
21
21
  phylogenie/treesimulator/events/__init__.py,sha256=6zSgZ0MEUMvTK4yPlSolJnRWzCARLS-jYreTzh45mQo,1033
22
22
  phylogenie/treesimulator/events/contact_tracing.py,sha256=_nJ85yhgGkeruQgMHvGpDYoyhheBf8M4LgZWiWdi5dY,4801
@@ -28,8 +28,8 @@ phylogenie/treesimulator/model.py,sha256=Nyg6R8XmMwZMSw1-dII81sU9uU7tDe-NMs8v1qK
28
28
  phylogenie/typeguards.py,sha256=JtqmbEWJZBRHbWgCvcl6nrWm3VcBfzRbklbTBYHItn0,1325
29
29
  phylogenie/typings.py,sha256=GknvAFXyiaWeeYJ8Lk5d6E2VHT-xW6ONEojYbtJYiB8,476
30
30
  phylogenie/utils.py,sha256=l7kJ0mkdhplz_hTUseBxaGpEKngsWUOSiCMyLMIWYZQ,1936
31
- phylogenie-2.1.14.dist-info/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
32
- phylogenie-2.1.14.dist-info/METADATA,sha256=elXtIXUWfGalXgdhTgretrdYVQwOWwiSfHUiZicf5WQ,5477
33
- phylogenie-2.1.14.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
34
- phylogenie-2.1.14.dist-info/entry_points.txt,sha256=Rt6_usN0FkBX1ZfiqCirjMN9FKOgFLG8rydcQ8kugeE,51
35
- phylogenie-2.1.14.dist-info/RECORD,,
31
+ phylogenie-2.1.16.dist-info/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
32
+ phylogenie-2.1.16.dist-info/METADATA,sha256=2Fyg0A7W9ooDxloKDdi6ZYg31fGMpRKYnDHwjgMjCGI,5477
33
+ phylogenie-2.1.16.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
34
+ phylogenie-2.1.16.dist-info/entry_points.txt,sha256=Rt6_usN0FkBX1ZfiqCirjMN9FKOgFLG8rydcQ8kugeE,51
35
+ phylogenie-2.1.16.dist-info/RECORD,,