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
Untested Idea!
-InjunJoel
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
idiom.(@array) = $string =~ /$pattern/g
Untested Idea!
Is that sort of what you were thinking of?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"; } }
-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 |
In Section
Seekers of Perl Wisdom