forked from sawsimeon/AChE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
William_Plot.Rmd
229 lines (173 loc) · 6.77 KB
/
William_Plot.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
---
title: "Applicability Domain (Williams Plot)"
author: Saw Simeon, Nuttapat Anuwongcharoen, Watshara Shoombuatong, Aijaz Ahmad Malik,
Virapong Prachayasittikul, Jarl E. S. Wikberg and Chanin Nantasenamat
date: "June 19, 2016"
output: pdf_document
---
# Function to create Williams Plot (Red = External, Cyan = Internal)
```{r, tidy = TRUE}
file <- function(x) {
library(randomForest)
library(caret)
library(ranger)
set.seed(10)
para <- dplyr::sample_n(x, size = 2570, replace = TRUE)
set.seed(3)
in_train_para <- sample(nrow(para),
size = as.integer(nrow(para) * 0.8),
replace = FALSE)
set.seed(4)
Train <- para[in_train_para, ]
Test <- para[-in_train_para, ]
model <- ranger::ranger(pIC50~., data = Train, write.forest = TRUE, save.memory = TRUE)
#actual <- train$Activity
prediction <- predict(model, Train)
prediction_Internal <- prediction$predictions
value <- data.frame(obs = Train$pIC50, pred = prediction_Internal)
labeling <- c("obs", "pred")
colnames(value) <- labeling
value$Label <- c("Internal")
prediction_External <- predict(model, Test)
prediction_External <- prediction_External$predictions
value_external <- data.frame(obs = Test$pIC50, pred = prediction_External)
colnames(value_external) <- labeling
value_external$Label <- c("External")
results <- rbind(value, value_external)
return(results)
}
get_leverage <- function(x) {
file <- file(x)
x <- file[, 1]
y <- file[, 2]
data <- data.frame(x, y)
error <- y-x
label <- file[3]
fit = lm(y~x,data = data)
hv <- as.data.frame(hatvalues(fit))
std.error = scale(error)
df <- data.frame(hv, std.error, label)
names(df) <- c("hv", "std.error", "Label")
return(df)
}
plot_william <- function(x, title) {
library(ggplot2)
library(cowplot)
ok <- get_leverage(x)
df <- data.frame(ok)
good <- ggplot(df, aes(hv, std.error)) +
geom_point(aes(color = Label), alpha = .20, size = 6) +
ggtitle(title) +
xlab("Leverage") + ylab("Standardized Residuals") +
geom_hline(yintercept = 3, color = "red", linetype = 2) +
geom_hline(yintercept = -3, color = "red", linetype = 2) +
theme(
panel.border = element_rect(linetype = "solid", colour = "black",
fill = NA, size = 1),
plot.title = element_text(size = 30, color = "black", face = "bold"),
axis.text.y = element_text(size = 20, colour = "black"),
axis.text.x = element_text(size = 20, colour = "black"),
axis.title.x = element_text(size = 30, color = "black", face = "bold"),
axis.title.y = element_text(size = 30, color = "black", face = "bold"),
legend.position = ("none"))
return(good)
}
```
\newpage
# CDK fingerprint
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$FingerPrinter
plot <- plot_william(df, title = "CDK Fingerprint")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
# CDK extended fingerprint
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$Extended_finterPrinter
plot <- plot_william(df, title = "CDK Extended Fingerprint")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
# CDK graph only fingerprint
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$GraphOnly_FingerPrinter
plot <- plot_william(df, title = "CDK Graph Only Fingerprint")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
# E-State fingerprint
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$Estate_FingerPrinter
plot <- plot_william(df, title = "E-State Fingerprint")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
# MACCS fingerprint
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$MACCS_FingerPrinter
plot <- plot_william(df, title = "MACCS Fingerprint")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
# PubChem fingerprint
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$Pubchem_FingerPrinter
plot <- plot_william(df, title = "PubChem Fingerprint")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
# Substructure fingerprint
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$Substructure_fingerPrinter
plot <- plot_william(df, title = "Substructure Fingerprint")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
\newpage
# Substructure count
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$Substructure_fingerPrintCount
plot <- plot_william(df, title = "Substructure Count")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
# Klekota-Roth fingerprint
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$KlekotaRoth_FingerPrinter
plot <- plot_william(df, title = "Klekota-Roth Fingerprint")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
# Klekota-Roth count
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$KlekotaRoth_FingerprintCount
plot <- plot_william(df, title = "Klekota-Roth count")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
# 2D atom pairs
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$AtomPairs2D_fingerPrinter
plot <- plot_william(df, title = "2D Atom Pairs")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```
# 2D atom pairs count
```{r, fig.width = 7, fig.height = 7, error = FALSE, message=FALSE, warning=FALSE}
input <- readRDS("data.Rds")
df <- input$AtomPairs2D_fingerPrintCount
plot <- plot_william(df, title = "2D Atom Pairs Count")
h <- 3*((dim(df)[2] - 1) + 1) / dim(df)[1]*0.8
plot + geom_vline(xintercept = h, linetype = 2, color = "red")
```