-
Notifications
You must be signed in to change notification settings - Fork 0
/
appcode.R
272 lines (241 loc) · 12.1 KB
/
appcode.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
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
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(tidyverse)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Circular Dichroism simulator"),
#Plot output
fluidRow(
tabsetPanel(type = "tabs",
tabPanel("Data", plotOutput("CDtrace"),
verbatimTextOutput("text")),
tabPanel("More information",
includeHTML("CD.html")))
)
,
fluidRow(
sidebarPanel(
selectInput("mode",
"Which mode do you want to use?",
choices = list("Prediction" = "predict",
"Display" = "display")
)
,
submitButton("Submit")
)
,
mainPanel(
#conditional panel
conditionalPanel(
condition = "input.mode == 'predict'",
checkboxInput("guides",
"Show secondary structure guides?",
value = FALSE,
width = NULL)
,
numericInput("helix",
"% alpha helix",
min = 0,
max = 100,
step = 5,
value = 50)
,
numericInput("sheet",
"% beta sheet",
min = 0,
max = 100,
step = 5,
value = 50)
,
numericInput("coil",
"% random coil",
min = 0,
max = 100,
step = 5,
value = 0)
)
,
conditionalPanel(
condition = "input.mode == 'display'",
selectInput("protein",
"Pick a protein to show predicted data for",
choices = list("Lysozyme (1LYD)" = "lyso",
"Ubiquitin (1UBQ)" = "ub",
"BST2 (3MQB)" = "bst",
"Hemoglobin (2HHB)" = "hemo",
"Antibody (1IGT)" = "ab")
)
,
"Simulated numbers generated in YASARA using the PDB IDs indicated"
)
)
),
br(),
br(),
"Shiny app created by C.E. Berndsen, 2018",
br(),
"Simulator based on work by Abriata, J. Chem. Ed. (2011)", tags$a(href="https://pubs.acs.org/doi/full/10.1021/ed200060t", "REF"), "using data from Greenfield and Fasman, Biochemistry (1969)", tags$a(href="https://pubs.acs.org/doi/10.1021/bi00838a031", "REF"),
br()
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$CDtrace <- renderPlot({
if(input$mode == "predict") {
#check to make sure fractions add to 100%
validate(
need(input$helix/100 + input$sheet/100 + input$coil/100 == 1,
"% of helix, sheet, and coil must = 100%"
)
)
#generate basis set
CDdat <- data.frame(lambda = seq(190, 250, by = 0.2))
CDdat <- CDdat %>% mutate(helix = 1*10^8 * (2230060.04151075*lambda^0 +
-100548.516559741*lambda^1 +
2037.18080475746*lambda^2 +
-24.4244919907991*lambda^3 +
0.19190243015954*lambda^4 +
-0.00103245782924168*lambda^5 +
0.00000385211889091252*lambda^6 +
-9.84175959744622E-09*lambda^7 +
1.64786777298595E-11*lambda^8 +
-1.63282751503442E-14*lambda^9 +
7.27089674019501E-18*lambda^10)) %>%
mutate(beta = 1*10^8 * (-677807.330017282*lambda^0 +
30975.2707887604*lambda^1 +
-636.143263740698*lambda^2 +
7.73164864362657*lambda^3 +
-6.15861633716145E-02*lambda^4 +
3.35943314432255E-04*lambda^5 +
-1.27092416556044E-06*lambda^6 +
3.29272089581372E-09*lambda^7 +
-5.59118151750062E-12*lambda^8 +
5.61899389095424E-15*lambda^9 +
-2.53794637234403E-18*lambda^10)) %>%
mutate(coil = 1*10^8 * (-580939.072386969*lambda^0 +
25845.2673351998*lambda^1 +
-516.713088253122*lambda^2 +
6.1134023680003*lambda^3 +
-4.74021175198809E-02*lambda^4 +
2.51692531821056E-04*lambda^5 +
-9.26824208397782E-07*lambda^6 +
2.33714935193268E-09*lambda^7 +
-3.86247107852678E-12*lambda^8 +
3.77764956561175E-15*lambda^9 +
-1.6603998403172E-18*lambda^10))
#Predict spectrum based on user input
CDdat <- CDdat %>% mutate(prediction = (input$helix)/100*helix + (input$sheet/100)*beta + (input$coil/100)*coil)
# draw the plot
if(input$guides == FALSE) {
ggplot(CDdat, aes(x = lambda, y = prediction/1000), color = "red") +
geom_jitter(alpha = 0.4) +
scale_x_continuous(breaks = seq(190, 250, by = 5)) +
labs(x = "wavelength (nm)", y = "Ellipticity", title = "Predicted CD spectrum") +
geom_hline(yintercept = 0) +
ylim(-50, 75) +
theme_classic() +
theme(axis.text = element_text(size = 10, face = "bold"), axis.title = element_text(size = 16, face = "bold"))
}
else {
ggplot() +
geom_jitter(data = CDdat, aes(x = lambda, y = prediction/1000), fill = "red", alpha = 0.4) +
geom_line(data = CDdat, aes(x = lambda, y = helix/1000), color = "red") +
geom_line(data = CDdat, aes(x = lambda, y = beta/1000), color = "green") +
geom_line(data = CDdat, aes(x = lambda, y = coil/1000), color = "purple") +
geom_hline(yintercept = 0) +
scale_x_continuous(breaks = seq(190, 250, by = 5)) +
labs(x = "wavelength (nm)", y = "Ellipticity", title = "Predicted CD spectrum") +
annotate("text", x = 235, y = 25, label = "Helix", color = "red", size = 5) +
annotate("text", x = 235, y = 20, label = "Beta Sheet", color = "green", size = 5) +
annotate("text", x = 235, y = 15, label = "Random Coil", color = "purple", size = 5) +
ylim(-50, 75) +
theme_classic() +
theme(axis.text = element_text(size = 10, face = "bold"), axis.title = element_text(size = 16, face = "bold"))
}
}
else {
#Generate the wavelength values
CDdat <- data.frame(lambda = seq(190, 250, by = 0.2))
#Generate the basis set from Abriata, L., J. Chem. Educ., 2011, 88 (9), pp 1268–1273 and Davidson, B. and Fasman, G. D., Biochemistry 1967 6 (6) 1616-1629
CDdat <- CDdat %>% mutate(helix = 1*10^8 * (2230060.04151075*lambda^0 +
-100548.516559741*lambda^1 +
2037.18080475746*lambda^2 +
-24.4244919907991*lambda^3 +
0.19190243015954*lambda^4 +
-0.00103245782924168*lambda^5 +
0.00000385211889091252*lambda^6 +
-9.84175959744622E-09*lambda^7 +
1.64786777298595E-11*lambda^8 +
-1.63282751503442E-14*lambda^9 +
7.27089674019501E-18*lambda^10)) %>%
mutate(beta = 1*10^8 * (-677807.330017282*lambda^0 +
30975.2707887604*lambda^1 +
-636.143263740698*lambda^2 +
7.73164864362657*lambda^3 +
-6.15861633716145E-02*lambda^4 +
3.35943314432255E-04*lambda^5 +
-1.27092416556044E-06*lambda^6 +
3.29272089581372E-09*lambda^7 +
-5.59118151750062E-12*lambda^8 +
5.61899389095424E-15*lambda^9 +
-2.53794637234403E-18*lambda^10)) %>%
mutate(coil = 1*10^8 * (-580939.072386969*lambda^0 +
25845.2673351998*lambda^1 +
-516.713088253122*lambda^2 +
6.1134023680003*lambda^3 +
-4.74021175198809E-02*lambda^4 +
2.51692531821056E-04*lambda^5 +
-9.26824208397782E-07*lambda^6 +
2.33714935193268E-09*lambda^7 +
-3.86247107852678E-12*lambda^8 +
3.77764956561175E-15*lambda^9 +
-1.6603998403172E-18*lambda^10))
#Predict spectrum based on user input
CDdat <- CDdat %>%
mutate(lyso = 0.7*helix + 0.07*beta + 0.17*coil) %>%
mutate(ub = 0.17*helix + 0.40*beta + 0.43*coil) %>%
mutate(bst = 0.92*helix + 0*beta + 0.08*coil) %>%
mutate(hemo = 0.74*helix + 0*beta + 0.17*coil) %>%
mutate(ab = 0.05*helix + 0.46*beta + 0.36*coil)
CDdat <- CDdat %>%
select(1:4, input$protein)
colnames(CDdat) <- c("lambda", "helix", "beta", "coil", "display")
ggplot() +
geom_jitter(data = CDdat, aes(x = lambda, y = display/1000), fill = "red", alpha = 0.4) +
geom_line(data = CDdat, aes(x = lambda, y = helix/1000), color = "red") +
geom_line(data = CDdat, aes(x = lambda, y = beta/1000), color = "green") +
geom_line(data = CDdat, aes(x = lambda, y = coil/1000), color = "purple") +
geom_hline(yintercept = 0) +
scale_x_continuous(breaks = seq(190, 250, by = 5)) +
labs(x = "wavelength (nm)", y = "Ellipticity") +
annotate("text", x = 235, y = 25, label = "Helix", color = "red", size = 7) +
annotate("text", x = 235, y = 20, label = "Beta Sheet", color = "green", size = 7) +
annotate("text", x = 235, y = 15, label = "Random Coil", color = "purple", size = 7) +
ylim(-50, 75) +
theme_classic() +
theme(axis.text = element_text(size = 10, face = "bold"), axis.title = element_text(size = 16, face = "bold"))
}
})
output$text <- renderText({
if(input$mode == "predict") {
paste("Spectrum showing", input$helix, "% alpha helix", input$sheet, "% beta sheet", input$coil, "% random coil")
}
else{
label <- ifelse(input$protein == 'lyso', "70% helix, 7% beta strand, 17% random coil",
ifelse(input$protein == 'ub', "17% helix, 40% beta strand, 43% random coil",
ifelse(input$protein == 'bst', "92% helix, 0% beta strand, 8% random coil",
ifelse(input$protein == 'ab', "5% helix, 46% beta strand, 36% random coil",
ifelse(input$protein == 'hemo', "74% helix, 0% beta strand, 17% random coil", "N/A")))))
paste("Structure contains", label)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)