napistu 0.3.4__py3-none-any.whl → 0.3.5__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/constants.py +4 -4
- napistu/network/ig_utils.py +35 -0
- napistu/network/precompute.py +2 -1
- napistu/sbml_dfs_core.py +702 -501
- napistu/source.py +1 -1
- {napistu-0.3.4.dist-info → napistu-0.3.5.dist-info}/METADATA +1 -1
- {napistu-0.3.4.dist-info → napistu-0.3.5.dist-info}/RECORD +13 -13
- tests/test_network_ig_utils.py +36 -0
- tests/test_sbml_dfs_core.py +131 -0
- {napistu-0.3.4.dist-info → napistu-0.3.5.dist-info}/WHEEL +0 -0
- {napistu-0.3.4.dist-info → napistu-0.3.5.dist-info}/entry_points.txt +0 -0
- {napistu-0.3.4.dist-info → napistu-0.3.5.dist-info}/licenses/LICENSE +0 -0
- {napistu-0.3.4.dist-info → napistu-0.3.5.dist-info}/top_level.txt +0 -0
napistu/constants.py
CHANGED
@@ -149,10 +149,10 @@ INTERACTION_EDGELIST_EXPECTED_VARS = {
|
|
149
149
|
"downstream_name",
|
150
150
|
"upstream_compartment",
|
151
151
|
"downstream_compartment",
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
152
|
+
SBML_DFS.R_NAME,
|
153
|
+
SBML_DFS.SBO_TERM,
|
154
|
+
SBML_DFS.R_IDENTIFIERS,
|
155
|
+
SBML_DFS.R_ISREVERSIBLE,
|
156
156
|
}
|
157
157
|
|
158
158
|
BQB_PRIORITIES = pd.DataFrame(
|
napistu/network/ig_utils.py
CHANGED
@@ -99,6 +99,41 @@ def filter_to_largest_subgraph(graph: ig.Graph) -> ig.Graph:
|
|
99
99
|
return largest_subgraph
|
100
100
|
|
101
101
|
|
102
|
+
def filter_to_largest_subgraphs(graph: ig.Graph, top_k: int) -> list[ig.Graph]:
|
103
|
+
"""
|
104
|
+
Filter an igraph to its largest weakly connected components.
|
105
|
+
|
106
|
+
Parameters
|
107
|
+
----------
|
108
|
+
graph : ig.Graph
|
109
|
+
The input network.
|
110
|
+
top_k : int
|
111
|
+
The number of largest components to return.
|
112
|
+
|
113
|
+
Returns
|
114
|
+
-------
|
115
|
+
list[ig.Graph]
|
116
|
+
A list of the top K largest components as graphs.
|
117
|
+
"""
|
118
|
+
if top_k < 1:
|
119
|
+
raise ValueError("top_k must be 1 or greater.")
|
120
|
+
|
121
|
+
component_members = graph.components(mode="weak")
|
122
|
+
if not component_members:
|
123
|
+
return []
|
124
|
+
|
125
|
+
component_sizes = [len(x) for x in component_members]
|
126
|
+
|
127
|
+
# Sort components by size in descending order
|
128
|
+
sorted_components = sorted(
|
129
|
+
zip(component_sizes, component_members), key=lambda x: x[0], reverse=True
|
130
|
+
)
|
131
|
+
|
132
|
+
# Return a list of the top K subgraphs
|
133
|
+
top_k_components = sorted_components[:top_k]
|
134
|
+
return [graph.induced_subgraph(members) for _, members in top_k_components]
|
135
|
+
|
136
|
+
|
102
137
|
def graph_to_pandas_dfs(graph: ig.Graph) -> tuple[pd.DataFrame, pd.DataFrame]:
|
103
138
|
"""
|
104
139
|
Convert an igraph to Pandas DataFrames for vertices and edges.
|
napistu/network/precompute.py
CHANGED
@@ -4,6 +4,7 @@ import logging
|
|
4
4
|
import math
|
5
5
|
from pathlib import Path
|
6
6
|
from typing import Union
|
7
|
+
import io
|
7
8
|
|
8
9
|
import numpy as np
|
9
10
|
import pandas as pd
|
@@ -144,7 +145,7 @@ def load_precomputed_distances(uri: Union[str, Path]) -> pd.DataFrame:
|
|
144
145
|
"""
|
145
146
|
try:
|
146
147
|
json_string = load_json(str(uri))
|
147
|
-
df = pd.read_json(json_string)
|
148
|
+
df = pd.read_json(io.StringIO(json_string))
|
148
149
|
|
149
150
|
# Convert integer columns to float
|
150
151
|
for col in df.columns:
|