Algorithms in Bioinformatics I, WS06/07, C.Dieterich 47 5 BLAST and FASTA This lecture is based on the following, which are all recommended reading: D.J. Lipman and W.R. Pearson, Rapid and Sensitive Protein Similarity Searches. Science 227, 1435-1441 (1985). Pearson, W. R. and Lipman, D. J. Improved tools for biological sequence comparison. Proc. Natl. Acad. Sci USA 85, 2444-2448 (1988). S.F. Altschul, W. Gish, W. Miller, E.W. Myers and D.J. Lipman. Basic local alignment search tool, J. Molecular Biology, 215:403-410 (1990). http://www.ncbi.nlm.nih.gov/blast/tutorial/altschul-1.html D. Gusfield, Algorithms on strings, trees and sequences, pg. 376 381, 1997. I. Eidhammer, I. Jonassen, W.R. Taylor, Protein Bioinformatics, pg. 34 64, 2004. 5.1 Introduction Pairwise alignment is used to detect homologies between different protein or DNA sequences, e.g. as global or local alignments. This can be solved using dynamic programming in time proportional to the product of the lengths of the two sequences being compared. However, this is too slow for searching current databases and in practice algorithms are used that run much faster, at the expense of possibly missing some significant hits due to the heuristics employed. Such algorithms are usually seed-and-extend approaches in which first small exact matches are found, which are then extended to obtain long inexact ones. The following strategies have devised their algorithms such that a large part of the computation is already finished. This leads to algorithms for which the query is broken up into short substrings. Afterwards those database entries are searched that contain a certain number of these and similar substrings in the right order. For biological sequences of length n there are 4 n (for the DNA-alphabet Σ = {A, G, C, T }) and/or 20 n (for the amino acid alphabet) different strings. For n not too large, it is possible to store all in a hash table. Since this is a very time intensive procedure, a certain consistency of the database entries is assumed. The large sequence databases are therefore split into two parts: one consists of the constant part, containing all the sequences that were used for the first table, and of a dynamic part, containing all new entries.
Algorithms in Bioinformatics I, WS06/07, C.Dieterich 48 5.2 BLAST BLAST, the Basic Local Alignment Search Tool (Altschul et al., 1990), is perhaps the most widely used bioinformatics tool ever written. It is an alignment heuristic that determines local alignments between a query and a database. It uses an approximation of the Smith-Waterman algorithm. BLAST consists of two components: a search algorithm and computation of the statistical significance of solutions. BLAST starts with the localization of substrings (so-called segment pairs or hits) in two sequences that have a certain similarity score. The hits are the starting point for deriving HSPs, locally optimal pairs that contain the hit. Extending to the left or right of an HSP would lead to a lower score. 5.2.1 BLAST terminology Definition 5.1. Let q be the query and d the database. A segment is simply a substring s of q or d. A segment-pair (s, t) (or hit) consists of two segments, one in q and one d, of the same length. Example: V A L L A R P A M M A R We think of s and t as being aligned without gaps and score this alignment using a substitution score matrix, e.g. BLOSUM or PAM in the case of protein sequences. The alignment score for (s, t) is denoted by σ(s, t). Definition 5.2. A locally maximal segment pair (LMSP) is any segment pair (s, t) whose score cannot be improved by shortening or extending the segment pair. A maximum segment pair (MSP) is any segment pair (s, t) of maximal alignment score σ(s, t). Given a cutoff score S, a segment pair (s, t) is called a high-scoring segment pair (HSP), if it is locally maximal and σ(s, t) S. Finally, a word is simply a short substring of fixed length w. Given S, the goal of BLAST is to compute all HSPs.
Algorithms in Bioinformatics I, WS06/07, C.Dieterich 49 5.2.2 The BLAST algorithm Given three parameters, i.e. a word size w, a word similarity threshold T and a minimum cut-off score S. Then we are looking for a segment pair with a score of at least S that contains at least one word pair of length w with score at least T. For protein sequences, BLAST operates as follows: Preprocessing: Of the query sequence q first all words of length w are generated. Then a list of all w-mers of length w over the alphabet Σ that have similarity > T to some word in the query sequence q is generated. Example: For the query sequence RQCSAGW the list of words of length w = 2 with a score T > 8 using the BLOSUM62 matrix are: word 2 mer with score > 8 RQ RQ QC QC, RC, EC, NC, DC, KC, MC, SC CS CS,CA,CN,CD,CQ,CE,CG,CK,CT SA - AG AG GW GW,AW,RW,NW,DW,QW,EW,HW,KW,PW,SW,TW,WW The search algorithm consists then of three steps: 1. Localization of the hits: The database sequence d is scanned for all hits t of w-mers s in the list, and the position of the hit is saved. 2. Detection of hits: First all pairs of hits are searched that have a distance of at most A (think of them lying on the same diagonal in the matrix of the SW-algorithm). 3. Extension to HSPs: Each such seed (s, t) is extended in both directions until its score σ(s, t) cannot be enlarged (LMSP). Then all best extensions are reported that have score S, these are the HSPs. Originally the extension did not include gaps, the modern BLAST2 algorithm allows insertion of gaps. In practice, w = 3 and A = 40 for proteins. With care, the list of all words of length w that have similarity > T to some word in the query sequence q can be produced in time proportional to the number of words in the list. These are placed in a keyword tree and then, for each word in the tree, all exact locations of the word in the database d are detected in time linear to the length of d.
Algorithms in Bioinformatics I, WS06/07, C.Dieterich 50 As an alternative to storing the words in a tree, a finite-state machine can be used, which Altschul et al. found to have the faster implementation. As BLAST does not allow indels at that stage, hit extension is very fast. Note that the use of seeds of length w and the termination of extensions with fading scores are both steps that speed up the algorithm, but also imply that BLAST is not guaranteed to find all HSPs (after all it is a heuristic). For DNA sequences, BLAST operates as follows: The list of all words of length w in the query sequence q is generated. practice, w = 12 for DNA. In The database d is scanned for all hits of words in this list. Blast uses a two-bit encoding for DNA. This saves space and also search time, as four bases are encoded per byte. Note that the T parameter dictates the speed and sensitivity of the search. 5.2.3 The BLAST family There are a number of different variants of the BLAST program: BLASTN: compares a DNA query sequence to a DNA sequence database; q DNA s DNA BLASTP: compares a protein query sequence to a protein sequence database; q protein s protein TBLASTN: compares a protein query sequence to a DNA sequence database (6 frames translation); q protein s t1 (DNA), q protein s t2 (DNA), q protein s t3 (DNA), q protein s t c 1 (DNA), q protein s t c 2 (DNA), q protein s t c 3 (DNA) BLASTX: compares a DNA query sequence (6 frames translation) to a protein sequence database; q t1 (DNA) s protein, q t2 (DNA) s protein, q t3 (DNA) s protein, q t c 1 (DNA) s protein, q t c 2 (DNA) s protein, q t c 3 (DNA) s protein TBLASTX: compares a DNA query sequence (6 frames translation) to a DNA sequence database (6 frames translation); q t1 (DNA) s t1 (DNA),..., q t c 3 (DNA) s t c 3 (DNA)
Algorithms in Bioinformatics I, WS06/07, C.Dieterich 51 5.3 Statistical analysis When a local alignment has been computed, next one needs to assess its statistical significance. This is done by the general approach of hypothesis testing. 5.3.1 Poisson distribution The Karlin and Altschul theory for local alignments (without gaps) is based on Poisson and extreme value distributions. The details of that theory are beyond the scope of this lecture, but basics are sketched in the following. Definition 5.3. The Poisson distribution with parameter v is given by P(X = x) = vx x! e v (5.1) Note that v is the expected value as well as the variance. From the equation we follow that the probability that a variable X will have a value at least x is P(X x) = 1 x 1 i=0 v i i! e v (5.2) 5.3.2 Statistical significance of an HSP Given an HSP (s, t) with score σ(s, t). How significant is this match (i.e., local alignment)? To analyze how high a score is likely to arise by chance, a model of random sequences over the alphabte Σ is needed. For proteins, the simplest model chooses the amino acid residues in a sequence independently, with specific background probabilities p a for the various residues a Σ. Given the scoring matrix S(a, b), the expected score for aligning a random pair of amino acid is required to be negative: E = p a p b S(a, b) < 0 a,b Σ Were this not the case, long alignments would tend to have high score independently of whether the segments aligned were related, and the statistical theory would break down. Just as the sum of a large number of independent identically distributed (i.i.d) random variables tends to a normal distribution, the maximum of a large number of i.i.d. random variables tends to an extreme value distribution as we will see below. Assume that the length m and n of the query and database respectively are sufficiently large.
Algorithms in Bioinformatics I, WS06/07, C.Dieterich 52 HSP scores are characterized by two parameters, K and λ. The parameters K and λ depend on the background probabilities of the symbols and on the employed scoring matrix. λ is the unique value for y that satisfies the equation p a p b e S(a,b)y = 1 a,b Σ K and λ are scaling-factors for the search space and for the scoring scheme, respectively. The number of random HSPs (s, t) with σ(s, t) S can be described by a Poisson distribution with parameter v = Kmne λs. The number of HSPs with score S that we expect to see due to chance is then the parameter v, also called the E-value: E(C) = Kmne λs (5.3) Note that doubling the query or database length should double the number of HSPs attaining the given score. However, doubling the cutoff score to 2S should cause an exponential drop-off of HSPs attaining the given score, as each HSP will have to achieve the score S twice in a row. Hence, the probability of finding exactly x HSPs with a score S is given by where E is the E-value for C. E Ex P(X = x) = e x!, (5.4) The probability of finding at least one HSP by chance is P(S) = 1 P(X = 0) = 1 e E. (5.5) Thus we see that the probability distribution of the scores follows an extreme value distribution. BLAST reports E-values rather than P -values as it is easier to interpret the difference between E-values than to interpret the difference between P -values. We would like to hide the parameters K and λ to make it easier to compare results from different BLAST searches. For a given HSP (s, t) we transform the raw score S into a bit-score: S := λs ln K. (5.6) ln 2 Such bit-scores can be compared between different BLAST searches, as the parameters of the given scoring systems are subsumed in them.
Algorithms in Bioinformatics I, WS06/07, C.Dieterich 53 To determine the significance of a given bit-score S the only additional value required is the size of the search space. Since S = (S ln 2 + ln K)/λ, we can express the E-value in terms of the bit-score as follows: E = Kmne λs = Kmne (S ln 2+ln K) = mn2 S. (5.7) 5.3.3 A practical demonstration of the BLAST service provided thru the NCBI 5.3.4 BLAST output BLASTN 2.2.5 [Nov-16-2002] Reference: Altschul, Stephen F., Thomas L. Madden, Alejandro A. Schaffer, Jinghui Zhang, Zheng Zhang, Webb Miller, and David J. Lipman (1997), "Gapped BLAST and PSI-BLAST: a new generation of protein database search programs", Nucleic Acids Res. 25:3389-3402. Query= gi 27666311 ref XM_213799.1 Rattus norvegicus similar to LD36129p [Drosophila melanogaster] (LOC288717), mrna (615 letters) Database: Mm.seq.uniq 87,543 sequences; 71,874,313 total letters Searching...done Sequences producing significant alignments: Score E (bits) Value gnl UG Mm#S1976993 Mus musculus 10, 11 days embryo whole body cd... 420 e-117 gnl UG Mm#S1660553 Mus musculus tuftelin interacting protein 11... 387 e-106 gnl UG Mm#S1422805 BB410669 Mus musculus cdna, 3 end /clone=c43... 40 0.035 gnl UG Mm#S2728452 Mus musculus, similar to KIAA1345 protein, c... 38 0.14 gnl UG Mm#S2050066 Mus musculus, clone IMAGE:3594635, mrna /cds=... 36 0.54 gnl UG Mm#S2610883 Mus musculus RIKEN cdna 4933405A16 gene (4933... 36 0.54 gnl UG Mm#S2470935 4063-18 Mus musculus cdna /gb=bi990266 /gi=17... 34 2.1 >gnl UG Mm#S1976993 Mus musculus 10, 11 days embryo whole body cdna, RIKEN full-length enriched library, clone:2810002g02:homolog to BK1048E9.3 (NOVEL PROTEIN), full insert sequence /cds=unknown /gb=ak012640 /gi=12849517 /ug=mm.206666 /len=1075 Length = 1075 Score = 420 bits (212), Expect = e-117 Identities = 251/264 (95%) Strand = Plus / Plus Query: 2 ttcagtcagactgaggtttccgttctcacctccctgggtgtgacagtcctcagtgagaat 61 Sbjct: 436 ttcagtcagactgaggtttccgttctcacctccctcggcgtgactgtcctcagtgagaat 495 Query: 62 gaggaaggcaagcacagtgtccagagccagcccactgtcttctacatgccacactgtggg 121 Sbjct: 496 gaggaaggcaagcgcagtgtccagggccagcccactgtcttctacatgccacactgtggg 555 Score = 385 bits (194), Expect = e-106 Identities = 313/349 (89%), Gaps = 4/349 (1%) Strand = Plus / Plus Query: 265 gattctgaaaggcctggaggagttcccactgcctcaaactccccagtacaccgacacctt 324 Sbjct: 725 gattctgaaaggcctggaggaggtcccactgccgcagactccccagtacactgacacctt 784 Query: 325 caatgacacatctgtccactggttccctcttctgaagctggaaggcttatctgaggacct 384 Sbjct: 785 taatgatacatctgtccactggttcccactattgaagctggaaggactgcctggggacct 844 >gnl UG Mm#S2470935 4063-18 Mus musculus cdna /gb=bi990266 /gi=17961276 /ug=mm.228667 /len=600 Length = 600 Score = 34.2 bits (17), Expect = 2.1 Identities = 17/17 (100%)
Algorithms in Bioinformatics I, WS06/07, C.Dieterich 54 Strand = Plus / Minus Query: 55 tgagaatgaggaaggca 71 Sbjct: 229 tgagaatgaggaaggca 213 Database: Mm.seq.uniq Posted date: Jan 15, 2003 5:12 PM Number of letters in database: 71,874,313 Number of sequences in database: 87,543 Lambda K H 1.37 0.711 1.31 Gapped Lambda K H 1.37 0.711 1.31 Matrix: blastn matrix:1-3 Gap Penalties: Existence: 5, Extension: 2 Number of Hits to DB: 33,888 Number of Sequences: 87543 Number of extensions: 33888 Number of successful extensions: 2616 Number of sequences better than 10.0: 52 Number of HSP s better than 10.0 without gapping: 52 Number of HSP s successfully gapped in prelim test: 0 Number of HSP s that attempted gapping in prelim test: 2552 Number of HSP s gapped (non-prelim): 58 length of query: 615 length of database: 71,874,313 effective HSP length: 18 effective length of query: 597 effective length of database: 70,298,539 effective search space: 41968227783 effective search space used: 41968227783 T: 0 A: 0 X1: 6 (11.9 bits) X2: 15 (29.7 bits) S1: 12 (24.3 bits) S2: 16 (32.2 bits) 5.4 FASTA FASTA (pronounced fast-ay) 1 is a heuristic for finding significant matches between a query string q and a database string d. It is the older of the two heuristics introduced in the lecture. FASTA s general strategy is to find the most significant diagonals in the dot-plot or dynamic programming matrix. The performance of the algorithm is influenced by a word-size parameter k, usually 6 for DNA and 2 for amino acids. The algorithm consists of four phases: Hashing, 1st scoring, 2nd scoring, alignment. 5.4.1 Hashing The first step of the algorithm is to determine all exact matches of length k (wordsize) between the two sequences, called hot-spots. 1 FASTA is an abbreviation of fast all. The predecessor of FASTA was FASTP which was only applicable to protein sequences
Algorithms in Bioinformatics I, WS06/07, C.Dieterich 55 To find these exact matches quickly, usually a hash (look-up) table is built that consists of all words of length k that are contained in the query sequence. Exact matches are then found by look-up of each word of length k that is contained in the database. A hot-spot is given by (i, j), where i and j are the locations (i.e., start positions) of an exact match of length k in the query and database sequence respectively. Any such hot-spot (i, j) lies on the diagonal (i j) of the dot-plot or dynamic programming matrix. Using this scheme, the main diagonal has number 0 (i = j), whereas diagonals above the main one have positive numbers (i < j), the ones below negative (i < j). A diagonal run is a set of hot-spots that lie in a consecutive sequence on the same diagonal. It corresponds to a gapless local alignment. A score is assigned to each diagonal run. This is done by giving a positive score to each match (using e.g. the PAM250 match score matrix in the case of proteins) and a negative score for gaps in the run, the latter scores decrease with increasing length of the gap. The algorithm then locates the ten best diagonal runs. 5.4.2 First and second scoring and alignment Each of the ten diagonal runs with highest score are further processed. Within each of these scores an optimal local alignment is computed using the match score substitution matrix. These alignments are called initial regions. The score of the best sub-alignment found in this phase is reported as init1. The next step is to combine high scoring sub-alignments into a single larger alignment, allowing the introduction of gaps into the alignment. The score of this alignment is reported as initn Finally, a banded Smith-Waterman dynamic program is used to produce an optimal local alignment along the best matched regions. The center of the band is determined by the region with the score init1, and the band has width 8 for ktup=2. The score of the resulting alignment is reported as opt. In this way, FASTA determines a highest scoring region, not all high scoring alignments between two sequences. Hence, FASTA may miss instances of repeats or multiple domains shared by two proteins.
Algorithms in Bioinformatics I, WS06/07, C.Dieterich 56 After all sequences of the databases have thus been searched a statistical significance similar to the BLAST statistics is computed and reported. The following matrix summarizes the principle of FASTA for the two sequences ACTGAC and TACCGA: The hot spots for k = 2 are marked as pairs of black bullets, a diagonal run is shaded in dark grey. An optimal sub-alignment in this case coincides with the diagonal run. The light grey shaded band of width 3 around the subalignment denotes the area in which the optimal local alignment is searched. 5.5 BLAST and FASTA BLAST Database FASTA Database Query Query Database Database Query Query (a) (b) (a) In BLAST, individual seeds are found and then extended without indels. (b) In FASTA, individual seeds contained in the same diagonal are merged and the resulting segments are then connected using a banded Smith-Waterman alignment.