risk-network 0.0.11__py3-none-any.whl → 0.0.12__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.
- risk/__init__.py +1 -1
- risk/annotation/__init__.py +10 -0
- risk/{annotations/annotations.py → annotation/annotation.py} +44 -44
- risk/{annotations → annotation}/io.py +93 -92
- risk/{annotations → annotation}/nltk_setup.py +6 -5
- risk/log/__init__.py +1 -1
- risk/log/parameters.py +26 -27
- risk/neighborhoods/__init__.py +0 -1
- risk/neighborhoods/api.py +38 -38
- risk/neighborhoods/community.py +33 -4
- risk/neighborhoods/domains.py +26 -28
- risk/neighborhoods/neighborhoods.py +8 -2
- risk/neighborhoods/stats/__init__.py +13 -0
- risk/neighborhoods/stats/permutation/__init__.py +6 -0
- risk/{stats → neighborhoods/stats}/permutation/permutation.py +24 -21
- risk/{stats → neighborhoods/stats}/permutation/test_functions.py +4 -4
- risk/{stats/stat_tests.py → neighborhoods/stats/tests.py} +62 -54
- risk/network/__init__.py +0 -2
- risk/network/graph/__init__.py +0 -2
- risk/network/graph/api.py +19 -19
- risk/network/graph/graph.py +73 -68
- risk/{stats/significance.py → network/graph/stats.py} +2 -2
- risk/network/graph/summary.py +12 -13
- risk/network/io.py +163 -20
- risk/network/plotter/__init__.py +0 -2
- risk/network/plotter/api.py +1 -1
- risk/network/plotter/canvas.py +36 -36
- risk/network/plotter/contour.py +14 -15
- risk/network/plotter/labels.py +303 -294
- risk/network/plotter/network.py +6 -6
- risk/network/plotter/plotter.py +8 -10
- risk/network/plotter/utils/colors.py +15 -8
- risk/network/plotter/utils/layout.py +3 -3
- risk/risk.py +6 -6
- risk_network-0.0.12.dist-info/METADATA +122 -0
- risk_network-0.0.12.dist-info/RECORD +40 -0
- {risk_network-0.0.11.dist-info → risk_network-0.0.12.dist-info}/WHEEL +1 -1
- risk/annotations/__init__.py +0 -7
- risk/network/geometry.py +0 -150
- risk/stats/__init__.py +0 -15
- risk/stats/permutation/__init__.py +0 -6
- risk_network-0.0.11.dist-info/METADATA +0 -798
- risk_network-0.0.11.dist-info/RECORD +0 -41
- {risk_network-0.0.11.dist-info → risk_network-0.0.12.dist-info/licenses}/LICENSE +0 -0
- {risk_network-0.0.11.dist-info → risk_network-0.0.12.dist-info}/top_level.txt +0 -0
risk/network/plotter/canvas.py
CHANGED
@@ -76,7 +76,7 @@ class Canvas:
|
|
76
76
|
fig = self.ax.figure
|
77
77
|
# Use a tight layout to ensure that title and subtitle do not overlap with the original plot
|
78
78
|
fig.tight_layout(
|
79
|
-
rect=
|
79
|
+
rect=(0, 0, 1, 1 - title_space_offset)
|
80
80
|
) # Leave space above the plot for title
|
81
81
|
|
82
82
|
# Plot title if provided
|
@@ -158,7 +158,7 @@ class Canvas:
|
|
158
158
|
# Calculate the center and radius of the bounding box around the network
|
159
159
|
center, radius = calculate_bounding_box(node_coordinates)
|
160
160
|
# Adjust the center based on user-defined offsets
|
161
|
-
adjusted_center = _calculate_adjusted_center(
|
161
|
+
adjusted_center = self._calculate_adjusted_center(
|
162
162
|
center, radius, center_offset_x, center_offset_y
|
163
163
|
)
|
164
164
|
# Scale the radius by the scale factor
|
@@ -250,42 +250,42 @@ class Canvas:
|
|
250
250
|
fill_alpha=fill_alpha,
|
251
251
|
)
|
252
252
|
|
253
|
+
def _calculate_adjusted_center(
|
254
|
+
self,
|
255
|
+
center: Tuple[float, float],
|
256
|
+
radius: float,
|
257
|
+
center_offset_x: float = 0.0,
|
258
|
+
center_offset_y: float = 0.0,
|
259
|
+
) -> Tuple[float, float]:
|
260
|
+
"""Calculate the adjusted center for the network perimeter circle based on user-defined offsets.
|
253
261
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
center (Tuple[float, float]): Original center coordinates of the network graph.
|
264
|
-
radius (float): Radius of the bounding box around the network.
|
265
|
-
center_offset_x (float, optional): Horizontal offset as a fraction of the diameter.
|
266
|
-
Negative values shift the center left, positive values shift it right. Allowed
|
267
|
-
values are in the range [-1, 1]. Defaults to 0.0.
|
268
|
-
center_offset_y (float, optional): Vertical offset as a fraction of the diameter.
|
269
|
-
Negative values shift the center down, positive values shift it up. Allowed
|
270
|
-
values are in the range [-1, 1]. Defaults to 0.0.
|
262
|
+
Args:
|
263
|
+
center (Tuple[float, float]): Original center coordinates of the network graph.
|
264
|
+
radius (float): Radius of the bounding box around the network.
|
265
|
+
center_offset_x (float, optional): Horizontal offset as a fraction of the diameter.
|
266
|
+
Negative values shift the center left, positive values shift it right. Allowed
|
267
|
+
values are in the range [-1, 1]. Defaults to 0.0.
|
268
|
+
center_offset_y (float, optional): Vertical offset as a fraction of the diameter.
|
269
|
+
Negative values shift the center down, positive values shift it up. Allowed
|
270
|
+
values are in the range [-1, 1]. Defaults to 0.0.
|
271
271
|
|
272
|
-
|
273
|
-
|
272
|
+
Returns:
|
273
|
+
Tuple[float, float]: Adjusted center coordinates after applying the offsets.
|
274
274
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
275
|
+
Raises:
|
276
|
+
ValueError: If the center offsets are outside the valid range [-1, 1].
|
277
|
+
"""
|
278
|
+
# Flip the y-axis to match the plot orientation
|
279
|
+
flipped_center_offset_y = -center_offset_y
|
280
|
+
# Validate the center offsets
|
281
|
+
if not -1 <= center_offset_x <= 1:
|
282
|
+
raise ValueError("Horizontal center offset must be in the range [-1, 1].")
|
283
|
+
if not -1 <= center_offset_y <= 1:
|
284
|
+
raise ValueError("Vertical center offset must be in the range [-1, 1].")
|
285
285
|
|
286
|
-
|
287
|
-
|
288
|
-
|
286
|
+
# Calculate adjusted center by applying offset fractions of the diameter
|
287
|
+
adjusted_center_x = center[0] + (center_offset_x * radius * 2)
|
288
|
+
adjusted_center_y = center[1] + (flipped_center_offset_y * radius * 2)
|
289
289
|
|
290
|
-
|
291
|
-
|
290
|
+
# Return the adjusted center coordinates
|
291
|
+
return adjusted_center_x, adjusted_center_y
|
risk/network/plotter/contour.py
CHANGED
@@ -11,7 +11,7 @@ from scipy import linalg
|
|
11
11
|
from scipy.ndimage import label
|
12
12
|
from scipy.stats import gaussian_kde
|
13
13
|
|
14
|
-
from risk.log import
|
14
|
+
from risk.log import logger, params
|
15
15
|
from risk.network.graph.graph import Graph
|
16
16
|
from risk.network.plotter.utils.colors import get_annotated_domain_colors, to_rgba
|
17
17
|
|
@@ -213,7 +213,7 @@ class Contour:
|
|
213
213
|
]
|
214
214
|
z = kde(np.vstack([x.ravel(), y.ravel()])).reshape(x.shape)
|
215
215
|
# Check if the KDE forms a single connected component
|
216
|
-
connected = _is_connected(z)
|
216
|
+
connected = self._is_connected(z)
|
217
217
|
if not connected:
|
218
218
|
bandwidth += 0.05 # Increase bandwidth slightly and retry
|
219
219
|
except linalg.LinAlgError:
|
@@ -282,8 +282,8 @@ class Contour:
|
|
282
282
|
scale_factor: float = 1.0,
|
283
283
|
ids_to_colors: Union[Dict[int, Any], None] = None,
|
284
284
|
random_seed: int = 888,
|
285
|
-
) ->
|
286
|
-
"""Get colors for the contours based on node
|
285
|
+
) -> List[Tuple]:
|
286
|
+
"""Get colors for the contours based on node annotation or a specified colormap.
|
287
287
|
|
288
288
|
Args:
|
289
289
|
cmap (str, optional): Name of the colormap to use for generating contour colors. Defaults to "gist_rainbow".
|
@@ -301,7 +301,7 @@ class Contour:
|
|
301
301
|
random_seed (int, optional): Seed for random number generation to ensure reproducibility. Defaults to 888.
|
302
302
|
|
303
303
|
Returns:
|
304
|
-
|
304
|
+
List[Tuple]: List of RGBA colors for the contours, one for each domain in the network graph.
|
305
305
|
"""
|
306
306
|
return get_annotated_domain_colors(
|
307
307
|
graph=self.graph,
|
@@ -316,15 +316,14 @@ class Contour:
|
|
316
316
|
random_seed=random_seed,
|
317
317
|
)
|
318
318
|
|
319
|
+
def _is_connected(self, z: np.ndarray) -> bool:
|
320
|
+
"""Determine if a thresholded grid represents a single, connected component.
|
319
321
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
Args:
|
324
|
-
z (np.ndarray): A binary grid where the component connectivity is evaluated.
|
322
|
+
Args:
|
323
|
+
z (np.ndarray): A binary grid where the component connectivity is evaluated.
|
325
324
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
325
|
+
Returns:
|
326
|
+
bool: True if the grid represents a single connected component, False otherwise.
|
327
|
+
"""
|
328
|
+
_, num_features = label(z)
|
329
|
+
return num_features == 1 # Return True if only one connected component is found
|