8. Regular Expression Quick Guide
^ Matches the beginning of a line
$ Matches the end of the line
. Matches any character
s Matches whitespace
S Matches any non-whitespace character
* Repeats a character zero or more times
*? Repeats a character zero or more times (non-greedy)
+ Repeats a chracter one or more times
+? Repeats a character one or more times (non-greedy)
[aeiou] Matches a single character in the listed set
[^XYZ] Matches a single character not in the listed set
[a-z0-9] The set of characters can include a range
( Indicates where string extraction is to start
) Indicates where string extraction is to end
9. Example
import re
dna = "ATCGCGAATTCAC"
if re.search(r"GAATTC", dna):
print("restriction site found!")
10. • Predict the fragment lengths that we will get
if we digest the sequence with two
restriction enzymes – EcoRI, whose
recognition site is G/AATTC alone.
• With BamHI, whose recognition site is
G/GATCG alone
• And when we do a double digest
• The forward slashes (/) in the recognition
sites represent the place where the
enzyme cuts the DNA.
• http://rebase.neb.com/rebase/rebase.html
Double digest
12. Towards a protein prosite scanner
N-{P}-[ST]-{P}.
[RK](2)-x-[ST].
[ST]-x-[RK].
[ST]-x(2)-[DE].
[RK]-x(2,3)-[DE]-x(2,3)-Y.
G-{EDRKHPFYW}-x(2)-[STAGCN]-{P}.
x-G-[RK]-[RK].
C-x-[DN]-x(4)-[FY]-x-C-x-C.
E-x(2)-[ERK]-E-x-C-x(6)-[EDR]-x(10,11)-[FYA]-[YW].
[DEQGSTALMKRH]-[LIVMFYSTAC]-[GNQ]-[LIVMFYAG]-[DNEKHS]-S-[LIVMST]-{PCFY}-[STAGCPQLIVMF]-[LIVMATN]-[DENQGTAKRHLM]-[LIVMWSTA]-
[LIVGSTACR]-{LPIY}-{VY}-[LIVMFA].
[KRHQSA]-[DENQ]-E-L>.
R-G-D.
[AG]-x(4)-G-K-[ST].
D-{W}-[DNS]-{ILVFYW}-[DENSTG]-[DNQGHRK]-{GP}-[LIVMC]-[DENQSTAGC]-x(2)-[DE]-[LIVMFYW].
[EQ]-{LNYH}-x-[ATV]-[FY]-{LDAM}-{T}-W-{PG}-N.
[LIVM]-x-[SGNL]-[LIVMN]-[DAGHENRS]-[SAG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QRF]-[LIVMFY]-x(4,5)-[LFY]-x(3)-
[FYIVA]-{FYWHCM}-{PGVI}-x(2)-[GSADENQKR]-x-[NSTAPKL]-[PARL].
Scan for the following prosite patterns in your 4 sequences
Hint: translate the patters to regexes and then scan
13. reuse galacto.py in github
Consensus_pattern="G-R-x-N-[LIV]-I-G-[DE]-H-x-D-Y"
pattern=Consensus_pattern.replace("-","")
pattern=pattern.replace("x","[A-Z]")
#print(pattern)
count=0
for s in sequences:
count=count+1
print ("searching seq",count)
s=s.replace(" ","")
matches = re.finditer(pattern,s)
for match in matches:
print (match.group(0),"from: ",match.start(),"to: ",match.end())