risk-network 0.0.6b5__tar.gz → 0.0.6b6__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.
Files changed (37) hide show
  1. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/PKG-INFO +1 -1
  2. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/__init__.py +1 -1
  3. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/network/plot.py +105 -45
  4. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk_network.egg-info/PKG-INFO +1 -1
  5. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/LICENSE +0 -0
  6. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/MANIFEST.in +0 -0
  7. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/README.md +0 -0
  8. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/pyproject.toml +0 -0
  9. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/annotations/__init__.py +0 -0
  10. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/annotations/annotations.py +0 -0
  11. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/annotations/io.py +0 -0
  12. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/constants.py +0 -0
  13. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/log/__init__.py +0 -0
  14. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/log/console.py +0 -0
  15. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/log/params.py +0 -0
  16. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/neighborhoods/__init__.py +0 -0
  17. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/neighborhoods/community.py +0 -0
  18. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/neighborhoods/domains.py +0 -0
  19. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/neighborhoods/neighborhoods.py +0 -0
  20. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/network/__init__.py +0 -0
  21. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/network/geometry.py +0 -0
  22. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/network/graph.py +0 -0
  23. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/network/io.py +0 -0
  24. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/risk.py +0 -0
  25. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/__init__.py +0 -0
  26. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/fisher_exact.py +0 -0
  27. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/hypergeom.py +0 -0
  28. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/permutation/__init__.py +0 -0
  29. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/permutation/permutation.py +0 -0
  30. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/permutation/test_functions.py +0 -0
  31. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/stats.py +0 -0
  32. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk_network.egg-info/SOURCES.txt +0 -0
  33. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk_network.egg-info/dependency_links.txt +0 -0
  34. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk_network.egg-info/requires.txt +0 -0
  35. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk_network.egg-info/top_level.txt +0 -0
  36. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/setup.cfg +0 -0
  37. {risk_network-0.0.6b5 → risk_network-0.0.6b6}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.6b5
3
+ Version: 0.0.6b6
4
4
  Summary: A Python package for biological network analysis
5
5
  Author: Ira Horecka
6
6
  Author-email: Ira Horecka <ira89@icloud.com>
@@ -7,4 +7,4 @@ RISK: RISK Infers Spatial Kinships
7
7
 
8
8
  from risk.risk import RISK
9
9
 
10
- __version__ = "0.0.6-beta.5"
10
+ __version__ = "0.0.6-beta.6"
@@ -550,6 +550,7 @@ class NetworkPlotter:
550
550
  fontcolor: Union[str, List, Tuple, np.ndarray] = "black",
551
551
  fontalpha: float = 1.0,
552
552
  arrow_linewidth: float = 1,
553
+ arrow_style: str = "->",
553
554
  arrow_color: Union[str, List, Tuple, np.ndarray] = "black",
554
555
  arrow_alpha: float = 1.0,
555
556
  max_labels: Union[int, None] = None,
@@ -557,7 +558,10 @@ class NetworkPlotter:
557
558
  min_words: int = 1,
558
559
  max_word_length: int = 20,
559
560
  min_word_length: int = 1,
560
- words_to_omit: Union[List[str], None] = None,
561
+ words_to_omit: Union[List, None] = None,
562
+ overlay_ids: bool = False,
563
+ ids_to_keep: Union[List, Tuple, np.ndarray, None] = None,
564
+ ids_to_replace: Union[Dict, None] = None,
561
565
  ) -> None:
562
566
  """Annotate the network graph with labels for different domains, positioned around the network for clarity.
563
567
 
@@ -569,6 +573,7 @@ class NetworkPlotter:
569
573
  fontcolor (str, list, tuple, or np.ndarray, optional): Color of the label text. Can be a string or RGBA array. Defaults to "black".
570
574
  fontalpha (float, optional): Transparency level for the font color. Defaults to 1.0.
571
575
  arrow_linewidth (float, optional): Line width of the arrows pointing to centroids. Defaults to 1.
576
+ arrow_style (str, optional): Style of the arrows pointing to centroids. Defaults to "->".
572
577
  arrow_color (str, list, tuple, or np.ndarray, optional): Color of the arrows. Defaults to "black".
573
578
  arrow_alpha (float, optional): Transparency level for the arrow color. Defaults to 1.0.
574
579
  max_labels (int, optional): Maximum number of labels to plot. Defaults to None (no limit).
@@ -576,7 +581,16 @@ class NetworkPlotter:
576
581
  min_words (int, optional): Minimum number of words required to display a label. Defaults to 1.
577
582
  max_word_length (int, optional): Maximum number of characters in a word to display. Defaults to 20.
578
583
  min_word_length (int, optional): Minimum number of characters in a word to display. Defaults to 1.
579
- words_to_omit (List[str], optional): List of words to omit from the labels. Defaults to None.
584
+ words_to_omit (List, optional): List of words to omit from the labels. Defaults to None.
585
+ overlay_ids (bool, optional): Whether to overlay domain IDs in the center of the centroids. Defaults to False.
586
+ ids_to_keep (list, tuple, np.ndarray, or None, optional): IDs of domains that must be labeled. To discover domain IDs,
587
+ you can set `overlay_ids=True`. Defaults to None.
588
+ ids_to_replace (dict, optional): A dictionary mapping domain IDs to custom labels (strings). The labels should be space-separated words.
589
+ If provided, the custom labels will replace the default domain terms. To discover domain IDs, you can set `overlay_ids=True`.
590
+ Defaults to None.
591
+
592
+ Raises:
593
+ ValueError: If the number of provided `ids_to_keep` exceeds `max_labels`.
580
594
  """
581
595
  # Log the plotting parameters
582
596
  params.log_plotter(
@@ -589,6 +603,7 @@ class NetworkPlotter:
589
603
  ), # np.ndarray usually indicates custom colors
590
604
  label_fontalpha=fontalpha,
591
605
  label_arrow_linewidth=arrow_linewidth,
606
+ label_arrow_style=arrow_style,
592
607
  label_arrow_color="custom" if isinstance(arrow_color, np.ndarray) else arrow_color,
593
608
  label_arrow_alpha=arrow_alpha,
594
609
  label_max_labels=max_labels,
@@ -597,9 +612,12 @@ class NetworkPlotter:
597
612
  label_max_word_length=max_word_length,
598
613
  label_min_word_length=min_word_length,
599
614
  label_words_to_omit=words_to_omit,
615
+ label_overlay_ids=overlay_ids,
616
+ label_ids_to_keep=ids_to_keep,
617
+ label_ids_to_replace=ids_to_replace,
600
618
  )
601
619
 
602
- # Convert colors to RGBA using the _to_rgba helper function, applying alpha separately for font and arrow
620
+ # Convert colors to RGBA using the _to_rgba helper function
603
621
  fontcolor = _to_rgba(fontcolor, fontalpha, num_repeats=len(self.graph.domain_to_nodes_map))
604
622
  arrow_color = _to_rgba(
605
623
  arrow_color, arrow_alpha, num_repeats=len(self.graph.domain_to_nodes_map)
@@ -615,55 +633,82 @@ class NetworkPlotter:
615
633
  if nodes: # Skip if the domain has no nodes
616
634
  domain_centroids[domain] = self._calculate_domain_centroid(nodes)
617
635
 
618
- # Initialize empty lists to collect valid indices
636
+ # Initialize dictionaries and lists for valid indices
619
637
  valid_indices = []
620
638
  filtered_domain_centroids = {}
621
639
  filtered_domain_terms = {}
622
- # Loop through domain_centroids with index
623
- for idx, (domain, centroid) in enumerate(domain_centroids.items()):
624
- # Process the domain term
625
- terms = self.graph.trimmed_domain_to_term[domain].split(" ")
626
- # Remove words_to_omit
627
- if words_to_omit:
628
- terms = [term for term in terms if term.lower() not in words_to_omit]
629
- # Filter words based on length
630
- terms = [term for term in terms if min_word_length <= len(term) <= max_word_length]
631
- # Trim to max_words
632
- terms = terms[:max_words]
633
- # Check if the domain passes the word count condition
634
- if len(terms) >= min_words:
635
- # Add to filtered_domain_centroids
636
- filtered_domain_centroids[domain] = centroid
637
- # Store the filtered and trimmed terms
638
- filtered_domain_terms[domain] = " ".join(terms)
639
- # Keep track of the valid index - used for fontcolor and arrow_color
640
- valid_indices.append(idx)
641
-
642
- # If max_labels is specified and less than the available labels
643
- if max_labels is not None and max_labels < len(filtered_domain_centroids):
644
- step = len(filtered_domain_centroids) / max_labels
645
- selected_indices = [int(i * step) for i in range(max_labels)]
646
- # Filter the centroids, terms, and valid_indices to only use the selected indices
647
- filtered_domain_centroids = {
648
- k: v
649
- for i, (k, v) in enumerate(filtered_domain_centroids.items())
650
- if i in selected_indices
651
- }
652
- filtered_domain_terms = {
653
- k: v
654
- for i, (k, v) in enumerate(filtered_domain_terms.items())
655
- if i in selected_indices
656
- }
657
- # Update valid_indices to match selected indices
658
- valid_indices = [valid_indices[i] for i in selected_indices]
640
+ # Handle the ids_to_keep logic
641
+ if ids_to_keep:
642
+ # Check if the number of provided ids_to_keep exceeds max_labels
643
+ if max_labels is not None and len(ids_to_keep) > max_labels:
644
+ raise ValueError(
645
+ f"Number of provided IDs ({len(ids_to_keep)}) exceeds max_labels ({max_labels})."
646
+ )
647
+
648
+ # Process the specified IDs first
649
+ for domain in ids_to_keep:
650
+ if domain in self.graph.trimmed_domain_to_term and domain in domain_centroids:
651
+ # Handle ids_to_replace logic here for ids_to_keep
652
+ if ids_to_replace and domain in ids_to_replace:
653
+ terms = ids_to_replace[domain].split(" ")
654
+ else:
655
+ terms = self.graph.trimmed_domain_to_term[domain].split(" ")
656
+
657
+ # Apply words_to_omit, word length constraints, and max_words
658
+ if words_to_omit:
659
+ terms = [term for term in terms if term.lower() not in words_to_omit]
660
+ terms = [
661
+ term for term in terms if min_word_length <= len(term) <= max_word_length
662
+ ]
663
+ terms = terms[:max_words]
664
+
665
+ # Check if the domain passes the word count condition
666
+ if len(terms) >= min_words:
667
+ filtered_domain_centroids[domain] = domain_centroids[domain]
668
+ filtered_domain_terms[domain] = " ".join(terms)
669
+ valid_indices.append(
670
+ list(domain_centroids.keys()).index(domain)
671
+ ) # Track the valid index
672
+
673
+ # Calculate remaining labels to plot after processing ids_to_keep
674
+ remaining_labels = (
675
+ max_labels - len(ids_to_keep) if ids_to_keep and max_labels else max_labels
676
+ )
677
+ # Process remaining domains to fill in additional labels, if there are slots left
678
+ if remaining_labels and remaining_labels > 0:
679
+ for idx, (domain, centroid) in enumerate(domain_centroids.items()):
680
+ if ids_to_keep and domain in ids_to_keep:
681
+ continue # Skip domains already handled by ids_to_keep
682
+
683
+ # Handle ids_to_replace logic first
684
+ if ids_to_replace and domain in ids_to_replace:
685
+ terms = ids_to_replace[domain].split(" ")
686
+ else:
687
+ terms = self.graph.trimmed_domain_to_term[domain].split(" ")
688
+
689
+ # Apply words_to_omit, word length constraints, and max_words
690
+ if words_to_omit:
691
+ terms = [term for term in terms if term.lower() not in words_to_omit]
692
+
693
+ terms = [term for term in terms if min_word_length <= len(term) <= max_word_length]
694
+ terms = terms[:max_words]
695
+ # Check if the domain passes the word count condition
696
+ if len(terms) >= min_words:
697
+ filtered_domain_centroids[domain] = centroid
698
+ filtered_domain_terms[domain] = " ".join(terms)
699
+ valid_indices.append(idx) # Track the valid index
700
+
701
+ # Stop once we've reached the max_labels limit
702
+ if len(filtered_domain_centroids) >= max_labels:
703
+ break
659
704
 
660
705
  # Calculate the bounding box around the network
661
706
  center, radius = _calculate_bounding_box(self.graph.node_coordinates, radius_margin=scale)
662
- # Calculate the best positions for labels around the perimeter
707
+ # Calculate the best positions for labels
663
708
  best_label_positions = _calculate_best_label_positions(
664
709
  filtered_domain_centroids, center, radius, offset
665
710
  )
666
- # Annotate the network with labels - valid_indices is used for fontcolor and arrow_color
711
+ # Annotate the network with labels
667
712
  for idx, (domain, pos) in zip(valid_indices, best_label_positions.items()):
668
713
  centroid = filtered_domain_centroids[domain]
669
714
  annotations = filtered_domain_terms[domain].split(" ")[:max_words]
@@ -677,8 +722,23 @@ class NetworkPlotter:
677
722
  fontsize=fontsize,
678
723
  fontname=font,
679
724
  color=fontcolor[idx],
680
- arrowprops=dict(arrowstyle="->", color=arrow_color[idx], linewidth=arrow_linewidth),
725
+ arrowprops=dict(
726
+ arrowstyle=arrow_style, color=arrow_color[idx], linewidth=arrow_linewidth
727
+ ),
681
728
  )
729
+ # Overlay domain ID at the centroid if requested
730
+ if overlay_ids:
731
+ self.ax.text(
732
+ centroid[0],
733
+ centroid[1],
734
+ domain,
735
+ ha="center",
736
+ va="center",
737
+ fontsize=fontsize,
738
+ fontname=font,
739
+ color=fontcolor[idx],
740
+ alpha=fontalpha,
741
+ )
682
742
 
683
743
  def plot_sublabel(
684
744
  self,
@@ -698,7 +758,7 @@ class NetworkPlotter:
698
758
  """Annotate the network graph with a single label for the given nodes, positioned at a specified radial angle.
699
759
 
700
760
  Args:
701
- nodes (List[str]): List of node labels to be used for calculating the centroid.
761
+ nodes (List): List of node labels to be used for calculating the centroid.
702
762
  label (str): The label to be annotated on the network.
703
763
  radial_position (float, optional): Radial angle for positioning the label, in degrees (0-360). Defaults to 0.0.
704
764
  scale (float, optional): Scale factor for positioning the label around the perimeter. Defaults to 1.05.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.6b5
3
+ Version: 0.0.6b6
4
4
  Summary: A Python package for biological network analysis
5
5
  Author: Ira Horecka
6
6
  Author-email: Ira Horecka <ira89@icloud.com>
File without changes
File without changes
File without changes
File without changes