napistu 0.2.5.dev7__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 -145
  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 +47 -65
  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.dev7.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 +156 -19
  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.dev7.dist-info/RECORD +0 -98
  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.dev7.dist-info → napistu-0.3.1.dist-info}/WHEEL +0 -0
  104. {napistu-0.2.5.dev7.dist-info → napistu-0.3.1.dist-info}/entry_points.txt +0 -0
  105. {napistu-0.2.5.dev7.dist-info → napistu-0.3.1.dist-info}/licenses/LICENSE +0 -0
  106. {napistu-0.2.5.dev7.dist-info → napistu-0.3.1.dist-info}/top_level.txt +0 -0
  107. /tests/{test_obo.py → test_ingestion_obo.py} +0 -0
@@ -1,13 +1,15 @@
1
+ import inspect
2
+ from typing import Optional, Union
3
+
1
4
  import pandas as pd
2
5
  import numpy as np
3
6
  import igraph as ig
4
- import inspect
5
7
 
6
- from typing import Optional
8
+ from napistu.network.napistu_graph_core import NapistuGraph
7
9
 
8
10
 
9
11
  def personalized_pagerank_by_attribute(
10
- g: ig.Graph,
12
+ napistu_graph: Union[NapistuGraph, ig.Graph],
11
13
  attribute: str,
12
14
  damping: float = 0.85,
13
15
  calculate_uniform_dist: bool = True,
@@ -19,8 +21,8 @@ def personalized_pagerank_by_attribute(
19
21
 
20
22
  Parameters
21
23
  ----------
22
- g : igraph.Graph
23
- The input graph.
24
+ napistu_graph : NapistuGraph
25
+ The input graph (subclass of igraph.Graph).
24
26
  attribute : str
25
27
  The vertex attribute to use for personalization.
26
28
  damping : float, optional
@@ -38,7 +40,7 @@ def personalized_pagerank_by_attribute(
38
40
  Example
39
41
  -------
40
42
  >>> import igraph as ig
41
- >>> from scraps.utils import personalized_pagerank_by_attribute
43
+ >>> from napistu.network.net_propagation import personalized_pagerank_by_attribute
42
44
  >>> g = ig.Graph.Full(3)
43
45
  >>> g.vs['name'] = ['A', 'B', 'C']
44
46
  >>> g.vs['score'] = [1, 0, 2]
@@ -46,24 +48,30 @@ def personalized_pagerank_by_attribute(
46
48
  >>> print(df)
47
49
  """
48
50
  # Validate and extract attribute (missing/None as 0)
49
- attr = _ensure_nonnegative_vertex_attribute(g, attribute)
51
+ attr = _ensure_nonnegative_vertex_attribute(napistu_graph, attribute)
50
52
 
51
53
  # Validate additional_propagation_args
52
54
  if additional_propagation_args is None:
53
55
  additional_propagation_args = {}
54
56
  else:
55
- valid_args = set(inspect.signature(g.personalized_pagerank).parameters.keys())
57
+ valid_args = set(
58
+ inspect.signature(napistu_graph.personalized_pagerank).parameters.keys()
59
+ )
56
60
  for k in additional_propagation_args:
57
61
  if k not in valid_args:
58
62
  raise ValueError(f"Invalid argument for personalized_pagerank: {k}")
59
63
 
60
64
  # Personalized PageRank (no normalization, igraph handles it)
61
- pr_attr = g.personalized_pagerank(
65
+ pr_attr = napistu_graph.personalized_pagerank(
62
66
  reset=attr.tolist(), damping=damping, **additional_propagation_args
63
67
  )
64
68
 
65
69
  # Node names
66
- names = g.vs["name"] if "name" in g.vs.attributes() else list(range(g.vcount()))
70
+ names = (
71
+ napistu_graph.vs["name"]
72
+ if "name" in napistu_graph.vs.attributes()
73
+ else list(range(napistu_graph.vcount()))
74
+ )
67
75
 
68
76
  data = {"name": names, "pagerank_by_attribute": pr_attr, attribute: attr}
69
77
 
@@ -75,7 +83,7 @@ def personalized_pagerank_by_attribute(
75
83
  raise ValueError("No nonzero attribute values for uniform PPR.")
76
84
  uniform_vec = np.zeros_like(attr, dtype=float)
77
85
  uniform_vec[used_in_uniform] = 1.0 / n_uniform
78
- pr_uniform = g.personalized_pagerank(
86
+ pr_uniform = napistu_graph.personalized_pagerank(
79
87
  reset=uniform_vec.tolist(), damping=damping, **additional_propagation_args
80
88
  )
81
89
  data["pagerank_uniform"] = pr_uniform
@@ -83,16 +91,36 @@ def personalized_pagerank_by_attribute(
83
91
  return pd.DataFrame(data)
84
92
 
85
93
 
86
- def _ensure_nonnegative_vertex_attribute(g: ig.Graph, attribute: str):
87
- """
88
- Utility to check that a vertex attribute is present, numeric, and non-negative.
89
- Raises ValueError if checks fail.
90
- Missing or None values are treated as 0.
91
- Raises ValueError if attribute is missing for all vertices or all values are zero.
94
+ def _ensure_nonnegative_vertex_attribute(
95
+ napistu_graph: Union[NapistuGraph, ig.Graph], attribute: str
96
+ ):
92
97
  """
98
+ Ensure a vertex attribute is present, numeric, and non-negative for all vertices.
93
99
 
100
+ This utility checks that the specified vertex attribute exists, is numeric, and non-negative
101
+ for all vertices in the graph. Missing or None values are treated as 0. Raises ValueError
102
+ if the attribute is missing for all vertices, if all values are zero, or if any value is negative.
103
+
104
+ Parameters
105
+ ----------
106
+ napistu_graph : NapistuGraph or ig.Graph
107
+ The input graph (NapistuGraph or igraph.Graph).
108
+ attribute : str
109
+ The name of the vertex attribute to check.
110
+
111
+ Returns
112
+ -------
113
+ np.ndarray
114
+ Array of attribute values (with missing/None replaced by 0).
115
+
116
+ Raises
117
+ ------
118
+ ValueError
119
+ If the attribute is missing for all vertices, all values are zero, or any value is negative.
120
+ """
94
121
  all_missing = all(
95
- (attribute not in v.attributes() or v[attribute] is None) for v in g.vs
122
+ (attribute not in v.attributes() or v[attribute] is None)
123
+ for v in napistu_graph.vs
96
124
  )
97
125
  if all_missing:
98
126
  raise ValueError(f"Vertex attribute '{attribute}' is missing for all vertices.")
@@ -103,7 +131,7 @@ def _ensure_nonnegative_vertex_attribute(g: ig.Graph, attribute: str):
103
131
  if (attribute in v.attributes() and v[attribute] is not None)
104
132
  else 0.0
105
133
  )
106
- for v in g.vs
134
+ for v in napistu_graph.vs
107
135
  ]
108
136
 
109
137
  arr = np.array(values, dtype=float)