-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractTemplateTimeSeries.py
More file actions
46 lines (35 loc) · 1.65 KB
/
extractTemplateTimeSeries.py
File metadata and controls
46 lines (35 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
This script writes submits a script to the grid engine to extract network specific timeseries subject-by-subject for use
in between network connectivity analysis.
"""
from glob import glob
from os import path,getcwd,chmod,system
# Define list of diagnosis, directory containing network templates (from the FIND lab) and the name of the preprocessed
# functional imaging file
diags = ["Control", "PSP", "CBD"]
templateDir = "templates_new"
funcFile = "functional_reordered_pp_wpd_MNI_cut_smooth.nii"
# get templates
templates = [path.basename(v) for v in glob(path.join(templateDir, "*")) if path.isdir(v) ]
# dictionary of diagnoses and subject lists
subjsDict = {}
for diag in diags:
subjsList = [ v for v in glob(path.join(diag, "*")) if path.isdir(v) ] # get all subject directories for the diagnosis
subjsDict[diag] = dict(zip(range(len(subjsList)), subjsList)) # add the subject list to the dictionary
print subjsDict
# extract network timeseries
for network in templates:
tf = path.join(templateDir, network, network+".nii.gz")
print network
# iterate through diagnoses
for diag in diags:
# open submission file
subF = path.join(diag, network+"exTs.sh")
f = open(subF, "w")
# iterate through subject list
for subjN in range(len(subjsDict[diag].keys())):
# write line to call fslmeants (FSL) function to extract the network timeseries
f.writelines(' '.join(["fslmeants", "-i", path.join(subjsDict[diag][subjN], funcFile), "-o", path.join(subjsDict[diag][subjN], network+"ts.txt"), "-m", tf])+'\n')
f.close()
# submit the submission script to the grid engine
system(' '.join(["fsl_sub", "-t", subF, "-q", "short.q", "-l", diag]))