|
10 | 10 | import cobra as cb
|
11 | 11 | import sklearn.metrics
|
12 | 12 | from matplotlib.colors import ListedColormap
|
13 |
| -from adjustText import adjust_text |
| 13 | +#from adjustText import adjust_text |
14 | 14 | from matplotlib.patches import Rectangle
|
15 | 15 | import genericLib as gL
|
16 | 16 |
|
|
105 | 105 | index_commonFBAvsRAS=df_concFBA.index.intersection(df_concRAS.index)
|
106 | 106 | indexCommon=index_commonMETvsFBA.intersection(index_commonMETvsRAS)
|
107 | 107 |
|
108 |
| -#save all the datasets of concordances |
109 |
| -#df_concFBA.to_csv(os.path.join(OUTDIR,"df_concFFD.csv")) |
110 |
| -##df_concRAS.to_csv(os.path.join(OUTDIR,"df_concRAS.csv")) |
111 |
| -#df_met.to_csv(os.path.join(OUTDIR,"df_concRPS.csv")) |
112 |
| - |
113 | 108 | # Create the indexes of all the reactions in the common datasets
|
114 | 109 | indexUnion=df_met.index.union(df_concRAS.index).union(df_concFBA.index)
|
115 | 110 |
|
|
169 | 164 | valori2.extend([-el for el in valori2])
|
170 | 165 |
|
171 | 166 | dfConcFRD_RASvsMET.loc[reaction,str(ind)]=sklearn.metrics.cohen_kappa_score(valori1,valori2,labels=[-1,0,1],weights="linear",sample_weight=None)
|
172 |
| - |
173 |
| - #for reaction in index_commonFBAvsRAS: |
174 |
| - # valori1=list(df_concFBA2.loc[reaction,:].values) |
175 |
| - # valori2=list(df_concRAS3.loc[reaction,:].values) |
176 |
| - # valori1.extend([-el for el in valori1]) |
177 |
| - # valori2.extend([-el for el in valori2]) |
178 |
| - |
179 |
| -# dfConcFRD_RASvsFBA.loc[reaction,str(ind)]=sklearn.metrics.cohen_kappa_score(valori1,valori2,labels=##[-1,0,1],weights="linear",sample_weight=None) |
180 |
| - |
| 167 | + |
181 | 168 |
|
182 | 169 | #######################################àà
|
183 | 170 | #kappa true
|
|
197 | 184 |
|
198 | 185 | dfConcRASvsMET.loc[reaction,:]=sklearn.metrics.cohen_kappa_score(valori1,valori2,labels=[-1,0,1],weights="linear",sample_weight=None)
|
199 | 186 |
|
200 |
| -#for reaction in index_commonFBAvsRAS: |
201 |
| -# valori1=list(df_concFBA2.loc[reaction,:].values) |
202 |
| -# valori2=list(df_concRAS2.loc[reaction,:].values) |
203 |
| -# valori1.extend([-el for el in valori1]) |
204 |
| -# valori2.extend([-el for el in valori2]) |
205 |
| - |
206 |
| -# dfConcRASvsFBA.loc[reaction,:]=sklearn.metrics.cohen_kappa_score(valori1,valori2,labels=[-1,0,1],weights="linear",sample_weight=None) |
207 |
| - |
208 | 187 | ###############################Plot of Cohen distribution (random vs experiment)
|
209 | 188 | #Cumulative distribution
|
210 | 189 | ecdfRPSvsFBA=ECDF(dfConcFRD_FBAvsMET.values.ravel())
|
211 | 190 | ecdfRPSvsFBA_result=ECDF(dfConcMETvsFBA["METvsFBA"].values)
|
212 | 191 | ecdfRASvsMET=ECDF(dfConcFRD_RASvsMET.values.ravel())
|
213 | 192 | ecdfRASvsMET_result=ECDF(dfConcRASvsMET["RASvsMET"].values)
|
214 | 193 |
|
215 |
| - |
216 |
| -#print(kstest(dfConcFRD_FBAvsMET.values.ravel(),dfConcMETvsFBA["METvsFBA"].values)) |
217 |
| -#print(kstest(dfConcFRD_RASvsMET.values.ravel(),dfConcRASvsMET["RASvsMET"].values)) |
218 |
| -#print(kstest(dfConcFRD_RASvsFBA.values.ravel(),dfConcRASvsFBA["RASvsFBA"].values)) |
219 |
| - |
220 | 194 | #####figure of cumulative distributions
|
221 | 195 | #engro2
|
222 | 196 | fig, ax=plt.subplots(1,1,figsize=(20, 10))
|
|
238 | 212 | fig.savefig(os.path.join(FIGUREDIR, "qqplotEngro2.png"),transparent=False,format="png")
|
239 | 213 |
|
240 | 214 |
|
241 |
| -######## Cumulative distribution |
242 |
| -#fig, ax=plt.subplots(1, 1, figsize=(30, 15)) |
243 |
| - |
244 |
| -#ax.plot(ecdfRPSvsFBA.x, ecdfRPSvsFBA.y,"black",label="Random") |
245 |
| -#ax.plot(ecdfRPSvsFBA_result.x, ecdfRPSvsFBA_result.y,"red",label="ENGRO2") |
246 |
| -#ax.legend() |
247 |
| -#ax.grid() |
248 |
| - |
249 |
| -#ax[1].plot(ecdfRASvsMET.x, ecdfRASvsMET.y,"black",label="Random") |
250 |
| -#ax[1].plot(ecdfRASvsMET_result.x, ecdfRASvsMET_result.y,"red",label="ENGRO2") |
251 |
| - |
252 |
| -#ax.set_xlim([-1,1]) |
253 |
| -#ax.set_xlim([-1,1]) |
254 |
| -#ax.set_ylim([0,1]) |
255 |
| -#ax[1].set_ylim([0,1]) |
256 |
| -#ax[0].grid() |
257 |
| -#ax[1].grid() |
258 |
| -#ax.set_xlabel("RPS vs FFD",fontsize=40) |
259 |
| -#ax[1].set_xlabel("Cohen",fontsize=25) |
260 |
| -#ax[0].set_title("Distribution RPS vs FBA",fontsize=25) |
261 |
| -#ax[1].set_title("Distribution RPS vs MET",fontsize=25) |
262 |
| - |
263 |
| -#ax.tick_params(axis="x", labelsize=30) |
264 |
| -#ax.tick_params(axis="y", labelsize=30) |
265 |
| -#ax.legend(loc=2, prop={'size': 40}) |
266 |
| - |
267 |
| -#fig.savefig(os.path.join(FIGUREDIR, "prova.png"),transparent=False,format="png") |
268 | 215 | ##########################################fdr correction
|
269 | 216 | ############pvalues MET vs FBA
|
270 | 217 | dfConcMETvsFBA=dfConcMETvsFBA.sort_values(by=dfConcMETvsFBA.columns[0],ascending=True)
|
|
298 | 245 | for el in dfConcRASvsMET.index:
|
299 | 246 | dict_pvaluesRASvsMET[el]=res[i]
|
300 | 247 | i=i+1
|
301 |
| -#print(dict_pvaluesRASvsMET) |
302 |
| - |
303 |
| -#print("RASvsMET") |
304 |
| -#k=0 |
305 |
| -#for el,reaction in zip(res,dfConcRASvsMET.index): |
306 |
| -# if el==True: |
307 |
| -# print(reaction,dfConcRASvsMET.loc[reaction,"RASvsMET"]) |
308 |
| - |
309 |
| -##############pvalues MET vs FBA |
310 |
| -#dfConcRASvsFBA=dfConcRASvsFBA.sort_values(by=dfConcRASvsFBA.columns[0],ascending=True) |
311 |
| -#valori=dfConcRASvsFBA.values |
312 |
| -#pvaluesRASvsFBA=[1-ecdfRASvsFBA(el[0]) for el in valori] |
313 |
| - |
314 |
| -#resultsRASvsFBA_correction=fdrcorrection(pvaluesRASvsFBA,0.05) |
315 |
| -#res=resultsRASvsFBA_correction[0] |
316 |
| - |
317 |
| -#print("RASvsFBA") |
318 |
| -#k=0 |
319 |
| -#for el,reaction in zip(res,dfConcRASvsFBA.index): |
320 |
| -# if el==True: |
321 |
| -# print(reaction,dfConcRASvsFBA.loc[reaction,"RASvsFBA"]) |
322 | 248 |
|
323 | 249 | ###################################
|
324 | 250 |
|
|
374 | 300 | if kappa_values.loc[r,'RPSvsRAS cohen']>=-1:
|
375 | 301 | kappa_values.loc[r,'RPSvsRAS pvalue']=1-ecdfRASvsMET(kappa_values.loc[r,'RPSvsRAS cohen'])
|
376 | 302 | kappa_values.loc[r,'RPSvsRAS adj-pvalue']=dict_pvaluesRASvsMET[r]
|
377 |
| - |
378 |
| - #if r in df_met2.index and r not in df_concRAS2.index: |
379 |
| - # kappa_values.loc[r,'RPSvsRAS cohen']=0 |
380 |
| - # kappa_values.loc[r,'RPSvsRAS spearman']=0 |
381 |
| - # kappa_values.loc[r,'RPSvsRAS pvalue']=0 |
382 | 303 |
|
383 | 304 | if r in df_concFBA2.index and r in df_concRAS2.index:
|
384 | 305 | list1=list(df_concFBA2.loc[r])
|
|
399 | 320 |
|
400 | 321 | ####
|
401 | 322 | kappa_values["Formula2"]=[str(el)+':'+str(dict_formule[el]) for el in kappa_values.index]
|
402 |
| -#kappa_values.index=[str(el)+':'+str(dict_formule[el]) for el in kappa_values.index] |
403 | 323 | kappa_values.fillna(-3,inplace=True) ## just the create a mask map for the next figure
|
404 | 324 |
|
405 | 325 | ##############################################################################
|
|
559 | 479 | for x,y,z in zip(df_cohen["RPSvsFBA "+name],df_cohen["RPSvsRAS "+name],df_cohen.index):
|
560 | 480 | if (x>=val1 and y>=-1) or (x<=-val1 and y<=-val2 and y>=-1):
|
561 | 481 | Texts.append(plt.text(x,y,z.split(':')[0],fontsize=15))
|
562 |
| -adjust_text(Texts)#,arrowprops=dict(arrowstyle="->", color='r', lw=0.5)) |
| 482 | +#adjust_text(Texts)#,arrowprops=dict(arrowstyle="->", color='r', lw=0.5)) |
563 | 483 | f.colorbar(im, ax=ax,orientation="horizontal")
|
564 | 484 | im.set_clim(-1,1)
|
565 | 485 |
|
|
580 | 500 | df_mean_RPS=df_met_mean2.loc[index]
|
581 | 501 | df_FBA=pd.DataFrame()
|
582 | 502 |
|
583 |
| -for datasetFBA,datasetRAS,test in zip(datasetsFBA,datasetsRAS,tests): |
584 | 503 | df_FBA[str(test[0])]=datasetFBA["median_"+test[0]]
|
585 | 504 | df_FBA[str(test[1])]=datasetFBA["median_"+test[1]]
|
586 | 505 |
|
|
0 commit comments