risk-network 0.0.9b5__py3-none-any.whl → 0.0.9b7__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 +26 -5
- risk/annotations/io.py +39 -23
- risk/neighborhoods/__init__.py +1 -1
- risk/neighborhoods/domains.py +4 -8
- risk/network/graph/network.py +28 -6
- risk/network/plot/canvas.py +1 -1
- risk/network/plot/contour.py +1 -1
- risk/network/plot/labels.py +1 -1
- risk/network/plot/network.py +1 -1
- risk/network/plot/plotter.py +1 -1
- risk/network/plot/utils/{color.py → colors.py} +1 -0
- risk/risk.py +8 -36
- {risk_network-0.0.9b5.dist-info → risk_network-0.0.9b7.dist-info}/METADATA +1 -1
- {risk_network-0.0.9b5.dist-info → risk_network-0.0.9b7.dist-info}/RECORD +18 -18
- {risk_network-0.0.9b5.dist-info → risk_network-0.0.9b7.dist-info}/LICENSE +0 -0
- {risk_network-0.0.9b5.dist-info → risk_network-0.0.9b7.dist-info}/WHEEL +0 -0
- {risk_network-0.0.9b5.dist-info → risk_network-0.0.9b7.dist-info}/top_level.txt +0 -0
risk/__init__.py
CHANGED
risk/annotations/annotations.py
CHANGED
@@ -15,6 +15,8 @@ import pandas as pd
|
|
15
15
|
from nltk.tokenize import word_tokenize
|
16
16
|
from nltk.corpus import stopwords
|
17
17
|
|
18
|
+
from risk.log import logger
|
19
|
+
|
18
20
|
|
19
21
|
def _setup_nltk():
|
20
22
|
"""Ensure necessary NLTK data is downloaded."""
|
@@ -35,15 +37,23 @@ _setup_nltk()
|
|
35
37
|
stop_words = set(stopwords.words("english"))
|
36
38
|
|
37
39
|
|
38
|
-
def load_annotations(
|
40
|
+
def load_annotations(
|
41
|
+
network: nx.Graph, annotations_input: Dict[str, Any], min_nodes_per_term: int = 2
|
42
|
+
) -> Dict[str, Any]:
|
39
43
|
"""Convert annotations input to a DataFrame and reindex based on the network's node labels.
|
40
44
|
|
41
45
|
Args:
|
42
46
|
network (nx.Graph): The network graph.
|
43
47
|
annotations_input (Dict[str, Any]): A dictionary with annotations.
|
48
|
+
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
49
|
+
term to be included. Defaults to 2.
|
44
50
|
|
45
51
|
Returns:
|
46
52
|
Dict[str, Any]: A dictionary containing ordered nodes, ordered annotations, and the binary annotations matrix.
|
53
|
+
|
54
|
+
Raises:
|
55
|
+
ValueError: If no annotations are found for the nodes in the network.
|
56
|
+
ValueError: If no annotations have at least min_nodes_per_term nodes in the network.
|
47
57
|
"""
|
48
58
|
# Flatten the dictionary to a list of tuples for easier DataFrame creation
|
49
59
|
flattened_annotations = [
|
@@ -61,13 +71,24 @@ def load_annotations(network: nx.Graph, annotations_input: Dict[str, Any]) -> Di
|
|
61
71
|
annotations_pivot = annotations_pivot.reindex(index=node_label_order)
|
62
72
|
# Raise an error if no valid annotations are found for the nodes in the network
|
63
73
|
if annotations_pivot.notnull().sum().sum() == 0:
|
74
|
+
raise ValueError("No terms found in the annotation file for the nodes in the network.")
|
75
|
+
|
76
|
+
# Filter out annotations with fewer than min_nodes_per_term occurrences
|
77
|
+
# This assists in reducing noise and focusing on more relevant annotations for statistical analysis
|
78
|
+
num_terms_before_filtering = annotations_pivot.shape[1]
|
79
|
+
annotations_pivot = annotations_pivot.loc[
|
80
|
+
:, (annotations_pivot.sum(axis=0) >= min_nodes_per_term)
|
81
|
+
]
|
82
|
+
num_terms_after_filtering = annotations_pivot.shape[1]
|
83
|
+
# Log the number of annotations before and after filtering
|
84
|
+
logger.info(f"Minimum number of nodes per annotation term: {min_nodes_per_term}")
|
85
|
+
logger.info(f"Number of input annotation terms: {num_terms_before_filtering}")
|
86
|
+
logger.info(f"Number of remaining annotation terms: {num_terms_after_filtering}")
|
87
|
+
if num_terms_after_filtering == 0:
|
64
88
|
raise ValueError(
|
65
|
-
"No
|
89
|
+
f"No annotation terms found with at least {min_nodes_per_term} nodes in the network."
|
66
90
|
)
|
67
91
|
|
68
|
-
# Remove columns with all zeros and those with only a single '1' to improve statistical performance
|
69
|
-
# (i.e., it's unreliable to compute the significance of an annotation in a node cluster based on a single occurrence).
|
70
|
-
annotations_pivot = annotations_pivot.loc[:, (annotations_pivot.sum(axis=0) > 1)]
|
71
92
|
# Extract ordered nodes and annotations
|
72
93
|
ordered_nodes = tuple(annotations_pivot.index)
|
73
94
|
ordered_annotations = tuple(annotations_pivot.columns)
|
risk/annotations/io.py
CHANGED
@@ -25,27 +25,32 @@ class AnnotationsIO:
|
|
25
25
|
def __init__(self):
|
26
26
|
pass
|
27
27
|
|
28
|
-
def load_json_annotation(
|
28
|
+
def load_json_annotation(
|
29
|
+
self, network: nx.Graph, filepath: str, min_nodes_per_term: int = 2
|
30
|
+
) -> Dict[str, Any]:
|
29
31
|
"""Load annotations from a JSON file and convert them to a DataFrame.
|
30
32
|
|
31
33
|
Args:
|
32
34
|
network (NetworkX graph): The network to which the annotations are related.
|
33
35
|
filepath (str): Path to the JSON annotations file.
|
36
|
+
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
37
|
+
term to be included. Defaults to 2.
|
34
38
|
|
35
39
|
Returns:
|
36
40
|
Dict[str, Any]: A dictionary containing ordered nodes, ordered annotations, and the annotations matrix.
|
37
41
|
"""
|
38
42
|
filetype = "JSON"
|
39
43
|
# Log the loading of the JSON file
|
40
|
-
params.log_annotations(
|
44
|
+
params.log_annotations(
|
45
|
+
filetype=filetype, filepath=filepath, min_nodes_per_term=min_nodes_per_term
|
46
|
+
)
|
41
47
|
_log_loading(filetype, filepath=filepath)
|
42
48
|
|
43
|
-
#
|
49
|
+
# Load the JSON file into a dictionary
|
44
50
|
with open(filepath, "r") as file:
|
45
51
|
annotations_input = json.load(file)
|
46
52
|
|
47
|
-
|
48
|
-
return load_annotations(network, annotations_input)
|
53
|
+
return load_annotations(network, annotations_input, min_nodes_per_term)
|
49
54
|
|
50
55
|
def load_excel_annotation(
|
51
56
|
self,
|
@@ -55,6 +60,7 @@ class AnnotationsIO:
|
|
55
60
|
nodes_colname: str = "nodes",
|
56
61
|
sheet_name: str = "Sheet1",
|
57
62
|
nodes_delimiter: str = ";",
|
63
|
+
min_nodes_per_term: int = 2,
|
58
64
|
) -> Dict[str, Any]:
|
59
65
|
"""Load annotations from an Excel file and associate them with the network.
|
60
66
|
|
@@ -65,6 +71,8 @@ class AnnotationsIO:
|
|
65
71
|
nodes_colname (str): Name of the column containing the nodes associated with each label.
|
66
72
|
sheet_name (str, optional): The name of the Excel sheet to load (default is 'Sheet1').
|
67
73
|
nodes_delimiter (str, optional): Delimiter used to separate multiple nodes within the nodes column (default is ';').
|
74
|
+
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
75
|
+
term to be included. Defaults to 2.
|
68
76
|
|
69
77
|
Returns:
|
70
78
|
Dict[str, Any]: A dictionary where each label is paired with its respective list of nodes,
|
@@ -72,7 +80,9 @@ class AnnotationsIO:
|
|
72
80
|
"""
|
73
81
|
filetype = "Excel"
|
74
82
|
# Log the loading of the Excel file
|
75
|
-
params.log_annotations(
|
83
|
+
params.log_annotations(
|
84
|
+
filetype=filetype, filepath=filepath, min_nodes_per_term=min_nodes_per_term
|
85
|
+
)
|
76
86
|
_log_loading(filetype, filepath=filepath)
|
77
87
|
|
78
88
|
# Load the specified sheet from the Excel file
|
@@ -82,10 +92,9 @@ class AnnotationsIO:
|
|
82
92
|
lambda x: x.split(nodes_delimiter)
|
83
93
|
)
|
84
94
|
# Convert the DataFrame to a dictionary pairing labels with their corresponding nodes
|
85
|
-
|
95
|
+
annotations_input = annotation.set_index(label_colname)[nodes_colname].to_dict()
|
86
96
|
|
87
|
-
|
88
|
-
return load_annotations(network, label_node_dict)
|
97
|
+
return load_annotations(network, annotations_input, min_nodes_per_term)
|
89
98
|
|
90
99
|
def load_csv_annotation(
|
91
100
|
self,
|
@@ -94,6 +103,7 @@ class AnnotationsIO:
|
|
94
103
|
label_colname: str = "label",
|
95
104
|
nodes_colname: str = "nodes",
|
96
105
|
nodes_delimiter: str = ";",
|
106
|
+
min_nodes_per_term: int = 2,
|
97
107
|
) -> Dict[str, Any]:
|
98
108
|
"""Load annotations from a CSV file and associate them with the network.
|
99
109
|
|
@@ -103,6 +113,8 @@ class AnnotationsIO:
|
|
103
113
|
label_colname (str): Name of the column containing the labels (e.g., GO terms).
|
104
114
|
nodes_colname (str): Name of the column containing the nodes associated with each label.
|
105
115
|
nodes_delimiter (str, optional): Delimiter used to separate multiple nodes within the nodes column (default is ';').
|
116
|
+
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
117
|
+
term to be included. Defaults to 2.
|
106
118
|
|
107
119
|
Returns:
|
108
120
|
Dict[str, Any]: A dictionary where each label is paired with its respective list of nodes,
|
@@ -110,7 +122,9 @@ class AnnotationsIO:
|
|
110
122
|
"""
|
111
123
|
filetype = "CSV"
|
112
124
|
# Log the loading of the CSV file
|
113
|
-
params.log_annotations(
|
125
|
+
params.log_annotations(
|
126
|
+
filetype=filetype, filepath=filepath, min_nodes_per_term=min_nodes_per_term
|
127
|
+
)
|
114
128
|
_log_loading(filetype, filepath=filepath)
|
115
129
|
|
116
130
|
# Load the CSV file into a dictionary
|
@@ -118,8 +132,7 @@ class AnnotationsIO:
|
|
118
132
|
filepath, label_colname, nodes_colname, delimiter=",", nodes_delimiter=nodes_delimiter
|
119
133
|
)
|
120
134
|
|
121
|
-
|
122
|
-
return load_annotations(network, annotations_input)
|
135
|
+
return load_annotations(network, annotations_input, min_nodes_per_term)
|
123
136
|
|
124
137
|
def load_tsv_annotation(
|
125
138
|
self,
|
@@ -128,6 +141,7 @@ class AnnotationsIO:
|
|
128
141
|
label_colname: str = "label",
|
129
142
|
nodes_colname: str = "nodes",
|
130
143
|
nodes_delimiter: str = ";",
|
144
|
+
min_nodes_per_term: int = 2,
|
131
145
|
) -> Dict[str, Any]:
|
132
146
|
"""Load annotations from a TSV file and associate them with the network.
|
133
147
|
|
@@ -137,6 +151,8 @@ class AnnotationsIO:
|
|
137
151
|
label_colname (str): Name of the column containing the labels (e.g., GO terms).
|
138
152
|
nodes_colname (str): Name of the column containing the nodes associated with each label.
|
139
153
|
nodes_delimiter (str, optional): Delimiter used to separate multiple nodes within the nodes column (default is ';').
|
154
|
+
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
155
|
+
term to be included. Defaults to 2.
|
140
156
|
|
141
157
|
Returns:
|
142
158
|
Dict[str, Any]: A dictionary where each label is paired with its respective list of nodes,
|
@@ -144,7 +160,9 @@ class AnnotationsIO:
|
|
144
160
|
"""
|
145
161
|
filetype = "TSV"
|
146
162
|
# Log the loading of the TSV file
|
147
|
-
params.log_annotations(
|
163
|
+
params.log_annotations(
|
164
|
+
filetype=filetype, filepath=filepath, min_nodes_per_term=min_nodes_per_term
|
165
|
+
)
|
148
166
|
_log_loading(filetype, filepath=filepath)
|
149
167
|
|
150
168
|
# Load the TSV file into a dictionary
|
@@ -152,15 +170,18 @@ class AnnotationsIO:
|
|
152
170
|
filepath, label_colname, nodes_colname, delimiter="\t", nodes_delimiter=nodes_delimiter
|
153
171
|
)
|
154
172
|
|
155
|
-
|
156
|
-
return load_annotations(network, annotations_input)
|
173
|
+
return load_annotations(network, annotations_input, min_nodes_per_term)
|
157
174
|
|
158
|
-
def load_dict_annotation(
|
175
|
+
def load_dict_annotation(
|
176
|
+
self, network: nx.Graph, content: Dict[str, Any], min_nodes_per_term: int = 2
|
177
|
+
) -> Dict[str, Any]:
|
159
178
|
"""Load annotations from a provided dictionary and convert them to a dictionary annotation.
|
160
179
|
|
161
180
|
Args:
|
162
181
|
network (NetworkX graph): The network to which the annotations are related.
|
163
182
|
content (Dict[str, Any]): The annotations dictionary to load.
|
183
|
+
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
184
|
+
term to be included. Defaults to 2.
|
164
185
|
|
165
186
|
Returns:
|
166
187
|
Dict[str, Any]: A dictionary containing ordered nodes, ordered annotations, and the annotations matrix.
|
@@ -176,13 +197,8 @@ class AnnotationsIO:
|
|
176
197
|
params.log_annotations(filepath="In-memory dictionary", filetype=filetype)
|
177
198
|
_log_loading(filetype, "In-memory dictionary")
|
178
199
|
|
179
|
-
# Load the annotations
|
180
|
-
|
181
|
-
# Ensure the output is a dictionary
|
182
|
-
if not isinstance(annotations_dict, dict):
|
183
|
-
raise ValueError("Expected output to be a dictionary")
|
184
|
-
|
185
|
-
return annotations_dict
|
200
|
+
# Load the annotations as a dictionary from the provided dictionary
|
201
|
+
return load_annotations(network, content, min_nodes_per_term)
|
186
202
|
|
187
203
|
|
188
204
|
def _load_matrix_file(
|
risk/neighborhoods/__init__.py
CHANGED
risk/neighborhoods/domains.py
CHANGED
@@ -86,13 +86,13 @@ def define_domains(
|
|
86
86
|
return node_to_domain
|
87
87
|
|
88
88
|
|
89
|
-
def
|
89
|
+
def trim_domains(
|
90
90
|
domains: pd.DataFrame,
|
91
91
|
top_annotations: pd.DataFrame,
|
92
92
|
min_cluster_size: int = 5,
|
93
93
|
max_cluster_size: int = 1000,
|
94
94
|
) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
|
95
|
-
"""Trim domains
|
95
|
+
"""Trim domains that do not meet size criteria and find outliers.
|
96
96
|
|
97
97
|
Args:
|
98
98
|
domains (pd.DataFrame): DataFrame of domain data for the network nodes.
|
@@ -101,8 +101,7 @@ def trim_domains_and_top_annotations(
|
|
101
101
|
max_cluster_size (int, optional): Maximum size of a cluster to be retained. Defaults to 1000.
|
102
102
|
|
103
103
|
Returns:
|
104
|
-
Tuple[pd.DataFrame, pd.DataFrame
|
105
|
-
- Trimmed annotations (pd.DataFrame)
|
104
|
+
Tuple[pd.DataFrame, pd.DataFrame]:
|
106
105
|
- Trimmed domains (pd.DataFrame)
|
107
106
|
- A DataFrame with domain labels (pd.DataFrame)
|
108
107
|
"""
|
@@ -155,14 +154,11 @@ def trim_domains_and_top_annotations(
|
|
155
154
|
).set_index("id")
|
156
155
|
|
157
156
|
# Remove invalid domains
|
158
|
-
valid_annotations = top_annotations[~top_annotations["domain"].isin(invalid_domain_ids)].drop(
|
159
|
-
columns=["normalized_value"]
|
160
|
-
)
|
161
157
|
valid_domains = domains[~domains["primary_domain"].isin(invalid_domain_ids)]
|
162
158
|
valid_trimmed_domains_matrix = trimmed_domains_matrix[
|
163
159
|
~trimmed_domains_matrix.index.isin(invalid_domain_ids)
|
164
160
|
]
|
165
|
-
return
|
161
|
+
return valid_domains, valid_trimmed_domains_matrix
|
166
162
|
|
167
163
|
|
168
164
|
def _optimize_silhouette_across_linkage_and_metrics(
|
risk/network/graph/network.py
CHANGED
@@ -27,7 +27,6 @@ class NetworkGraph:
|
|
27
27
|
network: nx.Graph,
|
28
28
|
annotations: Dict[str, Any],
|
29
29
|
neighborhoods: Dict[str, Any],
|
30
|
-
top_annotations: pd.DataFrame,
|
31
30
|
domains: pd.DataFrame,
|
32
31
|
trimmed_domains: pd.DataFrame,
|
33
32
|
node_label_to_node_id_map: Dict[str, Any],
|
@@ -39,24 +38,20 @@ class NetworkGraph:
|
|
39
38
|
network (nx.Graph): The network graph.
|
40
39
|
annotations (Dict[str, Any]): The annotations associated with the network.
|
41
40
|
neighborhoods (Dict[str, Any]): Neighborhood significance data.
|
42
|
-
top_annotations (pd.DataFrame): DataFrame containing annotations data for the network nodes.
|
43
41
|
domains (pd.DataFrame): DataFrame containing domain data for the network nodes.
|
44
42
|
trimmed_domains (pd.DataFrame): DataFrame containing trimmed domain data for the network nodes.
|
45
43
|
node_label_to_node_id_map (Dict[str, Any]): A dictionary mapping node labels to their corresponding IDs.
|
46
44
|
node_significance_sums (np.ndarray): Array containing the significant sums for the nodes.
|
47
45
|
"""
|
48
46
|
# Initialize self.network downstream of the other attributes
|
49
|
-
|
47
|
+
# All public attributes can be accessed after initialization
|
50
48
|
self.domain_id_to_node_ids_map = self._create_domain_id_to_node_ids_map(domains)
|
51
|
-
self.domains = domains
|
52
49
|
self.domain_id_to_domain_terms_map = self._create_domain_id_to_domain_terms_map(
|
53
50
|
trimmed_domains
|
54
51
|
)
|
55
52
|
self.domain_id_to_domain_info_map = self._create_domain_id_to_domain_info_map(
|
56
53
|
trimmed_domains
|
57
54
|
)
|
58
|
-
self.trimmed_domains = trimmed_domains
|
59
|
-
self.node_significance_sums = node_significance_sums
|
60
55
|
self.node_id_to_domain_ids_and_significance_map = (
|
61
56
|
self._create_node_id_to_domain_ids_and_significances(domains)
|
62
57
|
)
|
@@ -64,6 +59,7 @@ class NetworkGraph:
|
|
64
59
|
self.node_label_to_significance_map = dict(
|
65
60
|
zip(node_label_to_node_id_map.keys(), node_significance_sums)
|
66
61
|
)
|
62
|
+
self.node_significance_sums = node_significance_sums
|
67
63
|
self.node_label_to_node_id_map = node_label_to_node_id_map
|
68
64
|
|
69
65
|
# NOTE: Below this point, instance attributes (i.e., self) will be used!
|
@@ -75,6 +71,32 @@ class NetworkGraph:
|
|
75
71
|
# NOTE: Only after the above attributes are initialized, we can create the summary
|
76
72
|
self.summary = AnalysisSummary(annotations, neighborhoods, self)
|
77
73
|
|
74
|
+
def pop(self, domain_id: str) -> None:
|
75
|
+
"""Remove domain ID from instance domain ID mappings. This can be useful for cleaning up
|
76
|
+
domain-specific mappings based on a given criterion, as domain attributes are stored and
|
77
|
+
accessed only in dictionaries modified by this method.
|
78
|
+
|
79
|
+
Args:
|
80
|
+
key (str): The domain ID key to be removed from each mapping.
|
81
|
+
"""
|
82
|
+
# Define the domain mappings to be updated
|
83
|
+
domain_mappings = [
|
84
|
+
self.domain_id_to_node_ids_map,
|
85
|
+
self.domain_id_to_domain_terms_map,
|
86
|
+
self.domain_id_to_domain_info_map,
|
87
|
+
self.domain_id_to_node_labels_map,
|
88
|
+
]
|
89
|
+
# Remove the specified domain_id key from each mapping if it exists
|
90
|
+
for mapping in domain_mappings:
|
91
|
+
if domain_id in mapping:
|
92
|
+
mapping.pop(domain_id)
|
93
|
+
|
94
|
+
# Remove the domain_id from the node_id_to_domain_ids_and_significance_map
|
95
|
+
for node_id, domain_info in self.node_id_to_domain_ids_and_significance_map.items():
|
96
|
+
if domain_id in domain_info["domains"]:
|
97
|
+
domain_info["domains"].remove(domain_id)
|
98
|
+
domain_info["significances"].pop(domain_id)
|
99
|
+
|
78
100
|
@staticmethod
|
79
101
|
def _create_domain_id_to_node_ids_map(domains: pd.DataFrame) -> Dict[int, Any]:
|
80
102
|
"""Create a mapping from domains to the list of node IDs belonging to each domain.
|
risk/network/plot/canvas.py
CHANGED
@@ -10,7 +10,7 @@ import numpy as np
|
|
10
10
|
|
11
11
|
from risk.log import params
|
12
12
|
from risk.network.graph import NetworkGraph
|
13
|
-
from risk.network.plot.utils.
|
13
|
+
from risk.network.plot.utils.colors import to_rgba
|
14
14
|
from risk.network.plot.utils.layout import calculate_bounding_box
|
15
15
|
|
16
16
|
|
risk/network/plot/contour.py
CHANGED
@@ -13,7 +13,7 @@ from scipy.stats import gaussian_kde
|
|
13
13
|
|
14
14
|
from risk.log import params, logger
|
15
15
|
from risk.network.graph import NetworkGraph
|
16
|
-
from risk.network.plot.utils.
|
16
|
+
from risk.network.plot.utils.colors import get_annotated_domain_colors, to_rgba
|
17
17
|
|
18
18
|
|
19
19
|
class Contour:
|
risk/network/plot/labels.py
CHANGED
@@ -12,7 +12,7 @@ import pandas as pd
|
|
12
12
|
|
13
13
|
from risk.log import params
|
14
14
|
from risk.network.graph import NetworkGraph
|
15
|
-
from risk.network.plot.utils.
|
15
|
+
from risk.network.plot.utils.colors import get_annotated_domain_colors, to_rgba
|
16
16
|
from risk.network.plot.utils.layout import calculate_bounding_box
|
17
17
|
|
18
18
|
TERM_DELIMITER = "::::" # String used to separate multiple domain terms when constructing composite domain labels
|
risk/network/plot/network.py
CHANGED
@@ -10,7 +10,7 @@ import numpy as np
|
|
10
10
|
|
11
11
|
from risk.log import params
|
12
12
|
from risk.network.graph import NetworkGraph
|
13
|
-
from risk.network.plot.utils.
|
13
|
+
from risk.network.plot.utils.colors import get_domain_colors, to_rgba
|
14
14
|
|
15
15
|
|
16
16
|
class Network:
|
risk/network/plot/plotter.py
CHANGED
@@ -14,7 +14,7 @@ from risk.network.plot.canvas import Canvas
|
|
14
14
|
from risk.network.plot.contour import Contour
|
15
15
|
from risk.network.plot.labels import Labels
|
16
16
|
from risk.network.plot.network import Network
|
17
|
-
from risk.network.plot.utils.
|
17
|
+
from risk.network.plot.utils.colors import to_rgba
|
18
18
|
from risk.network.plot.utils.layout import calculate_bounding_box
|
19
19
|
|
20
20
|
|
risk/risk.py
CHANGED
@@ -16,7 +16,7 @@ from risk.neighborhoods import (
|
|
16
16
|
define_domains,
|
17
17
|
get_network_neighborhoods,
|
18
18
|
process_neighborhoods,
|
19
|
-
|
19
|
+
trim_domains,
|
20
20
|
)
|
21
21
|
from risk.network import NetworkIO, NetworkGraph, NetworkPlotter
|
22
22
|
from risk.stats import (
|
@@ -335,16 +335,20 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
335
335
|
)
|
336
336
|
|
337
337
|
log_header("Optimizing distance threshold for domains")
|
338
|
+
# Extract the significant significance matrix from the neighborhoods data
|
339
|
+
significant_neighborhoods_significance = processed_neighborhoods[
|
340
|
+
"significant_significance_matrix"
|
341
|
+
]
|
338
342
|
# Define domains in the network using the specified clustering settings
|
339
|
-
domains =
|
340
|
-
neighborhoods=processed_neighborhoods,
|
343
|
+
domains = define_domains(
|
341
344
|
top_annotations=top_annotations,
|
345
|
+
significant_neighborhoods_significance=significant_neighborhoods_significance,
|
342
346
|
linkage_criterion=linkage_criterion,
|
343
347
|
linkage_method=linkage_method,
|
344
348
|
linkage_metric=linkage_metric,
|
345
349
|
)
|
346
350
|
# Trim domains and top annotations based on cluster size constraints
|
347
|
-
|
351
|
+
domains, trimmed_domains = trim_domains(
|
348
352
|
domains=domains,
|
349
353
|
top_annotations=top_annotations,
|
350
354
|
min_cluster_size=min_cluster_size,
|
@@ -361,7 +365,6 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
361
365
|
network=network,
|
362
366
|
annotations=annotations,
|
363
367
|
neighborhoods=neighborhoods,
|
364
|
-
top_annotations=top_annotations,
|
365
368
|
domains=domains,
|
366
369
|
trimmed_domains=trimmed_domains,
|
367
370
|
node_label_to_node_id_map=node_label_to_id,
|
@@ -484,34 +487,3 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
484
487
|
min_cluster_size=min_cluster_size,
|
485
488
|
max_cluster_size=max_cluster_size,
|
486
489
|
)
|
487
|
-
|
488
|
-
def _define_domains(
|
489
|
-
self,
|
490
|
-
neighborhoods: Dict[str, Any],
|
491
|
-
top_annotations: pd.DataFrame,
|
492
|
-
linkage_criterion: str,
|
493
|
-
linkage_method: str,
|
494
|
-
linkage_metric: str,
|
495
|
-
) -> pd.DataFrame:
|
496
|
-
"""Define domains in the network based on significance data.
|
497
|
-
|
498
|
-
Args:
|
499
|
-
neighborhoods (Dict[str, Any]): Enrichment data for neighborhoods.
|
500
|
-
top_annotations (pd.DataFrame): Enrichment matrix for top annotations.
|
501
|
-
linkage_criterion (str): Clustering criterion for defining domains.
|
502
|
-
linkage_method (str): Clustering method to use.
|
503
|
-
linkage_metric (str): Metric to use for calculating distances.
|
504
|
-
|
505
|
-
Returns:
|
506
|
-
pd.DataFrame: Matrix of defined domains.
|
507
|
-
"""
|
508
|
-
# Extract the significant significance matrix from the neighborhoods data
|
509
|
-
significant_neighborhoods_significance = neighborhoods["significant_significance_matrix"]
|
510
|
-
# Call external function to define domains based on the extracted data
|
511
|
-
return define_domains(
|
512
|
-
top_annotations=top_annotations,
|
513
|
-
significant_neighborhoods_significance=significant_neighborhoods_significance,
|
514
|
-
linkage_criterion=linkage_criterion,
|
515
|
-
linkage_method=linkage_method,
|
516
|
-
linkage_metric=linkage_metric,
|
517
|
-
)
|
@@ -1,29 +1,29 @@
|
|
1
|
-
risk/__init__.py,sha256=
|
1
|
+
risk/__init__.py,sha256=qkmHFIeApkRQEVhb6MctmvmD84ri0SRmooehDAeIV2k,112
|
2
2
|
risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
|
3
|
-
risk/risk.py,sha256=
|
3
|
+
risk/risk.py,sha256=kntBxYwAEpoAjXN_l6BM3yxFKyuAKmd8OMGl2P00pZ4,22416
|
4
4
|
risk/annotations/__init__.py,sha256=kXgadEXaCh0z8OyhOhTj7c3qXGmWgOhaSZ4gSzSb59U,147
|
5
|
-
risk/annotations/annotations.py,sha256=
|
6
|
-
risk/annotations/io.py,sha256=
|
5
|
+
risk/annotations/annotations.py,sha256=WVT9wzTm8lTpMw_3SnbyljWR77yExo0rb1zVgJza8nw,14284
|
6
|
+
risk/annotations/io.py,sha256=tk1dAsxIwW5oLxB294ppiuZd4__Y5pj8se8KhitRSNA,10554
|
7
7
|
risk/log/__init__.py,sha256=gy7C5L6D222AYUChq5lkc0LsCJ_QMQPaFiBJKbecdac,201
|
8
8
|
risk/log/console.py,sha256=C52s3FgQ2e9kQWcXL8m7rs_pnKXt5Yy8PBHmQkOTiNo,4537
|
9
9
|
risk/log/parameters.py,sha256=o4StqYCa0kt7_Ht4mKa1DwwvhGUwkC_dGBaiUIc0GB0,5683
|
10
|
-
risk/neighborhoods/__init__.py,sha256=
|
10
|
+
risk/neighborhoods/__init__.py,sha256=C-SD0G-9skSLjLFdAB6v6lAjO8la2v6Fqy63h2MY28k,186
|
11
11
|
risk/neighborhoods/community.py,sha256=MAgIblbuisEPwVU6mFZd4Yd9NUKlaHK99suw51r1Is0,7065
|
12
|
-
risk/neighborhoods/domains.py,sha256=
|
12
|
+
risk/neighborhoods/domains.py,sha256=t91xSpx9Ty9hSlhRq2_XwyPpBP7sjKhovcPPvkwWtf0,11398
|
13
13
|
risk/neighborhoods/neighborhoods.py,sha256=0TAP-xi4hgtnrK0cKQPHQHq9IVGHOMF1wYEcx6tsxRA,22241
|
14
14
|
risk/network/__init__.py,sha256=iEPeJdZfqp0toxtbElryB8jbz9_t_k4QQ3iDvKE8C_0,126
|
15
15
|
risk/network/geometry.py,sha256=gFtYUj9j9aul4paKq_qSGJn39Nazxu_MXv8m-tYYtrk,6840
|
16
16
|
risk/network/io.py,sha256=AWSbZGLZHtl72KSlafQlcYoG00YLSznG7UYDi_wDT7M,22958
|
17
17
|
risk/network/graph/__init__.py,sha256=H0YEiwqZ02LBTkH4blPwUjQ-DOUnhaTTNHM0BcXii6U,81
|
18
|
-
risk/network/graph/network.py,sha256=
|
18
|
+
risk/network/graph/network.py,sha256=JzYbrgJLiNWFyPIR6_qNSjMtmXmfzRv2FwWSdyg8HjY,12205
|
19
19
|
risk/network/graph/summary.py,sha256=h2bpUjfwI1NMflkKwplGQEGPswfAtunormdTIEQYbvs,8987
|
20
20
|
risk/network/plot/__init__.py,sha256=MfmaXJgAZJgXZ2wrhK8pXwzETlcMaLChhWXKAozniAo,98
|
21
|
-
risk/network/plot/canvas.py,sha256=
|
22
|
-
risk/network/plot/contour.py,sha256=
|
23
|
-
risk/network/plot/labels.py,sha256=
|
24
|
-
risk/network/plot/network.py,sha256=
|
25
|
-
risk/network/plot/plotter.py,sha256=
|
26
|
-
risk/network/plot/utils/
|
21
|
+
risk/network/plot/canvas.py,sha256=W8dFv4XYTzCWXBchgsc0esOQRn4usM4LkwNGPSDMobE,13357
|
22
|
+
risk/network/plot/contour.py,sha256=VONX9l6owrZvWtR0mWQ6z2GSd1YXIv5wV_sf5ROQLT4,15581
|
23
|
+
risk/network/plot/labels.py,sha256=eorP80CmAbHmt7de2qHna1tHGKL8YiHknwFW2R3tvjI,45734
|
24
|
+
risk/network/plot/network.py,sha256=_K8Am2y6zSGrm3fAgMbXxzgspbugJi3uK4_tG8qqGoI,14015
|
25
|
+
risk/network/plot/plotter.py,sha256=eS1vHqvOA2O001Rq7WiDcgqcehJ3fg4OPfvkezH4erw,5771
|
26
|
+
risk/network/plot/utils/colors.py,sha256=k_461yoLgE7OxFYnpjU-Am1XFUbnOogiPqlVFYlwViQ,20803
|
27
27
|
risk/network/plot/utils/layout.py,sha256=6o7idoWQnyzujSWOFXQykUvyPy8NuRtJV04TnlbXXBo,3647
|
28
28
|
risk/stats/__init__.py,sha256=WcgoETQ-hS0LQqKRsAMIPtP15xZ-4eul6VUBuUx4Wzc,220
|
29
29
|
risk/stats/hypergeom.py,sha256=oc39f02ViB1vQ-uaDrxG_tzAT6dxQBRjc88EK2EGn78,2282
|
@@ -32,8 +32,8 @@ risk/stats/stats.py,sha256=z8NrhiVj4BzJ250bVLfytpmfC7RzYu7mBuIZD_l0aCA,7222
|
|
32
32
|
risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
|
33
33
|
risk/stats/permutation/permutation.py,sha256=meBNSrbRa9P8WJ54n485l0H7VQJlMSfHqdN4aCKYCtQ,10105
|
34
34
|
risk/stats/permutation/test_functions.py,sha256=lftOude6hee0pyR80HlBD32522JkDoN5hrKQ9VEbuoY,2345
|
35
|
-
risk_network-0.0.
|
36
|
-
risk_network-0.0.
|
37
|
-
risk_network-0.0.
|
38
|
-
risk_network-0.0.
|
39
|
-
risk_network-0.0.
|
35
|
+
risk_network-0.0.9b7.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
|
36
|
+
risk_network-0.0.9b7.dist-info/METADATA,sha256=Ss2U9ENOyI2wMdGcSPG0KVcE41sigd_hZZL0XosvpWM,47497
|
37
|
+
risk_network-0.0.9b7.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
38
|
+
risk_network-0.0.9b7.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
|
39
|
+
risk_network-0.0.9b7.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|