Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

Greetings,
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
idiom.

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?

Update
grep was not what I wanted after all...

-InjunJoel
"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


Comment on Re: generate regular expression
Select or Download Code
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.

    Pierre

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://540239]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-09-17 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (54 votes), past polls