risk-network 0.0.13b4__tar.gz → 0.0.13b5__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.
- {risk_network-0.0.13b4/src/risk_network.egg-info → risk_network-0.0.13b5}/PKG-INFO +1 -1
- risk_network-0.0.13b5/src/risk/__init__.py +11 -0
- risk_network-0.0.13b5/src/risk/_annotation/__init__.py +10 -0
- risk_network-0.0.13b4/src/risk/annotation/annotation.py → risk_network-0.0.13b5/src/risk/_annotation/_annotation.py +18 -11
- risk_network-0.0.13b4/src/risk/annotation/io.py → risk_network-0.0.13b5/src/risk/_annotation/_io.py +20 -12
- risk_network-0.0.13b4/src/risk/annotation/nltk_setup.py → risk_network-0.0.13b5/src/risk/_annotation/_nltk_setup.py +7 -5
- risk_network-0.0.13b5/src/risk/_log/__init__.py +11 -0
- risk_network-0.0.13b4/src/risk/log/console.py → risk_network-0.0.13b5/src/risk/_log/_console.py +22 -12
- risk_network-0.0.13b4/src/risk/log/parameters.py → risk_network-0.0.13b5/src/risk/_log/_parameters.py +25 -14
- risk_network-0.0.13b5/src/risk/_neighborhoods/__init__.py +8 -0
- risk_network-0.0.13b4/src/risk/neighborhoods/api.py → risk_network-0.0.13b5/src/risk/_neighborhoods/_api.py +23 -14
- risk_network-0.0.13b4/src/risk/neighborhoods/community.py → risk_network-0.0.13b5/src/risk/_neighborhoods/_community.py +19 -11
- risk_network-0.0.13b4/src/risk/neighborhoods/domains.py → risk_network-0.0.13b5/src/risk/_neighborhoods/_domains.py +15 -9
- risk_network-0.0.13b4/src/risk/neighborhoods/neighborhoods.py → risk_network-0.0.13b5/src/risk/_neighborhoods/_neighborhoods.py +24 -35
- risk_network-0.0.13b5/src/risk/_neighborhoods/_stats/__init__.py +13 -0
- risk_network-0.0.13b5/src/risk/_neighborhoods/_stats/_permutation/__init__.py +6 -0
- risk_network-0.0.13b4/src/risk/neighborhoods/stats/permutation/permutation.py → risk_network-0.0.13b5/src/risk/_neighborhoods/_stats/_permutation/_permutation.py +9 -6
- risk_network-0.0.13b4/src/risk/neighborhoods/stats/permutation/test_functions.py → risk_network-0.0.13b5/src/risk/_neighborhoods/_stats/_permutation/_test_functions.py +6 -4
- risk_network-0.0.13b4/src/risk/neighborhoods/stats/tests.py → risk_network-0.0.13b5/src/risk/_neighborhoods/_stats/_tests.py +12 -7
- risk_network-0.0.13b5/src/risk/_network/__init__.py +8 -0
- risk_network-0.0.13b5/src/risk/_network/_graph/__init__.py +7 -0
- risk_network-0.0.13b4/src/risk/network/graph/api.py → risk_network-0.0.13b5/src/risk/_network/_graph/_api.py +13 -10
- risk_network-0.0.13b4/src/risk/network/graph/graph.py → risk_network-0.0.13b5/src/risk/_network/_graph/_graph.py +24 -13
- risk_network-0.0.13b4/src/risk/network/graph/stats.py → risk_network-0.0.13b5/src/risk/_network/_graph/_stats.py +8 -5
- risk_network-0.0.13b4/src/risk/network/graph/summary.py → risk_network-0.0.13b5/src/risk/_network/_graph/_summary.py +21 -12
- risk_network-0.0.13b4/src/risk/network/io.py → risk_network-0.0.13b5/src/risk/_network/_io.py +45 -24
- risk_network-0.0.13b5/src/risk/_network/_plotter/__init__.py +6 -0
- risk_network-0.0.13b4/src/risk/network/plotter/api.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_api.py +9 -7
- risk_network-0.0.13b4/src/risk/network/plotter/canvas.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_canvas.py +14 -10
- risk_network-0.0.13b4/src/risk/network/plotter/contour.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_contour.py +17 -11
- risk_network-0.0.13b4/src/risk/network/plotter/labels.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_labels.py +38 -23
- risk_network-0.0.13b4/src/risk/network/plotter/network.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_network.py +17 -11
- risk_network-0.0.13b4/src/risk/network/plotter/plotter.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_plotter.py +19 -15
- risk_network-0.0.13b5/src/risk/_network/_plotter/_utils/__init__.py +7 -0
- risk_network-0.0.13b4/src/risk/network/plotter/utils/colors.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_utils/_colors.py +19 -11
- risk_network-0.0.13b4/src/risk/network/plotter/utils/layout.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_utils/_layout.py +8 -5
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/src/risk/risk.py +8 -8
- {risk_network-0.0.13b4 → risk_network-0.0.13b5/src/risk_network.egg-info}/PKG-INFO +1 -1
- risk_network-0.0.13b5/src/risk_network.egg-info/SOURCES.txt +51 -0
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/tests/test_load_annotation.py +26 -13
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/tests/test_load_graph.py +21 -11
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/tests/test_load_io_combinations.py +2 -1
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/tests/test_load_neighborhoods.py +24 -12
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/tests/test_load_network.py +32 -16
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/tests/test_load_plotter.py +62 -31
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/tests/test_log.py +9 -10
- risk_network-0.0.13b4/src/risk/__init__.py +0 -10
- risk_network-0.0.13b4/src/risk/annotation/__init__.py +0 -10
- risk_network-0.0.13b4/src/risk/log/__init__.py +0 -11
- risk_network-0.0.13b4/src/risk/neighborhoods/__init__.py +0 -7
- risk_network-0.0.13b4/src/risk/neighborhoods/stats/__init__.py +0 -13
- risk_network-0.0.13b4/src/risk/neighborhoods/stats/permutation/__init__.py +0 -6
- risk_network-0.0.13b4/src/risk/network/__init__.py +0 -4
- risk_network-0.0.13b4/src/risk/network/graph/__init__.py +0 -4
- risk_network-0.0.13b4/src/risk/network/plotter/__init__.py +0 -4
- risk_network-0.0.13b4/src/risk_network.egg-info/SOURCES.txt +0 -50
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/LICENSE +0 -0
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/README.md +0 -0
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/pyproject.toml +0 -0
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/setup.cfg +0 -0
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/src/risk_network.egg-info/dependency_links.txt +0 -0
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/src/risk_network.egg-info/requires.txt +0 -0
- {risk_network-0.0.13b4 → risk_network-0.0.13b5}/src/risk_network.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_annotation/_annotation
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
import re
|
@@ -14,12 +14,13 @@ import pandas as pd
|
|
14
14
|
from nltk.tokenize import word_tokenize
|
15
15
|
from scipy.sparse import coo_matrix
|
16
16
|
|
17
|
-
from
|
18
|
-
from
|
17
|
+
from .._log import logger
|
18
|
+
from ._nltk_setup import setup_nltk_resources
|
19
19
|
|
20
20
|
|
21
21
|
def initialize_nltk():
|
22
|
-
"""
|
22
|
+
"""
|
23
|
+
Initialize all required NLTK components."""
|
23
24
|
setup_nltk_resources()
|
24
25
|
|
25
26
|
# After resources are available, initialize the components
|
@@ -41,7 +42,8 @@ def load_annotation(
|
|
41
42
|
min_nodes_per_term: int = 1,
|
42
43
|
max_nodes_per_term: int = 10_000,
|
43
44
|
) -> Dict[str, Any]:
|
44
|
-
"""
|
45
|
+
"""
|
46
|
+
Convert annotation input to a sparse matrix and reindex based on the network's node labels.
|
45
47
|
|
46
48
|
Args:
|
47
49
|
network (nx.Graph): The network graph.
|
@@ -127,7 +129,8 @@ def define_top_annotation(
|
|
127
129
|
min_cluster_size: int = 5,
|
128
130
|
max_cluster_size: int = 1000,
|
129
131
|
) -> pd.DataFrame:
|
130
|
-
"""
|
132
|
+
"""
|
133
|
+
Define top annotations based on neighborhood significance sums and binary significance matrix.
|
131
134
|
|
132
135
|
Args:
|
133
136
|
network (NetworkX graph): The network graph.
|
@@ -218,7 +221,8 @@ def define_top_annotation(
|
|
218
221
|
|
219
222
|
|
220
223
|
def get_weighted_description(words_column: pd.Series, scores_column: pd.Series) -> str:
|
221
|
-
"""
|
224
|
+
"""
|
225
|
+
Generate a weighted description from words and their corresponding scores,
|
222
226
|
using improved weighting logic with normalization, lemmatization, and aggregation.
|
223
227
|
|
224
228
|
Args:
|
@@ -286,7 +290,8 @@ def get_weighted_description(words_column: pd.Series, scores_column: pd.Series)
|
|
286
290
|
|
287
291
|
|
288
292
|
def _simplify_word_list(words: List[str], threshold: float = 0.80) -> List[str]:
|
289
|
-
"""
|
293
|
+
"""
|
294
|
+
Filter out words that are too similar based on the Jaccard index,
|
290
295
|
keeping the word with the higher aggregated count.
|
291
296
|
|
292
297
|
Args:
|
@@ -326,7 +331,8 @@ def _simplify_word_list(words: List[str], threshold: float = 0.80) -> List[str]:
|
|
326
331
|
|
327
332
|
|
328
333
|
def _calculate_jaccard_index(set1: Set[Any], set2: Set[Any]) -> float:
|
329
|
-
"""
|
334
|
+
"""
|
335
|
+
Calculate the Jaccard index between two sets.
|
330
336
|
|
331
337
|
Args:
|
332
338
|
set1 (Set[Any]): The first set.
|
@@ -341,7 +347,8 @@ def _calculate_jaccard_index(set1: Set[Any], set2: Set[Any]) -> float:
|
|
341
347
|
|
342
348
|
|
343
349
|
def _generate_coherent_description(words: List[str]) -> str:
|
344
|
-
"""
|
350
|
+
"""
|
351
|
+
Generate a coherent description from a list of words.
|
345
352
|
|
346
353
|
If there is only one unique entry, return it directly.
|
347
354
|
Otherwise, order the words by frequency and join them into a single string.
|
risk_network-0.0.13b4/src/risk/annotation/io.py → risk_network-0.0.13b5/src/risk/_annotation/_io.py
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_annotation/_io
|
3
|
+
~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
import json
|
@@ -9,12 +9,13 @@ from typing import Any, Dict
|
|
9
9
|
import networkx as nx
|
10
10
|
import pandas as pd
|
11
11
|
|
12
|
-
from
|
13
|
-
from
|
12
|
+
from .._log import log_header, logger, params
|
13
|
+
from ._annotation import load_annotation
|
14
14
|
|
15
15
|
|
16
16
|
class AnnotationIO:
|
17
|
-
"""
|
17
|
+
"""
|
18
|
+
Handles the loading and exporting of annotation in various file formats.
|
18
19
|
|
19
20
|
The AnnotationIO class provides methods to load annotation from different file types (JSON, CSV, Excel, etc.)
|
20
21
|
and to export parameter data to various formats like JSON, CSV, and text files.
|
@@ -27,7 +28,8 @@ class AnnotationIO:
|
|
27
28
|
min_nodes_per_term: int = 1,
|
28
29
|
max_nodes_per_term: int = 10_000,
|
29
30
|
) -> Dict[str, Any]:
|
30
|
-
"""
|
31
|
+
"""
|
32
|
+
Load annotation from a JSON file and convert them to a DataFrame.
|
31
33
|
|
32
34
|
Args:
|
33
35
|
network (NetworkX graph): The network to which the annotation is related.
|
@@ -67,7 +69,8 @@ class AnnotationIO:
|
|
67
69
|
min_nodes_per_term: int = 1,
|
68
70
|
max_nodes_per_term: int = 10_000,
|
69
71
|
) -> Dict[str, Any]:
|
70
|
-
"""
|
72
|
+
"""
|
73
|
+
Load annotation from an Excel file and associate them with the network.
|
71
74
|
|
72
75
|
Args:
|
73
76
|
network (nx.Graph): The NetworkX graph to which the annotation is related.
|
@@ -116,7 +119,8 @@ class AnnotationIO:
|
|
116
119
|
min_nodes_per_term: int = 1,
|
117
120
|
max_nodes_per_term: int = 10_000,
|
118
121
|
) -> Dict[str, Any]:
|
119
|
-
"""
|
122
|
+
"""
|
123
|
+
Load annotation from a CSV file and associate them with the network.
|
120
124
|
|
121
125
|
Args:
|
122
126
|
network (nx.Graph): The NetworkX graph to which the annotation is related.
|
@@ -160,7 +164,8 @@ class AnnotationIO:
|
|
160
164
|
min_nodes_per_term: int = 1,
|
161
165
|
max_nodes_per_term: int = 10_000,
|
162
166
|
) -> Dict[str, Any]:
|
163
|
-
"""
|
167
|
+
"""
|
168
|
+
Load annotation from a TSV file and associate them with the network.
|
164
169
|
|
165
170
|
Args:
|
166
171
|
network (nx.Graph): The NetworkX graph to which the annotation is related.
|
@@ -201,7 +206,8 @@ class AnnotationIO:
|
|
201
206
|
min_nodes_per_term: int = 1,
|
202
207
|
max_nodes_per_term: int = 10_000,
|
203
208
|
) -> Dict[str, Any]:
|
204
|
-
"""
|
209
|
+
"""
|
210
|
+
Load annotation from a provided dictionary and convert them to a dictionary annotation.
|
205
211
|
|
206
212
|
Args:
|
207
213
|
network (NetworkX graph): The network to which the annotation is related.
|
@@ -244,7 +250,8 @@ class AnnotationIO:
|
|
244
250
|
delimiter: str = ",",
|
245
251
|
nodes_delimiter: str = ";",
|
246
252
|
) -> Dict[str, Any]:
|
247
|
-
"""
|
253
|
+
"""
|
254
|
+
Load annotation from a CSV or TSV file and convert them to a dictionary.
|
248
255
|
|
249
256
|
Args:
|
250
257
|
filepath (str): Path to the annotation file.
|
@@ -267,7 +274,8 @@ class AnnotationIO:
|
|
267
274
|
return label_node_dict
|
268
275
|
|
269
276
|
def _log_loading_annotation(self, filetype: str, filepath: str = "") -> None:
|
270
|
-
"""
|
277
|
+
"""
|
278
|
+
Log the loading of annotation files.
|
271
279
|
|
272
280
|
Args:
|
273
281
|
filetype (str): The type of the file being loaded (e.g., 'Cytoscape').
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_annotation/_nltk_setup
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
import os
|
@@ -11,11 +11,12 @@ import nltk
|
|
11
11
|
from nltk.data import find
|
12
12
|
from nltk.data import path as nltk_data_path
|
13
13
|
|
14
|
-
from
|
14
|
+
from .._log import logger
|
15
15
|
|
16
16
|
|
17
17
|
def setup_nltk_resources(required_resources: Optional[List[Tuple[str, str]]] = None) -> None:
|
18
|
-
"""
|
18
|
+
"""
|
19
|
+
Ensures all required NLTK resources are available and properly extracted.
|
19
20
|
Uses NLTK's default paths and mechanisms.
|
20
21
|
|
21
22
|
Args:
|
@@ -47,7 +48,8 @@ def setup_nltk_resources(required_resources: Optional[List[Tuple[str, str]]] = N
|
|
47
48
|
|
48
49
|
|
49
50
|
def verify_and_extract_if_needed(resource_path: str, package_name: str) -> None:
|
50
|
-
"""
|
51
|
+
"""
|
52
|
+
Verifies if the resource is properly extracted and extracts if needed. Respects
|
51
53
|
NLTK's directory structure where the extracted content should be in the same directory
|
52
54
|
as the zip file.
|
53
55
|
|
risk_network-0.0.13b4/src/risk/log/console.py → risk_network-0.0.13b5/src/risk/_log/_console.py
RENAMED
@@ -1,13 +1,14 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_log/_console
|
3
|
+
~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
import logging
|
7
7
|
|
8
8
|
|
9
9
|
def in_jupyter():
|
10
|
-
"""
|
10
|
+
"""
|
11
|
+
Check if the code is running in a Jupyter notebook environment.
|
11
12
|
|
12
13
|
Returns:
|
13
14
|
bool: True if running in a Jupyter notebook or QtConsole, False otherwise.
|
@@ -26,7 +27,8 @@ def in_jupyter():
|
|
26
27
|
|
27
28
|
# Define the MockLogger class to replicate logging behavior with print statements in Jupyter
|
28
29
|
class MockLogger:
|
29
|
-
"""
|
30
|
+
"""
|
31
|
+
MockLogger: A lightweight logger replacement using print statements in Jupyter.
|
30
32
|
|
31
33
|
The MockLogger class replicates the behavior of a standard logger using print statements
|
32
34
|
to display messages. This is primarily used in a Jupyter environment to show outputs
|
@@ -35,7 +37,8 @@ class MockLogger:
|
|
35
37
|
"""
|
36
38
|
|
37
39
|
def __init__(self, verbose: bool = True):
|
38
|
-
"""
|
40
|
+
"""
|
41
|
+
Initialize the MockLogger with verbosity settings.
|
39
42
|
|
40
43
|
Args:
|
41
44
|
verbose (bool): If True, display all log messages (info, debug, warning).
|
@@ -44,7 +47,8 @@ class MockLogger:
|
|
44
47
|
self.verbose = verbose
|
45
48
|
|
46
49
|
def info(self, message: str) -> None:
|
47
|
-
"""
|
50
|
+
"""
|
51
|
+
Display an informational message.
|
48
52
|
|
49
53
|
Args:
|
50
54
|
message (str): The informational message to be printed.
|
@@ -53,7 +57,8 @@ class MockLogger:
|
|
53
57
|
print(message)
|
54
58
|
|
55
59
|
def debug(self, message: str) -> None:
|
56
|
-
"""
|
60
|
+
"""
|
61
|
+
Display a debug message.
|
57
62
|
|
58
63
|
Args:
|
59
64
|
message (str): The debug message to be printed.
|
@@ -62,7 +67,8 @@ class MockLogger:
|
|
62
67
|
print(message)
|
63
68
|
|
64
69
|
def warning(self, message: str) -> None:
|
65
|
-
"""
|
70
|
+
"""
|
71
|
+
Display a warning message.
|
66
72
|
|
67
73
|
Args:
|
68
74
|
message (str): The warning message to be printed.
|
@@ -70,7 +76,8 @@ class MockLogger:
|
|
70
76
|
print(message)
|
71
77
|
|
72
78
|
def error(self, message: str) -> None:
|
73
|
-
"""
|
79
|
+
"""
|
80
|
+
Display an error message.
|
74
81
|
|
75
82
|
Args:
|
76
83
|
message (str): The error message to be printed.
|
@@ -78,7 +85,8 @@ class MockLogger:
|
|
78
85
|
print(message)
|
79
86
|
|
80
87
|
def setLevel(self, level: int) -> None:
|
81
|
-
"""
|
88
|
+
"""
|
89
|
+
Adjust verbosity based on the logging level.
|
82
90
|
|
83
91
|
Args:
|
84
92
|
level (int): Logging level to control message display.
|
@@ -108,7 +116,8 @@ else:
|
|
108
116
|
|
109
117
|
|
110
118
|
def set_global_verbosity(verbose):
|
111
|
-
"""
|
119
|
+
"""
|
120
|
+
Set the global verbosity level for the logger.
|
112
121
|
|
113
122
|
Args:
|
114
123
|
verbose (bool): Whether to display all log messages (True) or only error messages (False).
|
@@ -130,7 +139,8 @@ def set_global_verbosity(verbose):
|
|
130
139
|
|
131
140
|
|
132
141
|
def log_header(input_string: str) -> None:
|
133
|
-
"""
|
142
|
+
"""
|
143
|
+
Log the input string as a header with a line of dashes above and below it.
|
134
144
|
|
135
145
|
Args:
|
136
146
|
input_string (str): The string to be printed as a header.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_log/_parameters
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
import csv
|
@@ -11,14 +11,15 @@ from typing import Any, Dict
|
|
11
11
|
|
12
12
|
import numpy as np
|
13
13
|
|
14
|
-
from
|
14
|
+
from ._console import log_header, logger
|
15
15
|
|
16
16
|
# Suppress all warnings - this is to resolve warnings from multiprocessing
|
17
17
|
warnings.filterwarnings("ignore")
|
18
18
|
|
19
19
|
|
20
20
|
class Params:
|
21
|
-
"""
|
21
|
+
"""
|
22
|
+
Handles the storage and logging of various parameters for network analysis.
|
22
23
|
|
23
24
|
The Params class provides methods to log parameters related to different components of the analysis,
|
24
25
|
such as the network, annotation, neighborhoods, graph, and plotter settings. It also stores
|
@@ -39,7 +40,8 @@ class Params:
|
|
39
40
|
self.plotter = {}
|
40
41
|
|
41
42
|
def log_network(self, **kwargs) -> None:
|
42
|
-
"""
|
43
|
+
"""
|
44
|
+
Log network-related parameters.
|
43
45
|
|
44
46
|
Args:
|
45
47
|
**kwargs: Network parameters to log.
|
@@ -47,7 +49,8 @@ class Params:
|
|
47
49
|
self.network = {**self.network, **kwargs}
|
48
50
|
|
49
51
|
def log_annotation(self, **kwargs) -> None:
|
50
|
-
"""
|
52
|
+
"""
|
53
|
+
Log annotation-related parameters.
|
51
54
|
|
52
55
|
Args:
|
53
56
|
**kwargs: Annotation parameters to log.
|
@@ -55,7 +58,8 @@ class Params:
|
|
55
58
|
self.annotation = {**self.annotation, **kwargs}
|
56
59
|
|
57
60
|
def log_neighborhoods(self, **kwargs) -> None:
|
58
|
-
"""
|
61
|
+
"""
|
62
|
+
Log neighborhood-related parameters.
|
59
63
|
|
60
64
|
Args:
|
61
65
|
**kwargs: Neighborhood parameters to log.
|
@@ -63,7 +67,8 @@ class Params:
|
|
63
67
|
self.neighborhoods = {**self.neighborhoods, **kwargs}
|
64
68
|
|
65
69
|
def log_graph(self, **kwargs) -> None:
|
66
|
-
"""
|
70
|
+
"""
|
71
|
+
Log graph-related parameters.
|
67
72
|
|
68
73
|
Args:
|
69
74
|
**kwargs: Graph parameters to log.
|
@@ -71,7 +76,8 @@ class Params:
|
|
71
76
|
self.graph = {**self.graph, **kwargs}
|
72
77
|
|
73
78
|
def log_plotter(self, **kwargs) -> None:
|
74
|
-
"""
|
79
|
+
"""
|
80
|
+
Log plotter-related parameters.
|
75
81
|
|
76
82
|
Args:
|
77
83
|
**kwargs: Plotter parameters to log.
|
@@ -79,7 +85,8 @@ class Params:
|
|
79
85
|
self.plotter = {**self.plotter, **kwargs}
|
80
86
|
|
81
87
|
def to_csv(self, filepath: str) -> None:
|
82
|
-
"""
|
88
|
+
"""
|
89
|
+
Export the parameters to a CSV file.
|
83
90
|
|
84
91
|
Args:
|
85
92
|
filepath (str): The path where the CSV file will be saved.
|
@@ -102,7 +109,8 @@ class Params:
|
|
102
109
|
logger.info(f"Parameters exported to CSV file: {filepath}")
|
103
110
|
|
104
111
|
def to_json(self, filepath: str) -> None:
|
105
|
-
"""
|
112
|
+
"""
|
113
|
+
Export the parameters to a JSON file.
|
106
114
|
|
107
115
|
Args:
|
108
116
|
filepath (str): The path where the JSON file will be saved.
|
@@ -113,7 +121,8 @@ class Params:
|
|
113
121
|
logger.info(f"Parameters exported to JSON file: {filepath}")
|
114
122
|
|
115
123
|
def to_txt(self, filepath: str) -> None:
|
116
|
-
"""
|
124
|
+
"""
|
125
|
+
Export the parameters to a text file.
|
117
126
|
|
118
127
|
Args:
|
119
128
|
filepath (str): The path where the text file will be saved.
|
@@ -131,7 +140,8 @@ class Params:
|
|
131
140
|
logger.info(f"Parameters exported to text file: {filepath}")
|
132
141
|
|
133
142
|
def load(self) -> Dict[str, Any]:
|
134
|
-
"""
|
143
|
+
"""
|
144
|
+
Load and process various parameters, converting any np.ndarray values to lists.
|
135
145
|
|
136
146
|
Returns:
|
137
147
|
Dict[str, Any]: A dictionary containing the processed parameters.
|
@@ -149,7 +159,8 @@ class Params:
|
|
149
159
|
)
|
150
160
|
|
151
161
|
def _convert_ndarray_to_list(self, d: Dict[str, Any]) -> Dict[str, Any]:
|
152
|
-
"""
|
162
|
+
"""
|
163
|
+
Recursively convert all np.ndarray values in the dictionary to lists.
|
153
164
|
|
154
165
|
Args:
|
155
166
|
d (Dict[str, Any]): The dictionary to process.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_neighborhoods/_api
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
import copy
|
@@ -10,9 +10,9 @@ import networkx as nx
|
|
10
10
|
import numpy as np
|
11
11
|
from scipy.sparse import csr_matrix
|
12
12
|
|
13
|
-
from
|
14
|
-
from
|
15
|
-
from
|
13
|
+
from .._log import log_header, logger, params
|
14
|
+
from ._neighborhoods import get_network_neighborhoods
|
15
|
+
from ._stats import (
|
16
16
|
compute_binom_test,
|
17
17
|
compute_chi2_test,
|
18
18
|
compute_hypergeom_test,
|
@@ -23,7 +23,8 @@ from risk.neighborhoods.stats import (
|
|
23
23
|
|
24
24
|
|
25
25
|
class NeighborhoodsAPI:
|
26
|
-
"""
|
26
|
+
"""
|
27
|
+
Handles the loading of statistical results and annotation significance for neighborhoods.
|
27
28
|
|
28
29
|
The NeighborhoodsAPI class provides methods to load neighborhood results from statistical tests.
|
29
30
|
"""
|
@@ -42,7 +43,8 @@ class NeighborhoodsAPI:
|
|
42
43
|
null_distribution: str = "network",
|
43
44
|
random_seed: int = 888,
|
44
45
|
) -> Dict[str, Any]:
|
45
|
-
"""
|
46
|
+
"""
|
47
|
+
Load significant neighborhoods for the network using the binomial test.
|
46
48
|
|
47
49
|
Args:
|
48
50
|
network (nx.Graph): The network graph.
|
@@ -87,7 +89,8 @@ class NeighborhoodsAPI:
|
|
87
89
|
null_distribution: str = "network",
|
88
90
|
random_seed: int = 888,
|
89
91
|
) -> Dict[str, Any]:
|
90
|
-
"""
|
92
|
+
"""
|
93
|
+
Load significant neighborhoods for the network using the chi-squared test.
|
91
94
|
|
92
95
|
Args:
|
93
96
|
network (nx.Graph): The network graph.
|
@@ -132,7 +135,8 @@ class NeighborhoodsAPI:
|
|
132
135
|
null_distribution: str = "network",
|
133
136
|
random_seed: int = 888,
|
134
137
|
) -> Dict[str, Any]:
|
135
|
-
"""
|
138
|
+
"""
|
139
|
+
Load significant neighborhoods for the network using the hypergeometric test.
|
136
140
|
|
137
141
|
Args:
|
138
142
|
network (nx.Graph): The network graph.
|
@@ -180,7 +184,8 @@ class NeighborhoodsAPI:
|
|
180
184
|
random_seed: int = 888,
|
181
185
|
max_workers: int = 1,
|
182
186
|
) -> Dict[str, Any]:
|
183
|
-
"""
|
187
|
+
"""
|
188
|
+
Load significant neighborhoods for the network using the permutation test.
|
184
189
|
|
185
190
|
Args:
|
186
191
|
network (nx.Graph): The network graph.
|
@@ -235,7 +240,8 @@ class NeighborhoodsAPI:
|
|
235
240
|
null_distribution: str = "network",
|
236
241
|
random_seed: int = 888,
|
237
242
|
) -> Dict[str, Any]:
|
238
|
-
"""
|
243
|
+
"""
|
244
|
+
Load significant neighborhoods for the network using the Poisson test.
|
239
245
|
|
240
246
|
Args:
|
241
247
|
network (nx.Graph): The network graph.
|
@@ -280,7 +286,8 @@ class NeighborhoodsAPI:
|
|
280
286
|
null_distribution: str = "network",
|
281
287
|
random_seed: int = 888,
|
282
288
|
) -> Dict[str, Any]:
|
283
|
-
"""
|
289
|
+
"""
|
290
|
+
Load significant neighborhoods for the network using the z-score test.
|
284
291
|
|
285
292
|
Args:
|
286
293
|
network (nx.Graph): The network graph.
|
@@ -328,7 +335,8 @@ class NeighborhoodsAPI:
|
|
328
335
|
statistical_test_function: Any = compute_hypergeom_test,
|
329
336
|
**kwargs,
|
330
337
|
):
|
331
|
-
"""
|
338
|
+
"""
|
339
|
+
Load and compute significant neighborhoods for the network using a specified statistical test.
|
332
340
|
|
333
341
|
Args:
|
334
342
|
network (nx.Graph): The input network graph.
|
@@ -398,7 +406,8 @@ class NeighborhoodsAPI:
|
|
398
406
|
fraction_shortest_edges: Union[float, List, Tuple, np.ndarray] = 0.5,
|
399
407
|
random_seed: int = 888,
|
400
408
|
) -> csr_matrix:
|
401
|
-
"""
|
409
|
+
"""
|
410
|
+
Load significant neighborhoods for the network.
|
402
411
|
|
403
412
|
Args:
|
404
413
|
network (nx.Graph): The network graph.
|