Combinatorial Pattern Matching CS 466 Saurabh Sinha.

Slides:



Advertisements
Similar presentations
CS 336 March 19, 2012 Tandy Warnow.
Advertisements

Indexing DNA Sequences Using q-Grams
Combinatorial Pattern Matching CS 466 Saurabh Sinha.
Fa07CSE 182 CSE182-L4: Database filtering. Fa07CSE 182 Summary (through lecture 3) A2 is online We considered the basics of sequence alignment –Opt score.
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Space-for-Time Tradeoffs
Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
UNIVERSITY OF SOUTH CAROLINA College of Engineering & Information Technology Bioinformatics Algorithms and Data Structures Chapter : k-difference.
Suffix Trees Specialized form of keyword trees New ideas –preprocess text T, not pattern P O(m) preprocess time O(n+k) search time –k is number of occurrences.
15-853Page : Algorithms in the Real World Suffix Trees.
OUTLINE Suffix trees Suffix arrays Suffix trees Indexing techniques are used to locate highest – scoring alignments. One method of indexing uses the.
296.3: Algorithms in the Real World
© 2004 Goodrich, Tamassia Tries1. © 2004 Goodrich, Tamassia Tries2 Preprocessing Strings Preprocessing the pattern speeds up pattern matching queries.
1 Prof. Dr. Th. Ottmann Theory I Algorithm Design and Analysis (12 - Text search: suffix trees)
21/05/2015Applied Algorithmics - week51 Off-line text search (indexing)  Off-line text search refers to the situation in which a preprocessed digital.
Tries Standard Tries Compressed Tries Suffix Tries.
Tries Search for ‘bell’ O(n) by KMP algorithm O(dm) in a trie Tries
Combinational Pattern Matching Shashank Kadaveru.
Suffix Trees String … any sequence of characters. Substring of string S … string composed of characters i through j, i ate is.
Pattern Matching1. 2 Outline and Reading Strings (§9.1.1) Pattern matching algorithms Brute-force algorithm (§9.1.2) Boyer-Moore algorithm (§9.1.3) Knuth-Morris-Pratt.
Goodrich, Tamassia String Processing1 Pattern Matching.
. Class 4: Fast Sequence Alignment. Alignment in Real Life u One of the major uses of alignments is to find sequences in a “database” u Such collections.
Sequence Alignment Storing, retrieving and comparing DNA sequences in Databases. Comparing two or more sequences for similarities. Searching databases.
Dynamic Text and Static Pattern Matching Amihood Amir Gad M. Landau Moshe Lewenstein Dina Sokol Bar-Ilan University.
String Matching COMP171 Fall String matching 2 Pattern Matching * Given a text string T[0..n-1] and a pattern P[0..m-1], find all occurrences of.
Sequence Alignment Variations Computing alignments using only O(m) space rather than O(mn) space. Computing alignments with bounded difference Exclusion.
Combinatorial Pattern Matching
6/29/20151 Efficient Algorithms for Motif Search Sudha Balla Sanguthevar Rajasekaran University of Connecticut.
Fa05CSE 182 CSE182-L5: Scoring matrices Dictionary Matching.
Aho-Corasick Algorithm Generalizes KMP to handle sets of strings New ideas –keyword trees –failure functions/links –output links.
UNIVERSITY OF SOUTH CAROLINA College of Engineering & Information Technology Bioinformatics Algorithms and Data Structures Chapter 12.3: Exclusion Methods.
Building Suffix Trees in O(m) time Weiner had first linear time algorithm in 1973 McCreight developed a more space efficient algorithm in 1976 Ukkonen.
Pattern Matching1. 2 Outline Strings Pattern matching algorithms Brute-force algorithm Boyer-Moore algorithm Knuth-Morris-Pratt algorithm.
1 Exact Set Matching Charles Yan Exact Set Matching Goal: To find all occurrences in text T of any pattern in a set of patterns P={p 1,p 2,…,p.
On the Use of Regular Expressions for Searching Text Charles L.A. Clarke and Gordon V. Cormack Fast Text Searching.
String Matching. Problem is to find if a pattern P[1..m] occurs within text T[1..n] Simple solution: Naïve String Matching –Match each position in the.
Space-Efficient Sequence Alignment Space-Efficient Sequence Alignment Bioinformatics 202 University of California, San Diego Lecture Notes No. 7 Dr. Pavel.
1 Generalized Tree Alignment: The Deferred Path Heuristic Stinus Lindgreen
COMP3456 – adapted from textbook slides Combinatorial Pattern Matching.
MCS 101: Algorithms Instructor Neelima Gupta
UNIVERSITY OF SOUTH CAROLINA College of Engineering & Information Technology Bioinformatics Algorithms and Data Structures Chapter 1: Exact String Matching.
Tries1. 2 Outline and Reading Standard tries (§9.2.1) Compressed tries (§9.2.2) Suffix tries (§9.2.3)
BLAST: Basic Local Alignment Search Tool Altschul et al. J. Mol Bio CS 466 Saurabh Sinha.
Book: Algorithms on strings, trees and sequences by Dan Gusfield Presented by: Amir Anter and Vladimir Zoubritsky.
Short Read Mapper Evan Zhen CS 124. Introduction Find a short sequence in a very long DNA sequence Motivation – It is easy to sequence everyone’s genome,
1 CS 430: Information Discovery Lecture 4 Files Structures for Inverted Files.
MCS 101: Algorithms Instructor Neelima Gupta
String Matching String Matching Problem We introduce a general framework which is suitable to capture an essence of compressed pattern matching according.
Combinatorial Pattern Matching An Introduction to Bioinformatics Algorithms (Jones and Pevzner)
10/30/2012COMP 555 Bioalgorithms (Fall 2012)1 Lecture 16: Combinatorial Pattern Matching Study Chapter 9.1 – 9.5.
Suffix Tree 6 Mar MinKoo Seo. Contents  Basic Text Searching  Introduction to Suffix Tree  Suffix Trees and Exact Matching  Longest Common Substring.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Advanced Data Structures Lecture 8 Mingmin Xie. Agenda Overview Trie Suffix Tree Suffix Array, LCP Construction Applications.
Tries 4/16/2018 8:59 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
15-853:Algorithms in the Real World
13 Text Processing Hongfei Yan June 1, 2016.
CSE 5290: Algorithms for Bioinformatics Fall 2011
CSE 5290: Algorithms for Bioinformatics Fall 2009
Chapter 7 Space and Time Tradeoffs
Pattern Matching 1/14/2019 8:30 AM Pattern Matching Pattern Matching.
Combinatorial Pattern Matching
KMP String Matching Donald Knuth Jim H. Morris Vaughan Pratt 1997.
Pattern Matching 2/15/2019 6:17 PM Pattern Matching Pattern Matching.
Suffix Trees String … any sequence of characters.
Space-for-time tradeoffs
Tries 2/27/2019 5:37 PM Tries Tries.
Suffix Arrays and Suffix Trees
Pattern Matching Pattern Matching 5/1/2019 3:53 PM Spring 2007
Space-for-time tradeoffs
Sequences 5/17/ :43 AM Pattern Matching.
Presentation transcript:

Combinatorial Pattern Matching CS 466 Saurabh Sinha

Genomic Repeats Example of repeats: –ATGGTCTAGGTCCTAGTGGTC Motivation to find them: –Genomic rearrangements are often associated with repeats –Trace evolutionary secrets –Many tumors are characterized by an explosion of repeats

Genomic Repeats The problem is often more difficult: –ATGGTCTAGGACCTAGTGTTC Motivation to find them: –Genomic rearrangements are often associated with repeats –Trace evolutionary secrets –Many tumors are characterized by an explosion of repeats

l -mer Repeats Long repeats are difficult to find Short repeats are easy to find (e.g., hashing) Simple approach to finding long repeats: –Find exact repeats of short l -mers ( l is usually 10 to 13) –Use l -mer repeats to potentially extend into longer, maximal repeats

l -mer Repeats (cont’d) There are typically many locations where an l -mer is repeated: GCTTACAGATTCAGTCTTACAGATGGT The 4-mer TTAC starts at locations 3 and 17

Extending l -mer Repeats GCTTACAGATTCAGTCTTACAGATGGT Extend these 4-mer matches: GCTTACAGATTCAGTCTTACAGATGGT Maximal repeat: CTTACAGAT

Maximal Repeats To find maximal repeats in this way, we need ALL start locations of all l -mers in the genome Hashing lets us find repeats quickly in this manner

Hashing: Maximal Repeats To find repeats in a genome: –For all l -mers in the genome, note the start position and the sequence –Generate a hash table index for each unique l -mer sequence –In each index of the hash table, store all genome start locations of the l -mer which generated that index –Extend l -mer repeats to maximal repeats

Pattern Matching What if, instead of finding repeats in a genome, we want to find all sequences in a database that contain a given pattern? This leads us to a different problem, the Pattern Matching Problem

Pattern Matching Problem Goal: Find all occurrences of a pattern in a text Input: Pattern p = p 1 …p n and text t = t 1 …t m Output: All positions 1< i < (m – n + 1) such that the n-letter substring of t starting at i matches p Motivation: Searching database for a known pattern

Exact Pattern Matching: Running Time Naïve runtime: O(nm) On average, it’s more like O(m) –Why? Can solve problem in O(m) time ? –Yes, we’ll see how (later)

Generalization of problem: Multiple Pattern Matching Problem Goal: Given a set of patterns and a text, find all occurrences of any of patterns in text Input: k patterns p 1,…,p k, and text t = t 1 …t m Output: Positions 1 < i < m where substring of t starting at i matches p j for 1 < j < k Motivation: Searching database for known multiple patterns Solution: k “pattern matching problems”: O(kmn) Solution: Using “Keyword trees” => O(kn+m) where n is maximum length of p i

Keyword Trees: Example Keyword tree: –Apple

Keyword Trees: Example (cont’d) Keyword tree: –Apple –Apropos

Keyword Trees: Example (cont’d) Keyword tree: –Apple –Apropos –Banana

Keyword Trees: Example (cont’d) Keyword tree: –Apple –Apropos –Banana –Bandana

Keyword Trees: Example (cont’d) Keyword tree: –Apple –Apropos –Banana –Bandana –Orange

Keyword Trees: Properties –Stores a set of keywords in a rooted labeled tree –Each edge labeled with a letter from an alphabet –Any two edges coming out of the same vertex have distinct labels –Every keyword stored can be spelled on a path from root to some leaf

Multiple Pattern Matching: Keyword Tree Approach Build keyword tree in O(kn) time; kn is total length of all patterns Start “threading” at each position in text; at most n steps tell us if there is a match here to any p i O(kn + nm) Aho-Corasick algorithm: O(kn + m)

Aho-Corasick algorithm

“Fail” edges in keyword tree Dashed edge out of internal node if matching edge not found

“Fail” edges in keyword tree If currently at node q representing word L(q), find the longest proper suffix of L(q) that is a prefix of some pattern, and go to the node representing that prefix Example: node q = 5 L(q) = she; longest proper suffix that is a prefix of some pattern: “he”. Dashed edge to node q’=2

Automaton Transition among the different nodes by following edges depending on next character seen (“c”) If outgoing edge with label “c”, follow it If no such edge, and are at root, stay If no such edge, and at non-root, follow dashes edge (“fail” transition); DO NOT CONSUME THE CHARACTER (“c”) Example: search text “ushers” with the automaton

Aho-Corasickalgorithm O(kn) to build the automaton O(m) to search a text of length m Key insight: –For every character “consumed”, we move at most one level deeper (away from root) in the tree. Therefore total number of such “away from root” moves is <= m –Each fail transition moves us at least one level closer to root. Therefore total number of such “towards root” moves is <= m (you cant climb up more than you climbed down)

Suffix tree Build a tree from the text Used if the text is expected to be the same during several pattern queries Tree building is O(m) where m is the size of the text. This is preprocessing. Given any pattern of length n, we can answer if it occurs in text in O(n) time Suffix tree = “modified” keyword tree of all suffixes of text

Suffix Tree=Collapsed Keyword Trees Similar to keyword trees, except edges that form paths are collapsed –Each edge is labeled with a substring of a text –All internal edges have at least two outgoing edges –Leaves labeled by the index of the pattern.

Suffix Tree of a Text Suffix trees of a text is constructed for all its suffixes ATCATG TCATG CATG ATG TG G quadratic Keyword Tree Suffix Tree Time is linear in the total size of all suffixes, i.e., it is quadratic in the length of the text

Suffix Trees: Advantages Suffix trees build faster than keyword trees ATCATG TCATG CATG ATG TG G quadratic Keyword Tree Suffix Tree linear (Weiner suffix tree algorithm) Time to find k patterns of length n: O(m + kn)

Suffix Trees: Example

Multiple Pattern Matching: Summary Keyword and suffix trees are used to find patterns in a text Keyword trees: –Build keyword tree of patterns, and thread text through it Suffix trees: –Build suffix tree of text, and thread patterns through it

Approximate vs. Exact Pattern Matching So far all we’ve seen exact pattern matching algorithms Usually, because of mutations, it makes much more biological sense to find approximate pattern matches Biologists often use fast heuristic approaches (rather than local alignment) to find approximate matches

Heuristic Similarity Searches Genomes are huge: Smith-Waterman quadratic alignment algorithms are too slow Alignment of two sequences usually has short identical or highly similar fragments Many heuristic methods (i.e., FASTA) are based on the same idea of filtration –Find short exact matches, and use them as seeds for potential match extension

Query Matching Problem Goal: Find all substrings of the query that approximately match the text Input: Query q = q 1 …q w, text t = t 1 …t m, n (length of matching substrings), k (maximum number of mismatches) Output: All pairs of positions (i, j) such that the n-letter substring of q starting at i approximately matches the n-letter substring of t starting at j, with at most k mismatches

Query Matching: Main Idea Approximately matching strings share some perfectly matching substrings. Instead of searching for approximately matching strings (difficult) search for perfectly matching substrings (easy).

Filtration in Query Matching We want all n-matches between a query and a text with up to k mismatches “Filter” out positions we know do not match between text and query Potential match detection: find all matches of l -tuples in query and text for some small l Potential match verification: Verify each potential match by extending it to the left and right, until (k + 1) mismatches are found

Filtration: Match Detection If x 1 …x n and y 1 …y n match with at most k mismatches, they must share an l -tuple that is perfectly matched, with l =  n/(k + 1)  Break string of length n into k+1 parts, each each of length  n/(k + 1)  –k mismatches can affect at most k of these k+1 parts –At least one of these k+1 parts is perfectly matched

Filtration: Match Verification For each l -match we find, try to extend the match further to see if it is substantial query Extend perfect match of length l until we find an approximate match of length n with k mismatches text