import numpy as np
import pandas as pd
from sklearn.metrics import roc_curve, auc
from HH import to_categorical,categorical_probas_to_classes,calculate_performace
import itertools
import matplotlib.pyplot as plt
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import average_precision_score
import matplotlib
import matplotlib as mpl
import itertools
lw=1
mpl.rcParams['font.sans-serif']='Times New Roman'
matplotlib.rcParams['xtick.direction'] = 'in'
matplotlib.rcParams['ytick.direction'] = 'in'
plt.subplot(121)
A = open('label_Fusion.csv')
B = open('probability_Fusion.csv')
label = pd.read_csv(A)
score_= pd.read_csv(B)
label = np.array(label)
score_= np.array(score_)
y_class = np.delete(label,[0,2],axis=1)
y_test_tmp = np.delete(label,[0,1],axis=1)
y_class = np.array(y_class)
y_test_tmp = np.array(y_test_tmp)
score= np.delete(score_,0,axis=1)
ytest = np.append(y_test_tmp,score,axis=1)
ytest_GTB=np.array(ytest,dtype=np.float)
fpr, tpr, _ = roc_curve(ytest_GTB[:,0], ytest_GTB[:,2])
roc_auc = auc(fpr, tpr)
plt.plot(fpr, tpr, color='blue',lw=lw,label='CTD+PseAAC+PsePSSM(AUC=0.9700)')

A = open('label_CTD.csv')
B = open('probability_CTD.csv')
label = pd.read_csv(A)
score_= pd.read_csv(B)
label = np.array(label)
score_= np.array(score_)
y_class = np.delete(label,[0,2],axis=1)
y_test_tmp = np.delete(label,[0,1],axis=1)
y_class = np.array(y_class)
y_test_tmp = np.array(y_test_tmp)
score= np.delete(score_,0,axis=1)
ytest = np.append(y_test_tmp,score,axis=1)
ytest_GTB=np.array(ytest,dtype=np.float)
fpr, tpr, _ = roc_curve(ytest_GTB[:,0], ytest_GTB[:,2])
roc_auc = auc(fpr, tpr)
plt.plot(fpr, tpr, color='red',lw=lw,label='CTD(AUC=0.9679)')

A = open('label_Pseaac.csv')
B = open('probability_Pseaac.csv')
label = pd.read_csv(A)
score_= pd.read_csv(B)
label = np.array(label)
score_= np.array(score_)
y_class = np.delete(label,[0,2],axis=1)
y_test_tmp = np.delete(label,[0,1],axis=1)
y_class = np.array(y_class)
y_test_tmp = np.array(y_test_tmp)
score= np.delete(score_,0,axis=1)
ytest = np.append(y_test_tmp,score,axis=1)
ytest_GTB=np.array(ytest,dtype=np.float)
fpr, tpr, _ = roc_curve(ytest_GTB[:,0], ytest_GTB[:,2])
roc_auc = auc(fpr, tpr)
plt.plot(fpr, tpr, color='darkorange',lw=lw,label='PseAAC(AUC=0.9531)')

A = open('label_PsePSSM.csv')
B = open('probability_PsePSSM.csv')
label = pd.read_csv(A)
score_= pd.read_csv(B)
label = np.array(label)
score_= np.array(score_)
y_class = np.delete(label,[0,2],axis=1)
y_test_tmp = np.delete(label,[0,1],axis=1)
y_class = np.array(y_class)
y_test_tmp = np.array(y_test_tmp)
score= np.delete(score_,0,axis=1)
ytest = np.append(y_test_tmp,score,axis=1)
ytest_GTB=np.array(ytest,dtype=np.float)
fpr, tpr, _ = roc_curve(ytest_GTB[:,0], ytest_GTB[:,2])
roc_auc = auc(fpr, tpr)
plt.plot(fpr, tpr, color='green',lw=lw,label='PsePSSM(AUC=0.9473)')

ax = plt.gca()
ax.spines['left'].set_linewidth(0.3)
ax.spines['right'].set_linewidth(0.3)
ax.spines['bottom'].set_linewidth(0.3)
ax.spines['top'].set_linewidth(0.3)
plt.xlim([-0.02, 1.02])
plt.ylim([-0.02, 1.05])
plt.xlabel('False positive rate')
plt.ylabel('Ture positive rate')
font = {'family': 'Times New Roman', 'weight': 'normal', 'size': 7}
legend = plt.legend(prop=font,loc="lower left")
plt.subplots_adjust(left=0.125, right=0.9, bottom=0.1, top=0.9,hspace=0.2, wspace=0.3)
fig_size=matplotlib.pyplot.gcf()
fig_size.set_size_inches(7,3.15)
plt.show
plt.subplot(122)
A = open('label_Fusion.csv')
B = open('probability_Fusion.csv')
label = pd.read_csv(A)
score_= pd.read_csv(B)
label = np.array(label)
score_= np.array(score_)
y_class = np.delete(label,[0,2],axis=1)
y_test_tmp = np.delete(label,[0,1],axis=1)
y_class = np.array(y_class)
y_test_tmp = np.array(y_test_tmp)
score= np.delete(score_,0,axis=1)
ytest = np.append(y_test_tmp,score,axis=1)
ytest_GTB=np.array(ytest,dtype=np.float)
fpr, tpr, _ = precision_recall_curve(ytest_GTB[:,0], ytest_GTB[:,2])
aupr1=average_precision_score(ytest_GTB[:,0], ytest_GTB[:,2])
plt.plot(fpr, tpr, color='blue',lw=lw,label='CTD+PseAAC+PsePSSM(AUPR=0.9252)')


A = open('label_CTD.csv')
B = open('probability_CTD.csv')
label = pd.read_csv(A)
score_= pd.read_csv(B)
label = np.array(label)
score_= np.array(score_)
y_class = np.delete(label,[0,2],axis=1)
y_test_tmp = np.delete(label,[0,1],axis=1)
y_class = np.array(y_class)
y_test_tmp = np.array(y_test_tmp)
score= np.delete(score_,0,axis=1)
ytest = np.append(y_test_tmp,score,axis=1)
ytest_GTB=np.array(ytest,dtype=np.float)
fpr, tpr, _ = precision_recall_curve(ytest_GTB[:,0], ytest_GTB[:,2])
aupr2=average_precision_score(ytest_GTB[:,0], ytest_GTB[:,2])
plt.plot(fpr, tpr, color='red',lw=lw,label='CTD(AUPR=0.9190)')

A = open('label_Pseaac.csv')
B = open('probability_Pseaac.csv')
label = pd.read_csv(A)
score_= pd.read_csv(B)
label = np.array(label)
score_= np.array(score_)
y_class = np.delete(label,[0,2],axis=1)
y_test_tmp = np.delete(label,[0,1],axis=1)
y_class = np.array(y_class)
y_test_tmp = np.array(y_test_tmp)
score= np.delete(score_,0,axis=1)
ytest = np.append(y_test_tmp,score,axis=1)
ytest_GTB=np.array(ytest,dtype=np.float)
fpr, tpr, _ = precision_recall_curve(ytest_GTB[:,0], ytest_GTB[:,2])
aupr3=average_precision_score(ytest_GTB[:,0], ytest_GTB[:,2])
plt.plot(fpr, tpr, color='darkorange',lw=lw,label='PseAAC(AUPR=0.8871)')

A = open('label_PsePSSM.csv')
B = open('probability_PsePSSM.csv')
label = pd.read_csv(A)
score_= pd.read_csv(B)
label = np.array(label)
score_= np.array(score_)
y_class = np.delete(label,[0,2],axis=1)
y_test_tmp = np.delete(label,[0,1],axis=1)
y_class = np.array(y_class)
y_test_tmp = np.array(y_test_tmp)
score= np.delete(score_,0,axis=1)
ytest = np.append(y_test_tmp,score,axis=1)
ytest_GTB=np.array(ytest,dtype=np.float)
fpr, tpr, _ = precision_recall_curve(ytest_GTB[:,0], ytest_GTB[:,2])
aupr4=average_precision_score(ytest_GTB[:,0], ytest_GTB[:,2])
plt.plot(fpr, tpr, color='green',lw=lw,label='PsePSSM(AUPR=0.8847)')
ax = plt.gca()
ax.spines['left'].set_linewidth(0.3)
ax.spines['right'].set_linewidth(0.3)
ax.spines['bottom'].set_linewidth(0.3)
ax.spines['top'].set_linewidth(0.3)
plt.xlim([-0.03, 1.02])
plt.ylim([0.22, 1.03])
plt.xlabel('Recall')
plt.ylabel('Precision')
font = {'family': 'Times New Roman', 'weight': 'normal', 'size': 7}
legend = plt.legend(prop=font,loc="lower right=0.75")
plt.subplots_adjust(left=0.125, right=0.9, bottom=0.1, top=0.9,hspace=0.2, wspace=0.3)
fig_size=matplotlib.pyplot.gcf()
fig_size.set_size_inches(7,3.15)
plt.show
plt.savefig(r'fusion_auc_pr.svg',format='svg',dpi=2000)