def pearson_correlation(datadir, outdir, usemask=True, excludef='', exclude_idx=-1): slidir = datadir + os.path.sep + au.slices_str() subjsfile = datadir + os.path.sep + au.subjects_str() labelsfile = datadir + os.path.sep + au.labels_str() lst = os.listdir(slidir) n = au.count_match(lst, au.data_str() + '_' + au.slice_regex()) exclude_log = '' if exclude_idx > -1: exclude_log = ' excluding subject ' + str(exclude_idx) au.log.info('Calculating correlation of ' + slidir + os.path.sep + au.data_str() + '_' + au.slice_regex() + exclude_log) for i in range(n): slino = au.zeropad(i) dataf = slidir + os.path.sep + au.data_str() + '_' + au.slice_str( ) + '_' + slino + au.ext_str() maskf = slidir + os.path.sep + au.mask_str() + '_' + au.slice_str( ) + '_' + slino + au.ext_str() outf = outdir + os.path.sep + au.pearson_str() + '_' + au.slice_str( ) + '_' + slino if exclude_idx > -1: outf += '_' + au.excluded_str() + str(exclude_idx) + au.ext_str() else: outf += au.ext_str() if not os.path.isfile(dataf): au.log.error('Could not find ' + dataf) continue if not usemask: maskf = '' try: measure_pearson(dataf, labelsfile, outf, maskf, excludef, exclude_idx) except: au.log.error( 'pearson_correlation: Error measuring correlation on ' + dataf) au.log.error("Unexpected error: ", sys.exc_info()[0]) exit(1)
def pearson_correlation (datadir, outdir, usemask=True, excludef='', exclude_idx=-1): slidir = datadir + os.path.sep + au.slices_str() subjsfile = datadir + os.path.sep + au.subjects_str() labelsfile = datadir + os.path.sep + au.labels_str() lst = os.listdir(slidir) n = au.count_match(lst, au.data_str() + '_' + au.slice_regex()) exclude_log = '' if exclude_idx > -1: exclude_log = ' excluding subject ' + str(exclude_idx) au.log.info ('Calculating correlation of ' + slidir + os.path.sep + au.data_str() + '_' + au.slice_regex() + exclude_log) for i in range(n): slino = au.zeropad(i) dataf = slidir + os.path.sep + au.data_str() + '_' + au.slice_str() + '_' + slino + au.ext_str() maskf = slidir + os.path.sep + au.mask_str() + '_' + au.slice_str() + '_' + slino + au.ext_str() outf = outdir + os.path.sep + au.pearson_str() + '_' + au.slice_str() + '_' + slino if exclude_idx > -1: outf += '_' + au.excluded_str() + str(exclude_idx) + au.ext_str() else: outf += au.ext_str() if not os.path.isfile(dataf): au.log.error('Could not find ' + dataf) continue if not usemask: maskf = '' try: measure_pearson(dataf, labelsfile, outf, maskf, excludef, exclude_idx) except: au.log.error('pearson_correlation: Error measuring correlation on ' + dataf) au.log.error("Unexpected error: ", sys.exc_info()[0] ) exit(1)
outf_labels = outdir + os.path.sep + au.labels_str() np.savetxt(outf_subjs, subjs, fmt='%s') np.savetxt(outf_labels, subjlabels, fmt='%i') #creating folder for slices slidir = outdir + os.path.sep + au.slices_str() if not (os.path.exists(slidir)): os.mkdir(slidir) #slice the volumes #creating group and mask slices pre.slice_and_merge(outf_subjs, outf_labels, chkf, outdir, maskf) #creating measure output folder if measure == 'pea': measure_fname = au.pearson_str() elif measure == 'bat': measure_fname = au.bhattacharyya_str() elif measure == 'ttest': measure_fname = au.ttest_str() #checking the leave parameter if leave > (subjsnum - 1): au.log.warning('aizkolari_measure: the leave (-l) argument value is ' + str(leave) + ', bigger than the last index of subject: ' + str(subjsnum - 1) + '. Im setting it to -1.') leave = -1 #reading exclusion list excluded = parse_exclude_list(excluf, leave)
outf_labels = outdir + os.path.sep + au.labels_str() np.savetxt(outf_subjs, subjs, fmt='%s') np.savetxt(outf_labels, subjlabels, fmt='%i') #creating folder for slices slidir = outdir + os.path.sep + au.slices_str() if not(os.path.exists(slidir)): os.mkdir(slidir) #slice the volumes #creating group and mask slices pre.slice_and_merge(outf_subjs, outf_labels, chkf, outdir, maskf) #creating measure output folder if measure == 'pea': measure_fname = au.pearson_str() elif measure == 'bat': measure_fname = au.bhattacharyya_str() elif measure == 'ttest': measure_fname = au.ttest_str() #checking the leave parameter if leave > (subjsnum - 1): au.log.warning('aizkolari_measure: the leave (-l) argument value is ' + str(leave) + ', bigger than the last index of subject: ' + str(subjsnum - 1) + '. Im setting it to -1.') leave = -1 #reading exclusion list excluded = parse_exclude_list (excluf, leave) #setting the output folder mdir extension mdir = outdir + os.path.sep + measure_fname