|
|
- library(shiny)
- library(seqRFLP)
- library(reversetranslate)
-
- # Define UI
- ui <- fluidPage(
-
- # Application title
- titlePanel("Reverse translation"),
-
- navbarPage("Apps",
- tabPanel("Translation",
- sidebarPanel(
- fileInput("file1", "Upload file (fasta, csv or xlsx)", multiple = FALSE),
- selectInput("spec", label = h3("Specie"),
- choices = list("Human" = 1, "E. Coli" = 2),
- selected = 1),
- actionButton("but_an", "Analize"),
- selectInput("for_output", label = h3("Output Format"),
- choices = list("fasta" = 1, "tabla" = 2),
- selected = 1),
- ),
-
- mainPanel(
- textAreaInput("seqText", label="Enter mFasta text", width = "100%", height = "500px", value=""),
- uiOutput("seqDNAui")
- )
- ),
- tabPanel("Codon Frequency Table",
- mainPanel(
- tableOutput("tbl")
- )
- )
- )
- )
-
- # Define server
- server <- function(input, output) {
- 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
- if (grepl(".xlsx", input$file1$datapath)){
- file<-openxlsx::read.xlsx(input$file1$datapath)
- obj$fasta<-dataframe2fas(file)
- }else{
- if (grepl(".csv", input$file1$datapath)){
- file<-read.csv(input$file1$datapath)
- obj$fasta<-dataframe2fas(file)
- }else{
- obj$fasta<-read.fasta(input$file1$datapath)
- }
- }
- }
- })
-
- revtrans<-eventReactive(input$but_an, {
- if (input$seqText != "" | !is.null(obj$fasta)){
- if (input$seqText == ""){
- 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(seqs_DNA, 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("Name"=obj$names, "Seqs"=obj$seqs)
- }
- })
-
- {
- output$tbl <- renderTable({
- if(input$spec == 1){spec<-hsapien_tbl}
- if(input$spec == 2){spec<-ecoli_tbl}
- spec[order(spec$aa),]
- })
- }
-
- output$seqDNAui<-renderUI({
- observeEvent(input$but_an, {})
- if (input$for_output == 1){
- htmlOutput("seqDNA")
- }else{
- tableOutput("seqDNAt")
- }
- })
- }
-
- # Run the application
- shinyApp(ui = ui, server = server)
|