COMP 364-Lecture 23 (2008-03-03)
No announcements
Last class:
•	Pattern matching and strings

Today:
1.	More patterns (textbook chapter 7; chapter 6 in Jamison)

We've got a string (could be sequence data, gene coding, etc):
-$Str = 

We write it like: (where '~' is the binding operator)
if ($Str =~ /<Pattern>/)
		/abc/

•	if the string is abc, we have a match
•	if the string is xyz, no match
•	if the string is xyabcz, we have a match
•	if the string is xaybzc, no match

But we can do more interesting things with this:
“Alternation”
$Str =~/a|b|c/  --> where there is a match if anywhere there is an a, b or c
        = ~/a|e|i|o|u -->matches a lower case vowel
        =~/cat|dog/ --> matches if cat or dog are found anywhere in the string

Suppose you wanted to match:  bat, bet, bit, bot, but:
=~/bat|bet|...|but/ -->a bit laborious

ALTERNATIVELY:
=~/b(a|e|i|o|u)t/
=~/ba|e|i|o|ut/  

Wrote program: Pat1.pl
 After the match (if its true), you could use three special perl characters in the print command to see which parts matched:
$'= part of string before match
$& = match goes here
$' = part of string after match

-->created alternative program but place parentheses around all the vowels. The result was that there were some values that didn't match.

Character classes: Allow alternation of a set of characters (mostly covered last class)
for example:
=~/\d/ -->matches any digit 
=~/0|1|1|...|9/

Repetition: Say you're interested in protein localization, so you have a protein sequence Pseq:

$Pseq = “ABDEGKIKL...”

you may have noticed that all proteins localizing to a certain organelle might contain:
BDEDA
BDEEDA
BDEEEDA

in certain places of the protein sequence. You therefore hypothesize that you could look for those patterns (perhaps to identify other proteins in the database that may also localize).

=~BD(E|EE|EEE)DA/
or you could write
=~BD(E{1,3})DA/ -->which looks for BD and then looks for 1-3 E characters, then for DA.

/AB{3,3}C/ -->exactly 3 B characters
/(AB){3,3}C/ -->searches for 'AB' repeated three times followed by a C
ABABABC
Program: Pat3.pl:

=~/AB{3}C/ -->where {3} means exactly 3 B characters
=~AB{3,}C/ -->at least 3 but as many as infinite B characters

=~/AB{0,}C/ --> equivalent to =~AB*C/
-->matches AC,ABC,ABBC,...
=~/AB{1,}C/...same as =~/AB+C/

Wildcard: . -->matches any character except \n
=~/A.{3}C/

Program: Pat4.pl and Pat5.pl

More examples: 
To match
AC
or
ABC
=~/AB{0,1}C/
=~/AB?C/ -->'?' means zero or one copies