<jupyter_start><jupyter_text>The effect of a given mutation on antibody binding was represented by apparent affinity (avidity) relative to those for wild-type (WT) gp120, calculated with the formula ([(EC50_WT/EC50_mutant)/(EC50_WT for 2G12/EC50_mutant for 2G12)] × 100)<jupyter_code># Test data
VIH_final = pd.read_csv('../data/VIH_Test15.csv',index_col=0)

# original info data
vih_data = pd.read_csv("../data/HIV_escape_mutations.csv",sep="\t")

#vih_data["pred_ddg2EC50"] = vih_data["mCSM-AB_Pred"].apply(deltaG_to_Kd)*100
vih_original = vih_data.loc[vih_data["Mutation_type"]=="ORIGINAL"].copy()
vih_reverse = vih_data.loc[vih_data["Mutation_type"]=="REVERSE"]

#sort values to appedn to prediction data table
vih_original.loc[:,"mut_code"] = (vih_reverse["Chain"]+vih_reverse["Mutation"].str[1:]).values
vih_original.sort_values(by='mut_code',inplace=True)

vih_original["Mutation_original"] = vih_original["Mutation"].str[-1]+vih_original["Mutation"].str[1:-1]+vih_original["Mutation"].str[0]
vih_original.loc[(vih_original['Exptal'] <= 33 ),"mutation-effect"] = "decreased"
vih_original.loc[(vih_original['Exptal'] > 300 ),"mutation-effect"] = "increased"
vih_original.loc[(vih_original['Exptal'] < 300 )&(vih_original['Exptal'] > 33 ),"mutation-effect"] = "neutral"


vih_reverse.loc[(vih_reverse['Exptal'] <= 33 ),"mutation-effect"] = "decreased"
vih_reverse.loc[(vih_reverse['Exptal'] > 300 ),"mutation-effect"] = "increased"
vih_reverse.loc[(vih_reverse['Exptal'] < 300 )&(vih_reverse['Exptal'] > 33 ),"mutation-effect"] = "neutral"

#
#xgbr = XGBRegressor()
#xgbr.load_model(fname='xgb_final_400F_smote_032019.sav')

#xgbr_borderline = XGBRegressor()
#xgbr_borderline.load_model(fname='xgb_final_400F_borderlinesmote_032019.sav')

# X and y data transformed to delta G
X = VIH_final.drop("Exptal",axis=1)
y_energy = (VIH_final["Exptal"]/1000).apply(Kd_2_dG)
y_binding = VIH_final["Exptal"].values
PreparePredictions(X).run()
X.ddg.sort_values().head(10)
vih_original.loc[vih_original["mutation-effect"]=="increased"]
461
197
#ridge_model = joblib.load('ridgeLinear_train15skempiAB_FINAL.pkl')
lasso_model = joblib.load('Lasso_train15skempiAB_FINAL.pkl')
elasticnet_model = joblib.load('elasticNet_train15skempiAB_FINAL.pkl')
svr_model = joblib.load('rbfSVRmodel_train15skempiAB_FINAL.pkl')
poly_model = joblib.load("poly2SVRmodel_train15skempiAB_FINAL.pkl")
#rf_model = joblib.load('RFmodel_train15skempiAB_FINAL.pkl')
gbt_model = joblib.load('GBTmodel_train15skempiAB_FINAL.overf.pkl')
#xgb_model = joblib.load('XGBmodel_train15skempiAB_FINAL.pkl')
#ridge_pred = ridge_model.predict(X)
lasso_pred = lasso_model.predict(X)
elasticnet_pred = elasticnet_model.predict(X)
svr_pred = svr_model.predict(X)
poly_pred = poly_model.predict(X)
#rf_pred = rf_model.predict(X)
gbt_pred = gbt_model.predict(X)
#xgb_pred = xgb_model.predict(X)
pred_stack = np.hstack([vih_original[["mutation-effect","mCSM-AB_Pred","Exptal"]].values,
                        lasso_pred.reshape((-1,1)),gbt_pred.reshape((-1,1)),svr_pred.reshape((-1,1)),poly_pred.reshape((-1,1))])
pred_data = pd.DataFrame(pred_stack,columns=["mutation-effect","mCSM-AB_Pred","Exptal","Lasso_pred","gbt_pred","svr_pred","poly_pred"])
# transform prediction score to relative to kd , refered in paper
#pred_data_binding =  pred_data.applymap(deltaG_to_Kd)*100
pred_data["mean-pred"] = pred_data.loc[:,["Lasso_pred","gbt_pred","svr_pred"]].mean(axis=1)
pred_data
pred_data.loc[pred_data["mutation-effect"]=="increased"]
pred_data.loc[(pred_data["mean-pred"].abs() > 0.1)]
pred_data["True"] = y_energy.values
pred_data_binding["True"] = y_binding
#pred_data_converted.corr()
pred_data_binding.corr()
pred_data
average_pred_binding = pred_data_binding.drop("True",axis=1).loc[:,["gbt_pred","elasticnet_pred"]].mean(axis=1)
average_pred_energy = pred_data.drop("True",axis=1).loc[:,["gbt_pred","elasticnet_pred"]].mean(axis=1)
r2score =  r2_score(y_energy,average_pred_energy)
rmse = mean_squared_error(y_energy,average_pred_energy)

print("R2 score:", r2score)
print("RMSE score:", np.sqrt(rmse))
np.corrcoef(y["Exptal"],average_pred)
# Corr mCSM-AB with converted mCSM AB data
np.corrcoef(y_binding,vih_reverse["pred_ddg2EC50"])
# Corr mCSM-AB with converted VIH paper data
np.corrcoef(y_energy,vih_reverse["mCSM-AB_Pred"])
# Corr FoldX feature alone
np.corrcoef(y["Exptal"],VIH_final["dg_change"].apply(deltaG_to_Kd)*100)

import seaborn as sns
#rmse_test = np.round(np.sqrt(mean_squared_error(y_test, y_pred_test)), 3)
df_pred = pd.DataFrame({"Predicted ddG(kcal/mol)": pred_data["gbt_pred"], "Actual ddG(kcal/mol)": y_energy.values})
pearsonr_test = round(df_pred.corr().iloc[0,1],3)

g = sns.regplot(x="Actual ddG(kcal/mol)", y="Predicted ddG(kcal/mol)",data=df_pred)
plt.title("Predicted vs Experimental ddG (Independent set: 123 complexes)")

plt.text(-2,3,"pearsonr = %s" %pearsonr_test)
#plt.text(4.5,-0.5,"RMSE = %s" %rmse_test)

#plt.savefig("RFmodel_300_testfit.png",dpi=600)
PredictionError?<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16856856856856856, 'fraction_numerical': 0.03003003003003003, 'mean_word_length': 8.952191235059761, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '374', 'license': 'MIT', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2026, 'n_words': 250, 'path': 'notebooks/benchmark_vih.ipynb', 'repo_name': 'victorfica/Master-thesis', 'size': '4995'}