Pull subjects and save linkage


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']])


I will be pulling files from /data1/abide/Out/Remote/all_worked/out/sc36/stability_maps

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))


Loading network 0
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-5-46f687ef0f30> in <module>()
      3 for network in np.arange(36):
      4     print('Loading network {}'.format(network))
----> 5     data_dict = bb.fileOps.read_files(file_dict, network=network, silence=True)
      6     # We only loaded one network so it is always the first one
      7     results.append(bb.dataOps.calc_link(data_dict, metric, network=0))

/home/surchs/Code/brainbox/fileOps/base.pyc in read_files(file_dict, network, silence)
    123             # Preallocate array
    124             array_dict[sub_dir] = [np.empty(arr_size), 0]
--> 125         array_dict[sub_dir][0][array_dict[sub_dir][1], ...] = tmp_flat
    126         array_dict[sub_dir][1] += 1
    127 

KeyboardInterrupt: 

In [5]:



Out[5]:
{'dir': [], 'path': [], 'sub_name': []}

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]:
11

In [ ]: