risk-network 0.0.8b13__py3-none-any.whl → 0.0.8b15__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.8-beta.13"
10
+ __version__ = "0.0.8-beta.15"
risk/network/graph.py CHANGED
@@ -203,7 +203,8 @@ def _transform_colors(
203
203
  max_scale: float = 1.0,
204
204
  scale_factor: float = 1.0,
205
205
  ) -> np.ndarray:
206
- """Transform colors using power scaling to emphasize high enrichment sums more.
206
+ """Transform colors using power scaling to emphasize high enrichment sums more. Black colors are replaced with
207
+ very dark grey to avoid issues with color scaling (rgb(0.1, 0.1, 0.1)).
207
208
 
208
209
  Args:
209
210
  colors (np.ndarray): An array of RGBA colors.
@@ -34,7 +34,7 @@ class Labels:
34
34
  scale: float = 1.05,
35
35
  offset: float = 0.10,
36
36
  font: str = "Arial",
37
- fontcase: Union[str, None] = None,
37
+ fontcase: Union[str, Dict[str, str], None] = None,
38
38
  fontsize: int = 10,
39
39
  fontcolor: Union[str, List, Tuple, np.ndarray] = "black",
40
40
  fontalpha: Union[float, None] = 1.0,
@@ -60,8 +60,10 @@ class Labels:
60
60
  scale (float, optional): Scale factor for positioning labels around the perimeter. Defaults to 1.05.
61
61
  offset (float, optional): Offset distance for labels from the perimeter. Defaults to 0.10.
62
62
  font (str, optional): Font name for the labels. Defaults to "Arial".
63
- fontcase (str, None, optional): Case transformation for the labels. Can be "capitalize", "lower", "title",
64
- "upper", or None. Defaults to None.
63
+ fontcase (Union[str, Dict[str, str], None]): Defines how to transform the case of words.
64
+ - If a string (e.g., 'upper', 'lower', 'title'), applies the transformation to all words.
65
+ - If a dictionary, maps specific cases ('lower', 'upper', 'title') to transformations (e.g., 'lower'='upper').
66
+ - If None, no transformation is applied.
65
67
  fontsize (int, optional): Font size for the labels. Defaults to 10.
66
68
  fontcolor (str, list, tuple, or np.ndarray, optional): Color of the label text. Can be a string or RGBA array.
67
69
  Defaults to "black".
@@ -855,23 +857,43 @@ def _swap_and_evaluate(
855
857
  return _calculate_total_distance(swapped_positions, domain_centroids)
856
858
 
857
859
 
858
- def _apply_str_transformation(words: List[str], transformation: str) -> List[str]:
860
+ def _apply_str_transformation(
861
+ words: List[str], transformation: Union[str, Dict[str, str]]
862
+ ) -> List[str]:
859
863
  """Apply a user-specified case transformation to each word in the list without appending duplicates.
860
864
 
861
865
  Args:
862
866
  words (List[str]): A list of words to transform.
863
- transformation (str): The case transformation to apply (e.g., 'lower', 'upper', 'title', 'capitalize').
867
+ transformation (Union[str, Dict[str, str]]): A single transformation (e.g., 'lower', 'upper', 'title', 'capitalize')
868
+ or a dictionary mapping cases ('lower', 'upper', 'title') to transformations (e.g., 'lower'='upper').
864
869
 
865
870
  Returns:
866
871
  List[str]: A list of transformed words with no duplicates.
867
872
  """
868
873
  transformed_words = []
869
874
  for word in words:
870
- if hasattr(word, transformation):
871
- transformed_word = getattr(word, transformation)() # Apply the string method
872
-
873
- # Only append if the transformed word is not already in the list
874
- if transformed_word not in transformed_words:
875
- transformed_words.append(transformed_word)
875
+ # Convert the word to a string if it is not already
876
+ word = str(word)
877
+ transformed_word = word # Start with the original word
878
+ # If transformation is a string, apply it to all words
879
+ if isinstance(transformation, str):
880
+ if hasattr(word, transformation):
881
+ transformed_word = getattr(
882
+ word, transformation
883
+ )() # Apply the single transformation
884
+
885
+ # If transformation is a dictionary, apply case-specific transformations
886
+ elif isinstance(transformation, dict):
887
+ for case_type, transform in transformation.items():
888
+ if case_type == "lower" and word.islower() and transform:
889
+ transformed_word = getattr(word, transform)()
890
+ elif case_type == "upper" and word.isupper() and transform:
891
+ transformed_word = getattr(word, transform)()
892
+ elif case_type == "title" and word.istitle() and transform:
893
+ transformed_word = getattr(word, transform)()
894
+
895
+ # Only append if the transformed word is not already in the list
896
+ if transformed_word not in transformed_words:
897
+ transformed_words.append(transformed_word)
876
898
 
877
899
  return transformed_words
@@ -234,22 +234,18 @@ class Network:
234
234
  network_colors[:, 3] = alpha # Apply the alpha value to the enriched nodes' A channel
235
235
  # Convert the non-enriched color to RGBA using the to_rgba helper function
236
236
  nonenriched_color = to_rgba(color=nonenriched_color, alpha=nonenriched_alpha)
237
-
238
- # Compute the sum of RGB values for each color (ignoring alpha)
239
- color_sums = network_colors[:, :3].sum(axis=1)
240
- # Find the index of the darkest color (the lowest sum of RGB values)
241
- darkest_color_index = np.argmin(color_sums)
242
- # Extract the darkest color's RGB values
243
- darkest_color = network_colors[darkest_color_index, :3]
244
- # Adjust node colors: replace the darkest color with the non-enriched color
237
+ # Adjust node colors: replace any nodes where all three RGB values are equal and less than 0.1
238
+ # 0.1 is a predefined threshold for the minimum color intensity
245
239
  adjusted_network_colors = np.where(
246
- np.all(
247
- network_colors[:, :3] == darkest_color, axis=1, keepdims=True
248
- ), # Check if the color matches the darkest color
249
- np.array(nonenriched_color), # Apply the non-enriched color with alpha
250
- network_colors, # Keep the original colors for enriched nodes
240
+ (
241
+ np.all(network_colors[:, :3] < 0.1, axis=1)
242
+ & np.all(network_colors[:, :3] == network_colors[:, 0:1], axis=1)
243
+ )[:, None],
244
+ np.tile(
245
+ np.array(nonenriched_color), (network_colors.shape[0], 1)
246
+ ), # Replace with the full RGBA non-enriched color
247
+ network_colors, # Keep the original colors where no match is found
251
248
  )
252
-
253
249
  return adjusted_network_colors
254
250
 
255
251
  def get_annotated_node_sizes(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.8b13
3
+ Version: 0.0.8b15
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=NFLV6xDRDZaq7QKj28pf0H3eQA2SphZ1FXgsKXfGbkk,113
1
+ risk/__init__.py,sha256=IvvDrNrYMIFlFEmfZ6J1gTBoHqc33MwADdxoLjnyZg4,113
2
2
  risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
3
3
  risk/risk.py,sha256=slJXca_a726_D7oXwe765HaKTv3ZrOvhttyrWdCGPkA,21231
4
4
  risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
@@ -13,13 +13,13 @@ risk/neighborhoods/domains.py,sha256=D5MUIghbwyKKCAE8PN_HXvsO9NxLTGejQmyEqetD1Bk
13
13
  risk/neighborhoods/neighborhoods.py,sha256=M-wL4xB_BUTlSZg90swygO5NdrZ6hFUFqs6jsiZaqHk,18260
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=yuWqXG4p3Pmad_7dHcPweLgOd8t4LoeP9uQQ-ZZEdAY,16866
16
+ risk/network/graph.py,sha256=WxWh1BZvH9E_kgDb5HrwcQ-30hM8aNHPkBm2l3vzkAw,16973
17
17
  risk/network/io.py,sha256=u0PPcKjp6Xze--7eDOlvalYkjQ9S2sjiC-ac2476PUI,22942
18
18
  risk/network/plot/__init__.py,sha256=MfmaXJgAZJgXZ2wrhK8pXwzETlcMaLChhWXKAozniAo,98
19
19
  risk/network/plot/canvas.py,sha256=LXHndwanWIBShChoPag8zgGHF2P9MFWYdEnLKc2eeb0,10295
20
20
  risk/network/plot/contour.py,sha256=YPG8Uz0VlJ4skLdGaTH_FmQN6A_ArK8XSTNo1LzkSws,14276
21
- risk/network/plot/labels.py,sha256=PV21hig6gQJZRgfUAP9-zpn4wEmQFEjS2_X63SgzWMs,42064
22
- risk/network/plot/network.py,sha256=iikZpPKFxeIJgAlp0Wd6kXVzVp341wHpvQ2vLFdQELw,13000
21
+ risk/network/plot/labels.py,sha256=MQqM6iJJW91JI_dHzaFRbkrjK0yxJc5WBhTc_ea7Unk,43371
22
+ risk/network/plot/network.py,sha256=t5eMh7mBJOh_Wa19aK8g_1zpL7maiXZAYw-TEFHxAVM,12819
23
23
  risk/network/plot/plotter.py,sha256=rQV4Db6Ud86FJm11uaBvgSuzpmGsrZxnsRnUKjg6w84,5572
24
24
  risk/network/plot/utils.py,sha256=jZgI8EysSjviQmdYAceZk2MwJXcdeFAkYp-odZNqV0k,6316
25
25
  risk/stats/__init__.py,sha256=WcgoETQ-hS0LQqKRsAMIPtP15xZ-4eul6VUBuUx4Wzc,220
@@ -29,8 +29,8 @@ risk/stats/stats.py,sha256=kvShov-94W6ffgDUTb522vB9hDJQSyTsYif_UIaFfSM,7059
29
29
  risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
30
30
  risk/stats/permutation/permutation.py,sha256=D84Rcpt6iTQniK0PfQGcw9bLcHbMt9p-ARcurUnIXZQ,10095
31
31
  risk/stats/permutation/test_functions.py,sha256=lftOude6hee0pyR80HlBD32522JkDoN5hrKQ9VEbuoY,2345
32
- risk_network-0.0.8b13.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
33
- risk_network-0.0.8b13.dist-info/METADATA,sha256=_Fn1n_WLyoZ8NTHq_bfr3tnx9_16CXcmvyWWrclNNFY,47498
34
- risk_network-0.0.8b13.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
35
- risk_network-0.0.8b13.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
36
- risk_network-0.0.8b13.dist-info/RECORD,,
32
+ risk_network-0.0.8b15.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
33
+ risk_network-0.0.8b15.dist-info/METADATA,sha256=4hN4nT8j1a52ghqyJQ0mhjaVuhw2mt3EgKMAjpYTagY,47498
34
+ risk_network-0.0.8b15.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
35
+ risk_network-0.0.8b15.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
36
+ risk_network-0.0.8b15.dist-info/RECORD,,