Network Based Statistics Unpickling.Error



I am trying to run network based statistic on graphs from diffusion MRI data. I have the adjacency matrices of the graphs as csv files. I am wondering if it is possible to use cmtk.NetworkBasedStatistic() with a csv file. As far as I can see the documentation does not specify the required filetype.

My code currently looks as follows:

# Imports
import numpy as np
from numpy import genfromtxt
import os
import nipype.interfaces.cmtk as cmtk

# Create list of filenames
cur_path = '/Users/.../'
files = os.listdir(cur_path)
graphnames = []
for names in files:
    if names.endswith(".csv"):

# Network Based Statistic
nbs = cmtk.NetworkBasedStatistic()
filesedited = [cur_path + file for file in files]
nbs.inputs.in_group1 = filesedited[0:23]
nbs.inputs.in_group2 = filesedited[23:len(files)+1]
network,pval,files =

I get the following error:

Traceback (most recent call last):
  File "", line 34, in <module>
  File "/usr/local/lib/python3.6/site-packages/nipype/interfaces/", line 1081, in run
    runtime = self._run_wrapper(runtime)
  File "/usr/local/lib/python3.6/site-packages/nipype/interfaces/", line 1029, in _run_wrapper
    runtime = self._run_interface(runtime)
  File "/usr/local/lib/python3.6/site-packages/nipype/interfaces/cmtk/", line 87, in _run_interface
    X = ntwks_to_matrices(self.inputs.in_group1, edge_key)
  File "/usr/local/lib/python3.6/site-packages/nipype/interfaces/cmtk/", line 28, in ntwks_to_matrices
    first = nx.read_gpickle(in_files[0])
  File "<decorator-gen-174>", line 2, in read_gpickle
  File "/usr/local/lib/python3.6/site-packages/networkx/utils/", line 220, in _open_file
    result = func(*new_args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/networkx/readwrite/", line 101, in read_gpickle
    return pickle.load(path)
_pickle.UnpicklingError: invalid load key, '\x00'.
Interface NetworkBasedStatistic failed to run.

Unfortunately I am not familiar with the way Unpickling works and wasn’t able to find out what the problem is. I would greatly appreciate any suggestions.

Edit: Solved. I am still not sure how to interpret the Error message, but it disappeared by using Networkx to transform the files from CSV to pck format:

G = nx.from_numpy_matrix(graph)
nx.write_gpickle(G, out_path)


NetworkBasedStatistic uses networkx.read_gpickle to read in_group1 and in_group2 and the function takes Python pickle format. The error you got “_pickle.UnpicklingError: invalid load key” is a standard error that you get when you call networkx.read_gpickle with wrong file format. “Interface NetworkBasedStatistic failed to run.” is a general nipype error that you get when something goes wrong (e.g. pickle or networkx complains about anything).