risk-network 0.0.13b3__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.13b3/src/risk_network.egg-info → risk_network-0.0.13b5}/PKG-INFO +2 -2
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/pyproject.toml +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.13b3/src/risk/annotation/annotation.py → risk_network-0.0.13b5/src/risk/_annotation/_annotation.py +40 -19
- risk_network-0.0.13b3/src/risk/annotation/io.py → risk_network-0.0.13b5/src/risk/_annotation/_io.py +78 -32
- risk_network-0.0.13b3/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.13b3/src/risk/log/console.py → risk_network-0.0.13b5/src/risk/_log/_console.py +22 -12
- risk_network-0.0.13b3/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.13b3/src/risk/neighborhoods/api.py → risk_network-0.0.13b5/src/risk/_neighborhoods/_api.py +23 -14
- risk_network-0.0.13b3/src/risk/neighborhoods/community.py → risk_network-0.0.13b5/src/risk/_neighborhoods/_community.py +19 -11
- risk_network-0.0.13b3/src/risk/neighborhoods/domains.py → risk_network-0.0.13b5/src/risk/_neighborhoods/_domains.py +15 -9
- risk_network-0.0.13b3/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.13b3/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.13b3/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.13b3/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.13b3/src/risk/network/graph/api.py → risk_network-0.0.13b5/src/risk/_network/_graph/_api.py +13 -10
- risk_network-0.0.13b3/src/risk/network/graph/graph.py → risk_network-0.0.13b5/src/risk/_network/_graph/_graph.py +24 -13
- risk_network-0.0.13b3/src/risk/network/graph/stats.py → risk_network-0.0.13b5/src/risk/_network/_graph/_stats.py +8 -5
- risk_network-0.0.13b3/src/risk/network/graph/summary.py → risk_network-0.0.13b5/src/risk/_network/_graph/_summary.py +21 -12
- risk_network-0.0.13b3/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.13b3/src/risk/network/plotter/api.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_api.py +9 -7
- risk_network-0.0.13b3/src/risk/network/plotter/canvas.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_canvas.py +14 -10
- risk_network-0.0.13b3/src/risk/network/plotter/contour.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_contour.py +17 -11
- risk_network-0.0.13b3/src/risk/network/plotter/labels.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_labels.py +38 -23
- risk_network-0.0.13b3/src/risk/network/plotter/network.py → risk_network-0.0.13b5/src/risk/_network/_plotter/_network.py +17 -11
- risk_network-0.0.13b3/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.13b3/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.13b3/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.13b3 → risk_network-0.0.13b5}/src/risk/risk.py +8 -8
- {risk_network-0.0.13b3 → risk_network-0.0.13b5/src/risk_network.egg-info}/PKG-INFO +2 -2
- risk_network-0.0.13b5/src/risk_network.egg-info/SOURCES.txt +51 -0
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/tests/test_load_annotation.py +69 -14
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/tests/test_load_graph.py +21 -11
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/tests/test_load_io_combinations.py +2 -1
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/tests/test_load_neighborhoods.py +24 -12
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/tests/test_load_network.py +32 -16
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/tests/test_load_plotter.py +62 -31
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/tests/test_log.py +11 -10
- risk_network-0.0.13b3/src/risk/__init__.py +0 -10
- risk_network-0.0.13b3/src/risk/annotation/__init__.py +0 -10
- risk_network-0.0.13b3/src/risk/log/__init__.py +0 -11
- risk_network-0.0.13b3/src/risk/neighborhoods/__init__.py +0 -7
- risk_network-0.0.13b3/src/risk/neighborhoods/stats/__init__.py +0 -13
- risk_network-0.0.13b3/src/risk/neighborhoods/stats/permutation/__init__.py +0 -6
- risk_network-0.0.13b3/src/risk/network/__init__.py +0 -4
- risk_network-0.0.13b3/src/risk/network/graph/__init__.py +0 -4
- risk_network-0.0.13b3/src/risk/network/plotter/__init__.py +0 -4
- risk_network-0.0.13b3/src/risk_network.egg-info/SOURCES.txt +0 -50
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/LICENSE +0 -0
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/README.md +0 -0
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/setup.cfg +0 -0
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/src/risk_network.egg-info/dependency_links.txt +0 -0
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/src/risk_network.egg-info/requires.txt +0 -0
- {risk_network-0.0.13b3 → risk_network-0.0.13b5}/src/risk_network.egg-info/top_level.txt +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: risk-network
|
3
|
-
Version: 0.0.
|
4
|
-
Summary: A Python package for
|
3
|
+
Version: 0.0.13b5
|
4
|
+
Summary: A Python package for scalable network analysis and high-quality visualization.
|
5
5
|
Author-email: Ira Horecka <ira89@icloud.com>
|
6
6
|
License: GPL-3.0-or-later
|
7
7
|
Project-URL: Homepage, https://github.com/riskportal/network
|
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|
5
5
|
[project]
|
6
6
|
name = "risk-network"
|
7
7
|
dynamic = ["version"]
|
8
|
-
description = "A Python package for
|
8
|
+
description = "A Python package for scalable network analysis and high-quality visualization."
|
9
9
|
authors = [
|
10
10
|
{ name = "Ira Horecka", email = "ira89@icloud.com" },
|
11
11
|
]
|
@@ -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
|
@@ -36,15 +37,21 @@ initialize_nltk()
|
|
36
37
|
|
37
38
|
|
38
39
|
def load_annotation(
|
39
|
-
network: nx.Graph,
|
40
|
+
network: nx.Graph,
|
41
|
+
annotation_input: Dict[str, Any],
|
42
|
+
min_nodes_per_term: int = 1,
|
43
|
+
max_nodes_per_term: int = 10_000,
|
40
44
|
) -> Dict[str, Any]:
|
41
|
-
"""
|
45
|
+
"""
|
46
|
+
Convert annotation input to a sparse matrix and reindex based on the network's node labels.
|
42
47
|
|
43
48
|
Args:
|
44
49
|
network (nx.Graph): The network graph.
|
45
50
|
annotation_input (Dict[str, Any]): An annotation dictionary.
|
46
51
|
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
47
|
-
term to be included. Defaults to
|
52
|
+
term to be included. Defaults to 1.
|
53
|
+
max_nodes_per_term (int, optional): The maximum number of network nodes allowed for each annotation
|
54
|
+
term. Defaults to 10_000.
|
48
55
|
|
49
56
|
Returns:
|
50
57
|
Dict[str, Any]: A dictionary containing ordered nodes, ordered annotations, and the sparse binary annotations
|
@@ -52,7 +59,6 @@ def load_annotation(
|
|
52
59
|
|
53
60
|
Raises:
|
54
61
|
ValueError: If no annotation is found for the nodes in the network.
|
55
|
-
ValueError: If no annotation has at least min_nodes_per_term nodes in the network.
|
56
62
|
"""
|
57
63
|
# Step 1: Map nodes and annotations to indices
|
58
64
|
node_label_order = [attr["label"] for _, attr in network.nodes(data=True) if "label" in attr]
|
@@ -72,9 +78,18 @@ def load_annotation(
|
|
72
78
|
# Create a sparse binary matrix
|
73
79
|
num_nodes = len(node_to_idx)
|
74
80
|
num_annotation = len(annotation_to_idx)
|
75
|
-
|
76
|
-
|
77
|
-
|
81
|
+
# Convert to a sparse matrix and set the data type to uint8 for binary representation
|
82
|
+
annotation_pivot = (
|
83
|
+
coo_matrix((data, (row, col)), shape=(num_nodes, num_annotation)).tocsr().astype(np.uint8)
|
84
|
+
)
|
85
|
+
# Step 3: Filter out annotations with too few or too many nodes
|
86
|
+
valid_annotation = np.array(
|
87
|
+
[
|
88
|
+
annotation_pivot[:, i].sum() >= min_nodes_per_term
|
89
|
+
and annotation_pivot[:, i].sum() <= max_nodes_per_term
|
90
|
+
for i in range(num_annotation)
|
91
|
+
]
|
92
|
+
)
|
78
93
|
annotation_pivot = annotation_pivot[:, valid_annotation]
|
79
94
|
# Step 4: Raise errors for empty matrices
|
80
95
|
if annotation_pivot.nnz == 0:
|
@@ -83,7 +98,7 @@ def load_annotation(
|
|
83
98
|
num_remaining_annotation = annotation_pivot.shape[1]
|
84
99
|
if num_remaining_annotation == 0:
|
85
100
|
raise ValueError(
|
86
|
-
f"No annotation terms found with at least {min_nodes_per_term} nodes
|
101
|
+
f"No annotation terms found with at least {min_nodes_per_term} nodes and at most {max_nodes_per_term} nodes."
|
87
102
|
)
|
88
103
|
|
89
104
|
# Step 5: Extract ordered nodes and annotations
|
@@ -94,6 +109,7 @@ def load_annotation(
|
|
94
109
|
|
95
110
|
# Log the filtering details
|
96
111
|
logger.info(f"Minimum number of nodes per annotation term: {min_nodes_per_term}")
|
112
|
+
logger.info(f"Maximum number of nodes per annotation term: {max_nodes_per_term}")
|
97
113
|
logger.info(f"Number of input annotation terms: {num_annotation}")
|
98
114
|
logger.info(f"Number of remaining annotation terms: {num_remaining_annotation}")
|
99
115
|
|
@@ -113,7 +129,8 @@ def define_top_annotation(
|
|
113
129
|
min_cluster_size: int = 5,
|
114
130
|
max_cluster_size: int = 1000,
|
115
131
|
) -> pd.DataFrame:
|
116
|
-
"""
|
132
|
+
"""
|
133
|
+
Define top annotations based on neighborhood significance sums and binary significance matrix.
|
117
134
|
|
118
135
|
Args:
|
119
136
|
network (NetworkX graph): The network graph.
|
@@ -122,7 +139,7 @@ def define_top_annotation(
|
|
122
139
|
significant_significance_matrix (np.ndarray): Enrichment matrix below alpha threshold.
|
123
140
|
significant_binary_significance_matrix (np.ndarray): Binary significance matrix below alpha threshold.
|
124
141
|
min_cluster_size (int, optional): Minimum cluster size. Defaults to 5.
|
125
|
-
max_cluster_size (int, optional): Maximum cluster size. Defaults to
|
142
|
+
max_cluster_size (int, optional): Maximum cluster size. Defaults to 10_000.
|
126
143
|
|
127
144
|
Returns:
|
128
145
|
pd.DataFrame: DataFrame with top annotations and their properties.
|
@@ -204,7 +221,8 @@ def define_top_annotation(
|
|
204
221
|
|
205
222
|
|
206
223
|
def get_weighted_description(words_column: pd.Series, scores_column: pd.Series) -> str:
|
207
|
-
"""
|
224
|
+
"""
|
225
|
+
Generate a weighted description from words and their corresponding scores,
|
208
226
|
using improved weighting logic with normalization, lemmatization, and aggregation.
|
209
227
|
|
210
228
|
Args:
|
@@ -272,7 +290,8 @@ def get_weighted_description(words_column: pd.Series, scores_column: pd.Series)
|
|
272
290
|
|
273
291
|
|
274
292
|
def _simplify_word_list(words: List[str], threshold: float = 0.80) -> List[str]:
|
275
|
-
"""
|
293
|
+
"""
|
294
|
+
Filter out words that are too similar based on the Jaccard index,
|
276
295
|
keeping the word with the higher aggregated count.
|
277
296
|
|
278
297
|
Args:
|
@@ -312,7 +331,8 @@ def _simplify_word_list(words: List[str], threshold: float = 0.80) -> List[str]:
|
|
312
331
|
|
313
332
|
|
314
333
|
def _calculate_jaccard_index(set1: Set[Any], set2: Set[Any]) -> float:
|
315
|
-
"""
|
334
|
+
"""
|
335
|
+
Calculate the Jaccard index between two sets.
|
316
336
|
|
317
337
|
Args:
|
318
338
|
set1 (Set[Any]): The first set.
|
@@ -327,7 +347,8 @@ def _calculate_jaccard_index(set1: Set[Any], set2: Set[Any]) -> float:
|
|
327
347
|
|
328
348
|
|
329
349
|
def _generate_coherent_description(words: List[str]) -> str:
|
330
|
-
"""
|
350
|
+
"""
|
351
|
+
Generate a coherent description from a list of words.
|
331
352
|
|
332
353
|
If there is only one unique entry, return it directly.
|
333
354
|
Otherwise, order the words by frequency and join them into a single string.
|
risk_network-0.0.13b3/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,27 +9,35 @@ 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.
|
21
22
|
"""
|
22
23
|
|
23
24
|
def load_annotation_json(
|
24
|
-
self,
|
25
|
+
self,
|
26
|
+
network: nx.Graph,
|
27
|
+
filepath: str,
|
28
|
+
min_nodes_per_term: int = 1,
|
29
|
+
max_nodes_per_term: int = 10_000,
|
25
30
|
) -> Dict[str, Any]:
|
26
|
-
"""
|
31
|
+
"""
|
32
|
+
Load annotation from a JSON file and convert them to a DataFrame.
|
27
33
|
|
28
34
|
Args:
|
29
35
|
network (NetworkX graph): The network to which the annotation is related.
|
30
36
|
filepath (str): Path to the JSON annotation file.
|
31
37
|
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
32
|
-
term to be included. Defaults to
|
38
|
+
term to be included. Defaults to 1.
|
39
|
+
max_nodes_per_term (int, optional): The maximum number of network nodes allowed for each annotation
|
40
|
+
term to be included. Defaults to 10_000.
|
33
41
|
|
34
42
|
Returns:
|
35
43
|
Dict[str, Any]: A dictionary containing ordered nodes, ordered annotations, and the annotation matrix.
|
@@ -37,7 +45,10 @@ class AnnotationIO:
|
|
37
45
|
filetype = "JSON"
|
38
46
|
# Log the loading of the JSON file
|
39
47
|
params.log_annotation(
|
40
|
-
filetype=filetype,
|
48
|
+
filetype=filetype,
|
49
|
+
filepath=filepath,
|
50
|
+
min_nodes_per_term=min_nodes_per_term,
|
51
|
+
max_nodes_per_term=max_nodes_per_term,
|
41
52
|
)
|
42
53
|
self._log_loading_annotation(filetype, filepath=filepath)
|
43
54
|
|
@@ -45,7 +56,7 @@ class AnnotationIO:
|
|
45
56
|
with open(filepath, "r", encoding="utf-8") as file:
|
46
57
|
annotation_input = json.load(file)
|
47
58
|
|
48
|
-
return load_annotation(network, annotation_input, min_nodes_per_term)
|
59
|
+
return load_annotation(network, annotation_input, min_nodes_per_term, max_nodes_per_term)
|
49
60
|
|
50
61
|
def load_annotation_excel(
|
51
62
|
self,
|
@@ -55,9 +66,11 @@ class AnnotationIO:
|
|
55
66
|
nodes_colname: str = "nodes",
|
56
67
|
sheet_name: str = "Sheet1",
|
57
68
|
nodes_delimiter: str = ";",
|
58
|
-
min_nodes_per_term: int =
|
69
|
+
min_nodes_per_term: int = 1,
|
70
|
+
max_nodes_per_term: int = 10_000,
|
59
71
|
) -> Dict[str, Any]:
|
60
|
-
"""
|
72
|
+
"""
|
73
|
+
Load annotation from an Excel file and associate them with the network.
|
61
74
|
|
62
75
|
Args:
|
63
76
|
network (nx.Graph): The NetworkX graph to which the annotation is related.
|
@@ -67,7 +80,9 @@ class AnnotationIO:
|
|
67
80
|
sheet_name (str, optional): The name of the Excel sheet to load (default is 'Sheet1').
|
68
81
|
nodes_delimiter (str, optional): Delimiter used to separate multiple nodes within the nodes column (default is ';').
|
69
82
|
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
70
|
-
term to be included. Defaults to
|
83
|
+
term to be included. Defaults to 1.
|
84
|
+
max_nodes_per_term (int, optional): The maximum number of network nodes allowed for each annotation
|
85
|
+
term to be included. Defaults to 10_000.
|
71
86
|
|
72
87
|
Returns:
|
73
88
|
Dict[str, Any]: A dictionary where each label is paired with its respective list of nodes,
|
@@ -76,7 +91,10 @@ class AnnotationIO:
|
|
76
91
|
filetype = "Excel"
|
77
92
|
# Log the loading of the Excel file
|
78
93
|
params.log_annotation(
|
79
|
-
filetype=filetype,
|
94
|
+
filetype=filetype,
|
95
|
+
filepath=filepath,
|
96
|
+
min_nodes_per_term=min_nodes_per_term,
|
97
|
+
max_nodes_per_term=max_nodes_per_term,
|
80
98
|
)
|
81
99
|
self._log_loading_annotation(filetype, filepath=filepath)
|
82
100
|
|
@@ -89,7 +107,7 @@ class AnnotationIO:
|
|
89
107
|
# Convert the DataFrame to a dictionary pairing labels with their corresponding nodes
|
90
108
|
annotation_input = annotation.set_index(label_colname)[nodes_colname].to_dict()
|
91
109
|
|
92
|
-
return load_annotation(network, annotation_input, min_nodes_per_term)
|
110
|
+
return load_annotation(network, annotation_input, min_nodes_per_term, max_nodes_per_term)
|
93
111
|
|
94
112
|
def load_annotation_csv(
|
95
113
|
self,
|
@@ -98,9 +116,11 @@ class AnnotationIO:
|
|
98
116
|
label_colname: str = "label",
|
99
117
|
nodes_colname: str = "nodes",
|
100
118
|
nodes_delimiter: str = ";",
|
101
|
-
min_nodes_per_term: int =
|
119
|
+
min_nodes_per_term: int = 1,
|
120
|
+
max_nodes_per_term: int = 10_000,
|
102
121
|
) -> Dict[str, Any]:
|
103
|
-
"""
|
122
|
+
"""
|
123
|
+
Load annotation from a CSV file and associate them with the network.
|
104
124
|
|
105
125
|
Args:
|
106
126
|
network (nx.Graph): The NetworkX graph to which the annotation is related.
|
@@ -109,7 +129,9 @@ class AnnotationIO:
|
|
109
129
|
nodes_colname (str): Name of the column containing the nodes associated with each label.
|
110
130
|
nodes_delimiter (str, optional): Delimiter used to separate multiple nodes within the nodes column (default is ';').
|
111
131
|
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
112
|
-
term to be included. Defaults to
|
132
|
+
term to be included. Defaults to 1.
|
133
|
+
max_nodes_per_term (int, optional): The maximum number of network nodes allowed for each annotation
|
134
|
+
term to be included. Defaults to 10_000.
|
113
135
|
|
114
136
|
Returns:
|
115
137
|
Dict[str, Any]: A dictionary where each label is paired with its respective list of nodes,
|
@@ -118,7 +140,10 @@ class AnnotationIO:
|
|
118
140
|
filetype = "CSV"
|
119
141
|
# Log the loading of the CSV file
|
120
142
|
params.log_annotation(
|
121
|
-
filetype=filetype,
|
143
|
+
filetype=filetype,
|
144
|
+
filepath=filepath,
|
145
|
+
min_nodes_per_term=min_nodes_per_term,
|
146
|
+
max_nodes_per_term=max_nodes_per_term,
|
122
147
|
)
|
123
148
|
self._log_loading_annotation(filetype, filepath=filepath)
|
124
149
|
|
@@ -127,7 +152,7 @@ class AnnotationIO:
|
|
127
152
|
filepath, label_colname, nodes_colname, delimiter=",", nodes_delimiter=nodes_delimiter
|
128
153
|
)
|
129
154
|
|
130
|
-
return load_annotation(network, annotation_input, min_nodes_per_term)
|
155
|
+
return load_annotation(network, annotation_input, min_nodes_per_term, max_nodes_per_term)
|
131
156
|
|
132
157
|
def load_annotation_tsv(
|
133
158
|
self,
|
@@ -136,9 +161,11 @@ class AnnotationIO:
|
|
136
161
|
label_colname: str = "label",
|
137
162
|
nodes_colname: str = "nodes",
|
138
163
|
nodes_delimiter: str = ";",
|
139
|
-
min_nodes_per_term: int =
|
164
|
+
min_nodes_per_term: int = 1,
|
165
|
+
max_nodes_per_term: int = 10_000,
|
140
166
|
) -> Dict[str, Any]:
|
141
|
-
"""
|
167
|
+
"""
|
168
|
+
Load annotation from a TSV file and associate them with the network.
|
142
169
|
|
143
170
|
Args:
|
144
171
|
network (nx.Graph): The NetworkX graph to which the annotation is related.
|
@@ -147,7 +174,9 @@ class AnnotationIO:
|
|
147
174
|
nodes_colname (str): Name of the column containing the nodes associated with each label.
|
148
175
|
nodes_delimiter (str, optional): Delimiter used to separate multiple nodes within the nodes column (default is ';').
|
149
176
|
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
150
|
-
term to be included. Defaults to
|
177
|
+
term to be included. Defaults to 1.
|
178
|
+
max_nodes_per_term (int, optional): The maximum number of network nodes allowed for each annotation
|
179
|
+
term to be included. Defaults to 10_000.
|
151
180
|
|
152
181
|
Returns:
|
153
182
|
Dict[str, Any]: A dictionary where each label is paired with its respective list of nodes,
|
@@ -156,7 +185,10 @@ class AnnotationIO:
|
|
156
185
|
filetype = "TSV"
|
157
186
|
# Log the loading of the TSV file
|
158
187
|
params.log_annotation(
|
159
|
-
filetype=filetype,
|
188
|
+
filetype=filetype,
|
189
|
+
filepath=filepath,
|
190
|
+
min_nodes_per_term=min_nodes_per_term,
|
191
|
+
max_nodes_per_term=max_nodes_per_term,
|
160
192
|
)
|
161
193
|
self._log_loading_annotation(filetype, filepath=filepath)
|
162
194
|
|
@@ -165,18 +197,25 @@ class AnnotationIO:
|
|
165
197
|
filepath, label_colname, nodes_colname, delimiter="\t", nodes_delimiter=nodes_delimiter
|
166
198
|
)
|
167
199
|
|
168
|
-
return load_annotation(network, annotation_input, min_nodes_per_term)
|
200
|
+
return load_annotation(network, annotation_input, min_nodes_per_term, max_nodes_per_term)
|
169
201
|
|
170
202
|
def load_annotation_dict(
|
171
|
-
self,
|
203
|
+
self,
|
204
|
+
network: nx.Graph,
|
205
|
+
content: Dict[str, Any],
|
206
|
+
min_nodes_per_term: int = 1,
|
207
|
+
max_nodes_per_term: int = 10_000,
|
172
208
|
) -> Dict[str, Any]:
|
173
|
-
"""
|
209
|
+
"""
|
210
|
+
Load annotation from a provided dictionary and convert them to a dictionary annotation.
|
174
211
|
|
175
212
|
Args:
|
176
213
|
network (NetworkX graph): The network to which the annotation is related.
|
177
214
|
content (Dict[str, Any]): The annotation dictionary to load.
|
178
215
|
min_nodes_per_term (int, optional): The minimum number of network nodes required for each annotation
|
179
|
-
term to be included. Defaults to
|
216
|
+
term to be included. Defaults to 1.
|
217
|
+
max_nodes_per_term (int, optional): The maximum number of network nodes allowed for each annotation
|
218
|
+
term to be included. Defaults to 10_000.
|
180
219
|
|
181
220
|
Returns:
|
182
221
|
Dict[str, Any]: A dictionary containing ordered nodes, ordered annotations, and the annotation matrix.
|
@@ -192,11 +231,16 @@ class AnnotationIO:
|
|
192
231
|
|
193
232
|
filetype = "Dictionary"
|
194
233
|
# Log the loading of the annotation from the dictionary
|
195
|
-
params.log_annotation(
|
234
|
+
params.log_annotation(
|
235
|
+
filepath="In-memory dictionary",
|
236
|
+
filetype=filetype,
|
237
|
+
min_nodes_per_term=min_nodes_per_term,
|
238
|
+
max_nodes_per_term=max_nodes_per_term,
|
239
|
+
)
|
196
240
|
self._log_loading_annotation(filetype, "In-memory dictionary")
|
197
241
|
|
198
242
|
# Load the annotation as a dictionary from the provided dictionary
|
199
|
-
return load_annotation(network, content, min_nodes_per_term)
|
243
|
+
return load_annotation(network, content, min_nodes_per_term, max_nodes_per_term)
|
200
244
|
|
201
245
|
def _load_matrix_file(
|
202
246
|
self,
|
@@ -206,7 +250,8 @@ class AnnotationIO:
|
|
206
250
|
delimiter: str = ",",
|
207
251
|
nodes_delimiter: str = ";",
|
208
252
|
) -> Dict[str, Any]:
|
209
|
-
"""
|
253
|
+
"""
|
254
|
+
Load annotation from a CSV or TSV file and convert them to a dictionary.
|
210
255
|
|
211
256
|
Args:
|
212
257
|
filepath (str): Path to the annotation file.
|
@@ -229,7 +274,8 @@ class AnnotationIO:
|
|
229
274
|
return label_node_dict
|
230
275
|
|
231
276
|
def _log_loading_annotation(self, filetype: str, filepath: str = "") -> None:
|
232
|
-
"""
|
277
|
+
"""
|
278
|
+
Log the loading of annotation files.
|
233
279
|
|
234
280
|
Args:
|
235
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.13b3/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.
|