Skip to content

Commit

Permalink
add dname server
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjavilaventura committed Jan 9, 2021
1 parent 22453de commit 3a27878
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 19 deletions.
10 changes: 9 additions & 1 deletion src/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@
### DNApp SERVER FUNCTION ###
#############################

server <- function(input, output) {}
source("src/app_server_dname.R")

server <- function(input, output, session) {

dname_server(input, output, session)

}


73 changes: 73 additions & 0 deletions src/app_server_dname.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# ========================= #
# DNAme server function #
# ========================= #

# Render input name in text
dname_input <- function(input, output, session) {

output$name <- renderText({
isolate({input$dna_name})
})
}

# Render output name (dna name) in text
dname_outname <- function(input, output, session) {
output$text_output <- renderText({

nucl_acid <- isolate({input$nucleicacid})
if(nucl_acid == "DNA"){ table = dna_codon_aa }
else if(nucl_acid == "mRNA"){ table = rna_codon_aa }

DNAme <- name2dna(input = isolate({input$dna_name}), nucleic_acid = nucl_acid,
table = table, codon_usage = isolate({input$codon_usage}),
sep = isolate({input$separator}))
if(is.list(DNAme)){ paste(DNAme$name) }
else{ paste(DNAme) }
})
}

# Render table with all 1-letter, 3-letter aa, aa names and most frequent codons for several species.
dname_table <- function(input, output, session) {
output$table_output <- renderTable({

nucl_acid <- isolate({input$nucleicacid})
if(nucl_acid == "DNA"){ table = dna_codon_aa }
else if(nucl_acid == "mRNA"){ table = rna_codon_aa }

DNAme <- name2dna(input = isolate({input$dna_name}), nucleic_acid = nucl_acid,
table = table, codon_usage = isolate({input$codon_usage}),
sep = isolate({input$separator}))

if(is.list(DNAme)){ DNAme$df }
else{ paste(DNAme) }
})
}

dname_dsDNA <- function(input, output, session) {
output$dsDNA_name <- renderTable({

nucl_acid <- isolate({input$nucleicacid})
if(nucl_acid == "DNA"){ table = dna_codon_aa }
else if(nucl_acid == "mRNA"){ table = rna_codon_aa }

DNAme <- name2dna(input = isolate({input$dna_name}), nucleic_acid = nucl_acid,
table = table, codon_usage = isolate({input$codon_usage}),
sep = isolate({input$separator}))

if(is.list(DNAme)){ DNAme$ds_name }
else{ paste(DNAme) }
}, spacing = "xs")
}

# DNAme server function complete
dname_server <- function(input, output, session) {

observeEvent(input$submit_dname, {
dname_input(input, output, session)
dname_outname(input, output, session)
dname_table(input, output, session)
dname_dsDNA(input, output, session)
})

}

2 changes: 1 addition & 1 deletion src/app_ui_body_about.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dnapp_body_about <-
tags$p("The apps currently present in DNApp are:",
tags$ul(tags$li("DNAme"),
tags$li("sNAP+"))),
br(),br(),br(),br(),
br(),br(),br(),br(),br(),br(),br(),br(),
HTML('<center><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/">
<img alt="Creative Commons Licence" style="border-width:0"
src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" />
Expand Down
39 changes: 27 additions & 12 deletions src/app_ui_body_dname.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ======================== #
# DNAme user interface #
# ======================== #


############
# UI ABOUT #

dnapp_body_dname_about <- tabItem(tabName = "dname_about",
HTML('<p style="font-size:30px;font-family:Helvetica;color:black;"><u>Welcome to DNAme!</u></p>'),
Expand Down Expand Up @@ -76,22 +80,33 @@ dnapp_body_dname_about <- tabItem(tabName = "dname_about",



##########
# UI APP #

dnapp_body_dname_app <- tabItem("dname_app",
splitLayout(cellWidths = c("30%", "70%"),
column(width = 12,
box(title = tagList(icon("dna"), "DNA your name"), width = 12, solidHeader = T,
textInput(inputId = "name", label = "Write your name", value = "DNAme"),
actionButton(inputId = "submit", label = "DNAme")),
textInput(inputId = "dna_name", label = "Write your name", value = "DNAme"),
actionButton(inputId = "submit_dname", label = "DNAme")),
box(title = tagList(icon("gear"), "Parameters"), width = 12, collapsible = T, collapsed = T,
selectInput(inputId = "nucleicacid", label = "Select the nucleic acid:", choices = c("DNA", "mRNA"), selected = "DNA", selectize = T),
selectInput(inputId = "codon_usage", label = "Select an organism:", selected = "Human", choices = list("Human" = "Human", "Mouse" = "Mouse","C. elegans" = "Celegans", "A. thaliana" = "Athaliana", "E. coli" = "Ecoli")),
textInput(inputId = "separator", label = "Write a separator:", value = "-"))),
textInput(inputId = "separator", label = "Write a separator:", value = ""))),

conditionalPanel(condition = "input.submit > 0",
h4("This is your DNA name!"),
tags$div(HTML(paste(tags$span(style="color:blue", textOutput(outputId = "name"))))),
tags$div(HTML(paste(tags$span(style="color:red; font-face:bold; font-size:30px", textOutput("text_output"))))),
br(),br(),
h4("Information"),
helpText("This is all the information in the letters of your name."),
tableOutput(outputId = "table_output"))))
conditionalPanel(condition = "input.submit_dname > 0",
h4("Input name:"),
tags$div(HTML(paste(tags$span(style="color:blue; font-size:20px; font-family:courier;", textOutput(outputId = "name"))))),
br(),
h4("DNA name:"),
tags$div(HTML(paste(tags$span(style="color:red; font-face:bold; font-size:30px; font-family:courier;",
textOutput("text_output"))))),
br(),
conditionalPanel(condition = "input.nucleicacid == 'DNA'",
h4("dsDNA name:"),
tags$div(tableOutput("dsDNA_name"), style = "font-family:courier; font-size:25px"),
br()),
h4("Information:"),
tableOutput("table_output"))))


3 changes: 3 additions & 0 deletions src/app_ui_body_snap.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# ======================== #
# sNAP+ user interface #
# ======================== #

dnapp_body_snap_about <-
tabItem(tabName = "snap_about",
Expand Down
38 changes: 33 additions & 5 deletions src/functions_dname.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ is.letter.normal <- function(input){

# ----- is.aa.letter ----- #
# function to check if all letters in input have an associated amino acid
is.aa.letter <- function(input){
is.not.aa <- function(input){

library(dplyr)

Expand All @@ -46,11 +46,35 @@ is.aa.letter <- function(input){
return(check.aa.letter)
}

# ----- Get complementary sequence ----- #
# function to make the complementary sequence of an input
dna_complementary <- function(input, sep=""){

query <- str_to_upper(input) %>% str_split(pattern = "") %>% unlist()
complement <- character(length = length(query))

for(i in 1:length(query)){
complement[i] <- if_else(str_detect(query[i], "A"), "T",
if_else(str_detect(query[i], "G"), "C",
if_else(str_detect(query[i], "T"), "A",
if_else(str_detect(query[i], "C"), "G", " "))))
}

ds_name <- data_frame(`5' -> 3'` = paste(query, collapse = sep),
`3' <- 5'` = paste(complement, collapse = sep)) %>%
t() %>%
as.data.frame() %>%
set_colnames(c(" "))

return(ds_name)

}


# ----- Convert Name to DNA ----- #
name2dna <- function(input="DNAmeà", table = dna_codon_aa, codon_usage = "Human", sep = "-"){
name2dna <- function(input="DNAme", nucleic_acid = "DNA", table = dna_codon_aa, codon_usage = "Human", sep = "-"){

#library(Biostrings)
library(Biostrings)
library(stringr)
library(dplyr)
library(magrittr)
Expand All @@ -68,7 +92,7 @@ name2dna <- function(input="DNAmeà", table = dna_codon_aa, codon_usage = "Human
else{

# if there are not allowed letters --> stop
if(TRUE %in% is.aa.letter(input)){
if(TRUE %in% is.not.aa(input)){

message <- paste("One of the letters in", input, "does not have an associated amminoacid.")
return(message)
Expand All @@ -92,11 +116,15 @@ name2dna <- function(input="DNAmeà", table = dna_codon_aa, codon_usage = "Human

DNAme$name <- paste((dna_name %>% select(codon_usage))[1:length(name),1], collapse = sep)

if(nucleic_acid == "DNA"){
DNAme$ds_name <- dna_complementary(paste((dna_name %>% select(codon_usage))[1:length(name),1], collapse = ""), sep = "")
}

# return list
return(DNAme)
}

}

}


6 changes: 6 additions & 0 deletions src/tables_dname.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ rna_codon_aa <- data.frame(one_letter = c("A", "C", "D", "E", "F", "G", "H", "I"
"AAU", "CCU", "CAA", "AGA", "UCU", "ACU", "GUU", "UGG", "UAU", " "),
Ecoli = c("GCG", "UGC", "GAU", "GAA", "UUU", "GGC", "CAU", "AUU", "AAA", "CUG", "AUG",
"AAC", "CCG", "CAG", "CGU", "AGC", "ACC", "GUG", "UGG", "UAU", " "),






stringsAsFactors = F)

0 comments on commit 3a27878

Please sign in to comment.