risk-network 0.0.5b5__py3-none-any.whl → 0.0.6b0__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.5-beta.5"
10
+ __version__ = "0.0.6-beta.0"
risk/constants.py CHANGED
@@ -3,6 +3,8 @@ risk/constants
3
3
  ~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
+ GROUP_LINKAGE_METHODS = ["single", "complete", "average", "weighted", "centroid", "median", "ward"]
7
+
6
8
  GROUP_DISTANCE_METRICS = [
7
9
  "braycurtis",
8
10
  "canberra",
@@ -27,5 +29,3 @@ GROUP_DISTANCE_METRICS = [
27
29
  "sqeuclidean",
28
30
  "yule",
29
31
  ]
30
-
31
- GROUP_LINKAGE_METHODS = ["single", "complete", "average", "weighted", "centroid", "median", "ward"]
risk/network/io.py CHANGED
@@ -418,29 +418,37 @@ class NetworkIO:
418
418
  return G
419
419
 
420
420
  def _remove_invalid_graph_properties(self, G: nx.Graph) -> None:
421
- """Remove invalid properties from the graph.
421
+ """Remove invalid properties from the graph, including self-loops, nodes with fewer edges than
422
+ the threshold, and isolated nodes.
422
423
 
423
424
  Args:
424
425
  G (nx.Graph): A NetworkX graph object.
425
426
  """
426
- # First, Remove self-loop edges to ensure correct edge count
427
+ # Count number of nodes and edges before cleaning
428
+ num_initial_nodes = G.number_of_nodes()
429
+ num_initial_edges = G.number_of_edges()
430
+ # Remove self-loops to ensure correct edge count
427
431
  G.remove_edges_from(list(nx.selfloop_edges(G)))
428
- # Then, iteratively remove nodes with fewer edges than the specified threshold
432
+ # Iteratively remove nodes with fewer edges than the threshold
429
433
  while True:
430
- nodes_to_remove = [
431
- node for node in G.nodes() if G.degree(node) < self.min_edges_per_node
432
- ]
434
+ nodes_to_remove = [node for node in G.nodes if G.degree(node) < self.min_edges_per_node]
433
435
  if not nodes_to_remove:
434
- break # Exit loop if no more nodes to remove
435
-
436
- # Remove the nodes and their associated edges
436
+ break # Exit loop if no more nodes need removal
437
437
  G.remove_nodes_from(nodes_to_remove)
438
438
 
439
- # Optionally: Remove any isolated nodes if needed
439
+ # Remove isolated nodes
440
440
  isolated_nodes = list(nx.isolates(G))
441
441
  if isolated_nodes:
442
442
  G.remove_nodes_from(isolated_nodes)
443
443
 
444
+ # Log the number of nodes and edges before and after cleaning
445
+ num_final_nodes = G.number_of_nodes()
446
+ num_final_edges = G.number_of_edges()
447
+ print(f"Initial node count: {num_initial_nodes}")
448
+ print(f"Final node count: {num_final_nodes}")
449
+ print(f"Initial edge count: {num_initial_edges}")
450
+ print(f"Final edge count: {num_final_edges}")
451
+
444
452
  def _assign_edge_weights(self, G: nx.Graph) -> None:
445
453
  """Assign weights to the edges in the graph.
446
454
 
@@ -502,6 +510,7 @@ class NetworkIO:
502
510
  print(f"Edge weight: {'Included' if self.include_edge_weight else 'Excluded'}")
503
511
  if self.include_edge_weight:
504
512
  print(f"Weight label: {self.weight_label}")
513
+ print(f"Minimum edges per node: {self.min_edges_per_node}")
505
514
  print(f"Projection: {'Sphere' if self.compute_sphere else 'Plane'}")
506
515
  if self.compute_sphere:
507
516
  print(f"Surface depth: {self.surface_depth}")
risk/network/plot.py CHANGED
@@ -494,6 +494,7 @@ class NetworkPlotter:
494
494
  if max_labels is not None and max_labels < len(filtered_domain_centroids):
495
495
  step = len(filtered_domain_centroids) / max_labels
496
496
  selected_indices = [int(i * step) for i in range(max_labels)]
497
+ # Filter the centroids, terms, and valid_indices to only use the selected indices
497
498
  filtered_domain_centroids = {
498
499
  k: v
499
500
  for i, (k, v) in enumerate(filtered_domain_centroids.items())
@@ -504,8 +505,8 @@ class NetworkPlotter:
504
505
  for i, (k, v) in enumerate(filtered_domain_terms.items())
505
506
  if i in selected_indices
506
507
  }
507
- fontcolor = fontcolor[selected_indices]
508
- arrow_color = arrow_color[selected_indices]
508
+ # Update valid_indices to match selected indices
509
+ valid_indices = [valid_indices[i] for i in selected_indices]
509
510
 
510
511
  # Calculate the bounding box around the network
511
512
  center, radius = _calculate_bounding_box(
@@ -629,12 +630,16 @@ class NetworkPlotter:
629
630
  return domain_central_node
630
631
 
631
632
  def get_annotated_node_colors(
632
- self, nonenriched_color: str = "white", random_seed: int = 888, **kwargs
633
+ self,
634
+ nonenriched_color: Union[str, List, Tuple, np.ndarray] = "white",
635
+ random_seed: int = 888,
636
+ **kwargs,
633
637
  ) -> np.ndarray:
634
638
  """Adjust the colors of nodes in the network graph based on enrichment.
635
639
 
636
640
  Args:
637
- nonenriched_color (str, optional): Color for non-enriched nodes. Defaults to "white".
641
+ nonenriched_color (str, list, tuple, or np.ndarray, optional): Color for non-enriched nodes.
642
+ Defaults to "white". If an alpha channel is provided, it will be used to darken the RGB values.
638
643
  random_seed (int, optional): Seed for random number generation. Defaults to 888.
639
644
  **kwargs: Additional keyword arguments for `get_domain_colors`.
640
645
 
@@ -647,12 +652,23 @@ class NetworkPlotter:
647
652
  # Convert the non-enriched color from string to RGBA
648
653
  nonenriched_color = mcolors.to_rgba(nonenriched_color)
649
654
 
655
+ # Ensure nonenriched_color is a NumPy array
656
+ nonenriched_color = np.array(nonenriched_color)
657
+ # If alpha is provided (4th value), darken the RGB values based on alpha
658
+ if len(nonenriched_color) == 4 and nonenriched_color[3] < 1.0:
659
+ alpha = nonenriched_color[3]
660
+ # Adjust RGB based on alpha (darken)
661
+ nonenriched_color[:3] = nonenriched_color[:3] * alpha
662
+ # Set alpha to 1.0 after darkening the color
663
+ nonenriched_color[3] = 1.0
664
+
650
665
  # Adjust node colors: replace any fully transparent nodes (enriched) with the non-enriched color
651
666
  adjusted_network_colors = np.where(
652
- np.all(network_colors == 0, axis=1, keepdims=True),
653
- np.array([nonenriched_color]),
654
- network_colors,
667
+ np.all(network_colors[:, :3] == 0, axis=1, keepdims=True), # Check RGB values only
668
+ np.array([nonenriched_color]), # Apply the non-enriched color (with adjusted alpha)
669
+ network_colors, # Keep the original colors
655
670
  )
671
+
656
672
  return adjusted_network_colors
657
673
 
658
674
  def get_annotated_node_sizes(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.5b5
3
+ Version: 0.0.6b0
4
4
  Summary: A Python package for biological network analysis
5
5
  Author: Ira Horecka
6
6
  Author-email: Ira Horecka <ira89@icloud.com>
@@ -710,8 +710,7 @@ Requires-Dist: threadpoolctl
710
710
  Requires-Dist: tqdm
711
711
 
712
712
  <p align="center">
713
- <img src="./docs/github/risk-logo-dark.png#gh-dark-mode-only" width="400" />
714
- <img src="./docs/github/risk-logo-light.png#gh-light-mode-only" width="400" />
713
+ <img src="https://i.imgur.com/Fo9EmnK.png" width="400" />
715
714
  </p>
716
715
 
717
716
  <p align="center">
@@ -736,7 +735,7 @@ RISK is a software tool for visualizing spatial relationships in networks. It ai
736
735
 
737
736
  *Saccharomyces cerevisiae* proteins oriented by physical interactions discovered through affinity enrichment and mass spectrometry (Michaelis et al., 2023).
738
737
 
739
- ![PPI Network Demo](./docs/github/network.png)
738
+ ![PPI Network Demo](https://i.imgur.com/NnyK6nO.png)
740
739
 
741
740
  ## Installation
742
741
 
@@ -1,5 +1,5 @@
1
- risk/__init__.py,sha256=zGjRj03AbzDx0VGLJyR7TPzNLA1XQ5eLF7gbAKK507o,112
2
- risk/constants.py,sha256=AICk3x5qRQhls_ijTb4VdbdxU6mZ1aLGbAjLEdBwfJI,550
1
+ risk/__init__.py,sha256=IF4pnbb0hT2Ku49jwIG1EpkhgqUxp5qnolYAmF2ujds,112
2
+ risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
3
3
  risk/risk.py,sha256=UYM_Pf2Db-lbf4O5T2v5zKutz_GLXK-f43PgYT6xRyY,21328
4
4
  risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
5
5
  risk/annotations/annotations.py,sha256=DRUTdGzMdqo62NWSapBUksbvPr9CrzD76qtOcxeNKmo,10554
@@ -14,8 +14,8 @@ risk/neighborhoods/neighborhoods.py,sha256=SqYJaT49rUj77ts0XsPXb9cURM11aGh2Teks0
14
14
  risk/network/__init__.py,sha256=iEPeJdZfqp0toxtbElryB8jbz9_t_k4QQ3iDvKE8C_0,126
15
15
  risk/network/geometry.py,sha256=H1yGVVqgbfpzBzJwEheDLfvGLSA284jGQQTn612L4Vc,6759
16
16
  risk/network/graph.py,sha256=DTjNRQwgQbt6jJYDBHm7sgrdbZUDLL4HiZpdixkSI7Y,12433
17
- risk/network/io.py,sha256=otiRG6uT6HLgbbJql7X2wjYxab8OFJSgRoWJlcDoyu4,20291
18
- risk/network/plot.py,sha256=rg4pB0sndOnoayeNZSu4sU3sQ2P8x9ksE4XRTRP2HPM,40942
17
+ risk/network/io.py,sha256=8oncBfUaE-uDqWOr4OOWhR3ouhuOOzhnGlTUVxst3hs,20851
18
+ risk/network/plot.py,sha256=SXbHSBPNzrRw0m9xoENyRSgR6qHm2YoWMQat3PrFkI8,41866
19
19
  risk/stats/__init__.py,sha256=e-BE_Dr_jgiK6hKM-T-tlG4yvHnId8e5qjnM0pdwNVc,230
20
20
  risk/stats/fisher_exact.py,sha256=-bPwzu76-ob0HzrTV20mXUTot7v-MLuqFaAoab-QxPg,4966
21
21
  risk/stats/hypergeom.py,sha256=lrIFdhCWRjvM4apYw1MlOKqT_IY5OjtCwrjdtJdt6Tg,4954
@@ -23,8 +23,8 @@ risk/stats/stats.py,sha256=kvShov-94W6ffgDUTb522vB9hDJQSyTsYif_UIaFfSM,7059
23
23
  risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
24
24
  risk/stats/permutation/permutation.py,sha256=qLWdwxEY6nmkYPxpM8HLDcd2mbqYv9Qr7CKtJvhLqIM,9220
25
25
  risk/stats/permutation/test_functions.py,sha256=HuDIM-V1jkkfE1rlaIqrWWBSKZt3dQ1f-YEDjWpnLSE,2343
26
- risk_network-0.0.5b5.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
- risk_network-0.0.5b5.dist-info/METADATA,sha256=qSRqHP8c46IzvZU--rO7eUeir3LErWx98mPIbh0Q_c4,43236
28
- risk_network-0.0.5b5.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
29
- risk_network-0.0.5b5.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
- risk_network-0.0.5b5.dist-info/RECORD,,
26
+ risk_network-0.0.6b0.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
+ risk_network-0.0.6b0.dist-info/METADATA,sha256=TWOChIBPVrDKpp8wPEoCXayEWSp8M3uwdSQQw18rdMQ,43142
28
+ risk_network-0.0.6b0.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
29
+ risk_network-0.0.6b0.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
+ risk_network-0.0.6b0.dist-info/RECORD,,