Dear Listserve,

I have a data-parsing question for you. I recognize this is more in the domain of PERL/Python, but I don't know those languages! On the other hand, I am pretty good overall with R, so I'd rather get the job done within the R "ecosphere."

Here is what I want to do. Consider the following data:

string <- "ATCGCCCGTA[AGA]TAACCG"

I want to alter string so that it looks like this:

ATCGCCCGTA[A][G][A]TAACCG

In other words, I want to design a piece of code that will scan a character string, find bracketed groups of characters, break up each character within the bracket into its own individual bracketed character, and then put the group of individually bracketed characters back into the character string. The lengths of the character strings enclosed by a bracket will vary, but in every case, I want to do the same thing: break up each character within the bracket into its own individual bracketed character, and then put the group of individually bracketed characters back into the character string.

So, for example, another string may look like this:

string2 <- "ATTATACGCA[AAATGCCCCA]GCTA[AT]GCATTA"

I want to alter string so that it looks like this:

"ATTATACGCA[A][A][A][T][G][C][C][C][C][A]GCTA[A][T]GCATTA"

Thank you all in advance and have a great 2014!

-----------------------------------
Josh Banta, Ph.D
Assistant Professor
Department of Biology
The University of Texas at Tyler
Tyler, TX 75799
Tel: (903) 565-5655
http://plantevolutionaryecology.org


	[[alternative HTML version deleted]]

