Advertisement
ProzacR

Edita2013_specifiskumo_QSAR nebaigtas

Aug 21st, 2015
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 5.71 KB | None | 0 0
  1. library(cvq2)
  2. #library(leaps)
  3.  
  4.  
  5. # cia is karto jau pKd skirtumas imtas:
  6. selectivity<-read.table("selectivityCA12.csv", sep=",", header=TRUE)
  7. qsar12_1<-data.frame(K<-selectivity$CA12.1)
  8. qsar12_1$x<-as.matrix(read.table("edragon_descriptors_fix4.csv", sep=",", skip=1))
  9.  
  10.  
  11. #random numbers:
  12. #> test <- sort(round(runif(10, 1, 40)))
  13. #> test
  14. test <- c(2, 3, 8, 9, 10, 16, 18, 19, 29, 35)
  15. #tada:
  16. train <- c(1, 4, 5, 6, 7, 11, 12, 13, 14, 15, 17, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40)
  17.  
  18. r2=NULL
  19. r2good=NULL
  20. for (i in 1:1317 ) {
  21. fit.single<-lm(qsar12_1$K[train]~qsar12_1$x[train,i])
  22. r2[i]<-summary(fit.single)$r.squared
  23. if(r2[i]>0.3) {
  24. r2good[i]<-r2[i]
  25. }
  26. }
  27.  
  28. #leaps<-regsubsets(qsar12_1$K[train]~qsar12_1$x[train,c(1:31)], data=qsar12_1, nvmax=5)
  29. #plot(leaps, scale="r2")
  30.  
  31. qsar_12_1_train<-lm(qsar12_1$K[train] ~ qsar12_1$x[train, 105] + qsar12_1$x[train, 333] + qsar12_1$x[train, 1205])
  32. print(summary(qsar_12_1_train))
  33. qsar_12_1_test_pred_values<-coef(qsar_12_1_train)[1]+coef(qsar_12_1_train)[2]*qsar12_1$x[test, 105]+coef(qsar_12_1_train)[3]*qsar12_1$x[test, 333]+coef(qsar_12_1_train)[4]*qsar12_1$x[test, 1205]
  34. qsar_12_1_test<-lm(qsar_12_1_test_pred_values ~ qsar12_1$K[test])
  35. print(summary(qsar_12_1_test))
  36. x<-cbind(qsar12_1$x[train,c(105,333,1205)], qsar12_1$K[train])
  37. colnames(x)[4]<-"y"
  38. qsar_12_1_q2<-cvq2(x)
  39. print(qsar_12_1_q2)
  40.  
  41. #==========================================
  42.  
  43. qsar12_2<-data.frame(K<-selectivity$CA12.2)
  44. qsar12_2$x<-as.matrix(read.table("edragon_descriptors_fix4.csv", sep=",", skip=1))
  45.  
  46. r2=NULL
  47. r2good=NULL
  48. for (i in 1:1317 ) {
  49. fit.single<-lm(qsar12_2$K[train]~qsar12_2$x[train,i])
  50. r2[i]<-summary(fit.single)$r.squared
  51. if(r2[i]>0.3) {
  52. r2good[i]<-r2[i]
  53. }
  54. }
  55.  
  56. #kaip ir be leaps variantas:
  57. #tada imti didziausia is r2good ir salinti koreliacijas su kitais, rasti kuris nekoreliuoja
  58. #r2very_good istrintos koreliacijos su 1231 kuris labai geras  sitame....
  59.  
  60. #arba r2good kas gero tada dar ziureti su leaps
  61.  
  62. qsar_12_2_train<-lm(qsar12_2$K[train] ~ qsar12_2$x[train, 293] +qsar12_2$x[train, 308] + qsar12_2$x[train, 311])
  63. print(summary(qsar_12_2_train))
  64. qsar_12_2_test_pred_values<-coef(qsar_12_2_train)[1]+coef(qsar_12_2_train)[2]*qsar12_2$x[test, 293]+coef(qsar_12_2_train)[3]*qsar12_2$x[test, 308]+coef(qsar_12_2_train)[4]*qsar12_2$x[test, 311]
  65. qsar_12_2_test<-lm(qsar_12_2_test_pred_values ~ qsar12_2$K[test])
  66. print(summary(qsar_12_2_test))
  67. x<-cbind(qsar12_2$x[train,c(293,308,311)], qsar12_2$K[train])
  68. colnames(x)[4]<-"y"
  69. qsar_12_2_q2<-cvq2(x)
  70. print(qsar_12_2_q2)
  71.  
  72. #=============================================
  73.  
  74. qsar_12_3_train<-lm(qsar$K[train] ~ qsar$x[train, 100] + qsar$x[train, 275] + qsar$x[train, 300])
  75. print(summary(qsar_12_3_train))
  76. qsar_12_3_test_pred_values<-coef(qsar_12_3_train)[1]+coef(qsar_12_3_train)[2]*qsar$x[test, 100]+coef(qsar_12_3_train)[3]*qsar$x[test, 275]+coef(qsar_12_3_train)[4]*qsar$x[test, 300]
  77. qsar_12_3_test<-lm(qsar_12_3_test_pred_values ~ qsar$K[test])
  78. print(summary(qsar_12_3_test))
  79. x<-cbind(qsar$x[train,c(100,275,300)], qsar$K[train])
  80. colnames(x)[4]<-"y"
  81. qsar_12_3_q2<-cvq2(x)
  82. print(qsar_12_3_q2)
  83.  
  84. #===============================================
  85.  
  86. #grafiko asys nuo/iki:
  87. minK<-5.8
  88. maxK<-9
  89.  
  90. qsar1<-coef(qsar_12_1_train)[1]+coef(qsar_12_1_train)[2]*qsar$x[, 275]+coef(qsar_12_1_train)[3]*qsar$x[, 1074]+coef(qsar_12_1_train)[4]*qsar$x[, 1107]
  91. qsar2<-coef(qsar_12_2_train)[1]+coef(qsar_12_2_train)[2]*qsar$x[, 649]+coef(qsar_12_2_train)[3]*qsar$x[, 1074]+coef(qsar_12_2_train)[4]*qsar$x[, 1259]
  92. qsar3<-coef(qsar_12_3_train)[1]+coef(qsar_12_3_train)[2]*qsar$x[, 100]+coef(qsar_12_3_train)[3]*qsar$x[, 275]+coef(qsar_12_3_train)[4]*qsar$x[, 300]
  93. grafikui<-cbind(qsar$K, qsar1, qsar2, qsar3)
  94. colnames(grafikui)[1]<-"pKd"
  95. mod_qsar1<-lm(grafikui[train,1]~grafikui[train,2])
  96. mod_qsar2<-lm(grafikui[train,1]~grafikui[train,3])
  97. mod_qsar3<-lm(grafikui[train,1]~grafikui[train,4])
  98. mod_qsar1t<-lm(grafikui[test,1]~grafikui[test,2])
  99. mod_qsar2t<-lm(grafikui[test,1]~grafikui[test,3])
  100. mod_qsar3t<-lm(grafikui[test,1]~grafikui[test,4])
  101.  
  102.  
  103. png("Edita2013_grafikas2.png", width=600, height=900)
  104. par(mfrow=c(3,2), mar=c(1,1,0,0), oma=c(6,6,0,0), cex.axis=2)
  105. plot(grafikui[train,1], grafikui[train,2], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), ann=FALSE, xaxt="n")
  106. abline(mod_qsar1)
  107. title('QSAR1', line = -3, cex.main=3)
  108. axis(1,col.axis = "transparent", tck = 0.02)
  109.  
  110. plot(grafikui[test,1], grafikui[test,2], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), xlab=NA, ylab=NA, xaxt="n", yaxt="n")
  111. abline(mod_qsar1t)
  112. title('QSAR1 test set', line = -3, cex.main=3)
  113. axis(1,col.axis = "transparent", tck = 0.02)
  114. axis(2,col.axis = "transparent", tck = 0.02)
  115.  
  116. plot(grafikui[train,1], grafikui[train,3], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), ann=FALSE, xaxt="n")
  117. abline(mod_qsar2)
  118. title('QSAR2', line = -3, cex.main=3)
  119.  
  120. plot(grafikui[test,1], grafikui[test,3], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), ann=FALSE, xaxt="n", yaxt="n")
  121. abline(mod_qsar2t)
  122. title('QSAR2 test set', line = -3, cex.main=3)
  123. axis(1,col.axis = "transparent", tck = 0.02)
  124. axis(2,col.axis = "transparent", tck = 0.02)
  125.  
  126. plot(grafikui[train,1], grafikui[train,4], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), ann=FALSE)
  127. abline(mod_qsar3)
  128. title('QSAR3', line = -3, cex.main=3)
  129.  
  130. plot(grafikui[test,1], grafikui[test,4], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), yaxt="n", cex.lab=3)
  131. abline(mod_qsar3t)
  132. title('QSAR3 test set', line = -3, cex.main=3)
  133. axis(2,col.axis = "transparent", tck = 0.02)
  134.  
  135. mtext('pKd (experimental)', SOUTH<-1, line=2.5, cex=2, outer=TRUE)
  136. mtext('pKd (calculated)', WEST<-2, line=2.5, cex=2, outer=TRUE)
  137.  
  138. dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement