napistu 0.4.4__tar.gz → 0.4.6__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.
- {napistu-0.4.4/src/napistu.egg-info → napistu-0.4.6}/PKG-INFO +1 -1
- {napistu-0.4.4 → napistu-0.4.6}/setup.cfg +1 -1
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/constants.py +12 -1
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/neighborhoods.py +142 -92
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/ng_utils.py +8 -5
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/paths.py +40 -18
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/source.py +31 -6
- {napistu-0.4.4 → napistu-0.4.6/src/napistu.egg-info}/PKG-INFO +1 -1
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/conftest.py +10 -0
- napistu-0.4.6/src/tests/test_network_neighborhoods.py +141 -0
- napistu-0.4.6/src/tests/test_network_paths.py +80 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_source.py +1 -1
- napistu-0.4.4/src/tests/test_network_neighborhoods.py +0 -19
- napistu-0.4.4/src/tests/test_network_paths.py +0 -56
- {napistu-0.4.4 → napistu-0.4.6}/LICENSE +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/README.md +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/pyproject.toml +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/setup.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/__main__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/consensus.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/constants.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/context/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/context/discretize.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/context/filtering.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/gcs/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/gcs/constants.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/gcs/downloads.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/gcs/utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/identifiers.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/indices.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/bigg.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/constants.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/gtex.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/hpa.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/identifiers_etl.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/napistu_edgelist.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/obo.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/psi_mi.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/reactom_fi.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/reactome.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/sbml.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/string.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/trrust.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ingestion/yeast.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/matching/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/matching/constants.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/matching/interactions.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/matching/mount.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/matching/species.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/__main__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/client.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/codebase.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/codebase_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/component_base.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/config.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/constants.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/documentation.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/documentation_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/execution.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/health.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/profiles.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/server.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/tutorials.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/tutorials_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/mcp/utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/modify/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/modify/constants.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/modify/curation.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/modify/gaps.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/modify/pathwayannot.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/modify/uncompartmentalize.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/data_handling.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/ig_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/net_create.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/net_create_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/net_propagation.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/ng_core.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/network/precompute.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ontologies/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ontologies/constants.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ontologies/dogma.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ontologies/genodexito.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ontologies/id_tables.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ontologies/mygene.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/ontologies/renaming.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/rpy2/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/rpy2/callr.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/rpy2/constants.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/rpy2/rids.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/sbml_dfs_core.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/sbml_dfs_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/scverse/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/scverse/constants.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/scverse/loading.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/statistics/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/statistics/hypothesis_testing.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/statistics/quantiles.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu/utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu.egg-info/SOURCES.txt +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu.egg-info/dependency_links.txt +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu.egg-info/entry_points.txt +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu.egg-info/requires.txt +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/napistu.egg-info/top_level.txt +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_consensus.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_constants.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_context_discretize.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_context_filtering.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_curation.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_data/__init__.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_gaps.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_gcs.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_identifiers.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_indices.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_ingestion_napistu_edgelist.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_ingestion_obo.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_matching_interactions.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_matching_mount.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_matching_species.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_mcp_config.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_mcp_documentation_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_mcp_server.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_network_data_handling.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_network_ig_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_network_net_create.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_network_net_create_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_network_net_propagation.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_network_ng_core.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_network_ng_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_network_precompute.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_ontologies_genodexito.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_ontologies_id_tables.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_ontologies_mygene.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_ontologies_renaming.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_pathwayannot.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_rpy2_callr.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_rpy2_init.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_sbml.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_sbml_dfs_core.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_sbml_dfs_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_sbo.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_scverse_loading.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_statistics_hypothesis_testing.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_statistics_quantiles.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_uncompartmentalize.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/test_utils.py +0 -0
- {napistu-0.4.4 → napistu-0.4.6}/src/tests/utils.py +0 -0
@@ -14,7 +14,11 @@ NAPISTU_GRAPH_DIRECTEDNESS = SimpleNamespace(
|
|
14
14
|
DIRECTED="directed", UNDIRECTED="undirected"
|
15
15
|
)
|
16
16
|
|
17
|
-
NAPISTU_GRAPH_VERTICES = SimpleNamespace(
|
17
|
+
NAPISTU_GRAPH_VERTICES = SimpleNamespace(
|
18
|
+
NAME="name", # internal name
|
19
|
+
NODE_NAME="node_name", # human readable name
|
20
|
+
NODE_TYPE="node_type", # type of node (species or reaction)
|
21
|
+
)
|
18
22
|
|
19
23
|
NAPISTU_GRAPH_EDGES = SimpleNamespace(
|
20
24
|
DIRECTED="directed",
|
@@ -220,3 +224,10 @@ PARAMETRIC_NULL_DEFAULT_DISTRIBUTION = "norm"
|
|
220
224
|
MASK_KEYWORDS = SimpleNamespace(
|
221
225
|
ATTR="attr",
|
222
226
|
)
|
227
|
+
|
228
|
+
NEIGHBORHOOD_DICT_KEYS = SimpleNamespace(
|
229
|
+
GRAPH="graph",
|
230
|
+
VERTICES="vertices",
|
231
|
+
EDGES="edges",
|
232
|
+
REACTION_SOURCES="reaction_sources",
|
233
|
+
)
|
@@ -18,13 +18,21 @@ from napistu import utils
|
|
18
18
|
from napistu.network import ng_utils
|
19
19
|
from napistu.network import paths
|
20
20
|
|
21
|
-
from napistu.constants import
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
from napistu.constants import (
|
22
|
+
MINI_SBO_NAME_TO_POLARITY,
|
23
|
+
MINI_SBO_TO_NAME,
|
24
|
+
NAPISTU_EDGELIST,
|
25
|
+
SBML_DFS,
|
26
|
+
)
|
27
|
+
|
28
|
+
from napistu.network.constants import (
|
29
|
+
GRAPH_WIRING_APPROACHES,
|
30
|
+
NAPISTU_GRAPH_VERTICES,
|
31
|
+
NEIGHBORHOOD_DICT_KEYS,
|
32
|
+
NEIGHBORHOOD_NETWORK_TYPES,
|
33
|
+
NET_POLARITY,
|
34
|
+
VALID_NEIGHBORHOOD_NETWORK_TYPES,
|
35
|
+
)
|
28
36
|
|
29
37
|
logger = logging.getLogger(__name__)
|
30
38
|
|
@@ -34,8 +42,9 @@ def find_and_prune_neighborhoods(
|
|
34
42
|
napistu_graph: ig.Graph,
|
35
43
|
compartmentalized_species: str | list[str],
|
36
44
|
precomputed_distances: pd.DataFrame | None = None,
|
45
|
+
min_pw_size: int = 3,
|
37
46
|
source_total_counts: pd.Series | None = None,
|
38
|
-
network_type: str = NEIGHBORHOOD_NETWORK_TYPES.
|
47
|
+
network_type: str = NEIGHBORHOOD_NETWORK_TYPES.HOURGLASS,
|
39
48
|
order: int = 3,
|
40
49
|
verbose: bool = True,
|
41
50
|
top_n: int = 10,
|
@@ -55,6 +64,8 @@ def find_and_prune_neighborhoods(
|
|
55
64
|
Compartmentalized species IDs for neighborhood centers
|
56
65
|
precomputed_distances : pd.DataFrame or None
|
57
66
|
If provided, an edgelist of origin->destination path weights and lengths
|
67
|
+
min_pw_size: int
|
68
|
+
the minimum size of a pathway to be considered
|
58
69
|
source_total_counts: pd.Series | None
|
59
70
|
Optional, A series of the total counts of each source. As produced by
|
60
71
|
source.get_source_total_counts()
|
@@ -111,9 +122,10 @@ def find_and_prune_neighborhoods(
|
|
111
122
|
compartmentalized_species=compartmentalized_species,
|
112
123
|
network_type=network_type,
|
113
124
|
order=order,
|
114
|
-
verbose=verbose,
|
115
125
|
precomputed_neighbors=precomputed_neighbors,
|
126
|
+
min_pw_size=min_pw_size,
|
116
127
|
source_total_counts=source_total_counts,
|
128
|
+
verbose=verbose,
|
117
129
|
)
|
118
130
|
|
119
131
|
pruned_neighborhoods = prune_neighborhoods(neighborhoods, top_n=top_n)
|
@@ -283,7 +295,9 @@ def create_neighborhoods(
|
|
283
295
|
|
284
296
|
neighborhood_entities = pd.concat(
|
285
297
|
[
|
286
|
-
neighborhoods[sc_id][
|
298
|
+
neighborhoods[sc_id][NEIGHBORHOOD_DICT_KEYS.VERTICES].assign(
|
299
|
+
focal_sc_id=sc_id
|
300
|
+
)
|
287
301
|
for sc_id in neighborhoods.keys()
|
288
302
|
]
|
289
303
|
).assign(focal_s_id=s_id)
|
@@ -321,6 +335,7 @@ def create_neighborhood_prefix(network_type: str, order: int, top_n: int) -> str
|
|
321
335
|
def load_neighborhoods_by_partition(
|
322
336
|
selected_partition: int,
|
323
337
|
neighborhood_outdir: str,
|
338
|
+
cache_dir: str,
|
324
339
|
wiring_approach: str = GRAPH_WIRING_APPROACHES.REGULATORY,
|
325
340
|
) -> None:
|
326
341
|
"""
|
@@ -343,19 +358,18 @@ def load_neighborhoods_by_partition(
|
|
343
358
|
|
344
359
|
"""
|
345
360
|
|
346
|
-
consensus_root = "/group/cpr/consensus"
|
347
|
-
consensus_name = "reactome"
|
348
|
-
consensus_outdir = os.path.join(consensus_root, consensus_name)
|
349
|
-
|
350
361
|
if not os.path.isdir(neighborhood_outdir):
|
351
362
|
raise FileNotFoundError(f"{neighborhood_outdir} does not exist")
|
352
363
|
|
364
|
+
if not os.path.isdir(cache_dir):
|
365
|
+
raise FileNotFoundError(f"{cache_dir} does not exist")
|
366
|
+
|
353
367
|
partition_output = os.path.join(
|
354
368
|
neighborhood_outdir, f"partition_{selected_partition}"
|
355
369
|
)
|
356
370
|
# initialize an empty output
|
357
371
|
if os.path.isdir(partition_output):
|
358
|
-
|
372
|
+
logger.warning(f"removing existing directory: {partition_output}")
|
359
373
|
shutil.rmtree(partition_output)
|
360
374
|
os.makedirs(partition_output)
|
361
375
|
|
@@ -375,7 +389,7 @@ def load_neighborhoods_by_partition(
|
|
375
389
|
|
376
390
|
# read model containing Calico curations. this is primarily to support search programs
|
377
391
|
# to not use these switch to refined.pkl
|
378
|
-
refined_model_pkl_path = os.path.join(
|
392
|
+
refined_model_pkl_path = os.path.join(cache_dir, "curated.pkl")
|
379
393
|
with open(refined_model_pkl_path, "rb") as in_file:
|
380
394
|
refined_model = pickle.load(in_file)
|
381
395
|
refined_model.validate()
|
@@ -383,12 +397,12 @@ def load_neighborhoods_by_partition(
|
|
383
397
|
# load the graph
|
384
398
|
napistu_graph = ng_utils.read_network_pkl(
|
385
399
|
model_prefix="curated",
|
386
|
-
network_dir=
|
400
|
+
network_dir=cache_dir,
|
387
401
|
directed=True,
|
388
402
|
wiring_approach=wiring_approach,
|
389
403
|
)
|
390
404
|
|
391
|
-
|
405
|
+
_, _ = load_neighborhoods(
|
392
406
|
s_ids=parition_sids,
|
393
407
|
sbml_dfs=refined_model,
|
394
408
|
napistu_graph=napistu_graph,
|
@@ -510,11 +524,12 @@ def find_neighborhoods(
|
|
510
524
|
sbml_dfs: sbml_dfs_core.SBML_dfs,
|
511
525
|
napistu_graph: ig.Graph,
|
512
526
|
compartmentalized_species: list[str],
|
513
|
-
network_type: str =
|
527
|
+
network_type: str = NEIGHBORHOOD_NETWORK_TYPES.HOURGLASS,
|
514
528
|
order: int = 3,
|
515
|
-
|
529
|
+
min_pw_size: int = 3,
|
516
530
|
precomputed_neighbors: pd.DataFrame | None = None,
|
517
531
|
source_total_counts: pd.Series | None = None,
|
532
|
+
verbose: bool = True,
|
518
533
|
) -> dict:
|
519
534
|
"""
|
520
535
|
Find Neighborhood
|
@@ -536,14 +551,16 @@ def find_neighborhoods(
|
|
536
551
|
locates both upstream and downstream species.
|
537
552
|
order: int
|
538
553
|
Max steps away from center node
|
539
|
-
verbose: bool
|
540
|
-
Extra reporting
|
541
554
|
precomputed_neighbors: pd.DataFrame or None
|
542
555
|
If provided, a pre-filtered table of nodes nearby the compartmentalized species
|
543
556
|
which will be used to skip on-the-fly neighborhood generation.
|
557
|
+
min_pw_size: int
|
558
|
+
the minimum size of a pathway to be considered
|
544
559
|
source_total_counts: pd.Series | None
|
545
560
|
Optional, A series of the total counts of each source. As produced by
|
546
|
-
source.get_source_total_counts()
|
561
|
+
source.get_source_total_counts()\
|
562
|
+
verbose: bool
|
563
|
+
Extra reporting
|
547
564
|
|
548
565
|
Returns:
|
549
566
|
----------
|
@@ -554,10 +571,9 @@ def find_neighborhoods(
|
|
554
571
|
if not isinstance(network_type, str):
|
555
572
|
raise TypeError(f"network_type was a {type(network_type)} and must be a str")
|
556
573
|
|
557
|
-
|
558
|
-
if network_type not in valid_network_types:
|
574
|
+
if network_type not in VALID_NEIGHBORHOOD_NETWORK_TYPES:
|
559
575
|
raise ValueError(
|
560
|
-
f"network_type must be one of {', '.join(
|
576
|
+
f"network_type must be one of {', '.join(VALID_NEIGHBORHOOD_NETWORK_TYPES)}"
|
561
577
|
)
|
562
578
|
|
563
579
|
if not isinstance(order, int):
|
@@ -580,6 +596,7 @@ def find_neighborhoods(
|
|
580
596
|
neighborhood_df=neighborhood_df,
|
581
597
|
sbml_dfs=sbml_dfs,
|
582
598
|
napistu_graph=napistu_graph,
|
599
|
+
min_pw_size=min_pw_size,
|
583
600
|
source_total_counts=source_total_counts,
|
584
601
|
verbose=verbose,
|
585
602
|
)
|
@@ -594,6 +611,7 @@ def create_neighborhood_dict_entry(
|
|
594
611
|
neighborhood_df: pd.DataFrame,
|
595
612
|
sbml_dfs: sbml_dfs_core.SBML_dfs,
|
596
613
|
napistu_graph: ig.Graph,
|
614
|
+
min_pw_size: int = 3,
|
597
615
|
source_total_counts: pd.Series | None = None,
|
598
616
|
verbose: bool = False,
|
599
617
|
) -> dict[str, Any]:
|
@@ -612,6 +630,8 @@ def create_neighborhood_dict_entry(
|
|
612
630
|
A mechanistic molecular model
|
613
631
|
napistu_graph: igraph.Graph
|
614
632
|
A network connecting molecular species and reactions
|
633
|
+
min_pw_size: int
|
634
|
+
the minimum size of a pathway to be considered
|
615
635
|
source_total_counts: pd.Series
|
616
636
|
Optional, A series of the total counts of each source. As produced by
|
617
637
|
source.get_source_total_counts()
|
@@ -627,8 +647,8 @@ def create_neighborhood_dict_entry(
|
|
627
647
|
nodes in the neighborhood
|
628
648
|
edges: pd.DataFrame
|
629
649
|
edges in the neighborhood
|
630
|
-
|
631
|
-
models that
|
650
|
+
reaction_sources: pd.DataFrame
|
651
|
+
models that reactions were derived from
|
632
652
|
neighborhood_path_entities: dict
|
633
653
|
upstream and downstream dicts representing entities in paths.
|
634
654
|
If the keys are to be included in a neighborhood, the
|
@@ -662,14 +682,15 @@ def create_neighborhood_dict_entry(
|
|
662
682
|
)
|
663
683
|
|
664
684
|
try:
|
665
|
-
|
685
|
+
reaction_sources = ng_utils.get_minimal_sources_edges(
|
666
686
|
vertices.rename(columns={"name": "node"}),
|
667
687
|
sbml_dfs,
|
688
|
+
min_pw_size=min_pw_size,
|
668
689
|
# optional, counts of sources across the whole model
|
669
|
-
source_total_counts,
|
690
|
+
source_total_counts=source_total_counts,
|
670
691
|
)
|
671
692
|
except Exception:
|
672
|
-
|
693
|
+
reaction_sources = None
|
673
694
|
|
674
695
|
# to add weights to the network solve the shortest path problem
|
675
696
|
# from the focal node to each neighbor
|
@@ -799,7 +820,7 @@ def create_neighborhood_dict_entry(
|
|
799
820
|
"graph": updated_napistu_graph,
|
800
821
|
"vertices": vertices,
|
801
822
|
"edges": edges,
|
802
|
-
"
|
823
|
+
"reaction_sources": reaction_sources,
|
803
824
|
"neighborhood_path_entities": neighborhood_path_entities,
|
804
825
|
}
|
805
826
|
|
@@ -860,8 +881,10 @@ def add_vertices_uri_urls(
|
|
860
881
|
# add uri urls for each node
|
861
882
|
|
862
883
|
# add s_ids
|
863
|
-
neighborhood_species = vertices[
|
864
|
-
|
884
|
+
neighborhood_species = vertices[
|
885
|
+
vertices[NAPISTU_GRAPH_VERTICES.NODE_TYPE] == "species"
|
886
|
+
].merge(
|
887
|
+
sbml_dfs.compartmentalized_species[SBML_DFS.S_ID],
|
865
888
|
left_on="name",
|
866
889
|
right_index=True,
|
867
890
|
how="left",
|
@@ -869,24 +892,29 @@ def add_vertices_uri_urls(
|
|
869
892
|
|
870
893
|
# add a standard reference identifier
|
871
894
|
neighborhood_species_aug = neighborhood_species.merge(
|
872
|
-
sbml_dfs.get_uri_urls("species", neighborhood_species[
|
873
|
-
left_on=
|
895
|
+
sbml_dfs.get_uri_urls("species", neighborhood_species[SBML_DFS.S_ID]),
|
896
|
+
left_on=SBML_DFS.S_ID,
|
874
897
|
right_index=True,
|
875
898
|
how="left",
|
876
899
|
# add pharos ids where available
|
877
900
|
).merge(
|
878
901
|
sbml_dfs.get_uri_urls(
|
879
|
-
"species", neighborhood_species[
|
902
|
+
"species", neighborhood_species[SBML_DFS.S_ID], required_ontology="pharos"
|
880
903
|
).rename("pharos"),
|
881
|
-
left_on=
|
904
|
+
left_on=SBML_DFS.S_ID,
|
882
905
|
right_index=True,
|
883
906
|
how="left",
|
884
907
|
)
|
885
908
|
|
886
|
-
if sum(vertices[
|
887
|
-
neighborhood_reactions = vertices[
|
909
|
+
if sum(vertices[NAPISTU_GRAPH_VERTICES.NODE_TYPE] == "reaction") > 0:
|
910
|
+
neighborhood_reactions = vertices[
|
911
|
+
vertices[NAPISTU_GRAPH_VERTICES.NODE_TYPE] == "reaction"
|
912
|
+
].merge(
|
888
913
|
sbml_dfs.get_uri_urls(
|
889
|
-
"reactions",
|
914
|
+
"reactions",
|
915
|
+
vertices[vertices[NAPISTU_GRAPH_VERTICES.NODE_TYPE] == "reaction"][
|
916
|
+
"name"
|
917
|
+
],
|
890
918
|
),
|
891
919
|
left_on="name",
|
892
920
|
right_index=True,
|
@@ -947,38 +975,54 @@ def prune_neighborhoods(neighborhoods: dict, top_n: int = 100) -> dict:
|
|
947
975
|
pruned_vertices = _prune_vertex_set(one_neighborhood, top_n=top_n)
|
948
976
|
|
949
977
|
# reduce neighborhood to this set of high-weight vertices
|
950
|
-
all_neighbors = pd.DataFrame(
|
978
|
+
all_neighbors = pd.DataFrame(
|
979
|
+
{
|
980
|
+
NAPISTU_GRAPH_VERTICES.NODE_NAME: one_neighborhood[
|
981
|
+
NEIGHBORHOOD_DICT_KEYS.GRAPH
|
982
|
+
].vs[NAPISTU_GRAPH_VERTICES.NODE_NAME]
|
983
|
+
}
|
984
|
+
)
|
951
985
|
pruned_vertices_indices = all_neighbors[
|
952
|
-
all_neighbors[
|
986
|
+
all_neighbors[NAPISTU_GRAPH_VERTICES.NODE_NAME].isin(
|
987
|
+
pruned_vertices[NAPISTU_GRAPH_VERTICES.NODE_NAME]
|
988
|
+
)
|
953
989
|
].index.tolist()
|
954
990
|
|
955
|
-
pruned_neighborhood = one_neighborhood[
|
956
|
-
one_neighborhood[
|
991
|
+
pruned_neighborhood = one_neighborhood[NEIGHBORHOOD_DICT_KEYS.GRAPH].subgraph(
|
992
|
+
one_neighborhood[NEIGHBORHOOD_DICT_KEYS.GRAPH].vs[pruned_vertices_indices],
|
957
993
|
implementation="auto",
|
958
994
|
)
|
959
995
|
|
960
996
|
pruned_edges = pd.DataFrame([e.attributes() for e in pruned_neighborhood.es])
|
961
997
|
|
962
|
-
pruned_reactions = pruned_vertices[
|
963
|
-
"
|
964
|
-
]
|
998
|
+
pruned_reactions = pruned_vertices[
|
999
|
+
pruned_vertices[NAPISTU_GRAPH_VERTICES.NODE_TYPE] == "reaction"
|
1000
|
+
][NAPISTU_GRAPH_VERTICES.NODE_NAME]
|
965
1001
|
|
966
1002
|
if pruned_reactions.shape[0] != 0:
|
967
|
-
if one_neighborhood[
|
1003
|
+
if one_neighborhood[NEIGHBORHOOD_DICT_KEYS.REACTION_SOURCES] is None:
|
968
1004
|
# allow for missing source information since this is currently optional
|
969
|
-
|
1005
|
+
pruned_reaction_sources = one_neighborhood[
|
1006
|
+
NEIGHBORHOOD_DICT_KEYS.REACTION_SOURCES
|
1007
|
+
]
|
970
1008
|
else:
|
971
|
-
|
972
|
-
|
1009
|
+
pruned_reaction_sources = one_neighborhood[
|
1010
|
+
NEIGHBORHOOD_DICT_KEYS.REACTION_SOURCES
|
1011
|
+
][
|
1012
|
+
one_neighborhood[NEIGHBORHOOD_DICT_KEYS.REACTION_SOURCES][
|
1013
|
+
SBML_DFS.R_ID
|
1014
|
+
].isin(pruned_reactions)
|
973
1015
|
]
|
974
1016
|
else:
|
975
|
-
|
1017
|
+
pruned_reaction_sources = one_neighborhood[
|
1018
|
+
NEIGHBORHOOD_DICT_KEYS.REACTION_SOURCES
|
1019
|
+
]
|
976
1020
|
|
977
1021
|
pruned_neighborhoods_dict[an_sc_id] = {
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
1022
|
+
NEIGHBORHOOD_DICT_KEYS.GRAPH: pruned_neighborhood,
|
1023
|
+
NEIGHBORHOOD_DICT_KEYS.VERTICES: pruned_vertices,
|
1024
|
+
NEIGHBORHOOD_DICT_KEYS.EDGES: pruned_edges,
|
1025
|
+
NEIGHBORHOOD_DICT_KEYS.REACTION_SOURCES: pruned_reaction_sources,
|
982
1026
|
}
|
983
1027
|
|
984
1028
|
return pruned_neighborhoods_dict
|
@@ -1026,11 +1070,11 @@ def plot_neighborhood(
|
|
1026
1070
|
}
|
1027
1071
|
|
1028
1072
|
edge_polarity_colors = {
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1073
|
+
NET_POLARITY.AMBIGUOUS: "dimgray",
|
1074
|
+
NET_POLARITY.ACTIVATION: "gold",
|
1075
|
+
NET_POLARITY.INHIBITION: "royalblue",
|
1076
|
+
NET_POLARITY.AMBIGUOUS_ACTIVATION: "palegoldenrod",
|
1077
|
+
NET_POLARITY.AMBIGUOUS_INHIBITION: "powerblue",
|
1034
1078
|
np.nan: "dimgray",
|
1035
1079
|
}
|
1036
1080
|
|
@@ -1039,17 +1083,19 @@ def plot_neighborhood(
|
|
1039
1083
|
visual_style["vertex_size"] = 10
|
1040
1084
|
if name_nodes:
|
1041
1085
|
visual_style["vertex_label"] = [
|
1042
|
-
textwrap.fill(x, 15)
|
1086
|
+
textwrap.fill(x, 15)
|
1087
|
+
for x in neighborhood_graph.vs[NAPISTU_GRAPH_VERTICES.NODE_NAME]
|
1043
1088
|
]
|
1044
1089
|
visual_style["vertex_label_color"] = "white"
|
1045
1090
|
visual_style["vertex_label_size"] = 8
|
1046
1091
|
visual_style["vertex_label_angle"] = 90
|
1047
1092
|
visual_style["vertex_label_dist"] = 3
|
1048
1093
|
visual_style["vertex_color"] = [
|
1049
|
-
color_dict[x] for x in neighborhood_graph.vs[
|
1094
|
+
color_dict[x] for x in neighborhood_graph.vs[NAPISTU_GRAPH_VERTICES.NODE_TYPE]
|
1050
1095
|
]
|
1051
1096
|
visual_style["edge_color"] = [
|
1052
|
-
edge_polarity_colors[x]
|
1097
|
+
edge_polarity_colors[x]
|
1098
|
+
for x in neighborhood_graph.es[NET_POLARITY.NET_POLARITY]
|
1053
1099
|
]
|
1054
1100
|
visual_style["layout"] = neighborhood_graph_layout
|
1055
1101
|
visual_style["bbox"] = (plot_size, plot_size)
|
@@ -1081,8 +1127,8 @@ def _precompute_neighbors(
|
|
1081
1127
|
|
1082
1128
|
# check that compartmentalized_species are included in precomputed_distances
|
1083
1129
|
all_cspecies = {
|
1084
|
-
*precomputed_distances[
|
1085
|
-
*precomputed_distances[
|
1130
|
+
*precomputed_distances[NAPISTU_EDGELIST.SC_ID_ORIGIN].tolist(),
|
1131
|
+
*precomputed_distances[NAPISTU_EDGELIST.SC_ID_DEST].tolist(),
|
1086
1132
|
}
|
1087
1133
|
missing_cspecies = set(compartmentalized_species).difference(all_cspecies)
|
1088
1134
|
if len(missing_cspecies) > 0:
|
@@ -1097,14 +1143,16 @@ def _precompute_neighbors(
|
|
1097
1143
|
NEIGHBORHOOD_NETWORK_TYPES.DOWNSTREAM,
|
1098
1144
|
NEIGHBORHOOD_NETWORK_TYPES.HOURGLASS,
|
1099
1145
|
]:
|
1100
|
-
valid_origin = precomputed_distances[
|
1146
|
+
valid_origin = precomputed_distances[NAPISTU_EDGELIST.SC_ID_ORIGIN].isin(
|
1101
1147
|
compartmentalized_species
|
1102
1148
|
)
|
1103
1149
|
if network_type in [
|
1104
1150
|
NEIGHBORHOOD_NETWORK_TYPES.UPSTREAM,
|
1105
1151
|
NEIGHBORHOOD_NETWORK_TYPES.HOURGLASS,
|
1106
1152
|
]:
|
1107
|
-
valid_dest = precomputed_distances[
|
1153
|
+
valid_dest = precomputed_distances[NAPISTU_EDGELIST.SC_ID_DEST].isin(
|
1154
|
+
compartmentalized_species
|
1155
|
+
)
|
1108
1156
|
|
1109
1157
|
if network_type == NEIGHBORHOOD_NETWORK_TYPES.HOURGLASS:
|
1110
1158
|
cspecies_subset_precomputed_distances = precomputed_distances[
|
@@ -1141,7 +1189,7 @@ def _precompute_neighbors(
|
|
1141
1189
|
]
|
1142
1190
|
# sort by path_weight so we can retain the lowest weight neighbors
|
1143
1191
|
.sort_values("path_weights")
|
1144
|
-
.groupby(
|
1192
|
+
.groupby(NAPISTU_EDGELIST.SC_ID_ORIGIN)
|
1145
1193
|
.head(top_n)
|
1146
1194
|
)
|
1147
1195
|
|
@@ -1153,9 +1201,9 @@ def _precompute_neighbors(
|
|
1153
1201
|
]:
|
1154
1202
|
top_ancestors = (
|
1155
1203
|
close_cspecies_subset_precomputed_distances[
|
1156
|
-
close_cspecies_subset_precomputed_distances[
|
1157
|
-
|
1158
|
-
)
|
1204
|
+
close_cspecies_subset_precomputed_distances[
|
1205
|
+
NAPISTU_EDGELIST.SC_ID_DEST
|
1206
|
+
].isin(compartmentalized_species)
|
1159
1207
|
]
|
1160
1208
|
# sort by path_upstream_weights so we can retain the lowest weight neighbors
|
1161
1209
|
# we allow for upstream weights to differ from downstream weights
|
@@ -1169,7 +1217,7 @@ def _precompute_neighbors(
|
|
1169
1217
|
# we penalize based on the number of parents of a node when
|
1170
1218
|
# we use it (i.e., the default upstream_weights).
|
1171
1219
|
.sort_values("path_upstream_weights")
|
1172
|
-
.groupby(
|
1220
|
+
.groupby(NAPISTU_EDGELIST.SC_ID_DEST)
|
1173
1221
|
.head(top_n)
|
1174
1222
|
)
|
1175
1223
|
|
@@ -1209,8 +1257,8 @@ def _precompute_neighbors(
|
|
1209
1257
|
# an sc_id_origin-specific subgraph
|
1210
1258
|
identity_df = pd.DataFrame(
|
1211
1259
|
{
|
1212
|
-
|
1213
|
-
|
1260
|
+
NAPISTU_EDGELIST.SC_ID_ORIGIN: compartmentalized_species,
|
1261
|
+
NAPISTU_EDGELIST.SC_ID_DEST: compartmentalized_species,
|
1214
1262
|
}
|
1215
1263
|
)
|
1216
1264
|
|
@@ -1224,14 +1272,16 @@ def _precompute_neighbors(
|
|
1224
1272
|
downstream_reactions, # type: ignore
|
1225
1273
|
identity_df,
|
1226
1274
|
]
|
1227
|
-
)[
|
1275
|
+
)[
|
1276
|
+
[NAPISTU_EDGELIST.SC_ID_ORIGIN, NAPISTU_EDGELIST.SC_ID_DEST]
|
1277
|
+
].drop_duplicates()
|
1228
1278
|
elif network_type == NEIGHBORHOOD_NETWORK_TYPES.DOWNSTREAM:
|
1229
1279
|
precomputed_neighbors = pd.concat([top_descendants, downstream_reactions, identity_df])[ # type: ignore
|
1230
|
-
[
|
1280
|
+
[NAPISTU_EDGELIST.SC_ID_ORIGIN, NAPISTU_EDGELIST.SC_ID_DEST]
|
1231
1281
|
].drop_duplicates()
|
1232
1282
|
elif network_type == NEIGHBORHOOD_NETWORK_TYPES.UPSTREAM:
|
1233
1283
|
precomputed_neighbors = pd.concat([top_ancestors, upstream_reactions, identity_df])[ # type: ignore
|
1234
|
-
[
|
1284
|
+
[NAPISTU_EDGELIST.SC_ID_ORIGIN, NAPISTU_EDGELIST.SC_ID_DEST]
|
1235
1285
|
].drop_duplicates()
|
1236
1286
|
else:
|
1237
1287
|
raise ValueError("This error shouldn't happen")
|
@@ -1325,11 +1375,11 @@ def _find_neighbors(
|
|
1325
1375
|
)
|
1326
1376
|
|
1327
1377
|
if relationship == "descendants":
|
1328
|
-
bait_id =
|
1329
|
-
target_id =
|
1378
|
+
bait_id = NAPISTU_EDGELIST.SC_ID_ORIGIN
|
1379
|
+
target_id = NAPISTU_EDGELIST.SC_ID_DEST
|
1330
1380
|
elif relationship == "ancestors":
|
1331
|
-
bait_id =
|
1332
|
-
target_id =
|
1381
|
+
bait_id = NAPISTU_EDGELIST.SC_ID_DEST
|
1382
|
+
target_id = NAPISTU_EDGELIST.SC_ID_ORIGIN
|
1333
1383
|
else:
|
1334
1384
|
raise ValueError(
|
1335
1385
|
f"relationship must be 'descendants' or 'ancestors' but was {relationship}"
|
@@ -1340,7 +1390,7 @@ def _find_neighbors(
|
|
1340
1390
|
precomputed_neighbors[bait_id].isin(compartmentalized_species)
|
1341
1391
|
]
|
1342
1392
|
.merge(nodes_to_names.rename({"name": target_id}, axis=1))
|
1343
|
-
.rename({bait_id:
|
1393
|
+
.rename({bait_id: SBML_DFS.SC_ID}, axis=1)
|
1344
1394
|
.drop([target_id], axis=1)
|
1345
1395
|
.assign(relationship=relationship)
|
1346
1396
|
)
|
@@ -1363,7 +1413,7 @@ def _find_neighbors(
|
|
1363
1413
|
|
1364
1414
|
neighbors_df = pd.concat(
|
1365
1415
|
[
|
1366
|
-
pd.DataFrame({
|
1416
|
+
pd.DataFrame({SBML_DFS.SC_ID: c, "neighbor": x}, index=range(0, len(x)))
|
1367
1417
|
for c, x in zip(compartmentalized_species, neighbors)
|
1368
1418
|
]
|
1369
1419
|
).assign(relationship=relationship)
|
@@ -1394,11 +1444,11 @@ def _find_reactions_by_relationship(
|
|
1394
1444
|
return None
|
1395
1445
|
|
1396
1446
|
if relationship == "descendants":
|
1397
|
-
bait_id =
|
1398
|
-
target_id =
|
1447
|
+
bait_id = NAPISTU_EDGELIST.SC_ID_ORIGIN
|
1448
|
+
target_id = NAPISTU_EDGELIST.SC_ID_DEST
|
1399
1449
|
elif relationship == "ancestors":
|
1400
|
-
bait_id =
|
1401
|
-
target_id =
|
1450
|
+
bait_id = NAPISTU_EDGELIST.SC_ID_DEST
|
1451
|
+
target_id = NAPISTU_EDGELIST.SC_ID_ORIGIN
|
1402
1452
|
else:
|
1403
1453
|
raise ValueError(
|
1404
1454
|
f"relationship must be 'descendants' or 'ancestors' but was {relationship}"
|
@@ -1429,8 +1479,8 @@ def _find_reactions_by_relationship(
|
|
1429
1479
|
relatives_cspecies = {*relatives, *[uq]}
|
1430
1480
|
# count the number of relative cspecies including each reaction
|
1431
1481
|
rxn_species_counts = sbml_dfs.reaction_species[
|
1432
|
-
sbml_dfs.reaction_species[
|
1433
|
-
].value_counts(
|
1482
|
+
sbml_dfs.reaction_species[SBML_DFS.SC_ID].isin(relatives_cspecies)
|
1483
|
+
].value_counts(SBML_DFS.R_ID)
|
1434
1484
|
|
1435
1485
|
# retain reactions involving 2+ cspecies.
|
1436
1486
|
# some of these reactions will be irrelevant and will be excluded when
|
@@ -1478,7 +1528,7 @@ def _prune_vertex_set(one_neighborhood: dict, top_n: int) -> pd.DataFrame:
|
|
1478
1528
|
neighborhood_vertices = one_neighborhood["vertices"]
|
1479
1529
|
|
1480
1530
|
indexed_neighborhood_species = neighborhood_vertices[
|
1481
|
-
neighborhood_vertices[
|
1531
|
+
neighborhood_vertices[NAPISTU_GRAPH_VERTICES.NODE_TYPE] == "species"
|
1482
1532
|
].set_index("node_orientation")
|
1483
1533
|
|
1484
1534
|
pruned_oriented_neighbors = list()
|
@@ -114,6 +114,7 @@ def compartmentalize_species_pairs(
|
|
114
114
|
def get_minimal_sources_edges(
|
115
115
|
vertices: pd.DataFrame,
|
116
116
|
sbml_dfs: sbml_dfs_core.SBML_dfs,
|
117
|
+
min_pw_size: int = 3,
|
117
118
|
source_total_counts: Optional[pd.Series] = None,
|
118
119
|
) -> pd.DataFrame | None:
|
119
120
|
"""
|
@@ -125,13 +126,15 @@ def get_minimal_sources_edges(
|
|
125
126
|
A table of vertices.
|
126
127
|
sbml_dfs: sbml_dfs_core.SBML_dfs
|
127
128
|
A pathway model
|
129
|
+
min_pw_size: int
|
130
|
+
the minimum size of a pathway to be considered
|
128
131
|
source_total_counts: pd.Series
|
129
132
|
A series of the total counts of each source.
|
130
133
|
|
131
134
|
Returns
|
132
135
|
-------
|
133
|
-
|
134
|
-
A table of
|
136
|
+
reaction_sources: pd.DataFrame
|
137
|
+
A table of reactions and the sources they are assigned to.
|
135
138
|
"""
|
136
139
|
|
137
140
|
nodes = vertices["node"].tolist()
|
@@ -145,10 +148,10 @@ def get_minimal_sources_edges(
|
|
145
148
|
if source_df is None:
|
146
149
|
return None
|
147
150
|
else:
|
148
|
-
|
149
|
-
source_df, source_total_counts, sbml_dfs
|
151
|
+
reaction_sources = source.source_set_coverage(
|
152
|
+
source_df, source_total_counts, sbml_dfs, min_pw_size=min_pw_size
|
150
153
|
)
|
151
|
-
return
|
154
|
+
return reaction_sources.reset_index()[
|
152
155
|
[SBML_DFS.R_ID, SOURCE_SPEC.PATHWAY_ID, SOURCE_SPEC.NAME]
|
153
156
|
]
|
154
157
|
|