def comparedWithRmsd(fixed_rmsd_xcms): def calculateAUC(scores): scores["native_like"] = scores.rmsd.apply( lambda r: 1 if r < 3 else 0) fpr, tpr, thresholds = metrics.roc_curve(scores.native_like, scores.spearmanr, pos_label=1) return metrics.auc(fpr, tpr) ''' # averaged spearmanr print( "################################################################################") ave_spearmanr = fixed_rmsd_xcms.groupby("query").apply( lambda g: g[["spearmanr", "rmsd"]].mean()) print("AUC:", calculateAUC(ave_spearmanr)) pprint(ave_spearmanr.corr()) pprint(pd.Series(minepy.minestats(ave_spearmanr.rmsd, ave_spearmanr.spearmanr))) # ave_spearmanr.plot(kind='scatter', x='rmsd', y="spearmanr") # plt.savefig('rmsd_ave_spearmanr.png') # tc_times_ps weighted spearmanr def weighted(g): score = g["tc_times_ps"].dot(g["spearmanr"]) / g[ "tc_times_ps"].sum() return pd.DataFrame( {"rmsd": g["rmsd"].tolist()[0], "spearmanr": score}, index=[0]) # tc_times_ps weighted spearmanr print( "################################################################################") weighted_spearmanr = fixed_rmsd_xcms.groupby("query").apply( weighted) print("AUC:", calculateAUC(weighted_spearmanr)) pprint(weighted_spearmanr.corr()) pprint(pd.Series(minepy.minestats(weighted_spearmanr.rmsd, weighted_spearmanr.spearmanr))) # weighted_spearmanr.plot(kind='scatter', x='rmsd', y="spearmanr") # plt.savefig('rmsd_weighted_spearmanr.png') ''' # tc_times_ps ranked spearmanr print( "################################################################################") ranked_spearmanr = fixed_rmsd_xcms.groupby("query").apply( lambda g: g.sort_values("tc_times_ps", ascending=False).iloc[0][["spearmanr", "rmsd"]]) print("AUC:", calculateAUC(ranked_spearmanr)) print pprint(ranked_spearmanr.corr()) print pprint(pd.Series(minepy.minestats(ranked_spearmanr.rmsd, ranked_spearmanr.spearmanr)))
def doCorrelation(vectorX, vectorY): corrList_=[] #from minepy import minepy from scipy import stats import minepy ## do not chnage alpha and c in the following line minedValue = minepy.minestats(vectorX, vectorY, alpha=0.6, c=15) spearmanValue = stats.spearmanr(vectorX, vectorY) pearsonValue = stats.pearsonr(vectorX, vectorY) corrList_ =[pearsonValue[0] , pearsonValue[1], spearmanValue[0], spearmanValue[1], minedValue['mic'], minedValue['nonlinearity']] return corrList_
def doCorrelation(vectorX, vectorY): corrList_ = [] #from minepy import minepy from scipy import stats import minepy ## do not chnage alpha and c in the following line minedValue = minepy.minestats(vectorX, vectorY, alpha=0.6, c=15) spearmanValue = stats.spearmanr(vectorX, vectorY) pearsonValue = stats.pearsonr(vectorX, vectorY) corrList_ = [ pearsonValue[0], pearsonValue[1], spearmanValue[0], spearmanValue[1], minedValue['mic'], minedValue['nonlinearity'] ] return corrList_
def performMIC(combined_list, l1, l2): print (l1, l2, len(combined_list)) outfile2 = open(prots+"_mic"+".csv", 'w') outfile2.writelines('first,' + 'second,' + 'mic,' + '\n') for counter1 in range(0, l1-1): for counter2 in range(l1, len(combined_list)-1): mine_result = minestats(combined_list[counter1],combined_list[counter2],alpha=0.6, c=15) print (mine_result.items()) outfile2.writelines(str(counter1)+','+str(counter2-l1)+','+str(mine_result['mic'])) outfile2.write('\n') outfile2.flush() outfile2.close()
def correlation(df): tc_times_ps = df.Tc * df.ps_score print("Maximal information-based stats") pprint(minepy.minestats(tc_times_ps, df['spearmanr']))
sph_obs = int(np.round(1/(tsol[1]-tsol[0]))) ts_data = sol[:,[0,2,4,6]] ts_pre_fix = np.copy(ts_data) ts_data = np.zeros([np.floor(sph*len(ts_data)/sph_obs),cellcount]) for i in range(len(ts_data)): ts_data[i,:] = np.sum(ts_pre_fix[ int(i*sph_obs/sph):int((1+i)*sph_obs/sph),:],axis=0) mic = np.zeros([cellcount**2,4]) aa = [range(cellcount),range(cellcount)] inds = list(itertools.product(*aa)) for i in xrange(len(inds)): [c1,c2] = inds[i] ts1 = ts_data[:,c1] ts2 = ts_data[:,c2] mic[i,:] = [c1, c2, mp.minestats(ts1,ts2)['mic'], stats.linregress(ts1,ts2)[2]] hmp = np.zeros([cellcount,cellcount]) hmp2 = np.copy(hmp) for i in range(len(mic)): ind1 = mic[i][0] ind2 = mic[i][1] hmp[ind1,ind2] = mic[i][2] hmp2[ind1,ind2] = mic[i][3] np.fill_diagonal(hmp,0) plt.figure(2) plt.pcolormesh(hmp2) plt.colorbar()