Skip to content

Commit f92c07d

Browse files
authored
Merge branch 'master' into enh/6.0.1
2 parents 802383e + 119a738 commit f92c07d

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

run.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def run(command, env={}, ignore_errors=False):
111111
if glob(os.path.join(args.bids_dir, "sub-*", "ses-*")):
112112
subjects = [subject_dir.split("-")[-1] for subject_dir in subject_dirs]
113113
for subject_label in subjects:
114-
session_dirs = glob(os.path.join(args.bids_dir,"sub-%s"%subject_label,"ses-*"))
114+
session_dirs = glob(os.path.join(args.bids_dir, "sub-%s"%subject_label, "ses-*"))
115115
sessions = [os.path.split(dr)[-1].split("-")[-1] for dr in session_dirs]
116116
n_valid_sessions = 0
117117
for session_label in sessions:
@@ -167,36 +167,36 @@ def run(command, env={}, ignore_errors=False):
167167
for subject_label in subjects_to_analyze:
168168
if glob(os.path.join(args.bids_dir, "sub-%s"%subject_label, "ses-*")):
169169
T1s = glob(os.path.join(args.bids_dir,
170-
"sub-%s"%subject_label,
171-
"ses-*",
172-
"anat",
173-
"%s_T1w.nii*"%acq_tpl))
170+
"sub-%s"%subject_label,
171+
"ses-*",
172+
"anat",
173+
"%s_T1w.nii*"%acq_tpl))
174174
sessions = set([os.path.normpath(t1).split(os.sep)[-3].split("-")[-1] for t1 in T1s])
175175
if args.session_label:
176176
sessions = sessions.intersection(args.session_label)
177177

178178
if len(sessions) > 0 and longitudinal_study == True:
179179
timepoints = ["sub-%s_ses-%s"%(subject_label, session_label) for session_label in sessions]
180-
if ('cross-sectional' in args.steps):
180+
if 'cross-sectional' in args.steps:
181181
# Running each session separately, prior to doing longitudinal pipeline
182182
for session_label in sessions:
183183
T1s = glob(os.path.join(args.bids_dir,
184-
"sub-%s"%subject_label,
185-
"ses-%s"%session_label,
186-
"anat",
187-
"%s_T1w.nii*"%acq_tpl))
184+
"sub-%s"%subject_label,
185+
"ses-%s"%session_label,
186+
"anat",
187+
"%s_T1w.nii*"%acq_tpl))
188188
input_args = ""
189189
for T1 in T1s:
190-
if (round(max(nibabel.load(T1).header.get_zooms()),1) < 1.0 and args.hires_mode == "auto") or args.hires_mode == "enable":
190+
if (round(max(nibabel.load(T1).header.get_zooms()), 1) < 1.0 and args.hires_mode == "auto") or args.hires_mode == "enable":
191191
input_args += " -hires"
192192
input_args += " -i %s"%T1
193193

194194
T2s = glob(os.path.join(args.bids_dir, "sub-%s"%subject_label,
195195
"ses-%s"%session_label, "anat",
196196
"*%s_T2w.nii*"%acq_t2))
197197
FLAIRs = glob(os.path.join(args.bids_dir, "sub-%s"%subject_label,
198-
"ses-%s"%session_label, "anat",
199-
"*%s_FLAIR.nii*"%acq_t2))
198+
"ses-%s"%session_label, "anat",
199+
"*%s_FLAIR.nii*"%acq_t2))
200200
if args.refine_pial == "T2":
201201
for T2 in T2s:
202202
if max(nibabel.load(T2).header.get_zooms()) < 1.2:
@@ -225,7 +225,7 @@ def run(command, env={}, ignore_errors=False):
225225
print("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:")
226226
print(cmd)
227227
run(cmd, env=env)
228-
elif os.path.isfile(os.path.join(output_dir, fsid, "mri/aseg.mgz")):
228+
elif os.path.isfile(os.path.join(output_dir, fsid, "label/BA_exvivo.thresh.ctab")):
229229
print("SUBJECT ALREADY SEGMENTED, SKIPPING")
230230
elif os.path.exists(os.path.join(output_dir, fsid)):
231231
print("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:")
@@ -234,8 +234,8 @@ def run(command, env={}, ignore_errors=False):
234234
else:
235235
print(cmd)
236236
run(cmd, env=env)
237-
238-
if ('template' in args.steps):
237+
238+
if 'template' in args.steps:
239239
# creating a subject specific template
240240
input_args = " ".join(["-tp %s"%tp for tp in timepoints])
241241
fsid = "sub-%s"%subject_label
@@ -246,12 +246,12 @@ def run(command, env={}, ignore_errors=False):
246246
stages,
247247
args.n_cpus)
248248

249-
if os.path.isfile(os.path.join(output_dir, fsid,"scripts/IsRunning.lh+rh")):
249+
if os.path.isfile(os.path.join(output_dir, fsid, "scripts/IsRunning.lh+rh")):
250250
rmtree(os.path.join(output_dir, fsid))
251251
print("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:")
252252
print(cmd)
253253
run(cmd, env=env)
254-
elif os.path.isfile(os.path.join(output_dir, fsid, "mri/aseg.mgz")):
254+
elif os.path.isfile(os.path.join(output_dir, fsid, "label/BA_exvivo.thresh.ctab")):
255255
print("TEMPLATE ALREADY CREATED, SKIPPING")
256256
elif os.path.exists(os.path.join(output_dir, fsid)):
257257
print("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:")
@@ -260,8 +260,8 @@ def run(command, env={}, ignore_errors=False):
260260
else:
261261
print(cmd)
262262
run(cmd, env=env)
263-
264-
if ('longitudinal' in args.steps):
263+
264+
if 'longitudinal' in args.steps:
265265
for tp in timepoints:
266266
# longitudinally process all timepoints
267267
fsid = "sub-%s"%subject_label
@@ -277,7 +277,7 @@ def run(command, env={}, ignore_errors=False):
277277
print("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:")
278278
print(cmd)
279279
run(cmd, env=env)
280-
elif os.path.isfile(os.path.join(output_dir, tp + ".long." + fsid, "mri/aseg.mgz")):
280+
elif os.path.isfile(os.path.join(output_dir, tp + ".long." + fsid, "label/BA_exvivo.thresh.ctab")):
281281
print("SUBJECT ALREADY SEGMENTED, SKIPPING")
282282
else:
283283
print(cmd)
@@ -334,6 +334,8 @@ def run(command, env={}, ignore_errors=False):
334334
print("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:")
335335
print(cmd)
336336
run(cmd, env=env)
337+
elif os.path.isfile(os.path.join(output_dir, fsid, "label/BA_exvivo.thresh.ctab")):
338+
print("SUBJECT ALREADY SEGMENTED, SKIPPING")
337339
elif os.path.exists(os.path.join(output_dir, fsid)):
338340
print("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:")
339341
print(resume_cmd)
@@ -390,6 +392,8 @@ def run(command, env={}, ignore_errors=False):
390392
print("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:")
391393
print(cmd)
392394
run(cmd, env=env)
395+
elif os.path.isfile(os.path.join(output_dir, fsid, "label/BA_exvivo.thresh.ctab")):
396+
print("SUBJECT ALREADY SEGMENTED, SKIPPING")
393397
elif os.path.exists(os.path.join(output_dir, fsid)):
394398
print("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:")
395399
print(resume_cmd)

0 commit comments

Comments
 (0)