def calc_labels_avg(target_subject, hemi, atlas, fmri_fname, res_dir, cwd, overwrite=True, output_txt_fname='', output_sum_fname='', ret_files_name=False, **kargs): def get_labels_names(line): label_name = line.split()[4] label_nums = utils.find_num_in_str(label_name) label_num = label_nums[-1] if len(label_nums) > 0 else '' if label_num != '': name_len = label_name.find('_{}'.format(label_num)) + len(str(label_num)) + 1 label_name = '{}-{}'.format(label_name[:name_len], hemi) return label_name if output_txt_fname == '': output_txt_fname = op.join(res_dir, '{}_{}_{}.txt'.format(utils.namebase(fmri_fname), atlas, hemi)) if output_sum_fname == '': output_sum_fname = op.join(res_dir, '{}_{}_{}.sum'.format(utils.namebase(fmri_fname), atlas, hemi)) if not op.isfile(output_txt_fname) or not op.isfile(output_sum_fname) or overwrite: print('Running mri_segstats on {} ({})'.format(fmri_fname, utils.file_modification_time(fmri_fname))) utils.partial_run_script(locals(), cwd=cwd)(mri_segstats) if not op.isfile(output_txt_fname): raise Exception('The output file was not created!') labels_data = np.genfromtxt(output_txt_fname).T labels_names = utils.read_list_from_file(output_sum_fname, get_labels_names, 'rb') if ret_files_name: return labels_data, labels_names, output_txt_fname, output_sum_fname else: return labels_data, labels_names
def find_good_subjects_indices(all_subjects): good_subjects = utils.read_list_from_file( op.join(root_path, 'good_subjects.txt')) return [ ind for ind in range(len(all_subjects)) if all_subjects[ind] in good_subjects ]
def decode_subjects(subjects): for sub in subjects: if '*' in sub: subjects.remove(sub) subjects.extend([ utils.namebase(fol) for fol in glob.glob(op.join(SUBJECTS_DIR, sub)) ]) elif 'file:' in sub: subjects.remove(sub) subjects.extend(utils.read_list_from_file(sub[len('file:'):])) return subjects
def decode_subjects(subjects, remote_subject_dir=''): for sub in subjects: if '*' in sub: subjects.remove(sub) subjects.extend([ utils.namebase(fol) for fol in glob.glob(op.join(SUBJECTS_DIR, sub)) ]) if remote_subject_dir != '': for fol in glob.glob( op.join(remote_subject_dir.format(subject=sub))): start_ind = utils.namebase(remote_subject_dir).index( '{subject}') end_ind = re.search( '[-_,\.!?]', utils.namebase(fol)[start_ind:]).start() + start_ind subjects.append(utils.namebase(fol)[start_ind:end_ind]) subjects = list(set(subjects)) elif 'file:' in sub: subjects.remove(sub) subjects.extend(utils.read_list_from_file(sub[len('file:'):])) return subjects