risk-network 0.0.6b9__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 +1 -1
- risk/annotations/annotations.py +19 -14
- risk/log/params.py +2 -0
- risk/neighborhoods/domains.py +13 -14
- risk/network/plot.py +3 -1
- risk/risk.py +3 -3
- {risk_network-0.0.6b9.dist-info → risk_network-0.0.7b0.dist-info}/METADATA +1 -1
- {risk_network-0.0.6b9.dist-info → risk_network-0.0.7b0.dist-info}/RECORD +11 -11
- {risk_network-0.0.6b9.dist-info → risk_network-0.0.7b0.dist-info}/WHEEL +1 -1
- {risk_network-0.0.6b9.dist-info → risk_network-0.0.7b0.dist-info}/LICENSE +0 -0
- {risk_network-0.0.6b9.dist-info → risk_network-0.0.7b0.dist-info}/top_level.txt +0 -0
risk/__init__.py
CHANGED
risk/annotations/annotations.py
CHANGED
@@ -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 =
|
137
|
-
|
138
|
-
|
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
|
-
|
146
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
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
|
|
risk/log/params.py
CHANGED
@@ -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)
|
risk/neighborhoods/domains.py
CHANGED
@@ -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
|
-
|
39
|
-
|
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
|
-
|
49
|
-
|
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))
|
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)
|
risk/risk.py
CHANGED
@@ -62,7 +62,7 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
62
62
|
|
63
63
|
Args:
|
64
64
|
network (nx.Graph): The network graph.
|
65
|
-
annotations (
|
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 (
|
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 (
|
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,21 +1,21 @@
|
|
1
|
-
risk/__init__.py,sha256=
|
1
|
+
risk/__init__.py,sha256=Qyktssx5ZswUpqcPtSMq9Zn-zzJXl2fka6MqbHS-JxQ,112
|
2
2
|
risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
|
3
|
-
risk/risk.py,sha256
|
3
|
+
risk/risk.py,sha256=CKDIzVo9Jvl-fgzIlk5ZtJL9pIBMma24WK6EYdVu5po,20648
|
4
4
|
risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
|
5
|
-
risk/annotations/annotations.py,sha256=
|
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
|
-
risk/log/params.py,sha256=
|
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=
|
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=
|
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.
|
27
|
-
risk_network-0.0.
|
28
|
-
risk_network-0.0.
|
29
|
-
risk_network-0.0.
|
30
|
-
risk_network-0.0.
|
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,,
|
File without changes
|
File without changes
|