Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Pattern searching allowing for mis-matches...

by bv (Friar)
on Dec 14, 2009 at 00:08 UTC ( [id://812627]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Pattern searching allowing for mis-matches...
in thread Pattern searching allowing for mis-matches...

Your second question is much easier: Yes. Regular expressions can be built from any string, including those supplied by users. Generally, you should use quotemeta or the \Q and \E markers to make sure the string is free from regular expression meta characters like *, ., and more evil eval-type expressions. In your case, you could also check that the string is a valid nt sequence:

my $string = quotemeta shift; die "Not a valid nucleotide sequence" if $string =~ /[^AGTC]/;

As for the first question, one way would be to build a regex for each possibility. An example:

my $string = "TGAT"; my @nts = map { my $tmp = $string; substr $tmp, $_, 1, '.'; $tmp; } (0 .. length ($string) -1); my $groupings = join '|', @nts; my $sample = "TGATTGGAATGTTAGAT"; while ( $sample =~ /($groupings)/go ) { print "Matched $1 ending at position ", pos $sample, "\n"; }

@_=qw; Just another Perl hacker,; ;$_=q=print "@_"= and eval;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found