Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: generate regular expression

by injunjoel (Priest)
on Mar 30, 2006 at 18:53 UTC ( [id://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

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.

    Pierre

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-20 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found