Debian Codegraph @

hmmer/documentation/userguide/pipeline.tex

raw
1
2 \chapter{The HMMER profile/sequence comparison pipeline}
3 \label{chapter:pipeline}
4 \setcounter{footnote}{0}
5
6 Now I'll briefly outline the processing pipeline for a single
7 profile/sequence comparison.\marginnote{Code gurus, masochists: you
8 can follow along in \mono{src/p7\_pipeline.c}.} This should help
9 give you a sense of what HMMER is doing under the hood, what sort of
10 mistakes it may make (rarely, of course!), and what the various
11 results in the output actually mean. I'll first describe the pipeline
12 in the context of protein search (\mono{phmmer}, \mono{hmmsearch},
13 \mono{hmmscan}, \mono{jackhmmer}), then wrap back around to discuss
14 the modified pipeline used in \mono{nhmmer} and \mono{nhmmscan}.
15
16 In briefest outline, the comparison pipeline takes the following
17 steps:
18
19 \begin{description}
20 \item[\textbf{Null model.}] Calculate a score term for the ``null
21 hypothesis'' (a probability model of \emph{non-}homology). This
22 score correction is used to turn all subsequent profile/sequence bit
23 scores into a final log-odds bit score.
24
25 \item[\textbf{MSV filter.}] The main acceleration heuristic. The MSV
26 (``Multiple Segment Viterbi'') algorithm looks for one or more
27 high-scoring \emph{ungapped} alignments. If the MSV score passes a
28 set threshold, the entire sequence passes on to the next pipeline
29 step; else it is rejected.
30
31 \item[\textbf{Bias filter.}] A hack that reduces false positive MSV
32 hits due to biased composition sequences. A two-state HMM is
33 constructed from the mean residue composition of the profile and the
34 standard residue composition of the null model, and used to score
35 the sequence. The MSV bit score is corrected using this as a second
36 null hypothesis. If the MSV score still passes the MSV threshold,
37 the sequence passes on to the next step; else it is rejected. The
38 bias filter score correction will also be applied to the Viterbi
39 filter and Forward filter scores that follow.
40
41 \item[\textbf{Viterbi filter.}] A more stringent accelerated filter.
42 An optimal (maximum likelihood) gapped alignment score is
43 calculated. If this score passes a set threshold, the sequence
44 passes to the next step; else it is rejected.
45
46 \item[\textbf{Forward filter/parser.}] The full likelihood of the
47 profile/sequence comparison is evaluated, summed over the entire
48 alignment ensemble, using the HMM Forward algorithm. This score is
49 corrected to a bit score using the null model and bias filter
50 scores. If the bit score passes a set threshold, the sequence passes
51 on to the next step; else it is rejected.
52
53 \item[\textbf{Domain identification.}] Using the Forward parser
54 results, now combined with a Backward parser, posterior
55 probabilities of domain locations are calculated. A discrete set of
56 putative domains (alignments) is identified by applying heuristics
57 to posterior probabilities. This procedure identifies
58 \emph{envelopes}: subsequences on the target sequence which contain
59 a lot of probability mass for a match to the profile.
60
61 \item[\textbf{Alignment.}] For each identified domain, a full
62 Forward/Backward algorithm is performed. An \emph{ad hoc} ``null2''
63 hypothesis is constructed for each domain's composition and used to
64 calculate a biased composition score correction. A maximum expected
65 accuracy (MEA) alignment is calculated. This identifies one MEA
66 alignment within each envelope.
67
68 \item[\textbf{Storage.}] Now we have a \emph{sequence score} (and
69 P-value); the sequence contains one or more domains, each of which
70 has a \emph{domain score} (and P-value), and each domain has an MEA
71 alignment annotated with per-residue posterior probabilities.
72
73 \end{description}
74
75 In more detail, each step is described below.
76
77 \section{Null model}
78
79 The ``null model'' calculates the probability that the target sequence
80 is \emph{not} homologous to the query profile. A HMMER bit score is
81 the log of the ratio of the sequence's probability according to the
82 profile (the homology hypothesis) over the null model probability (the
83 non-homology hypothesis).
84
85 The null model is a one-state HMM configured to generate ``random''
86 sequences of the same mean length $L$ as the target sequence, with
87 each residue drawn from a background frequency distribution (a
88 standard i.i.d. model: residues are treated as independent and
89 identically distributed). Currently, this background frequency
90 distribution is hardcoded as the mean residue frequencies in Swiss-Prot
91 50.8 (October 2006).
92
93 For technical reasons, HMMER incorporates the \emph{residue emission}
94 probabilities of the null model directly into the profile, by turning
95 each emission probability in the profile into an odds ratio. The null
96 model score calculation therefore is only concerned with accounting
97 for the remaining \emph{transition} probabilities of the null model
98 and toting them up into a bit score correction. The null model
99 calculation is fast, because it only depends on the length of the
100 target sequence, not its sequence.
101
102 \section{MSV filter}
103
104 The sequence is aligned to the profile using a specialized model that
105 allows multiple high-scoring local ungapped segments to match. The
106 optimal alignment score (Viterbi score) is calculated under this
107 multisegment model, hence the term MSV, for ``multi-segment
108 Viterbi''. This is HMMER's main speed heuristic.
109
110 The MSV score is comparable to BLAST's sum score (optimal sum of
111 ungapped alignment segments). Roughly speaking, MSV is comparable to
112 skipping the heuristic word hit and hit extension steps of the BLAST
113 acceleration algorithm.
114
115 The MSV filter is very, very fast. In addition to avoiding indel
116 calculations in the dynamic programming table, it uses reduced precision
117 scores scaled to 8-bit integers, enabling acceleration via 16-way
118 parallel SIMD vector instructions.
119
120 The MSV score is a true log-odds likelihood ratio, so it obeys
121 conjectures about the expected score distribution\cite{Eddy08} that
122 allow immediate and accurate calculation of the statistical
123 significance (P-value) of the MSV bit score.
124
125 By default, comparisons with a P-value of $\leq$ 0.02 pass this
126 filter, meaning that about $2\%$ of nonhomologous sequences are
127 expected to pass. You can use the \mono{-{}-F1 <x>} option to change
128 this threshold. For example, \mono{-{}-F1 0.05} would pass 5\% of the
129 comparisons, making a search more sensitive but slower. Setting the
130 threshold to $\ge 1.0$ (\mono{-{}-F1 99} for example) assures that all
131 comparisons will pass. Shutting off the MSV filter may be worthwhile
132 if you want to make sure you don't miss comparisons that have a lot of
133 scattered insertions and deletions. Alternatively, the \mono{-{}-max}
134 option causes the MSV filter step (and all other filter steps) to be
135 bypassed.
136
137 The MSV bit score is calculated as a log-odds score using the null
138 model for comparison. No correction for a biased composition or
139 repetitive sequence is done at this stage. For comparisons involving
140 biased sequences and/or profiles, more than 2\% of comparisons will
141 pass the MSV filter. At the end of search output, there is a line
142 like:
143
144 \begin{sreoutput}
145 Passed MSV filter: 107917 (0.020272); expected 106468.8 (0.02)
146 \end{sreoutput}
147
148 which tells you how many and what fraction of comparisons passed the
149 MSV filter, versus how many (and what fraction) were expected.
150
151
152 \section{Biased composition filter}
153
154 It's possible for profiles and/or sequences to have biased residue
155 compositions that result in ``significant'' log-odds bit scores not
156 because the sequence matches the profile well, but because the
157 sequence matches the null model badly.
158
159 HMMER uses fairly good methods to compensate its scores for biased
160 composition, but these methods are computationally expensive and
161 applied late in the pipeline (described below).
162
163 In a few cases, profiles and/or target sequences are sufficiently
164 biased that too many comparisons pass the MSV filter, causing HMMER
165 speed performance to be severely degraded. Although the final scores
166 and E-values at the end of the pipeline will be calculated taking into
167 account a ``null2'' model of biased composition and simple repetition,
168 the null2 model is dependent on a full alignment ensemble calculation
169 via the Forward/Backward algorithm, making it computationally complex,
170 so it won't get calculated until the very end. The treatment of biased
171 composition comparisons is an inadequately solved problem in HMMER. As
172 a stopgap solution to rescuing most of the speed degradation while not
173 sacrificing too much sensitivity, an \emph{ad hoc} biased composition
174 filtering step is applied to remove highly biased comparisons.
175
176 On the fly, a two-state HMM is constructed. One state emits residues
177 from the background frequency distribution (same as the null1 model),
178 and the other state emits residues from the mean residue composition
179 of the profile (i.e. the expected composition of sequences generated
180 by the core model, including match and insert
181 states.)\sidenote{\mono{p7\_hmm.c:p7\_hmm\_SetComposition()}} Thus if
182 the profile is highly biased (cysteine-rich, for example; or highly
183 hydrophobic with many transmembrane segments), this composition bias
184 will be captured by this second state. This model's transitions are
185 arbitrarily set such that state 1 emits an expected length of 400 at a
186 time, and state 2 emits an expected length of M/8 at a time (for a
187 profile of length M). An overall target sequence length distribution
188 is set to a mean of $L$, identical to the null1 model.
189
190 The sequence is then rescored using this ``bias filter model'' in
191 place of the null1 model, using the HMM Forward algorithm. (This
192 replaces the null1 model score at all subsequent filter steps in the
193 pipeline, until a final Forward score is calculated.) A new MSV bit
194 score is obtained.
195
196 If the P-value of this still satisfies the MSV thresholds, the
197 sequence passes the biased composition filter.
198
199 The \mono{-{}-F1 <x>} option controls the P-value threshold for
200 passing the MSV filter score, both before (with the simple null1
201 model) and after the bias composition filter is applied.
202
203 The \mono{-{}-max} option bypasses all filters in the pipeline,
204 including the bias filter.
205
206 The \mono{-{}-nobias} option turns off (bypasses) the biased
207 composition filter. The simple null model is used as a null
208 hypothesis for MSV and in subsequent filter steps. The biased
209 composition filter step compromises a small amount of sensitivity.
210 Though it is good to have it on by default, you may want to shut it
211 off if you know you will have no problem with biased composition hits.
212
213 At the end of a search output, you will see a line like:
214
215 \begin{sreoutput}
216 Passed bias filter: 105665 (0.019849); expected 106468.8 (0.02)
217 \end{sreoutput}
218
219 which tells you how many and what fraction of comparisons passed the
220 biased composition filter, versus how many were expected. (If the
221 filter was turned off, all comparisons pass.)
222
223
224 \section{Viterbi filter}
225
226 The sequence is now aligned to the profile using a fast Viterbi
227 algorithm for optimal gapped alignment.
228
229 This Viterbi implementation is specialized for speed. It is
230 implemented in 8-way parallel SIMD vector instructions, using reduced
231 precision scores that have been scaled to 16-bit integers. Only one
232 row of the dynamic programming matrix is stored, so the routine only
233 recovers the score, not the optimal alignment itself. The reduced
234 representation has limited range; local alignment scores will not
235 underflow, but high scoring comparisons can overflow and return
236 infinity, in which case they automatically pass the filter.
237
238 The final Viterbi filter bit score is then computed using the
239 appropriate null model log likelihood (by default the biased
240 composition filter model score, or if the biased filter is off, just
241 the null model score). If the P-value of this score passes the Viterbi
242 filter threshold, the sequence passes on to the next step of the
243 pipeline.
244
245 The \mono{-{}-F2 <x>} option controls the P-value threshold for passing
246 the Viterbi filter score. The default is 0.001.
247 The \mono{-{}-max} option bypasses all filters in the pipeline.
248
249
250 At the end of a search output, you will see a line like:
251
252 \begin{sreoutput}
253 Passed Vit filter: 2207 (0.00443803); expected 497.3 (0.001)
254 \end{sreoutput}
255
256 which tells you how many and what fraction of comparisons passed the
257 Viterbi filter, versus how many were expected.
258
259
260
261 \section{Forward filter/parser}
262
263 The sequence is now aligned to the profile using the full Forward
264 algorithm, which calculates the likelihood of the target sequence
265 given the profile, summed over the ensemble of all possible
266 alignments.
267
268 This is a specialized time- and memory-efficient Forward
269 implementation called the ``Forward parser''. It is implemented in
270 4-way parallel SIMD vector instructions, in full precision (32-bit
271 floating point). It stores just enough information that, in
272 combination with the results of the Backward parser (below), posterior
273 probabilities of start and stop points of alignments (domains) can be
274 calculated in the domain definition step (below), although the
275 detailed alignments themselves cannot be.
276
277 The Forward filter bit score is calculated by correcting this score
278 using the appropriate null model log likelihood (by default the biased
279 composition filter model score, or if the biased filter is off, just
280 the null model score). If the P-value of this bit score passes the
281 Forward filter threshold, the sequence passes on to the next step of
282 the pipeline.
283
284 The bias filter score has no further effect in the pipeline. It is
285 only used in filter stages. It has \emph{no} effect on final reported
286 bit scores or P-values. Biased composition compensation for final bit
287 scores is done by a more complex domain-specific algorithm, described
288 below.
289
290 The \mono{-{}-F3 <x>} option controls the P-value threshold for passing
291 the Forward filter score. The default is 1e-5. The \mono{-{}-max}
292 option bypasses all filters in the pipeline.
293
294 At the end of a search output, you will see a line like:
295
296 \begin{sreoutput}
297 Passed Fwd filter: 1076 (0.00216371); expected 5.0 (1e-05)
298 \end{sreoutput}
299
300 which tells you how many and what fraction of comparisons passed the
301 Forward filter, versus how many were expected.
302
303
304 \section{Domain definition}
305
306 A target sequence that reaches this point is very likely to contain
307 one or more significant matches to the profile. These matches are
308 referred to as ``domains'', since the main use of HMMER has
309 historically been to match profile HMMs from protein domain databases
310 like Pfam, and one of HMMER's strengths is to be able to cleanly parse
311 a multidomain target sequence into its multiple nonoverlapping hits to
312 the same domain model.
313
314 The domain definition step is essentially its own pipeline, with steps
315 as follows:\sidenote{\mono{src/p7\_domaindef.c}}
316
317 \paragraph{Backward parser}
318 The counterpart of the Forward parser algorithm is calculated in an
319 analogous time- and memory-efficient implementation. The Forward
320 algorithm gives the likelihood of all \emph{prefixes} of the target
321 sequence, summed over their alignment ensemble, and the Backward
322 algorithm gives the likelihood of all \emph{suffixes}. For any given
323 point of a possible model state/residue alignment, the product of the
324 Forward and Backward likelihoods gives the likelihood of the entire
325 alignment ensemble conditional on using that particular alignment
326 point. Thus, we can calculate things like the posterior probability
327 that an alignment starts or ends at a given position in the target
328 sequence.
329
330 \paragraph{Domain decoding.}
331 The posterior decoding algorithm is applied, to calculate the
332 posterior probability of alignment starts and ends (profile B and E
333 state alignments) with respect to target sequence position.
334
335 The sum of the posterior probabilities of alignment starts (B states)
336 over the entire target sequence is the \emph{expected number of
337 domains} in the sequence.
338
339 In a tabular output (\mono{-{}-tblout}) file, this number is in the
340 column labeled \mono{exp}.
341
342 \paragraph{Region identification.}
343
344 A heuristic is now applied to identify a \emph{non-overlapping} set of
345 ``regions'' that contain significant probability mass suggesting the
346 presence of a match (alignment) to the profile.
347
348 For each region, the expected number of domains is calculated (again
349 by posterior decoding on the Forward/Backward parser results). This
350 number should be about 1: we expect each region to contain one local
351 alignment to the profile.
352
353 In a tabular output (\mono{-{}-tblout}) file, the number of discrete
354 regions identified by this posterior decoding step is in the column
355 labeled \mono{reg}. It ought to be almost the same as the expectation
356 \mono{exp}. If it is not, there may be something funny going on, like
357 a tandem repetitive element in the target sequence (which can produce
358 so many overlapping weak hits that the sequence appears to be a
359 significant hit with lots of domains expected \emph{somewhere}, but
360 the probability is fuzzed out over the repetitive region and few or no
361 good discrete alignment regions can be identified).
362
363 \paragraph{Envelope identification.}
364
365 Now, within each region, we will attempt to identify \emph{envelopes}.
366 An \emph{envelope} is a subsequence of the target sequence that
367 appears to contain alignment probability mass for a likely domain (one
368 local alignment to the profile).
369
370 When the region contains $\simeq$1 expected domain, envelope
371 identification is already done: the region's start and end points are
372 converted directly to the envelope coordinates of a putative domain.
373
374 There are a few cases where the region appears to contain more than
375 one expected domain -{}- where more than one domain is closely spaced on
376 the target sequence and/or the domain scores are weak and the
377 probability masses are ill-resolved from each other. These
378 ``multidomain regions'', when they occur, are passed off to an even
379 more \emph{ad hoc} resolution algorithm called \emph{stochastic
380 traceback clustering}. In stochastic traceback clustering, we sample
381 many alignments from the posterior alignment ensemble, cluster those
382 alignments according to their overlap in start/end coordinates, and
383 pick clusters that sum up to sufficiently high probability. Consensus
384 start and end points are chosen for each cluster of sampled
385 alignments. These start/end points define envelopes.
386
387 These envelopes identified by stochastic traceback clustering are
388 \emph{not} guaranteed to be nonoverlapping. It's possible that there
389 are alternative ``solutions'' for parsing the sequence into domains,
390 when the correct parsing is ambiguous. HMMER will report all
391 high-likelihood solutions, not just a single nonoverlapping parse.\marginnote{
392 It's also possible (though rare) for stochastic clustering to identify
393 \emph{no} envelopes in the region.}
394
395 In a tabular output (\mono{-{}-tblout}) file, the number of regions
396 that had to be subjected to stochastic traceback clustering is given
397 in the column labeled \mono{clu}. This ought to be a small number
398 (often it's zero). The number of envelopes identified by stochastic
399 traceback clustering that overlap with other envelopes is in the
400 column labeled \mono{ov}. If this number is non-zero, you need to be
401 careful when you interpret the details of alignments in the output,
402 because HMMER is going to be showing overlapping alternative
403 solutions. The total number of domain envelopes identified (either by
404 the simple method or by stochastic traceback clustering) is in the
405 column labeled \mono{env}. It ought to be almost the same as the
406 expectation and the number of regions.
407
408 \paragraph{Maximum expected accuracy alignment.}
409 Each envelope is now aligned to the profile using the full
410 Forward/Backward algorithm. The profile is configured to ``unihit''
411 mode, so that the profile expects only one local alignment (domain) in
412 the envelope (as opposed to multiple domains). Posterior decoding is
413 used to calculate the posterior probability of every detailed
414 alignment of profile state to sequence residue. The posterior
415 decodings are used to extract a ``maximum expected accuracy''
416 alignment. Each aligned residue is annotated with its posterior
417 probability in the Forward/Backward alignment ensemble.
418
419 Currently, the Forward, Backward, and posterior decoding calculations
420 at this step are \emph{not} memory efficient. They calculate matrices
421 requiring roughly $36 ML$ bytes, where $M$ is the profile length and
422 $L$ is the length of the envelope subsequence. Usually in
423 \mono{hmmsearch} and \mono{hmmscan}, profiles and envelopes are small
424 enough that this is not a problem. For example, a typical Pfam domain
425 model is about 200 residues long, matching to individual target
426 envelopes of about 200 residues each; this requires about 1.4 MB of
427 memory in MEA alignment. However, in \mono{phmmer} and
428 \mono{jackhmmer} programs, it's often going to be the case that you're
429 aligning an entire query sequence to an entire target sequence in a
430 single unresolved ``domain'' alignment. If this is titin (about 40,000
431 residues), it would require 57.6 GB of RAM. For this reason,
432 currently, \mono{phmmer} and \mono{jackhmmer} can only handle query
433 sequences of up to a few thousand residues. If you see a ``fatal
434 exception'' error complaining about failure of a large memory
435 allocation, you're almost certainly seeing a prohibitive memory
436 requirement at this stage.\footnote{I know how to fix this with
437 memory-efficient algorithms, and I'm working on it.}
438
439 In a tabular output (\mono{-{}-tblout}) file, the number of domains in
440 envelopes (before any significance thresholding) is in the column
441 labeled \mono{dom}. This will generally be the same as the number of
442 envelopes.
443
444 \paragraph{Biased composition score correction (``null2'')}
445 An \emph{ad hoc} biased composition score correction is calculated for
446 each envelope, using the posterior decoding. A corrected bit score and
447 P-value for each envelope is calculated. These null2-corrected scores
448 are subjected to the reporting and inclusion thresholds, at both the full
449 sequence level and per-domain.
450
451 %Once the position-specific ``null2'' score is available, specifying a
452 %biased composition correction that applies to every residue, the total
453 %corrected bit score for the target sequence is recalculated, by
454 %summing up envelope scores for each significant domain.
455
456
457
458 \section{Modifications to the pipeline as used for DNA search}
459
460 \subsection{SSV, not MSV.}
461
462 In the MSV filter, one or more high-scoring ungapped segments
463 contribute to a score that, if sufficiently high, causes the entire
464 sequence to be passed on to the next stage (the bias filter). This
465 strategy won't work for long DNA sequences; it doesn't filter the
466 human genome much to say ``there's a hit on chromosome 1, now
467 postprocess the whole thing''. In the scanning-SSV (``Single ungapped
468 Segment Viterbi'') algorithm used in \mono{nhmmer} and
469 \mono{nhmmscan}, each comparison between a query and target is scanned
470 for high-scoring ungapped alignment segments, and a window around each
471 such segment is extracted, merging overlapping windows. Each window is
472 then passed on to the remaining filter cascade, where it is treated as
473 described above for the most part. As with the MSV filter, the default
474 P-value threshold is $0.02$, and can be controlled with the
475 \mono{-{}-F1} flag.
476
477 The \mono{-{}-max} flag also controls the amount of the sequence database that
478 passes the SSV filter, but instead of the threshold being set to $1.0$, as
479 described for the protein pipeline, it is set to $0.4$.
480 %, which allows passage to anything with a sniff of a chance of passing the
481 % final threshold
482
483 %Without doing this, the
484 %segment-surrounding windows all overlap to the point that merging them causes
485 %full-length chromosomes to possibly trickle down to the later
486 %envelope-definition machinery, causing to out-of-memory errors. As a special
487 %hack in case of very long merged windows, a maximum window length of 80Kb is
488 %enforced by splitting long windows (keeping overlapping blocks, and tracking
489 %shared hits as necessary to avoid duplicates).
490
491
492 \subsection{There are no domains, but there are envelopes}
493
494 In HMMER's protein-search programs, multiple matches of the model to a
495 target sequence are treated as domains contained within a single hit
496 for that sequence. In the DNA-search programs, each match of the model
497 to a subsequence is treated as an independent hit - there's no notion
498 of a domain. This is largely a difference in reporting. Both pipelines
499 rely on essentially the same envelope detection code; envelopes lead
500 to domains in protein search, and hits in DNA search.
501
502
503 \subsection{Biased composition.}
504
505 DNA sequence is littered with regions containing tandem simple repeats
506 or other low complexity sequence. Without accounting for such
507 composition bias, we see many cases in which one part of a hit is
508 obviously legitimate, and serves as the anchor for a neighboring
509 alignment segment that is clearly low-complexity garbage, one form of
510 a problem known as homologous overextension.\cite{Gonzalez10}. The
511 null2 method used in protein search delays score modification until
512 after the alignment is complete, but we know that this kind of
513 overextension can be (mostly) avoided if the model's log odds scores
514 account for the composition bias of the target region while
515 constructing the alignment. The DNA search pipeline therefore does
516 just this: it modifies the scoring scheme for each target envelope as
517 a function of that envelope's sequence composition, then builds the
518 alignment according to that scheme.
519
520
521 %\subsection{More about envelopes.}
522
523 %DNA sequence is littered with regions containing tandem simple repeats or other
524 %low complexity sequence. When an HMM contains a regions with similar bias, the
525 %envelope-definition machinery can produce absurdly long envelopes
526 %around plausible alignments\footnote{we've seen envelopes extending more than
527 %1000 bases beyond the end of an alignment of length 300}. This happens because
528 %the region-identification method is confused: there are many overlapping weak
529 %hits, with no discrete alignment good enough to call a hit.
530
531 %By trimming these very long envelopes such that they are no more than 20 bases
532 %beyond the edges of the aligned range, \ldots
533