Suppose I have a string x
like so.
x <- "CTTTANNNNNNNYG"
I would like to replace each letter in x with a different string that may not be f the same length.
a <- c("A","C","G","T","W","S","M","K","R","Y","B","D","H","V","N")
b <- c("A","C","G","T","(A|T)","(C|G)","(A|C)","(G|T)","(A|G)","(C|T)","(C|G|T)","(A|G|T)","(A|C|T)","(A|C|G)","(A|C|G|T)")
If I wanted to replace the letters in vector a with the corresponding ones in vector b, I would want to manipulate string x into:
"CTTTA(A|C|G|T)(A|C|G|T)(A|C|G|T)(A|C|G|T)(A|C|G|T)(A|C|G|T)(A|C|G|T)(C|T)G"
I've tried using mapply(gsub, a,b,x)
and str_replace()
to no avail. Any help would be appreciated.