Combinatorial Pattern Matching. CS 466 Saurabh Sinha

Similar documents
11/5/09 Comp 590/Comp Fall

Combinatorial Pattern Matching

11/5/13 Comp 555 Fall

Example of repeats: ATGGTCTAGGTCCTAGTGGTC Motivation to find them: Genomic rearrangements are often associated with repeats Trace evolutionary

COMBINATORIAL PATTERN MATCHING

Combinatorial Pattern Matching

CMSC423: Bioinformatic Algorithms, Databases and Tools. Exact string matching: Suffix trees Suffix arrays

Exact String Matching. The Knuth-Morris-Pratt Algorithm

CS481: Bioinformatics Algorithms

EECS730: Introduction to Bioinformatics

Exact Matching: Hash-tables and Automata

Lecture 5: Suffix Trees

BLAST: Basic Local Alignment Search Tool Altschul et al. J. Mol Bio CS 466 Saurabh Sinha

Suffix trees and applications. String Algorithms

Data structures for string pattern matching: Suffix trees

Suffix Arrays CMSC 423

Project Proposal. ECE 526 Spring Modified Data Structure of Aho-Corasick. Benfano Soewito, Ed Flanigan and John Pangrazio

Applied Databases. Sebastian Maneth. Lecture 14 Indexed String Search, Suffix Trees. University of Edinburgh - March 9th, 2017

Divya R. Singh. Faster Sequence Alignment using Suffix Tree and Data-Mining Techniques. February A Thesis Presented by

String Matching. Pedro Ribeiro 2016/2017 DCC/FCUP. Pedro Ribeiro (DCC/FCUP) String Matching 2016/ / 42

Applications of Suffix Tree

4. Suffix Trees and Arrays

4. Suffix Trees and Arrays

Dynamic Programming: Sequence alignment. CS 466 Saurabh Sinha

COMBINATORIAL PATTERN MATCHING

CSCI2950-C Lecture 4 DNA Sequencing and Fragment Assembly

BLAST & Genome assembly

Suffix Tree and Array

FINDING APPROXIMATE REPEATS WITH MULTIPLE SPACED SEEDS

Alignment of Long Sequences

Dynamic Programming Part I: Examples. Bioinfo I (Institut Pasteur de Montevideo) Dynamic Programming -class4- July 25th, / 77

splitmem: graphical pan-genome analysis with suffix skips Shoshana Marcus May 7, 2014

Project Proposal. ECE 526 Spring Modified Data Structure of Aho-Corasick. Benfano Soewito, Ed Flanigan and John Pangrazio

From Smith-Waterman to BLAST

TCCAGGTG-GAT TGCAAGTGCG-T. Local Sequence Alignment & Heuristic Local Aligners. Review: Probabilistic Interpretation. Chance or true homology?

Indexing and Searching

An introduction to suffix trees and indexing

Suffix links are stored for compact trie nodes only, but we can define and compute them for any position represented by a pair (u, d):

Inexact Pattern Matching Algorithms via Automata 1

17 dicembre Luca Bortolussi SUFFIX TREES. From exact to approximate string matching.

Lecture 7 February 26, 2010

Computational Molecular Biology

CSE 417 Dynamic Programming (pt 5) Multiple Inputs

USING AN EXTENDED SUFFIX TREE TO SPEED-UP SEQUENCE ALIGNMENT

Suffix Arrays Slides by Carl Kingsford

Knuth-Morris-Pratt. Kranthi Kumar Mandumula Indiana State University Terre Haute IN, USA. December 16, 2011

SORTING. Practical applications in computing require things to be in order. To consider: Runtime. Memory Space. Stability. In-place algorithms???

Graph Algorithms in Bioinformatics

COMP4128 Programming Challenges

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Given a text file, or several text files, how do we search for a query string?

An Improved Query Time for Succinct Dynamic Dictionary Matching

String Matching Algorithms

Introduction to Suffix Trees

Chapter 7. Space and Time Tradeoffs. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Indexing and Searching

Reconstructing long sequences from overlapping sequence fragment. Searching databases for related sequences and subsequences

DNA Sequencing. Overview

CSC Design and Analysis of Algorithms. Lecture 9. Space-For-Time Tradeoffs. Space-for-time tradeoffs

Sequencing. Computational Biology IST Ana Teresa Freitas 2011/2012. (BACs) Whole-genome shotgun sequencing Celera Genomics

Indexing and Searching

Lowest Common Ancestor (LCA) Queries

FastA & the chaining problem

FastA and the chaining problem, Gunnar Klau, December 1, 2005, 10:

Introduction to Computational Molecular Biology

Mapping Reads to Reference Genome

Accurate Long-Read Alignment using Similarity Based Multiple Pattern Alignment and Prefix Tree Indexing

Subject Index. Journal of Discrete Algorithms 5 (2007)

24 Grundlagen der Bioinformatik, SS 10, D. Huson, April 26, This lecture is based on the following papers, which are all recommended reading:

The Language for Specifying Lexical Analyzer

Genome 373: Mapping Short Sequence Reads I. Doug Fowler

Special course in Computer Science: Advanced Text Algorithms

Figure 1. The Suffix Trie Representing "BANANAS".

Longest Common Substring

University of Waterloo CS240 Spring 2018 Help Session Problems

Lecture 6: Suffix Trees and Their Construction

6.047 / Computational Biology: Genomes, Networks, Evolution Fall 2008

Exact String Matching Part II. Suffix Trees See Gusfield, Chapter 5

Suffix Trees. Martin Farach-Colton Rutgers University & Tokutek, Inc

DNA Sequencing The Shortest Superstring & Traveling Salesman Problems Sequencing by Hybridization

Fast Substring Matching

Genome 373: Genome Assembly. Doug Fowler

Longest Common Subsequence

String Matching Algorithms

Regular Expression Constrained Sequence Alignment

Small-Space 2D Compressed Dictionary Matching

A THEORETICAL ANALYSIS OF SCALABILITY OF THE PARALLEL GENOME ASSEMBLY ALGORITHMS

Omega: an Overlap-graph de novo Assembler for Metagenomics

String matching algorithms

BUNDLED SUFFIX TREES

Administrative. Machine learning code. Supervised learning (e.g. classification) Machine learning: Unsupervised learning" BANANAS APPLES

Proceedings of the 11 th International Conference for Informatics and Information Technology

Lecture L16 April 19, 2012

Index-assisted approximate matching

OPEN MP-BASED PARALLEL AND SCALABLE GENETIC SEQUENCE ALIGNMENT

Lectures by Volker Heun, Daniel Huson and Knut Reinert, in particular last years lectures

CSED233: Data Structures (2017F) Lecture12: Strings and Dynamic Programming

Computational Molecular Biology

Boyer-Moore. Ben Langmead. Department of Computer Science

CSCI S-Q Lecture #13 String Searching 8/3/98

Transcription:

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-Corasick algorithm 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 linear (Weiner suffix tree algorithm) Suffix Tree 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 text Extend perfect match of length l until we find an approximate match of length n with k mismatches