-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
executable file
·185 lines (162 loc) · 8.21 KB
/
app.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
# ===================================================================
# Title: BAPTA: Action Potential Batch Analyser
#
# Purpose: This script allows the automated analysis of APs from adult, neonatal and hiPSC-derived cardiomyocytes.
# Author: Luca Sala, PhD
# ===================================================================
if (require(shiny) == F) {
installed.packages("shiny")
require(shiny)
}
APD_values_input <- c(5,10,20,30,40,50,60,70,75,80,85,90,95)
saving_all_or_SS_input <- c("SS", "All")
data_pattern_input <- c(".abf", ".csv", ".txt")
#__Data examples__
Time_s <- c(0, 0.0002, 0.0004, 0.0006, "...")
Trace_1_mV <- c(-73.36, -73.36,-73.46, -73.48, "...")
Trace_2_mV <- c(-76.53, -76.57, -76.53, -76.53, "...")
table_trigered <- data.frame(Time_s, Trace_1_mV , Trace_2_mV, Trace_n_mV = "...")
table_spontaneous <- data.frame(Time_s, "Trace_mV" = Trace_1_mV)
path_shiny <- getwd()
#___
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel(windowTitle = "BAPTA",
title=div(img(src="/20220908_AP_logo.jpg", width = 587, height = 200))
),
mainPanel(
# Input: Select quotes ----
radioButtons(inputId = "type_of_recording",
label = "Were the cells paced or spontaneously beating?",
choices = c("Spontaneously Beating" = "run_GF",
"Paced" = "run_TR"),
inline = TRUE,),
checkboxGroupInput("APD_values",
"Which Action Potential Durations you want? (APD90 is mandatory)",
APD_values_input,
selected = 90,
inline = TRUE,),
radioButtons(inputId = "representatives",
label = "Do you want to save representative traces?",
choices = c("Yes" = T,
"No" = F),
inline = TRUE,),
numericInput("sweeps", "How many sweeps you want to average for steady state? (Default = 5)",
value = 5, min = 1, max = 1000),
numericInput("sweeps_SD", "How many sweeps you want to average for SD1 and SD2 calculations? (Default = 30)",
value = 30, min = 1, max = 1000),
# numericInput("high_pass", "Difene parametr of high pass filter? (Default = 70)", value = 70),
# numericInput("low_pass", "Difene parametr of low pass filter? (Default = -100)", value = -100),
selectInput(inputId = "data_pattern",
label = "Chose files format",
choices = data_pattern_input),
conditionalPanel(condition = "input.data_pattern != '.abf'",
selectInput(inputId = "time_parametr",
label = "Time in seconds or miliseconds?",
choices = c("Seconds" = 1000, "Miliseconds" = 1)),
conditionalPanel(condition = "input.type_of_recording == 'run_TR'",
p("Files should contain more then 2 columns in following order:" ),
p("Time (s or ms); Voltage 1 (mV); Voltage 2 (mV); etc." ),
fluidRow(
column(12, tableOutput('table_TR'))
),
),
conditionalPanel( condition = "input.type_of_recording == 'run_GF'",
p("Files should contain 2 columns in following order:"),
p("Time (s or ms); Voltage (mV)"),
fluidRow(
column(12, tableOutput('table_GF'))
),
),
),
conditionalPanel( condition = "input.type_of_recording == 'run_GF'",
numericInput("minpeakheight", "What is the minimum voltage threshold? (Default = -10 mV)",
value = -10, min = -100, max = 100),
numericInput("minpeakdistance", "What is the minimum cycle length between consequent AP?
(Default = 100 ms)",
value = 100),
radioButtons(inputId = "saving_all_or_SS",
label = "Do you want to save/average all data or only the APs at the steady state?",
choices = saving_all_or_SS_input,
inline = TRUE),
),
actionButton("start", "Run!", class = "btn-success btn-lg"),
actionButton("stop", "Close App", class = "btn-danger btn-lg")
)
)
# Define server part
server <- function(input, output, session) {
output$table_GF <- renderTable(table_spontaneous)
output$table_TR <- renderTable(table_trigered)
observeEvent(input$start, {
if(input$type_of_recording == "run_GF"){
showModal(modalDialog(
title = "Analysis Started",
"The estimated execution time can vary significantly based on size of the files.
Advice: It's a good practice to move the results of previous analyses to a separate location
and keep the output data folder clean before starting a new analysis. This ensures that your
workspace remains organized and prevents accidental overwriting or mixing of results from
different analyses.",
fade = TRUE,
easyClose = TRUE,
footer = NULL,))
type_of_recording <<- input$type_of_recording
APD_values <<- as.numeric(input$APD_values)
sweeps <<- input$sweeps
sweeps_SD <<- input$sweeps_SD
data_pattern <<- input$data_pattern
minpeakheight <<- input$minpeakheight
minpeakdistance <<- input$minpeakdistance
saving_all_or_SS <<- input$saving_all_or_SS
representatives <<- input$representatives
time_parametr <<- input$time_parametr
withProgress(message = 'Data Processing', value = 0,{
source("scripts/AP_Gap_Free_Analysis.R")
})
setwd(path_shiny)
showModal(modalDialog(
title = "Analysis Concluded",
paste("Finished analysis of ", file.number, "files. Total execution time: ", total_time, "min"),
fade = TRUE,
easyClose = TRUE,
footer = NULL,))
} else if(input$type_of_recording == "run_TR"){
showModal(modalDialog(
title = "Analysis Started",
"The estimated execution time can vary significantly based on size of the files.
Advice: It's a good practice to move the results of previous analyses to a separate location
and keep the output data folder clean before starting a new analysis. This ensures that your
workspace remains organized and prevents accidental overwriting or mixing of results from
different analyses.",
fade = TRUE,
easyClose = TRUE,
footer = NULL,))
type_of_recording <<- input$type_of_recording
data_pattern <<- input$data_pattern
APD_values <<- as.numeric(input$APD_values)
sweeps <<- input$sweeps
sweeps_SD <<- input$sweeps_SD
time_parametr <<- input$time_parametr
representatives <<- input$representatives
withProgress(message = 'Data Processing', value = 0,{
source("scripts/AP_Paced_Analysis.R")
})
setwd(path_shiny)
showModal(modalDialog(
title = "Analysis Concluded",
paste("Finished analysis of ", file.number, "files. Total execution time: ", total_time, "min"),
fade = TRUE,
easyClose = TRUE,
footer = NULL,))
}
})
observeEvent(input$stop, {
stopApp(session$onSessionEnded(stopApp))
})
observe({
if (input$stop > 0) stopApp() # stop shiny
})
}
# Run the application
shinyApp(ui = ui, server = server)