phylogenie 3.1.9__tar.gz → 3.1.10__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.
Files changed (46) hide show
  1. {phylogenie-3.1.9/src/phylogenie.egg-info → phylogenie-3.1.10}/PKG-INFO +1 -1
  2. {phylogenie-3.1.9 → phylogenie-3.1.10}/pyproject.toml +1 -1
  3. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/draw.py +97 -10
  4. {phylogenie-3.1.9 → phylogenie-3.1.10/src/phylogenie.egg-info}/PKG-INFO +1 -1
  5. {phylogenie-3.1.9 → phylogenie-3.1.10}/LICENSE.txt +0 -0
  6. {phylogenie-3.1.9 → phylogenie-3.1.10}/README.md +0 -0
  7. {phylogenie-3.1.9 → phylogenie-3.1.10}/setup.cfg +0 -0
  8. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/__init__.py +0 -0
  9. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/generators/__init__.py +0 -0
  10. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/generators/alisim.py +0 -0
  11. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/generators/configs.py +0 -0
  12. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/generators/dataset.py +0 -0
  13. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/generators/factories.py +0 -0
  14. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/generators/trees.py +0 -0
  15. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/generators/typeguards.py +0 -0
  16. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/io/__init__.py +0 -0
  17. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/io/fasta.py +0 -0
  18. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/main.py +0 -0
  19. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/mixins.py +0 -0
  20. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/msa.py +0 -0
  21. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/py.typed +0 -0
  22. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/skyline/__init__.py +0 -0
  23. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/skyline/matrix.py +0 -0
  24. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/skyline/parameter.py +0 -0
  25. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/skyline/vector.py +0 -0
  26. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/__init__.py +0 -0
  27. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/events/__init__.py +0 -0
  28. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/events/base.py +0 -0
  29. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/events/contact_tracing.py +0 -0
  30. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/events/core.py +0 -0
  31. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/events/mutations.py +0 -0
  32. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/features.py +0 -0
  33. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/gillespie.py +0 -0
  34. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/io/__init__.py +0 -0
  35. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/io/newick.py +0 -0
  36. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/io/nexus.py +0 -0
  37. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/model.py +0 -0
  38. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/tree.py +0 -0
  39. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/treesimulator/utils.py +0 -0
  40. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/typeguards.py +0 -0
  41. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie/typings.py +0 -0
  42. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie.egg-info/SOURCES.txt +0 -0
  43. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie.egg-info/dependency_links.txt +0 -0
  44. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie.egg-info/entry_points.txt +0 -0
  45. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie.egg-info/requires.txt +0 -0
  46. {phylogenie-3.1.9 → phylogenie-3.1.10}/src/phylogenie.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: phylogenie
3
- Version: 3.1.9
3
+ Version: 3.1.10
4
4
  Summary: Generate phylogenetic datasets with minimal setup effort
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "phylogenie"
3
- version = "3.1.9"
3
+ version = "3.1.10"
4
4
  description = "Generate phylogenetic datasets with minimal setup effort"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -32,6 +32,8 @@ def draw_tree(
32
32
  ax: Axes | None = None,
33
33
  colors: Color | dict[Tree, Color] = "black",
34
34
  backward_time: bool = False,
35
+ branch_kwargs: dict[str, Any] | None = None,
36
+ sampled_ancestor_kwargs: dict[str, Any] | None = None,
35
37
  ) -> Axes:
36
38
  """
37
39
  Draw a phylogenetic tree with colored branches.
@@ -46,6 +48,10 @@ def draw_tree(
46
48
  A single color for all branches or a dictionary mapping each node to a color.
47
49
  backward_time : bool, optional
48
50
  If True, the x-axis is inverted to represent time going backward.
51
+ branch_kwargs : dict[str, Any] | None, optional
52
+ Additional keyword arguments to pass to the branch drawing functions.
53
+ sampled_ancestor_kwargs : dict[str, Any] | None, optional
54
+ Additional keyword arguments to highlight sampled ancestors.
49
55
 
50
56
  Returns
51
57
  -------
@@ -54,6 +60,12 @@ def draw_tree(
54
60
  """
55
61
  if ax is None:
56
62
  ax = plt.gca()
63
+ if branch_kwargs is None:
64
+ branch_kwargs = {}
65
+ if sampled_ancestor_kwargs is None:
66
+ sampled_ancestor_kwargs = {}
67
+ if "marker" not in sampled_ancestor_kwargs:
68
+ sampled_ancestor_kwargs["marker"] = "o"
57
69
 
58
70
  if not isinstance(colors, dict):
59
71
  colors = {node: colors for node in tree}
@@ -66,20 +78,33 @@ def draw_tree(
66
78
  else get_node_depths(tree)
67
79
  )
68
80
 
69
- ys: dict[Tree, float] = {node: i for i, node in enumerate(tree.get_leaves())}
81
+ leaves = tree.get_leaves()
82
+ ys: dict[Tree, float] = {
83
+ node: i
84
+ for i, node in enumerate(leaves)
85
+ if node.parent is None or node.branch_length != 0
86
+ }
70
87
  for node in tree.postorder_traversal():
71
88
  if node.is_internal():
72
- ys[node] = sum(ys[child] for child in node.children) / len(node.children)
89
+ children = [child for child in node.children if child.branch_length != 0]
90
+ ys[node] = sum(ys[child] for child in children) / len(children)
91
+ for leaf in leaves:
92
+ if leaf.parent is not None and leaf.branch_length == 0:
93
+ ys[leaf] = ys[leaf.parent]
73
94
 
74
95
  if tree.branch_length is not None:
75
96
  xmin = xs[tree] + tree.branch_length if backward_time else 0
76
- ax.hlines(y=ys[tree], xmin=xmin, xmax=xs[tree], color=colors[tree]) # pyright: ignore
97
+ ax.hlines( # pyright: ignore
98
+ y=ys[tree], xmin=xmin, xmax=xs[tree], color=colors[tree], **branch_kwargs
99
+ )
77
100
  for node in tree:
78
101
  x1, y1 = xs[node], ys[node]
102
+ if node.parent is not None and node.branch_length == 0:
103
+ ax.plot(x1, y1, color=colors[node], **sampled_ancestor_kwargs) # pyright: ignore
79
104
  for child in node.children:
80
105
  x2, y2 = xs[child], ys[child]
81
- ax.hlines(y=y2, xmin=x1, xmax=x2, color=colors[child]) # pyright: ignore
82
- ax.vlines(x=x1, ymin=y1, ymax=y2, color=colors[child]) # pyright: ignore
106
+ ax.hlines(y=y2, xmin=x1, xmax=x2, color=colors[child], **branch_kwargs) # pyright: ignore
107
+ ax.vlines(x=x1, ymin=y1, ymax=y2, color=colors[child], **branch_kwargs) # pyright: ignore
83
108
 
84
109
  if backward_time:
85
110
  ax.invert_xaxis()
@@ -117,6 +142,7 @@ def draw_dated_tree(
117
142
  calibration_nodes: tuple[CalibrationNode, CalibrationNode],
118
143
  ax: Axes | None = None,
119
144
  colors: Color | dict[Tree, Color] = "black",
145
+ branch_kwargs: dict[str, Any] | None = None,
120
146
  ) -> Axes:
121
147
  """
122
148
  Draw a phylogenetic tree with branches positioned according to calibrated dates.
@@ -131,6 +157,8 @@ def draw_dated_tree(
131
157
  The matplotlib Axes to draw on. If None, uses the current Axes.
132
158
  colors : Color | dict[Tree, Color], optional
133
159
  A single color for all branches or a dictionary mapping each node to a color.
160
+ branch_kwargs : dict[str, Any] | None, optional
161
+ Additional keyword arguments to pass to the branch drawing functions.
134
162
 
135
163
  Returns
136
164
  -------
@@ -139,6 +167,8 @@ def draw_dated_tree(
139
167
  """
140
168
  if ax is None:
141
169
  ax = plt.gca()
170
+ if branch_kwargs is None:
171
+ branch_kwargs = {}
142
172
 
143
173
  if not isinstance(colors, dict):
144
174
  colors = {node: colors for node in tree}
@@ -160,6 +190,7 @@ def draw_dated_tree(
160
190
  xmin=mdates.date2num(origin_date), # pyright: ignore
161
191
  xmax=mdates.date2num(xs[tree]), # pyright: ignore
162
192
  color=colors[tree],
193
+ **branch_kwargs,
163
194
  )
164
195
  for node in tree:
165
196
  x1, y1 = xs[node], ys[node]
@@ -170,8 +201,15 @@ def draw_dated_tree(
170
201
  xmin=mdates.date2num(x1), # pyright: ignore
171
202
  xmax=mdates.date2num(x2), # pyright: ignore
172
203
  color=colors[child],
204
+ **branch_kwargs,
205
+ )
206
+ ax.vlines( # pyright: ignore
207
+ x=mdates.date2num(x1), # pyright: ignore
208
+ ymin=y1,
209
+ ymax=y2,
210
+ color=colors[child],
211
+ **branch_kwargs,
173
212
  )
174
- ax.vlines(x=mdates.date2num(x1), ymin=y1, ymax=y2, color=colors[child]) # pyright: ignore
175
213
 
176
214
  ax.xaxis.set_major_locator(mdates.AutoDateLocator())
177
215
  ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m-%d"))
@@ -260,6 +298,8 @@ def draw_colored_tree_categorical(
260
298
  show_legend: bool = True,
261
299
  labels: dict[Any, str] | None = None,
262
300
  legend_kwargs: dict[str, Any] | None = None,
301
+ branch_kwargs: dict[str, Any] | None = None,
302
+ sampled_ancestor_kwargs: dict[str, Any] | None = None,
263
303
  ):
264
304
  """
265
305
  Draw a phylogenetic tree with branches colored based on categorical metadata.
@@ -284,6 +324,10 @@ def draw_colored_tree_categorical(
284
324
  A mapping from category values to labels for the legend.
285
325
  legend_kwargs : dict[str, Any] | None, optional
286
326
  Additional keyword arguments to pass to the legend.
327
+ branch_kwargs : dict[str, Any] | None, optional
328
+ Additional keyword arguments to pass to the branch drawing functions.
329
+ sampled_ancestor_kwargs : dict[str, Any] | None, optional
330
+ Additional keyword arguments to highlight sampled ancestors.
287
331
 
288
332
  Returns
289
333
  -------
@@ -300,7 +344,14 @@ def draw_colored_tree_categorical(
300
344
  labels=labels,
301
345
  legend_kwargs=legend_kwargs,
302
346
  )
303
- return draw_tree(tree=tree, ax=ax, colors=colors, backward_time=backward_time)
347
+ return draw_tree(
348
+ tree=tree,
349
+ ax=ax,
350
+ colors=colors,
351
+ backward_time=backward_time,
352
+ branch_kwargs=branch_kwargs,
353
+ sampled_ancestor_kwargs=sampled_ancestor_kwargs,
354
+ )
304
355
 
305
356
 
306
357
  def draw_colored_dated_tree_categorical(
@@ -313,6 +364,7 @@ def draw_colored_dated_tree_categorical(
313
364
  show_legend: bool = True,
314
365
  labels: dict[Any, str] | None = None,
315
366
  legend_kwargs: dict[str, Any] | None = None,
367
+ branch_kwargs: dict[str, Any] | None = None,
316
368
  ) -> Axes:
317
369
  """
318
370
  Draw a dated phylogenetic tree with branches colored based on categorical metadata.
@@ -337,6 +389,8 @@ def draw_colored_dated_tree_categorical(
337
389
  A mapping from category values to labels for the legend.
338
390
  legend_kwargs : dict[str, Any] | None, optional
339
391
  Additional keyword arguments to pass to the legend.
392
+ branch_kwargs : dict[str, Any] | None, optional
393
+ Additional keyword arguments to pass to the branch drawing functions.
340
394
 
341
395
  Returns
342
396
  -------
@@ -354,7 +408,11 @@ def draw_colored_dated_tree_categorical(
354
408
  legend_kwargs=legend_kwargs,
355
409
  )
356
410
  return draw_dated_tree(
357
- tree=tree, calibration_nodes=calibration_nodes, ax=ax, colors=colors
411
+ tree=tree,
412
+ calibration_nodes=calibration_nodes,
413
+ ax=ax,
414
+ colors=colors,
415
+ branch_kwargs=branch_kwargs,
358
416
  )
359
417
 
360
418
 
@@ -477,6 +535,8 @@ def draw_colored_tree_continuous(
477
535
  colormap: str | Colormap = "viridis",
478
536
  vmin: float | None = None,
479
537
  vmax: float | None = None,
538
+ branch_kwargs: dict[str, Any] | None = None,
539
+ sampled_ancestor_kwargs: dict[str, Any] | None = None,
480
540
  *,
481
541
  show_hist: Literal[False],
482
542
  hist_kwargs: dict[str, Any] | None = None,
@@ -492,6 +552,8 @@ def draw_colored_tree_continuous(
492
552
  colormap: str | Colormap = "viridis",
493
553
  vmin: float | None = None,
494
554
  vmax: float | None = None,
555
+ branch_kwargs: dict[str, Any] | None = None,
556
+ sampled_ancestor_kwargs: dict[str, Any] | None = None,
495
557
  show_hist: Literal[True] = True,
496
558
  hist_kwargs: dict[str, Any] | None = None,
497
559
  hist_axes_kwargs: dict[str, Any] | None = None,
@@ -505,6 +567,8 @@ def draw_colored_tree_continuous(
505
567
  colormap: str | Colormap = "viridis",
506
568
  vmin: float | None = None,
507
569
  vmax: float | None = None,
570
+ branch_kwargs: dict[str, Any] | None = None,
571
+ sampled_ancestor_kwargs: dict[str, Any] | None = None,
508
572
  show_hist: bool = True,
509
573
  hist_kwargs: dict[str, Any] | None = None,
510
574
  hist_axes_kwargs: dict[str, Any] | None = None,
@@ -530,6 +594,10 @@ def draw_colored_tree_continuous(
530
594
  The minimum value for normalization. If None, uses the minimum of the data.
531
595
  vmax : float | None, optional
532
596
  The maximum value for normalization. If None, uses the maximum of the data.
597
+ branch_kwargs : dict[str, Any] | None, optional
598
+ Additional keyword arguments to pass to the branch drawing functions.
599
+ sampled_ancestor_kwargs : dict[str, Any] | None, optional
600
+ Additional keyword arguments to highlight sampled ancestors.
533
601
  show_hist : bool, optional
534
602
  Whether to display a histogram of the continuous values.
535
603
  hist_kwargs : dict[str, Any] | None, optional
@@ -557,7 +625,12 @@ def draw_colored_tree_continuous(
557
625
  hist_axes_kwargs=hist_axes_kwargs,
558
626
  )
559
627
  return draw_tree(
560
- tree=tree, ax=ax, colors=colors, backward_time=backward_time
628
+ tree=tree,
629
+ ax=ax,
630
+ colors=colors,
631
+ backward_time=backward_time,
632
+ branch_kwargs=branch_kwargs,
633
+ sampled_ancestor_kwargs=sampled_ancestor_kwargs,
561
634
  ), hist_ax
562
635
 
563
636
  ax, colors = _init_colored_tree_continuous(
@@ -572,7 +645,14 @@ def draw_colored_tree_continuous(
572
645
  hist_kwargs=hist_kwargs,
573
646
  hist_axes_kwargs=hist_axes_kwargs,
574
647
  )
575
- return draw_tree(tree=tree, ax=ax, colors=colors, backward_time=backward_time)
648
+ return draw_tree(
649
+ tree=tree,
650
+ ax=ax,
651
+ colors=colors,
652
+ backward_time=backward_time,
653
+ branch_kwargs=branch_kwargs,
654
+ sampled_ancestor_kwargs=sampled_ancestor_kwargs,
655
+ )
576
656
 
577
657
 
578
658
  @overload
@@ -585,6 +665,7 @@ def draw_colored_dated_tree_continuous(
585
665
  colormap: str | Colormap = "viridis",
586
666
  vmin: float | None = None,
587
667
  vmax: float | None = None,
668
+ branch_kwargs: dict[str, Any] | None = None,
588
669
  *,
589
670
  show_hist: Literal[False],
590
671
  hist_kwargs: dict[str, Any] | None = None,
@@ -600,6 +681,7 @@ def draw_colored_dated_tree_continuous(
600
681
  colormap: str | Colormap = "viridis",
601
682
  vmin: float | None = None,
602
683
  vmax: float | None = None,
684
+ branch_kwargs: dict[str, Any] | None = None,
603
685
  show_hist: Literal[True] = True,
604
686
  hist_kwargs: dict[str, Any] | None = None,
605
687
  hist_axes_kwargs: dict[str, Any] | None = None,
@@ -613,6 +695,7 @@ def draw_colored_dated_tree_continuous(
613
695
  colormap: str | Colormap = "viridis",
614
696
  vmin: float | None = None,
615
697
  vmax: float | None = None,
698
+ branch_kwargs: dict[str, Any] | None = None,
616
699
  show_hist: bool = True,
617
700
  hist_kwargs: dict[str, Any] | None = None,
618
701
  hist_axes_kwargs: dict[str, Any] | None = None,
@@ -638,6 +721,8 @@ def draw_colored_dated_tree_continuous(
638
721
  The minimum value for normalization. If None, uses the minimum of the data.
639
722
  vmax : float | None, optional
640
723
  The maximum value for normalization. If None, uses the maximum of the data.
724
+ branch_kwargs : dict[str, Any] | None, optional
725
+ Additional keyword arguments to pass to the branch drawing functions.
641
726
  show_hist : bool, optional
642
727
  Whether to display a histogram of the continuous values.
643
728
  hist_kwargs : dict[str, Any] | None, optional
@@ -669,6 +754,7 @@ def draw_colored_dated_tree_continuous(
669
754
  calibration_nodes=calibration_nodes,
670
755
  ax=ax,
671
756
  colors=colors,
757
+ branch_kwargs=branch_kwargs,
672
758
  ), hist_ax
673
759
 
674
760
  ax, colors = _init_colored_tree_continuous(
@@ -688,4 +774,5 @@ def draw_colored_dated_tree_continuous(
688
774
  calibration_nodes=calibration_nodes,
689
775
  ax=ax,
690
776
  colors=colors,
777
+ branch_kwargs=branch_kwargs,
691
778
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: phylogenie
3
- Version: 3.1.9
3
+ Version: 3.1.10
4
4
  Summary: Generate phylogenetic datasets with minimal setup effort
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
File without changes
File without changes
File without changes