In [2]:
# Imports
import re
import os
import gzip
import numpy as np
import pandas as pd
import cPickle as cp
import brainbox as bb
from matplotlib import pyplot as plt
import scipy.cluster.hierarchy as clh
In [3]:
# Paths
debug_path = '/data1/abide/Out/Remote/all_worked/out/sc36'
out_path = '/data1/abide/Test'
if not os.path.isdir(out_path):
try:
os.makedirs(out_path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(out_path):
pass
else: raise
In [4]:
# Find the data
metric = 'stability_maps'
file_dict = bb.fileOps.grab_files(debug_path, '.nii.gz', metric)
# Get subject IDs of the files I just read in
data_subs = np.array([int64(re.search(r'(?<=\d{2})\d{5}', sub_id).group()) for sub_id in file_dict['sub_name']])
In [5]:
# Loop the data
results = list()
for network in np.arange(36):
print('Loading network {}'.format(network))
data_dict = bb.fileOps.read_files(file_dict, network=network, silence=True)
# We only loaded one network so it is always the first one
results.append(bb.dataOps.calc_link(data_dict, metric, network=0))
In [5]:
Out[5]:
In [14]:
out = (data_subs, results)
In [15]:
outFile = os.path.join(out_path, 'linkage.gz')
outF = gzip.open(outFile, 'wb')
cp.dump(out, outF, protocol=2)
outF.close()
In [1]:
10 +1
Out[1]:
In [ ]: