-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict_structure.R
189 lines (144 loc) · 6.52 KB
/
predict_structure.R
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
#Set the window size
window_size=11;
# Create samples
train_samples = create_samples(window_size,"datasets/train.txt");
test_samples = create_samples(window_size, "datasets/test.txt");
## Binary classifiers One vs Rest - training and model evaluation
# Train model
model_CnotC<-create_binary_model(train_samples,train_samples$CnotC....CnotC);
saveRDS(model_CnotC, "model_CnotC13.rds");
# Evaluate binary classifiers
# C/~C
test_samples$pred_class_CnotC <- predict(
model_CnotC, test_samples[,8:ncol(test_samples)],type = "response");
test_samples$pred_class_CnotC <- ifelse(
test_samples$pred_class_CnotC >= 0.5, "1", "-1");
ctab_test_CnotC <- table(test_samples$CnotC....CnotC, test_samples$pred_class_CnotC);
accuracy_test_CnotC <- sum(diag(ctab_test_CnotC))/sum(ctab_test_CnotC)*100
# Train model
model_HnotH<-create_binary_model(train_samples,train_samples$HnotH....HnotH);
saveRDS(model_HnotH, "model_HnotH13.rds");
# H/~H
test_samples$pred_class_HnotH <- predict(
model_HnotH, test_samples[,8:ncol(test_samples)],type = "response");
test_samples$pred_class_HnotH <- ifelse(
test_samples$pred_class_HnotH >= 0.5, "1", "-1");
ctab_test_HnotH <- table(test_samples$HnotH....HnotH, test_samples$pred_class_HnotH);
accuracy_test_HnotH <- sum(diag(ctab_test_HnotH))/sum(ctab_test_HnotH)*100
# Train model
model_EnotE<-create_binary_model(train_samples,train_samples$EnotE....EnotE);
saveRDS(model_EnotE, "model_EnotE13.rds");
# E/~E
test_samples$pred_class_EnotE <- predict(
model_EnotE, test_samples[,8:ncol(test_samples)],type = "response");
test_samples$pred_class_EnotE <- ifelse(
test_samples$pred_class_EnotE >= 0.5, "1", "-1");
ctab_test_EnotE <- table(test_samples$EnotE....EnotE, test_samples$pred_class_EnotE);
accuracy_test_EnotE <- sum(diag(ctab_test_EnotE))/sum(ctab_test_EnotE)*100
# Train model
train_samplesHE <-train_samples[train_samples$HE....HE != 0, ]
model_HE<-create_binary_model(train_samplesHE,train_samplesHE$HE....HE);
saveRDS(model_HE, "model_HE7.rds");
# H/E
test_samplesHE <-test_samples[test_samples$HE....HE != 0, ]
test_samplesHE$pred_class_HE <- predict(
model_HE, test_samplesHE[,8:ncol(test_samplesHE)],type = "response");
test_samplesHE$pred_class_HE <- ifelse(
test_samplesHE$pred_class_HE >= 0.5, "1", "-1");
ctab_test_HE <- table(test_samplesHE$HE....HE, test_samplesHE$pred_class_HE);
accuracy_test_HE <- sum(diag(ctab_test_HE))/sum(ctab_test_HE)*100
# Train model
train_samplesEC <-train_samples[train_samples$EC....EC != 0, ]
model_EC<-create_binary_model(train_samplesEC,train_samplesEC$EC....EC);
saveRDS(model_EC, "model_EC7.rds");
# E/C
test_samplesEC <-test_samples[test_samples$EC....EC != 0, ]
test_samplesEC$pred_class_EC <- predict(
model_EC, test_samplesEC[,8:ncol(test_samplesEC)],type = "response");
test_samplesEC$pred_class_EC <- ifelse(
test_samplesEC$pred_class_EC >= 0.5, "1", "-1");
ctab_test_EC <- table(test_samplesEC$EC....EC, test_samplesEC$pred_class_EC);
accuracy_test_EC <- sum(diag(ctab_test_EC))/sum(ctab_test_EC)*100
# Train model
train_samplesCH <-train_samples[train_samples$CH....CH != 0, ]
model_CH<-create_binary_model(train_samplesCH,train_samplesCH$CH....CH);
saveRDS(model_CH, "model_CH7.rds");
# C/H
test_samplesCH <-test_samples[test_samples$CH....CH != 0, ]
test_samplesCH$pred_class_CH <- predict(
model_CH, test_samplesCH[,8:ncol(test_samplesCH)],type = "response");
test_samplesCH$pred_class_CH <- ifelse(
test_samplesCH$pred_class_CH >= 0.5, "1", "-1");
ctab_test_CH <- table(test_samplesCH$CH....CH, test_samplesCH$pred_class_CH);
accuracy_test_CH <- sum(diag(ctab_test_CH))/sum(ctab_test_CH)*100
model_EnotE <- readRDS("model_EnotE13.rds")
model_CnotC <- readRDS("model_CnotC13.rds")
model_HnotH <- readRDS("model_HnotH13.rds")
model_HE <- readRDS("model_HE13.rds")
model_CH <- readRDS("model_CH13.rds")
model_CE <- readRDS("model_EC13.rds")
#data <- test_samples
# one vs rest (H/~H & E/~E & C/~C)
#data<-test_samples
data$pred_class_EnotE <- predict(
model_EnotE, data[,8:ncol(data)],type = "response");
data$pred_class_CnotC <- predict(
model_CnotC, data[,8:ncol(data)],type = "response");
data$pred_class_HnotH <- predict(
model_HnotH, data[,8:ncol(data)],type = "response");
data$pred_classCHE=" ";
# combine results
data$pred_classCHE <- ifelse(data$pred_class_EnotE > data$pred_class_CnotC,ifelse(
data$pred_class_EnotE > data$pred_class_HnotH,"E",data$pred_classCHE
), data$pred_classCHE);
data$pred_classCHE <- ifelse(data$pred_class_HnotH > data$pred_class_EnotE,ifelse(
data$pred_class_HnotH > data$pred_class_CnotC,"H",data$pred_classCHE
), data$pred_classCHE);
data$pred_classCHE <- ifelse(data$pred_class_CnotC > data$pred_class_HnotH,ifelse(
data$pred_class_CnotC > data$pred_class_EnotE,"C",data$pred_classCHE
), data$pred_classCHE);
data_tab <- table(data$struct_str....struct_str, data$pred_classCHE)
accuracyHCE <- sum(diag(data_tab))/sum(data_tab)*100
save_as_fasta(data$pred_classCHE, "HCE", "HCE.fasta")
# Tertiary classifier
# C/~C & H/E
data$pred_class_CnotC <- predict(
model_CnotC, data[,8:ncol(data)],type = "response");
data$pred_class_HE <- predict(
model_HE, data[,8:ncol(data)],type = "response")
data$pred_classCnotCHE=" ";
# combine results
data$pred_classCnotCHE <- ifelse(data$pred_class_CnotC <0.5,ifelse(
data$pred_class_HE > 0.5,"H","E"
), "C");
data_tab <- table(data$struct_str....struct_str, data$pred_classCnotCHE)
accuracyCnotCHE <- sum(diag(data_tab))/sum(data_tab)*100
save_as_fasta(data$pred_classCnotCHE, "CnotCHE", "CnotCHE.fasta")
# Tertiary classifier
# H/~H & C/E
data$pred_class_HnotH <- predict(
model_HnotH, data[,8:ncol(data)],type = "response");
data$pred_class_CE <- predict(
model_CE, data[,8:ncol(data)],type = "response")
data$pred_classHnotHCE=" ";
# combine results
data$pred_classHnotHCE <- ifelse(data$pred_class_HnotH <0.5,ifelse(
data$pred_class_CE > 0.5,"E","C"
), "H");
data_tab <- table(data$struct_str....struct_str, data$pred_classHnotHCE)
accuracyHnotHCE <- sum(diag(data_tab))/sum(data_tab)*100
save_as_fasta(data$pred_classHnotHCE, "HnotHCE", "HnotHCE.fasta")
# Tertiary classifier
# E/~E & C/H
data$pred_class_EnotE <- predict(
model_EnotE, data[,8:ncol(data)],type = "response");
data$pred_class_CH <- predict(
model_CH, data[,8:ncol(data)],type = "response")
data$pred_classEnotECH=" ";
# combine results
data$pred_classEnotECH <- ifelse(data$pred_class_EnotE <0.5,ifelse(
data$pred_class_CH > 0.5,"C","H"
), "E");
data_tab <- table(data$struct_str....struct_str, data$pred_classEnotECH)
accuracyEnotECH <- sum(diag(data_tab))/sum(data_tab)*100
save_as_fasta(data$pred_classEnotECH, "EnotECH", "EnotECH.fasta")