Skip to content

Commit

Permalink
update dnainspect server and ui
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjavilaventura committed Jan 12, 2021
1 parent e33f49b commit d3fec2b
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 76 deletions.
1 change: 1 addition & 0 deletions app.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ source("src/functions_dnainspect.R")
# codon usage tables
source("src/tables_dname.R")
source("src/tables_snap.R")
source("src/tables_dnainspect.R")

### ----- load ui and server files -----
source("src/app_ui.R")
Expand Down
23 changes: 18 additions & 5 deletions src/app_server_dnainspect.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@ inspect_palindrome <- function(input, output, session){
})
}

# ----- Inspect palindrome -----
inspect_start_codon <- function(input, output, session){
# ----- Inspect search codon -----
inspect_search_codon <- function(input, output, session){

observeEvent(input$inspect_codons, {
output$inspect_start_codon <- renderTable({
output$inspect_search_codon <- renderTable({
query <- tibble(seq = isolate(input$input_inspect), nucleotide = isolate(input$nucleotide_inspect), start = isolate(input$start_inspect))
search_codons(input = query$seq, start = query$start, nucleotide = query$nucleotide, aa = isolate(input$inspect_search_codon))
})
})
}

# ----- Inspect search codon -----
inspect_search_pattern <- function(input, output, session){

observeEvent(input$inspect_match, {
output$inspect_match <- renderTable({
query <- tibble(seq = isolate(input$input_inspect), nucleotide = isolate(input$nucleotide_inspect), start = isolate(input$start_inspect))
start_codons(input = query$seq, start = query$start, nucleotide = query$nucleotide)
search_pattern(input = query$seq, start = query$start, nucleotide = query$nucleotide, pattern = isolate(input$match_text))

})
})
}
Expand All @@ -41,5 +53,6 @@ inspect_server <- function(input, output, session){

inspect_stats(input, output, session)
inspect_palindrome(input, output, session)
inspect_start_codon(input, output, session)
inspect_search_codon(input, output, session)
inspect_search_pattern(input, output, session)
}
17 changes: 9 additions & 8 deletions src/app_ui_body_dnainspect.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,29 @@ dnapp_body_dnainspect_app <-
box(title = tagList(icon("calculator"), " Stats. params."), width = 12, collapsible = T, collapsed = T,
actionButton(inputId = "inspect_stats", label = "Show stats")),
box(title = tagList(icon("equals"), " Match params."), width = 12, collapsible = T, collapsed = T,
actionButton(inputId = "inspect_match", label = "Search matches")),
textInput(inputId = "match_text", label = "Write a pattern to search:", width = "100%"),
actionButton(inputId = "inspect_match", label = "Search patterns")),
box(title = tagList(icon("exchange-alt"), " Palindrome params."), width = 12, collapsible = T, collapsed = T,
actionButton(inputId = "inspect_palindrome", label = "Search palindromes")),
#box(title = tagList(icon("cut"), "Restriction params."), width = 12, collapsible = T, collapsed = F,
# actionButton(inputId = "inspect_restriction", label = "Search restriction targets")),
box(title = tagList(icon("dice-three"), " Codons prams."), width = 12, collapsible = T, collapsed = T,
selectInput(inputId = "inspect_search_codon",
label = "Select the aminoacid to look at its codons:",
choices = codons$aa_3l, multiple = F, width = "100%"),
actionButton(inputId = "inspect_codons", label = "Search codons"))),

column(width = 12,
box(title = tagList(icon("calculator"), " Statistics"), width = 12, collapsible = T, collapsed = F,
tags$div(tableOutput(outputId = "inspect_stats"), style = "font-family:courier;")),
box(title = tagList(icon("equals"), " Matches"), width = 12, collapsible = T, collapsed = F),
box(title = tagList(icon("equals"), " Matches"), width = 12, collapsible = T, collapsed = F,
tags$div(tableOutput(outputId = "inspect_match"), style = "font-family:courier;")),
box(title = tagList(icon("exchange-alt"), " Palindromes"), width = 12, collapsible = T, collapsed = F,
tags$div(tableOutput(outputId = "inspect_palindrome"), style = "font-family:courier;")),
#box(title = tagList(icon("cut"), "Restriction targets"), width = 12, collapsible = T, collapsed = F),
box(title = tagList(icon("dice-three"), " Codons"), width = 12, collapsible = T, collapsed = F,
tabsetPanel(
tabPanel(title = "Start", value = "start_codon",
tags$div(tableOutput(outputId = "inspect_start_codon"), style = "font-family:courier;")),
tabPanel(title = "Stop", value = "stop_codon"),
tabPanel(title = "Other", value = "other_codon")
)))))
tags$div(tableOutput(outputId = "inspect_search_codon"), style = "font-family:courier;"))
)))



Expand Down
120 changes: 75 additions & 45 deletions src/functions_dnainspect.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
# is.dna ---> function already present in the snap functions

# ----- Search for palindromes -----
palindromes <- function(input, start=1, nucleotide = "DNA"){
palindromes <- function(input, start = 1, nucleotide = "DNA"){

library(dplyr)
library(magrittr)
library(Biostrings)

if(nucleotide == "DNA"){
if(!is.dna(input, nucleotide)){ return("The input DNA must contain only A,T,G and C.")}
if(!is.dna(input = input, nucleotide = nucleotide)){ return("The input DNA must contain only A,T,G and C.")}
else{ query <- DNAString(x = input, start = start) }
}

else{
if(!is.dna(input, nucleotide)){ return("The input RNA must contain only A,U,G and C.")}
if(!is.dna(input = input, nucleotide = nucleotide)){ return("The input RNA must contain only A,U,G and C.")}
else{ query <- RNAString(x = input, start = start) }
}

Expand All @@ -26,44 +26,50 @@ palindromes <- function(input, start=1, nucleotide = "DNA"){
as.data.frame(res)) %>%
set_colnames(c("Start", "End", "Width", "Palindrome"))

if(nrow(out)==0){ return("There aren't any palindromes in the input sequence.") }

return(out)

}

# ----- Search for start codons -----
start_codons <- function(input, start = 1, nucleotide = "DNA"){
# ----- Search for codons -----
search_codons <- function(input, start = 1, nucleotide = "DNA" , aa = "START"){

library(Biostrings)
library(dplyr)
library(magrittr)
library(magrittr)


if(nucleotide == "DNA"){
if(!is.dna(input, nucleotide)){ return("The input DNA must contain only A,T,G and C.")}
if(!is.dna(input = input, nucleotide = nucleotide)){ return("The input DNA must contain only A,T,G and C.")}
else{
start_codon <- "ATG"
query <- DNAString(x = input, start = start)
query <- DNAString(x = input, start = start)
pattern <- codons$codon_dna[which(codons$aa_3l == aa)]
}
}

else{
if(!is.dna(input, nucleotide)){ return("The input RNA must contain only A,U,G and C.")}
else{
start_codon <- "AUG"
query <- RNAString(x = input, start = start)
if(!is.dna(input = input, nucleotide = nucleotide)){ return("The input RNA must contain only A,U,G and C.")}
else{
query <- RNAString(x = input, start = start)
pattern <- codons$codon_rna[which(codons$aa_3l == aa)]
}
}

res <- Biostrings::matchPattern(pattern = start_codon, subject = query)
out <- bind_cols(as.data.frame((ranges(res))),
as.data.frame(res)) %>%
set_colnames(c("Start", "End", "Width", "Codon"))
out <- list()
for(i in 1:length(pattern)){
res <- Biostrings::matchPattern(pattern = pattern[i], subject = query)
out[[i]] <- bind_cols(as.data.frame((ranges(res))),
as.data.frame(res)) %>%
set_colnames(c("Start", "End", "Width", "Codon"))
}

out <- bind_rows(out)

if(nrow(out)==0){ return(paste("The codon coding for", aa, "is not in the input sequence.")) }

return(out)

return(out)
}

# ----- Search for stop codons -----
stop_codons <- function(input, start=1, nucleotide ="DNA"){}


# ----- DNA stats -----
dna.stats2 <- function(input, start = 1, nucleotide = "DNA"){
Expand All @@ -73,20 +79,15 @@ dna.stats2 <- function(input, start = 1, nucleotide = "DNA"){
library(magrittr)
library(stringr)

bases <- str_split(input, "") %>% unlist()

if(nucleotide == "DNA"){
if(!is.dna(input, nucleotide)){ return("The input DNA must contain only A,T,G and C.")}
else{
bases <- str_split(input, "") %>% unlist()
query <- DNAString(x = input, start = start)
}
if(!is.dna(input = input, nucleotide = nucleotide)){ return("The input DNA must contain only A,T,G and C.") }
else{ query <- DNAString(x = input, start = start) }
}

else{
if(!is.dna(input, nucleotide)){ return("The input RNA must contain only A,U,G and C.")}
else{
bases <- str_split(input, "") %>% unlist()
query <- RNAString(x = input, start = start)
}
if(!is.dna(input = input, nucleotide = nucleotide)){ return("The input RNA must contain only A,U,G and C.")}
else{ query <- RNAString(x = input, start = start) }
}

len <- query@length
Expand All @@ -95,25 +96,54 @@ dna.stats2 <- function(input, start = 1, nucleotide = "DNA"){
n_codons <- length(codons)
start_base <- start

palindrome <- palindromes(input, start = start, nucleotide = nucleotide)
palindrome <- palindromes(input, start = start, nucleotide = nucleotide)
n_palindrome <- nrow(palindrome)
if(!is.data.frame(palindrome)){n_palindrome <- 0}

start <- start_codons(input, start = start, nucleotide = nucleotide)
n_start <- nrow(start)

#stop <- stop_codons(input, start = start, nucleotide = nucleotide)
#n_stop <- nrow(stop)
start_codon <- search_codons(input, start = start, nucleotide = nucleotide, aa = "START")
n_start <- nrow(start_codon)
if(!is.data.frame(start_codon)){n_start <- 0}

stop <- search_codons(input, start = start, nucleotide = nucleotide, aa = "STOP")
n_stop <- nrow(stop)
if(!is.data.frame(stop)){n_stop <- 0}

out <- tibble(Stat = c("Input", "Length", "% GC", "Start base",
"Number of codons", "Number of palindromes",
"Possible starting codons"),
"Number of codons", "Possible palindromes",
"Possible starting codons", "Possible stop codons"),
Value = c(input, len, gc, start_base,
n_codons, n_palindrome,
n_start))
n_start, n_stop))

return(out)

}



# ----- Search for patterns -----
search_pattern <- function(input, start = 1, nucleotide ="DNA", pattern = "ATG"){

library(Biostrings)
library(dplyr)
library(magrittr)

if(nucleotide == "DNA"){
if(!is.dna(input = input, nucleotide = nucleotide)){ return("The input DNA must contain only A,T,G and C.") }
#else if(!is.dna(pattern, nucleotide)){ return("The pattern DNA must contain only A,T,G and C.") }
else{ query <- DNAString(x = input, start = start) }
}
else{
if(!is.dna(input = input, nucleotide = nucleotide)){ return("The input RNA must contain only A,U,G and C.") }
#else if(!is.dna(pattern, nucleotide)){ return("The pattern RNA must contain only A,U,G and C.") }
else{ query <- RNAString(x = input, start = start) }
}

res <- Biostrings::matchPattern(pattern = pattern, subject = query)
out <- bind_cols(as.data.frame(ranges(res)),
as.data.frame(res)) %>%
set_colnames(c("Start", "End", "Width", "Pattern"))

if(nrow(out) == 0){ return("The input pattern has not been found in the input sequence.") }

return(out)

}
34 changes: 16 additions & 18 deletions src/tables_dnainspect.R
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
### DNAinspect tables
### ===============================================================================================

c("TTT", "TTC", "TTA", "TTG", "TCT", "TCC", "TCA", "TCG", "TAT", "TAC", "TAA", "TAG",
"TGT", "TGC", "TGA", "TGG", "CTT", "CTC", "CTA", "CTG", "CCT", "CCC", "CCA", "CCG",
"CAT", "CAC", "CAA", "CAG", "CGT", "CGC", "CGA", "CGG", "ATT", "ATC", "ATA", "ATG",
"ACT", "ACC", "ACA", "ACG", "AAT", "AAC", "AAA", "AAG", "AGT", "AGC", "AGA", "AGG",
"GTT", "GTC", "GTA", "GTG", "GCT", "GCC", "GCA", "GCG", "GAT", "GAC", "GAA", "GAG",
"GGT", "GGC", "GGA", "GGG")


codons <- data.frame(aa_1l = c("F", "F", "L", "L", "S", "S", "S", "S", "Y", "Y", "*", "*",
"C", "C", "*", "W", "L", "L", "L", "L", "P", "P", "P", "P",
"H", "H", "Q", "Q", "R", "R", "R", "R", "I", "I", "I", "M",
"T", "T", "T", "T", "N", "N", "K", "K", "S", "S", "R", "R",
"V", "V", "V", "V", "A", "A", "A", "A", "D", "D", "E", "E",
"G", "G", "G", "G"),
"G", "G", "G", "G", "START"),
aa_3l = c("Phe", "Phe", "Leu", "Leu", "Ser", "Ser", "Ser", "Ser", "Tyr", "Tyr", "STOP", "STOP",
"Cys", "Cys", "STOP", "Trp", "Leu", "Leu", "Leu", "Leu", "Pro", "Pro", "Pro", "Pro",
"His", "His", "Gln", "Gln", "Arg", "Arg", "Arg", "Arg", "Ile", "Ile", "Ile", "Met",
"Thr", "Thr", "Thr", "Thr", "Asn", "Asn", "Lys", "Lys", "Ser", "Ser", "Arg", "Arg",
"Val", "Val", "Val", "Val", "Ala", "Ala", "Ala", "Ala", "Asp", "Asp", "Glu", "Glu",
"Gly", "Gly", "Gly", "Gly"),
"Gly", "Gly", "Gly", "Gly", "START"),
aa_name = c("Phenylalanine", "Phenylalanine", "Leucine", "Leucine", "Serine", "Serine", "Serine", "Serine", "Tyrosine", "Tyrosine", "STOP", "STOP",
"Cysteine", "Cysteine", "STOP", "Tryptophan", "Leucine", "Leucine", "Leucine", "Leucine", "Proline", "Proline", "Proline", "Proline",
"Histidine", "Histidine", "Glutamine", "Glutamine", "Arginine", "Arginine", "Arginine", "Arginine", "Isoleucine", "Isoleucine", "Isoleucine", "Methionine",
"Threonine", "Threonine", "Threonine", "Threonine", "Asparagine", "Asparagine", "Lysine", "Lysine", "Serine", "Serine", "Arginine", "Arginine",
"Valine", "Valine", "Valine", "Valine", "Alanine", "Alanine", "Alanine", "Alanine", "Aspartic acid", "Aspartic acid", "Glutamic acid", "Glutamic acid",
"Glycine", "Glycine", "Glycine", "Glycine"),
codon = c("TTT", "TTC", "TTA", "TTG", "TCT", "TCC", "TCA", "TCG", "TAT", "TAC", "TAA", "TAG",
"TGT", "TGC", "TGA", "TGG", "CTT", "CTC", "CTA", "CTG", "CCT", "CCC", "CCA", "CCG",
"CAT", "CAC", "CAA", "CAG", "CGT", "CGC", "CGA", "CGG", "ATT", "ATC", "ATA", "ATG",
"ACT", "ACC", "ACA", "ACG", "AAT", "AAC", "AAA", "AAG", "AGT", "AGC", "AGA", "AGG",
"GTT", "GTC", "GTA", "GTG", "GCT", "GCC", "GCA", "GCG", "GAT", "GAC", "GAA", "GAG",
"GGT", "GGC", "GGA", "GGG")
)
"Glycine", "Glycine", "Glycine", "Glycine", "START"),
codon_dna = c("TTT", "TTC", "TTA", "TTG", "TCT", "TCC", "TCA", "TCG", "TAT", "TAC", "TAA", "TAG",
"TGT", "TGC", "TGA", "TGG", "CTT", "CTC", "CTA", "CTG", "CCT", "CCC", "CCA", "CCG",
"CAT", "CAC", "CAA", "CAG", "CGT", "CGC", "CGA", "CGG", "ATT", "ATC", "ATA", "ATG",
"ACT", "ACC", "ACA", "ACG", "AAT", "AAC", "AAA", "AAG", "AGT", "AGC", "AGA", "AGG",
"GTT", "GTC", "GTA", "GTG", "GCT", "GCC", "GCA", "GCG", "GAT", "GAC", "GAA", "GAG",
"GGT", "GGC", "GGA", "GGG", "ATG"),
codon_rna = c("UUU", "UUC", "UUA", "UUG", "UCU", "UCC", "UCA", "UCG", "UAU", "UAC", "UAA", "UAG",
"UGU", "UGC", "UGA", "UGG", "CUU", "CUC", "CUA", "CUG", "CCU", "CCC", "CCA", "CCG",
"CAU", "CAC", "CAA", "CAG", "CGU", "CGC", "CGA", "CGG", "AUU", "AUC", "AUA", "AUG",
"ACU", "ACC", "ACA", "ACG", "AAU", "AAC", "AAA", "AAG", "AGU", "AGC", "AGA", "AGG",
"GUU", "GUC", "GUA", "GUG", "GCU", "GCC", "GCA", "GCG", "GAU", "GAC", "GAA", "GAG",
"GGU", "GGC", "GGA", "GGG", "AUG"),
stringsAsFactors = F)



Expand Down

0 comments on commit d3fec2b

Please sign in to comment.