risk-network 0.0.7b7__py3-none-any.whl → 0.0.7b9__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.7-beta.7"
10
+ __version__ = "0.0.7-beta.9"
@@ -177,19 +177,18 @@ def get_description(words_column: pd.Series) -> str:
177
177
  all_words = words_column.str.cat(sep=" ")
178
178
  tokens = word_tokenize(all_words)
179
179
 
180
- # Check if all tokens are numeric strings or contain a mixture of strings and numbers
180
+ # Separate numeric tokens
181
181
  numeric_tokens = [token for token in tokens if token.replace(".", "", 1).isdigit()]
182
- non_numeric_tokens = [token for token in tokens if not token.replace(".", "", 1).isdigit()]
183
182
  # If there's only one unique numeric value, return it directly as a string
184
183
  unique_numeric_values = set(numeric_tokens)
185
184
  if len(unique_numeric_values) == 1:
186
185
  return f"{list(unique_numeric_values)[0]}"
187
186
 
188
- # Allow the inclusion of both alphabetic and numeric tokens if mixture is detected
187
+ # Ensure that all values in 'words' are strings and include both alphabetic and numeric tokens
189
188
  words = [
190
- (
189
+ str(
191
190
  word.lower() if word.istitle() else word
192
- ) # Lowercase all words except proper nouns (e.g., RNA, mRNA)
191
+ ) # Convert to string and lowercase all words except proper nouns (e.g., RNA, mRNA)
193
192
  for word in tokens
194
193
  if word.isalpha()
195
194
  or word.replace(".", "", 1).isdigit() # Keep alphabetic words and numeric strings
@@ -263,11 +262,11 @@ def _generate_coherent_description(words: List[str]) -> str:
263
262
  Returns:
264
263
  str: A coherent description formed by arranging the words in a logical sequence.
265
264
  """
266
- # If there are no words or the input is invalid, raise an error
267
- if not words or not isinstance(words, list) or not all(isinstance(word, str) for word in words):
268
- raise ValueError("Input must be a list of strings.")
265
+ # If there are no words, return a keyword indicating no data is available
266
+ if not words:
267
+ return "N/A"
269
268
 
270
- # If there's only one unique word, return it directly (even if it's a number-like string)
269
+ # If there's only one unique word, return it directly
271
270
  unique_words = set(words)
272
271
  if len(unique_words) == 1:
273
272
  return list(unique_words)[0]
@@ -4,6 +4,7 @@ risk/neighborhoods/domains
4
4
  """
5
5
 
6
6
  from contextlib import suppress
7
+ from itertools import product
7
8
  from tqdm import tqdm
8
9
  from typing import Tuple
9
10
 
@@ -165,21 +166,20 @@ def _optimize_silhouette_across_linkage_and_metrics(
165
166
  total_combinations = len(linkage_methods) * len(linkage_metrics)
166
167
 
167
168
  # Evaluating optimal linkage method and metric
168
- for method in tqdm(
169
- linkage_methods,
169
+ for method, metric in tqdm(
170
+ product(linkage_methods, linkage_metrics),
170
171
  desc="Evaluating optimal linkage method and metric",
171
172
  total=total_combinations,
172
173
  bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}]",
173
174
  ):
174
- for metric in linkage_metrics:
175
- with suppress(Exception):
176
- Z = linkage(m, method=method, metric=metric)
177
- threshold, score = _find_best_silhouette_score(Z, m, metric, linkage_criterion)
178
- if score > best_overall_score:
179
- best_overall_score = score
180
- best_overall_threshold = threshold
181
- best_overall_method = method
182
- best_overall_metric = metric
175
+ with suppress(Exception):
176
+ Z = linkage(m, method=method, metric=metric)
177
+ threshold, score = _find_best_silhouette_score(Z, m, metric, linkage_criterion)
178
+ if score > best_overall_score:
179
+ best_overall_score = score
180
+ best_overall_threshold = threshold
181
+ best_overall_method = method
182
+ best_overall_metric = metric
183
183
 
184
184
  return best_overall_method, best_overall_metric, best_overall_threshold
185
185
 
@@ -54,10 +54,10 @@ def get_network_neighborhoods(
54
54
  network, edge_length_percentile=edge_length_threshold
55
55
  )
56
56
 
57
- if distance_metric == "greedy_modularity":
58
- return calculate_greedy_modularity_neighborhoods(network)
59
57
  if distance_metric == "louvain":
60
58
  return calculate_louvain_neighborhoods(network, louvain_resolution, random_seed=random_seed)
59
+ if distance_metric == "greedy_modularity":
60
+ return calculate_greedy_modularity_neighborhoods(network)
61
61
  if distance_metric == "label_propagation":
62
62
  return calculate_label_propagation_neighborhoods(network)
63
63
  if distance_metric == "markov_clustering":
risk/stats/hypergeom.py CHANGED
@@ -22,9 +22,7 @@ def compute_hypergeom_test(
22
22
  Returns:
23
23
  dict: Dictionary containing depletion and enrichment p-values.
24
24
  """
25
- # Ensure both matrices are binary (presence/absence)
26
- neighborhoods = (neighborhoods > 0).astype(int)
27
- annotations = (annotations > 0).astype(int)
25
+ # Get the total number of nodes in the network
28
26
  total_node_count = neighborhoods.shape[0]
29
27
 
30
28
  if null_distribution == "network":
risk/stats/poisson.py CHANGED
@@ -22,9 +22,6 @@ def compute_poisson_test(
22
22
  Returns:
23
23
  dict: Dictionary containing depletion and enrichment p-values.
24
24
  """
25
- # Ensure both matrices are binary (presence/absence)
26
- neighborhoods = (neighborhoods > 0).astype(int)
27
- annotations = (annotations > 0).astype(int)
28
25
  # Matrix multiplication to get the number of annotated nodes in each neighborhood
29
26
  annotated_in_neighborhood = neighborhoods @ annotations
30
27
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.7b7
3
+ Version: 0.0.7b9
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,30 +1,30 @@
1
- risk/__init__.py,sha256=0dNrjhRgqzBRG5Rqy_GKy_8ETWm10xSCYvaOm6fdI0Q,112
1
+ risk/__init__.py,sha256=Pj1ulqySghRcgi9kiMTvpjr7Mw5dg4vtjEdAkyImDFU,112
2
2
  risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
3
3
  risk/risk.py,sha256=6666BzdMTgOaQl98ZKiJ19c6XBot26eTJ0iIlk-ZCZQ,20515
4
4
  risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
5
- risk/annotations/annotations.py,sha256=k9LGTL2uqdYvI5F3jU3UKz-O855B-DoazGPMzSn-XUc,11673
5
+ risk/annotations/annotations.py,sha256=3FFyJE9Gp5oRN72_8iVAUnecsmTtx2G2fp5AlCY1oUk,11405
6
6
  risk/annotations/io.py,sha256=lo7NKqOVkeeBp58JBxWJHtA0xjL5Yoxqe9Ox0daKlZk,9457
7
7
  risk/log/__init__.py,sha256=xuLImfxFlKpnVhzi_gDYlr2_c9cLkrw2c_3iEsXb1as,107
8
8
  risk/log/console.py,sha256=im9DRExwf6wHlcn9fewoDcKIpo3vPcorZIaNAl-0csY,355
9
9
  risk/log/params.py,sha256=Rfdg5UcGCrG80m6V79FyORERWUqIzHFO7tGiY4zAImM,6347
10
10
  risk/neighborhoods/__init__.py,sha256=tKKEg4lsbqFukpgYlUGxU_v_9FOqK7V0uvM9T2QzoL0,206
11
11
  risk/neighborhoods/community.py,sha256=stYYBXeZlGLMV-k8ckQeIqThT6v9y-S3hETobAo9590,6817
12
- risk/neighborhoods/domains.py,sha256=bxJUxqFTynzX0mf3E8-AA4_Rfccje1reeVVhfzb1-pE,10672
13
- risk/neighborhoods/neighborhoods.py,sha256=r-JeUb6dTjzMtnaMDvJy6MI3mTl-yUzILcdcjtOhFdM,18218
12
+ risk/neighborhoods/domains.py,sha256=vTCKtRE0oFcY862squrF7_cqCjnckiC9Sl0Qh2FM81k,10665
13
+ risk/neighborhoods/neighborhoods.py,sha256=5WVXCZ0f-MzUfDITdNlL0NgDS3DBamdc_ZVPA-p9j7U,18218
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=_LEoom4EEowGALuJKSXcev9RAAHu2FqIeq3u7mkifW0,16479
17
17
  risk/network/io.py,sha256=gG50kOknO-D3HkW1HsbHMkTMvjUtn3l4W4Jwd-rXNr8,21202
18
18
  risk/network/plot.py,sha256=3OucCoKJwx9M9H4lqAvcQdM9YiCSyIxz21jyqDbpffc,62286
19
19
  risk/stats/__init__.py,sha256=WcgoETQ-hS0LQqKRsAMIPtP15xZ-4eul6VUBuUx4Wzc,220
20
- risk/stats/hypergeom.py,sha256=DcGYjmfcgt1qshNZPJt5IHGIHtxw9tWRS1r6QJ6V3dI,2378
21
- risk/stats/poisson.py,sha256=CnLk65CHViR4YhAaN3ix37iyLm_YQYGo851bSnGyyxY,1950
20
+ risk/stats/hypergeom.py,sha256=o6Qnj31gCAKxr2uQirXrbv7XvdDJGEq69MFW-ubx_hA,2272
21
+ risk/stats/poisson.py,sha256=8x9hB4DCukq4gNIlIKO-c_jYG1-BTwTX53oLauFyfj8,1793
22
22
  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=kmSZ7bQ-AD0TFiQDgIwfxTeqHa4pjp7fIcOzAqyhUNY,9714
25
25
  risk/stats/permutation/test_functions.py,sha256=HuDIM-V1jkkfE1rlaIqrWWBSKZt3dQ1f-YEDjWpnLSE,2343
26
- risk_network-0.0.7b7.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
- risk_network-0.0.7b7.dist-info/METADATA,sha256=LDTOo8S-g09TbNgixGR4nCBkyaHW_usy0zE8kNsqTRg,43142
28
- risk_network-0.0.7b7.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
- risk_network-0.0.7b7.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
- risk_network-0.0.7b7.dist-info/RECORD,,
26
+ risk_network-0.0.7b9.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
+ risk_network-0.0.7b9.dist-info/METADATA,sha256=SMrU7EhdEUAHteWWFDPCCQ5PxRjcAOoNfGlOKMpp-w4,43142
28
+ risk_network-0.0.7b9.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
+ risk_network-0.0.7b9.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
+ risk_network-0.0.7b9.dist-info/RECORD,,