def perm_hist(subj): conf = AnalysisConfiguration() data_dir = os.environ.get('DATA_DIR') or '/home/user/data' sub_dir = _opj(data_dir,conf.study_name,'sub{:0>3d}'.format(subj)) directory = _opj(data_dir,'LP/sub{:0>3d}/results/'.format(subj)) print conf.dir_name() for pair in conf.conditions_to_compare: #print _opj(directory,conf.dir_name(),'{}*{}{}*.p'.format(conf.mask_name,pair[0],pair[1])) files = sorted(glob(_opj(directory,conf.dir_name(),'{}*{}{}*.p'.format(conf.mask_name,pair[0],pair[1])))) plt.figure() plt.subplot(211) plt.title('sub{:0>3d}-{}{}'.format(subj,pair[0],pair[1])) print pair, " ", len(files) all_maps = [] for f in files[:-1]: f_h = file(f,'r') m = pickle.load(f_h) all_maps.append(m) if 'perm' in f: color = 'black' line_width = 1 else: color = 'crimson' line_width = 2 plt.hist(np.transpose(m),bins=20,histtype='step',color=[color], lw = line_width) perms = vstack(all_maps) real_f = files[-1] f_h = file(real_f,'r') real_map = pickle.load(f_h) color = 'crimson' line_width = 2 plt.hist(np.transpose(real_map),bins=20,histtype='step',color=[color], lw = line_width) percentiles = np.zeros((1,len(real_map.samples[0]))) for i,vox in enumerate(real_map.samples[0]): percentiles[0,i]=percentileofscore(perms[:,i].samples.flat,vox) plt.subplot(212) print len(percentiles[0]) plt.hist(percentiles[0],bins=20,histtype='step') real_map.samples=percentiles nii = real_f.replace("_sl_map.p", "-acc.nii.gz") nii_file = nib.load(nii) perc_results = map2nifti(real_map, imghdr=nii_file.header) perc_nii_filename =real_f.replace("_sl_map.p", "-percentiles_sub{:0>3d}.nii.gz".format(subj)) perc_results.to_filename(perc_nii_filename) thr_prc_filename = perc_nii_filename.replace(".nii.gz","_p0.01.nii.gz") thr = fsl.maths.Threshold(in_file=perc_nii_filename, thresh=100, out_file=thr_prc_filename) thr.run() mni_thr_filename = thr_prc_filename.replace(".nii.gz","_mni.nii.gz") apply_warp(sub_dir,thr_prc_filename, mni_thr_filename) plt.show() #plt.savefig('/tmp/sub{:0>3d}_{}{}'.format(subj,pair[0],pair[1])) raw_input()
def main(): conf = AnalysisConfiguration() data_dir = os.environ.get('DATA_DIR') or '/home/user/data' op = OpenFMRIData(data_dir, conf.study_name) analyzer = OpenFMRIAnalyzer(op, conf) all_subject_dirs = op.all_subjects_dirs_with_raw() for subject in all_subject_dirs: analyzer.extract_brain(subject) for subject in all_subject_dirs: analyzer.anatomical_registration(subject) for subject in all_subject_dirs: #for task in conf.mvpa_tasks: #subject.remove_volumes_from_model(1, "", task, conf.num_of_volumes_to_delete) analyzer.motion_correction(subject) analyzer.functional_registration(subject) if conf.func_seg: analyzer.functional_segmentation(subject) else: analyzer.segmentation(subject) analyzer.generate_functional_gm_masks(subject) #analyzer.warp_standard_mask(subject) for subject in all_subject_dirs: # DO SL out_dir = _opj(subject.path(),'results',conf.dir_name()) if not os.path.exists(out_dir): os.makedirs(out_dir) run_searchlight(op, subject, conf, out_dir) # run_searchlight(op.study_dir(), subject.subcode(), mask_name, k, [['G1','G4']], out_dir,flavor) #Group Level output_dir = _opj(op.study_dir(), 'results', "{}".format(conf.dir_name())) if not os.path.exists(output_dir): os.makedirs(output_dir) files = glob(_opj(op.study_dir(), "**", 'results', conf.dir_name(), '*acc_mni.nii.gz')) print files generate_group_level_map( files, output_dir)
def main(): conf = AnalysisConfiguration() data_dir = os.environ.get('DATA_DIR') or '/home/daniel/fsl-analysis/data' op = OpenFMRIData(data_dir, conf.study_name) analyzer = OpenFMRIAnalyzer(op, conf) all_subject_dirs = op.all_subjects_dirs_with_raw() for subject in all_subject_dirs: analyzer.extract_brain(subject) for subject in all_subject_dirs: analyzer.anatomical_registration(subject) for subject in all_subject_dirs: #for task in conf.mvpa_tasks: #subject.remove_volumes_from_model(1, "", task, conf.num_of_volumes_to_delete) analyzer.motion_correction(subject) analyzer.functional_registration(subject) if conf.func_seg: analyzer.functional_segmentation(subject) else: analyzer.segmentation(subject) analyzer.generate_functional_gm_masks(subject) #analyzer.warp_standard_mask(subject) for subject in all_subject_dirs: # DO SL out_dir = _opj(subject.path(),'results',conf.dir_name()) if not os.path.exists(out_dir): os.makedirs(out_dir) run_searchlight(op, subject, conf, out_dir)