napistu 0.2.5.dev7__py3-none-any.whl → 0.3.1.dev1__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.
- napistu/__init__.py +1 -3
- napistu/__main__.py +126 -96
- napistu/constants.py +35 -41
- napistu/context/__init__.py +10 -0
- napistu/context/discretize.py +462 -0
- napistu/context/filtering.py +387 -0
- napistu/gcs/__init__.py +1 -1
- napistu/identifiers.py +74 -15
- napistu/indices.py +68 -0
- napistu/ingestion/__init__.py +1 -1
- napistu/ingestion/bigg.py +47 -62
- napistu/ingestion/constants.py +18 -133
- napistu/ingestion/gtex.py +113 -0
- napistu/ingestion/hpa.py +147 -0
- napistu/ingestion/sbml.py +0 -97
- napistu/ingestion/string.py +2 -2
- napistu/matching/__init__.py +10 -0
- napistu/matching/constants.py +18 -0
- napistu/matching/interactions.py +518 -0
- napistu/matching/mount.py +529 -0
- napistu/matching/species.py +510 -0
- napistu/mcp/__init__.py +7 -4
- napistu/mcp/__main__.py +128 -72
- napistu/mcp/client.py +16 -25
- napistu/mcp/codebase.py +201 -145
- napistu/mcp/component_base.py +170 -0
- napistu/mcp/config.py +223 -0
- napistu/mcp/constants.py +45 -2
- napistu/mcp/documentation.py +253 -136
- napistu/mcp/documentation_utils.py +13 -48
- napistu/mcp/execution.py +372 -305
- napistu/mcp/health.py +47 -65
- napistu/mcp/profiles.py +10 -6
- napistu/mcp/server.py +161 -80
- napistu/mcp/tutorials.py +139 -87
- napistu/modify/__init__.py +1 -1
- napistu/modify/gaps.py +1 -1
- napistu/network/__init__.py +1 -1
- napistu/network/constants.py +101 -34
- napistu/network/data_handling.py +388 -0
- napistu/network/ig_utils.py +351 -0
- napistu/network/napistu_graph_core.py +354 -0
- napistu/network/neighborhoods.py +40 -40
- napistu/network/net_create.py +373 -309
- napistu/network/net_propagation.py +47 -19
- napistu/network/{net_utils.py → ng_utils.py} +124 -272
- napistu/network/paths.py +67 -51
- napistu/network/precompute.py +11 -11
- napistu/ontologies/__init__.py +10 -0
- napistu/ontologies/constants.py +129 -0
- napistu/ontologies/dogma.py +243 -0
- napistu/ontologies/genodexito.py +649 -0
- napistu/ontologies/mygene.py +369 -0
- napistu/ontologies/renaming.py +198 -0
- napistu/rpy2/__init__.py +229 -86
- napistu/rpy2/callr.py +47 -77
- napistu/rpy2/constants.py +24 -23
- napistu/rpy2/rids.py +61 -648
- napistu/sbml_dfs_core.py +587 -222
- napistu/scverse/__init__.py +15 -0
- napistu/scverse/constants.py +28 -0
- napistu/scverse/loading.py +727 -0
- napistu/utils.py +118 -10
- {napistu-0.2.5.dev7.dist-info → napistu-0.3.1.dev1.dist-info}/METADATA +8 -3
- napistu-0.3.1.dev1.dist-info/RECORD +133 -0
- tests/conftest.py +22 -0
- tests/test_context_discretize.py +56 -0
- tests/test_context_filtering.py +267 -0
- tests/test_identifiers.py +100 -0
- tests/test_indices.py +65 -0
- tests/{test_edgelist.py → test_ingestion_napistu_edgelist.py} +2 -2
- tests/test_matching_interactions.py +108 -0
- tests/test_matching_mount.py +305 -0
- tests/test_matching_species.py +394 -0
- tests/test_mcp_config.py +193 -0
- tests/test_mcp_documentation_utils.py +12 -3
- tests/test_mcp_server.py +156 -19
- tests/test_network_data_handling.py +397 -0
- tests/test_network_ig_utils.py +23 -0
- tests/test_network_neighborhoods.py +19 -0
- tests/test_network_net_create.py +459 -0
- tests/test_network_ng_utils.py +30 -0
- tests/test_network_paths.py +56 -0
- tests/{test_precomputed_distances.py → test_network_precompute.py} +8 -6
- tests/test_ontologies_genodexito.py +58 -0
- tests/test_ontologies_mygene.py +39 -0
- tests/test_ontologies_renaming.py +110 -0
- tests/test_rpy2_callr.py +79 -0
- tests/test_rpy2_init.py +151 -0
- tests/test_sbml.py +0 -31
- tests/test_sbml_dfs_core.py +134 -10
- tests/test_scverse_loading.py +778 -0
- tests/test_set_coverage.py +2 -2
- tests/test_utils.py +121 -1
- napistu/mechanism_matching.py +0 -1353
- napistu/rpy2/netcontextr.py +0 -467
- napistu-0.2.5.dev7.dist-info/RECORD +0 -98
- tests/test_igraph.py +0 -367
- tests/test_mechanism_matching.py +0 -784
- tests/test_net_utils.py +0 -149
- tests/test_netcontextr.py +0 -105
- tests/test_rpy2.py +0 -61
- /napistu/ingestion/{cpr_edgelist.py → napistu_edgelist.py} +0 -0
- {napistu-0.2.5.dev7.dist-info → napistu-0.3.1.dev1.dist-info}/WHEEL +0 -0
- {napistu-0.2.5.dev7.dist-info → napistu-0.3.1.dev1.dist-info}/entry_points.txt +0 -0
- {napistu-0.2.5.dev7.dist-info → napistu-0.3.1.dev1.dist-info}/licenses/LICENSE +0 -0
- {napistu-0.2.5.dev7.dist-info → napistu-0.3.1.dev1.dist-info}/top_level.txt +0 -0
- /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
|
8
|
+
from napistu.network.napistu_graph_core import NapistuGraph
|
7
9
|
|
8
10
|
|
9
11
|
def personalized_pagerank_by_attribute(
|
10
|
-
|
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
|
-
|
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
|
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(
|
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(
|
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 =
|
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 =
|
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 =
|
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(
|
87
|
-
|
88
|
-
|
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)
|
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
|
134
|
+
for v in napistu_graph.vs
|
107
135
|
]
|
108
136
|
|
109
137
|
arr = np.array(values, dtype=float)
|