@@ -111,7 +111,7 @@ def run(command, env={}, ignore_errors=False):
111111if 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 :
@@ -161,36 +161,36 @@ def run(command, env={}, ignore_errors=False):
161161 for subject_label in subjects_to_analyze :
162162 if glob (os .path .join (args .bids_dir , "sub-%s" % subject_label , "ses-*" )):
163163 T1s = glob (os .path .join (args .bids_dir ,
164- "sub-%s" % subject_label ,
165- "ses-*" ,
166- "anat" ,
167- "%s_T1w.nii*" % acq_tpl ))
164+ "sub-%s" % subject_label ,
165+ "ses-*" ,
166+ "anat" ,
167+ "%s_T1w.nii*" % acq_tpl ))
168168 sessions = set ([os .path .normpath (t1 ).split (os .sep )[- 3 ].split ("-" )[- 1 ] for t1 in T1s ])
169169 if args .session_label :
170170 sessions = sessions .intersection (args .session_label )
171171
172172 if len (sessions ) > 0 and longitudinal_study == True :
173173 timepoints = ["sub-%s_ses-%s" % (subject_label , session_label ) for session_label in sessions ]
174- if ( 'cross-sectional' in args .steps ) :
174+ if 'cross-sectional' in args .steps :
175175 # Running each session separately, prior to doing longitudinal pipeline
176176 for session_label in sessions :
177177 T1s = glob (os .path .join (args .bids_dir ,
178- "sub-%s" % subject_label ,
179- "ses-%s" % session_label ,
180- "anat" ,
181- "%s_T1w.nii*" % acq_tpl ))
178+ "sub-%s" % subject_label ,
179+ "ses-%s" % session_label ,
180+ "anat" ,
181+ "%s_T1w.nii*" % acq_tpl ))
182182 input_args = ""
183183 for T1 in T1s :
184- if (round (max (nibabel .load (T1 ).header .get_zooms ()),1 ) < 1.0 and args .hires_mode == "auto" ) or args .hires_mode == "enable" :
184+ if (round (max (nibabel .load (T1 ).header .get_zooms ()), 1 ) < 1.0 and args .hires_mode == "auto" ) or args .hires_mode == "enable" :
185185 input_args += " -hires"
186186 input_args += " -i %s" % T1
187187
188188 T2s = glob (os .path .join (args .bids_dir , "sub-%s" % subject_label ,
189189 "ses-%s" % session_label , "anat" ,
190190 "*%s_T2w.nii*" % acq_t2 ))
191191 FLAIRs = glob (os .path .join (args .bids_dir , "sub-%s" % subject_label ,
192- "ses-%s" % session_label , "anat" ,
193- "*%s_FLAIR.nii*" % acq_t2 ))
192+ "ses-%s" % session_label , "anat" ,
193+ "*%s_FLAIR.nii*" % acq_t2 ))
194194 if args .refine_pial == "T2" :
195195 for T2 in T2s :
196196 if max (nibabel .load (T2 ).header .get_zooms ()) < 1.2 :
@@ -219,7 +219,7 @@ def run(command, env={}, ignore_errors=False):
219219 print ("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:" )
220220 print (cmd )
221221 run (cmd )
222- elif os .path .isfile (os .path .join (output_dir , fsid , "mri/aseg.mgz " )):
222+ elif os .path .isfile (os .path .join (output_dir , fsid , "label/BA_exvivo.thresh.ctab " )):
223223 print ("SUBJECT ALREADY SEGMENTED, SKIPPING" )
224224 elif os .path .exists (os .path .join (output_dir , fsid )):
225225 print ("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:" )
@@ -228,8 +228,8 @@ def run(command, env={}, ignore_errors=False):
228228 else :
229229 print (cmd )
230230 run (cmd )
231-
232- if ( 'template' in args .steps ) :
231+
232+ if 'template' in args .steps :
233233 # creating a subject specific template
234234 input_args = " " .join (["-tp %s" % tp for tp in timepoints ])
235235 fsid = "sub-%s" % subject_label
@@ -240,12 +240,12 @@ def run(command, env={}, ignore_errors=False):
240240 stages ,
241241 args .n_cpus )
242242
243- if os .path .isfile (os .path .join (output_dir , fsid ,"scripts/IsRunning.lh+rh" )):
243+ if os .path .isfile (os .path .join (output_dir , fsid , "scripts/IsRunning.lh+rh" )):
244244 rmtree (os .path .join (output_dir , fsid ))
245245 print ("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:" )
246246 print (cmd )
247247 run (cmd )
248- elif os .path .isfile (os .path .join (output_dir , fsid , "mri/aseg.mgz " )):
248+ elif os .path .isfile (os .path .join (output_dir , fsid , "label/BA_exvivo.thresh.ctab " )):
249249 print ("TEMPLATE ALREADY CREATED, SKIPPING" )
250250 elif os .path .exists (os .path .join (output_dir , fsid )):
251251 print ("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:" )
@@ -254,8 +254,8 @@ def run(command, env={}, ignore_errors=False):
254254 else :
255255 print (cmd )
256256 run (cmd )
257-
258- if ( 'longitudinal' in args .steps ) :
257+
258+ if 'longitudinal' in args .steps :
259259 for tp in timepoints :
260260 # longitudinally process all timepoints
261261 fsid = "sub-%s" % subject_label
@@ -271,7 +271,7 @@ def run(command, env={}, ignore_errors=False):
271271 print ("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:" )
272272 print (cmd )
273273 run (cmd )
274- elif os .path .isfile (os .path .join (output_dir , tp + ".long." + fsid , "mri/aseg.mgz " )):
274+ elif os .path .isfile (os .path .join (output_dir , tp + ".long." + fsid , "label/BA_exvivo.thresh.ctab " )):
275275 print ("SUBJECT ALREADY SEGMENTED, SKIPPING" )
276276 else :
277277 print (cmd )
@@ -328,6 +328,8 @@ def run(command, env={}, ignore_errors=False):
328328 print ("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:" )
329329 print (cmd )
330330 run (cmd )
331+ elif os .path .isfile (os .path .join (output_dir , fsid , "label/BA_exvivo.thresh.ctab" )):
332+ print ("SUBJECT ALREADY SEGMENTED, SKIPPING" )
331333 elif os .path .exists (os .path .join (output_dir , fsid )):
332334 print ("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:" )
333335 print (resume_cmd )
@@ -384,6 +386,8 @@ def run(command, env={}, ignore_errors=False):
384386 print ("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:" )
385387 print (cmd )
386388 run (cmd )
389+ elif os .path .isfile (os .path .join (output_dir , fsid , "label/BA_exvivo.thresh.ctab" )):
390+ print ("SUBJECT ALREADY SEGMENTED, SKIPPING" )
387391 elif os .path .exists (os .path .join (output_dir , fsid )):
388392 print ("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:" )
389393 print (resume_cmd )
0 commit comments