napistu 0.2.5.dev6__py3-none-any.whl → 0.3.1__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.
Files changed (107) hide show
  1. napistu/__main__.py +126 -96
  2. napistu/constants.py +35 -41
  3. napistu/context/__init__.py +10 -0
  4. napistu/context/discretize.py +462 -0
  5. napistu/context/filtering.py +387 -0
  6. napistu/gcs/__init__.py +1 -1
  7. napistu/identifiers.py +74 -15
  8. napistu/indices.py +68 -0
  9. napistu/ingestion/__init__.py +1 -1
  10. napistu/ingestion/bigg.py +47 -62
  11. napistu/ingestion/constants.py +18 -133
  12. napistu/ingestion/gtex.py +113 -0
  13. napistu/ingestion/hpa.py +147 -0
  14. napistu/ingestion/sbml.py +0 -97
  15. napistu/ingestion/string.py +2 -2
  16. napistu/matching/__init__.py +10 -0
  17. napistu/matching/constants.py +18 -0
  18. napistu/matching/interactions.py +518 -0
  19. napistu/matching/mount.py +529 -0
  20. napistu/matching/species.py +510 -0
  21. napistu/mcp/__init__.py +7 -4
  22. napistu/mcp/__main__.py +128 -72
  23. napistu/mcp/client.py +16 -25
  24. napistu/mcp/codebase.py +201 -153
  25. napistu/mcp/component_base.py +170 -0
  26. napistu/mcp/config.py +223 -0
  27. napistu/mcp/constants.py +45 -2
  28. napistu/mcp/documentation.py +253 -136
  29. napistu/mcp/documentation_utils.py +13 -48
  30. napistu/mcp/execution.py +372 -305
  31. napistu/mcp/health.py +49 -67
  32. napistu/mcp/profiles.py +10 -6
  33. napistu/mcp/server.py +161 -80
  34. napistu/mcp/tutorials.py +139 -87
  35. napistu/modify/__init__.py +1 -1
  36. napistu/modify/gaps.py +1 -1
  37. napistu/network/__init__.py +1 -1
  38. napistu/network/constants.py +101 -34
  39. napistu/network/data_handling.py +388 -0
  40. napistu/network/ig_utils.py +351 -0
  41. napistu/network/napistu_graph_core.py +354 -0
  42. napistu/network/neighborhoods.py +40 -40
  43. napistu/network/net_create.py +373 -309
  44. napistu/network/net_propagation.py +47 -19
  45. napistu/network/{net_utils.py → ng_utils.py} +124 -272
  46. napistu/network/paths.py +67 -51
  47. napistu/network/precompute.py +11 -11
  48. napistu/ontologies/__init__.py +10 -0
  49. napistu/ontologies/constants.py +129 -0
  50. napistu/ontologies/dogma.py +243 -0
  51. napistu/ontologies/genodexito.py +649 -0
  52. napistu/ontologies/mygene.py +369 -0
  53. napistu/ontologies/renaming.py +198 -0
  54. napistu/rpy2/__init__.py +229 -86
  55. napistu/rpy2/callr.py +47 -77
  56. napistu/rpy2/constants.py +24 -23
  57. napistu/rpy2/rids.py +61 -648
  58. napistu/sbml_dfs_core.py +587 -222
  59. napistu/scverse/__init__.py +15 -0
  60. napistu/scverse/constants.py +28 -0
  61. napistu/scverse/loading.py +727 -0
  62. napistu/utils.py +118 -10
  63. {napistu-0.2.5.dev6.dist-info → napistu-0.3.1.dist-info}/METADATA +8 -3
  64. napistu-0.3.1.dist-info/RECORD +133 -0
  65. tests/conftest.py +22 -0
  66. tests/test_context_discretize.py +56 -0
  67. tests/test_context_filtering.py +267 -0
  68. tests/test_identifiers.py +100 -0
  69. tests/test_indices.py +65 -0
  70. tests/{test_edgelist.py → test_ingestion_napistu_edgelist.py} +2 -2
  71. tests/test_matching_interactions.py +108 -0
  72. tests/test_matching_mount.py +305 -0
  73. tests/test_matching_species.py +394 -0
  74. tests/test_mcp_config.py +193 -0
  75. tests/test_mcp_documentation_utils.py +12 -3
  76. tests/test_mcp_server.py +356 -0
  77. tests/test_network_data_handling.py +397 -0
  78. tests/test_network_ig_utils.py +23 -0
  79. tests/test_network_neighborhoods.py +19 -0
  80. tests/test_network_net_create.py +459 -0
  81. tests/test_network_ng_utils.py +30 -0
  82. tests/test_network_paths.py +56 -0
  83. tests/{test_precomputed_distances.py → test_network_precompute.py} +8 -6
  84. tests/test_ontologies_genodexito.py +58 -0
  85. tests/test_ontologies_mygene.py +39 -0
  86. tests/test_ontologies_renaming.py +110 -0
  87. tests/test_rpy2_callr.py +79 -0
  88. tests/test_rpy2_init.py +151 -0
  89. tests/test_sbml.py +0 -31
  90. tests/test_sbml_dfs_core.py +134 -10
  91. tests/test_scverse_loading.py +778 -0
  92. tests/test_set_coverage.py +2 -2
  93. tests/test_utils.py +121 -1
  94. napistu/mechanism_matching.py +0 -1353
  95. napistu/rpy2/netcontextr.py +0 -467
  96. napistu-0.2.5.dev6.dist-info/RECORD +0 -97
  97. tests/test_igraph.py +0 -367
  98. tests/test_mechanism_matching.py +0 -784
  99. tests/test_net_utils.py +0 -149
  100. tests/test_netcontextr.py +0 -105
  101. tests/test_rpy2.py +0 -61
  102. /napistu/ingestion/{cpr_edgelist.py → napistu_edgelist.py} +0 -0
  103. {napistu-0.2.5.dev6.dist-info → napistu-0.3.1.dist-info}/WHEEL +0 -0
  104. {napistu-0.2.5.dev6.dist-info → napistu-0.3.1.dist-info}/entry_points.txt +0 -0
  105. {napistu-0.2.5.dev6.dist-info → napistu-0.3.1.dist-info}/licenses/LICENSE +0 -0
  106. {napistu-0.2.5.dev6.dist-info → napistu-0.3.1.dist-info}/top_level.txt +0 -0
  107. /tests/{test_obo.py → test_ingestion_obo.py} +0 -0
@@ -15,14 +15,14 @@ import numpy as np
15
15
  import pandas as pd
16
16
  from napistu import sbml_dfs_core
17
17
  from napistu import utils
18
- from napistu.network import net_utils
18
+ from napistu.network import ng_utils
19
19
  from napistu.network import paths
20
20
 
21
21
  from napistu.constants import SBML_DFS
22
22
  from napistu.constants import MINI_SBO_NAME_TO_POLARITY
23
23
  from napistu.constants import MINI_SBO_TO_NAME
24
24
 
25
- from napistu.network.constants import CPR_GRAPH_TYPES
25
+ from napistu.network.constants import NAPISTU_GRAPH_TYPES
26
26
  from napistu.network.constants import NEIGHBORHOOD_NETWORK_TYPES
27
27
  from napistu.network.constants import VALID_NEIGHBORHOOD_NETWORK_TYPES
28
28
 
@@ -31,7 +31,7 @@ logger = logging.getLogger(__name__)
31
31
 
32
32
  def find_and_prune_neighborhoods(
33
33
  sbml_dfs: sbml_dfs_core.SBML_dfs,
34
- cpr_graph: ig.Graph,
34
+ napistu_graph: ig.Graph,
35
35
  compartmentalized_species: str | list[str],
36
36
  precomputed_distances: pd.DataFrame | None = None,
37
37
  network_type: str = NEIGHBORHOOD_NETWORK_TYPES.DOWNSTREAM,
@@ -48,7 +48,7 @@ def find_and_prune_neighborhoods(
48
48
  ----------
49
49
  sbml_dfs: sbml_dfs_core.SBML_dfs
50
50
  A mechanistic molecular model
51
- cpr_graph : igraph.Graph
51
+ napistu_graph : igraph.Graph
52
52
  A bipartite network connecting molecular species and reactions
53
53
  compartmentalized_species : [str] or str
54
54
  Compartmentalized species IDs for neighborhood centers
@@ -103,7 +103,7 @@ def find_and_prune_neighborhoods(
103
103
 
104
104
  neighborhoods = find_neighborhoods(
105
105
  sbml_dfs=sbml_dfs,
106
- cpr_graph=cpr_graph,
106
+ napistu_graph=napistu_graph,
107
107
  compartmentalized_species=compartmentalized_species,
108
108
  network_type=network_type,
109
109
  order=order,
@@ -119,7 +119,7 @@ def find_and_prune_neighborhoods(
119
119
  def load_neighborhoods(
120
120
  s_ids: list[str],
121
121
  sbml_dfs: sbml_dfs_core.SBML_dfs,
122
- cpr_graph: ig.Graph,
122
+ napistu_graph: ig.Graph,
123
123
  output_dir: str,
124
124
  network_type: str,
125
125
  order: int,
@@ -140,7 +140,7 @@ def load_neighborhoods(
140
140
  create a neighborhood around each species
141
141
  sbml_dfs: sbml_dfs_core.SBML_dfs
142
142
  network model
143
- cpr_graph: igraph.Graph
143
+ napistu_graph: igraph.Graph
144
144
  network associated with sbml_dfs
145
145
  output_dir: str
146
146
  path to existing output directory
@@ -185,7 +185,7 @@ def load_neighborhoods(
185
185
  all_neighborhoods_df, neighborhoods_dict = create_neighborhoods(
186
186
  s_ids=s_ids,
187
187
  sbml_dfs=sbml_dfs,
188
- cpr_graph=cpr_graph,
188
+ napistu_graph=napistu_graph,
189
189
  network_type=network_type,
190
190
  order=order,
191
191
  top_n=top_n,
@@ -205,7 +205,7 @@ def load_neighborhoods(
205
205
  def create_neighborhoods(
206
206
  s_ids: list[str],
207
207
  sbml_dfs: sbml_dfs_core.SBML_dfs,
208
- cpr_graph: ig.Graph,
208
+ napistu_graph: ig.Graph,
209
209
  network_type: str,
210
210
  order: int,
211
211
  top_n: int,
@@ -222,7 +222,7 @@ def create_neighborhoods(
222
222
  create a neighborhood around each species
223
223
  sbml_dfs: sbml_dfs_core.SBML_dfs
224
224
  network model
225
- cpr_graph: igraph.Graph
225
+ napistu_graph: igraph.Graph
226
226
  network associated with sbml_dfs
227
227
  network_type: str
228
228
  downstream, upstream or hourglass (i.e., downstream and upstream)
@@ -260,13 +260,13 @@ def create_neighborhoods(
260
260
  neighborhoods_list = list()
261
261
  neighborhoods_dict = dict()
262
262
  for s_id in s_ids:
263
- query_sc_species = net_utils.compartmentalize_species(sbml_dfs, s_id)
263
+ query_sc_species = ng_utils.compartmentalize_species(sbml_dfs, s_id)
264
264
 
265
265
  compartmentalized_species = query_sc_species[SBML_DFS.SC_ID].tolist()
266
266
 
267
267
  neighborhoods = find_and_prune_neighborhoods(
268
268
  sbml_dfs,
269
- cpr_graph,
269
+ napistu_graph,
270
270
  compartmentalized_species=compartmentalized_species,
271
271
  network_type=network_type,
272
272
  order=order,
@@ -316,7 +316,7 @@ def create_neighborhood_prefix(network_type: str, order: int, top_n: int) -> str
316
316
  def load_neighborhoods_by_partition(
317
317
  selected_partition: int,
318
318
  neighborhood_outdir: str,
319
- graph_type: str = CPR_GRAPH_TYPES.REGULATORY,
319
+ graph_type: str = NAPISTU_GRAPH_TYPES.REGULATORY,
320
320
  ) -> None:
321
321
  """
322
322
  Load Neighborhoods By Partition
@@ -376,7 +376,7 @@ def load_neighborhoods_by_partition(
376
376
  refined_model.validate()
377
377
 
378
378
  # load the graph
379
- cpr_graph = net_utils.read_network_pkl(
379
+ napistu_graph = ng_utils.read_network_pkl(
380
380
  model_prefix="curated",
381
381
  network_dir=consensus_outdir,
382
382
  directed=True,
@@ -386,7 +386,7 @@ def load_neighborhoods_by_partition(
386
386
  all_neighborhoods_df, neighborhoods_dict = load_neighborhoods(
387
387
  s_ids=parition_sids,
388
388
  sbml_dfs=refined_model,
389
- cpr_graph=cpr_graph,
389
+ napistu_graph=napistu_graph,
390
390
  output_dir=partition_output,
391
391
  network_type="hourglass",
392
392
  order=12,
@@ -400,7 +400,7 @@ def load_neighborhoods_by_partition(
400
400
 
401
401
  def read_paritioned_neighborhoods(
402
402
  sbml_dfs: sbml_dfs_core.SBML_dfs,
403
- cpr_graph: ig.Graph,
403
+ napistu_graph: ig.Graph,
404
404
  partitions_path: str,
405
405
  n_partitions: int = 200,
406
406
  ) -> tuple[pd.DataFrame, dict[str, Any]]:
@@ -413,7 +413,7 @@ def read_paritioned_neighborhoods(
413
413
  ------
414
414
  sbml_dfs: sbml_dfs_core.SBML_dfs
415
415
  network model
416
- cpr_graph: igraph.Graph
416
+ napistu_graph: igraph.Graph
417
417
  network associated with sbml_dfs
418
418
  partitions_path: str
419
419
  Path to a directory containing folders for each partition's results
@@ -473,7 +473,7 @@ def read_paritioned_neighborhoods(
473
473
  partition_paths, partition_dict = load_neighborhoods(
474
474
  s_ids=["stub"],
475
475
  sbml_dfs=sbml_dfs,
476
- cpr_graph=cpr_graph,
476
+ napistu_graph=napistu_graph,
477
477
  output_dir=os.path.join(partitions_path, p),
478
478
  # these settings define the neighborhood string so they must
479
479
  # match the settings at the time of network generation
@@ -503,7 +503,7 @@ def read_paritioned_neighborhoods(
503
503
 
504
504
  def find_neighborhoods(
505
505
  sbml_dfs: sbml_dfs_core.SBML_dfs,
506
- cpr_graph: ig.Graph,
506
+ napistu_graph: ig.Graph,
507
507
  compartmentalized_species: list[str],
508
508
  network_type: str = "downstream",
509
509
  order: int = 3,
@@ -520,7 +520,7 @@ def find_neighborhoods(
520
520
  ----------
521
521
  sbml_dfs: sbml_dfs_core.SBML_dfs
522
522
  A mechanistic molecular model
523
- cpr_graph : igraph.Graph
523
+ napistu_graph : igraph.Graph
524
524
  A network connecting molecular species and reactions
525
525
  compartmentalized_species : [str]
526
526
  Compartmentalized species IDs for neighborhood centers
@@ -557,7 +557,7 @@ def find_neighborhoods(
557
557
  # create a table which includes cspecies and reaction nearby each of the
558
558
  # focal compartmentalized_speecies
559
559
  neighborhood_df = _build_raw_neighborhood_df(
560
- cpr_graph=cpr_graph,
560
+ napistu_graph=napistu_graph,
561
561
  compartmentalized_species=compartmentalized_species,
562
562
  network_type=network_type,
563
563
  order=order,
@@ -567,7 +567,7 @@ def find_neighborhoods(
567
567
  # format the vertices and edges in each compartmentalized species' network
568
568
  neighborhood_dict = {
569
569
  sc_id: create_neighborhood_dict_entry(
570
- sc_id, neighborhood_df, sbml_dfs, cpr_graph, verbose=verbose
570
+ sc_id, neighborhood_df, sbml_dfs, napistu_graph, verbose=verbose
571
571
  )
572
572
  for sc_id in compartmentalized_species
573
573
  }
@@ -579,7 +579,7 @@ def create_neighborhood_dict_entry(
579
579
  sc_id: str,
580
580
  neighborhood_df: pd.DataFrame,
581
581
  sbml_dfs: sbml_dfs_core.SBML_dfs,
582
- cpr_graph: ig.Graph,
582
+ napistu_graph: ig.Graph,
583
583
  verbose: bool = False,
584
584
  ) -> dict[str, Any]:
585
585
  """
@@ -595,7 +595,7 @@ def create_neighborhood_dict_entry(
595
595
  A table of upstream and/or downstream neighbors of all compartmentalized species
596
596
  sbml_dfs: sbml_dfs_core.SBML_dfs
597
597
  A mechanistic molecular model
598
- cpr_graph: igraph.Graph
598
+ napistu_graph: igraph.Graph
599
599
  A network connecting molecular species and reactions
600
600
  verbose: bool
601
601
  Extra reporting?
@@ -630,8 +630,8 @@ def create_neighborhood_dict_entry(
630
630
  )
631
631
 
632
632
  # create the subgraph formed by filtering to neighborhoods
633
- neighborhood_graph = cpr_graph.subgraph(
634
- cpr_graph.vs[one_neighborhood_df["neighbor"]], implementation="auto"
633
+ neighborhood_graph = napistu_graph.subgraph(
634
+ napistu_graph.vs[one_neighborhood_df["neighbor"]], implementation="auto"
635
635
  )
636
636
 
637
637
  vertices = pd.DataFrame([v.attributes() for v in neighborhood_graph.vs])
@@ -644,7 +644,7 @@ def create_neighborhood_dict_entry(
644
644
  )
645
645
 
646
646
  try:
647
- edge_sources = net_utils.get_minimal_sources_edges(
647
+ edge_sources = ng_utils.get_minimal_sources_edges(
648
648
  vertices.rename(columns={"name": "node"}), sbml_dfs
649
649
  )
650
650
  except Exception:
@@ -732,7 +732,7 @@ def create_neighborhood_dict_entry(
732
732
  raise ValueError(
733
733
  f"vertex_neighborhood_attrs did not contain the expected columns: {EXPECTED_VERTEX_ATTRS}."
734
734
  "This is likely because of inconsistencies between the precomputed distances, graph and/or sbml_dfs."
735
- "Please try net_utils.validate_assets() to check for consistency."
735
+ "Please try ng_utils.validate_assets() to check for consistency."
736
736
  )
737
737
 
738
738
  # add net_polarity to edges in addition to nodes
@@ -766,16 +766,16 @@ def create_neighborhood_dict_entry(
766
766
  }
767
767
 
768
768
  # update graph with additional vertex and edge attributes
769
- updated_cpr_graph = ig.Graph.DictList(
769
+ updated_napistu_graph = ig.Graph.DictList(
770
770
  vertices=vertices.to_dict("records"),
771
771
  edges=edges.to_dict("records"),
772
- directed=cpr_graph.is_directed(),
772
+ directed=napistu_graph.is_directed(),
773
773
  vertex_name_attr="name",
774
774
  edge_foreign_keys=("from", "to"),
775
775
  )
776
776
 
777
777
  outdict = {
778
- "graph": updated_cpr_graph,
778
+ "graph": updated_napistu_graph,
779
779
  "vertices": vertices,
780
780
  "edges": edges,
781
781
  "edge_sources": edge_sources,
@@ -1138,7 +1138,7 @@ def _precompute_neighbors(
1138
1138
  ]
1139
1139
  # sort by path_upstream_weights so we can retain the lowest weight neighbors
1140
1140
  # we allow for upstream weights to differ from downstream weights
1141
- # when creating a network in process_cpr_graph.
1141
+ # when creating a network in process_napistu_graph.
1142
1142
  #
1143
1143
  # the default network weighting penalizing an edge from a node
1144
1144
  # based on the number of children it has. this captures the idea
@@ -1219,7 +1219,7 @@ def _precompute_neighbors(
1219
1219
 
1220
1220
 
1221
1221
  def _build_raw_neighborhood_df(
1222
- cpr_graph: ig.Graph,
1222
+ napistu_graph: ig.Graph,
1223
1223
  compartmentalized_species: list[str],
1224
1224
  network_type: str,
1225
1225
  order: int,
@@ -1227,7 +1227,7 @@ def _build_raw_neighborhood_df(
1227
1227
  ) -> pd.DataFrame:
1228
1228
  # report if network_type is not the default and will be ignored due to the network
1229
1229
  # being undirected
1230
- is_directed = cpr_graph.is_directed()
1230
+ is_directed = napistu_graph.is_directed()
1231
1231
  if not is_directed and network_type != NEIGHBORHOOD_NETWORK_TYPES.DOWNSTREAM:
1232
1232
  logger.warning(
1233
1233
  "Network is undirected; network_type will be treated as 'downstream'"
@@ -1240,7 +1240,7 @@ def _build_raw_neighborhood_df(
1240
1240
  NEIGHBORHOOD_NETWORK_TYPES.HOURGLASS,
1241
1241
  ]:
1242
1242
  descendants_df = _find_neighbors(
1243
- cpr_graph=cpr_graph,
1243
+ napistu_graph=napistu_graph,
1244
1244
  compartmentalized_species=compartmentalized_species,
1245
1245
  relationship="descendants",
1246
1246
  order=order,
@@ -1253,7 +1253,7 @@ def _build_raw_neighborhood_df(
1253
1253
  NEIGHBORHOOD_NETWORK_TYPES.HOURGLASS,
1254
1254
  ]:
1255
1255
  ancestors_df = _find_neighbors(
1256
- cpr_graph=cpr_graph,
1256
+ napistu_graph=napistu_graph,
1257
1257
  compartmentalized_species=compartmentalized_species,
1258
1258
  relationship="ancestors",
1259
1259
  order=order,
@@ -1272,14 +1272,14 @@ def _build_raw_neighborhood_df(
1272
1272
 
1273
1273
  # add name since this is an easy way to lookup igraph vertices
1274
1274
  neighborhood_df["name"] = [
1275
- x["name"] for x in cpr_graph.vs[neighborhood_df["neighbor"]]
1275
+ x["name"] for x in napistu_graph.vs[neighborhood_df["neighbor"]]
1276
1276
  ]
1277
1277
 
1278
1278
  return neighborhood_df
1279
1279
 
1280
1280
 
1281
1281
  def _find_neighbors(
1282
- cpr_graph: ig.Graph,
1282
+ napistu_graph: ig.Graph,
1283
1283
  compartmentalized_species: list[str],
1284
1284
  relationship: str,
1285
1285
  order: int = 3,
@@ -1298,7 +1298,7 @@ def _find_neighbors(
1298
1298
  if isinstance(precomputed_neighbors, pd.DataFrame):
1299
1299
  # add graph indices to neighbors
1300
1300
  nodes_to_names = (
1301
- pd.DataFrame({"name": cpr_graph.vs["name"]})
1301
+ pd.DataFrame({"name": napistu_graph.vs["name"]})
1302
1302
  .reset_index()
1303
1303
  .rename({"index": "neighbor"}, axis=1)
1304
1304
  )
@@ -1333,7 +1333,7 @@ def _find_neighbors(
1333
1333
  f"relationship must be 'descendants' or 'ancestors' but was {relationship}"
1334
1334
  )
1335
1335
 
1336
- neighbors = cpr_graph.neighborhood(
1336
+ neighbors = napistu_graph.neighborhood(
1337
1337
  # mode = out queries outgoing edges and is ignored if the network is undirected
1338
1338
  vertices=compartmentalized_species,
1339
1339
  order=order,