risk-network 0.0.8b24__py3-none-any.whl → 0.0.8b26__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.24"
10
+ __version__ = "0.0.8-beta.26"
risk/network/geometry.py CHANGED
@@ -3,6 +3,8 @@ risk/network/geometry
3
3
  ~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
+ import copy
7
+
6
8
  import networkx as nx
7
9
  import numpy as np
8
10
 
@@ -55,10 +57,10 @@ def assign_edge_lengths(
55
57
  if compute_sphere:
56
58
  # Map to sphere and adjust depth
57
59
  _map_to_sphere(G)
58
- G_depth = _create_depth(G.copy(), surface_depth=surface_depth)
60
+ G_depth = _create_depth(copy.deepcopy(G), surface_depth=surface_depth)
59
61
  else:
60
62
  # Calculate edge lengths directly on the plane
61
- G_depth = G.copy()
63
+ G_depth = copy.deepcopy(G)
62
64
 
63
65
  for u, v, _ in G_depth.edges(data=True):
64
66
  u_coords = np.array([G_depth.nodes[u]["x"], G_depth.nodes[u]["y"]])
risk/network/io.py CHANGED
@@ -5,6 +5,7 @@ risk/network/io
5
5
  This file contains the code for the RISK class and command-line access.
6
6
  """
7
7
 
8
+ import copy
8
9
  import json
9
10
  import os
10
11
  import pickle
@@ -155,7 +156,7 @@ class NetworkIO:
155
156
  self._log_loading(filetype)
156
157
 
157
158
  # Important: Make a copy of the network to avoid modifying the original
158
- network_copy = network.copy()
159
+ network_copy = copy.deepcopy(network)
159
160
  # Initialize the graph
160
161
  return self._initialize_graph(network_copy)
161
162
 
@@ -112,6 +112,8 @@ class Canvas:
112
112
  def plot_circle_perimeter(
113
113
  self,
114
114
  scale: float = 1.0,
115
+ center_offset_x: float = 0.0,
116
+ center_offset_y: float = 0.0,
115
117
  linestyle: str = "dashed",
116
118
  linewidth: float = 1.5,
117
119
  color: Union[str, List, Tuple, np.ndarray] = "black",
@@ -122,6 +124,10 @@ class Canvas:
122
124
 
123
125
  Args:
124
126
  scale (float, optional): Scaling factor for the perimeter diameter. Defaults to 1.0.
127
+ center_offset_x (float, optional): Horizontal offset as a fraction of the diameter.
128
+ Negative values shift the center left, positive values shift it right. Defaults to 0.0.
129
+ center_offset_y (float, optional): Vertical offset as a fraction of the diameter.
130
+ Negative values shift the center down, positive values shift it up. Defaults to 0.0.
125
131
  linestyle (str, optional): Line style for the network perimeter circle (e.g., dashed, solid). Defaults to "dashed".
126
132
  linewidth (float, optional): Width of the circle's outline. Defaults to 1.5.
127
133
  color (str, List, Tuple, or np.ndarray, optional): Color of the network perimeter circle. Defaults to "black".
@@ -134,6 +140,8 @@ class Canvas:
134
140
  params.log_plotter(
135
141
  perimeter_type="circle",
136
142
  perimeter_scale=scale,
143
+ perimeter_center_offset_x=center_offset_x,
144
+ perimeter_center_offset_y=center_offset_y,
137
145
  perimeter_linestyle=linestyle,
138
146
  perimeter_linewidth=linewidth,
139
147
  perimeter_color=(
@@ -147,6 +155,10 @@ class Canvas:
147
155
  node_coordinates = self.graph.node_coordinates
148
156
  # Calculate the center and radius of the bounding box around the network
149
157
  center, radius = calculate_bounding_box(node_coordinates)
158
+ # Adjust the center based on user-defined offsets
159
+ adjusted_center = _calculate_adjusted_center(
160
+ center, radius, center_offset_x, center_offset_y
161
+ )
150
162
  # Scale the radius by the scale factor
151
163
  scaled_radius = radius * scale
152
164
 
@@ -160,7 +172,7 @@ class Canvas:
160
172
 
161
173
  # Draw a circle to represent the network perimeter
162
174
  circle = plt.Circle(
163
- center,
175
+ adjusted_center,
164
176
  scaled_radius,
165
177
  linestyle=linestyle,
166
178
  linewidth=linewidth,
@@ -234,3 +246,43 @@ class Canvas:
234
246
  linewidth=linewidth,
235
247
  fill_alpha=fill_alpha,
236
248
  )
249
+
250
+
251
+ def _calculate_adjusted_center(
252
+ center: Tuple[float, float],
253
+ radius: float,
254
+ center_offset_x: float = 0.0,
255
+ center_offset_y: float = 0.0,
256
+ ) -> Tuple[float, float]:
257
+ """Calculate the adjusted center for the network perimeter circle based on user-defined offsets.
258
+
259
+ Args:
260
+ center (Tuple[float, float]): Original center coordinates of the network graph.
261
+ radius (float): Radius of the bounding box around the network.
262
+ center_offset_x (float, optional): Horizontal offset as a fraction of the diameter.
263
+ Negative values shift the center left, positive values shift it right. Allowed
264
+ values are in the range [-1, 1]. Defaults to 0.0.
265
+ center_offset_y (float, optional): Vertical offset as a fraction of the diameter.
266
+ Negative values shift the center down, positive values shift it up. Allowed
267
+ values are in the range [-1, 1]. Defaults to 0.0.
268
+
269
+ Returns:
270
+ Tuple[float, float]: Adjusted center coordinates after applying the offsets.
271
+
272
+ Raises:
273
+ ValueError: If the center offsets are outside the valid range [-1, 1].
274
+ """
275
+ # Flip the y-axis to match the plot orientation
276
+ flipped_center_offset_y = -center_offset_y
277
+ # Validate the center offsets
278
+ if not -1 <= center_offset_x <= 1:
279
+ raise ValueError("Horizontal center offset must be in the range [-1, 1].")
280
+ if not -1 <= center_offset_y <= 1:
281
+ raise ValueError("Vertical center offset must be in the range [-1, 1].")
282
+
283
+ # Calculate adjusted center by applying offset fractions of the diameter
284
+ adjusted_center_x = center[0] + (center_offset_x * radius * 2)
285
+ adjusted_center_y = center[1] + (flipped_center_offset_y * radius * 2)
286
+
287
+ # Return the adjusted center coordinates
288
+ return adjusted_center_x, adjusted_center_y
@@ -3,6 +3,7 @@ risk/network/plot/labels
3
3
  ~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
+ import copy
6
7
  from typing import Any, Dict, List, Tuple, Union
7
8
 
8
9
  import matplotlib.pyplot as plt
@@ -616,7 +617,7 @@ class Labels:
616
617
  """
617
618
  # Return custom labels if domain is in ids_to_replace
618
619
  if ids_to_replace and domain in ids_to_replace:
619
- terms = ids_to_replace[domain].split(" ")
620
+ terms = ids_to_replace[domain].replace(" ", TERM_DELIMITER)
620
621
  return terms
621
622
 
622
623
  else:
@@ -723,12 +724,19 @@ def _combine_words(words: List[str], max_chars_per_line: int, max_label_lines: i
723
724
  # Main logic: start with max_label_lines number of words
724
725
  combined_lines = try_combinations(words[:max_label_lines])
725
726
  remaining_words = words[max_label_lines:] # Remaining words after the initial batch
727
+ # Track words that have already been added
728
+ existing_words = set(" ".join(combined_lines).split())
726
729
 
727
730
  # Continue pulling more words until we fill the lines
728
731
  while remaining_words and len(combined_lines) < max_label_lines:
729
732
  available_slots = max_label_lines - len(combined_lines)
730
- words_to_add = remaining_words[:available_slots]
733
+ words_to_add = [
734
+ word for word in remaining_words[:available_slots] if word not in existing_words
735
+ ]
731
736
  remaining_words = remaining_words[available_slots:]
737
+ # Update the existing words set
738
+ existing_words.update(words_to_add)
739
+ # Add to combined_lines only unique words
732
740
  combined_lines += try_combinations(words_to_add)
733
741
 
734
742
  # Join the final combined lines with TERM_DELIMITER, a special separator for line breaks
@@ -862,7 +870,7 @@ def _swap_and_evaluate(
862
870
  """
863
871
  # Get the list of labels from the dictionary keys
864
872
  labels = list(label_positions.keys())
865
- swapped_positions = label_positions.copy()
873
+ swapped_positions = copy.deepcopy(label_positions)
866
874
  # Swap the positions of the two specified labels
867
875
  swapped_positions[labels[i]], swapped_positions[labels[j]] = (
868
876
  swapped_positions[labels[j]],
risk/risk.py CHANGED
@@ -3,6 +3,7 @@ risk/risk
3
3
  ~~~~~~~~~
4
4
  """
5
5
 
6
+ import copy
6
7
  from typing import Any, Dict, List, Tuple, Union
7
8
 
8
9
  import networkx as nx
@@ -94,7 +95,7 @@ class RISK(NetworkIO, AnnotationsIO):
94
95
  )
95
96
 
96
97
  # Make a copy of the network to avoid modifying the original
97
- network = network.copy()
98
+ network = copy.deepcopy(network)
98
99
 
99
100
  # Load neighborhoods based on the network and distance metric
100
101
  neighborhoods = self._load_neighborhoods(
@@ -154,7 +155,7 @@ class RISK(NetworkIO, AnnotationsIO):
154
155
  )
155
156
 
156
157
  # Make a copy of the network to avoid modifying the original
157
- network = network.copy()
158
+ network = copy.deepcopy(network)
158
159
 
159
160
  # Load neighborhoods based on the network and distance metric
160
161
  neighborhoods = self._load_neighborhoods(
@@ -223,7 +224,7 @@ class RISK(NetworkIO, AnnotationsIO):
223
224
  )
224
225
 
225
226
  # Make a copy of the network to avoid modifying the original
226
- network = network.copy()
227
+ network = copy.deepcopy(network)
227
228
 
228
229
  # Load neighborhoods based on the network and distance metric
229
230
  neighborhoods = self._load_neighborhoods(
@@ -305,7 +306,7 @@ class RISK(NetworkIO, AnnotationsIO):
305
306
  )
306
307
 
307
308
  # Make a copy of the network to avoid modifying the original
308
- network = network.copy()
309
+ network = copy.deepcopy(network)
309
310
 
310
311
  logger.debug(f"p-value cutoff: {pval_cutoff}")
311
312
  logger.debug(f"FDR BH cutoff: {fdr_cutoff}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.8b24
3
+ Version: 0.0.8b26
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=cH9ocvJT5oWRV0qbQAG2O5ZSdpVcuvxbHoe8hT6DeJM,113
1
+ risk/__init__.py,sha256=alJKI-P75Y0Cm9xyrTe0zsvDhyqO_gh50ygLQvzp7hs,113
2
2
  risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
3
- risk/risk.py,sha256=7JERU-ZkDuESY3LJDyqEJGVs-YdYQwCt2SO3nHGYk0E,23809
3
+ risk/risk.py,sha256=8GTUpj3TC7XLwEUD22-fDTKXtW7PndzW9TixWaZ23bI,23853
4
4
  risk/annotations/__init__.py,sha256=kXgadEXaCh0z8OyhOhTj7c3qXGmWgOhaSZ4gSzSb59U,147
5
5
  risk/annotations/annotations.py,sha256=dHO6kQOQjMA57nYA-yTAU1uB-ieiZ5sknAKvX6vF0Os,13024
6
6
  risk/annotations/io.py,sha256=powWzeimVdE0WCwlBCXyu5otMyZZHQujC0DS3m5DC0c,9505
@@ -12,13 +12,13 @@ risk/neighborhoods/community.py,sha256=MAgIblbuisEPwVU6mFZd4Yd9NUKlaHK99suw51r1I
12
12
  risk/neighborhoods/domains.py,sha256=3iV0-nRLF2sL9_7epHY5b9AtTU-QQ84hOWO76VwFcrs,11685
13
13
  risk/neighborhoods/neighborhoods.py,sha256=cT9CCi1uQLn9Kv9Lxt8AN_4s63SKIlOZspvUZnx27nE,21832
14
14
  risk/network/__init__.py,sha256=iEPeJdZfqp0toxtbElryB8jbz9_t_k4QQ3iDvKE8C_0,126
15
- risk/network/geometry.py,sha256=Y3Brp0XYWoBL2VHJX7I-gW5x-q7lGiEMqr2kqtutgkQ,6811
15
+ risk/network/geometry.py,sha256=gFtYUj9j9aul4paKq_qSGJn39Nazxu_MXv8m-tYYtrk,6840
16
16
  risk/network/graph.py,sha256=-tslu8nSbuBaqNGf6TQ8ON7C27v-BLH_37J2aC6Ke14,9602
17
- risk/network/io.py,sha256=u0PPcKjp6Xze--7eDOlvalYkjQ9S2sjiC-ac2476PUI,22942
17
+ risk/network/io.py,sha256=-NJ9Tg1s-DxhlDbwQGO4o87rbMqO4-BzShgnIgFoRRE,22962
18
18
  risk/network/plot/__init__.py,sha256=MfmaXJgAZJgXZ2wrhK8pXwzETlcMaLChhWXKAozniAo,98
19
- risk/network/plot/canvas.py,sha256=ZO6bHw1chIsUqtE7IkPKdgX4tFLA-T5OwN5SojqGSNU,10672
19
+ risk/network/plot/canvas.py,sha256=0A3i4GNMfQcZc--cRlAHoq4tmnDzxbpnaCUFINF_Zro,13269
20
20
  risk/network/plot/contour.py,sha256=CwX4i3uE5HL0W4kfx34U7YyoTTqMxyb7xaXKRVoNLzY,15265
21
- risk/network/plot/labels.py,sha256=2XTL8jwqiGnkJYQizQDgUrjU8CPyjpwV3AapsG_Uqw4,45153
21
+ risk/network/plot/labels.py,sha256=fNccRds6seShMFPN6WX_7M1_qnscBkcWEH3QOJAKalk,45502
22
22
  risk/network/plot/network.py,sha256=6RURL1OdBFyQ34qNcwM_uH3LSQGYZZ8tZT51dggH1a0,13685
23
23
  risk/network/plot/plotter.py,sha256=iTPMiTnTTatM_-q1Ox_bjt5Pvv-Lo8gceiYB6TVzDcw,5770
24
24
  risk/network/plot/utils/color.py,sha256=WSs1ge2oZ8yXwyVk2QqBF-avRd0aYT-sYZr9cxxAn7M,19626
@@ -30,8 +30,8 @@ risk/stats/stats.py,sha256=6iGi0-oN05mTmupg6X_VEBxEQvi2rujNhfPk4aLjwNI,7186
30
30
  risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
31
31
  risk/stats/permutation/permutation.py,sha256=meBNSrbRa9P8WJ54n485l0H7VQJlMSfHqdN4aCKYCtQ,10105
32
32
  risk/stats/permutation/test_functions.py,sha256=lftOude6hee0pyR80HlBD32522JkDoN5hrKQ9VEbuoY,2345
33
- risk_network-0.0.8b24.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
34
- risk_network-0.0.8b24.dist-info/METADATA,sha256=YlQYQ6UuQrShoKaJtiryZKTj1_bPrqJQxYN7PAAlHj4,47498
35
- risk_network-0.0.8b24.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
36
- risk_network-0.0.8b24.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
37
- risk_network-0.0.8b24.dist-info/RECORD,,
33
+ risk_network-0.0.8b26.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
34
+ risk_network-0.0.8b26.dist-info/METADATA,sha256=5I2n-fHbP--XuLA-iW4xIzxPKJbNYu0ds3-xOGWEmhw,47498
35
+ risk_network-0.0.8b26.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
36
+ risk_network-0.0.8b26.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
37
+ risk_network-0.0.8b26.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.2.0)
2
+ Generator: setuptools (75.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5