-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBT_PCM.Rmd
289 lines (252 loc) · 10.4 KB
/
BT_PCM.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
---
title: "Proteocheometrics modeling of Bitter Taste Receptors"
author: "Saw Simeon and Chanin Nantasenamat"
date: "October 14, 2015"
output: html_document
---
Principal components analysis fo natural bitter taste compounds
```{r}
library(caret)
library(paran)
library(grid)
set.seed(2222)
setwd("/Volumes/SAW SIMEON/Bitter/Padel_Descriptors/Natural/")
nature <- read.csv("Natural.csv", header = TRUE)
nature <- nature[-1]
nature <- nature[, -nearZeroVar(nature)]
paran(nature)
pca <- prcomp(nature, center = TRUE, scale. = TRUE, retx = TRUE)
summary(pca)
loadings <- pca$rotation[, 1:6]
print(loadings)
scores <- pca$x[, 1:6]
km <- kmeans(scores, center= 3, nstart = 5)
ggdata <- data.frame(scores, Cluster = km$cluster)
natural_pca_plot_scores <- ggplot(ggdata, aes(x = PC1, y = PC2, colour = Cluster)) +
geom_point(aes(fill = factor(Cluster)), size = 5, shape = 20, pch = 21, alpha = 0.8) +
ggtitle("Scores Plot ") +
stat_ellipse(aes(fill = factor(Cluster)), colour = "black",
geom = "polygon", level = 0.95, alpha = 0.2) +
guides(color = guide_legend("Cluster"), fill = guide_legend("Cluster")) +
theme(
legend.position = ("none"),
panel.border = element_rect(linetype = "solid", colour = "black", fill = NA),
axis.text.y = element_text(size = 15),
axis.ticks.length = unit(0.3, "cm"),
axis.text.x = element_text(size = 15),
legend.title = element_blank(),
axis.title.x = element_text(colour = "black", size = 20),
axis.title.y = element_text(color = "black", size = 20))
print(natural_pca_plot_scores)
##Loading plot
km <- kmeans(loadings, center = 3, nstart = 5)
ggdata <- data.frame(loadings, Cluster = km$cluster)
set.seed(2220)
natural_pca_plot_loadings <- ggplot(ggdata, aes(x = PC1, y = PC2, colour = Cluster)) +
geom_point(aes(fill = factor(Cluster)), size = 5, shape = 20, pch = 21, alpha = 0.8) +
ggtitle("Loading plot") +
stat_ellipse(aes(fill = factor(Cluster)), colour = "black", geom= "polygon", level = 0.95,
alpha = 0.2) +
guides(color = guide_legend("Cluster"), fill = guide_legend("Cluster")) +
theme(
legend.position = ("none"),
panel.border = element_rect(linetype = "solid", colour = "black", fill = NA, size = 1),
axis.text.y = element_text(size = 15),
axis.ticks.length = unit(0.3, "cm"),
axis.text.x = element_text(size = 15),
legend.title = element_text(size = 15),
legend.title = element_blank(),
axis.title.x = element_text(color = "black", size = 20),
axis.title.y = element_text(color = "black", size = 20))
print(natural_pca_plot_loadings)
```
```{r}
setwd("/Volumes/SAW SIMEON/Bitter/Padel_Descriptors/Synthetic/")
synthetic <- read.csv("Synthetic.csv", header = TRUE)
synthetic <- synthetic[-1]
synthetic <- nature[, -nearZeroVar(synthetic)]
paran(synthetic)
pca <- prcomp(synthetic, center = TRUE, scale. = TRUE, retx = TRUE)
summary(pca)
loadings <- pca$rotation[, 1:6]
print(loadings)
scores <- pca$x[, 1:6]
km <- kmeans(scores, center= 3, nstart = 5)
ggdata <- data.frame(scores, Cluster = km$cluster)
synthetic_pca_plot_scores <- ggplot(ggdata, aes(x = PC1, y = PC2, colour = Cluster)) +
geom_point(aes(fill = factor(Cluster)), size = 5, shape = 20, pch = 21, alpha = 0.8) +
ggtitle("Scores Plot ") +
stat_ellipse(aes(fill = factor(Cluster)), colour = "black",
geom = "polygon", level = 0.95, alpha = 0.2) +
guides(color = guide_legend("Cluster"), fill = guide_legend("Cluster")) +
theme(
legend.position = ("none"),
panel.border = element_rect(linetype = "solid", colour = "black", fill = NA, size = 1),
axis.text.y = element_text(size = 15),
axis.ticks.length = unit(0.3, "cm"),
axis.text.x = element_text(size = 15),
legend.title = element_blank(),
axis.title.x = element_text(colour = "black", size = 20),
axis.title.y = element_text(color = "black", size = 20))
print(synthetic_pca_plot_scores)
set.seed(200)
km <- kmeans(loadings, center = 3, nstart = 5)
ggdata <- data.frame(loadings, Cluster = km$cluster)
synthetic_pca_plot_loadings <- ggplot(ggdata, aes(x = PC1, y = PC2, colour = Cluster)) +
geom_point(aes(fill = factor(Cluster)), size = 5, shape = 20, pch = 21, alpha = 0.8) +
ggtitle("Loadings Plot") +
stat_ellipse(aes(fill = factor(Cluster)), colour = "black",
geom = "polygon", level = 0.95, alpha = 0.2) +
guides(color = guide_legend("Cluster"), fill = guide_legend("Cluster")) +
theme(
legend.position = ("none"),
panel.border = element_rect(linetype = "solid", colour = "black", fill = NA, size = 1),
axis.text.y = element_text(size =15),
axis.ticks.length = unit(0.3, "cm"),
axis.text.x = element_text(size = 15),
legend.title = element_blank(),
axis.title.x = element_text(color = "black", size = 20),
axis.title.y = element_text(color = "black", size = 20))
print(synthetic_pca_plot_loadings)
setwd("/Volumes/SAW SIMEON/Bitter/")
```
```{r}
setwd("/Volumes/SAW SIMEON/Bitter/MEME_Motif/")
library(readxl)
protein <- read_excel("Motif_descriptors.xlsx")
protein <- protein[-1]
protein <- nature[, -nearZeroVar(protein)]
paran(protein)
pca <- prcomp(protein, center = TRUE, scale. = TRUE, retx = TRUE)
summary(pca)
loadings <- pca$rotation[, 1:5]
print(loadings)
scores <- pca$x[, 1:5]
km <- kmeans(scores, center= 3, nstart = 5)
ggdata <- data.frame(scores, Cluster = km$cluster)
protein_pca_plot_scores <- ggplot(ggdata, aes(x = PC1, y = PC2, colour = Cluster)) +
geom_point(aes(fill = factor(Cluster)), size = 5, shape = 20, pch = 21, alpha = 0.8) +
ggtitle("Scores Plot ") +
stat_ellipse(aes(fill = factor(Cluster)), colour = "black",
geom = "polygon", level = 0.95, alpha = 0.2) +
guides(color = guide_legend("Cluster"), fill = guide_legend("Cluster")) +
theme(
legend.position = ("none"),
panel.border = element_rect(linetype = "solid", colour = "black", fill = NA),
axis.text.y = element_text(size = 15),
axis.ticks.length = unit(0.3, "cm"),
axis.text.x = element_text(size = 15),
legend.title = element_blank(),
axis.title.x = element_text(colour = "black", size = 20),
axis.title.y = element_text(color = "black", size = 20))
print(protein_pca_plot_scores)
km <- kmeans(loadings, center = 3, nstart = 5)
ggdata <- data.frame(loadings, Cluster = km$cluster)
set.seed(200)
protein_pca_plot_loadings <- ggplot(ggdata, aes(x = PC1, y = PC2, colour = Cluster)) +
geom_point(aes(fill = factor(Cluster)), size = 5, shape = 20, pch = 21, alpha = 0.8) +
ggtitle("Loading Plot") +
stat_ellipse(aes(fill = factor(Cluster)), colour = "black",
geom = "polygon", level = 0.95, alpha = 0.2) +
guides(color = guide_legend("Cluster"), fill = guide_legend("Cluster")) +
theme(
legend.position = ("none"),
panel.border = element_rect(linetype = "solid", colour = "black", fill = NA, size = 1),
axis.text.y = element_text(size = 15),
axis.ticks.length = unit(0.3, "cm"),
axis.text.x = element_text(size = 15),
legend.title = element_blank(),
axis.title.x = element_text(colour = "black", size = 20),
axis.title.y = element_text(colour = "black", size = 20))
print(protein_pca_plot_loadings)
setwd("/Volumes/SAW SIMEON/Bitter/")
```
```{r, echo = FALSE, eval = FALSE}
setwd("E:/Bitter")
library(readxl)
library(caret)
library(Rcpi)
data <- read_excel("BT_PCM_Data.xlsx")
Activity <- data$Activity
Activity <- as.factor(Activity)
compound <- data[, 4:310]
compound <- compound[, -nearZeroVar(compound)]
protein <- data[, 311:880]
protein <- protein[, -nearZeroVar(protein)]
compound[compound == "0"] <- -1
CxP <- getCPI(compound, protein, type = "tensorprod")
CxP <- as.data.frame(CxP)
dfcompound <- names(data.frame(compound[,1:43]))
dfprotein <- names(data.frame(protein[,1:504]))
compoundNamecross <- rep(dfcompound, each = 504)
proteinNamecross <- rep(dfprotein, times = 43)
label <- paste(compoundNamecross, proteinNamecross, sep="_")
colnames(CxP) <- label
PxP <- getCPI(protein, protein, type = "tensorprod")
proteinName2 <- rep(dfprotein, times = 504)
proteinName1 <- rep(dfprotein, each = 504)
label_protein <- paste(proteinName1, proteinName2, sep = "_")
colnames(PxP) <- label_protein
index <- c(1, 41, 81, 121, 161, 201, 241, 281, 321, 361, 401, 441,
481, 521, 561, 601, 641, 681, 721, 761, 801, 841, 881,
921, 961, 1001, 1041, 1081, 1121, 1161, 1201, 1241, 1281,
1321, 1361, 1401, 1441, 1481, 1521)
protein_selfcross <- PxP[, -index]
transposedIndexed_protein <- t(protein_selfcross)
index1 <- which(duplicated(transposedIndexed_protein))
removed_duplicated_protein <- transposedIndexed_protein[-index1, ]
PxP <- t(removed_duplicated_protein)
CxC <- getCPI(compound, compound, type = "tensorprod")
compoundName2 <- rep(dfcompound, times = 39)
compoundName1 <- rep(dfcompound, each = 39)
label <- paste(compoundName1, compoundName2, sep = "_")
colnames(CxC) <- label
index3 <- c(1, 41, 81, 121, 161, 201, 241, 281, 321, 361, 401, 441,
481, 521, 561, 601, 641, 681, 721, 761, 801, 841, 881,
921, 961, 1001, 1041, 1081, 1121, 1161, 1201, 1241, 1281,
1321, 1361, 1401, 1441, 1481, 1521)
compound_selfcross <- CxC[, -index3]
transposedIndexed_compound <- t(compound_selfcross)
index4 <- which(duplicated(transposedIndexed_compound))
removed_compound <- transposedIndexed_compound[-index4, ]
compound_finalcrossterms <- t(removed_compound)
CxC <- compound_finalcrossterms
```
```{r, echo=FALSE, eval = FALSE}
J48_training <- function(x,) {
library(parallel)
library(doSNOW)
cl <- makeCluster(8)
registerDoSNOW(cl)
ok <- list(100)
ok <- foreach(i = 1:100 ) %dopar% {
in_train <- caret::createDataPartition(x$Activity, p = 0.80, list = FALSe)
train <- x[in_train, ]
test <- x[-in_train, ]
model_train <- RWeka::J48(Activity ~., data = train)
actual <- train$Activity
prediciton <- predict(model_train , train)
restuls <- caret::confusionMatrix(prediction, actual)
resutls <- table(prediction, actual)
results <- as.numeric(results)
}
}
J48_10_CV <- function(x) {
library(parallel)
library(doSNOW)
cl <- makeCluster(8)
registerDoSNWO(cl)
ok <- list(100)
ok <- foreach(i = 1:100) %dopar% {
in_train <- caret::createDataPartition(x$Activity, p = 0.80, list = FALSe)
myData <- x[in_train, ]
test <- x[-in_train, ]
k = 10
index <- sample(1:k, nrow(myData), replace = TRUE)
folds <- 1:k
myRes <- data.frame()
for (j in 1:k)
training <- subset(myDAta, index %in% )
}
}
```