Browse Source

Afegit acció del butó, així com opció d'output fasta o taula.

main
marcelcosta 2 years ago
parent
commit
d49109cec8
1 changed files with 64 additions and 24 deletions
  1. +64
    -24
      app.R

+ 64
- 24
app.R

@ -15,13 +15,15 @@ ui <- fluidPage(
selectInput("spec", label = h3("Specie"),
choices = list("Human" = 1, "E. Coli" = 2),
selected = 1),
actionButton("calab", "Analizar")
actionButton("but_an", "Analizar"),
selectInput("for_output", label = h3("Formato Output"),
choices = list("fasta" = 1, "tabla" = 2),
selected = 1),
),
mainPanel(
textAreaInput("seqText", label="Enter mFasta text", width = "100%", height = "500px", value=""),
# tags$head(tags$style(HTML("pre { white-space: pre-wrap; word-break: break-all; }"))),
htmlOutput("seqDNA")
uiOutput("seqDNAui")
)
),
tabPanel("Codon Frequency Table",
@ -34,38 +36,76 @@ ui <- fluidPage(
# Define server
server <- function(input, output) {
output$seqDNA <- renderText({
obj<-reactiveValues()
obj$fasta<-NULL
obj$seqs<-NULL
obj$names<-NULL
observe({
if (!is.null(input$file1)){ # This ensures that the reading is only tried when File selected
obj$fasta<-read.fasta(input$file1$datapath)
}
})
revtrans<-eventReactive(input$but_an, {
if (input$seqText != "" | !is.null(obj$fasta)){
if (input$seqText == ""){
print("Result")
seqs<-obj$fasta
}else{
seqs<-strsplit(input$seqText,"\n")[[1]]
names_seqs<-seqs[grepl("^>",seqs)]
names_seqs<-gsub(">","", names_seqs)
seqs<-seqs[!grepl("^>", seqs)]
if(input$spec == 1){spec<-hsapien_tbl}
if(input$spec == 2){spec<-ecoli_tbl}
seqs_DNA<-c()
progress <- shiny::Progress$new(min=0, max=length(seqs))
for (i in 1:length(seqs)){
set.seed(123)
seqs_DNA<-c(seqsDNA<-reverse_translate(seqs[i],spec))
progress$set(message = "Reverse Translating", value = i)
}
paste(dataframe2fas(data.frame(names=names_seqs,
seqs=seqs_DNA)), collapse="<br>")
}
names_seqs<-seqs[grepl("^>",seqs)]
names_seqs<-gsub(">","", names_seqs)
seqs<-seqs[!grepl("^>", seqs)]
if(input$spec == 1){spec<-hsapien_tbl}
if(input$spec == 2){spec<-ecoli_tbl}
seqs_DNA<-c()
progress <- shiny::Progress$new(min=0, max=length(seqs))
for (i in 1:length(seqs)){
set.seed(123)
seqs_DNA<-c(seqsDNA<-reverse_translate(seqs[i],spec))
progress$set(message = "Reverse Translating", value = i)
}
progress$close()
obj$seqs<-seqs_DNA
obj$names<-names_seqs
}
})
output$seqDNA <- renderText({
print(1)
observeEvent(input$but_an, {revtrans()})
if (!is.null(obj$seqs)){
paste(dataframe2fas(data.frame(names=obj$names, seqs=obj$seqs)), collapse="<br>")
}
})
output$seqDNAt <- renderTable({
print(2)
observeEvent(input$but_an, {revtrans()})
if (!is.null(obj$seqs)){
data.frame("Nombre"=obj$names, "Seqs"=obj$seqs)
}
})
{
output$tbl <- renderTable({
if(input$spec == 1){spec<-hsapien_tbl}
if(input$spec == 2){spec<-ecoli_tbl}
spec %>% arrange(aa)
spec[order(spec$aa),]
})
}
output$seqDNAui<-renderUI({
observeEvent(input$but_an, {})
if (input$for_output == 1){
htmlOutput("seqDNA")
}else{
tableOutput("seqDNAt")
}
})
}
# Run the application

Loading…
Cancel
Save