risk-network 0.0.8b3__tar.gz → 0.0.8b4__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.8b3 → risk_network-0.0.8b4}/PKG-INFO +1 -1
  2. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/__init__.py +1 -1
  3. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/network/plot.py +112 -37
  4. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk_network.egg-info/PKG-INFO +1 -1
  5. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/LICENSE +0 -0
  6. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/MANIFEST.in +0 -0
  7. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/README.md +0 -0
  8. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/pyproject.toml +0 -0
  9. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/annotations/__init__.py +0 -0
  10. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/annotations/annotations.py +0 -0
  11. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/annotations/io.py +0 -0
  12. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/constants.py +0 -0
  13. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/log/__init__.py +0 -0
  14. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/log/config.py +0 -0
  15. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/log/params.py +0 -0
  16. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/neighborhoods/__init__.py +0 -0
  17. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/neighborhoods/community.py +0 -0
  18. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/neighborhoods/domains.py +0 -0
  19. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/neighborhoods/neighborhoods.py +0 -0
  20. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/network/__init__.py +0 -0
  21. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/network/geometry.py +0 -0
  22. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/network/graph.py +0 -0
  23. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/network/io.py +0 -0
  24. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/risk.py +0 -0
  25. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/stats/__init__.py +0 -0
  26. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/stats/hypergeom.py +0 -0
  27. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/stats/permutation/__init__.py +0 -0
  28. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/stats/permutation/permutation.py +0 -0
  29. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/stats/permutation/test_functions.py +0 -0
  30. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/stats/poisson.py +0 -0
  31. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk/stats/stats.py +0 -0
  32. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk_network.egg-info/SOURCES.txt +0 -0
  33. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk_network.egg-info/dependency_links.txt +0 -0
  34. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk_network.egg-info/requires.txt +0 -0
  35. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/risk_network.egg-info/top_level.txt +0 -0
  36. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/setup.cfg +0 -0
  37. {risk_network-0.0.8b3 → risk_network-0.0.8b4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.8b3
3
+ Version: 0.0.8b4
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.8-beta.3"
10
+ __version__ = "0.0.8-beta.4"
@@ -705,10 +705,10 @@ class NetworkPlotter:
705
705
  arrow_base_shrink (float, optional): Distance between the text and the base of the arrow. Defaults to 0.0.
706
706
  arrow_tip_shrink (float, optional): Distance between the arrow tip and the centroid. Defaults to 0.0.
707
707
  max_labels (int, optional): Maximum number of labels to plot. Defaults to None (no limit).
708
- max_label_lines (int, optional): Maximum number of lines in a label. Defaults to None (no limit).
709
708
  min_label_lines (int, optional): Minimum number of lines in a label. Defaults to 1.
710
- max_chars_per_line (int, optional): Maximum number of characters in a line to display. Defaults to None (no limit).
709
+ max_label_lines (int, optional): Maximum number of lines in a label. Defaults to None (no limit).
711
710
  min_chars_per_line (int, optional): Minimum number of characters in a line to display. Defaults to 1.
711
+ max_chars_per_line (int, optional): Maximum number of characters in a line to display. Defaults to None (no limit).
712
712
  words_to_omit (list, optional): List of words to omit from the labels. Defaults to None.
713
713
  overlay_ids (bool, optional): Whether to overlay domain IDs in the center of the centroids. Defaults to False.
714
714
  ids_to_keep (list, tuple, np.ndarray, or None, optional): IDs of domains that must be labeled. To discover domain IDs,
@@ -761,11 +761,11 @@ class NetworkPlotter:
761
761
  if words_to_omit:
762
762
  words_to_omit = set(word.lower() for word in words_to_omit)
763
763
 
764
- # Calculate the center and radius of the network
765
- domain_centroids = {}
764
+ # Calculate the center and radius of domains to position labels around the network
765
+ domain_id_to_centroid_map = {}
766
766
  for domain_id, node_ids in self.graph.domain_id_to_node_ids_map.items():
767
767
  if node_ids: # Skip if the domain has no nodes
768
- domain_centroids[domain_id] = self._calculate_domain_centroid(node_ids)
768
+ domain_id_to_centroid_map[domain_id] = self._calculate_domain_centroid(node_ids)
769
769
 
770
770
  # Initialize dictionaries and lists for valid indices
771
771
  valid_indices = [] # List of valid indices to plot colors and arrows
@@ -775,8 +775,8 @@ class NetworkPlotter:
775
775
  if ids_to_keep:
776
776
  # Process the ids_to_keep first INPLACE
777
777
  self._process_ids_to_keep(
778
+ domain_id_to_centroid_map=domain_id_to_centroid_map,
778
779
  ids_to_keep=ids_to_keep,
779
- domain_centroids=domain_centroids,
780
780
  ids_to_replace=ids_to_replace,
781
781
  words_to_omit=words_to_omit,
782
782
  max_labels=max_labels,
@@ -796,7 +796,7 @@ class NetworkPlotter:
796
796
  # Process remaining domains INPLACE to fill in additional labels, if there are slots left
797
797
  if remaining_labels and remaining_labels > 0:
798
798
  self._process_remaining_domains(
799
- domain_centroids=domain_centroids,
799
+ domain_id_to_centroid_map=domain_id_to_centroid_map,
800
800
  ids_to_keep=ids_to_keep,
801
801
  ids_to_replace=ids_to_replace,
802
802
  words_to_omit=words_to_omit,
@@ -977,8 +977,8 @@ class NetworkPlotter:
977
977
 
978
978
  def _process_ids_to_keep(
979
979
  self,
980
+ domain_id_to_centroid_map: Dict[str, np.ndarray],
980
981
  ids_to_keep: Union[List[str], Tuple[str], np.ndarray],
981
- domain_centroids: Dict[str, np.ndarray],
982
982
  ids_to_replace: Union[Dict[str, str], None],
983
983
  words_to_omit: Union[List[str], None],
984
984
  max_labels: Union[int, None],
@@ -993,8 +993,8 @@ class NetworkPlotter:
993
993
  """Process the ids_to_keep, apply filtering, and store valid domain centroids and terms.
994
994
 
995
995
  Args:
996
+ domain_id_to_centroid_map (dict): Mapping of domain IDs to their centroids.
996
997
  ids_to_keep (list, tuple, or np.ndarray, optional): IDs of domains that must be labeled.
997
- domain_centroids (dict): Mapping of domains to their centroids.
998
998
  ids_to_replace (dict, optional): A dictionary mapping domain IDs to custom labels. Defaults to None.
999
999
  words_to_omit (list, optional): List of words to omit from the labels. Defaults to None.
1000
1000
  max_labels (int, optional): Maximum number of labels allowed.
@@ -1020,25 +1020,30 @@ class NetworkPlotter:
1020
1020
 
1021
1021
  # Process each domain in ids_to_keep
1022
1022
  for domain in ids_to_keep:
1023
- if domain in self.graph.domain_id_to_domain_terms_map and domain in domain_centroids:
1024
- domain_terms = self._process_terms(
1023
+ if (
1024
+ domain in self.graph.domain_id_to_domain_terms_map
1025
+ and domain in domain_id_to_centroid_map
1026
+ ):
1027
+ domain_centroid = domain_id_to_centroid_map[domain]
1028
+ # No need to filter the domain terms if it is in ids_to_keep
1029
+ _ = self._validate_and_update_domain(
1025
1030
  domain=domain,
1031
+ domain_centroid=domain_centroid,
1032
+ domain_id_to_centroid_map=domain_id_to_centroid_map,
1026
1033
  ids_to_replace=ids_to_replace,
1027
1034
  words_to_omit=words_to_omit,
1035
+ min_label_lines=min_label_lines,
1028
1036
  max_label_lines=max_label_lines,
1029
1037
  min_chars_per_line=min_chars_per_line,
1030
1038
  max_chars_per_line=max_chars_per_line,
1039
+ filtered_domain_centroids=filtered_domain_centroids,
1040
+ filtered_domain_terms=filtered_domain_terms,
1041
+ valid_indices=valid_indices,
1031
1042
  )
1032
- num_domain_lines = len(domain_terms.split(TERM_DELIMITER))
1033
- # Check if the number of lines in the label is greater than or equal to the minimum
1034
- if num_domain_lines >= min_label_lines:
1035
- filtered_domain_terms[domain] = domain_terms
1036
- filtered_domain_centroids[domain] = domain_centroids[domain]
1037
- valid_indices.append(list(domain_centroids.keys()).index(domain))
1038
1043
 
1039
1044
  def _process_remaining_domains(
1040
1045
  self,
1041
- domain_centroids: Dict[str, np.ndarray],
1046
+ domain_id_to_centroid_map: Dict[str, np.ndarray],
1042
1047
  ids_to_keep: Union[List[str], Tuple[str], np.ndarray],
1043
1048
  ids_to_replace: Union[Dict[str, str], None],
1044
1049
  words_to_omit: Union[List[str], None],
@@ -1054,7 +1059,7 @@ class NetworkPlotter:
1054
1059
  """Process remaining domains to fill in additional labels, respecting the remaining_labels limit.
1055
1060
 
1056
1061
  Args:
1057
- domain_centroids (dict): Mapping of domains to their centroids.
1062
+ domain_id_to_centroid_map (dict): Mapping of domain IDs to their centroids.
1058
1063
  ids_to_keep (list, tuple, or np.ndarray, optional): IDs of domains that must be labeled.
1059
1064
  ids_to_replace (dict, optional): A dictionary mapping domain IDs to custom labels. Defaults to None.
1060
1065
  words_to_omit (list, optional): List of words to omit from the labels. Defaults to None.
@@ -1066,13 +1071,16 @@ class NetworkPlotter:
1066
1071
  filtered_domain_centroids (dict): Dictionary to store filtered domain centroids (output).
1067
1072
  filtered_domain_terms (dict): Dictionary to store filtered domain terms (output).
1068
1073
  valid_indices (list): List to store valid indices (output).
1074
+
1075
+ Note:
1076
+ The `filtered_domain_centroids`, `filtered_domain_terms`, and `valid_indices` are modified in-place.
1069
1077
  """
1070
1078
  # Counter to track how many labels have been created
1071
1079
  label_count = 0
1072
1080
  # Collect domains not in ids_to_keep
1073
1081
  remaining_domains = {
1074
1082
  domain: centroid
1075
- for domain, centroid in domain_centroids.items()
1083
+ for domain, centroid in domain_id_to_centroid_map.items()
1076
1084
  if domain not in ids_to_keep and not pd.isna(domain)
1077
1085
  }
1078
1086
 
@@ -1112,26 +1120,89 @@ class NetworkPlotter:
1112
1120
 
1113
1121
  # Process the selected domains and add to filtered lists
1114
1122
  for domain in selected_domains:
1115
- centroid = remaining_domains[domain]
1116
- domain_terms = self._process_terms(
1123
+ domain_centroid = remaining_domains[domain]
1124
+ is_domain_valid = self._validate_and_update_domain(
1117
1125
  domain=domain,
1126
+ domain_centroid=domain_centroid,
1127
+ domain_id_to_centroid_map=domain_id_to_centroid_map,
1118
1128
  ids_to_replace=ids_to_replace,
1119
1129
  words_to_omit=words_to_omit,
1130
+ min_label_lines=min_label_lines,
1120
1131
  max_label_lines=max_label_lines,
1121
1132
  min_chars_per_line=min_chars_per_line,
1122
1133
  max_chars_per_line=max_chars_per_line,
1134
+ filtered_domain_centroids=filtered_domain_centroids,
1135
+ filtered_domain_terms=filtered_domain_terms,
1136
+ valid_indices=valid_indices,
1123
1137
  )
1124
- num_domain_lines = len(domain_terms.split(TERM_DELIMITER))
1125
- # Check if the number of lines in the label is greater than or equal to the minimum
1126
- if num_domain_lines >= min_label_lines:
1127
- filtered_domain_centroids[domain] = centroid
1128
- filtered_domain_terms[domain] = domain_terms
1129
- valid_indices.append(list(domain_centroids.keys()).index(domain))
1130
-
1138
+ # Increment the label count if the domain is valid
1139
+ if is_domain_valid:
1131
1140
  label_count += 1
1132
1141
  if label_count >= remaining_labels:
1133
1142
  break
1134
1143
 
1144
+ def _validate_and_update_domain(
1145
+ self,
1146
+ domain: str,
1147
+ domain_centroid: np.ndarray,
1148
+ domain_id_to_centroid_map: Dict[str, np.ndarray],
1149
+ ids_to_replace: Union[Dict[str, str], None],
1150
+ words_to_omit: Union[List[str], None],
1151
+ min_label_lines: int,
1152
+ max_label_lines: int,
1153
+ min_chars_per_line: int,
1154
+ max_chars_per_line: int,
1155
+ filtered_domain_centroids: Dict[str, np.ndarray],
1156
+ filtered_domain_terms: Dict[str, str],
1157
+ valid_indices: List[int],
1158
+ ) -> bool:
1159
+ """Validate and process the domain terms, updating relevant dictionaries if valid.
1160
+
1161
+ Args:
1162
+ domain (str): Domain ID to process.
1163
+ domain_centroid (np.ndarray): Centroid position of the domain.
1164
+ domain_id_to_centroid_map (dict): Mapping of domain IDs to their centroids.
1165
+ ids_to_replace (Union[Dict[str, str], None]): A dictionary mapping domain IDs to custom labels.
1166
+ words_to_omit (Union[List[str], None]): List of words to omit from the labels.
1167
+ min_label_lines (int): Minimum number of lines required in a label.
1168
+ max_label_lines (int): Maximum number of lines allowed in a label.
1169
+ min_chars_per_line (int): Minimum number of characters allowed per line.
1170
+ max_chars_per_line (int): Maximum number of characters allowed per line.
1171
+ filtered_domain_centroids (Dict[str, np.ndarray]): Dictionary to store valid domain centroids.
1172
+ filtered_domain_terms (Dict[str, str]): Dictionary to store valid domain terms.
1173
+ valid_indices (List[int]): List of valid domain indices.
1174
+
1175
+ Returns:
1176
+ bool: True if the domain is valid and added to the filtered dictionaries, False otherwise.
1177
+
1178
+ Note:
1179
+ The `filtered_domain_centroids`, `filtered_domain_terms`, and `valid_indices` are modified in-place.
1180
+ """
1181
+ # Process the domain terms
1182
+ domain_terms = self._process_terms(
1183
+ domain=domain,
1184
+ ids_to_replace=ids_to_replace,
1185
+ words_to_omit=words_to_omit,
1186
+ max_label_lines=max_label_lines,
1187
+ min_chars_per_line=min_chars_per_line,
1188
+ max_chars_per_line=max_chars_per_line,
1189
+ )
1190
+ # If domain_terms is empty, skip further processing
1191
+ if not domain_terms:
1192
+ return False
1193
+
1194
+ # Split the terms by TERM_DELIMITER and count the number of lines
1195
+ num_domain_lines = len(domain_terms.split(TERM_DELIMITER))
1196
+ # Check if the number of lines is greater than or equal to the minimum
1197
+ if num_domain_lines >= min_label_lines:
1198
+ filtered_domain_centroids[domain] = domain_centroid
1199
+ filtered_domain_terms[domain] = domain_terms
1200
+ # Add the index of the domain to the valid indices list
1201
+ valid_indices.append(list(domain_id_to_centroid_map.keys()).index(domain))
1202
+ return True
1203
+
1204
+ return False
1205
+
1135
1206
  def _process_terms(
1136
1207
  self,
1137
1208
  domain: str,
@@ -1152,7 +1223,7 @@ class NetworkPlotter:
1152
1223
  max_chars_per_line (int): Maximum number of characters in a line to display.
1153
1224
 
1154
1225
  Returns:
1155
- list: Processed terms, with words combined if necessary to fit within constraints.
1226
+ str: Processed terms separated by TERM_DELIMITER, with words combined if necessary to fit within constraints.
1156
1227
  """
1157
1228
  # Handle ids_to_replace logic
1158
1229
  if ids_to_replace and domain in ids_to_replace:
@@ -1487,13 +1558,13 @@ def _calculate_bounding_box(
1487
1558
  return center, radius
1488
1559
 
1489
1560
 
1490
- def _combine_words(words: List[str], max_length: int, max_label_lines: int) -> str:
1491
- """Combine words to fit within the max_length and max_label_lines constraints,
1492
- and separate the final output by ':' for plotting.
1561
+ def _combine_words(words: List[str], max_chars_per_line: int, max_label_lines: int) -> str:
1562
+ """Combine words to fit within the max_chars_per_line and max_label_lines constraints,
1563
+ and separate the final output by TERM_DELIMITER for plotting.
1493
1564
 
1494
1565
  Args:
1495
1566
  words (List[str]): List of words to combine.
1496
- max_length (int): Maximum allowed length for a combined line.
1567
+ max_chars_per_line (int): Maximum number of characters in a line to display.
1497
1568
  max_label_lines (int): Maximum number of lines in a label.
1498
1569
 
1499
1570
  Returns:
@@ -1510,14 +1581,18 @@ def _combine_words(words: List[str], max_length: int, max_label_lines: int) -> s
1510
1581
  # Try to combine more words if possible, and ensure the combination fits within max_length
1511
1582
  for j in range(i + 1, len(words_batch)):
1512
1583
  next_word = words_batch[j]
1513
- if len(combined_word) + len(next_word) + 2 <= max_length: # +2 for ', '
1584
+ # Ensure that the combined word fits within the max_chars_per_line limit
1585
+ if len(combined_word) + len(next_word) + 1 <= max_chars_per_line: # +1 for space
1514
1586
  combined_word = f"{combined_word} {next_word}"
1515
1587
  i += 1 # Move past the combined word
1516
1588
  else:
1517
1589
  break # Stop combining if the length is exceeded
1518
1590
 
1519
- combined_lines.append(combined_word) # Add the combined word or single word
1520
- i += 1 # Move to the next word
1591
+ # Add the combined word only if it fits within the max_chars_per_line limit
1592
+ if len(combined_word) <= max_chars_per_line:
1593
+ combined_lines.append(combined_word) # Add the combined word
1594
+ # Move to the next word
1595
+ i += 1
1521
1596
 
1522
1597
  # Stop if we've reached the max_label_lines limit
1523
1598
  if len(combined_lines) >= max_label_lines:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.8b3
3
+ Version: 0.0.8b4
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