-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.R
More file actions
122 lines (98 loc) · 3.27 KB
/
Copy pathserver.R
File metadata and controls
122 lines (98 loc) · 3.27 KB
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
library(protr)
library(seqinr)
#library(Interpol)
#library(caret)
library(kernlab)
library(e1071)
library(data.table)
shinyServer(function(input, output, session) {
# Loads the Model to memory
filepath <- file.path("data","Model.rds")
mod <- readRDS(filepath)
observe({
shinyjs::hide("downloadData") # Hide download button before input submission
if(input$submitbutton>0)
shinyjs::show("downloadData") # Show download button after input submission
})
observe({
FASTADATA <- ''
fastaexample <- '>ACP1
GLWSKIKEVGKEAAKAAAKAAGKAALGAVSEAV
>ACP2
GLFDIIKKIAESI
>ACP3
GLLDIVKKVVGAFGSL
>non-ACP1
MTISLIWGIAMVVCCCIWVIFDRRRRKAGEPPL
>non-ACP2
MFATPLRQPTNASGARPAVSMDGQETPFQYEITD
>non-ACP3
LLWRKVAGATVGPGPVPA
'
if(input$addlink>0) {
isolate({
FASTADATA <- fastaexample
updateTextInput(session, inputId = "Sequence", value = FASTADATA)
})
}
})
datasetInput <- reactive({
inFile <- input$file1
inTextbox <- input$Sequence
if (is.null(inTextbox)) {
return("Please insert/upload sequence in FASTA format")
} else {
if (is.null(inFile)) {
# Read data from text box
x <- inTextbox
write.fasta(sequence = x, names = names(x),
nbchar = 80, file.out = "text.fasta")
x <- readFASTA("text.fasta")
# Feature extraction for Testing set
#test <- read.fasta(x, seqtype="AA", as.string = TRUE)###read data
test <- x
test <- test[(sapply(test, protcheck))]###check special symbol
AACtest <- t(sapply(test, extractAAC))
col = 20+ 2*4
APAACtest <- matrix(nrow = length(test), ncol = col)
for (i in 1:length(test)){
APAACtest[i,] = extractAPAAC(test[[i]][1],lambda = 4, w = 0.01, customprops = NULL)
}
Dtest = data.frame(AACtest,APAACtest)
# Predicting unknown sequences
results <- data.frame(Prediction= predict(mod,Dtest), round(predict(mod,Dtest,type="prob"),3))
print(results)
}
else {
# Read data from uploaded file
x <- readFASTA(inFile$datapath)
# Feature extraction for Testing set
#test <- read.fasta(x, seqtype="AA", as.string = TRUE)###read data
test <- x
test <- test[(sapply(test, protcheck))]###check special symbol
AACtest <- t(sapply(test, extractAAC))
col = 20+ 2*4
APAACtest <- matrix(nrow = length(test), ncol = col)
for (i in 1:length(test)){
APAACtest[i,] = extractAPAAC(test[[i]][1],lambda = 4, w = 0.01, customprops = NULL)
}
Dtest = data.frame(AACtest,APAACtest)
# Predicting unknown sequences
results <- data.frame(Prediction= predict(mod,Dtest), round(predict(mod,Dtest,type="prob"),3))
print(results)
}
}
})
output$contents <- renderPrint({
if (input$submitbutton>0) {
isolate(datasetInput())
} else {
return("Server is ready for prediction.")
}
})
output$downloadData <- downloadHandler(
filename = function() { paste('predicted_results', '.csv', sep='') },
content = function(file) {
write.csv(datasetInput(), file, row.names=FALSE)
})
})