860 likes | 986 Views
Master Course. MSc Bioinformatics for Health Sciences H15: Algorithms on strings and sequences Xavier Messeguer Peypoch (http://www.lsi.upc.es/~alggen) Dep. de Llenguatges i Sistemes Informàtics CEPBA-IBM Research Institute Universitat Politècnica de Catalunya. Contents.
E N D
Master Course MSc Bioinformatics for Health Sciences H15: Algorithms on strings and sequences Xavier Messeguer Peypoch (http://www.lsi.upc.es/~alggen) Dep. de Llenguatges i Sistemes Informàtics CEPBA-IBM Research Institute Universitat Politècnica de Catalunya
Contents 1. (Exact) String matching of one pattern 2. (Exact) String matching of many patterns 3. Extended string matching and regular expressions 4. Approximate string matching (Dynamic programming) 5. Pairwise and multiple alignment 6. Suffix trees
Master Course Second lecture: First part: Extended string matching
Extended string matching There are classes of characters represented by one Symbol. For instace the IUPAC code for the DNA alphabet is: R = {G,A} Y = {T,C} K = {G,T} M = {A,C} S = {G,C} W = {A,T} B = {G,T,C } D = {G,A,T} H = {A,C,T} V = {G,C,A} N = {A,G,C,T} (any) 1. Classes of characters in the tetx. There are characters in the text that represent sets of simbols 2. Classes of characters in the pattern. There are characters in the text that represent sets of simbols
Classes in the text Algorismes més eficients (Navarro & Raffinot) | | 64 32 16 Horspool 8 BOM BNDM 4 Long. patró 2 w 2 4 8 16 32 64 128 256
Classes in the text :Horspool example A 4 C 5 G 2 T 1 R ? … N ? Given the pattern ATGTA the shift table is:
Classes in the text :Horspool example A 4 C 5 G 2 T 1 R 2 … N ? Suposem que el patró és ATGTA La taula de salts seria:
Classes in the text :Horspool example Given the taxt : G T A R T R N A A G G A … A T G T A A T G T A A T G T A A 4 C 5 G 2 T 1 R 2 … N 1 Given the pattern ATGTA and the shift table:
Classes in the text :Horspool example IGiven the text : G T A R T R N A A G G A ... A T G T A A T G T A A T G T A A T G T A A 4 C 5 G 2 T 1 R 2 … N 1 Given the pattern ATGTA and the shift table: …
Classes in the text Algorismes més eficients (Navarro & Raffinot) BNDM : Backward Nondeterministic Dawg Matching | | BOM : Backward Oracle Matching 64 32 16 Horspool 8 BOM BNDM 4 Long. patró 2 w 2 4 8 16 32 64 128 256
Alg. Cerca exacta d’un patró (text on-line) Algorismes més eficients (Navarro & Raffinot) BNDM : Backward Nondeterministic Dawg Matching | | BOM : Backward Oracle Matching 64 32 16 Horspool 8 BOM BNDM 4 Long. patró 2 w 2 4 8 16 32 64 128 256
Classes in the text: BOM Com fa la comparació? Text : Patró : Autòmata: Factor Oracle Com es determina la següent posició de la finestra? Comproba si el sufix és factor del patró Però primer analitzem com fa la comparació…
Classes in the text: BOM example G T A G T T A G T A I la cerca sobre el text : G T A R T R N A A T G… Com fa la comparació? Es construeix l’autòmata del patró invers: Suposem que el patró és ATGTATG A T G T A T G No és possible cap millora!
Alg. Cerca exacta de molts patrons 8 | | (5 mots) Wu-Manber 4 SBOM Long. mínima 2 5 10 15 20 25 30 35 40 45 8 Wu-Manber (10 mots) (100 mots) 4 SBOM 8 Wu-Manber Ad AC 2 SBOM 4 5 10 15 20 25 30 35 40 45 Ad AC 2 5 10 15 20 25 30 35 40 45 Wu-Manber 8 (1000 mots) SBOM 4 Ad AC 2 5 10 15 20 25 30 35 40 45
Classes in the text: Set Horspool G T A T A T G G T A T A A T A A Search for the patterns ATGTATG,TATG,ATAAT,ATGTG In the text: ARTGNCTATGTGACA… <it’s not possible any improvment!
Classes in the text 8 | | (5 mots) Wu-Manber 4 SBOM Long. mínima 2 5 10 15 20 25 30 35 40 45 8 Wu-Manber (10 mots) (100 mots) 4 SBOM 8 Wu-Manber Ad AC 2 SBOM 4 5 10 15 20 25 30 35 40 45 Ad AC 2 5 10 15 20 25 30 35 40 45 Wu-Manber 8 (1000 mots) SBOM 4 Ad AC 2 5 10 15 20 25 30 35 40 45
Classes in the pattern Algorismes més eficients (Navarro & Raffinot) | | 64 32 16 Horspool 8 BOM BNDM 4 Long. patró 2 w 2 4 8 16 32 64 128 256
Classes in the text 8 | | (5 mots) Wu-Manber 4 SBOM Long. mínima 2 5 10 15 20 25 30 35 40 45 8 Wu-Manber (10 mots) (100 mots) 4 SBOM 8 Wu-Manber Ad AC 2 SBOM 4 5 10 15 20 25 30 35 40 45 Ad AC 2 5 10 15 20 25 30 35 40 45 Wu-Manber 8 (1000 mots) SBOM 4 Ad AC 2 5 10 15 20 25 30 35 40 45
Alg. Cerca exacta de molts patrons 8 | | (5 mots) Wu-Manber 4 SBOM Long. mínima 2 5 10 15 20 25 30 35 40 45 8 Wu-Manber (10 mots) (100 mots) 4 SBOM 8 Wu-Manber Ad AC 2 SBOM 4 5 10 15 20 25 30 35 40 45 Ad AC 2 5 10 15 20 25 30 35 40 45 Wu-Manber 8 (1000 mots) SBOM 4 Ad AC 2 5 10 15 20 25 30 35 40 45
Alg. Cerca exacta de molts patrons 8 | | (5 mots) Wu-Manber 4 SBOM Long. mínima 2 5 10 15 20 25 30 35 40 45 8 Wu-Manber (10 mots) (100 mots) 4 SBOM 8 Wu-Manber Ad AC 2 SBOM 4 5 10 15 20 25 30 35 40 45 Ad AC 2 5 10 15 20 25 30 35 40 45 Wu-Manber 8 (1000 mots) SBOM 4 Ad AC 2 5 10 15 20 25 30 35 40 45
Master Course Second lecture: Second part: Regular expressions matching
Expressions regulars Una expressió regular ℛés una cadena sobre ΣU { ε, |, · , * , (, ) } definida recursivament com: ε és una expressió regular Un caràcter de Σés una expressió regular ( ℛ ) és una expressió regular ℛ1 ·ℛ2és una expressió regular ℛ1 |ℛ2és una expressió regular ℛ *és una expressió regular
Llenguatge regular El llenguatge representat per una expressió regular és el conjunt dels mots que es poden construir a partir de l’expressió regular. El problema de buscar una expressió regular dins el text és el de buscar tots els factors que pertanyen al respectiu llenguatge regular.
Master Course Second lecture: Third part: Approximate string matching
Approximate string matching For instance, given the sequence CTACTACTACGTCTATACTGATCGTAGCTACTACATGC search for the pattern ACTGA allowing one error… … but what is the meaning of “one error”?
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)= d(ACT,AC)= d(ACT,C)= d(ACT,)= d(AC,ATC)= d(ACTTG,ATCTG)=
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)=0 d(ACT,AC)=1 d(ACT,C)=2 d(ACT,)= d(AC,ATC)= d(ACTTG,ATCTG)=
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)=0 d(ACT,AC)=1 d(ACT,C)=2 d(ACT,)= 3 d(AC,ATC)=1 d(ACTTG,ATCTG)=2
Edit distance and alignment of strings The Edit distance is related with the best alignment of strings Given d(ACT,ACT)=0 d(ACT,AC)=1 d(ACTTG,ATCTG)=2 which is the best alignment in every case? • ACT and ACT : ACT ACT • ACT and AC: ACT AC- ACTTG and ATCTG: ACTTG ATCTG ACT - TG A - TCTG
Edit distance and alignment of strings But which is the distance between the strings ACGCTATGCTATACG and ACGGTAGTGACGC? … and the best alignment between them? 1966 was the first time this problem was discussed… and the algorithm was proposed in 1968,1970,… using the technique called “Dynamic programming”
Approximate string matching For instance, given the sequence CTACTACTACGTCTATACTGATCGTAGCTACTACATGC search for the pattern ACTGA allowing one error… … but what is the meaning of “one error”?
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)= d(ACT,AC)= d(ACT,C)= d(ACT,)= d(AC,ATC)= d(ACTTG,ATCTG)=
Approximate string matching For instance, given the sequence CTACTACTACGTCTATACTGATCGTAGCTACTACATGC search for the pattern ACTGA allowing one error… … but what is the meaning of “one error”?
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)= d(ACT,AC)= d(ACT,C)= d(ACT,)= d(AC,ATC)= d(ACTTG,ATCTG)=
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)=0 d(ACT,AC)=1 d(ACT,C)=2 d(ACT,)= d(AC,ATC)= d(ACTTG,ATCTG)=
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)=0 d(ACT,AC)=1 d(ACT,C)=2 d(ACT,)= 3 d(AC,ATC)=1 d(ACTTG,ATCTG)=2
Edit distance and alignment of strings The Edit distance is related with the best alignment of strings Given d(ACT,ACT)=0 d(ACT,AC)=1 d(ACTTG,ATCTG)=2 which is the best alignment in every case? • ACT and ACT : ACT ACT • ACT and AC: ACT AC- ACTTG and ATCTG: ACTTG ATCTG ACT - TG A - TCTG
Edit distance and alignment of strings But which is the distance between the strings ACGCTATGCTATACG and ACGGTAGTGACGC? … and the best alignment between them? 1966 was the first time this problem was discussed… and the algorithm was proposed in 1968,1970,… using the technique called “Dynamic programming”
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)=0 d(ACT,AC)=1 d(ACT,C)=2 d(ACT,)= d(AC,ATC)= d(ACTTG,ATCTG)=
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)=0 d(ACT,AC)=1 d(ACT,C)=2 d(ACT,)= 3 d(AC,ATC)=1 d(ACTTG,ATCTG)=2
Edit distance and alignment of strings The Edit distance is related with the best alignment of strings Given d(ACT,ACT)=0 d(ACT,AC)=1 d(ACTTG,ATCTG)=2 which is the best alignment in every case? • ACT and ACT : ACT ACT • ACT and AC: ACT AC- ACTTG and ATCTG: ACTTG ATCTG ACT - TG A - TCTG
Edit distance and alignment of strings But which is the distance between the strings ACGCTATGCTATACG and ACGGTAGTGACGC? … and the best alignment between them? 1966 was the first time this problem was discussed… and the algorithm was proposed in 1968,1970,… using the technique called “Dynamic programming”
Edit distance and alignment of strings C T A C T A C T A C G T A C T G A
Edit distance and alignment of strings C T A C T A C T A C G T A C T G A
Edit distance and alignment of strings C T A C T A C T A C G T A C T G A The cell contains the distance between AC and CTACT.
Approximate string matching For instance, given the sequence CTACTACTACGTCTATACTGATCGTAGCTACTACATGC search for the pattern ACTGA allowing one error… … but what is the meaning of “one error”?
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)= d(ACT,AC)= d(ACT,C)= d(ACT,)= d(AC,ATC)= d(ACTTG,ATCTG)=
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)=0 d(ACT,AC)=1 d(ACT,C)=2 d(ACT,)= d(AC,ATC)= d(ACTTG,ATCTG)=
Edit distance Indel We accept three types of errors: 1. Mismatch: ACCGTGAT ACCGAGAT 2. Insertion: ACCGTGAT ACCGATGAT 3. Deletion: ACCGTGAT ACCGGAT The edit distance d between two strings is the minimum number of substitutions,insertions and deletions needed to transform the first string into the second one d(ACT,ACT)=0 d(ACT,AC)=1 d(ACT,C)=2 d(ACT,)= 3 d(AC,ATC)=1 d(ACTTG,ATCTG)=2
Edit distance and alignment of strings The Edit distance is related with the best alignment of strings Given d(ACT,ACT)=0 d(ACT,AC)=1 d(ACTTG,ATCTG)=2 which is the best alignment in every case? • ACT and ACT : ACT ACT • ACT and AC: ACT AC- ACTTG and ATCTG: ACTTG ATCTG ACT - TG A - TCTG