risk-network 0.0.9b6__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 CHANGED
@@ -7,4 +7,4 @@ RISK: RISK Infers Spatial Kinships
7
7
 
8
8
  from risk.risk import RISK
9
9
 
10
- __version__ = "0.0.9-beta.6"
10
+ __version__ = "0.0.9-beta.7"
risk/annotations/io.py CHANGED
@@ -41,7 +41,9 @@ class AnnotationsIO:
41
41
  """
42
42
  filetype = "JSON"
43
43
  # Log the loading of the JSON file
44
- params.log_annotations(filepath=filepath, filetype=filetype)
44
+ params.log_annotations(
45
+ filetype=filetype, filepath=filepath, min_nodes_per_term=min_nodes_per_term
46
+ )
45
47
  _log_loading(filetype, filepath=filepath)
46
48
 
47
49
  # Load the JSON file into a dictionary
@@ -78,7 +80,9 @@ class AnnotationsIO:
78
80
  """
79
81
  filetype = "Excel"
80
82
  # Log the loading of the Excel file
81
- params.log_annotations(filepath=filepath, filetype=filetype)
83
+ params.log_annotations(
84
+ filetype=filetype, filepath=filepath, min_nodes_per_term=min_nodes_per_term
85
+ )
82
86
  _log_loading(filetype, filepath=filepath)
83
87
 
84
88
  # Load the specified sheet from the Excel file
@@ -118,7 +122,9 @@ class AnnotationsIO:
118
122
  """
119
123
  filetype = "CSV"
120
124
  # Log the loading of the CSV file
121
- params.log_annotations(filepath=filepath, filetype=filetype)
125
+ params.log_annotations(
126
+ filetype=filetype, filepath=filepath, min_nodes_per_term=min_nodes_per_term
127
+ )
122
128
  _log_loading(filetype, filepath=filepath)
123
129
 
124
130
  # Load the CSV file into a dictionary
@@ -154,7 +160,9 @@ class AnnotationsIO:
154
160
  """
155
161
  filetype = "TSV"
156
162
  # Log the loading of the TSV file
157
- params.log_annotations(filepath=filepath, filetype=filetype)
163
+ params.log_annotations(
164
+ filetype=filetype, filepath=filepath, min_nodes_per_term=min_nodes_per_term
165
+ )
158
166
  _log_loading(filetype, filepath=filepath)
159
167
 
160
168
  # Load the TSV file into a dictionary
@@ -3,7 +3,7 @@ risk/neighborhoods
3
3
  ~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
- from .domains import define_domains, trim_domains_and_top_annotations
6
+ from .domains import define_domains, trim_domains
7
7
  from .neighborhoods import (
8
8
  get_network_neighborhoods,
9
9
  process_neighborhoods,
@@ -86,13 +86,13 @@ def define_domains(
86
86
  return node_to_domain
87
87
 
88
88
 
89
- def trim_domains_and_top_annotations(
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 and top annotations that do not meet size criteria and find outliers.
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, 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 valid_annotations, valid_domains, valid_trimmed_domains_matrix
161
+ return valid_domains, valid_trimmed_domains_matrix
166
162
 
167
163
 
168
164
  def _optimize_silhouette_across_linkage_and_metrics(
@@ -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
- self.top_annotations = top_annotations
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.
@@ -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.color import to_rgba
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
 
@@ -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.color import get_annotated_domain_colors, to_rgba
16
+ from risk.network.plot.utils.colors import get_annotated_domain_colors, to_rgba
17
17
 
18
18
 
19
19
  class Contour:
@@ -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.color import get_annotated_domain_colors, to_rgba
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
@@ -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.color import get_domain_colors, to_rgba
13
+ from risk.network.plot.utils.colors import get_domain_colors, to_rgba
14
14
 
15
15
 
16
16
  class Network:
@@ -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.color import to_rgba
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
 
@@ -410,6 +410,7 @@ def to_rgba(
410
410
 
411
411
  if alpha is not None: # Override alpha if provided
412
412
  rgba[3] = alpha
413
+
413
414
  return rgba
414
415
 
415
416
  # If color is a 2D array of RGBA values, convert it to a list of lists
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
- trim_domains_and_top_annotations,
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 = self._define_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
- top_annotations, domains, trimmed_domains = trim_domains_and_top_annotations(
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.9b6
3
+ Version: 0.0.9b7
4
4
  Summary: A Python package for biological network analysis
5
5
  Author: Ira Horecka
6
6
  Author-email: Ira Horecka <ira89@icloud.com>
@@ -1,29 +1,29 @@
1
- risk/__init__.py,sha256=fpCtulKZFHI4Je7dm4qBJHyP9InK9uDRYmYYgog9BGQ,112
1
+ risk/__init__.py,sha256=qkmHFIeApkRQEVhb6MctmvmD84ri0SRmooehDAeIV2k,112
2
2
  risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
3
- risk/risk.py,sha256=De1vn8Xc-TKz6aTL0bvJI-SVrIqU3k0IWAbKc7dde1c,23618
3
+ risk/risk.py,sha256=kntBxYwAEpoAjXN_l6BM3yxFKyuAKmd8OMGl2P00pZ4,22416
4
4
  risk/annotations/__init__.py,sha256=kXgadEXaCh0z8OyhOhTj7c3qXGmWgOhaSZ4gSzSb59U,147
5
5
  risk/annotations/annotations.py,sha256=WVT9wzTm8lTpMw_3SnbyljWR77yExo0rb1zVgJza8nw,14284
6
- risk/annotations/io.py,sha256=Nj_RPmn-WM1zMsssm9bVGR94SHytkEBK-wcBJ3WhqkU,10310
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=tKKEg4lsbqFukpgYlUGxU_v_9FOqK7V0uvM9T2QzoL0,206
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=cMp2McuaSxRp7lQvzjgZnlt5dzxwyj6HAWKyT9u2sng,11662
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=j75Lfwd5VGIDv0GlVoYIgN6RRua7i-PNg5D-ssgRhfo,11190
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=TlCpNtvoceizAumNr9I02JcBrBO6FiAFAa2ZC0bx3SU,13356
22
- risk/network/plot/contour.py,sha256=91-K9jlV3K82Ax13BoLdDeZkBR5_8AnZujAblHBK-3A,15580
23
- risk/network/plot/labels.py,sha256=S1UOYUB1WbsaQEVkEr5cUKQbUuebKJPKILqhL8zmQWM,45733
24
- risk/network/plot/network.py,sha256=vcm53MlaWd-wmaPDo8-Ap2gJPAp0SNEGZ2NiGamkJKo,14014
25
- risk/network/plot/plotter.py,sha256=iTPMiTnTTatM_-q1Ox_bjt5Pvv-Lo8gceiYB6TVzDcw,5770
26
- risk/network/plot/utils/color.py,sha256=T5qOlPhHzgLwileaVqT8Vq9A1ZQvaSMWvsCTnauAgTs,20802
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.9b6.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
36
- risk_network-0.0.9b6.dist-info/METADATA,sha256=0YZ5Rd4bqOid3nSHpa-S6fBBtBhYPoAQ1SlACtmDVaw,47497
37
- risk_network-0.0.9b6.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
38
- risk_network-0.0.9b6.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
39
- risk_network-0.0.9b6.dist-info/RECORD,,
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,,