risk-network 0.0.5b4__py3-none-any.whl → 0.0.5b5__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.5-beta.4"
10
+ __version__ = "0.0.5-beta.5"
@@ -207,7 +207,7 @@ def _simplify_word_list(words: List[str], threshold: float = 0.80) -> List[str]:
207
207
  similar_words = [
208
208
  other_word
209
209
  for other_word in word_counts
210
- if _jaccard_index(word_set, set(other_word)) >= threshold
210
+ if _calculate_jaccard_index(word_set, set(other_word)) >= threshold
211
211
  ]
212
212
  # Sort by frequency and choose the most frequent word
213
213
  similar_words.sort(key=lambda w: word_counts[w], reverse=True)
@@ -220,7 +220,7 @@ def _simplify_word_list(words: List[str], threshold: float = 0.80) -> List[str]:
220
220
  return final_words
221
221
 
222
222
 
223
- def _jaccard_index(set1: Set[Any], set2: Set[Any]) -> float:
223
+ def _calculate_jaccard_index(set1: Set[Any], set2: Set[Any]) -> float:
224
224
  """Calculate the Jaccard Index of two sets.
225
225
 
226
226
  Args:
risk/network/graph.py CHANGED
@@ -5,7 +5,7 @@ risk/network/graph
5
5
 
6
6
  import random
7
7
  from collections import defaultdict
8
- from typing import Any, Dict, List, Tuple
8
+ from typing import Any, Dict, List, Tuple, Union
9
9
 
10
10
  import networkx as nx
11
11
  import numpy as np
@@ -100,7 +100,12 @@ class NetworkGraph:
100
100
  self.node_coordinates = _extract_node_coordinates(G_2d)
101
101
 
102
102
  def get_domain_colors(
103
- self, min_scale: float = 0.8, max_scale: float = 1.0, random_seed: int = 888, **kwargs
103
+ self,
104
+ min_scale: float = 0.8,
105
+ max_scale: float = 1.0,
106
+ scale_factor: float = 1.0,
107
+ random_seed: int = 888,
108
+ **kwargs,
104
109
  ) -> np.ndarray:
105
110
  """Generate composite colors for domains.
106
111
 
@@ -111,6 +116,8 @@ class NetworkGraph:
111
116
  Args:
112
117
  min_scale (float, optional): Minimum scale for color intensity. Defaults to 0.8.
113
118
  max_scale (float, optional): Maximum scale for color intensity. Defaults to 1.0.
119
+ scale_factor (float, optional): Exponent for scaling, where values > 1 increase contrast by dimming small
120
+ values more. Defaults to 1.0.
114
121
  random_seed (int, optional): Seed for random number generation. Defaults to 888.
115
122
  **kwargs: Additional keyword arguments for color generation.
116
123
 
@@ -118,7 +125,7 @@ class NetworkGraph:
118
125
  np.ndarray: Array of transformed colors.
119
126
  """
120
127
  # Get colors for each domain
121
- domain_colors = self._get_domain_colors(**kwargs, random_seed=random_seed)
128
+ domain_colors = self._get_domain_colors(random_seed=random_seed)
122
129
  # Generate composite colors for nodes
123
130
  node_colors = self._get_composite_node_colors(domain_colors)
124
131
  # Transform colors to ensure proper alpha values and intensity
@@ -127,6 +134,7 @@ class NetworkGraph:
127
134
  self.node_enrichment_sums,
128
135
  min_scale=min_scale,
129
136
  max_scale=max_scale,
137
+ scale_factor=scale_factor,
130
138
  )
131
139
 
132
140
  return transformed_colors
@@ -152,9 +160,15 @@ class NetworkGraph:
152
160
 
153
161
  return composite_colors
154
162
 
155
- def _get_domain_colors(self, **kwargs) -> Dict[str, Any]:
163
+ def _get_domain_colors(
164
+ self, color: Union[str, None] = None, random_seed: int = 888
165
+ ) -> Dict[str, Any]:
156
166
  """Get colors for each domain.
157
167
 
168
+ Args:
169
+ color (Union[str, None], optional): Specific color to use for all domains. If specified, it will overwrite the colormap.
170
+ random_seed (int, optional): Seed for random number generation. Defaults to 888.
171
+
158
172
  Returns:
159
173
  dict: A dictionary mapping domain keys to their corresponding RGBA colors.
160
174
  """
@@ -163,20 +177,28 @@ class NetworkGraph:
163
177
  col for col in self.domains.columns if isinstance(col, (int, np.integer))
164
178
  ]
165
179
  domains = np.sort(numeric_domains)
166
- domain_colors = _get_colors(**kwargs, num_colors_to_generate=len(domains))
180
+ domain_colors = _get_colors(
181
+ num_colors_to_generate=len(domains), color=color, random_seed=random_seed
182
+ )
167
183
  return dict(zip(self.domain_to_nodes.keys(), domain_colors))
168
184
 
169
185
 
170
186
  def _transform_colors(
171
- colors: np.ndarray, enrichment_sums: np.ndarray, min_scale: float = 0.8, max_scale: float = 1.0
187
+ colors: np.ndarray,
188
+ enrichment_sums: np.ndarray,
189
+ min_scale: float = 0.8,
190
+ max_scale: float = 1.0,
191
+ scale_factor: float = 1.0,
172
192
  ) -> np.ndarray:
173
- """Transform colors to ensure proper alpha values and intensity based on enrichment sums.
193
+ """Transform colors using power scaling to emphasize high enrichment sums more.
174
194
 
175
195
  Args:
176
196
  colors (np.ndarray): An array of RGBA colors.
177
197
  enrichment_sums (np.ndarray): An array of enrichment sums corresponding to the colors.
178
198
  min_scale (float, optional): Minimum scale for color intensity. Defaults to 0.8.
179
199
  max_scale (float, optional): Maximum scale for color intensity. Defaults to 1.0.
200
+ scale_factor (float, optional): Exponent for scaling, where values > 1 increase contrast by dimming small
201
+ values more. Defaults to 1.0.
180
202
 
181
203
  Returns:
182
204
  np.ndarray: The transformed array of RGBA colors with adjusted intensities.
@@ -184,11 +206,12 @@ def _transform_colors(
184
206
  if min_scale == max_scale:
185
207
  min_scale = max_scale - 10e-6 # Avoid division by zero
186
208
 
187
- log_enrichment_sums = np.log1p(enrichment_sums) # Use log1p to avoid log(0)
188
- # Normalize the capped enrichment sums to the range [0, 1]
189
- normalized_sums = log_enrichment_sums / np.max(log_enrichment_sums)
190
- # Scale normalized sums to the specified color range [min_scale, max_scale]
191
- scaled_sums = min_scale + (max_scale - min_scale) * normalized_sums
209
+ # Normalize the enrichment sums to the range [0, 1]
210
+ normalized_sums = enrichment_sums / np.max(enrichment_sums)
211
+ # Apply power scaling to dim lower values and emphasize higher values
212
+ scaled_sums = normalized_sums**scale_factor
213
+ # Linearly scale the normalized sums to the range [min_scale, max_scale]
214
+ scaled_sums = min_scale + (max_scale - min_scale) * scaled_sums
192
215
  # Adjust RGB values based on scaled sums
193
216
  for i in range(3): # Only adjust RGB values
194
217
  colors[:, i] = scaled_sums * colors[:, i]
@@ -249,7 +272,10 @@ def _extract_node_coordinates(G: nx.Graph) -> np.ndarray:
249
272
 
250
273
 
251
274
  def _get_colors(
252
- num_colors_to_generate: int = 10, cmap: str = "hsv", random_seed: int = 888, **kwargs
275
+ num_colors_to_generate: int = 10,
276
+ cmap: str = "hsv",
277
+ random_seed: int = 888,
278
+ color: Union[str, None] = None,
253
279
  ) -> List[Tuple]:
254
280
  """Generate a list of RGBA colors from a specified colormap or use a direct color string.
255
281
 
@@ -257,16 +283,17 @@ def _get_colors(
257
283
  num_colors_to_generate (int): The number of colors to generate. Defaults to 10.
258
284
  cmap (str): The name of the colormap to use. Defaults to "hsv".
259
285
  random_seed (int): Seed for random number generation. Defaults to 888.
260
- **kwargs: Additional keyword arguments, such as 'color' for a specific color.
286
+ color (str, optional): Specific color to use for all nodes. If specified, it will overwrite the colormap.
287
+ Defaults to None.
261
288
 
262
289
  Returns:
263
290
  list of tuple: List of RGBA colors.
264
291
  """
265
292
  # Set random seed for reproducibility
266
293
  random.seed(random_seed)
267
- if kwargs.get("color"):
268
- # If a direct color string is provided, generate a list with that color
269
- rgba = matplotlib.colors.to_rgba(kwargs["color"])
294
+ if color:
295
+ # If a direct color is provided, generate a list with that color
296
+ rgba = matplotlib.colors.to_rgba(color)
270
297
  rgbas = [rgba] * num_colors_to_generate
271
298
  else:
272
299
  colormap = matplotlib.colormaps.get_cmap(cmap)
risk/network/plot.py CHANGED
@@ -512,7 +512,7 @@ class NetworkPlotter:
512
512
  self.graph.node_coordinates, radius_margin=perimeter_scale
513
513
  )
514
514
  # Calculate the best positions for labels around the perimeter
515
- best_label_positions = _best_label_positions(
515
+ best_label_positions = _calculate_best_label_positions(
516
516
  filtered_domain_centroids, center, radius, offset
517
517
  )
518
518
  # Annotate the network with labels - valid_indices is used for fontcolor and arrow_color
@@ -795,7 +795,7 @@ def _calculate_bounding_box(
795
795
  return center, radius
796
796
 
797
797
 
798
- def _best_label_positions(
798
+ def _calculate_best_label_positions(
799
799
  filtered_domain_centroids: Dict[str, Any], center: np.ndarray, radius: float, offset: float
800
800
  ) -> Dict[str, Any]:
801
801
  """Calculate and optimize label positions for clarity.
@@ -811,7 +811,9 @@ def _best_label_positions(
811
811
  """
812
812
  num_domains = len(filtered_domain_centroids)
813
813
  # Calculate equidistant positions around the center for initial label placement
814
- equidistant_positions = _equidistant_angles_around_center(center, radius, offset, num_domains)
814
+ equidistant_positions = _calculate_equidistant_positions_around_center(
815
+ center, radius, offset, num_domains
816
+ )
815
817
  # Create a mapping of domains to their initial label positions
816
818
  label_positions = {
817
819
  domain: position
@@ -821,7 +823,7 @@ def _best_label_positions(
821
823
  return _optimize_label_positions(label_positions, filtered_domain_centroids)
822
824
 
823
825
 
824
- def _equidistant_angles_around_center(
826
+ def _calculate_equidistant_positions_around_center(
825
827
  center: np.ndarray, radius: float, label_offset: float, num_domains: int
826
828
  ) -> List[np.ndarray]:
827
829
  """Calculate positions around a center at equidistant angles.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.5b4
3
+ Version: 0.0.5b5
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,8 +1,8 @@
1
- risk/__init__.py,sha256=bzj1Zn2Vm3Nh5mYk1ZoFg3njX6gjTO8aKOI6Zi_6JuE,112
1
+ risk/__init__.py,sha256=zGjRj03AbzDx0VGLJyR7TPzNLA1XQ5eLF7gbAKK507o,112
2
2
  risk/constants.py,sha256=AICk3x5qRQhls_ijTb4VdbdxU6mZ1aLGbAjLEdBwfJI,550
3
3
  risk/risk.py,sha256=UYM_Pf2Db-lbf4O5T2v5zKutz_GLXK-f43PgYT6xRyY,21328
4
4
  risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
5
- risk/annotations/annotations.py,sha256=t4aLwROCFHcqk8g-viuwkFG--HqVpVN_2yVVcjhg6wI,10534
5
+ risk/annotations/annotations.py,sha256=DRUTdGzMdqo62NWSapBUksbvPr9CrzD76qtOcxeNKmo,10554
6
6
  risk/annotations/io.py,sha256=TMicRACfY8bNtmbvVrxHoh8zkOVLOIhZwWrpxUlR28Q,7988
7
7
  risk/log/__init__.py,sha256=xuLImfxFlKpnVhzi_gDYlr2_c9cLkrw2c_3iEsXb1as,107
8
8
  risk/log/console.py,sha256=im9DRExwf6wHlcn9fewoDcKIpo3vPcorZIaNAl-0csY,355
@@ -13,9 +13,9 @@ risk/neighborhoods/domains.py,sha256=HwuChmZH0RGD9eQOvk2-ezQDJRUHHn93vhVgHb-kX6I
13
13
  risk/neighborhoods/neighborhoods.py,sha256=SqYJaT49rUj77ts0XsPXb9cURM11aGh2Teks0nBH_4s,13939
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=F_SY7nZev6XZuHwkJnVdeow-oMSmR4u8AUiFCrh6yvk,11543
16
+ risk/network/graph.py,sha256=DTjNRQwgQbt6jJYDBHm7sgrdbZUDLL4HiZpdixkSI7Y,12433
17
17
  risk/network/io.py,sha256=otiRG6uT6HLgbbJql7X2wjYxab8OFJSgRoWJlcDoyu4,20291
18
- risk/network/plot.py,sha256=Ti0nT49NffoQc9qjXOclEFBRuuN_4LLntpBZn3cp5Fo,40882
18
+ risk/network/plot.py,sha256=rg4pB0sndOnoayeNZSu4sU3sQ2P8x9ksE4XRTRP2HPM,40942
19
19
  risk/stats/__init__.py,sha256=e-BE_Dr_jgiK6hKM-T-tlG4yvHnId8e5qjnM0pdwNVc,230
20
20
  risk/stats/fisher_exact.py,sha256=-bPwzu76-ob0HzrTV20mXUTot7v-MLuqFaAoab-QxPg,4966
21
21
  risk/stats/hypergeom.py,sha256=lrIFdhCWRjvM4apYw1MlOKqT_IY5OjtCwrjdtJdt6Tg,4954
@@ -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.5b4.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
- risk_network-0.0.5b4.dist-info/METADATA,sha256=tSh6tuMzdhFwIJ4XzzccgnONtulZDNCfLkHEAV7XtSI,43236
28
- risk_network-0.0.5b4.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
29
- risk_network-0.0.5b4.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
- risk_network-0.0.5b4.dist-info/RECORD,,
26
+ risk_network-0.0.5b5.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
+ risk_network-0.0.5b5.dist-info/METADATA,sha256=qSRqHP8c46IzvZU--rO7eUeir3LErWx98mPIbh0Q_c4,43236
28
+ risk_network-0.0.5b5.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
29
+ risk_network-0.0.5b5.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
+ risk_network-0.0.5b5.dist-info/RECORD,,