Skip to content

Commit 6052cdc

Browse files
authored
Merge pull request #673 from malariagen/GH656_avoid_anjl_import
Replicate anjl params to avoid global import causing delays
2 parents 5c95d71 + 4b9c438 commit 6052cdc

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

malariagen_data/anoph/distance.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numba # type: ignore
77
import numpy as np
88
from numpydoc_decorator import doc # type: ignore
9-
import anjl.params # type: ignore
109

1110
# Internal imports.
1211
from .snp_data import AnophelesSnpData
@@ -410,10 +409,10 @@ def plot_njt(
410409
metric: distance_params.distance_metric = distance_params.default_distance_metric,
411410
distance_sort: Optional[tree_params.distance_sort] = None,
412411
count_sort: Optional[tree_params.count_sort] = None,
413-
center_x: anjl.params.center_x = 0,
414-
center_y: anjl.params.center_y = 0,
415-
arc_start: anjl.params.arc_start = 0,
416-
arc_stop: anjl.params.arc_stop = 2 * math.pi,
412+
center_x: distance_params.center_x = 0,
413+
center_y: distance_params.center_y = 0,
414+
arc_start: distance_params.arc_start = 0,
415+
arc_stop: distance_params.arc_stop = 2 * math.pi,
417416
width: plotly_params.fig_width = 800,
418417
height: plotly_params.fig_height = 600,
419418
show: plotly_params.show = True,
@@ -426,8 +425,8 @@ def plot_njt(
426425
color_discrete_sequence: plotly_params.color_discrete_sequence = None,
427426
color_discrete_map: plotly_params.color_discrete_map = None,
428427
category_orders: plotly_params.category_order = None,
429-
edge_legend: anjl.params.edge_legend = False,
430-
leaf_legend: anjl.params.leaf_legend = True,
428+
edge_legend: distance_params.edge_legend = False,
429+
leaf_legend: distance_params.leaf_legend = True,
431430
legend_sizing: plotly_params.legend_sizing = "constant",
432431
thin_offset: base_params.thin_offset = 0,
433432
sample_sets: Optional[base_params.sample_sets] = None,
@@ -449,6 +448,10 @@ def plot_njt(
449448
inline_array: base_params.inline_array = base_params.inline_array_default,
450449
chunks: base_params.chunks = base_params.native_chunks,
451450
) -> plotly_params.figure:
451+
# Only import anjl if needed, as it requires a couple of seconds to compile
452+
# functions.
453+
import anjl # type: ignore
454+
452455
# Normalise params.
453456
if count_sort is None and distance_sort is None:
454457
count_sort = True

malariagen_data/anoph/distance_params.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,20 @@
1919
]
2020

2121
default_nj_algorithm: nj_algorithm = "dynamic"
22+
23+
center_x: TypeAlias = Annotated[int | float, "X coordinate where plotting is centered."]
24+
25+
center_y: TypeAlias = Annotated[int | float, "Y coordinate where plotting is centered."]
26+
27+
arc_start: TypeAlias = Annotated[int | float, "Angle where tree layout begins."]
28+
29+
arc_stop: TypeAlias = Annotated[int | float, "Angle where tree layout ends."]
30+
31+
edge_legend: TypeAlias = Annotated[
32+
bool, "Show legend entries for the different edge (line) colors."
33+
]
34+
35+
leaf_legend: TypeAlias = Annotated[
36+
bool,
37+
"Show legend entries for the different leaf node (scatter) colors and symbols.",
38+
]

0 commit comments

Comments
 (0)