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"): graphnames.append(names) # 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 = nbs.run()
I get the following error:
Traceback (most recent call last): File "nbs_try.py", line 34, in <module> nbs.run() File "/usr/local/lib/python3.6/site-packages/nipype/interfaces/base.py", line 1081, in run runtime = self._run_wrapper(runtime) File "/usr/local/lib/python3.6/site-packages/nipype/interfaces/base.py", line 1029, in _run_wrapper runtime = self._run_interface(runtime) File "/usr/local/lib/python3.6/site-packages/nipype/interfaces/cmtk/nbs.py", 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/nbs.py", line 28, in ntwks_to_matrices first = nx.read_gpickle(in_files) File "<decorator-gen-174>", line 2, in read_gpickle File "/usr/local/lib/python3.6/site-packages/networkx/utils/decorators.py", line 220, in _open_file result = func(*new_args, **kwargs) File "/usr/local/lib/python3.6/site-packages/networkx/readwrite/gpickle.py", 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)