From d49109cec8ee672db0da4806f976feee055ec377 Mon Sep 17 00:00:00 2001 From: marcelcosta Date: Tue, 12 Jul 2022 15:35:09 +0200 Subject: [PATCH] =?UTF-8?q?Afegit=20acci=C3=B3=20del=20but=C3=B3,=20aix?= =?UTF-8?q?=C3=AD=20com=20opci=C3=B3=20d'output=20fasta=20o=20taula.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.R | 88 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 24 deletions(-) diff --git a/app.R b/app.R index 6e12914..72cc8ea 100644 --- a/app.R +++ b/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="
") } + 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="
") + } }) + + 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