generate all combinations of strings from regular expression in R
0
0
Entering edit mode
3.0 years ago
Chirag Parsania ★ 2.0k

Hi,

I have a regular expreesion - C|T|G,C|T,T,C,G,A,G,A|G,A|G|C,A|T|G|C of sequence motif. How can I generate all possible strings out of that in R ?

EDIT ========

the regx pattern is this [C|T|G][C|T]TCGAG[A|G][A|G|C][A|T|G|C] and not the above one.

Thanks, Chirag.

regularexpression R • 1.2k views
ADD COMMENT
1
Entering edit mode

try this in python 3:

import exrex
print(list(exrex.generate ('(C|T|G)(C|T)TCGAG(A|G)(A|G|C)(A|T|G|C)')))

try one of the following in R:

assertr::col_concat(expand.grid(c("C","T","G"),c ("C","T"), "TCGAG", c("A","G"),c("A","G","C"),c("A","T","G","C")), sep = "")
tidyr::unite("all",data=expand.grid(c("C","T","G"),c ("C","T"), "TCGAG", c("A","G"),c("A","G","C"),c("A","T","G","C")),1:6,sep = "")
Reduce(paste0,expand.grid(c("C","T","G"),c ("C","T"), "TCGAG", c("A","G"),c("A","G","C"),c("A","T","G","C")))
ADD REPLY
0
Entering edit mode

Thanks. expand.grid is the one!

ADD REPLY

Login before adding your answer.

Traffic: 2295 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6