diff --git a/run.py b/run.py index db32e42..36123c5 100755 --- a/run.py +++ b/run.py @@ -111,7 +111,7 @@ def run(command, env={}, ignore_errors=False): if glob(os.path.join(args.bids_dir, "sub-*", "ses-*")): subjects = [subject_dir.split("-")[-1] for subject_dir in subject_dirs] for subject_label in subjects: - session_dirs = glob(os.path.join(args.bids_dir,"sub-%s"%subject_label,"ses-*")) + session_dirs = glob(os.path.join(args.bids_dir, "sub-%s"%subject_label, "ses-*")) sessions = [os.path.split(dr)[-1].split("-")[-1] for dr in session_dirs] n_valid_sessions = 0 for session_label in sessions: @@ -161,27 +161,27 @@ def run(command, env={}, ignore_errors=False): for subject_label in subjects_to_analyze: if glob(os.path.join(args.bids_dir, "sub-%s"%subject_label, "ses-*")): T1s = glob(os.path.join(args.bids_dir, - "sub-%s"%subject_label, - "ses-*", - "anat", - "%s_T1w.nii*"%acq_tpl)) + "sub-%s"%subject_label, + "ses-*", + "anat", + "%s_T1w.nii*"%acq_tpl)) sessions = set([os.path.normpath(t1).split(os.sep)[-3].split("-")[-1] for t1 in T1s]) if args.session_label: sessions = sessions.intersection(args.session_label) if len(sessions) > 0 and longitudinal_study == True: timepoints = ["sub-%s_ses-%s"%(subject_label, session_label) for session_label in sessions] - if ('cross-sectional' in args.steps): + if 'cross-sectional' in args.steps: # Running each session separately, prior to doing longitudinal pipeline for session_label in sessions: T1s = glob(os.path.join(args.bids_dir, - "sub-%s"%subject_label, - "ses-%s"%session_label, - "anat", - "%s_T1w.nii*"%acq_tpl)) + "sub-%s"%subject_label, + "ses-%s"%session_label, + "anat", + "%s_T1w.nii*"%acq_tpl)) input_args = "" for T1 in T1s: - if (round(max(nibabel.load(T1).header.get_zooms()),1) < 1.0 and args.hires_mode == "auto") or args.hires_mode == "enable": + if (round(max(nibabel.load(T1).header.get_zooms()), 1) < 1.0 and args.hires_mode == "auto") or args.hires_mode == "enable": input_args += " -hires" input_args += " -i %s"%T1 @@ -189,8 +189,8 @@ def run(command, env={}, ignore_errors=False): "ses-%s"%session_label, "anat", "*%s_T2w.nii*"%acq_t2)) FLAIRs = glob(os.path.join(args.bids_dir, "sub-%s"%subject_label, - "ses-%s"%session_label, "anat", - "*%s_FLAIR.nii*"%acq_t2)) + "ses-%s"%session_label, "anat", + "*%s_FLAIR.nii*"%acq_t2)) if args.refine_pial == "T2": for T2 in T2s: if max(nibabel.load(T2).header.get_zooms()) < 1.2: @@ -219,7 +219,7 @@ def run(command, env={}, ignore_errors=False): print("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:") print(cmd) run(cmd) - elif os.path.isfile(os.path.join(output_dir, fsid, "mri/aseg.mgz")): + elif os.path.isfile(os.path.join(output_dir, fsid, "label/BA_exvivo.thresh.ctab")): print("SUBJECT ALREADY SEGMENTED, SKIPPING") elif os.path.exists(os.path.join(output_dir, fsid)): print("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:") @@ -228,8 +228,8 @@ def run(command, env={}, ignore_errors=False): else: print(cmd) run(cmd) - - if ('template' in args.steps): + + if 'template' in args.steps: # creating a subject specific template input_args = " ".join(["-tp %s"%tp for tp in timepoints]) fsid = "sub-%s"%subject_label @@ -240,12 +240,12 @@ def run(command, env={}, ignore_errors=False): stages, args.n_cpus) - if os.path.isfile(os.path.join(output_dir, fsid,"scripts/IsRunning.lh+rh")): + if os.path.isfile(os.path.join(output_dir, fsid, "scripts/IsRunning.lh+rh")): rmtree(os.path.join(output_dir, fsid)) print("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:") print(cmd) run(cmd) - elif os.path.isfile(os.path.join(output_dir, fsid, "mri/aseg.mgz")): + elif os.path.isfile(os.path.join(output_dir, fsid, "label/BA_exvivo.thresh.ctab")): print("TEMPLATE ALREADY CREATED, SKIPPING") elif os.path.exists(os.path.join(output_dir, fsid)): print("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:") @@ -254,8 +254,8 @@ def run(command, env={}, ignore_errors=False): else: print(cmd) run(cmd) - - if ('longitudinal' in args.steps): + + if 'longitudinal' in args.steps: for tp in timepoints: # longitudinally process all timepoints fsid = "sub-%s"%subject_label @@ -271,7 +271,7 @@ def run(command, env={}, ignore_errors=False): print("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:") print(cmd) run(cmd) - elif os.path.isfile(os.path.join(output_dir, tp + ".long." + fsid, "mri/aseg.mgz")): + elif os.path.isfile(os.path.join(output_dir, tp + ".long." + fsid, "label/BA_exvivo.thresh.ctab")): print("SUBJECT ALREADY SEGMENTED, SKIPPING") else: print(cmd) @@ -328,6 +328,8 @@ def run(command, env={}, ignore_errors=False): print("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:") print(cmd) run(cmd) + elif os.path.isfile(os.path.join(output_dir, fsid, "label/BA_exvivo.thresh.ctab")): + print("SUBJECT ALREADY SEGMENTED, SKIPPING") elif os.path.exists(os.path.join(output_dir, fsid)): print("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:") print(resume_cmd) @@ -384,6 +386,8 @@ def run(command, env={}, ignore_errors=False): print("DELETING OUTPUT SUBJECT DIR AND RE-RUNNING COMMAND:") print(cmd) run(cmd) + elif os.path.isfile(os.path.join(output_dir, fsid, "label/BA_exvivo.thresh.ctab")): + print("SUBJECT ALREADY SEGMENTED, SKIPPING") elif os.path.exists(os.path.join(output_dir, fsid)): print("SUBJECT DIR ALREADY EXISTS (without IsRunning.lh+rh), RUNNING COMMAND:") print(resume_cmd)