Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: generate regular expression

by injunjoel (Priest)
on Mar 30, 2006 at 18:53 UTC ( #540239=note: print w/replies, xml ) Need Help??

in reply to generate regular expression

In your example you have two different situations:
The "and" situation "2 CAC and 2 TTT" in which case its really two seperate searches.
And the "single" search situation "1 A|T CAC", "2 C|A TTT T|G".

If your search criteria is submitted as you have specified you could split the query on "and" or "or" to handle your first situation. Once split, capture out the count criteria and test with the scalar return value from your array of matches using the
(@array) = $string =~ /$pattern/g

Untested Idea!
my $base_data = 'ATCACTGGTTCCTGGACACTACCCTAAACCTTTGAGGA AATAACCGCTTTGTTGTTGCGATCGCCTAATAAATATC AGCGTCTTCGTATGATAAACCAATGCGGAAGTACAAAA TAAAGAGACTGTATTATGTTACT'; #the user submitted search pattern my $search_submitted = '2 CAC and 2 TTT'; #split it into chunks if applicable. my @search_chunks = split /and|or/, $search_submitted; #for each distinct pattern foreach my $chunk (@search_chunks){ #get the count we are looking for and the pattern we want to use my ($count, $search_string) = $chunk =~ /\s?(\d+)\s?([ATGCU\s\|]+) +/; #replace the |'s with character classes. $search_string =~ s/([ATGCU])\|([ATGCU])/[$1$2]/g; #replace all spaces $search_string =~ s/\s+//g; #run the match and see how many we get. my (@search_count) = $base_data =~ /$search_string/g; #check our results. if(scalar @search_count >= $count){ print "Found it!\n"; }else{ print "Nope...".scalar @search_count."\n"; } }
Is that sort of what you were thinking of?

grep was not what I wanted after all...

"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

Replies are listed 'Best First'.
Re^2: generate regular expression
by khoueiry (Initiate) on Apr 01, 2006 at 10:10 UTC
    Thanks a lot.
    Actually it is too close of what i was thinking of. I found that I have to split the search to different step instead of making only one complicated query.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://540239]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2017-05-01 07:00 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (545 votes). Check out past polls.