phylogenie 2.1.15__py3-none-any.whl → 2.1.17__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/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,5 +1,5 @@
1
1
  from collections import deque
2
- from collections.abc import Iterator
2
+ from collections.abc import Callable, Iterator
3
3
  from typing import Any
4
4
 
5
5
 
@@ -26,7 +26,7 @@ class Tree:
26
26
  @property
27
27
  def depth(self) -> float:
28
28
  if self.parent is None:
29
- return 0.0
29
+ return 0 if self.branch_length is None else self.branch_length
30
30
  if self.branch_length is None:
31
31
  raise ValueError(f"Branch length of node {self.name} is not set.")
32
32
  return self.parent.depth + self.branch_length
@@ -56,6 +56,10 @@ class Tree:
56
56
  return 0
57
57
  return 1 + max(child.height_level for child in self.children)
58
58
 
59
+ @property
60
+ def n_leaves(self) -> int:
61
+ return len(self.get_leaves())
62
+
59
63
  def set(self, key: str, value: Any) -> None:
60
64
  self._features[key] = value
61
65
 
@@ -122,10 +126,10 @@ class Tree:
122
126
  def get_leaves(self) -> tuple["Tree", ...]:
123
127
  return tuple(node for node in self if node.is_leaf())
124
128
 
125
- def ladderize(self, feature: str) -> None:
126
- self._children.sort(key=lambda x: x.get(feature))
129
+ def ladderize(self, criterion: Callable[["Tree"], Any]) -> None:
130
+ self._children.sort(key=criterion)
127
131
  for child in self.children:
128
- child.ladderize(feature)
132
+ child.ladderize(criterion)
129
133
 
130
134
  def copy(self):
131
135
  new_tree = Tree(self.name, self.branch_length)
phylogenie/utils.py CHANGED
@@ -22,7 +22,7 @@ def get_node_depths(tree: Tree) -> dict[Tree, float]:
22
22
  depths: dict[Tree, float] = {}
23
23
  for node in tree:
24
24
  if node.parent is None:
25
- depths[node] = 0
25
+ depths[node] = 0 if node.branch_length is None else node.branch_length
26
26
  else:
27
27
  if node.branch_length is None:
28
28
  raise ValueError(f"Branch length of node {node.name} is not set.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: phylogenie
3
- Version: 2.1.15
3
+ Version: 2.1.17
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=EL2bn40AafxQfpA3NP7ohAVA5EoQ87d2JhtulPOyZqg,4413
19
+ phylogenie/tree.py,sha256=qaHMEcnqEtjd8Jlo2wF1vw0Gi6tcMlXngK_6IKEaQkw,4568
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
@@ -27,9 +27,9 @@ phylogenie/treesimulator/gillespie.py,sha256=LZHB2Ko147E78LoUCtN_BN7NYO1xhMYRy5P
27
27
  phylogenie/treesimulator/model.py,sha256=Nyg6R8XmMwZMSw1-dII81sU9uU7tDe-NMs8v1qKE4_M,5746
28
28
  phylogenie/typeguards.py,sha256=JtqmbEWJZBRHbWgCvcl6nrWm3VcBfzRbklbTBYHItn0,1325
29
29
  phylogenie/typings.py,sha256=GknvAFXyiaWeeYJ8Lk5d6E2VHT-xW6ONEojYbtJYiB8,476
30
- phylogenie/utils.py,sha256=l7kJ0mkdhplz_hTUseBxaGpEKngsWUOSiCMyLMIWYZQ,1936
31
- phylogenie-2.1.15.dist-info/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
32
- phylogenie-2.1.15.dist-info/METADATA,sha256=Yrjt2kSAxD3Wx87slr4iu59T7XCHbIhg5JORHsxTxZg,5477
33
- phylogenie-2.1.15.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
34
- phylogenie-2.1.15.dist-info/entry_points.txt,sha256=Rt6_usN0FkBX1ZfiqCirjMN9FKOgFLG8rydcQ8kugeE,51
35
- phylogenie-2.1.15.dist-info/RECORD,,
30
+ phylogenie/utils.py,sha256=faDicpAtjxM-QDwPKOv8AOxPe7skPUOGKmVWBZRzUbU,1990
31
+ phylogenie-2.1.17.dist-info/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
32
+ phylogenie-2.1.17.dist-info/METADATA,sha256=TUa2AtURiUDVcWfYzt_6BQYaH7N4Izgco0O5vKVOuH0,5477
33
+ phylogenie-2.1.17.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
34
+ phylogenie-2.1.17.dist-info/entry_points.txt,sha256=Rt6_usN0FkBX1ZfiqCirjMN9FKOgFLG8rydcQ8kugeE,51
35
+ phylogenie-2.1.17.dist-info/RECORD,,