phylogenie 2.1.17__py3-none-any.whl → 2.1.19__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
@@ -1,9 +1,11 @@
1
1
  from enum import Enum
2
+ from typing import Any
2
3
 
3
4
  import matplotlib.colors as mcolors
4
5
  import matplotlib.patches as mpatches
5
6
  import matplotlib.pyplot as plt
6
7
  from matplotlib.axes import Axes
8
+ from mpl_toolkits.axes_grid1.inset_locator import inset_axes # pyright: ignore
7
9
 
8
10
  from phylogenie.tree import Tree
9
11
  from phylogenie.utils import get_node_depth_levels, get_node_depths
@@ -22,7 +24,10 @@ def plot_tree(
22
24
  coloring: str | Coloring | None = None,
23
25
  cmap: str | None = None,
24
26
  show_legend: bool = True,
25
- ) -> Axes:
27
+ show_hist: bool = True,
28
+ hist_kwargs: dict[str, Any] | None = None,
29
+ hist_axes_kwargs: dict[str, Any] | None = None,
30
+ ) -> Axes | tuple[Axes, Axes]:
26
31
  if ax is None:
27
32
  ax = plt.gca()
28
33
 
@@ -34,7 +39,8 @@ def plot_tree(
34
39
  ys = {node: i for i, node in enumerate(tree.inorder_traversal())}
35
40
 
36
41
  if color_by is not None:
37
- features = set(node.get(color_by) for node in tree if color_by in node.features)
42
+ features = [node.get(color_by) for node in tree if color_by in node.features]
43
+
38
44
  if coloring is None and any(isinstance(f, float) for f in features):
39
45
  coloring = Coloring.CONTINUOUS
40
46
  elif coloring is None:
@@ -47,7 +53,7 @@ def plot_tree(
47
53
  )
48
54
  colormap = plt.get_cmap("tab20" if cmap is None else cmap)
49
55
  feature_colors = {
50
- f: mcolors.to_hex(colormap(i)) for i, f in enumerate(features)
56
+ f: mcolors.to_hex(colormap(i)) for i, f in enumerate(set(features))
51
57
  }
52
58
  colors = {
53
59
  node: (
@@ -61,11 +67,11 @@ def plot_tree(
61
67
  if show_legend:
62
68
  legend_handles = [
63
69
  mpatches.Patch(color=feature_colors[f], label=str(f))
64
- for f in features
70
+ for f in feature_colors
65
71
  ]
66
72
  if any(color_by not in node.features for node in tree):
67
73
  legend_handles.append(
68
- mpatches.Patch(color=default_color, label="None")
74
+ mpatches.Patch(color=default_color, label="NA")
69
75
  )
70
76
  ax.legend(handles=legend_handles, title=color_by) # pyright: ignore
71
77
 
@@ -81,8 +87,25 @@ def plot_tree(
81
87
  for node in tree
82
88
  }
83
89
 
84
- sm = plt.cm.ScalarMappable(cmap=colormap, norm=norm)
85
- ax.get_figure().colorbar(sm, ax=ax) # pyright: ignore
90
+ if show_hist:
91
+ default_hist_axes_kwargs = {"width": "25%", "height": "25%"}
92
+ if hist_axes_kwargs is not None:
93
+ default_hist_axes_kwargs.update(hist_axes_kwargs)
94
+ hist_ax = inset_axes(ax, **default_hist_axes_kwargs) # pyright: ignore
95
+
96
+ hist_kwargs = {} if hist_kwargs is None else hist_kwargs
97
+ _, bins, patches = hist_ax.hist( # pyright: ignore
98
+ features, **hist_kwargs
99
+ )
100
+
101
+ for patch, b0, b1 in zip( # pyright: ignore
102
+ patches, bins[:-1], bins[1:] # pyright: ignore
103
+ ):
104
+ midpoint = (b0 + b1) / 2 # pyright: ignore
105
+ patch.set_facecolor(colormap(norm(midpoint))) # pyright: ignore
106
+ else:
107
+ sm = plt.cm.ScalarMappable(cmap=colormap, norm=norm)
108
+ ax.get_figure().colorbar(sm, ax=ax) # pyright: ignore
86
109
 
87
110
  else:
88
111
  raise ValueError(
@@ -100,5 +123,14 @@ def plot_tree(
100
123
  ax.vlines(x=x0, ymin=y0, ymax=y1, color=colors[node]) # pyright: ignore
101
124
  ax.hlines(y=y1, xmin=x0, xmax=x1, color=colors[node]) # pyright: ignore
102
125
 
126
+ for node in tree:
127
+ x1, y1 = xs[node], ys[node]
128
+ if node.parent is None:
129
+ ax.hlines(y=y1, xmin=0, xmax=x1, color=colors[node]) # pyright: ignore
130
+ continue
131
+ x0, y0 = xs[node.parent], ys[node.parent]
132
+ ax.vlines(x=x0, ymin=y0, ymax=y1, color=colors[node]) # pyright: ignore
133
+ ax.hlines(y=y1, xmin=x0, xmax=x1, color=colors[node]) # pyright: ignore
134
+
103
135
  ax.set_yticks([]) # pyright: ignore
104
136
  return ax
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: phylogenie
3
- Version: 2.1.17
3
+ Version: 2.1.19
4
4
  Summary: Generate phylogenetic datasets with minimal setup effort
5
5
  Author: Gabriele Marino
6
6
  Author-email: gabmarino.8601@gmail.com
@@ -10,7 +10,7 @@ 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=I1QH7bZ09t7KtI4LleQlph9YZZeyCwu_Jr-YH2JKrW0,3618
13
+ phylogenie/plot.py,sha256=5xwPbZWO0jX_spEVPH7UUnxc7evqQbhSPKHWpXHNXro,5121
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
@@ -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=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,,
31
+ phylogenie-2.1.19.dist-info/LICENSE.txt,sha256=NUrDqElK-eD3I0WqC004CJsy6cs0JgsAoebDv_42-pw,1071
32
+ phylogenie-2.1.19.dist-info/METADATA,sha256=g2cXt1gj4UITtGZgm21eKyOdyKHZYULHDuIpU32Gi9o,5477
33
+ phylogenie-2.1.19.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
34
+ phylogenie-2.1.19.dist-info/entry_points.txt,sha256=Rt6_usN0FkBX1ZfiqCirjMN9FKOgFLG8rydcQ8kugeE,51
35
+ phylogenie-2.1.19.dist-info/RECORD,,