-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.R
165 lines (133 loc) · 4.2 KB
/
server.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
library(protr)
library(seqinr)
library(randomForest)
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 <- '>AA1
AAPFLECQGRQGTCHFFAN
>AA2
ANIKLSVQMKLFKRHLKWKIIVKLNDGRELSLDA
>AA3
ARPAKAAATQKKVERKAPDA
>AA4
ASWSACSVSCGGGARQRTR
>AA5
ATPFIECSGARGTCHYFAN
>neg1
ADNWQSFDRWKDH
>neg2
AEALAALRALADKNQVF
>neg3
AERWREAAKLI
>neg4
AFAQFGSDLDAATQKLLNRGARLTELMKQPQ
>neg5
AGAGYALLALIGTEAAS
'
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")
xtest <- readFASTA("text.fasta")
A <- xtest[(sapply(xtest, protcheck))]###check special symbol
m = length(A)
# Set parameters
pse = 1
weightpse = 0.9
ampse = 1
weightampse = 0.9
# Calculate AAC
AAC <- t(sapply(A, extractAAC))
# Calculate PAAC
PAAC <- matrix(nrow = m, ncol = 20 + pse)
for(i in 1:m){
PAAC[i, ] = extractPAAC(A[[i]][1],lambda = pse, w = weightpse, props = c("Hydrophobicity", "Hydrophilicity", "SideChainMass"))
}
# Calculate APAAC
col = 20+ 2*ampse
APAAC <- matrix(nrow = length(A), ncol = col)
for (i in 1:length(A)){
APAAC[i,] = extractAPAAC(A[[i]][1],lambda = ampse, w = weightampse, customprops = NULL)
}
# Merge descriptor into single data frame
Dtest <- data.frame(AAC,PAAC,APAAC)
# 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
xtest <- readFASTA(inFile$datapath)
A <- xtest[(sapply(xtest, protcheck))]###check special symbol
m = length(A)
# Set parameters
pse = 1
weightpse = 0.9
ampse = 1
weightampse = 0.9
# Calculate AAC
AAC <- t(sapply(A, extractAAC))
# Calculate PAAC
PAAC <- matrix(nrow = m, ncol = 20 + pse)
for(i in 1:m){
PAAC[i, ] = extractPAAC(A[[i]][1],lambda = pse, w = weightpse, props = c("Hydrophobicity", "Hydrophilicity", "SideChainMass"))
}
# Calculate APAAC
col = 20+ 2*ampse
APAAC <- matrix(nrow = length(A), ncol = col)
for (i in 1:length(A)){
APAAC[i,] = extractAPAAC(A[[i]][1],lambda = ampse, w = weightampse, customprops = NULL)
}
# Merge descriptor into single data frame
Dtest <- data.frame(AAC,PAAC,APAAC)
# 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=TRUE)
})
output$downloadExample <- downloadHandler(
filename <- function() {
paste("example", "fasta", sep=".")
},
content <- function(file) {
file.copy("examples.fasta", file)
},
contentType = "text/csv"
)
})