risk-network 0.0.9b44__tar.gz → 0.0.9b46__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 (47) hide show
  1. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/PKG-INFO +1 -1
  2. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/__init__.py +1 -1
  3. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/neighborhoods/domains.py +23 -13
  4. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/geometry.py +2 -19
  5. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk_network.egg-info/PKG-INFO +1 -1
  6. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/setup.py +3 -2
  7. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/LICENSE +0 -0
  8. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/MANIFEST.in +0 -0
  9. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/README.md +0 -0
  10. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/pyproject.toml +0 -0
  11. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/annotations/__init__.py +0 -0
  12. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/annotations/annotations.py +0 -0
  13. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/annotations/io.py +0 -0
  14. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/log/__init__.py +0 -0
  15. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/log/console.py +0 -0
  16. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/log/parameters.py +0 -0
  17. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/neighborhoods/__init__.py +0 -0
  18. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/neighborhoods/api.py +0 -0
  19. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/neighborhoods/community.py +0 -0
  20. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/neighborhoods/neighborhoods.py +0 -0
  21. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/__init__.py +0 -0
  22. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/graph/__init__.py +0 -0
  23. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/graph/api.py +0 -0
  24. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/graph/graph.py +0 -0
  25. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/graph/summary.py +0 -0
  26. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/io.py +0 -0
  27. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/plotter/__init__.py +0 -0
  28. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/plotter/api.py +0 -0
  29. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/plotter/canvas.py +0 -0
  30. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/plotter/contour.py +0 -0
  31. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/plotter/labels.py +0 -0
  32. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/plotter/network.py +0 -0
  33. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/plotter/plotter.py +0 -0
  34. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/plotter/utils/colors.py +0 -0
  35. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/network/plotter/utils/layout.py +0 -0
  36. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/risk.py +0 -0
  37. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/stats/__init__.py +0 -0
  38. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/stats/permutation/__init__.py +0 -0
  39. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/stats/permutation/permutation.py +0 -0
  40. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/stats/permutation/test_functions.py +0 -0
  41. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/stats/significance.py +0 -0
  42. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk/stats/stat_tests.py +0 -0
  43. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk_network.egg-info/SOURCES.txt +0 -0
  44. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk_network.egg-info/dependency_links.txt +0 -0
  45. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk_network.egg-info/requires.txt +0 -0
  46. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/risk_network.egg-info/top_level.txt +0 -0
  47. {risk_network-0.0.9b44 → risk_network-0.0.9b46}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: risk-network
3
- Version: 0.0.9b44
3
+ Version: 0.0.9b46
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: Regional Inference of Significant Kinships
7
7
 
8
8
  from risk.risk import RISK
9
9
 
10
- __version__ = "0.0.9-beta.44"
10
+ __version__ = "0.0.9-beta.46"
@@ -3,12 +3,12 @@ risk/neighborhoods/domains
3
3
  ~~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
- from contextlib import suppress
7
6
  from itertools import product
8
7
  from typing import Tuple, Union
9
8
 
10
9
  import numpy as np
11
10
  import pandas as pd
11
+ from numpy.linalg import LinAlgError
12
12
  from scipy.cluster.hierarchy import linkage, fcluster
13
13
  from sklearn.metrics import silhouette_score
14
14
  from tqdm import tqdm
@@ -73,7 +73,7 @@ def define_domains(
73
73
  domains = fcluster(Z, max_d_optimal, criterion=linkage_criterion)
74
74
  top_annotations["domain"] = 0
75
75
  top_annotations.loc[top_annotations["significant_annotations"], "domain"] = domains
76
- except ValueError:
76
+ except (ValueError, LinAlgError):
77
77
  # If a ValueError is encountered, handle it by assigning unique domains
78
78
  n_rows = len(top_annotations)
79
79
  if linkage_criterion == "off":
@@ -247,16 +247,17 @@ def _optimize_silhouette_across_linkage_and_metrics(
247
247
  bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}]",
248
248
  ):
249
249
  # Some linkage methods and metrics may not work with certain data
250
- with suppress(ValueError):
250
+ try:
251
251
  Z = linkage(m, method=method, metric=metric)
252
+ except (ValueError, LinAlgError):
253
+ # If linkage fails, set a default threshold (a float) and a very poor score
254
+ current_threshold = 0.0
255
+ score = -float("inf")
256
+ else:
252
257
  # Only optimize silhouette score if the threshold is "auto"
253
258
  if linkage_threshold == "auto":
254
259
  threshold, score = _find_best_silhouette_score(Z, m, metric, linkage_criterion)
255
- if score > best_overall_score:
256
- best_overall_score = score
257
- best_overall_threshold = threshold
258
- best_overall_method = method
259
- best_overall_metric = metric
260
+ current_threshold = threshold
260
261
  else:
261
262
  # Use the provided threshold without optimization
262
263
  score = silhouette_score(
@@ -264,11 +265,20 @@ def _optimize_silhouette_across_linkage_and_metrics(
264
265
  fcluster(Z, linkage_threshold * np.max(Z[:, 2]), criterion=linkage_criterion),
265
266
  metric=metric,
266
267
  )
267
- if score > best_overall_score:
268
- best_overall_score = score
269
- best_overall_threshold = linkage_threshold
270
- best_overall_method = method
271
- best_overall_metric = metric
268
+ current_threshold = linkage_threshold
269
+
270
+ if score > best_overall_score:
271
+ best_overall_score = score
272
+ best_overall_threshold = float(current_threshold) # Ensure it's a float
273
+ best_overall_method = method
274
+ best_overall_metric = metric
275
+
276
+ # Ensure that we always return a valid tuple:
277
+ if best_overall_score == -np.inf:
278
+ # No valid linkage was found; return default values.
279
+ best_overall_threshold = float(linkage_threshold) if linkage_threshold != "auto" else 0.0
280
+ best_overall_method = linkage_method
281
+ best_overall_metric = linkage_metric
272
282
 
273
283
  return best_overall_method, best_overall_metric, best_overall_threshold
274
284
 
@@ -12,7 +12,7 @@ def assign_edge_lengths(
12
12
  compute_sphere: bool = True,
13
13
  surface_depth: float = 0.0,
14
14
  ) -> nx.Graph:
15
- """Assign edge lengths in the graph, optionally mapping nodes to a sphere and including edge weights.
15
+ """Assign edge lengths in the graph, optionally mapping nodes to a sphere.
16
16
 
17
17
  Args:
18
18
  G (nx.Graph): The input graph.
@@ -33,9 +33,8 @@ def assign_edge_lengths(
33
33
  return np.arccos(np.clip(dot_products, -1.0, 1.0))
34
34
  return np.linalg.norm(u_coords - v_coords, axis=1)
35
35
 
36
- # Normalize graph coordinates and weights
36
+ # Normalize graph coordinates
37
37
  _normalize_graph_coordinates(G)
38
- _normalize_weights(G)
39
38
 
40
39
  # Map nodes to sphere and adjust depth if required
41
40
  if compute_sphere:
@@ -110,22 +109,6 @@ def _normalize_graph_coordinates(G: nx.Graph) -> None:
110
109
  G.nodes[node]["x"], G.nodes[node]["y"] = normalized_xy[i]
111
110
 
112
111
 
113
- def _normalize_weights(G: nx.Graph) -> None:
114
- """Normalize the weights of the edges in the graph.
115
-
116
- Args:
117
- G (nx.Graph): The input graph with weighted edges.
118
- """
119
- # "weight" is present for all edges - weights are 1.0 if weight was not specified by the user
120
- weights = [data["weight"] for _, _, data in G.edges(data=True)]
121
- if weights: # Ensure there are weighted edges
122
- min_weight = min(weights)
123
- max_weight = max(weights)
124
- range_weight = max_weight - min_weight if max_weight > min_weight else 1
125
- for _, _, data in G.edges(data=True):
126
- data["normalized_weight"] = (data["weight"] - min_weight) / range_weight
127
-
128
-
129
112
  def _create_depth(G: nx.Graph, surface_depth: float = 0.0) -> nx.Graph:
130
113
  """Adjust the 'z' attribute of each node based on the subcluster strengths and normalized surface depth.
131
114
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: risk-network
3
- Version: 0.0.9b44
3
+ Version: 0.0.9b46
4
4
  Summary: A Python package for biological network analysis
5
5
  Author: Ira Horecka
6
6
  Author-email: Ira Horecka <ira89@icloud.com>
@@ -10,8 +10,8 @@ from setuptools import setup, find_packages
10
10
  import numpy
11
11
 
12
12
 
13
- # Function to extract version from __init__.py
14
13
  def find_version():
14
+ """Function to find the version string in the __init__.py file."""
15
15
  with open("risk/__init__.py", "r", encoding="utf-8") as f:
16
16
  version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", f.read(), re.M)
17
17
  if version_match:
@@ -40,7 +40,8 @@ setup(
40
40
  "nltk==3.8.1",
41
41
  "numpy",
42
42
  "openpyxl",
43
- "pandas" "python-igraph",
43
+ "pandas",
44
+ "python-igraph",
44
45
  "python-louvain",
45
46
  "scikit-learn",
46
47
  "scipy",
File without changes