in reply to Regex::Reverse tricky test cases

Hello. I have an additional use for reversed regular expressions. In computational biology you often need to search for a pattern in both a genomic sequence (a string of chars from {A,T,G,C}) and its "reverse complement", generated by reversing the string and substituting characters according to the mapping (A<=>T, G<=>C). For example, the sequence: ACGGTCATCCGAGGCACC has reverse complement GGTGCCTCGGATGACCGT. Say I am looking for the pattern /ACGG/ is the forward direction. I would typically also be interested in instances of /ACGG/ on the reverse complement. Rather than reverse a sequence containing billions of characters, this search could be accomplished more effectively by taking the reverse complement of the regex instead, and searching the forward sequence with both regexes. I am currently writing an genome-searching application that requires this functionality. Roy, you mention that you are working on a module for this, which (along with an extensive search of cpan and perlmonks) suggests that one is not yet available. Can I use your module in my app? Or does a module for automatically reversing a regex already exist? Thanks in advance for your suggestions.

Replies are listed 'Best First'.
Re^2: Regex::Reverse tricky test cases
by Roy Johnson (Monsignor) on Oct 28, 2005 at 02:36 UTC
    Backreferences Make Reversing Regexes Fun for the Whole Family, a few nodes up in this thread, gives a good explanation of the difficulties in reversing regexen. Once I understood where the difficulties were, I realized I would not be able to make a module, so there isn't one.

    Even so, it's possible to reverse a limited subset of regexen, so it still might be a workable approach for your situation.


    Caution: Contents may have been coded under pressure.