risk-network 0.0.9b8__py3-none-any.whl → 0.0.9b9__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 CHANGED
@@ -7,4 +7,4 @@ RISK: RISK Infers Spatial Kinships
7
7
 
8
8
  from risk.risk import RISK
9
9
 
10
- __version__ = "0.0.9-beta.8"
10
+ __version__ = "0.0.9-beta.9"
@@ -234,88 +234,37 @@ def _get_colors(
234
234
  color: Union[str, List, Tuple, np.ndarray, None] = None,
235
235
  random_seed: int = 888,
236
236
  ) -> List[Tuple]:
237
- """Generate a list of RGBA colors based on domain centroids, ensuring that domains
238
- close in space get maximally separated colors, while keeping some randomness.
237
+ """Generate a list of RGBA colors for domains, ensuring maximally separated colors for nearby domains.
239
238
 
240
239
  Args:
241
240
  network (nx.Graph): The graph representing the network.
242
241
  domain_id_to_node_ids_map (Dict[int, Any]): Mapping from domain IDs to lists of node IDs.
243
242
  cmap (str, optional): The name of the colormap to use. Defaults to "gist_rainbow".
244
- color (str, List, Tuple, np.ndarray, or None, optional): A specific color or array of colors to use for the domains.
243
+ color (str, List, Tuple, np.ndarray, or None, optional): A specific color or array of colors to use.
245
244
  If None, the colormap will be used. Defaults to None.
246
245
  random_seed (int, optional): Seed for random number generation. Defaults to 888.
247
246
 
248
247
  Returns:
249
- List[Tuple]: List of RGBA colors.
248
+ List[Tuple]: List of RGBA colors for each domain.
250
249
  """
251
- # Set random seed for reproducibility
252
250
  np.random.seed(random_seed)
253
-
254
- # Determine the number of colors to generate based on the number of domains
255
251
  num_domains = len(domain_id_to_node_ids_map)
256
252
  if color:
257
- # Generate all colors as the same specified color
253
+ # If a single color is specified, apply it to all domains
258
254
  rgba = to_rgba(color, num_repeats=num_domains)
259
255
  return rgba
260
256
 
261
- # Load colormap
257
+ # Load colormap and generate a large, maximally separated set of colors
262
258
  colormap = matplotlib.colormaps.get_cmap(cmap)
263
- # Step 1: Calculate centroids for each domain
264
- centroids = calculate_centroids(network, domain_id_to_node_ids_map)
265
- centroid_array = np.array(centroids)
266
-
267
- # Step 2: Cluster domains based on proximity using Agglomerative Clustering
268
- dist_matrix = np.linalg.norm(centroid_array[:, None] - centroid_array, axis=-1)
269
- max_distance = np.max(dist_matrix) if np.max(dist_matrix) != 0 else 1
270
- proximity_threshold = 0.3 * max_distance
271
-
272
- clustering_model = AgglomerativeClustering(
273
- n_clusters=None, distance_threshold=proximity_threshold
274
- )
275
- cluster_labels = clustering_model.fit_predict(centroid_array)
276
- num_clusters = len(set(cluster_labels))
277
-
278
- # Step 3: Assign base color positions for each cluster, spaced across colormap
279
- cluster_positions = np.linspace(0, 1, num_clusters, endpoint=False)
280
- np.random.shuffle(cluster_positions) # Shuffle based on seed to vary color layout
281
- cluster_id_to_position = {
282
- cluster_id: pos for cluster_id, pos in zip(np.unique(cluster_labels), cluster_positions)
283
- }
284
-
285
- # Step 4: Assign colors to each domain based on cluster base color with a global shift
286
- global_shift = np.random.uniform(-0.1, 0.1) # Small global shift for variety
287
- colors = []
288
- for i in range(num_domains):
289
- cluster_idx = cluster_labels[i]
290
- base_position = cluster_id_to_position[cluster_idx]
291
- # Add global shift and ensure it stays within [0, 1]
292
- color_position = (base_position + global_shift) % 1
293
- colors.append(colormap(color_position)) # Get color from colormap
259
+ color_positions = np.linspace(0, 1, num_domains, endpoint=False)
260
+ # Shuffle color positions to avoid spatial clustering of similar colors
261
+ np.random.shuffle(color_positions)
262
+ # Assign colors based on positions in the colormap
263
+ colors = [colormap(pos) for pos in color_positions]
294
264
 
295
265
  return colors
296
266
 
297
267
 
298
- def _assign_distant_colors(dist_matrix: np.ndarray, num_colors_to_generate: int) -> np.ndarray:
299
- """Assign color positions ensuring centroids close in space are maximally separated in color.
300
-
301
- Args:
302
- dist_matrix (ndarray): Matrix of pairwise centroid distances.
303
- num_colors_to_generate (int): Number of colors to generate.
304
-
305
- Returns:
306
- np.array: Array of color positions in the range [0, 1].
307
- """
308
- # Step 1: Calculate proximity order based on the sum of distances
309
- proximity_order = sorted(
310
- range(num_colors_to_generate), key=lambda idx: np.sum(dist_matrix[idx])
311
- )
312
- # Step 2: Generate evenly spaced color positions
313
- color_positions = np.linspace(0, 1, num_colors_to_generate, endpoint=False)
314
- # Step 3: Shuffle color positions based on proximity
315
- color_positions = color_positions[proximity_order]
316
- return color_positions
317
-
318
-
319
268
  def _blend_colors_perceptually(
320
269
  colors: Union[List, Tuple, np.ndarray], significances: List[float], gamma: float = 2.2
321
270
  ) -> Tuple[float, float, float, float]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.9b8
3
+ Version: 0.0.9b9
4
4
  Summary: A Python package for biological network analysis
5
5
  Author: Ira Horecka
6
6
  Author-email: Ira Horecka <ira89@icloud.com>
@@ -1,4 +1,4 @@
1
- risk/__init__.py,sha256=CF_5U_LFsoHtqjLJO9F0HRUYI0sDt4UlIWwkpkOG-no,112
1
+ risk/__init__.py,sha256=wOa6WyqiT30Dx0Mk77M-4ilHgFK5rf0eRjG7ceeU8Gw,112
2
2
  risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
3
3
  risk/risk.py,sha256=kntBxYwAEpoAjXN_l6BM3yxFKyuAKmd8OMGl2P00pZ4,22416
4
4
  risk/annotations/__init__.py,sha256=kXgadEXaCh0z8OyhOhTj7c3qXGmWgOhaSZ4gSzSb59U,147
@@ -23,7 +23,7 @@ risk/network/plot/contour.py,sha256=VONX9l6owrZvWtR0mWQ6z2GSd1YXIv5wV_sf5ROQLT4,
23
23
  risk/network/plot/labels.py,sha256=eorP80CmAbHmt7de2qHna1tHGKL8YiHknwFW2R3tvjI,45734
24
24
  risk/network/plot/network.py,sha256=_K8Am2y6zSGrm3fAgMbXxzgspbugJi3uK4_tG8qqGoI,14015
25
25
  risk/network/plot/plotter.py,sha256=eS1vHqvOA2O001Rq7WiDcgqcehJ3fg4OPfvkezH4erw,5771
26
- risk/network/plot/utils/colors.py,sha256=lNDwlTbpXCKAbaqSHsRlxxY_MRAbogma81xyqHawl3U,21005
26
+ risk/network/plot/utils/colors.py,sha256=9zuU2O-Nkpljb1yVGUR_IjqD1y-wH6Bf6Vm1MMVB0Lo,18718
27
27
  risk/network/plot/utils/layout.py,sha256=6o7idoWQnyzujSWOFXQykUvyPy8NuRtJV04TnlbXXBo,3647
28
28
  risk/stats/__init__.py,sha256=WcgoETQ-hS0LQqKRsAMIPtP15xZ-4eul6VUBuUx4Wzc,220
29
29
  risk/stats/hypergeom.py,sha256=oc39f02ViB1vQ-uaDrxG_tzAT6dxQBRjc88EK2EGn78,2282
@@ -32,8 +32,8 @@ risk/stats/stats.py,sha256=z8NrhiVj4BzJ250bVLfytpmfC7RzYu7mBuIZD_l0aCA,7222
32
32
  risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
33
33
  risk/stats/permutation/permutation.py,sha256=meBNSrbRa9P8WJ54n485l0H7VQJlMSfHqdN4aCKYCtQ,10105
34
34
  risk/stats/permutation/test_functions.py,sha256=lftOude6hee0pyR80HlBD32522JkDoN5hrKQ9VEbuoY,2345
35
- risk_network-0.0.9b8.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
36
- risk_network-0.0.9b8.dist-info/METADATA,sha256=JaTFHNn11mwliUNgsG6jvz2sU53goxjS3cwQXLEbcEw,47497
37
- risk_network-0.0.9b8.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
38
- risk_network-0.0.9b8.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
39
- risk_network-0.0.9b8.dist-info/RECORD,,
35
+ risk_network-0.0.9b9.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
36
+ risk_network-0.0.9b9.dist-info/METADATA,sha256=iBZOFuXgFhOXgRkBH90TC3Fkk7r1iAX6Yq0bPuGjxck,47497
37
+ risk_network-0.0.9b9.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
38
+ risk_network-0.0.9b9.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
39
+ risk_network-0.0.9b9.dist-info/RECORD,,