def crop_t2_star_pipeline(path, box_size=75):
    """
    Pretreatment pipeline croping the t2star files from a dataset around the spinal cord and both croped t2star and gray matter manual segmentation to a 75*75 squared image

    :param path: path to the data
    """

    for subject_dir in os.listdir(path):
        if os.path.isdir(path + subject_dir + '/'):
            t2star = ''
            sc_seg = ''
            seg_in = ''
            seg_in_name = ''
            manual_seg = ''
            manual_seg_name = ''
            mask_box = ''
            seg_in_croped = ''
            manual_seg_croped = ''

            for subject_file in os.listdir(path + '/' + subject_dir):
                file_low = subject_file.lower()
                if 't2star' in file_low or 'im' in file_low  in file_low and file_low not in 'mask' and 'seg' not in file_low and 'irp' not in file_low:
                    t2star = subject_file
                    t2star_path, t2star_name, ext = sct.extract_fname(t2star)
                elif 'square' in file_low and 'mask' in file_low and 'irp' not in file_low:
                    mask_box = subject_file
                elif 'seg' in file_low and 'in' not in file_low and 'croped' not in file_low and 'gm' not in file_low and 'irp' not in file_low:
                    sc_seg = subject_file
                elif 'gm' in file_low and 'croped.nii' not in file_low and 'irp' not in file_low:
                    manual_seg = subject_file
                    manual_seg_name = sct.extract_fname(manual_seg)[1]
                elif '_croped.nii' in file_low and 'gm' in file_low and 'irp' not in file_low:
                    manual_seg_croped = subject_file

            if t2star != '' and sc_seg != '':
                subject_path = path + '/' + subject_dir + '/'
                os.chdir(subject_path)
                ext = '.nii.gz'
                try:
                    if seg_in == '':
                        seg_in_name = t2star_name + '_seg_in'
                        seg_in = seg_in_name + ext
                        sct.run('sct_crop_image -i ' + t2star + ' -m ' + sc_seg + ' -b 0 -o ' + seg_in)

                    if mask_box == '':
                        mask_box = t2star_name + '_square_mask_from_sc_seg'+ext
                        sct.run('sct_create_mask -i ' + seg_in + ' -p centerline,' + sc_seg + ' -size ' + str(box_size) + ' -o ' + mask_box + ' -f box')

                    if seg_in_croped == '':
                        seg_in_im = Image(seg_in)
                        mask_im = Image(mask_box)
                        seg_in_im.crop_and_stack(mask_im, suffix='_croped', save=True)
                        seg_in_name += '_croped'
                        seg_in_im.setFileName(seg_in_name +ext)
                        seg_in_im = set_orientation(seg_in_im, 'IRP')

                    if manual_seg_croped == '':
                        manual_seg_im = Image(manual_seg)
                        mask_im = Image(mask_box)
                        manual_seg_im.crop_and_stack(mask_im, suffix='_croped', save=True)
                        manual_seg_name += '_croped'
                        manual_seg_im.setFileName(manual_seg_name+ext)
                        manual_seg_im = set_orientation(manual_seg_im, 'IRP')

                except Exception, e:
                    sct.printv('WARNING: an error occured ... \n ' + str(e), 1, 'warning')
                else:
                    print 'Done !'
                os.chdir('..')


# ------------------------------------------------------------------------------------------------------------------
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/msct_gmseg_utils.py/crop_t2_star_pipeline/swapped operands of `not in`