-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.py
executable file
·76 lines (66 loc) · 3.55 KB
/
run.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import argparse
import os
from os.path import join, exists, abspath
from subprocess import check_call
from glob import glob
from nipype.utils.filemanip import split_filename
__version__ = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'version')).read()
def get_t1_images(basedir, subject_label):
print(join(basedir,subject_label, "anat", "sub-%s_T1w.nii.gz" % (subject_label)))
print(join(basedir,subject_label, "anat", "sub-%s_ses-*_T1w.nii.gz" % (subject_label)))
out = glob(join(basedir,"sub-%s"%subject_label,"anat", "sub-%s_T1w.nii.gz" % (subject_label))) + \
glob(join(basedir,"sub-%s"%subject_label, "anat", "sub-%s_ses-*_T1w.nii.gz" % (subject_label)))
return out
def run_mindboggle(image, subject_id, output_dir):
#mindboggle123 $IMAGE --id $ID --out $OUT --working $WORKING
cmd = ["mindboggle123", image,
"--id", subject_id,
"--out", join(output_dir, "derivatives", "mindboggle"),
"--working", join(output_dir,"scratch"),
]
check_call(cmd)
return
parser = argparse.ArgumentParser(description='Example BIDS App entrypoint script.')
parser.add_argument('bids_dir', help='The directory with the input dataset '
'formatted according to the BIDS standard.')
parser.add_argument('output_dir', help='The directory where the output files '
'should be stored. If you are running group level analysis '
'this folder should be prepopulated with the results of the'
'participant level analysis.')
parser.add_argument('analysis_level', help='Level of the analysis that will be performed. '
'Multiple participant level analyses can be run independently '
'(in parallel) using the same output_dir.',
choices=['participant'])
parser.add_argument('--participant_label', help='The label(s) of the participant(s) that should be analyzed. The label '
'corresponds to sub-<participant_label> from the BIDS spec '
'(so it does not include "sub-"). If this parameter is not '
'provided all subjects should be analyzed. Multiple '
'participants can be specified with a space separated list.',
nargs="+")
parser.add_argument('-v', '--version', action='version',
version='BIDS-App Mindboggle version {}'.format(__version__))
args = parser.parse_args()
subjects_to_analyze = []
# only for a subset of subjects
if args.participant_label:
subjects_to_analyze = args.participant_label
# for all subjects
else:
subjects_to_analyze = [s.split("/")[-1].replace("sub-","") for s in glob(os.path.join(args.bids_dir, "sub*"))]
# running participant level
print(args)
print(subjects_to_analyze)
if args.analysis_level == "participant":
print("running")
# find all T1s and skullstrip them
for subject_label in subjects_to_analyze:
print("subject_label is", subject_label)
t1_images = get_t1_images(args.bids_dir, subject_label)
print("images are", t1_images)
for t1 in t1_images:
if len(t1_images) > 1:
pth, label, ext = split_filename(t1)
else:
label = "sub-%s" % subject_label
run_mindboggle(t1, label, args.output_dir)