Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c3a1909

Browse files
committed
FIX: Purge nx.read_gpickle
1 parent 9340748 commit c3a1909

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

‎nipype/interfaces/cmtk/convert.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
from .base import CFFBaseInterface, have_cfflib
1919

2020

21+
def _read_pickle(fname):
22+
import pickle
23+
with open(fname, 'rb') as f:
24+
return pickle.load(f)
25+
26+
2127
class CFFConverterInputSpec(BaseInterfaceInputSpec):
2228
graphml_networks = InputMultiPath(
2329
File(exists=True), desc="list of graphML networks"
@@ -135,7 +141,7 @@ def _run_interface(self, runtime):
135141
unpickled = []
136142
for ntwk in self.inputs.gpickled_networks:
137143
_, ntwk_name, _ = split_filename(ntwk)
138-
unpickled = nx.read_gpickle(ntwk)
144+
unpickled = _read_pickle(ntwk)
139145
cnet = cf.CNetwork(name=ntwk_name)
140146
cnet.set_with_nxgraph(unpickled)
141147
a.add_connectome_network(cnet)

‎nipype/interfaces/cmtk/nbs.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@
2424
iflogger = logging.getLogger("nipype.interface")
2525

2626

27+
def _read_pickle(fname):
28+
with open(fname, 'rb') as f:
29+
return pickle.load(f)
30+
31+
2732
def ntwks_to_matrices(in_files, edge_key):
28-
first = nx.read_gpickle(in_files[0])
33+
first = _read_pickle(in_files[0])
2934
files = len(in_files)
3035
nodes = len(first.nodes())
3136
matrix = np.zeros((nodes, nodes, files))
3237
for idx, name in enumerate(in_files):
33-
graph = nx.read_gpickle(name)
38+
graph = _read_pickle(name)
3439
for u, v, d in graph.edges(data=True):
3540
try:
3641
graph[u][v]["weight"] = d[
@@ -162,7 +167,7 @@ def _run_interface(self, runtime):
162167
else:
163168
node_ntwk_name = self.inputs.in_group1[0]
164169

165-
node_network = nx.read_gpickle(node_ntwk_name)
170+
node_network = _read_pickle(node_ntwk_name)
166171
iflogger.info(
167172
"Populating node dictionaries with attributes from %s", node_ntwk_name
168173
)

‎nipype/interfaces/cmtk/nx.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@
2424
iflogger = logging.getLogger("nipype.interface")
2525

2626

27+
def _read_pickle(fname):
28+
with open(fname, 'rb') as f:
29+
return pickle.load(f)
30+
31+
2732
def read_unknown_ntwk(ntwk):
2833
if not isinstance(ntwk, nx.classes.graph.Graph):
2934
_, _, ext = split_filename(ntwk)
3035
if ext == ".pck":
31-
ntwk = nx.read_gpickle(ntwk)
36+
ntwk = _read_pickle(ntwk)
3237
elif ext == ".graphml":
3338
ntwk = nx.read_graphml(ntwk)
3439
return ntwk
@@ -121,7 +126,7 @@ def average_networks(in_files, ntwk_res_file, group_id):
121126
counting_ntwk = ntwk.copy()
122127
# Sums all the relevant variables
123128
for index, subject in enumerate(in_files):
124-
tmp = nx.read_gpickle(subject)
129+
tmp = _read_pickle(subject)
125130
iflogger.info("File %s has %i edges", subject, tmp.number_of_edges())
126131
edges = list(tmp.edges())
127132
for edge in edges:
@@ -461,7 +466,7 @@ def _run_interface(self, runtime):
461466
edgentwks = list()
462467
kntwks = list()
463468
matlab = list()
464-
ntwk = nx.read_gpickle(self.inputs.in_file)
469+
ntwk = _read_pickle(self.inputs.in_file)
465470

466471
# Each block computes, writes, and saves a measure
467472
# The names are then added to the output .pck file list

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /