risk-network 0.0.6b0__tar.gz → 0.0.6b2__tar.gz

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.
Files changed (37) hide show
  1. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/PKG-INFO +1 -1
  2. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/__init__.py +1 -1
  3. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/annotations/io.py +15 -3
  4. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/neighborhoods/community.py +7 -3
  5. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/neighborhoods/neighborhoods.py +2 -2
  6. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/network/graph.py +26 -21
  7. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/network/io.py +11 -0
  8. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/network/plot.py +430 -202
  9. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/risk.py +6 -18
  10. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk_network.egg-info/PKG-INFO +1 -1
  11. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/LICENSE +0 -0
  12. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/MANIFEST.in +0 -0
  13. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/README.md +0 -0
  14. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/pyproject.toml +0 -0
  15. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/annotations/__init__.py +0 -0
  16. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/annotations/annotations.py +0 -0
  17. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/constants.py +0 -0
  18. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/log/__init__.py +0 -0
  19. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/log/console.py +0 -0
  20. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/log/params.py +0 -0
  21. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/neighborhoods/__init__.py +0 -0
  22. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/neighborhoods/domains.py +0 -0
  23. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/network/__init__.py +0 -0
  24. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/network/geometry.py +0 -0
  25. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/stats/__init__.py +0 -0
  26. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/stats/fisher_exact.py +0 -0
  27. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/stats/hypergeom.py +0 -0
  28. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/stats/permutation/__init__.py +0 -0
  29. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/stats/permutation/permutation.py +0 -0
  30. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/stats/permutation/test_functions.py +0 -0
  31. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk/stats/stats.py +0 -0
  32. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk_network.egg-info/SOURCES.txt +0 -0
  33. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk_network.egg-info/dependency_links.txt +0 -0
  34. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk_network.egg-info/requires.txt +0 -0
  35. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/risk_network.egg-info/top_level.txt +0 -0
  36. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/setup.cfg +0 -0
  37. {risk_network-0.0.6b0 → risk_network-0.0.6b2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.6b0
3
+ Version: 0.0.6b2
4
4
  Summary: A Python package for biological network analysis
5
5
  Author: Ira Horecka
6
6
  Author-email: Ira Horecka <ira89@icloud.com>
@@ -7,4 +7,4 @@ RISK: RISK Infers Spatial Kinships
7
7
 
8
8
  from risk.risk import RISK
9
9
 
10
- __version__ = "0.0.6-beta.0"
10
+ __version__ = "0.0.6-beta.2"
@@ -36,13 +36,15 @@ class AnnotationsIO:
36
36
  dict: A dictionary containing ordered nodes, ordered annotations, and the annotations matrix.
37
37
  """
38
38
  filetype = "JSON"
39
+ # Log the loading of the JSON file
39
40
  params.log_annotations(filepath=filepath, filetype=filetype)
40
41
  _log_loading(filetype, filepath=filepath)
42
+
41
43
  # Open and read the JSON file
42
44
  with open(filepath, "r") as file:
43
45
  annotations_input = json.load(file)
44
46
 
45
- # Process the JSON data and return it in the context of the network
47
+ # Load the annotations into the provided network
46
48
  return load_annotations(network, annotations_input)
47
49
 
48
50
  def load_excel_annotation(
@@ -69,14 +71,18 @@ class AnnotationsIO:
69
71
  linked to the provided network.
70
72
  """
71
73
  filetype = "Excel"
74
+ # Log the loading of the Excel file
72
75
  params.log_annotations(filepath=filepath, filetype=filetype)
73
76
  _log_loading(filetype, filepath=filepath)
77
+
74
78
  # Load the specified sheet from the Excel file
75
79
  df = pd.read_excel(filepath, sheet_name=sheet_name)
76
80
  # Split the nodes column by the specified nodes_delimiter
77
81
  df[nodes_colname] = df[nodes_colname].apply(lambda x: x.split(nodes_delimiter))
78
82
  # Convert the DataFrame to a dictionary pairing labels with their corresponding nodes
79
83
  label_node_dict = df.set_index(label_colname)[nodes_colname].to_dict()
84
+
85
+ # Load the annotations into the provided network
80
86
  return load_annotations(network, label_node_dict)
81
87
 
82
88
  def load_csv_annotation(
@@ -101,13 +107,16 @@ class AnnotationsIO:
101
107
  linked to the provided network.
102
108
  """
103
109
  filetype = "CSV"
110
+ # Log the loading of the CSV file
104
111
  params.log_annotations(filepath=filepath, filetype=filetype)
105
112
  _log_loading(filetype, filepath=filepath)
113
+
106
114
  # Load the CSV file into a dictionary
107
115
  annotations_input = _load_matrix_file(
108
116
  filepath, label_colname, nodes_colname, delimiter=",", nodes_delimiter=nodes_delimiter
109
117
  )
110
- # Process and return the annotations in the context of the network
118
+
119
+ # Load the annotations into the provided network
111
120
  return load_annotations(network, annotations_input)
112
121
 
113
122
  def load_tsv_annotation(
@@ -132,13 +141,16 @@ class AnnotationsIO:
132
141
  linked to the provided network.
133
142
  """
134
143
  filetype = "TSV"
144
+ # Log the loading of the TSV file
135
145
  params.log_annotations(filepath=filepath, filetype=filetype)
136
146
  _log_loading(filetype, filepath=filepath)
147
+
137
148
  # Load the TSV file into a dictionary
138
149
  annotations_input = _load_matrix_file(
139
150
  filepath, label_colname, nodes_colname, delimiter="\t", nodes_delimiter=nodes_delimiter
140
151
  )
141
- # Process and return the annotations in the context of the network
152
+
153
+ # Load the annotations into the provided network
142
154
  return load_annotations(network, annotations_input)
143
155
 
144
156
 
@@ -25,10 +25,14 @@ def calculate_dijkstra_neighborhoods(network: nx.Graph) -> np.ndarray:
25
25
 
26
26
  # Populate the neighborhoods matrix based on Dijkstra's distances
27
27
  for source, targets in all_dijkstra_paths.items():
28
+ max_length = max(targets.values()) if targets else 1 # Handle cases with no targets
28
29
  for target, length in targets.items():
29
- neighborhoods[source, target] = (
30
- 1 if np.isnan(length) or length == 0 else np.sqrt(1 / length)
31
- )
30
+ if np.isnan(length):
31
+ neighborhoods[source, target] = max_length # Use max distance for NaN
32
+ elif length == 0:
33
+ neighborhoods[source, target] = 1 # Assign 1 for zero-length paths (self-loops)
34
+ else:
35
+ neighborhoods[source, target] = 1 / length # Inverse of the distance
32
36
 
33
37
  return neighborhoods
34
38
 
@@ -4,7 +4,7 @@ risk/neighborhoods/neighborhoods
4
4
  """
5
5
 
6
6
  import warnings
7
- from typing import Any, Dict, Tuple
7
+ from typing import Any, Dict, List, Tuple
8
8
 
9
9
  import networkx as nx
10
10
  import numpy as np
@@ -305,7 +305,7 @@ def _get_node_position(network: nx.Graph, node: Any) -> np.ndarray:
305
305
  )
306
306
 
307
307
 
308
- def _calculate_threshold(average_distances: list, distance_threshold: float) -> float:
308
+ def _calculate_threshold(average_distances: List, distance_threshold: float) -> float:
309
309
  """Calculate the distance threshold based on the given average distances and a percentile threshold.
310
310
 
311
311
  Args:
@@ -101,31 +101,32 @@ class NetworkGraph:
101
101
 
102
102
  def get_domain_colors(
103
103
  self,
104
+ cmap: str = "gist_rainbow",
105
+ color: Union[str, None] = None,
104
106
  min_scale: float = 0.8,
105
107
  max_scale: float = 1.0,
106
108
  scale_factor: float = 1.0,
107
109
  random_seed: int = 888,
108
- **kwargs,
109
110
  ) -> np.ndarray:
110
- """Generate composite colors for domains.
111
-
112
- This method generates composite colors for nodes based on their enrichment scores and transforms
113
- them to ensure proper alpha values and intensity. For nodes with alpha == 0, it assigns new colors
114
- based on the closest valid neighbors within a specified distance.
111
+ """Generate composite colors for domains based on enrichment or specified colors.
115
112
 
116
113
  Args:
117
- min_scale (float, optional): Minimum scale for color intensity. Defaults to 0.8.
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.
121
- random_seed (int, optional): Seed for random number generation. Defaults to 888.
122
- **kwargs: Additional keyword arguments for color generation.
114
+ cmap (str, optional): Name of the colormap to use for generating domain colors. Defaults to "gist_rainbow".
115
+ color (str or None, optional): A specific color to use for all generated colors. Defaults to None.
116
+ min_scale (float, optional): Minimum intensity scale for the colors generated by the colormap.
117
+ Controls the dimmest colors. Defaults to 0.8.
118
+ max_scale (float, optional): Maximum intensity scale for the colors generated by the colormap.
119
+ Controls the brightest colors. Defaults to 1.0.
120
+ scale_factor (float, optional): Exponent for adjusting the color scaling based on enrichment scores.
121
+ A higher value increases contrast by dimming lower scores more. Defaults to 1.0.
122
+ random_seed (int, optional): Seed for random number generation to ensure reproducibility of color assignments.
123
+ Defaults to 888.
123
124
 
124
125
  Returns:
125
- np.ndarray: Array of transformed colors.
126
+ np.ndarray: Array of RGBA colors generated for each domain, based on enrichment or the specified color.
126
127
  """
127
128
  # Get colors for each domain
128
- domain_colors = self._get_domain_colors(random_seed=random_seed)
129
+ domain_colors = self._get_domain_colors(cmap=cmap, color=color, random_seed=random_seed)
129
130
  # Generate composite colors for nodes
130
131
  node_colors = self._get_composite_node_colors(domain_colors)
131
132
  # Transform colors to ensure proper alpha values and intensity
@@ -161,12 +162,16 @@ class NetworkGraph:
161
162
  return composite_colors
162
163
 
163
164
  def _get_domain_colors(
164
- self, color: Union[str, None] = None, random_seed: int = 888
165
+ self,
166
+ cmap: str = "gist_rainbow",
167
+ color: Union[str, None] = None,
168
+ random_seed: int = 888,
165
169
  ) -> Dict[str, Any]:
166
170
  """Get colors for each domain.
167
171
 
168
172
  Args:
169
- color (Union[str, None], optional): Specific color to use for all domains. If specified, it will overwrite the colormap.
173
+ cmap (str, optional): The name of the colormap to use. Defaults to "gist_rainbow".
174
+ color (str or None, optional): A specific color to use for all generated colors. Defaults to None.
170
175
  random_seed (int, optional): Seed for random number generation. Defaults to 888.
171
176
 
172
177
  Returns:
@@ -178,7 +183,7 @@ class NetworkGraph:
178
183
  ]
179
184
  domains = np.sort(numeric_domains)
180
185
  domain_colors = _get_colors(
181
- num_colors_to_generate=len(domains), color=color, random_seed=random_seed
186
+ num_colors_to_generate=len(domains), cmap=cmap, color=color, random_seed=random_seed
182
187
  )
183
188
  return dict(zip(self.domain_to_nodes.keys(), domain_colors))
184
189
 
@@ -273,17 +278,17 @@ def _extract_node_coordinates(G: nx.Graph) -> np.ndarray:
273
278
 
274
279
  def _get_colors(
275
280
  num_colors_to_generate: int = 10,
276
- cmap: str = "hsv",
277
- random_seed: int = 888,
281
+ cmap: str = "gist_rainbow",
278
282
  color: Union[str, None] = None,
283
+ random_seed: int = 888,
279
284
  ) -> List[Tuple]:
280
285
  """Generate a list of RGBA colors from a specified colormap or use a direct color string.
281
286
 
282
287
  Args:
283
288
  num_colors_to_generate (int): The number of colors to generate. Defaults to 10.
284
- cmap (str): The name of the colormap to use. Defaults to "hsv".
289
+ cmap (str, optional): The name of the colormap to use. Defaults to "gist_rainbow".
290
+ color (str or None, optional): A specific color to use for all generated colors.
285
291
  random_seed (int): Seed for random number generation. Defaults to 888.
286
- color (str, optional): Specific color to use for all nodes. If specified, it will overwrite the colormap.
287
292
  Defaults to None.
288
293
 
289
294
  Returns:
@@ -48,6 +48,7 @@ class NetworkIO:
48
48
  self.min_edges_per_node = min_edges_per_node
49
49
  self.include_edge_weight = include_edge_weight
50
50
  self.weight_label = weight_label
51
+ # Log the initialization of the NetworkIO class
51
52
  params.log_network(
52
53
  compute_sphere=compute_sphere,
53
54
  surface_depth=surface_depth,
@@ -98,11 +99,14 @@ class NetworkIO:
98
99
  nx.Graph: Loaded and processed network.
99
100
  """
100
101
  filetype = "GPickle"
102
+ # Log the loading of the GPickle file
101
103
  params.log_network(filetype=filetype, filepath=filepath)
102
104
  self._log_loading(filetype, filepath=filepath)
105
+
103
106
  with open(filepath, "rb") as f:
104
107
  G = pickle.load(f)
105
108
 
109
+ # Initialize the graph
106
110
  return self._initialize_graph(G)
107
111
 
108
112
  @classmethod
@@ -147,8 +151,11 @@ class NetworkIO:
147
151
  nx.Graph: Processed network.
148
152
  """
149
153
  filetype = "NetworkX"
154
+ # Log the loading of the NetworkX graph
150
155
  params.log_network(filetype=filetype)
151
156
  self._log_loading(filetype)
157
+
158
+ # Initialize the graph
152
159
  return self._initialize_graph(network)
153
160
 
154
161
  @classmethod
@@ -213,8 +220,10 @@ class NetworkIO:
213
220
  nx.Graph: Loaded and processed network.
214
221
  """
215
222
  filetype = "Cytoscape"
223
+ # Log the loading of the Cytoscape file
216
224
  params.log_network(filetype=filetype, filepath=str(filepath))
217
225
  self._log_loading(filetype, filepath=filepath)
226
+
218
227
  cys_files = []
219
228
  tmp_dir = ".tmp_cytoscape"
220
229
  # Try / finally to remove unzipped files
@@ -295,6 +304,7 @@ class NetworkIO:
295
304
  node
296
305
  ] # Assuming you have a dict `node_y_positions` for y coordinates
297
306
 
307
+ # Initialize the graph
298
308
  return self._initialize_graph(G)
299
309
 
300
310
  finally:
@@ -354,6 +364,7 @@ class NetworkIO:
354
364
  NetworkX graph: Loaded and processed network.
355
365
  """
356
366
  filetype = "Cytoscape JSON"
367
+ # Log the loading of the Cytoscape JSON file
357
368
  params.log_network(filetype=filetype, filepath=str(filepath))
358
369
  self._log_loading(filetype, filepath=filepath)
359
370