risk-network 0.0.7b3__py3-none-any.whl → 0.0.7b4__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.7-beta.3"
10
+ __version__ = "0.0.7-beta.4"
@@ -200,7 +200,6 @@ def _impute_neighbors_with_similarity(
200
200
  depth = 1
201
201
  rows_to_impute = np.where(binary_enrichment_matrix.sum(axis=1) == 0)[0]
202
202
  while len(rows_to_impute) and depth <= max_depth:
203
- next_rows_to_impute = []
204
203
  # Iterate over all enriched nodes
205
204
  for row_index in range(binary_enrichment_matrix.shape[0]):
206
205
  if binary_enrichment_matrix[row_index].sum() != 0:
risk/network/graph.py CHANGED
@@ -3,7 +3,6 @@ risk/network/graph
3
3
  ~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
- import random
7
6
  from collections import defaultdict
8
7
  from typing import Any, Dict, List, Tuple, Union
9
8
 
@@ -307,7 +306,7 @@ def _get_colors(
307
306
  List[Tuple]: List of RGBA colors.
308
307
  """
309
308
  # Set random seed for reproducibility
310
- random.seed(random_seed)
309
+ np.random.seed(random_seed)
311
310
  # Determine the number of colors to generate based on the number of domains
312
311
  num_colors_to_generate = len(domain_id_to_node_ids_map)
313
312
  if color:
@@ -322,23 +321,15 @@ def _get_colors(
322
321
  # Step 2: Calculate pairwise distances between centroids
323
322
  centroid_array = np.array(centroids)
324
323
  dist_matrix = np.linalg.norm(centroid_array[:, None] - centroid_array, axis=-1)
325
-
326
- # Step 3: Generate positions in the colormap, with a focus on centroids that are close
327
- remaining_indices = set(range(num_colors_to_generate))
328
- # Assign distant colors to close centroids
329
- color_positions = _assign_distant_colors(
330
- remaining_indices, dist_matrix, colormap, num_colors_to_generate
331
- )
332
-
333
- # Step 4: Randomly shuffle color positions to generate a new color palette
334
- # while maintaining the dissimilarity between neighboring colors. This shuffling
335
- # preserves the relative distances between centroids, ensuring that close centroids
336
- # remain visually distinct while introducing randomness into the overall color arrangement.
337
- random.shuffle(color_positions)
338
- # Ensure that all positions remain between 0 and 1
324
+ # Step 3: Assign distant colors to close centroids
325
+ color_positions = _assign_distant_colors(dist_matrix, num_colors_to_generate)
326
+ # Step 4: Randomly shift the entire color palette while maintaining relative distances
327
+ global_shift = np.random.uniform(-0.1, 0.1) # Small global shift to change the overall palette
328
+ color_positions = (color_positions + global_shift) % 1 # Wrap around to keep within [0, 1]
329
+ # Step 5: Ensure that all positions remain between 0 and 1
339
330
  color_positions = np.clip(color_positions, 0, 1)
340
331
 
341
- # Step 5: Generate colors based on positions
332
+ # Step 6: Generate RGBA colors based on positions
342
333
  return [colormap(pos) for pos in color_positions]
343
334
 
344
335
 
@@ -365,28 +356,26 @@ def _calculate_centroids(network, domain_id_to_node_ids_map):
365
356
  return centroids
366
357
 
367
358
 
368
- def _assign_distant_colors(remaining_indices, dist_matrix, colormap, num_colors_to_generate):
359
+ def _assign_distant_colors(dist_matrix, num_colors_to_generate):
369
360
  """Assign colors to centroids that are close in space, ensuring stark color differences.
370
361
 
371
362
  Args:
372
- remaining_indices (set): Indices of centroids left to color.
373
363
  dist_matrix (ndarray): Matrix of pairwise centroid distances.
374
- colormap (Colormap): The colormap used to assign colors.
375
364
  num_colors_to_generate (int): Number of colors to generate.
376
365
 
377
366
  Returns:
378
- np.array: Array of color positions in the colormap.
367
+ np.array: Array of color positions in the range [0, 1].
379
368
  """
380
369
  color_positions = np.zeros(num_colors_to_generate)
381
- # Convert the set to a list to index over it
382
- remaining_indices = list(remaining_indices)
383
- # Sort remaining indices by centroid proximity (based on sum of distances to others)
384
- proximity_order = sorted(remaining_indices, key=lambda idx: np.sum(dist_matrix[idx]))
385
- # Assign colors starting with the most distant points in proximity order
370
+ # Step 1: Sort indices by centroid proximity (based on sum of distances to others)
371
+ proximity_order = sorted(
372
+ range(num_colors_to_generate), key=lambda idx: np.sum(dist_matrix[idx])
373
+ )
374
+ # Step 2: Assign colors starting with the most distant points in proximity order
386
375
  for i, idx in enumerate(proximity_order):
387
376
  color_positions[idx] = i / num_colors_to_generate
388
377
 
389
- # Adjust colors so that centroids close to one another are maximally distant on the color spectrum
378
+ # Step 3: Adjust colors so that centroids close to one another are maximally distant on the color spectrum
390
379
  half_spectrum = int(num_colors_to_generate / 2)
391
380
  for i in range(half_spectrum):
392
381
  # Split the spectrum so that close centroids are assigned distant colors
risk/risk.py CHANGED
@@ -315,7 +315,7 @@ class RISK(NetworkIO, AnnotationsIO):
315
315
  max_cluster_size=max_cluster_size,
316
316
  )
317
317
 
318
- print_header(f"Optimizing distance threshold for domains")
318
+ print_header("Optimizing distance threshold for domains")
319
319
  # Define domains in the network using the specified clustering settings
320
320
  domains = self._define_domains(
321
321
  neighborhoods=processed_neighborhoods,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.7b3
3
+ Version: 0.0.7b4
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,6 +1,6 @@
1
- risk/__init__.py,sha256=Yoz9l74qVwPoFeWtUKqy_dgQZlDTZtaNIvtmzNx5G78,112
1
+ risk/__init__.py,sha256=yg0YESPRjq_Td8aQO5G_h7ennsyEeHumimLbCYxX-ts,112
2
2
  risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
3
- risk/risk.py,sha256=jhfOv60iZdOssCF35tAjJ_br9w8aIqPFT2owVTehgtA,20648
3
+ risk/risk.py,sha256=WQKPvUO4J2oYVDytn2C8w0lSFmLBzlhsKjfjWrjDt2Y,20647
4
4
  risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
5
5
  risk/annotations/annotations.py,sha256=K7cUA6vYTKYAvj0xHqrAwNEYtmPq4H7LDYENAOVQdQ0,11014
6
6
  risk/annotations/io.py,sha256=lo7NKqOVkeeBp58JBxWJHtA0xjL5Yoxqe9Ox0daKlZk,9457
@@ -10,10 +10,10 @@ risk/log/params.py,sha256=Rfdg5UcGCrG80m6V79FyORERWUqIzHFO7tGiY4zAImM,6347
10
10
  risk/neighborhoods/__init__.py,sha256=tKKEg4lsbqFukpgYlUGxU_v_9FOqK7V0uvM9T2QzoL0,206
11
11
  risk/neighborhoods/community.py,sha256=7ebo1Q5KokSQISnxZIh2SQxsKXdXm8aVkp-h_DiQ3K0,6818
12
12
  risk/neighborhoods/domains.py,sha256=bxJUxqFTynzX0mf3E8-AA4_Rfccje1reeVVhfzb1-pE,10672
13
- risk/neighborhoods/neighborhoods.py,sha256=cEk4gDvIkBky5POZhtHnO78iV-NXu4BeV-e5XdhYOkM,17508
13
+ risk/neighborhoods/neighborhoods.py,sha256=N02r2nnCfDtzVicuUt2WA77EUPHtruqjX8qJmXUP7ik,17475
14
14
  risk/network/__init__.py,sha256=iEPeJdZfqp0toxtbElryB8jbz9_t_k4QQ3iDvKE8C_0,126
15
15
  risk/network/geometry.py,sha256=H1yGVVqgbfpzBzJwEheDLfvGLSA284jGQQTn612L4Vc,6759
16
- risk/network/graph.py,sha256=_ZCyT2b9RtKAYzwul-Kp9__uQwTcagECf-mPMiAmP8U,16977
16
+ risk/network/graph.py,sha256=_LEoom4EEowGALuJKSXcev9RAAHu2FqIeq3u7mkifW0,16479
17
17
  risk/network/io.py,sha256=gG50kOknO-D3HkW1HsbHMkTMvjUtn3l4W4Jwd-rXNr8,21202
18
18
  risk/network/plot.py,sha256=F6KPjmBYWrThKZScHs9SuzoKQiytBvzrmGhGberHjwo,62063
19
19
  risk/stats/__init__.py,sha256=e-BE_Dr_jgiK6hKM-T-tlG4yvHnId8e5qjnM0pdwNVc,230
@@ -23,8 +23,8 @@ risk/stats/stats.py,sha256=kvShov-94W6ffgDUTb522vB9hDJQSyTsYif_UIaFfSM,7059
23
23
  risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
24
24
  risk/stats/permutation/permutation.py,sha256=qLWdwxEY6nmkYPxpM8HLDcd2mbqYv9Qr7CKtJvhLqIM,9220
25
25
  risk/stats/permutation/test_functions.py,sha256=HuDIM-V1jkkfE1rlaIqrWWBSKZt3dQ1f-YEDjWpnLSE,2343
26
- risk_network-0.0.7b3.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
- risk_network-0.0.7b3.dist-info/METADATA,sha256=6D_1SuZdpPYaUQLLzctNrVLC_gdzsTrx7V1leqBvcio,43142
28
- risk_network-0.0.7b3.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
- risk_network-0.0.7b3.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
- risk_network-0.0.7b3.dist-info/RECORD,,
26
+ risk_network-0.0.7b4.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
+ risk_network-0.0.7b4.dist-info/METADATA,sha256=vWM06f64mDBpDM6rcbI3rP0SCAz0gbcBZPj8OCVbHjo,43142
28
+ risk_network-0.0.7b4.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
+ risk_network-0.0.7b4.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
+ risk_network-0.0.7b4.dist-info/RECORD,,