regex - output computation in R using shiny -
this question has answer here:
i trying find pattern of "gc" in different genes(strings) user interface using shiny.i using grep command of r find pattern not able correct output.below code of ui.r
library(shiny) setwd("c:/users/ishaan/documents/aaa") shinyui(fluidpage( # copy line below make select box selectinput("select", label = h3("select human gene sequence"), choices = list("cd83" = "ugggugauuacauaaucugacaaauaaaaaaaucccgacuuugggaugagugcuaggauguuguaaa" , "sec23a" = "uuucacugu" , "ankfy1" = "aaguuugacuauauguguaaagggacuaaauauuuuugcaacagcc" ,"enst00000250457"="acuuguugaauaaacucagucucc" ), selected = "ugggugauuacauaaucugacaaauaaaaaaaucccgacuuugggaugagugcuaggauguuguaaa"), hr(), fluidrow(column(5, verbatimtextoutput("value")),column(5, verbatimtextoutput("value2"))) ))
server.r
library(shiny) setwd("c:/users/ishaan/documents/aaa") shinyserver(function(input , output) { strings=input$select # can access value of widget input$select, e.g. output$value <- renderprint({ input$select }) output$value2 <- renderprint({ grep("*gc*",input$value }) })
as indicated in comments there parenteses missing in code. furthermore statement seems wrong. grep expects regular expression. star doesn't make sense here. instead have use .*
. however, means grep
match entire string if contains gc
guess not result want have.
however can use grepexpr
search string gc
>gregexpr("gc","aagccaagcca")[[1]] [1] 3 8 attr(,"match.length") [1] 2 2 attr(,"usebytes") [1] true
the output looks bit confusing (to me). can can see string found @ position 3
, 8
the number of occurences given by
length(gregexpr("gc","aagccaagcca")[[1]]) [1] 2
to make match uppercase strings well
length(gregexpr("gc","gcaagccaagcca",ignore.case=true)[[1]])
finally there issue length calculation if there no match. solve issue need use
mtch <- gregexpr("gcxx","gcaagccaagcxca",ignore.case=true)[[1]] if(mtch[1]==-1) 0 else length(mtch)
Comments
Post a Comment