risk-network 0.0.8b25__py3-none-any.whl → 0.0.8b27__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.25"
10
+ __version__ = "0.0.8-beta.27"
risk/log/__init__.py CHANGED
@@ -3,7 +3,7 @@ risk/log
3
3
  ~~~~~~~~
4
4
  """
5
5
 
6
- from .config import logger, log_header, set_global_verbosity
6
+ from .console import logger, log_header, set_global_verbosity
7
7
  from .params import Params
8
8
 
9
9
  params = Params()
@@ -1,6 +1,6 @@
1
1
  """
2
- risk/log/config
3
- ~~~~~~~~~~~~~~~
2
+ risk/log/console
3
+ ~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  import logging
risk/log/params.py CHANGED
@@ -12,7 +12,7 @@ from typing import Any, Dict
12
12
 
13
13
  import numpy as np
14
14
 
15
- from .config import logger, log_header
15
+ from .console import logger, log_header
16
16
 
17
17
  # Suppress all warnings - this is to resolve warnings from multiprocessing
18
18
  warnings.filterwarnings("ignore")
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
 
@@ -36,6 +36,7 @@ class Canvas:
36
36
  font: str = "Arial",
37
37
  title_color: Union[str, List, Tuple, np.ndarray] = "black",
38
38
  subtitle_color: Union[str, List, Tuple, np.ndarray] = "gray",
39
+ title_x: float = 0.5,
39
40
  title_y: float = 0.975,
40
41
  title_space_offset: float = 0.075,
41
42
  subtitle_offset: float = 0.025,
@@ -52,6 +53,7 @@ class Canvas:
52
53
  Defaults to "black".
53
54
  subtitle_color (str, List, Tuple, or np.ndarray, optional): Color of the subtitle text. Can be a string or an array of colors.
54
55
  Defaults to "gray".
56
+ title_x (float, optional): X-axis position of the title. Defaults to 0.5.
55
57
  title_y (float, optional): Y-axis position of the title. Defaults to 0.975.
56
58
  title_space_offset (float, optional): Fraction of figure height to leave for the space above the plot. Defaults to 0.075.
57
59
  subtitle_offset (float, optional): Offset factor to position the subtitle below the title. Defaults to 0.025.
@@ -85,7 +87,7 @@ class Canvas:
85
87
  fontsize=title_fontsize,
86
88
  color=title_color,
87
89
  fontname=font,
88
- x=0.5, # Center the title horizontally
90
+ x=title_x,
89
91
  ha="center",
90
92
  va="top",
91
93
  y=title_y,
@@ -112,6 +114,8 @@ class Canvas:
112
114
  def plot_circle_perimeter(
113
115
  self,
114
116
  scale: float = 1.0,
117
+ center_offset_x: float = 0.0,
118
+ center_offset_y: float = 0.0,
115
119
  linestyle: str = "dashed",
116
120
  linewidth: float = 1.5,
117
121
  color: Union[str, List, Tuple, np.ndarray] = "black",
@@ -122,6 +126,10 @@ class Canvas:
122
126
 
123
127
  Args:
124
128
  scale (float, optional): Scaling factor for the perimeter diameter. Defaults to 1.0.
129
+ center_offset_x (float, optional): Horizontal offset as a fraction of the diameter.
130
+ Negative values shift the center left, positive values shift it right. Defaults to 0.0.
131
+ center_offset_y (float, optional): Vertical offset as a fraction of the diameter.
132
+ Negative values shift the center down, positive values shift it up. Defaults to 0.0.
125
133
  linestyle (str, optional): Line style for the network perimeter circle (e.g., dashed, solid). Defaults to "dashed".
126
134
  linewidth (float, optional): Width of the circle's outline. Defaults to 1.5.
127
135
  color (str, List, Tuple, or np.ndarray, optional): Color of the network perimeter circle. Defaults to "black".
@@ -134,6 +142,8 @@ class Canvas:
134
142
  params.log_plotter(
135
143
  perimeter_type="circle",
136
144
  perimeter_scale=scale,
145
+ perimeter_center_offset_x=center_offset_x,
146
+ perimeter_center_offset_y=center_offset_y,
137
147
  perimeter_linestyle=linestyle,
138
148
  perimeter_linewidth=linewidth,
139
149
  perimeter_color=(
@@ -147,6 +157,10 @@ class Canvas:
147
157
  node_coordinates = self.graph.node_coordinates
148
158
  # Calculate the center and radius of the bounding box around the network
149
159
  center, radius = calculate_bounding_box(node_coordinates)
160
+ # Adjust the center based on user-defined offsets
161
+ adjusted_center = _calculate_adjusted_center(
162
+ center, radius, center_offset_x, center_offset_y
163
+ )
150
164
  # Scale the radius by the scale factor
151
165
  scaled_radius = radius * scale
152
166
 
@@ -160,7 +174,7 @@ class Canvas:
160
174
 
161
175
  # Draw a circle to represent the network perimeter
162
176
  circle = plt.Circle(
163
- center,
177
+ adjusted_center,
164
178
  scaled_radius,
165
179
  linestyle=linestyle,
166
180
  linewidth=linewidth,
@@ -234,3 +248,43 @@ class Canvas:
234
248
  linewidth=linewidth,
235
249
  fill_alpha=fill_alpha,
236
250
  )
251
+
252
+
253
+ def _calculate_adjusted_center(
254
+ center: Tuple[float, float],
255
+ radius: float,
256
+ center_offset_x: float = 0.0,
257
+ center_offset_y: float = 0.0,
258
+ ) -> Tuple[float, float]:
259
+ """Calculate the adjusted center for the network perimeter circle based on user-defined offsets.
260
+
261
+ Args:
262
+ center (Tuple[float, float]): Original center coordinates of the network graph.
263
+ radius (float): Radius of the bounding box around the network.
264
+ center_offset_x (float, optional): Horizontal offset as a fraction of the diameter.
265
+ Negative values shift the center left, positive values shift it right. Allowed
266
+ values are in the range [-1, 1]. Defaults to 0.0.
267
+ center_offset_y (float, optional): Vertical offset as a fraction of the diameter.
268
+ Negative values shift the center down, positive values shift it up. Allowed
269
+ values are in the range [-1, 1]. Defaults to 0.0.
270
+
271
+ Returns:
272
+ Tuple[float, float]: Adjusted center coordinates after applying the offsets.
273
+
274
+ Raises:
275
+ ValueError: If the center offsets are outside the valid range [-1, 1].
276
+ """
277
+ # Flip the y-axis to match the plot orientation
278
+ flipped_center_offset_y = -center_offset_y
279
+ # Validate the center offsets
280
+ if not -1 <= center_offset_x <= 1:
281
+ raise ValueError("Horizontal center offset must be in the range [-1, 1].")
282
+ if not -1 <= center_offset_y <= 1:
283
+ raise ValueError("Vertical center offset must be in the range [-1, 1].")
284
+
285
+ # Calculate adjusted center by applying offset fractions of the diameter
286
+ adjusted_center_x = center[0] + (center_offset_x * radius * 2)
287
+ adjusted_center_y = center[1] + (flipped_center_offset_y * radius * 2)
288
+
289
+ # Return the adjusted center coordinates
290
+ 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
@@ -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.8b25
3
+ Version: 0.0.8b27
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,24 +1,24 @@
1
- risk/__init__.py,sha256=Qyc4qWblCngk-E90hZv6DYKLI0-FV0bvyLCGHF1TvgA,113
1
+ risk/__init__.py,sha256=ac92cxvpV3NMnUqcZb1WHPrNCiY2Du_Nl1UOytIwoyg,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
7
- risk/log/__init__.py,sha256=aDUz5LMFQsz0UlsQI2EdXtiBKRLfml1UMeZKC7QQIGU,134
8
- risk/log/config.py,sha256=m8pzj-hN4vI_2JdJUfyOoSvzT8_lhoIfBt27sKbnOes,4535
9
- risk/log/params.py,sha256=rvyg86RnkHwotST7x42RgsiYfq2HB-9BZxp6KkT_04o,6415
7
+ risk/log/__init__.py,sha256=xKeU9uK1AnVk7Yt9GTp-E-dn7Ealow2igEXZZnQRa2c,135
8
+ risk/log/console.py,sha256=C52s3FgQ2e9kQWcXL8m7rs_pnKXt5Yy8PBHmQkOTiNo,4537
9
+ risk/log/params.py,sha256=qSTktJ3OazldTzgtDGZkh0s30vu5kiXPkiNGLdSFDvg,6416
10
10
  risk/neighborhoods/__init__.py,sha256=tKKEg4lsbqFukpgYlUGxU_v_9FOqK7V0uvM9T2QzoL0,206
11
11
  risk/neighborhoods/community.py,sha256=MAgIblbuisEPwVU6mFZd4Yd9NUKlaHK99suw51r1Is0,7065
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=TlCpNtvoceizAumNr9I02JcBrBO6FiAFAa2ZC0bx3SU,13356
20
20
  risk/network/plot/contour.py,sha256=CwX4i3uE5HL0W4kfx34U7YyoTTqMxyb7xaXKRVoNLzY,15265
21
- risk/network/plot/labels.py,sha256=1c7R3aXd_9jBqkvt70bvxqJOkZm4NGQzR_OxbHJcLfU,45171
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.8b25.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
34
- risk_network-0.0.8b25.dist-info/METADATA,sha256=4EgVGDOFG3aT9ruKe6oSuml4Fk2khMv4qcyXHJnSWKo,47498
35
- risk_network-0.0.8b25.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
36
- risk_network-0.0.8b25.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
37
- risk_network-0.0.8b25.dist-info/RECORD,,
33
+ risk_network-0.0.8b27.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
34
+ risk_network-0.0.8b27.dist-info/METADATA,sha256=7PXFvXkTlaMC7TB5B7P1ePXPwDPZqpXMeeKb_pVZL8o,47498
35
+ risk_network-0.0.8b27.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
36
+ risk_network-0.0.8b27.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
37
+ risk_network-0.0.8b27.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