def get_laus125_ts_labels():
    laus125_labels_lh = [
        line.rstrip()
        for line in open(op.join(root_path, 'fmri_laus125_lh.txt'))
    ]
    laus125_labels_rh = [
        line.rstrip()
        for line in open(op.join(root_path, 'fmri_laus125_rh.txt'))
    ]
    laus125_labels_lh = [s + '-lh' for s in laus125_labels_lh]
    laus125_labels_rh = [s + '-rh' for s in laus125_labels_rh]
    laus125_labels = np.array(laus125_labels_lh + laus125_labels_rh)
    utils.write_list_to_file(laus125_labels,
                             op.join(root_path, 'linda_laus125_order.txt'))
    return laus125_labels
Ejemplo n.º 2
0
def run_on_subjects(args, main_func, subjects_itr=None, subject_func=None):
    if subjects_itr is None:
        subjects_itr = args.subject
    subjects_flags, subjects_errors = {}, {}
    args = init_args(args)
    for tup in subjects_itr:
        subject = get_subject(tup, subject_func)
        utils.make_dir(op.join(MMVT_DIR, subject, 'mmvt'))
        remote_subject_dir = utils.build_remote_subject_dir(
            args.remote_subject_dir, subject)
        logging.info(args)
        print(
            '****************************************************************')
        print('subject: {}, atlas: {}'.format(subject, args.atlas))
        print('remote dir: {}'.format(remote_subject_dir))
        print(
            '****************************************************************')
        os.environ['SUBJECT'] = subject
        flags = dict()
        try:
            # if utils.should_run(args, 'prepare_subject_folder'):
            # I think we always want to run this
            # *) Prepare the local subject's folder
            flags['prepare_subject_folder'] = prepare_subject_folder(
                subject, remote_subject_dir, args)
            if not flags['prepare_subject_folder'] and not args.ignore_missing:
                ans = input('Do you wish to continue (y/n)? ')
                if not au.is_true(ans):
                    continue
            flags['prepare_subject_folder'] = True

            flags = main_func(tup, remote_subject_dir, args, flags)
            subjects_flags[subject] = flags
        except:
            subjects_errors[subject] = traceback.format_exc()
            print('Error in subject {}'.format(subject))
            print(traceback.format_exc())

    errors = defaultdict(list)
    ret = True
    good_subjects, bad_subjects = [], []
    logs_fol = utils.make_dir(op.join(MMVT_DIR, subject, 'logs'))
    logging.basicConfig(filename=op.join(logs_fol, 'preproc.log'),
                        level=logging.DEBUG)
    for subject, flags in subjects_flags.items():
        print('subject {}:'.format(subject))
        logging.info('subject {}:'.format(subject))
        for flag_type, val in flags.items():
            print('{}: {}'.format(flag_type, val))
            logging.info('{}: {}'.format(flag_type, val))
            if not val:
                errors[subject].append(flag_type)
    if len(errors) > 0:
        ret = False
        print('Errors:')
        logging.info('Errors:')
        for subject, error in errors.items():
            print('{}: {}'.format(subject, error))
            logging.info('{}: {}'.format(subject, error))
    for subject in subjects_flags.keys():
        if len(errors[subject]) == 0:
            good_subjects.append(subject)
        else:
            bad_subjects.append(subject)
    print('Good subjects:\n {}'.format(good_subjects))
    logging.info('Good subjects:\n {}'.format(good_subjects))
    print('Bad subjects:\n {}'.format(bad_subjects))
    logging.info('Good subjects:\n {}'.format(good_subjects))
    utils.write_list_to_file(
        good_subjects, op.join(utils.get_logs_fol(), 'good_subjects.txt'))
    utils.write_list_to_file(bad_subjects,
                             op.join(utils.get_logs_fol(), 'bad_subjects.txt'))
    return ret