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.
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/PKG-INFO +1 -1
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/__init__.py +1 -1
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/network/plot.py +105 -45
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk_network.egg-info/PKG-INFO +1 -1
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/LICENSE +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/MANIFEST.in +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/README.md +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/pyproject.toml +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/annotations/__init__.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/annotations/annotations.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/annotations/io.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/constants.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/log/__init__.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/log/console.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/log/params.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/neighborhoods/__init__.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/neighborhoods/community.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/neighborhoods/domains.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/neighborhoods/neighborhoods.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/network/__init__.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/network/geometry.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/network/graph.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/network/io.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/risk.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/__init__.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/fisher_exact.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/hypergeom.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/permutation/__init__.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/permutation/permutation.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/permutation/test_functions.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk/stats/stats.py +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk_network.egg-info/SOURCES.txt +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk_network.egg-info/dependency_links.txt +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk_network.egg-info/requires.txt +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/risk_network.egg-info/top_level.txt +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/setup.cfg +0 -0
- {risk_network-0.0.6b5 → risk_network-0.0.6b6}/setup.py +0 -0
@@ -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
|
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
|
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
|
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
|
636
|
+
# Initialize dictionaries and lists for valid indices
|
619
637
|
valid_indices = []
|
620
638
|
filtered_domain_centroids = {}
|
621
639
|
filtered_domain_terms = {}
|
622
|
-
#
|
623
|
-
|
624
|
-
#
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
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
|
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
|
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(
|
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
|
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.
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|