Class 8: How BLAST works

Bioinformatics

Andrés Aravena

October 27, 2022

Today

  • Cost of searching
  • Heuristic
  • Indices
  • Word Size

Computational cost

What is computational cost?

  • How much time does it take to
    • find the optimal alignment?
    • search the database?
  • How much computer memory is needed?

It depends on the technology and the algorithm

Let’s ignore the technology

Cost depends on input size

Small sizes take short time

Larger sizes take longer time

Computational cost of alignment

  • How many comparisons/multiplications are needed?

  • It depends on query and subject size, so \[Cost=f(m, n)\] where \(m\) and \(n\) are the query and subject lengths

  • So, What is the formula?

Big-O notation

We care on how time depends on the input size

We do not care about fixed numbers

For example \(100m^2 n^4\) is equivalent to \(m^2 n^4\)

We say “the cost is on the order of \(m^2 n^4\)

We write \[O(m^2 n^4)\]

Computational cost of Alignment

Size of dot plot matrix is \(m\cdot n\)

Building dot plot matrix takes time \(m\cdot n\)

Then we have to find “the best diagonals”

Thus, computational cost is \(O(m\cdot n)\)

What was the cost?

Indices

Now try with this

0  69
1  62 253
12  278
15  66
2  92 258
2015  278
226  278
3  87 191 264
4  250 269
71  86
94  66
a  6 10 11 15 16 19 26 27 33 35 38 48 56 59 63 66 68 73 81 82 93 94 96 100 103 107 112 135 146 147 151 159 164 172 181 183 185 187 188 190 192 193 207 215 218 220 223 231 261 264 265 267 270
ab  51
abandoned  127
able  64 109
about  145 146 147 162
above  7 83
absolute  32 207
absurd  244
acceptance  88
accepted  89
acknowledge  74
acknowledged  168
across  93 261
actions  126
actually  96
adjective  240
administer  208
adoption  76
affirm  201
after  7 248
age  235
ages  30
ago  63 92 192
air  29
all  12 25 48 65 83 93 101 103 104 107 108 109 115 119 120 125 139 155 163 181 201 202 204 205 208 270
allegorical  211
allowed  100 206
almost  93 154 199
alphabet  103 255
already  213 219 229
also  44 98 103 138 179 265
alvarez  269
always  8 164 170
am  27 28 45 234
an  4 35 120 199 247 259 271 273
analogous  183
analysis  98
ancient  79 80 246
and  7 13 16 20 22 30 39 55 57 60 64 65 71 72 76 82 86 103 106 111 120 123 125 126 128 139 143 147 148 155 159 164 169 170 177 181 182 185 189 190 192 193 195 199 202 204 209 212 215 217 224 231 234 235 238 243 244 254 255 259 261 266 267
annihilated  195
announced  119
annuls  229
another  7 12 67 87 101 130 179 209
any  6 39 84 88 168 247
anything  149
apologie  125
apparent  274
apparently  210
appearances  17
appointments  54
approximately  43
arabic  97
arcana  126
archangels  110
are  13 19 21 32 44 62 70 104 144 170 183 193 210 225 234 248 255 266
argue  32 33
argued  180
argument  77
armed  237
around  36
arrangement  7
arrive  145
as  46 77 93 189 204 220 244
ascetic  165
at  33 124 138 145 210 236
attempting  73
author  256
authorities  157
autobiographies  110
aware  45
axaxaxas  210
axioms  49
b  188
babel  1 278
back  276
basilides  113
battered  195
be  18 29 31 53 56 85 102 109 136 139 140 155 169 188 193 194 195 207 245 264 274
bear  21
beat  185
became  123
becomes  83 249
bede  116
been  64 89 143 156 173 229
before  46 231
belief  179
believe  233 242
believed  79
belong  84
below  7
black  43 59
blasphemous  154
body  30 273
bold  245
book  26 35 37 42 44 59 65 93 115 148 169 180 181 182 187 188 189 191 193 264 265
books  42 55 65 73 76 79 101 105 116 117 119 125 153 156 163 165 171 175 176 182 231 245 266
bookshelf  41 152
bookshelves  8 9 41 54 106 219
borges  2 278
born  28
bounded  6
bread  223
breadth  124
brigandage  233
bulbs  21
burnished  19
but  36 75 84 87 93 116 134 158 167 170 195 198 203 235 247
by  2 6 20 31 128 132 151 169 171 173 174 175 187 206 234 250
c  66 84 86 189
cacophony  70
calculated  136
call  4
came  92
can  6 27 52 56 136 140 188 204 214 216
cannot  84 190 231
canonical  156
capital  253
catalog  26 110 112
catalogs  26 111 112
cavalieri  273
ceiling  10
center  5 39
centuries  143 192 248
century  96 272
certain  20 225
certainty  152 229
chamber  34 35
chance  53 135 156
chaotic  65 74
characters  214
cheered  250
chief  92
childhood  158
cipher  181
circuit  66
circular  35
circumference  39
claim  34 198
classic  38
classical  97
clearly  149
closets  56
codes  89
coherence  199
coincidental  76
combed  209
combination  213
combinations  107
combinatorial  98
coming  261
comma  102 172 254
commentary  113 114
commit  218
committed  173
common  271
compare  58
compartments  13
compassionate  28
compendium  181
complete  106
completely  36
composed  4
composition  228
condemn  165
condition  228
confirmed  104
confound  202
confuse  202
congruent  123
conjecture  64 89
consequences  47 173
consist  102 271
consisted  66
constantly  201
constructed  157
consult  187 188
consulted  68
contain  107
contained  119 153 213
containing  35 93
contains  42 69 205
contend  75
content  98 278
continuous  36
corollary  52
correct  222
correspondence  46
corresponds  267
corridors  129 243 261
could  116
countless  220
cover  44 59
cramp  209
creature  196
credentials  164
crimson  176
crosswise  22
crude  58
cryptographic  211
cup  159
cyclical  37
daresay  172
dark  130
days  25
de  269
dead  28
death  114
deaths  132
decay  30
deceiving  131
decimated  233
decipher  94
declare  31
deduced  105
deep  59
define  224
definition  222
definitions  225
degenerate  232
deity  203
delicate  59
demiurges  54
deny  202 266
deplorable  204
depredations  173
depression  152
desire  128
desperate  205
despite  172
destroyed  167
detailed  109
determined  96 98
devolves  82
dhcmrlchtdj  214
dialect  82 97
dialectal  85
dice  159
dictum  38
did  116 122
die  27
differ  171
different  81 101
direction  248
disappeared  158
discontinued  155
discords  232
discover  100 149
discovery  47 62
discuss  266
diseases  259
disgraceful  148
disgustedly  164
dishonorable  149
disks  159
disorder  160 203 249
disproportionate  152
dissolve  30
distance  16 57
distant  80 132 184
distracts  228
districts  230
divine  57 65 130 160 214
do  132 162
does  215 220
doubt  52 266
down  131 261
downstairs  128
downward  16
dream  19
dreams  73
duplicates  17
each  5 8 22 41 42 43 44 86 169 274
earlier  258
early  272
easy  274
ecstasies  34
ed  256
edu  278
effort  175
eighty  43
elegant  54 250
elements  102
eliminate  163
eloquent  122
else  224
employ  221
employed  81
enabled  62
end  244 260
endless  31
endlessly  7 99
endure  238
engendered  30
enigmatic  55
enlightened  236
enormous  35 196
enough  151 246
entire  165
entirely  77
epidemics  232
epistle  219
equating  73
eternal  247
eternitate  51
eternity  52
even  192 199
event  48
evergreen  278
everlasting  222
every  69 109 115 126 185 234 258 273
everything  229
ex  212
exact  39
exaggerated  174
examined  182
example  214 265
examples  99
exception  200
excluded  265
execrated  166
exemplify  204
exhausted  145
exist  122 133 181 194 264
existed  51
existence  212
exists  219
expects  149
experts  96
explained  140
expressed  109
extinction  236
extraordinary  142
eyes  27
facsimiles  171
fact  12 103
facts  168
failed  134
faithful  110
faithfully  17
fall  31
fallacious  77
fallible  58
false  111 112 164
falsity  111 112
fanatics  174
far  80
father  66
fear  235
feebly  159
felt  120
feverish  200
few  28 48 82
figuration  20
filled  216
find  72 73 94 128 196 248
finding  135
finest  208
first  12 51 67 80 119 162 187 188 210
five  8 41 62 75 92 206 219 255
floor  9
floors  7 83
for  13 14 18 30 37 55 56 69 79 125 126 143 148 158 185 194 205 214 258 260 264 265
forbidden  159
forced  157
foreseen  215
forever  153
forget  245
format  42
formless  65
formulate  63
formulated  90
forthright  70
fortuitous  76
forty  43
found  188
four  9 42 84 143
free  11
frenzy  167
frequent  234
from  6 17 28 67 81 97 101 105 179 228
front  44
fruits  21
fundamental  100 138
furnished  41
future  52 110 133
futures  127
galleries  5 8 147 223
gallery  5 12
general  63 172
genius  100
give  22
gnostic  112
god  37 56 183 218
gods  191
goes  36
going  162
gone  184
gospel  113 114
grammar  143
grasp  57
great  88
greater  10
greedy  127
grieve  167
guarani  97
habit  72 241
had  64 96 156
hallucinating  203
hand  58 74
handiwork  56
hands  29 169
hardly  10 27
has  51 57 88 89 192 215 229 253 269
have  25 27 77 85 88 104 116 133 142 143 145 158 173 179 182 184 189 224 233 240 242 259 260 276
havoc  259
he  94 103 248
heaven  194
height  9 10
held  126
hell  194
hereby  241
heretical  232
hexagon  6 9 11 22 28 39 41 66 122 145 152 176 180 186
hexagonal  5 32 223
hexagons  92 128 144 163 208 220 243 258
hide  159 215
him  94 185
him?  186
his  94 135 136
history  48 109
holds  42
holy  175
homogeneous  94
honor  193
hope  124 138 250
hopefulness  151
horror  174
how  186
however  85 101
https  278
huge  168
human  57 169 235
humanity  228
humankind  124
humble  199
hundred  42 63 84 92 171 185
hurled  131
hygienic  165
hypothesi  213
hypothesize  242
i  19 25 27 28 31 38 45 48 71 83 133 144 158 172 189 190 191 200 208 230 233 234 235 240 241 245 260 264
idealists  32
identical  12 42 102 104
idolized  186
if  18 140 193 247
ignorance  205
illogical  241
illusory  19
illustrated  99 177
imaginary  134
imitated  75
immediate  51
impenetrable  79
imperfect  53 171
important  48
impossible  265
imprecations  130
improbable  156
in  5 11 12 16 21 25 26 30 42 47 48 56 66 68 73 74 76 79 90 95 104 109 122 126 129 133 134 139 140 147 152 158 159 162 167 179 180 183 184 185 189 191 194 198 213 215 217 219 221 230 242 247 249 258 264 271 272
included  240
includes  206
incoherency  71
incoherent  210
incomprehensible  83
inconceivable  34 275
inconceivably  244
incontrovertible  105
incorruptible  238
indeed  140
indefatigable  55
indefinite  4
indicate  45
individuals  127
inevitably  232
infer  17
infidels  198 204
infinite  5 18 20 31 108 237 240 242 272 273
infinitely  272
infinitesimal  169
infinity  189
inflections  97
influences  86
inimitably  60
inquisitors  144
insane  132
inside  45 59
inspired  174
instant  195
insufficient  22
intact  120
interpolations  115
into  16 82 115 201 233 275
invade  163
inventors  75
irreplaceable  170
is  4 6 8 10 13 16 18 20 22 31 34 36 37 38 39 41 48 52 68 69 77 80 82 84 87 106 108 141 142 165 166 168 169 170 181 182 189 190 198 199 208 209 212 213 216 217 218 223 241 242 244 245 246 250 254 256 264 265 269 270 273
issue  157
it  18 37 79 80 81 83 85 90 95 119 148 162 165 180 189 190 204 206 207 224 241 242 264
its  47 54 55 90 106 196 215 220
itself  212
jorge  2
journey  247
journeyed  26
joy  120 193
jumbled  93
just  240
justification  196 212
justified  123
killed  146
kiss  231
know  71 200 230
knowledge  179
known  69
labyrinth  68
lack  46
language  81 82 85 96 109 115 141 142 143 183
language?  226
languages  80 217 221
last  67
latrines  159
law  100
lay  166
leaf  148 164
leagues  28 70
least  33
left  13
let  37 194 195
letizia  269
letter  86 172 232
letters  43 44 59 66 68 103 155 253 255
librarian  10 53 56 100 105 147 182 184 262
librarians  72 81
library  1 4 18 25 31 38 51 63 100 104 106 111 119 139 141 168 170 196 198 200 205 213 214 222 223 236 246 269 278
light  20 22
like  25 202 231
likelihood  140
limited  254
limits  242
line  8 43 67 70 86 87
lines  43 74 94 95
lithuanian  97
loaf  223
locate  186 187 188
long  158
loss  166
lost  117
low  6
luis  2
lung  259
m  66 84 86
mad  202
magical  177
make  27 214
malevolent  53
man  53 135 180 192 258
mankind  63 139
manuscript  253
many  79 184 208
marks  254
may  53 85 196 243
me  29 195 225 228
meaning  73 77
melancholy  260
memory  260
men  17 25 46 120 127 132 143 155 158 185
mentioned  88 233
mere  68 241
met  88
metal  159
methodical  228
middle  275
might  102 139
mighty  217
miles  82
millions  166
mimicking  160
mind  52
miraculous  199
mirror  16 17
misled  234
missing  146
mlo  210
moment  38
more  171 215 234
most  48 80
much  67 69 124
multiform  141
must  141 169 181 182
muttered  129
my  25 26 29 30 31 58 66 158 190 193 194 225 249
myself  27 208
mysteries  138 140
mysterious  46
mystery  47
mystics  34
mythology  116
n  220
name  21 166 218
narrow  11 129
native  127
natural  75 176
naturally  151
nature  65
nearest  148
nearly  146
neat  59
necessary  32
necessities  14
need  18
neither  44 253
next  86
nights  260
nine  271
ninety  83
no  52 64 77 104 121 149 171 213 216 265 266 276
non  198
nonsense  71 207
nor  45 253
normal  10
not  18 77 87 88 90 108 116 122 134 141 164 193 198 203 206 215 216 217 240 241 245 274
note  256
now  26
number  5 108 220 245 272 274
numbers  253
obscure  37
observe  207
observed  101 269
of  1 4 5 7 9 10 11 13 20 21 25 26 32 33 41 44 46 47 52 53 56 59 63 65 66 68 70 71 72 74 75 83 84 86 87 89 92 93 97 98 99 100 102 103 107 109 110 111 112 113 114 115 116 117 120 124 125 126 127 132 133 134 135 136 138 139 141 143 153 156 165 166 173 175 179 181 183 184 192 193 200 207 208 212 214 215 217 218 219 220 221 222 223 228 236 241 245 255 259 267 270 271 272 273 274 278
official  144
often  17
old  158 235
omnipotent  176
on  44 58 86 87 113 114 116 130 174 180 189 191 260
once  46 66 147
one  6 7 10 13 14 57 65 71 74 81 92 101 130 149 154 168 186 195 196 214 215 216 217 219 220 258
only  56 57 203 235 265
onto  11 12
open  275
opens  11
opinion  172
opposite  162
or  33 53 70 73 79 85 135 148 172 211 215 223 224 229 243 271
order  56 212 249 264
orders  157
organic  59
origin  139
original  253
originators  90
orthographic  62 107 206
other  14 181 225 275
others  4 88 93 95 132 162 194 201 267
our  33 82 256
out  27 153 240
over  29 167
overlook  167
own  135 136 193 194
page  43 68 86 87 275
pages  43 45 84 93 231 272 275
palm  74
passes  15
path  185
pdf  278
pentagonal  34
penultimate  68
people  117 230
peoples  80
perception  33
perfect  106 181
perfectly  237
perfidious  135
perhaps  5 26 48 134 234
period  102 124 138 179 254
periodic  247
periods  158
person  126
personal  121
persons  133
perused  192
perversely  67
phantasmal  230
philosopher  101
philosophers  141
phrase  69
phrases  210
physical  14
picture  244
piece  207
pilgrimages  232
pilgrims  129
place  194 243
places  243
planes  274
plaster  209
played  259
point  271
pointless  207 218 237 270
polished  261
politicalshakespeares  278
population  233
portuguese  95
posited  103
possesses  222
possessors  120
possibility  89 267
possible  107 185 221 245 265
pray  191
precious  153 237
prefer  19
prefigure  45
premises  105
preparing  27
present  228
primitive  85
printed  271
problem  121 246
proclaim  203
produced  142
profound  140
promise  20
proof  111 112
prophecies  125
proportion  259
proposed  154 187
prostrate  230
prove  204 266
provided  20
punctuation  254
pure  199
purifiers  173
pyramid  224
pyramids  69
quest  26 73 134
quite  81
rage  165
railing  6 29
random  200
rational  52 70
rationality  199
reach  154 175
reaction  119
read  192 225 231
reading  193 211
recall  48 134
reduction  169
refer  133
referring  256
refutation  220
regions  132
regression  187
remote  243
remotest  16
renders  229
repeat  38 83 264
repeated  67 249
repeating  99
replication?  19
repudiate  72
required  142 270
reveal  35
revealed  139
rhetorical  241
riddle  64
right  13 82
rooms  32
rudiments  98
rule  198
rungs  146
rushed  128
s  9 11 14 74 84 124 127 135
said  95
same  8 87 138 174 221 248 249
samoyed  97
satisfactorily  64
satisfying  14
savages  231
saw  66
saxon  117
say  45
scouring  144
scrawls  58
search  184
searchers  144
searches  154
searching  148 187
seated  56
second  62
secret  121 186 215 238
sect  154 157 184
see  6 77 204
seen  133 145 158
semibarbarous  71
sense  72 90 198
senseless  70 166
separates  57
series  87
set  22
seventeenth  272
several  171
shaft  6
shafts  131
shall  31 77
shape  32
shelf  180 191
sheltered  186
should  247
show  163
showed  94
shuffle  155
side  8
sides  9 11
significance  216
silken  274
similar  275
similarly  151
since  104 170
single  172 192 207 261 270
sink  30
sites  278
six  9 224
size  271
sleeping  14
smaller  176
so  168 189 201
solid  273
solitary  237
solitude  250
solution  47 122 246
solve  64
some  85 92 122 135 145 152 156 180 182 191 192 202 221 243
someday  175
someone  187
something  224
sometimes  260
somewhere  122 213
sort  11
space  15 33 102 255
speak  81 146 200 216 218
speaking  270
species  235 236
spent  190
sphere  38
spherical  21
spine  36
spiral  15
spite  47
spurred  128 174
squabbled  129
squandered  190
staircase  15 146 266 267
staircases  55 130 147 243 261
state  241
stated  273
statement  70
still  183
story  114
strangled  130
strict  157
strictly  270
stroke  156
struck  46
structure  267
structures  205
succeeded  151
such  73 189 190 193
suddenly  123
suffice  37
sufficient  141 256 264
suggest  246
suggested  85
suicide  258
suicides  234
summarizing  46
superposition  273
superstition  179
superstitious  72
surely  142
surfaces  19
susceptible  211
suspect  37 235
sweet  127
syllable  216
symbol  221
symbols  58 62 75 107 155 206 256
symmetrical  60
system  222
tacitus  117
take  148
talk  124 146
tasks  145
taste  204
tautologies  218
teeters  236
tells  188
ten  42 84 271
tenderness  217
tens  192
termed  180
terrible  216
terror  217
testimony  36
than  10 171 176
that  17 18 19 21 26 31 32 33 34 36 37 38 45 51 57 62 64 74 76 77 79 80 82 83 85 86 88 89 95 101 105 106 108 113 114 119 124 125 126 135 138 142 143 146 151 152 153 154 155 164 165 167 168 169 171 172 179 181 182 184 186 189 190 191 192 198 199 201 207 208 211 214 215 216 217 224 229 232 235 236 240 241 242 245 248 250 256 259 264 266 267 269 270 271 273 274
the  1 4 5 7 8 9 10 12 13 14 16 18 20 21 22 25 26 28 29 30 31 32 36 38 44 45 46 47 48 51 52 53 54 55 56 57 58 59 63 64 65 66 67 69 72 74 75 80 81 82 86 87 89 90 92 93 95 96 98 100 102 103 104 105 107 109 110 111 112 113 114 115 116 117 119 120 122 123 124 126 128 129 130 132 133 135 138 139 140 141 142 143 144 147 148 152 154 157 159 160 162 163 166 167 168 170 172 173 174 175 180 181 183 184 186 191 193 198 200 204 205 206 207 208 209 212 213 214 217 219 220 221 222 223 224 228 229 230 233 235 236 240 242 243 244 245 246 248 249 253 254 255 259 265 269 270 272 273 275 278
their  34 36 37 127 129 131 145 165 166 231
them  35 133 134 145 146 194 221
themselves  76 120 131 224 230
then  141 194
theory  63
there  15 16 18 21 44 62 70 104 121 124 138 144 170 181 183 190 195 213 216 258 266
thereby  64
these  21 58 129 189
thesis  88
they  22 33 74 102 145 146 147 163 174 200 201 231
thin  272
thing  162 223
things  202
think  190 241
thirty  42 219
this  15 17 68 69 101 182 183 218 246
those  44 79 99 105 112 134 140 153 155 167 174 203 210 217 242 244 254
though  89 108 194 231 266
thought  162
thousand  171
thousands  111 127
threaten  201
three  63 258
threw  130
through  15 148 156 164 175
throw  29
thunder  209
thy  69 196
time  69 125 139
times  258
tiny  13
titled  208 209
to  8 9 12 19 27 35 48 57 63 64 67 72 73 82 84 94 100 109 128 131 133 134 136 149 157 162 165 175 183 186 187 188 189 191 193 201 207 211 218 241 242 246 254 256 264 267
today  81 166
together  142
told  94
toledo  269
tomb  29
tongues  215
too  15
tortured  195
total  106 170 191
tragic  47
translation  114
transmogrify  201
traveled  25 260
traveler  55 247
travelers  104
traveling  94
treasure  121
treasures  167
treatise  116
trembling  58
triangular  33
true  80 82 84 112 114
truth  51
trying  72
turn  11
twenty  8 62 75 103 107 206 255
two  13 21 42 93 103 104 107 133 167 169 254 255
type  271
ubiquitous  222
unattainable  39
unbearable  154
unbounded  120
unbridled  151
unceasing  23
understand  225
undoubtedly  210
unfathomable  29
unimaginably  108
unique  170
universally  89
universe  4 54 122 123 126 191
unknown  191 256
unlikely  190
unlimited  123 245 247
unmoving  237
unrelenting  175
unspeakably  260
until  155
untold  248
unvarying  84
up  148
uploads  278
upon  113
upper  92
upright  14
upstairs  128
upward  15
us  229
using  274
v  67 84 86
vademecum  274
vague  88
vain  72 128 186
value  86 87
variations  99 206
vast  108 269
ventilation  6 131
ventures  189
verbal  71 205 212
verbose  218
verge  236
version  136
vestibule  11 13 16
vestiges  183
vindicate  125
vindication  129 135
vindications  125 132
virtually  65
vocabulary  221
volume  164 208 270
volumes  131 166 200 219 237 248
wall  41
walls  36 165
was  28 76 79 95 96 98 119 120 121 122 124 138 151 154 162 180 186 258
water  55
way  162
we  77 81 165 179
well  204
went  132 134
were  18 79 95 131 146 153 157 164 174
what  18 27 45 96 180
when  28 119
where  28 188
wherein  196
which  4 11 15 17 31 58 65 90 103 108 133 188 203 230 234 244 249
while  147 205 209 223
who  94 134 158 167 225 242 244
whole  106
whose  38 39 47 51 68 71 121 200 267
widely  168
width  123
will  29 30 45 74 238 245
wind  30
winds  15
wisdom  193
wish  48
with  35 41 54 59 73 88 97 99 123 143 147 159 217 237 259
within  95
without  261
wondrous  126
word  240
words  37 140 143 149 203 212 224
work  53
world  52 121 242 244
worshiped  184
worthless  163
would  18 125 158 163 207 248 271 274 275
wp  278
writing  75
written  27 95 116 229 240
year  234
years  63 79 92 185 190
yet  153 236 244
yiddish  95
you  225
young  230
younger  25
your  114
zeal  175
zero  136
zone  68 71 183

That is an Index

  • This works for exact match
  • It does not replace the original text
  • Takes extra space
  • search is faster
  • sorted files are faster to search

What is the cost of searching a sorted file?

Divide-and-conquer strategy

The database is \((s_1,…,s_d)\)

We need two auxiliary variables. Let \(l ←1, u ←d\)

To search in a sorted file, we start in the middle

  • Let \(i ← (u-l)/2\)
  • If \(q=s_i,\) we found it.
  • If \(q<s_i\) then we can ignore the second half of database
    • \(u ← i\), and repeat
  • If \(q>s_i\) then we can ignore the first half of database
    • \(l ← i\), and repeat

Search space halves every time

In a sorted file, we can discard half of the database after every comparison

So we need to compare the query with \(\log(d)\) subjects

Thus, the search cost is \(O(mn\log_2(d))\)

With numbers

Let’s say that \(m=100, n=100.\) Then

d plain.database time with.index time_2
1000 1e+07 10 sec 99658 0.1 sec
10000 1e+08 1.7 min 132877 0.13 sec
1e+05 1e+09 16.7 min 166096 0.17 sec
1e+06 1e+10 2.8 hours 199316 0.2 sec
1e+07 1e+11 1.2 days 232535 0.23 sec
1e+08 1e+12 11.6 days 265754 0.27 sec
1e+09 1e+13 115.7 days 298974 0.3 sec

assuming one million comparisons each second

Index, gaps and indels

All previous discussion assumed exact match

It can be extended to partial match

Let’s say that there are at most 3 mismatches (indels or gaps) between query and the best subject

  • Split the query in 4 parts
  • At least one of the parts has zero mismatches
  • Look each part using the index
  • See if the other parts match with indels and gaps

In general

To find a partial match with \(n\) mismatches

  • Split the query in \((n+1)\) parts
  • One of the parts will have a partial match

This is how BLAST works

BLAST uses indices to look for an initial hit

(sometimes called seed)

Then it tries to extend it using building a dot-matrix around the hit

The key parameter is Word size

After finding a seed,
BLAST must validate it

Word size tradeoff

  • Words of larger size are faster to search

    • But they may miss subjects with many mismatch
  • Small word size is more sensitive

    • but it will take longer time to find them all

BLAST does not guarantee
to find all matching sequences

Heuristics

BLAST is an Heuristic

  • BLAST can miss some cases
  • It does not solve the initial question
    • because the initial question is too hard
  • It is an heuristic
    • It gives the correct answer to a similar question
    • It give an approximate answer

Algorithm v/s Heuristics

  • An Algorithm is a protocol that always delivers a correct answer to a specific problem in a finite number of steps
    • for example, when we divide two numbers
    • This was first shown in Al-Khwarizmi’s book
  • An Heuristic is a protocol that solves a simplified problem, or that gives an approximate answer with lower cost that the complete algorithm
    • For example, instead of asking everybody, we can take a small random sample
    • Or computers playing chess

Heuristics solve an easier problem…

…but not the original problem

Most Bioinformatic tools are heuristics

In particular Multiple Alignment

Summary

  • Computational Cost:
    • number of steps, depending on input size
    • we only care about the order of
  • Big-O notation: forget about constants
  • Indices speed up searches
  • Indices can be used in partial matches
  • BLAST is a heuristic
  • Heuristics: approximate answers