risk-network 0.0.6b1__tar.gz → 0.0.6b3__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.
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/PKG-INFO +1 -1
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/__init__.py +1 -1
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/network/graph.py +26 -21
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/network/plot.py +115 -51
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk_network.egg-info/PKG-INFO +1 -1
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/LICENSE +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/MANIFEST.in +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/README.md +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/pyproject.toml +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/annotations/__init__.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/annotations/annotations.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/annotations/io.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/constants.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/log/__init__.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/log/console.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/log/params.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/neighborhoods/__init__.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/neighborhoods/community.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/neighborhoods/domains.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/neighborhoods/neighborhoods.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/network/__init__.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/network/geometry.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/network/io.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/risk.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/stats/__init__.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/stats/fisher_exact.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/stats/hypergeom.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/stats/permutation/__init__.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/stats/permutation/permutation.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/stats/permutation/test_functions.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk/stats/stats.py +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk_network.egg-info/SOURCES.txt +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk_network.egg-info/dependency_links.txt +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk_network.egg-info/requires.txt +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/risk_network.egg-info/top_level.txt +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/setup.cfg +0 -0
- {risk_network-0.0.6b1 → risk_network-0.0.6b3}/setup.py +0 -0
@@ -101,31 +101,32 @@ class NetworkGraph:
|
|
101
101
|
|
102
102
|
def get_domain_colors(
|
103
103
|
self,
|
104
|
+
cmap: str = "gist_rainbow",
|
105
|
+
color: Union[str, None] = None,
|
104
106
|
min_scale: float = 0.8,
|
105
107
|
max_scale: float = 1.0,
|
106
108
|
scale_factor: float = 1.0,
|
107
109
|
random_seed: int = 888,
|
108
|
-
**kwargs,
|
109
110
|
) -> np.ndarray:
|
110
|
-
"""Generate composite colors for domains.
|
111
|
-
|
112
|
-
This method generates composite colors for nodes based on their enrichment scores and transforms
|
113
|
-
them to ensure proper alpha values and intensity. For nodes with alpha == 0, it assigns new colors
|
114
|
-
based on the closest valid neighbors within a specified distance.
|
111
|
+
"""Generate composite colors for domains based on enrichment or specified colors.
|
115
112
|
|
116
113
|
Args:
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
114
|
+
cmap (str, optional): Name of the colormap to use for generating domain colors. Defaults to "gist_rainbow".
|
115
|
+
color (str or None, optional): A specific color to use for all generated colors. Defaults to None.
|
116
|
+
min_scale (float, optional): Minimum intensity scale for the colors generated by the colormap.
|
117
|
+
Controls the dimmest colors. Defaults to 0.8.
|
118
|
+
max_scale (float, optional): Maximum intensity scale for the colors generated by the colormap.
|
119
|
+
Controls the brightest colors. Defaults to 1.0.
|
120
|
+
scale_factor (float, optional): Exponent for adjusting the color scaling based on enrichment scores.
|
121
|
+
A higher value increases contrast by dimming lower scores more. Defaults to 1.0.
|
122
|
+
random_seed (int, optional): Seed for random number generation to ensure reproducibility of color assignments.
|
123
|
+
Defaults to 888.
|
123
124
|
|
124
125
|
Returns:
|
125
|
-
np.ndarray: Array of
|
126
|
+
np.ndarray: Array of RGBA colors generated for each domain, based on enrichment or the specified color.
|
126
127
|
"""
|
127
128
|
# Get colors for each domain
|
128
|
-
domain_colors = self._get_domain_colors(random_seed=random_seed)
|
129
|
+
domain_colors = self._get_domain_colors(cmap=cmap, color=color, random_seed=random_seed)
|
129
130
|
# Generate composite colors for nodes
|
130
131
|
node_colors = self._get_composite_node_colors(domain_colors)
|
131
132
|
# Transform colors to ensure proper alpha values and intensity
|
@@ -161,12 +162,16 @@ class NetworkGraph:
|
|
161
162
|
return composite_colors
|
162
163
|
|
163
164
|
def _get_domain_colors(
|
164
|
-
self,
|
165
|
+
self,
|
166
|
+
cmap: str = "gist_rainbow",
|
167
|
+
color: Union[str, None] = None,
|
168
|
+
random_seed: int = 888,
|
165
169
|
) -> Dict[str, Any]:
|
166
170
|
"""Get colors for each domain.
|
167
171
|
|
168
172
|
Args:
|
169
|
-
|
173
|
+
cmap (str, optional): The name of the colormap to use. Defaults to "gist_rainbow".
|
174
|
+
color (str or None, optional): A specific color to use for all generated colors. Defaults to None.
|
170
175
|
random_seed (int, optional): Seed for random number generation. Defaults to 888.
|
171
176
|
|
172
177
|
Returns:
|
@@ -178,7 +183,7 @@ class NetworkGraph:
|
|
178
183
|
]
|
179
184
|
domains = np.sort(numeric_domains)
|
180
185
|
domain_colors = _get_colors(
|
181
|
-
num_colors_to_generate=len(domains), color=color, random_seed=random_seed
|
186
|
+
num_colors_to_generate=len(domains), cmap=cmap, color=color, random_seed=random_seed
|
182
187
|
)
|
183
188
|
return dict(zip(self.domain_to_nodes.keys(), domain_colors))
|
184
189
|
|
@@ -273,17 +278,17 @@ def _extract_node_coordinates(G: nx.Graph) -> np.ndarray:
|
|
273
278
|
|
274
279
|
def _get_colors(
|
275
280
|
num_colors_to_generate: int = 10,
|
276
|
-
cmap: str = "
|
277
|
-
random_seed: int = 888,
|
281
|
+
cmap: str = "gist_rainbow",
|
278
282
|
color: Union[str, None] = None,
|
283
|
+
random_seed: int = 888,
|
279
284
|
) -> List[Tuple]:
|
280
285
|
"""Generate a list of RGBA colors from a specified colormap or use a direct color string.
|
281
286
|
|
282
287
|
Args:
|
283
288
|
num_colors_to_generate (int): The number of colors to generate. Defaults to 10.
|
284
|
-
cmap (str): The name of the colormap to use. Defaults to "
|
289
|
+
cmap (str, optional): The name of the colormap to use. Defaults to "gist_rainbow".
|
290
|
+
color (str or None, optional): A specific color to use for all generated colors.
|
285
291
|
random_seed (int): Seed for random number generation. Defaults to 888.
|
286
|
-
color (str, optional): Specific color to use for all nodes. If specified, it will overwrite the colormap.
|
287
292
|
Defaults to None.
|
288
293
|
|
289
294
|
Returns:
|
@@ -207,6 +207,7 @@ class NetworkPlotter:
|
|
207
207
|
self,
|
208
208
|
node_size: Union[int, np.ndarray] = 50,
|
209
209
|
node_shape: str = "o",
|
210
|
+
node_edgewidth: float = 1.0,
|
210
211
|
edge_width: float = 1.0,
|
211
212
|
node_color: Union[str, List, Tuple, np.ndarray] = "white",
|
212
213
|
node_edgecolor: Union[str, List, Tuple, np.ndarray] = "black",
|
@@ -214,16 +215,17 @@ class NetworkPlotter:
|
|
214
215
|
node_alpha: float = 1.0,
|
215
216
|
edge_alpha: float = 1.0,
|
216
217
|
) -> None:
|
217
|
-
"""Plot the network graph with customizable node colors, sizes, and edge widths.
|
218
|
+
"""Plot the network graph with customizable node colors, sizes, edge widths, and node edge widths.
|
218
219
|
|
219
220
|
Args:
|
220
221
|
node_size (int or np.ndarray, optional): Size of the nodes. Can be a single integer or an array of sizes. Defaults to 50.
|
221
222
|
node_shape (str, optional): Shape of the nodes. Defaults to "o".
|
223
|
+
node_edgewidth (float, optional): Width of the node edges. Defaults to 1.0.
|
222
224
|
edge_width (float, optional): Width of the edges. Defaults to 1.0.
|
223
225
|
node_color (str, list, tuple, or np.ndarray, optional): Color of the nodes. Can be a single color or an array of colors. Defaults to "white".
|
224
226
|
node_edgecolor (str, list, tuple, or np.ndarray, optional): Color of the node edges. Defaults to "black".
|
225
227
|
edge_color (str, list, tuple, or np.ndarray, optional): Color of the edges. Defaults to "black".
|
226
|
-
node_alpha (float, optional): Alpha value (transparency) for the nodes. Defaults to 1.0.
|
228
|
+
node_alpha (float, optional): Alpha value (transparency) for the nodes. Defaults to 1.0. Annotated node_color alphas will override this value.
|
227
229
|
edge_alpha (float, optional): Alpha value (transparency) for the edges. Defaults to 1.0.
|
228
230
|
"""
|
229
231
|
# Log the plotting parameters
|
@@ -232,6 +234,7 @@ class NetworkPlotter:
|
|
232
234
|
"custom" if isinstance(node_size, np.ndarray) else node_size
|
233
235
|
), # np.ndarray usually indicates custom sizes
|
234
236
|
network_node_shape=node_shape,
|
237
|
+
network_node_edgewidth=node_edgewidth,
|
235
238
|
network_edge_width=edge_width,
|
236
239
|
network_node_color=(
|
237
240
|
"custom" if isinstance(node_color, np.ndarray) else node_color
|
@@ -245,10 +248,7 @@ class NetworkPlotter:
|
|
245
248
|
# Convert colors to RGBA using the _to_rgba helper function
|
246
249
|
# If node_colors was generated using get_annotated_node_colors, its alpha values will override node_alpha
|
247
250
|
node_color = _to_rgba(node_color, node_alpha, num_repeats=len(self.graph.network.nodes))
|
248
|
-
|
249
|
-
node_edgecolor = _to_rgba(
|
250
|
-
node_edgecolor, 1.0, num_repeats=len(self.graph.network.nodes)
|
251
|
-
) # Node edges are usually fully opaque
|
251
|
+
node_edgecolor = _to_rgba(node_edgecolor, 1.0, num_repeats=len(self.graph.network.nodes))
|
252
252
|
edge_color = _to_rgba(edge_color, edge_alpha, num_repeats=len(self.graph.network.edges))
|
253
253
|
|
254
254
|
# Extract node coordinates from the network graph
|
@@ -262,6 +262,7 @@ class NetworkPlotter:
|
|
262
262
|
node_shape=node_shape,
|
263
263
|
node_color=node_color,
|
264
264
|
edgecolors=node_edgecolor,
|
265
|
+
linewidths=node_edgewidth,
|
265
266
|
ax=self.ax,
|
266
267
|
)
|
267
268
|
# Draw the edges of the graph
|
@@ -522,7 +523,7 @@ class NetworkPlotter:
|
|
522
523
|
|
523
524
|
def plot_labels(
|
524
525
|
self,
|
525
|
-
|
526
|
+
scale: float = 1.05,
|
526
527
|
offset: float = 0.10,
|
527
528
|
font: str = "Arial",
|
528
529
|
fontsize: int = 10,
|
@@ -541,7 +542,7 @@ class NetworkPlotter:
|
|
541
542
|
"""Annotate the network graph with labels for different domains, positioned around the network for clarity.
|
542
543
|
|
543
544
|
Args:
|
544
|
-
|
545
|
+
scale (float, optional): Scale factor for positioning labels around the perimeter. Defaults to 1.05.
|
545
546
|
offset (float, optional): Offset distance for labels from the perimeter. Defaults to 0.10.
|
546
547
|
font (str, optional): Font name for the labels. Defaults to "Arial".
|
547
548
|
fontsize (int, optional): Font size for the labels. Defaults to 10.
|
@@ -559,7 +560,7 @@ class NetworkPlotter:
|
|
559
560
|
"""
|
560
561
|
# Log the plotting parameters
|
561
562
|
params.log_plotter(
|
562
|
-
label_perimeter_scale=
|
563
|
+
label_perimeter_scale=scale,
|
563
564
|
label_offset=offset,
|
564
565
|
label_font=font,
|
565
566
|
label_fontsize=fontsize,
|
@@ -637,9 +638,7 @@ class NetworkPlotter:
|
|
637
638
|
valid_indices = [valid_indices[i] for i in selected_indices]
|
638
639
|
|
639
640
|
# Calculate the bounding box around the network
|
640
|
-
center, radius = _calculate_bounding_box(
|
641
|
-
self.graph.node_coordinates, radius_margin=perimeter_scale
|
642
|
-
)
|
641
|
+
center, radius = _calculate_bounding_box(self.graph.node_coordinates, radius_margin=scale)
|
643
642
|
# Calculate the best positions for labels around the perimeter
|
644
643
|
best_label_positions = _calculate_best_label_positions(
|
645
644
|
filtered_domain_centroids, center, radius, offset
|
@@ -666,7 +665,7 @@ class NetworkPlotter:
|
|
666
665
|
nodes: List,
|
667
666
|
label: str,
|
668
667
|
radial_position: float = 0.0,
|
669
|
-
|
668
|
+
scale: float = 1.05,
|
670
669
|
offset: float = 0.10,
|
671
670
|
font: str = "Arial",
|
672
671
|
fontsize: int = 10,
|
@@ -682,7 +681,7 @@ class NetworkPlotter:
|
|
682
681
|
nodes (List[str]): List of node labels to be used for calculating the centroid.
|
683
682
|
label (str): The label to be annotated on the network.
|
684
683
|
radial_position (float, optional): Radial angle for positioning the label, in degrees (0-360). Defaults to 0.0.
|
685
|
-
|
684
|
+
scale (float, optional): Scale factor for positioning the label around the perimeter. Defaults to 1.05.
|
686
685
|
offset (float, optional): Offset distance for the label from the perimeter. Defaults to 0.10.
|
687
686
|
font (str, optional): Font name for the label. Defaults to "Arial".
|
688
687
|
fontsize (int, optional): Font size for the label. Defaults to 10.
|
@@ -708,9 +707,7 @@ class NetworkPlotter:
|
|
708
707
|
# Calculate the centroid of the provided nodes
|
709
708
|
centroid = self._calculate_domain_centroid(node_ids)
|
710
709
|
# Calculate the bounding box around the network
|
711
|
-
center, radius = _calculate_bounding_box(
|
712
|
-
self.graph.node_coordinates, radius_margin=perimeter_scale
|
713
|
-
)
|
710
|
+
center, radius = _calculate_bounding_box(self.graph.node_coordinates, radius_margin=scale)
|
714
711
|
# Convert radial position to radians, adjusting for a 90-degree rotation
|
715
712
|
radial_radians = np.deg2rad(radial_position - 90)
|
716
713
|
label_position = (
|
@@ -755,26 +752,41 @@ class NetworkPlotter:
|
|
755
752
|
|
756
753
|
def get_annotated_node_colors(
|
757
754
|
self,
|
755
|
+
cmap: str = "gist_rainbow",
|
756
|
+
color: Union[str, None] = None,
|
757
|
+
min_scale: float = 0.8,
|
758
|
+
max_scale: float = 1.0,
|
759
|
+
scale_factor: float = 1.0,
|
758
760
|
alpha: float = 1.0,
|
759
761
|
nonenriched_color: Union[str, List, Tuple, np.ndarray] = "white",
|
760
762
|
nonenriched_alpha: float = 1.0,
|
761
763
|
random_seed: int = 888,
|
762
|
-
**kwargs,
|
763
764
|
) -> np.ndarray:
|
764
765
|
"""Adjust the colors of nodes in the network graph based on enrichment.
|
765
766
|
|
766
767
|
Args:
|
768
|
+
cmap (str, optional): Colormap to use for coloring the nodes. Defaults to "gist_rainbow".
|
769
|
+
color (str or None, optional): Color to use for the nodes. If None, the colormap will be used. Defaults to None.
|
770
|
+
min_scale (float, optional): Minimum scale for color intensity. Defaults to 0.8.
|
771
|
+
max_scale (float, optional): Maximum scale for color intensity. Defaults to 1.0.
|
772
|
+
scale_factor (float, optional): Factor for adjusting the color scaling intensity. Defaults to 1.0.
|
767
773
|
alpha (float, optional): Alpha value for enriched nodes. Defaults to 1.0.
|
768
774
|
nonenriched_color (str, list, tuple, or np.ndarray, optional): Color for non-enriched nodes. Defaults to "white".
|
769
775
|
nonenriched_alpha (float, optional): Alpha value for non-enriched nodes. Defaults to 1.0.
|
770
776
|
random_seed (int, optional): Seed for random number generation. Defaults to 888.
|
771
|
-
**kwargs: Additional keyword arguments for `get_domain_colors`.
|
772
777
|
|
773
778
|
Returns:
|
774
779
|
np.ndarray: Array of RGBA colors adjusted for enrichment status.
|
775
780
|
"""
|
776
781
|
# Get the initial domain colors for each node, which are returned as RGBA
|
777
|
-
network_colors = self.graph.get_domain_colors(
|
782
|
+
network_colors = self.graph.get_domain_colors(
|
783
|
+
cmap=cmap,
|
784
|
+
color=color,
|
785
|
+
min_scale=min_scale,
|
786
|
+
max_scale=max_scale,
|
787
|
+
scale_factor=scale_factor,
|
788
|
+
random_seed=random_seed,
|
789
|
+
)
|
778
790
|
# Apply the alpha value for enriched nodes
|
779
791
|
network_colors[:, 3] = alpha # Apply the alpha value to the enriched nodes' A channel
|
780
792
|
# Convert the non-enriched color to RGBA using the _to_rgba helper function
|
@@ -813,68 +825,120 @@ class NetworkPlotter:
|
|
813
825
|
|
814
826
|
return node_sizes
|
815
827
|
|
816
|
-
def get_annotated_contour_colors(
|
817
|
-
|
828
|
+
def get_annotated_contour_colors(
|
829
|
+
self,
|
830
|
+
cmap: str = "gist_rainbow",
|
831
|
+
color: Union[str, None] = None,
|
832
|
+
min_scale: float = 0.8,
|
833
|
+
max_scale: float = 1.0,
|
834
|
+
scale_factor: float = 1.0,
|
835
|
+
random_seed: int = 888,
|
836
|
+
) -> np.ndarray:
|
837
|
+
"""Get colors for the contours based on node annotations or a specified colormap.
|
818
838
|
|
819
839
|
Args:
|
820
|
-
|
821
|
-
|
840
|
+
cmap (str, optional): Name of the colormap to use for generating contour colors. Defaults to "gist_rainbow".
|
841
|
+
color (str or None, optional): Color to use for the contours. If None, the colormap will be used. Defaults to None.
|
842
|
+
min_scale (float, optional): Minimum intensity scale for the colors generated by the colormap.
|
843
|
+
Controls the dimmest colors. Defaults to 0.8.
|
844
|
+
max_scale (float, optional): Maximum intensity scale for the colors generated by the colormap.
|
845
|
+
Controls the brightest colors. Defaults to 1.0.
|
846
|
+
scale_factor (float, optional): Exponent for adjusting color scaling based on enrichment scores.
|
847
|
+
A higher value increases contrast by dimming lower scores more. Defaults to 1.0.
|
848
|
+
random_seed (int, optional): Seed for random number generation to ensure reproducibility. Defaults to 888.
|
822
849
|
|
823
850
|
Returns:
|
824
851
|
np.ndarray: Array of RGBA colors for contour annotations.
|
825
852
|
"""
|
826
|
-
return self._get_annotated_domain_colors(
|
853
|
+
return self._get_annotated_domain_colors(
|
854
|
+
cmap=cmap,
|
855
|
+
color=color,
|
856
|
+
min_scale=min_scale,
|
857
|
+
max_scale=max_scale,
|
858
|
+
scale_factor=scale_factor,
|
859
|
+
random_seed=random_seed,
|
860
|
+
)
|
827
861
|
|
828
|
-
def get_annotated_label_colors(
|
829
|
-
|
862
|
+
def get_annotated_label_colors(
|
863
|
+
self,
|
864
|
+
cmap: str = "gist_rainbow",
|
865
|
+
color: Union[str, None] = None,
|
866
|
+
min_scale: float = 0.8,
|
867
|
+
max_scale: float = 1.0,
|
868
|
+
scale_factor: float = 1.0,
|
869
|
+
random_seed: int = 888,
|
870
|
+
) -> np.ndarray:
|
871
|
+
"""Get colors for the labels based on node annotations or a specified colormap.
|
830
872
|
|
831
873
|
Args:
|
832
|
-
|
833
|
-
|
874
|
+
cmap (str, optional): Name of the colormap to use for generating label colors. Defaults to "gist_rainbow".
|
875
|
+
color (str or None, optional): Color to use for the labels. If None, the colormap will be used. Defaults to None.
|
876
|
+
min_scale (float, optional): Minimum intensity scale for the colors generated by the colormap.
|
877
|
+
Controls the dimmest colors. Defaults to 0.8.
|
878
|
+
max_scale (float, optional): Maximum intensity scale for the colors generated by the colormap.
|
879
|
+
Controls the brightest colors. Defaults to 1.0.
|
880
|
+
scale_factor (float, optional): Exponent for adjusting color scaling based on enrichment scores.
|
881
|
+
A higher value increases contrast by dimming lower scores more. Defaults to 1.0.
|
882
|
+
random_seed (int, optional): Seed for random number generation to ensure reproducibility. Defaults to 888.
|
834
883
|
|
835
884
|
Returns:
|
836
885
|
np.ndarray: Array of RGBA colors for label annotations.
|
837
886
|
"""
|
838
|
-
return self._get_annotated_domain_colors(
|
887
|
+
return self._get_annotated_domain_colors(
|
888
|
+
cmap=cmap,
|
889
|
+
color=color,
|
890
|
+
min_scale=min_scale,
|
891
|
+
max_scale=max_scale,
|
892
|
+
scale_factor=scale_factor,
|
893
|
+
random_seed=random_seed,
|
894
|
+
)
|
839
895
|
|
840
896
|
def _get_annotated_domain_colors(
|
841
897
|
self,
|
842
|
-
|
898
|
+
cmap: str = "gist_rainbow",
|
899
|
+
color: Union[str, None] = None,
|
900
|
+
min_scale: float = 0.8,
|
901
|
+
max_scale: float = 1.0,
|
902
|
+
scale_factor: float = 1.0,
|
843
903
|
random_seed: int = 888,
|
844
|
-
**kwargs,
|
845
904
|
) -> np.ndarray:
|
846
|
-
"""Get colors for the domains based on node annotations.
|
905
|
+
"""Get colors for the domains based on node annotations, or use a specified color.
|
847
906
|
|
848
907
|
Args:
|
849
|
-
|
850
|
-
|
851
|
-
|
908
|
+
cmap (str, optional): Colormap to use for generating domain colors. Defaults to "gist_rainbow".
|
909
|
+
color (str or None, optional): Color to use for the domains. If None, the colormap will be used. Defaults to None.
|
910
|
+
min_scale (float, optional): Minimum scale for color intensity when generating domain colors.
|
911
|
+
Defaults to 0.8.
|
912
|
+
max_scale (float, optional): Maximum scale for color intensity when generating domain colors.
|
913
|
+
Defaults to 1.0.
|
914
|
+
scale_factor (float, optional): Factor for adjusting the contrast in the colors generated based on
|
915
|
+
enrichment. Higher values increase the contrast. Defaults to 1.0.
|
916
|
+
random_seed (int, optional): Seed for random number generation to ensure reproducibility. Defaults to 888.
|
852
917
|
|
853
918
|
Returns:
|
854
919
|
np.ndarray: Array of RGBA colors for each domain.
|
855
920
|
"""
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
node_colors = self.graph.get_domain_colors(**kwargs, random_seed=random_seed)
|
921
|
+
# Generate domain colors based on the enrichment data
|
922
|
+
node_colors = self.graph.get_domain_colors(
|
923
|
+
cmap=cmap,
|
924
|
+
color=color,
|
925
|
+
min_scale=min_scale,
|
926
|
+
max_scale=max_scale,
|
927
|
+
scale_factor=scale_factor,
|
928
|
+
random_seed=random_seed,
|
929
|
+
)
|
866
930
|
annotated_colors = []
|
867
931
|
for _, nodes in self.graph.domain_to_nodes.items():
|
868
932
|
if len(nodes) > 1:
|
869
|
-
# For domains
|
933
|
+
# For multi-node domains, choose the brightest color based on RGB sum
|
870
934
|
domain_colors = np.array([node_colors[node] for node in nodes])
|
871
935
|
brightest_color = domain_colors[
|
872
|
-
np.argmax(domain_colors[:, :3].sum(axis=1))
|
873
|
-
]
|
936
|
+
np.argmax(domain_colors[:, :3].sum(axis=1)) # Sum the RGB values
|
937
|
+
]
|
874
938
|
annotated_colors.append(brightest_color)
|
875
939
|
else:
|
876
|
-
#
|
877
|
-
default_color = np.array([1.0, 1.0, 1.0, 1.0])
|
940
|
+
# Single-node domains default to white (RGBA)
|
941
|
+
default_color = np.array([1.0, 1.0, 1.0, 1.0])
|
878
942
|
annotated_colors.append(default_color)
|
879
943
|
|
880
944
|
return np.array(annotated_colors)
|
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
|
File without changes
|