risk-network 0.0.6b9__tar.gz → 0.0.7b0__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.6b9 → risk_network-0.0.7b0}/PKG-INFO +1 -1
  2. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/__init__.py +1 -1
  3. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/annotations/annotations.py +19 -14
  4. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/log/params.py +2 -0
  5. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/neighborhoods/domains.py +13 -14
  6. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/network/plot.py +3 -1
  7. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/risk.py +3 -3
  8. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk_network.egg-info/PKG-INFO +1 -1
  9. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/LICENSE +0 -0
  10. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/MANIFEST.in +0 -0
  11. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/README.md +0 -0
  12. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/pyproject.toml +0 -0
  13. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/annotations/__init__.py +0 -0
  14. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/annotations/io.py +0 -0
  15. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/constants.py +0 -0
  16. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/log/__init__.py +0 -0
  17. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/log/console.py +0 -0
  18. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/neighborhoods/__init__.py +0 -0
  19. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/neighborhoods/community.py +0 -0
  20. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/neighborhoods/neighborhoods.py +0 -0
  21. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/network/__init__.py +0 -0
  22. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/network/geometry.py +0 -0
  23. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/network/graph.py +0 -0
  24. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/network/io.py +0 -0
  25. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/stats/__init__.py +0 -0
  26. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/stats/fisher_exact.py +0 -0
  27. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/stats/hypergeom.py +0 -0
  28. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/stats/permutation/__init__.py +0 -0
  29. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/stats/permutation/permutation.py +0 -0
  30. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/stats/permutation/test_functions.py +0 -0
  31. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk/stats/stats.py +0 -0
  32. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk_network.egg-info/SOURCES.txt +0 -0
  33. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk_network.egg-info/dependency_links.txt +0 -0
  34. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk_network.egg-info/requires.txt +0 -0
  35. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/risk_network.egg-info/top_level.txt +0 -0
  36. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/setup.cfg +0 -0
  37. {risk_network-0.0.6b9 → risk_network-0.0.7b0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.6b9
3
+ Version: 0.0.7b0
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.9"
10
+ __version__ = "0.0.7-beta.0"
@@ -132,27 +132,32 @@ def define_top_annotations(
132
132
  nx.connected_components(enriched_network), key=len, reverse=True
133
133
  )
134
134
  size_connected_components = np.array([len(c) for c in connected_components])
135
+
136
+ # Filter the size of connected components by min_cluster_size and max_cluster_size
137
+ filtered_size_connected_components = size_connected_components[
138
+ (size_connected_components >= min_cluster_size)
139
+ & (size_connected_components <= max_cluster_size)
140
+ ]
141
+ # Calculate the number of connected components and large connected components
135
142
  num_connected_components = len(connected_components)
136
- num_large_connected_components = np.sum(
137
- np.logical_and(
138
- size_connected_components >= min_cluster_size,
139
- size_connected_components <= max_cluster_size,
140
- )
141
- )
143
+ num_large_connected_components = len(filtered_size_connected_components)
144
+
145
+ # Assign the number of connected components
142
146
  annotations_enrichment_matrix.loc[attribute, "num connected components"] = (
143
147
  num_connected_components
144
148
  )
145
- annotations_enrichment_matrix.at[attribute, "size connected components"] = (
146
- size_connected_components
147
- )
149
+ # Filter out attributes with more than one connected component
150
+ annotations_enrichment_matrix.loc[
151
+ annotations_enrichment_matrix["num connected components"] > 1, "top attributes"
152
+ ] = False
153
+ # Assign the number of large connected components
148
154
  annotations_enrichment_matrix.loc[attribute, "num large connected components"] = (
149
155
  num_large_connected_components
150
156
  )
151
-
152
- # Filter out attributes with more than one connected component
153
- annotations_enrichment_matrix.loc[
154
- annotations_enrichment_matrix["num connected components"] > 1, "top attributes"
155
- ] = False
157
+ # Assign the size of connected components, ensuring it is always a list
158
+ annotations_enrichment_matrix.at[attribute, "size connected components"] = (
159
+ filtered_size_connected_components.tolist()
160
+ )
156
161
 
157
162
  return annotations_enrichment_matrix
158
163
 
@@ -7,6 +7,7 @@ import csv
7
7
  import json
8
8
  import warnings
9
9
  from datetime import datetime
10
+ from functools import wraps
10
11
  from typing import Any, Dict
11
12
 
12
13
  import numpy as np
@@ -27,6 +28,7 @@ def _safe_param_export(func):
27
28
  function: The wrapped function with error handling.
28
29
  """
29
30
 
31
+ @wraps(func)
30
32
  def wrapper(*args, **kwargs):
31
33
  try:
32
34
  result = func(*args, **kwargs)
@@ -23,7 +23,8 @@ def define_domains(
23
23
  linkage_method: str,
24
24
  linkage_metric: str,
25
25
  ) -> pd.DataFrame:
26
- """Define domains and assign nodes to these domains based on their enrichment scores and clustering.
26
+ """Define domains and assign nodes to these domains based on their enrichment scores and clustering,
27
+ handling errors by assigning unique domains when clustering fails.
27
28
 
28
29
  Args:
29
30
  top_annotations (pd.DataFrame): DataFrame of top annotations data for the network nodes.
@@ -35,31 +36,29 @@ def define_domains(
35
36
  Returns:
36
37
  pd.DataFrame: DataFrame with the primary domain for each node.
37
38
  """
38
- # Check if there's more than one column in significant_neighborhoods_enrichment
39
- if significant_neighborhoods_enrichment.shape[1] == 1:
40
- print("Single annotation detected. Skipping clustering.")
41
- top_annotations["domain"] = 1 # Assign a default domain or handle appropriately
42
- else:
43
- # Perform hierarchical clustering on the binary enrichment matrix
39
+ try:
40
+ # Transpose the matrix to cluster annotations
44
41
  m = significant_neighborhoods_enrichment[:, top_annotations["top attributes"]].T
45
42
  best_linkage, best_metric, best_threshold = _optimize_silhouette_across_linkage_and_metrics(
46
43
  m, linkage_criterion, linkage_method, linkage_metric
47
44
  )
48
- try:
49
- Z = linkage(m, method=best_linkage, metric=best_metric)
50
- except ValueError as e:
51
- raise ValueError("No significant annotations found.") from e
52
-
45
+ # Perform hierarchical clustering
46
+ Z = linkage(m, method=best_linkage, metric=best_metric)
53
47
  print(
54
48
  f"Linkage criterion: '{linkage_criterion}'\nLinkage method: '{best_linkage}'\nLinkage metric: '{best_metric}'"
55
49
  )
56
50
  print(f"Optimal linkage threshold: {round(best_threshold, 3)}")
57
-
51
+ # Calculate the optimal threshold for clustering
58
52
  max_d_optimal = np.max(Z[:, 2]) * best_threshold
59
- domains = fcluster(Z, max_d_optimal, criterion=linkage_criterion)
60
53
  # Assign domains to the annotations matrix
54
+ domains = fcluster(Z, max_d_optimal, criterion=linkage_criterion)
61
55
  top_annotations["domain"] = 0
62
56
  top_annotations.loc[top_annotations["top attributes"], "domain"] = domains
57
+ except ValueError:
58
+ # If a ValueError is encountered, handle it by assigning unique domains
59
+ n_rows = len(top_annotations)
60
+ print(f"Error encountered. Skipping clustering and assigning {n_rows} unique domains.")
61
+ top_annotations["domain"] = range(1, n_rows + 1) # Assign unique domains
63
62
 
64
63
  # Create DataFrames to store domain information
65
64
  node_to_enrichment = pd.DataFrame(
@@ -1123,7 +1123,9 @@ def _to_rgba(
1123
1123
  """
1124
1124
  # Handle single color case (string, RGB, or RGBA)
1125
1125
  if isinstance(color, str) or (
1126
- isinstance(color, (list, tuple, np.ndarray)) and len(color) in [3, 4]
1126
+ isinstance(color, (list, tuple, np.ndarray))
1127
+ and len(color) in [3, 4]
1128
+ and not any(isinstance(c, (list, tuple, np.ndarray)) for c in color)
1127
1129
  ):
1128
1130
  rgba_color = np.array(mcolors.to_rgba(color))
1129
1131
  # Only set alpha if the input is an RGB color or a string (not RGBA)
@@ -62,7 +62,7 @@ class RISK(NetworkIO, AnnotationsIO):
62
62
 
63
63
  Args:
64
64
  network (nx.Graph): The network graph.
65
- annotations (pd.DataFrame): The matrix of annotations associated with the network.
65
+ annotations (dict): The annotations associated with the network.
66
66
  distance_metric (str, optional): Distance metric for neighborhood analysis. Defaults to "dijkstra".
67
67
  louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
68
68
  edge_length_threshold (float, optional): Edge length threshold for neighborhood analysis. Defaults to 0.5.
@@ -131,7 +131,7 @@ class RISK(NetworkIO, AnnotationsIO):
131
131
 
132
132
  Args:
133
133
  network (nx.Graph): The network graph.
134
- annotations (pd.DataFrame): The matrix of annotations associated with the network.
134
+ annotations (dict): The annotations associated with the network.
135
135
  distance_metric (str, optional): Distance metric for neighborhood analysis. Defaults to "dijkstra".
136
136
  louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
137
137
  edge_length_threshold (float, optional): Edge length threshold for neighborhood analysis. Defaults to 0.5.
@@ -187,7 +187,7 @@ class RISK(NetworkIO, AnnotationsIO):
187
187
 
188
188
  Args:
189
189
  network (nx.Graph): The network graph.
190
- annotations (pd.DataFrame): The matrix of annotations associated with the network.
190
+ annotations (dict): The annotations associated with the network.
191
191
  distance_metric (str, optional): Distance metric for neighborhood analysis. Defaults to "dijkstra".
192
192
  louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
193
193
  edge_length_threshold (float, optional): Edge length threshold for neighborhood analysis. Defaults to 0.5.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.6b9
3
+ Version: 0.0.7b0
4
4
  Summary: A Python package for biological network analysis
5
5
  Author: Ira Horecka
6
6
  Author-email: Ira Horecka <ira89@icloud.com>
File without changes
File without changes
File without changes
File without changes