phylogenie 2.1.17__tar.gz → 2.1.19__tar.gz
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-2.1.17 → phylogenie-2.1.19}/PKG-INFO +1 -1
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/plot.py +39 -7
- {phylogenie-2.1.17 → phylogenie-2.1.19}/pyproject.toml +1 -1
- {phylogenie-2.1.17 → phylogenie-2.1.19}/LICENSE.txt +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/README.md +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/__init__.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/generators/__init__.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/generators/alisim.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/generators/configs.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/generators/dataset.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/generators/factories.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/generators/trees.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/generators/typeguards.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/io.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/main.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/models.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/msa.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/py.typed +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/skyline/__init__.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/skyline/matrix.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/skyline/parameter.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/skyline/vector.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/tree.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/treesimulator/__init__.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/treesimulator/events/__init__.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/treesimulator/events/contact_tracing.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/treesimulator/events/core.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/treesimulator/events/mutations.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/treesimulator/features.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/treesimulator/gillespie.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/treesimulator/model.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/typeguards.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/typings.py +0 -0
- {phylogenie-2.1.17 → phylogenie-2.1.19}/phylogenie/utils.py +0 -0
|
@@ -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
|
-
|
|
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 =
|
|
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
|
|
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="
|
|
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
|
-
|
|
85
|
-
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|