risk-network 0.0.6b10__py3-none-any.whl → 0.0.7b0__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.6-beta.10"
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
 
@@ -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(
risk/network/plot.py CHANGED
@@ -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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.6b10
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>
@@ -1,21 +1,21 @@
1
- risk/__init__.py,sha256=nUkWz8VqnztwzCLGVbN6G8bFixZFkDyLsEOsb5mLAGc,113
1
+ risk/__init__.py,sha256=Qyktssx5ZswUpqcPtSMq9Zn-zzJXl2fka6MqbHS-JxQ,112
2
2
  risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
3
3
  risk/risk.py,sha256=CKDIzVo9Jvl-fgzIlk5ZtJL9pIBMma24WK6EYdVu5po,20648
4
4
  risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
5
- risk/annotations/annotations.py,sha256=DRUTdGzMdqo62NWSapBUksbvPr9CrzD76qtOcxeNKmo,10554
5
+ risk/annotations/annotations.py,sha256=K7cUA6vYTKYAvj0xHqrAwNEYtmPq4H7LDYENAOVQdQ0,11014
6
6
  risk/annotations/io.py,sha256=lo7NKqOVkeeBp58JBxWJHtA0xjL5Yoxqe9Ox0daKlZk,9457
7
7
  risk/log/__init__.py,sha256=xuLImfxFlKpnVhzi_gDYlr2_c9cLkrw2c_3iEsXb1as,107
8
8
  risk/log/console.py,sha256=im9DRExwf6wHlcn9fewoDcKIpo3vPcorZIaNAl-0csY,355
9
9
  risk/log/params.py,sha256=Rfdg5UcGCrG80m6V79FyORERWUqIzHFO7tGiY4zAImM,6347
10
10
  risk/neighborhoods/__init__.py,sha256=tKKEg4lsbqFukpgYlUGxU_v_9FOqK7V0uvM9T2QzoL0,206
11
11
  risk/neighborhoods/community.py,sha256=7ebo1Q5KokSQISnxZIh2SQxsKXdXm8aVkp-h_DiQ3K0,6818
12
- risk/neighborhoods/domains.py,sha256=5V--Nj-TrSdubhD_2PI57ffcn_PMSEgpX_iY5OjT6R8,10626
12
+ risk/neighborhoods/domains.py,sha256=bxJUxqFTynzX0mf3E8-AA4_Rfccje1reeVVhfzb1-pE,10672
13
13
  risk/neighborhoods/neighborhoods.py,sha256=sHmjFFl2U5qV9YbQCRbpbI36j7dS7IFfFwwRb1_-AuM,13945
14
14
  risk/network/__init__.py,sha256=iEPeJdZfqp0toxtbElryB8jbz9_t_k4QQ3iDvKE8C_0,126
15
15
  risk/network/geometry.py,sha256=H1yGVVqgbfpzBzJwEheDLfvGLSA284jGQQTn612L4Vc,6759
16
16
  risk/network/graph.py,sha256=7haHu4M3fleqbrIzs6HC9jnKizSERzmmAYSmUwdoSXA,13953
17
17
  risk/network/io.py,sha256=gG50kOknO-D3HkW1HsbHMkTMvjUtn3l4W4Jwd-rXNr8,21202
18
- risk/network/plot.py,sha256=_g5xHolMTAfZCBvYYEX1CYME4s4zA2hTHtN-utaMPik,61978
18
+ risk/network/plot.py,sha256=F6KPjmBYWrThKZScHs9SuzoKQiytBvzrmGhGberHjwo,62063
19
19
  risk/stats/__init__.py,sha256=e-BE_Dr_jgiK6hKM-T-tlG4yvHnId8e5qjnM0pdwNVc,230
20
20
  risk/stats/fisher_exact.py,sha256=-bPwzu76-ob0HzrTV20mXUTot7v-MLuqFaAoab-QxPg,4966
21
21
  risk/stats/hypergeom.py,sha256=lrIFdhCWRjvM4apYw1MlOKqT_IY5OjtCwrjdtJdt6Tg,4954
@@ -23,8 +23,8 @@ risk/stats/stats.py,sha256=kvShov-94W6ffgDUTb522vB9hDJQSyTsYif_UIaFfSM,7059
23
23
  risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
24
24
  risk/stats/permutation/permutation.py,sha256=qLWdwxEY6nmkYPxpM8HLDcd2mbqYv9Qr7CKtJvhLqIM,9220
25
25
  risk/stats/permutation/test_functions.py,sha256=HuDIM-V1jkkfE1rlaIqrWWBSKZt3dQ1f-YEDjWpnLSE,2343
26
- risk_network-0.0.6b10.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
- risk_network-0.0.6b10.dist-info/METADATA,sha256=aOz9JrsPIpByvzMCwsbBBcBHHMLu3JzLF9FZMp9-IuM,43143
28
- risk_network-0.0.6b10.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
- risk_network-0.0.6b10.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
- risk_network-0.0.6b10.dist-info/RECORD,,
26
+ risk_network-0.0.7b0.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
+ risk_network-0.0.7b0.dist-info/METADATA,sha256=Yokjvu7qlqWV6F_qJQ9O6TIwKw_9XpD_2qgwQHyimRY,43142
28
+ risk_network-0.0.7b0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
+ risk_network-0.0.7b0.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
+ risk_network-0.0.7b0.dist-info/RECORD,,