Debian Codegraph @

hmmer/src/hmmer.h

raw symbols SCIP
1 /* The all-encompassing include file for HMMER.
2 * All-encompassing because there's a lot of crossdependency.
3 * There's some opportunity for modularity, but not a lot.
4 *
5 * 1. P7_HMM: a core model.
6 * 2. P7_PROFILE: a scoring profile, and its implicit model.
7 * 3. P7_BG: a null (background) model.
8 * 4. P7_TRACE: a traceback path (alignment of seq to profile).
9 * 5. P7_HMMFILE: an HMM save file or database, open for reading.
10 * 6. P7_GMX: a "generic" dynamic programming matrix
11 * 7. P7_PRIOR: mixture Dirichlet prior for profile HMMs
12 * 8. P7_SPENSEMBLE: segment pair ensembles for domain locations
13 * 9. P7_ALIDISPLAY: an alignment formatted for printing
14 * 10. P7_DOMAINDEF: reusably managing workflow in annotating domains
15 * 11. P7_TOPHITS: ranking lists of top-scoring hits
16 * 12. P7_SCOREDATA: data used in diagonal recovery and extension
17 * 13. P7_HMM_WINDOW: data used to track lists of sequence windows
18 * 14. Inclusion of the architecture-specific optimized implementation.
19 * 16. P7_PIPELINE: H3's accelerated seq/profile comparison pipeline
20 * 17. P7_BUILDER: configuration options for new HMM construction.
21 * 18. Declaration of functions in HMMER's exposed API.
22 *
23 * Also, see impl_{sse,vmx,neon}/impl_{sse,vmx,neon}.h for additional API
24 * specific to the acceleration layer; in particular, the P7_OPROFILE
25 * structure for an optimized profile.
26 */
27 #ifndef P7_HMMERH_INCLUDED
28 #define P7_HMMERH_INCLUDED
29 #include <p7_config.h>
30
31 #include <stdio.h>
32 #include <stddef.h> // ptrdiff_t
33
34 #ifdef HMMER_MPI
35 #include "mpi.h"
36 #endif
37
38 #ifdef HMMER_THREADS
39 #include <pthread.h>
40 #endif
41
42 #include "easel.h"
43 #include "esl_alphabet.h" /* ESL_DSQ, ESL_ALPHABET */
44 #include "esl_dmatrix.h" /* ESL_DMATRIX */
45 #include "esl_getopts.h" /* ESL_GETOPTS */
46 #include "esl_histogram.h" /* ESL_HISTOGRAM */
47 #include "esl_hmm.h" /* ESL_HMM */
48 #include "esl_keyhash.h" /* ESL_KEYHASH */
49 #include "esl_mixdchlet.h" /* ESL_MIXDCHLET */
50 #include "esl_msa.h" /* ESL_MSA */
51 #include "esl_random.h" /* ESL_RANDOMNESS */
52 #include "esl_rand64.h" /* ESL_RAND64 */
53 #include "esl_sq.h" /* ESL_SQ */
54 #include "esl_scorematrix.h" /* ESL_SCOREMATRIX */
55 #include "esl_stopwatch.h" /* ESL_STOPWATCH */
56
57
58
59 /* Search modes. */
60 #define p7_NO_MODE 0
61 #define p7_LOCAL 1 /* multihit local: "fs" mode */
62 #define p7_GLOCAL 2 /* multihit glocal: "ls" mode */
63 #define p7_UNILOCAL 3 /* unihit local: "sw" mode */
64 #define p7_UNIGLOCAL 4 /* unihit glocal: "s" mode */
65
66 #define p7_IsLocal(mode) (mode == p7_LOCAL || mode == p7_UNILOCAL)
67 #define p7_IsMulti(mode) (mode == p7_LOCAL || mode == p7_GLOCAL)
68
69 #define p7_NEVPARAM 6 /* number of statistical parameters stored in models */
70 #define p7_NCUTOFFS 6 /* number of Pfam score cutoffs stored in models */
71 #define p7_NOFFSETS 3 /* number of disk offsets stored in models for hmmscan's fast model input */
72 enum p7_evparams_e { p7_MMU = 0, p7_MLAMBDA = 1, p7_VMU = 2, p7_VLAMBDA = 3, p7_FTAU = 4, p7_FLAMBDA = 5 };
73 enum p7_cutoffs_e { p7_GA1 = 0, p7_GA2 = 1, p7_TC1 = 2, p7_TC2 = 3, p7_NC1 = 4, p7_NC2 = 5 };
74 enum p7_offsets_e { p7_MOFFSET = 0, p7_FOFFSET = 1, p7_POFFSET = 2 };
75
76 #define p7_EVPARAM_UNSET -99999.0f /* if evparam[0] is unset, then all unset */
77 #define p7_CUTOFF_UNSET -99999.0f /* if cutoff[XX1] is unset, then cutoff[XX2] unset, XX={GA,TC,NC} */
78 #define p7_COMPO_UNSET -1.0f /* if compo[0] is unset, then all unset */
79
80 /* Option flags when creating multiple alignments with p7_tracealign_*() */
81 #define p7_DEFAULT 0
82 #define p7_DIGITIZE (1<<0)
83 #define p7_ALL_CONSENSUS_COLS (1<<1)
84 #define p7_TRIM (1<<2)
85
86 /* Option flags when creating faux traces with p7_trace_FauxFromMSA() */
87 #define p7_MSA_COORDS (1<<0) /* default: i = unaligned seq residue coords */
88
89 /* Which strand(s) should be searched */
90 enum p7_strands_e { p7_STRAND_TOPONLY = 0, p7_STRAND_BOTTOMONLY = 1, p7_STRAND_BOTH = 2};
91
92 /*****************************************************************
93 * 1. P7_HMM: a core model.
94 *****************************************************************/
95
96 /* Bit flags used in <hmm->flags>: optional annotation in an HMM
97 *
98 * Flags marked with ! may not be changed nor used for other meanings,
99 * because they're codes used by HMMER2 (and earlier) that must be
100 * preserved for reverse compatibility with old HMMER files.
101 *
102 * Why use flags? (So I don't ask this question of myself again:)
103 * 1. The way we allocate an HMM, we need to know if we're allocating
104 * M-width annotation fields (RF, CS, CA, MAP) before we read the
105 * annotation from the file.
106 * 2. Historically, H2 used flags, so we still need to read H2 flags
107 * for backwards compatibility; so we may as well keep using them.
108 */
109 #define p7H_HASBITS (1<<0) /* obsolete (was: model has log-odds scores) !*/
110 #define p7H_DESC (1<<1) /* description exists (legacy; xref SRE:J5/114) !*/
111 #define p7H_RF (1<<2) /* #RF annotation available !*/
112 #define p7H_CS (1<<3) /* #CS annotation available !*/
113 #define p7H_XRAY (1<<4) /* obsolete (was: structural data available) !*/
114 #define p7H_HASPROB (1<<5) /* obsolete (was: model in probability form) !*/
115 #define p7H_HASDNA (1<<6) /* obsolete (was: protein HMM->DNA seq params set) !*/
116 #define p7H_STATS (1<<7) /* model has E-value statistics calibrated !*/
117 #define p7H_MAP (1<<8) /* alignment map is available !*/
118 #define p7H_ACC (1<<9) /* accession is available (legacy; xref SRE:J5/114)!*/
119 #define p7H_GA (1<<10) /* gathering thresholds available !*/
120 #define p7H_TC (1<<11) /* trusted cutoffs available !*/
121 #define p7H_NC (1<<12) /* noise cutoffs available !*/
122 #define p7H_CA (1<<13) /* surface accessibilities available !*/
123 #define p7H_COMPO (1<<14) /* model-specific residue composition available */
124 #define p7H_CHKSUM (1<<15) /* model has an alignment checksum */
125 #define p7H_CONS (1<<16) /* consensus residue line available */
126 #define p7H_MMASK (1<<17) /* #MM annotation available !*/
127
128 /* Indices of Plan7 main model state transitions, hmm->t[k][] */
129 enum p7h_transitions_e {
130 p7H_MM = 0,
131 p7H_MI = 1,
132 p7H_MD = 2,
133 p7H_IM = 3,
134 p7H_II = 4,
135 p7H_DM = 5,
136 p7H_DD = 6
137 };
138 #define p7H_NTRANSITIONS 7
139
140 /* How the hmm->t[k] vector is interpreted as separate probability vectors. */
141 #define P7H_TMAT(hmm, k) ((hmm)->t[k])
142 #define P7H_TINS(hmm, k) ((hmm)->t[k]+3)
143 #define P7H_TDEL(hmm, k) ((hmm)->t[k]+5)
144 #define p7H_NTMAT 3
145 #define p7H_NTDEL 2
146 #define p7H_NTINS 2
147
148 /* Some notes:
149 * 0. The model might be either in counts or probability form.
150 * 1. t[0] is special: t[0][TMM,TMI,TMD] are the begin->M_1,I_0,D_1 entry probabilities,
151 * t[0][TIM,TII] are the I_0 transitions, and delete state 0 doesn't
152 * exist. Therefore D[0] transitions and mat[0] emissions are unused.
153 * To simplify some normalization code, we adopt a convention that these are set
154 * to valid probability distributions: 1.0 for t[0][TDM] and mat[0][0],
155 * and 0 for the rest.
156 * 2. t[M] is also special: TMD and TDD are 0 because there is no next delete state;
157 * TDM is therefore 1.0 by definition. TMM and TDM are interpreted as the
158 * M->E and D->E end transitions. t[M][TDM] must be 1.0, therefore.
159 */
160 typedef struct p7_hmm_s {
161 /*::cexcerpt::plan7_core::begin::*/
162 int M; /* length of the model (# nodes) */
163 float **t; /* transition prob's. t[(0),1..M][0..p7H_NTRANSITIONS-1] */
164 float **mat; /* match emissions. mat[1..M][0..K-1] */
165 float **ins; /* insert emissions. ins[1..M][0..K-1] */
166 /*::cexcerpt::plan7_core::end::*/
167
168 /* Annotation. Everything but <name> is optional. Flags are set when
169 * optional values are set. All the char *'s are proper nul-terminated
170 * strings, not just arrays. (hmm->map is an int array).
171 */
172 char *name; /* name of the model (mandatory) */ /* String, \0-terminated */
173 char *acc; /* accession number of model (Pfam) (optional: NULL) */ /* String, \0-terminated */
174 char *desc; /* brief (1-line) description of model (optional: NULL) */ /* String, \0-terminated */
175 char *rf; /* reference line from alignment 1..M (p7H_RF) */ /* String; 0=' ', M+1='\0' */
176 char *mm; /* model mask line from alignment 1..M (p7H_MM) */ /* String; 0=' ', M+1='\0' */
177 char *consensus; /* consensus residue line 1..M (p7H_CONS) */ /* String; 0=' ', M+1='\0' */
178 char *cs; /* consensus structure line 1..M (p7H_CS) */ /* String; 0=' ', M+1='\0' */
179 char *ca; /* consensus accessibility line 1..M (p7H_CA) */ /* String; 0=' ', M+1='\0' */
180
181 char *comlog; /* command line(s) that built model (optional: NULL) */ /* String, \0-terminated */
182 int nseq; /* number of training sequences (optional: -1) */
183 float eff_nseq; /* effective number of seqs (<= nseq) (optional: -1) */
184 int max_length; /* upper bound length, all but 1e-7 prob (optional: -1) */
185 char *ctime; /* creation date (optional: NULL) */
186 int *map; /* map of alignment cols onto model 1..M (p7H_MAP) */ /* Array; map[0]=0 */
187 uint32_t checksum; /* checksum of training sequences (p7H_CHKSUM) */
188 float evparam[p7_NEVPARAM]; /* E-value params (p7H_STATS) */
189 float cutoff[p7_NCUTOFFS]; /* Pfam score cutoffs (p7H_{GA,TC,NC}) */
190 float compo[p7_MAXABET]; /* model bg residue comp (p7H_COMPO) */
191
192 off_t offset; /* HMM record offset on disk */
193 const ESL_ALPHABET *abc; /* ptr to alphabet info (hmm->abc->K is alphabet size) */
194 int flags; /* status flags */
195 } P7_HMM;
196
197
198 /*****************************************************************
199 * 2. P7_PROFILE: a scoring profile, and its implicit model.
200 *****************************************************************/
201
202 /* Indices for special state types in the length model, gm->xsc[x][]
203 */
204 enum p7p_xstates_e {
205 p7P_E = 0,
206 p7P_N = 1,
207 p7P_J = 2,
208 p7P_C = 3
209 };
210 #define p7P_NXSTATES 4
211
212 /* Indices for transitions from the length modeling scores gm->xsc[][x]
213 */
214 enum p7p_xtransitions_e {
215 p7P_LOOP = 0,
216 p7P_MOVE = 1
217 };
218 #define p7P_NXTRANS 2
219
220 /* Indices for transition scores gm->tsc[k][] */
221 /* order is optimized for dynamic programming */
222 enum p7p_tsc_e {
223 p7P_MM = 0,
224 p7P_IM = 1,
225 p7P_DM = 2,
226 p7P_BM = 3,
227 p7P_MD = 4,
228 p7P_DD = 5,
229 p7P_MI = 6,
230 p7P_II = 7,
231 };
232 #define p7P_NTRANS 8
233
234 /* Indices for residue emission score vectors
235 */
236 enum p7p_rsc_e {
237 p7P_MSC = 0,
238 p7P_ISC = 1
239 };
240 #define p7P_NR 2
241
242 /* Accessing transition, emission scores */
243 /* _BM is specially stored off-by-one: [k-1][p7P_BM] is score for entering at Mk */
244 #define p7P_TSC(gm, k, s) ((gm)->tsc[(k) * p7P_NTRANS + (s)])
245 #define p7P_MSC(gm, k, x) ((gm)->rsc[x][(k) * p7P_NR + p7P_MSC])
246 #define p7P_ISC(gm, k, x) ((gm)->rsc[x][(k) * p7P_NR + p7P_ISC])
247
248
249 typedef struct p7_profile_s {
250 float *tsc; /* transitions [0.1..M-1][0..p7P_NTRANS-1], hand-indexed */
251 float **rsc; /* emissions [0..Kp-1][0.1..M][p7P_NR], hand-indexed */
252 float xsc[p7P_NXSTATES][p7P_NXTRANS]; /* special transitions [NECJ][LOOP,MOVE] */
253
254 int mode; /* configured algorithm mode (e.g. p7_LOCAL) */
255 int L; /* current configured target seq length */
256 int allocM; /* max # of nodes allocated in this structure */
257 int M; /* number of nodes in the model */
258 int max_length; /* calculated upper bound on emitted seq length */
259 float nj; /* expected # of uses of J; precalculated from loop config */
260
261 /* Info, most of which is a copy from parent HMM: */
262 char *name; /* unique name of model */
263 char *acc; /* unique accession of model, or NULL */
264 char *desc; /* brief (1-line) description of model, or NULL */
265 char *rf; /* reference line from alignment 1..M; *rf=0 means unused */
266 char *mm; /* modelmask line 1..M; *ref=0: unused */
267 char *cs; /* consensus structure line 1..M, *cs=0 means unused */
268 char *consensus; /* consensus residues to display in alignments, 1..M */
269 float evparam[p7_NEVPARAM]; /* parameters for determining E-values, or UNSET */
270 float cutoff[p7_NCUTOFFS]; /* per-seq/per-domain bit score cutoffs, or UNSET */
271 float compo[p7_MAXABET]; /* per-model HMM filter composition, or UNSET */
272
273 /* Disk offset information for hmmpfam's fast model retrieval */
274 off_t offs[p7_NOFFSETS]; /* p7_{MFP}OFFSET, or -1 */
275
276 off_t roff; /* record offset (start of record); -1 if none */
277 off_t eoff; /* offset to last byte of record; -1 if unknown */
278
279 const ESL_ALPHABET *abc; /* copy of pointer to appropriate alphabet */
280 } P7_PROFILE;
281
282
283
284 /*****************************************************************
285 * 3. P7_BG: a null (background) model.
286 *****************************************************************/
287
288 /* This really contains three different things:
289 *
290 * - the "null1" model, a one-state HMM consisting of background
291 * frequencies <f> and a parameter <p1> for a target-length
292 * dependent geometric;
293 *
294 * - the "bias filter" <fhmm> a two-state HMM composed from null1's
295 * background <f> and the model's mean composition <compo>. This
296 * model is constructed dynamically, every time a new profile is
297 * considered;
298 *
299 * - a single term <omega> that's needed by the "null2" model to set
300 * a balance between the null1 and null2 scoring terms. The null2
301 * model is otherwise defined by construction, in p7_domaindef.c.
302 *
303 * Someday we might pull this apart into two or three separate
304 * objects.
305 */
306 typedef struct p7_bg_s {
307 float *f; /* null1 background residue frequencies [0..K-1]: set at initialization */
308 float p1; /* null1's transition prob: p7_bg_SetLength() sets this from target seq L */
309
310 ESL_HMM *fhmm; /* bias filter: p7_bg_SetFilter() sets this, from model's mean composition */
311
312 float omega; /* the "prior" on null2/null3: set at initialization (one omega for both null types) */
313
314 const ESL_ALPHABET *abc; /* reference to alphabet in use: set at initialization */
315 } P7_BG;
316
317 /*****************************************************************
318 * 4. P7_TRACE: a traceback (alignment of seq to profile).
319 *****************************************************************/
320
321 /* Traceback structure for alignment of a model to a sequence.
322 *
323 * A traceback only makes sense in a triplet (tr, gm, dsq), for a
324 * given profile or HMM (with nodes 1..M) and a given digital sequence
325 * (with positions 1..L).
326 *
327 * A traceback may be relative to a profile (usually) or to a core
328 * model (as a special case in model construction; see build.c). You
329 * can tell the difference by looking at the first statetype,
330 * tr->st[0]; if it's a p7T_S, it's for a profile, and if it's p7T_B,
331 * it's for a core model.
332 *
333 * A "profile" trace uniquely has S,N,C,T,J states and their
334 * transitions; it also can have B->Mk and Mk->E internal entry/exit
335 * transitions for local alignments. It may not contain X states.
336 *
337 * A "core" trace may contain I0, IM, and D1 states and their
338 * transitions. A "core" trace can also have B->X->{MDI}k and
339 * {MDI}k->X->E transitions as a special hack in a build procedure, to
340 * deal with the case of a local alignment fragment implied by an
341 * input alignment, which is "impossible" for a core model.
342 * X "states" only appear in core traces, and only at these
343 * entry/exit places; some code depends on this.
344 *
345 * A profile's N,C,J states emit on transition, not on state, so a
346 * path of N emits 0 residues, NN emits 1 residue, NNN emits 2
347 * residues, and so on. By convention, the trace always associates an
348 * emission-on-transition with the trailing (destination) state, so
349 * the first N, C, or J is stored in a trace as a nonemitter (i=0).
350 *
351 * A i coords in a traceback are usually 1..L with respect to an
352 * unaligned digital target sequence, but in the special case of
353 * traces faked from existing MSAs (as in hmmbuild), the coords may
354 * be 1..alen relative to an MSA's columns.
355 */
356
357 /* State types */
358 enum p7t_statetype_e {
359 p7T_BOGUS = 0,
360 p7T_M = 1,
361 p7T_D = 2,
362 p7T_I = 3,
363 p7T_S = 4,
364 p7T_N = 5,
365 p7T_B = 6,
366 p7T_E = 7,
367 p7T_C = 8,
368 p7T_T = 9,
369 p7T_J = 10,
370 p7T_X = 11, /* missing data: used esp. for local entry/exits */
371 };
372 #define p7T_NSTATETYPES 12
373
374 typedef struct p7_trace_s {
375 int N; /* length of traceback */
376 int nalloc; /* allocated length of traceback */
377 char *st; /* state type code [0..N-1]*/
378 int *k; /* node index; 1..M if M,D,I; else 0 [0..N-1]*/
379 int *i; /* pos emitted in dsq, 1..L; else 0 [0..N-1]*/
380 float *pp; /* posterior prob of x_i; else 0 [0..N-1]*/
381 int M; /* model length M (maximum k) */
382 int L; /* sequence length L (maximum i) */
383
384 /* The following section is data generated by "indexing" a trace's domains */
385 int ndom; /* number of domains in trace (= # of B or E states) */
386 int *tfrom, *tto; /* locations of B/E states in trace (0..tr->N-1) */
387 int *sqfrom, *sqto; /* first/last M-emitted residue on sequence (1..L) */
388 int *hmmfrom, *hmmto;/* first/last M state on model (1..M) */
389 int ndomalloc; /* current allocated size of these stacks */
390
391 } P7_TRACE;
392
393
394
395 /*****************************************************************
396 * 5. P7_HMMFILE: an HMM save file or database, open for reading.
397 *****************************************************************/
398
399 /* These tags need to be in temporal order, so we can do tests
400 * like "if (format >= p7_HMMFILE_3b) ..."
401 */
402 enum p7_hmmfile_formats_e {
403 p7_HMMFILE_20 = 0,
404 p7_HMMFILE_3a = 1,
405 p7_HMMFILE_3b = 2,
406 p7_HMMFILE_3c = 3,
407 p7_HMMFILE_3d = 4,
408 p7_HMMFILE_3e = 5,
409 p7_HMMFILE_3f = 6,
410 };
411
412 typedef struct p7_hmmfile_s {
413 FILE *f; /* pointer to stream for reading models */
414 char *fname; /* (fully qualified) name of the HMM file; [STDIN] if - */
415 ESL_SSI *ssi; /* open SSI index for model file <f>; NULL if none. */
416
417 int do_gzip; /* TRUE if f is "gzip -dc |" (will pclose(f)) */
418 int do_stdin; /* TRUE if f is stdin (won't close f) */
419 int newly_opened; /* TRUE if we just opened the stream (and parsed magic) */
420 int is_pressed; /* TRUE if a pressed HMM database file (Pfam or equiv) */
421
422 int format; /* HMM file format code */
423 int (*parser)(struct p7_hmmfile_s *, ESL_ALPHABET **, P7_HMM **);
424 ESL_FILEPARSER *efp;
425
426 /* If <is_pressed>, we can read optimized profiles directly, via: */
427 FILE *ffp; /* MSV part of the optimized profile */
428 FILE *pfp; /* rest of the optimized profile */
429
430 #ifdef HMMER_THREADS
431 int syncRead;
432 pthread_mutex_t readMutex;
433 #endif
434
435 char errbuf[eslERRBUFSIZE];
436 char rr_errbuf[eslERRBUFSIZE]; // p7_oprofile_ReadRest() uses this instead of errbuf, as a workaround for a thread race issue. See notes there.
437 } P7_HMMFILE;
438
439 /* note on <fname>, above:
440 * this is the actual name of the HMM file being read.
441 *
442 * The way p7_hmmfile_Open() works, it will preferentially look for
443 * hmmpress'ed binary files. If you open "foo", it will first try to
444 * open "foo.h3m" and <fname> will be "foo.h3m". "foo" does not even
445 * have to exist. If a parsing error occurs, you want <fname> to
446 * be "foo.h3m", so error messages report blame correctly.
447 * In the special case of reading from stdin, <fname> is "[STDIN]".
448 */
449
450
451 /*****************************************************************
452 * 6. P7_GMX: a "generic" dynamic programming matrix
453 *****************************************************************/
454
455 enum p7g_scells_e {
456 p7G_M = 0,
457 p7G_I = 1,
458 p7G_D = 2,
459 };
460 #define p7G_NSCELLS 3
461
462 enum p7g_xcells_e {
463 p7G_E = 0,
464 p7G_N = 1,
465 p7G_J = 2,
466 p7G_B = 3,
467 p7G_C = 4
468 };
469 #define p7G_NXCELLS 5
470
471
472 typedef struct p7_gmx_s {
473 int M; /* actual model dimension (model 1..M) */
474 int L; /* actual sequence dimension (seq 1..L) */
475
476 int allocR; /* current allocated # of rows : L+1 <= validR <= allocR */
477 int validR; /* # of rows actually pointing at DP memory */
478 int allocW; /* current set row width : M+1 <= allocW */
479 uint64_t ncells; /* total # of allocated cells in 2D matrix : ncells >= (validR)(allocW) */
480
481 float **dp; /* logically [0.1..L][0.1..M][0..p7G_NSCELLS-1]; indexed [i][k*p7G_NSCELLS+s] */
482 float *xmx; /* logically [0.1..L][0..p7G_NXCELLS-1]; indexed [i*p7G_NXCELLS+s] */
483
484 float *dp_mem;
485 } P7_GMX;
486
487 /* Macros below implement indexing idioms for generic DP routines.
488 * They require the following setup, for profile <gm> and matrix <gx>:
489 * float const *tsc = gm->tsc;
490 * float **dp = gx->dp;
491 * float *xmx = gx->xmx;
492 * and for each row i (target residue x_i in digital seq <dsq>):
493 * float const *rsc = gm->rsc[dsq[i]];
494 */
495 #define MMX(i,k) (dp[(i)][(k) * p7G_NSCELLS + p7G_M])
496 #define IMX(i,k) (dp[(i)][(k) * p7G_NSCELLS + p7G_I])
497 #define DMX(i,k) (dp[(i)][(k) * p7G_NSCELLS + p7G_D])
498 #define XMX(i,s) (xmx[(i) * p7G_NXCELLS + (s)])
499
500 #define TSC(s,k) (tsc[(k) * p7P_NTRANS + (s)])
501 #define MSC(k) (rsc[(k) * p7P_NR + p7P_MSC])
502 #define ISC(k) (rsc[(k) * p7P_NR + p7P_ISC])
503
504 /* Flags that control P7_GMX debugging dumps */
505 #define p7_HIDE_SPECIALS (1<<0)
506 #define p7_SHOW_LOG (1<<1)
507
508
509 /*****************************************************************
510 * 7. P7_PRIOR: mixture Dirichlet prior for profile HMMs
511 *****************************************************************/
512
513 typedef struct p7_prior_s {
514 ESL_MIXDCHLET *tm; /* match transitions */
515 ESL_MIXDCHLET *ti; /* insert transitions */
516 ESL_MIXDCHLET *td; /* delete transitions */
517 ESL_MIXDCHLET *em; /* match emissions */
518 ESL_MIXDCHLET *ei; /* insert emissions */
519 } P7_PRIOR;
520
521
522
523
524 /*****************************************************************
525 * 8. P7_SPENSEMBLE: segment pair ensembles for domain locations
526 *****************************************************************/
527
528 /* struct p7_spcoord_s:
529 * a coord quad defining a segment pair.
530 */
531 struct p7_spcoord_s {
532 int idx; /* backreference index: which trace a seg came from, or which cluster a domain came from */
533 int i, j; /* start,end in a target sequence (1..L) */
534 int k, m; /* start,end in a query model (1..M) */
535 float prob; /* posterior probability of segment */
536 };
537
538 /* Structure: P7_SPENSEMBLE
539 *
540 * Collection and clustering of an ensemble of sampled segment pairs,
541 * in order to define domain locations using their posterior
542 * probability distribution (as opposed to Viterbi MAP tracebacks).
543 */
544 typedef struct p7_spensemble_s {
545 /* Section 1: a collected ensemble of segment pairs */
546 int nsamples; /* number of sampled traces */
547 struct p7_spcoord_s *sp; /* array of sampled seg pairs; [0..n-1] */
548 int nalloc; /* allocated size of <sp> */
549 int n; /* number of seg pairs in <sp> */
550
551 /* Section 2: then the ensemble is clustered by single-linkage clustering */
552 int *workspace; /* temp space for Easel SLC algorithm: 2*n */
553 int *assignment; /* each seg pair's cluster index: [0..n-1] = (0..nc-1) */
554 int nc; /* number of different clusters */
555
556 /* Section 3: then endpoint distribution is examined within each large cluster */
557 int *epc; /* array counting frequency of each endpoint */
558 int epc_alloc; /* allocated width of <epc> */
559
560 /* Section 4: finally each large cluster is resolved into domain coords */
561 struct p7_spcoord_s *sigc; /* array of coords for each domain, [0..nsigc-1] */
562 int nsigc; /* number of "significant" clusters, domains */
563 int nsigc_alloc; /* current allocated max for nsigc */
564 } P7_SPENSEMBLE;
565
566
567
568 /*****************************************************************
569 * 9. P7_ALIDISPLAY: an alignment formatted for printing
570 *****************************************************************/
571
572 /* Structure: P7_ALIDISPLAY
573 *
574 * Alignment of a sequence domain to an HMM, formatted for printing.
575 *
576 * For an alignment of L residues and names C chars long, requires
577 * 6L + 2C + 30 bytes; for typical case of L=100,C=10, that's
578 * <0.7 Kb.
579 */
580 typedef struct p7_alidisplay_s {
581 char *rfline; /* reference coord info; or NULL */
582 char *mmline; /* modelmask coord info; or NULL */
583 char *csline; /* consensus structure info; or NULL */
584 char *model; /* aligned query consensus sequence */
585 char *mline; /* "identities", conservation +'s, etc. */
586 char *aseq; /* aligned target sequence */
587 char *ntseq; /* nucleotide target sequence if nhmmscant */
588 char *ppline; /* posterior prob annotation; or NULL */
589 int N; /* length of strings */
590
591 char *hmmname; /* name of HMM */
592 char *hmmacc; /* accession of HMM; or [0]='\0' */
593 char *hmmdesc; /* description of HMM; or [0]='\0' */
594 int hmmfrom; /* start position on HMM (1..M, or -1) */
595 int hmmto; /* end position on HMM (1..M, or -1) */
596 int M; /* length of model */
597
598 char *sqname; /* name of target sequence */
599 char *sqacc; /* accession of target seq; or [0]='\0' */
600 char *sqdesc; /* description of targ seq; or [0]='\0' */
601 int64_t sqfrom; /* start position on sequence (1..L) */
602 int64_t sqto; /* end position on sequence (1..L) */
603 int64_t L; /* length of sequence */
604
605 int memsize; /* size of allocated block of memory */
606 char *mem; /* memory used for the char data above */
607 } P7_ALIDISPLAY;
608
609
610 /*****************************************************************
611 * 10. P7_DOMAINDEF: reusably managing workflow in defining domains
612 *****************************************************************/
613
614 typedef struct p7_dom_s {
615 int64_t ienv, jenv;
616 int64_t iali, jali;
617 int64_t iorf, jorf; /* Used in translated search to capture the range in the DNA sequence of the ORF containing the match to a protein query */
618 float envsc; /* Forward score in envelope ienv..jenv; NATS; without null2 correction */
619 float domcorrection; /* null2 score when calculating a per-domain score; NATS */
620 float dombias; /* FLogsum(0, log(bg->omega) + domcorrection): null2 score contribution; NATS */
621 float oasc; /* optimal accuracy score (units: expected # residues correctly aligned) */
622 float bitscore; /* overall score in BITS, null corrected, if this were the only domain in seq */
623 double lnP; /* log(P-value) of the bitscore */
624 int is_reported; /* TRUE if domain meets reporting thresholds */
625 int is_included; /* TRUE if domain meets inclusion thresholds */
626 float *scores_per_pos; /* only used by `nhmmer --aliscoresout`; score in BITS that each pos in ali contributes to viterbi score */
627 P7_ALIDISPLAY *ad;
628 } P7_DOMAIN;
629
630 /* Structure: P7_DOMAINDEF
631 *
632 * This is a container for all the necessary information for domain
633 * definition procedures in <p7_domaindef.c>, including a bunch of
634 * heuristic thresholds. The structure is reusable to minimize the
635 * number of allocation/free cycles that need to be done when
636 * processing a large number of sequences. You create the structure
637 * with <p7_domaindef_Create()>; after you're done with defining
638 * domains on a sequence, you call <p7_domaindef_Reuse()> before using
639 * it on the next sequence; and when you're completely done, you free
640 * it with <p7_domaindef_Destroy()>. All memory management is handled
641 * internally; you don't need to reallocate anything yourself.
642 */
643 typedef struct p7_domaindef_s {
644 /* for posteriors of being in a domain, B, E */
645 float *mocc; /* mocc[i=1..L] = prob that i is emitted by core model (is in a domain) */
646 float *btot; /* btot[i=1..L] = cumulative expected times that domain starts at or before i */
647 float *etot; /* etot[i=1..L] = cumulative expected times that domain ends at or before i */
648 int L;
649 int Lalloc;
650
651 /* the ad hoc null2 model: 1..L nat scores for each residue, log f'(x_i) / f(x_i) */
652 float *n2sc;
653
654 /* rng and reusable memory for stochastic tracebacks */
655 ESL_RANDOMNESS *r; /* random number generator */
656 int do_reseeding; /* TRUE to reset the RNG, make results reproducible */
657 P7_SPENSEMBLE *sp; /* an ensemble of sampled segment pairs (domain endpoints) */
658 P7_TRACE *tr; /* reusable space for a trace of a domain */
659 P7_TRACE *gtr; /* reusable space for a traceback of the entire target seq */
660
661 /* Heuristic thresholds that control the region definition process */
662 /* "rt" = "region threshold", for lack of better term */
663 float rt1; /* controls when regions are called. mocc[i] post prob >= dt1 : triggers a region around i */
664 float rt2; /* controls extent of regions. regions extended until mocc[i]-{b,e}occ[i] < dt2 */
665 float rt3; /* controls when regions are flagged for split: if expected # of E preceding B is >= dt3 */
666
667 /* Heuristic thresholds that control the stochastic traceback/clustering process */
668 int nsamples; /* collect ensemble of this many stochastic traces */
669 float min_overlap; /* 0.8 means >= 80% overlap of (smaller/larger) segment to link, both in seq and hmm */
670 int of_smaller; /* see above; TRUE means overlap denom is calc'ed wrt smaller segment; FALSE means larger */
671 int max_diagdiff; /* 4 means either start or endpoints of two segments must be within <=4 diagonals of each other */
672 float min_posterior; /* 0.25 means a cluster must have >= 25% posterior prob in the sample to be reported */
673 float min_endpointp; /* 0.02 means choose widest endpoint with post prob of at least 2% */
674
675 /* storage of the results; domain locations, scores, alignments */
676 P7_DOMAIN *dcl;
677 int ndom; /* number of domains defined, in the end. */
678 int nalloc; /* number of domain structures allocated in <dcl> */
679
680 /* Additional results storage */
681 float nexpected; /* posterior expected number of domains in the sequence (from posterior arrays) */
682 int nregions; /* number of regions evaluated */
683 int nclustered; /* number of regions evaluated by clustering ensemble of tracebacks */
684 int noverlaps; /* number of envelopes defined in ensemble clustering that overlap w/ prev envelope */
685 int nenvelopes; /* number of envelopes handed over for domain definition, null2, alignment, and scoring. */
686
687 } P7_DOMAINDEF;
688
689
690 /*****************************************************************
691 * 11. P7_TOPHITS: ranking lists of top-scoring hits
692 *****************************************************************/
693
694 #define p7_HITFLAGS_DEFAULT 0
695 #define p7_IS_INCLUDED (1<<0)
696 #define p7_IS_REPORTED (1<<1)
697 #define p7_IS_NEW (1<<2)
698 #define p7_IS_DROPPED (1<<3)
699 #define p7_IS_DUPLICATE (1<<4)
700
701
702 /* Structure: P7_HIT
703 *
704 * Info about a high-scoring database hit, kept so we can output a
705 * sorted list of high hits at the end.
706 *
707 * sqfrom and sqto are the coordinates that will be shown
708 * in the results, not coords in arrays... therefore, reverse
709 * complements have sqfrom > sqto
710 */
711 typedef struct p7_hit_s {
712 char *name; /* name of the target (mandatory) */
713 char *acc; /* accession of the target (optional; else NULL) */
714 char *desc; /* description of the target (optional; else NULL) */
715 int window_length; /* for later use in e-value computation, when splitting long sequences */
716 double sortkey; /* number to sort by; big is better */
717
718 float score; /* bit score of the sequence (all domains, w/ correction) */
719 float pre_score; /* bit score of sequence before null2 correction */
720 float sum_score; /* bit score reconstructed from sum of domain envelopes */
721
722 double lnP; /* log(P-value) of the score */
723 double pre_lnP; /* log(P-value) of the pre_score */
724 double sum_lnP; /* log(P-value) of the sum_score */
725
726 float nexpected; /* posterior expected number of domains in the sequence (from posterior arrays) */
727 int nregions; /* number of regions evaluated */
728 int nclustered; /* number of regions evaluated by clustering ensemble of tracebacks */
729 int noverlaps; /* number of envelopes defined in ensemble clustering that overlap w/ prev envelope */
730 int nenvelopes; /* number of envelopes handed over for domain definition, null2, alignment, and scoring. */
731 int ndom; /* total # of domains identified in this seq */
732
733 uint32_t flags; /* p7_IS_REPORTED | p7_IS_INCLUDED | p7_IS_NEW | p7_IS_DROPPED */
734 int nreported; /* # of domains satisfying reporting thresholding */
735 int nincluded; /* # of domains satisfying inclusion thresholding */
736 int best_domain; /* index of best-scoring domain in dcl */
737
738 int64_t seqidx; /*unique identifier to track the database sequence from which this hit came*/
739 int64_t subseq_start; /*used to track which subsequence of a full_length target this hit came from, for purposes of removing duplicates */
740
741 P7_DOMAIN *dcl; /* domain coordinate list and alignment display */
742 esl_pos_t offset; /* used in socket communications, in serialized communication: offset of P7_DOMAIN msg for this P7_HIT */
743 } P7_HIT;
744
745
746 /* Structure: P7_TOPHITS
747 * merging when we prepare to output results. "hit" list is NULL and
748 * unavailable until after we do a sort.
749 */
750 typedef struct p7_tophits_s {
751 P7_HIT **hit; /* sorted pointer array */
752 P7_HIT *unsrt; /* unsorted data storage */
753 uint64_t Nalloc; /* current allocation size */
754 uint64_t N; /* number of hits in list now */
755 uint64_t nreported; /* number of hits that are reportable */
756 uint64_t nincluded; /* number of hits that are includable */
757 int is_sorted_by_sortkey; /* TRUE when hits sorted by sortkey and th->hit valid for all N hits */
758 int is_sorted_by_seqidx; /* TRUE when hits sorted by seq_idx, position, and th->hit valid for all N hits */
759 } P7_TOPHITS;
760
761
762
763
764
765 /*****************************************************************
766 * 12. P7_SCOREDATA: data used in diagonal recovery and extension
767 *****************************************************************/
768
769 enum p7_scoredatatype_e {
770 p7_sd_std = 0,
771 p7_sd_fm = 1,
772 };
773
774
775 /* This contains a compact representation of 8-bit bias-shifted scores for use in
776 * diagonal recovery (standard SSV) and extension (standard and FM-SSV),
777 * along with MAXL-associated prefix- and suffix-lengths, and optimal extensions
778 * for FM-SSV.
779 */
780 typedef struct p7_scoredata_s {
781 int type;
782 int M;
783 union {//implicit (M+1)*K matrix, where M = # states, and K = # characters in alphabet
784 uint8_t *ssv_scores; // this 2D array is used in the default nhmmer pipeline
785 float *ssv_scores_f; // this 2D array is used in the FM-index based pipeline
786 };
787 float *prefix_lengths;
788 float *suffix_lengths;
789 float *fwd_scores;
790 float **fwd_transitions;
791 float **opt_ext_fwd; // Used only for FM-index based pipeline
792 float **opt_ext_rev; // Used only for FM-index based pipeline
793 } P7_SCOREDATA;
794
795
796 /*****************************************************************
797 * 13. P7_HMM_WINDOW: data used to track lists of sequence windows
798 *****************************************************************/
799
800
801 typedef struct p7_hmm_window_s {
802 float score;
803 float null_sc;
804 int32_t id; //sequence id of the database sequence hit
805 int64_t n; //position in database sequence at which the diagonal/window starts
806 int64_t fm_n; //position in the concatenated fm-index sequence at which the diagonal starts
807 int32_t length; // length of the diagonal/window
808 int16_t k; //position of the model at which the diagonal ends
809 int64_t target_len; //length of the target sequence
810 int8_t complementarity;
811 int8_t used_to_extend;
812 } P7_HMM_WINDOW;
813
814 typedef struct p7_hmm_window_list_s {
815 P7_HMM_WINDOW *windows;
816 int count;
817 int size;
818 } P7_HMM_WINDOWLIST;
819
820
821
822 /*****************************************************************
823 * 14. Choice of vector implementation.
824 *****************************************************************/
825 #if defined (eslENABLE_NEON)
826 #include "impl_neon/impl_neon.h"
827 #elif defined (eslENABLE_SSE)
828 #include "impl_sse/impl_sse.h"
829 #elif defined (eslENABLE_VMX)
830 #include "impl_vmx/impl_vmx.h"
831 #else
832 #error "No vector implementation enabled"
833 #endif
834
835
836 /*****************************************************************
837 * 15. The FM-index acceleration to the SSV filter. Only works for SSE
838 *****************************************************************/
839 #define FM_MAX_LINE 256
840
841 /* Structure the 2D occ array into a single array. "type" is either b or sb.
842 * Note that one extra count value is required by RLE, one 4-byte int for
843 * each superblock count vector, and one 2-byte short for each block count
844 * vector. This is small overhead, even for a small alphabet like dna.
845 */
846 #define FM_OCC_CNT( type, i, c) ( occCnts_##type[(meta->alph_size)*(i) + (c)])
847
848 enum fm_alphabettypes_e {
849 fm_DNA = 0, //acgt, 2 bit
850 //fm_DNA_full = 1, //includes ambiguity codes, 4 bit.
851 fm_AMINO = 4, // 5 bit
852 };
853 /*TODO: fm_DNA_full has currently been disabled because of problems with how the
854 * FM index handles very long runs of the same character (in this case, Ns).
855 * See wheelert/notebook/2013/12-11-FM-alphabet-speed notes on 12/12.
856 */
857
858 enum fm_direction_e {
859 fm_forward = 0,
860 fm_backward = 1,
861 };
862
863
864 typedef struct fm_interval_s {
865 int lower;
866 int upper;
867 } FM_INTERVAL;
868
869 typedef struct fm_hit_s {
870 uint64_t start;
871 uint32_t block;
872 int direction;
873 int length;
874 int sortkey;
875 } FM_HIT;
876
877
878
879 typedef struct fm_ambiglist_s {
880 FM_INTERVAL *ranges;
881 uint32_t count;
882 uint32_t size;
883 } FM_AMBIGLIST;
884
885
886 typedef struct fm_seqdata_s {
887
888 uint32_t target_id; // Which sequence in the target database did this segment come from (can be multiple segment per sequence, if a sequence has Ns)
889 uint64_t target_start; // The position in sequence {id} in the target database at which this sequence-block starts (usually 1, unless its a long sequence split out over multiple FMs)
890 uint32_t fm_start; // The position in the FM block at which this sequence begins
891 uint32_t length; // Length of this sequence segment (usually the length of the target sequence, unless its a long sequence split out over multiple FMs)
892
893
894 //meta data taken from the sequence this segment was taken from
895 uint16_t name_length;
896 uint16_t source_length;
897 uint16_t acc_length;
898 uint16_t desc_length;
899 char *name;
900 char *source;
901 char *acc;
902 char *desc;
903 } FM_SEQDATA;
904
905
906 typedef struct fm_metadata_s {
907 uint8_t fwd_only;
908 uint8_t alph_type;
909 uint8_t alph_size;
910 uint8_t charBits;
911 uint32_t freq_SA; //frequency with which SA is sampled
912 uint32_t freq_cnt_sb; //frequency with which full cumulative counts are captured
913 uint32_t freq_cnt_b; //frequency with which intermittent counts are captured
914 uint16_t block_count;
915 uint32_t seq_count;
916 uint64_t char_count; //total count of characters including those in and out of the alphabet
917 char *alph;
918 char *inv_alph;
919 int *compl_alph;
920 FILE *fp;
921 FM_SEQDATA *seq_data;
922 FM_AMBIGLIST *ambig_list;
923 } FM_METADATA;
924
925
926 typedef struct fm_data_s {
927 uint64_t N; //length of text
928 uint32_t term_loc; // location in the BWT at which the '$' char is found (replaced in the sequence with 'a')
929 uint32_t seq_offset;
930 uint32_t ambig_offset;
931 uint32_t seq_cnt;
932 uint32_t ambig_cnt;
933 uint32_t overlap; // number of bases at the beginning that overlap the FM-index for the preceding block
934 uint8_t *T; //text corresponding to the BWT
935 uint8_t *BWT_mem;
936 uint8_t *BWT;
937 uint32_t *SA; // sampled suffix array
938 int64_t *C; //the first position of each letter of the alphabet if all of T is sorted. (signed, as I use that to keep tract of presence/absence)
939 uint32_t *occCnts_sb;
940 uint16_t *occCnts_b;
941 } FM_DATA;
942
943 typedef struct fm_dp_pair_s {
944 uint16_t pos; // position of the diagonal in the model.
945 float score;
946 float max_score;
947 uint8_t score_peak_len; // how long was the diagonal when the most recent peak (within fm_drop_lim of the max score) was seen?
948 uint8_t consec_pos;
949 uint8_t max_consec_pos;
950 uint8_t consec_consensus;
951 uint8_t model_direction;
952 uint8_t complementarity;
953 } FM_DP_PAIR;
954
955
956 typedef struct fm_diag_s {
957 uint64_t n; //position of the database sequence at which the diagonal starts
958 union {
959 double sortkey;
960 double score;
961 };
962 uint16_t k; //position of the model at which the diagonal starts
963 uint16_t length;
964 uint8_t complementarity;
965 } FM_DIAG;
966
967 typedef struct fm_diaglist_s {
968 FM_DIAG *diags;
969 int count;
970 int size;
971 } FM_DIAGLIST;
972
973 /* Effectively global variables, to be initialized once in fm_initConfig(),
974 * then passed around among threads to avoid recomputing them
975 *
976 * When allocated, must be 16-byte aligned, and all _m128i elements
977 * must precede other types
978 */
979 typedef struct {
980 #if defined (eslENABLE_SSE)
981 /* mask arrays, and 16-byte-offsets into them */
982 __m128i *fm_masks_mem;
983 __m128i *fm_masks_v;
984 __m128i *fm_reverse_masks_mem;
985 __m128i *fm_reverse_masks_v;
986 __m128i *fm_chars_mem;
987 __m128i *fm_chars_v;
988
989 /*various precomputed vectors*/
990 __m128i fm_allones_v;
991 __m128i fm_zeros_v;
992 __m128i fm_neg128_v;
993 __m128i fm_m0f; //00 00 11 11
994 __m128i fm_m01; //01 01 01 01
995 __m128i fm_m11; //00 00 00 11
996
997 /* no non-__m128i- elements above this line */
998 #endif //#if defined (eslENABLE_SSE)
999
1000 /*counter, to compute FM-index speed*/
1001 int occCallCnt;
1002
1003 /*bounding cutoffs*/
1004 int max_depth;
1005 float drop_lim; // 0.2 ; in seed, max drop in a run of length [fm_drop_max_len]
1006 int drop_max_len; // 4 ; maximum run length with score under (max - [fm_drop_lim])
1007 int consec_pos_req; //5
1008 int consensus_match_req; //10
1009 float score_density_req; //.5
1010 int ssv_length;
1011 float scthreshFM;
1012 float sc_thresh_ratio; //information content deficit, actual_relent/target_relent
1013
1014 /*pointer to FM-index metadata*/
1015 FM_METADATA *meta;
1016
1017 } FM_CFG;
1018
1019
1020 #if defined (eslENABLE_SSE)
1021 //used to convert from a byte array to an __m128i
1022 typedef union {
1023 uint8_t bytes[16];
1024 __m128i m128;
1025 } byte_m128;
1026
1027
1028 /* Gather the sum of all counts in a 16x8-bit element into a single 16-bit
1029 * element of the register (the 0th element)
1030 *
1031 * the _mm_sad_epu8 accumulates 8-bit counts into 16-bit counts:
1032 * left 8 counts (64-bits) accumulate in counts_v[0],
1033 * right 8 counts in counts_v[4] (the other 6 16-bit ints are 0)
1034 * the _mm_shuffle_epi32 flips the 4th int into the 0th slot
1035 */
1036 #define FM_GATHER_8BIT_COUNTS( in_v, mid_v, out_v ) do {\
1037 mid_v = _mm_sad_epu8 (in_v, cfg->fm_zeros_v);\
1038 tmp_v = _mm_shuffle_epi32(mid_v, _MM_SHUFFLE(1, 1, 1, 2));\
1039 out_v = _mm_add_epi16(mid_v, tmp_v);\
1040 } while (0)
1041
1042
1043 /* Macro for SSE operations to turn 2-bit character values into 2-bit binary
1044 * (00 or 01) match/mismatch values representing occurrences of a character in a
1045 * 4-char-per-byte packed BWT.
1046 *
1047 * Typically followed by a call to FM_COUNT_SSE_4PACKED, possibly with a
1048 * mask in between to handle the case where we don't want to add over all
1049 * positions in the vector
1050 *
1051 * tmp_v and tmp2_v are used as temporary vectors throughout, and hold meaningless values
1052 * at the end
1053 *
1054 * xor(in_v, c_v) : each 2-bit value will be 00 if a match, and non-0 if a mismatch
1055 * and(in_v, 01010101) : look at the right bit of each 2-bit value,
1056 * srli(1)+and() : look at the left bit of each 2-bit value,
1057 * or() : if either left bit or right bit is non-0, 01, else 00 (match is 00)
1058 *
1059 * subs() : invert, so match is 01, mismatch is 00
1060 *
1061 */
1062 #define FM_MATCH_2BIT(in_v, c_v, a_v, b_v, out_v) do {\
1063 a_v = _mm_xor_si128(in_v, c_v);\
1064 \
1065 b_v = _mm_srli_epi16(a_v, 1);\
1066 a_v = _mm_or_si128(a_v, b_v);\
1067 b_v = _mm_and_si128(a_v, cfg->fm_m01);\
1068 \
1069 out_v = _mm_subs_epi8(cfg->fm_m01,b_v);\
1070 } while (0)
1071
1072
1073 /*Macro for SSE operations to count bits produced by FM_MATCH_SSE_4PACKED
1074 *
1075 * tmp_v and tmp2_v are used as temporary vectors throughout, and hold meaningless values
1076 * at the end
1077 *
1078 * then add up the 2-bit values:
1079 * srli(4)+add() : left 4 bits shifted right, added to right 4 bits
1080 *
1081 * srli(2)+and(00000011) : left 2 bits (value 0..2) shifted right, masked, so no other bits active
1082 * and(00000011) : right 2 bits (value 0..2) masked so no other bits active
1083 *
1084 * final 2 add()s : tack current counts on to already-tabulated counts.
1085 */
1086 #define FM_COUNT_2BIT(a_v, b_v, cnts_v) do {\
1087 b_v = _mm_srli_epi16(a_v, 4);\
1088 a_v = _mm_add_epi16(a_v, b_v);\
1089 \
1090 b_v = _mm_srli_epi16(a_v, 2);\
1091 a_v = _mm_and_si128(a_v,cfg->fm_m11);\
1092 b_v = _mm_and_si128(b_v,cfg->fm_m11);\
1093 \
1094 cnts_v = _mm_add_epi16(cnts_v, a_v);\
1095 cnts_v = _mm_add_epi16(cnts_v, b_v);\
1096 } while (0)
1097
1098
1099
1100 /* Macro for SSE operations that turns a vector of 4-bit character values into
1101 * 2 vectors representing matches. Each byte in the input vector consists of
1102 * a left half (4 bits) and a right half (4 bits). The 16 left-halves produce
1103 * one vector, which contains all-1s for bytes in which the left half matches
1104 * the c_v character (and 0s if it doesn't), while the 16 right-halves produce
1105 * the other vector, again with each byte either all-1s or all-0s.
1106 *
1107 * The expectation is that FM_COUNT_4BIT will be called after this, to
1108 * turn these binary values into sums over a series of vectors. The macros
1109 * are split up to allow one end or other to be trimmed in the case that
1110 * counting is not expected to include the full vector.
1111 *
1112 * srli(4)+and() : capture the left 4-bit value (need the mask because 16-bit shift leaves garbage in left-4-bit chunks)
1113 * and() : capture the right 4-bit value
1114 *
1115 * cmpeq()x2 : test if both left and right == c. For each, if ==c , value = 11111111 (-1)
1116 */
1117 #define FM_MATCH_4BIT(in_v, c_v, out1_v, out2_v) do {\
1118 out1_v = _mm_srli_epi16(in_v, 4);\
1119 out2_v = _mm_and_si128(in_v, cfg->fm_m0f);\
1120 out1_v = _mm_and_si128(out1_v, cfg->fm_m0f);\
1121 \
1122 out1_v = _mm_cmpeq_epi8(out1_v, c_v);\
1123 out2_v = _mm_cmpeq_epi8(out2_v, c_v);\
1124 } while (0)
1125
1126
1127 /* Macro for SSE operations that turns a vector of 4-bit character values into
1128 * 2 vectors representing matches. Each byte in the input vector consists of
1129 * a left half (4 bits) and a right half (4 bits). The 16 left-halves produce
1130 * one vector, which contains all-1s for bytes in which the left half is less than
1131 * the c_v character (and 0s if it doesn't), while the 16 right-halves produce
1132 * the other vector, again with each byte either all-1s or all-0s.
1133 *
1134 * The expectation is that FM_COUNT_4BIT will be called after this, to
1135 * turn these binary values into sums over a series of vectors. The macros
1136 * are split up to allow one end or other to be trimmed in the case that
1137 * counting is not expected to include the full vector.
1138 *
1139 * srli(4)+and() : capture the left 4-bit value (need the mask because 16-bit shift leaves garbage in left-4-bit chunks)
1140 * and() : capture the right 4-bit value
1141 *
1142 * cmplt()x2 : test if both left and right < c. For each, if <c , value = 11111111 (-1)
1143 */
1144 #define FM_LT_4BIT(in_v, c_v, out1_v, out2_v) do {\
1145 out1_v = _mm_srli_epi16(in_v, 4);\
1146 out2_v = _mm_and_si128(in_v, cfg->fm_m0f);\
1147 out1_v = _mm_and_si128(out1_v, cfg->fm_m0f);\
1148 \
1149 out1_v = _mm_cmplt_epi8(out1_v, c_v);\
1150 out2_v = _mm_cmplt_epi8(out2_v, c_v);\
1151 } while (0)
1152
1153
1154
1155 /* Macro for SSE operations to add occurrence counts to the tally vector counts_v,
1156 * in the 4-bits-per-character case
1157 *
1158 * The expectation is that in[12]_v will contain bytes that are either
1159 * 00000000 = 0
1160 * or
1161 * 11111111 = -1
1162 * so subtracting the value of the byte is the same as adding 0 or 1.
1163 */
1164 #define FM_COUNT_4BIT(in1_v, in2_v, cnts_v) do {\
1165 cnts_v = _mm_subs_epi8(cnts_v, in1_v);\
1166 cnts_v = _mm_subs_epi8(cnts_v, in2_v);\
1167 } while (0)
1168
1169
1170 #endif // if defined (eslENABLE_SSE)
1171
1172 /*****************************************************************
1173 * 16. P7_PIPELINE: H3's accelerated seq/profile comparison pipeline
1174 *****************************************************************/
1175
1176 enum p7_pipemodes_e { p7_SEARCH_SEQS = 0, p7_SCAN_MODELS = 1 };
1177 enum p7_zsetby_e { p7_ZSETBY_NTARGETS = 0, p7_ZSETBY_OPTION = 1, p7_ZSETBY_FILEINFO = 2 };
1178 enum p7_complementarity_e { p7_NOCOMPLEMENT = 0, p7_COMPLEMENT = 1 };
1179
1180 typedef struct p7_pipeline_s {
1181 /* Dynamic programming matrices */
1182 P7_OMX *oxf; /* one-row Forward matrix, accel pipe */
1183 P7_OMX *oxb; /* one-row Backward matrix, accel pipe */
1184 P7_OMX *fwd; /* full Fwd matrix for domain envelopes */
1185 P7_OMX *bck; /* full Bck matrix for domain envelopes */
1186
1187 /* Domain postprocessing */
1188 ESL_RANDOMNESS *r; /* random number generator */
1189 int do_reseeding; /* TRUE: reseed for reproducible results */
1190 int do_alignment_score_calc; /* used only by nhmmer --aliscoresout */
1191 P7_DOMAINDEF *ddef; /* domain definition workflow */
1192
1193 /* Reporting threshold settings */
1194 int by_E; /* TRUE to cut per-target report off by E */
1195 double E; /* per-target E-value threshold */
1196 double T; /* per-target bit score threshold */
1197 int dom_by_E; /* TRUE to cut domain reporting off by E */
1198 double domE; /* domain E-value threshold */
1199 double domT; /* domain bit score threshold */
1200 int use_bit_cutoffs; /* (FALSE | p7H_GA | p7H_TC | p7H_NC) */
1201
1202 /* Inclusion threshold settings */
1203 int inc_by_E; /* TRUE to threshold inclusion by E-values */
1204 double incE; /* per-target inclusion E-value threshold */
1205 double incT; /* per-target inclusion score threshold */
1206 int incdom_by_E; /* TRUE to threshold domain inclusion by E */
1207 double incdomE; /* per-domain inclusion E-value threshold */
1208 double incdomT; /* per-domain inclusion E-value threshold */
1209
1210 /* Tracking search space sizes for E value calculations */
1211 double Z; /* eff # targs searched (per-target E-val) */
1212 double domZ; /* eff # signific targs (per-domain E-val) */
1213 enum p7_zsetby_e Z_setby; /* how Z was set */
1214 enum p7_zsetby_e domZ_setby; /* how domZ was set */
1215
1216 /* Threshold settings for pipeline */
1217 int do_max; /* TRUE to run in slow/max mode */
1218 double F1; /* MSV filter threshold */
1219 double F2; /* Viterbi filter threshold */
1220 double F3; /* uncorrected Forward filter threshold */
1221 int B1; /* window length for biased-composition modifier - MSV*/
1222 int B2; /* window length for biased-composition modifier - Viterbi*/
1223 int B3; /* window length for biased-composition modifier - Forward*/
1224 int do_biasfilter; /* TRUE to use biased comp HMM filter */
1225 int do_null2; /* TRUE to use null2 score corrections */
1226
1227 /* Accounting. (reduceable in threaded/MPI parallel version) */
1228 uint64_t nmodels; /* # of HMMs searched */
1229 uint64_t nseqs; /* # of sequences searched */
1230 uint64_t nres; /* # of residues searched */
1231 uint64_t nnodes; /* # of model nodes searched */
1232 uint64_t n_past_msv; /* # comparisons that pass MSVFilter() */
1233 uint64_t n_past_bias; /* # comparisons that pass bias filter */
1234 uint64_t n_past_vit; /* # comparisons that pass ViterbiFilter() */
1235 uint64_t n_past_fwd; /* # comparisons that pass ForwardFilter() */
1236 uint64_t n_output; /* # alignments that make it to the final output (used for nhmmer) */
1237 uint64_t pos_past_msv; /* # positions that pass MSVFilter() (used for nhmmer) */
1238 uint64_t pos_past_bias; /* # positions that pass bias filter (used for nhmmer) */
1239 uint64_t pos_past_vit; /* # positions that pass ViterbiFilter() (used for nhmmer) */
1240 uint64_t pos_past_fwd; /* # positions that pass ForwardFilter() (used for nhmmer) */
1241 uint64_t pos_output; /* # positions that make it to the final output (used for nhmmer) */
1242
1243 enum p7_pipemodes_e mode; /* p7_SCAN_MODELS | p7_SEARCH_SEQS */
1244 int long_targets; /* TRUE if the target sequences are expected to be very long (e.g. dna chromosome search in nhmmer) */
1245 int strands; /* p7_STRAND_TOPONLY | p7_STRAND_BOTTOMONLY | p7_STRAND_BOTH */
1246 int W; /* window length for nhmmer scan - essentially maximum length of model that we expect to find*/
1247 int block_length; /* length of overlapping blocks read in the multi-threaded variant (default MAX_RESIDUE_COUNT) */
1248
1249 int show_accessions;/* TRUE to output accessions not names */
1250 int show_alignments;/* TRUE to output alignments (default) */
1251
1252 P7_HMMFILE *hfp; /* COPY of open HMM database (if scan mode) */
1253 char errbuf[eslERRBUFSIZE];
1254 } P7_PIPELINE;
1255
1256
1257
1258 /*****************************************************************
1259 * 17. P7_BUILDER: pipeline for new HMM construction
1260 *****************************************************************/
1261
1262 #define p7_DEFAULT_WINDOW_BETA 1e-7
1263
1264 enum p7_archchoice_e { p7_ARCH_FAST = 0, p7_ARCH_HAND = 1 };
1265 enum p7_wgtchoice_e { p7_WGT_NONE = 0, p7_WGT_GIVEN = 1, p7_WGT_GSC = 2, p7_WGT_PB = 3, p7_WGT_BLOSUM = 4 };
1266 enum p7_effnchoice_e { p7_EFFN_NONE = 0, p7_EFFN_SET = 1, p7_EFFN_CLUST = 2, p7_EFFN_ENTROPY = 3, p7_EFFN_ENTROPY_EXP = 4 };
1267
1268 typedef struct p7_builder_s {
1269 /* Model architecture */
1270 enum p7_archchoice_e arch_strategy; /* choice of model architecture determination algorithm */
1271 float symfrac; /* residue occ thresh for fast architecture determination */
1272 float fragthresh; /* if L <= fragthresh*alen, seq is called a fragment */
1273
1274 /* Relative sequence weights */
1275 enum p7_wgtchoice_e wgt_strategy; /* choice of relative sequence weighting algorithm */
1276 double wid; /* %id threshold for BLOSUM relative weighting */
1277
1278 /* Effective sequence number */
1279 enum p7_effnchoice_e effn_strategy; /* choice of effective seq # determination algorithm */
1280 double re_target; /* rel entropy target for effn eweighting, if set; or -1.0*/
1281 double esigma; /* min total rel ent parameter for effn entropy weights */
1282 double eid; /* %id threshold for effn clustering */
1283 double eset; /* effective sequence number, if --eset; or -1.0 */
1284
1285 /* Run-to-run variation due to random number generation */
1286 ESL_RANDOMNESS *r; /* RNG for E-value calibration simulations */
1287 int do_reseeding; /* TRUE to reseed, making results reproducible */
1288
1289 /* E-value parameter calibration */
1290 int EmL; /* length of sequences generated for MSV fitting */
1291 int EmN; /* # of sequences generated for MSV fitting */
1292 int EvL; /* length of sequences generated for Viterbi fitting */
1293 int EvN; /* # of sequences generated for Viterbi fitting */
1294 int EfL; /* length of sequences generated for Forward fitting */
1295 int EfN; /* # of sequences generated for Forward fitting */
1296 double Eft; /* tail mass used for Forward fitting */
1297
1298 /* Choice of prior */
1299 P7_PRIOR *prior; /* choice of prior when parameterizing from counts */
1300 int max_insert_len;
1301
1302 /* Optional: information used for parameterizing single sequence queries */
1303 ESL_SCOREMATRIX *S; /* residue score matrix */
1304 ESL_DMATRIX *Q; /* Q->mx[a][b] = P(b|a) residue probabilities */
1305 double popen; /* gap open probability */
1306 double pextend; /* gap extend probability */
1307
1308 double w_beta; /*beta value used to compute W (window length) */
1309 int w_len; /*W (window length) explicitly set */
1310
1311 const ESL_ALPHABET *abc; /* COPY of alphabet */
1312 char errbuf[eslERRBUFSIZE]; /* informative message on model construction failure */
1313 } P7_BUILDER;
1314
1315
1316
1317 /*****************************************************************
1318 * 18. Routines in HMMER's exposed API.
1319 *****************************************************************/
1320
1321 /* build.c */
1322 extern int p7_Handmodelmaker(ESL_MSA *msa, P7_BUILDER *bld, P7_HMM **ret_hmm, P7_TRACE ***ret_tr);
1323 extern int p7_Fastmodelmaker(ESL_MSA *msa, float symfrac, P7_BUILDER *bld, P7_HMM **ret_hmm, P7_TRACE ***ret_tr);
1324
1325 /* emit.c */
1326 extern int p7_CoreEmit (ESL_RANDOMNESS *r, const P7_HMM *hmm, ESL_SQ *sq, P7_TRACE *tr);
1327 extern int p7_ProfileEmit(ESL_RANDOMNESS *r, const P7_HMM *hmm, const P7_PROFILE *gm, const P7_BG *bg, ESL_SQ *sq, P7_TRACE *tr);
1328 extern int p7_emit_SimpleConsensus(const P7_HMM *hmm, ESL_SQ *sq);
1329 extern int p7_emit_FancyConsensus (const P7_HMM *hmm, float min_lower, float min_upper, ESL_SQ *sq);
1330
1331 /* errors.c */
1332 extern void p7_Die (char *format, ...);
1333 extern void p7_Fail(char *format, ...);
1334
1335 /* evalues.c */
1336 extern int p7_Calibrate(P7_HMM *hmm, P7_BUILDER *cfg_b, ESL_RANDOMNESS **byp_rng, P7_BG **byp_bg, P7_PROFILE **byp_gm, P7_OPROFILE **byp_om);
1337 extern int p7_Lambda(P7_HMM *hmm, P7_BG *bg, double *ret_lambda);
1338 extern int p7_MSVMu (ESL_RANDOMNESS *r, P7_OPROFILE *om, P7_BG *bg, int L, int N, double lambda, double *ret_mmu);
1339 extern int p7_ViterbiMu (ESL_RANDOMNESS *r, P7_OPROFILE *om, P7_BG *bg, int L, int N, double lambda, double *ret_vmu);
1340 extern int p7_Tau (ESL_RANDOMNESS *r, P7_OPROFILE *om, P7_BG *bg, int L, int N, double lambda, double tailp, double *ret_tau);
1341
1342 /* eweight.c */
1343 extern int p7_EntropyWeight(const P7_HMM *hmm, const P7_BG *bg, const P7_PRIOR *pri, double infotarget, double *ret_Neff);
1344
1345 extern int p7_EntropyWeight_exp(const P7_HMM *hmm, const P7_BG *bg, const P7_PRIOR *pri, double etarget, double *ret_exp);
1346 /* generic_decoding.c */
1347 extern int p7_GDecoding (const P7_PROFILE *gm, const P7_GMX *fwd, P7_GMX *bck, P7_GMX *pp);
1348 extern int p7_GDomainDecoding(const P7_PROFILE *gm, const P7_GMX *fwd, const P7_GMX *bck, P7_DOMAINDEF *ddef);
1349
1350 /* generic_fwdback.c */
1351 extern int p7_GForward (const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, P7_GMX *gx, float *ret_sc);
1352 extern int p7_GBackward (const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, P7_GMX *gx, float *ret_sc);
1353 extern int p7_GHybrid (const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, P7_GMX *gx, float *opt_fwdscore, float *opt_hybscore);
1354
1355 /* generic_msv.c */
1356 extern int p7_GMSV (const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, P7_GMX *gx, float nu, float *ret_sc);
1357 extern int p7_GMSV_longtarget(const ESL_DSQ *dsq, int L, P7_PROFILE *gm, P7_GMX *gx, float nu, P7_BG *bg, double P, P7_HMM_WINDOWLIST *windowlist);
1358
1359 /* generic_null2.c */
1360 extern int p7_GNull2_ByExpectation(const P7_PROFILE *gm, P7_GMX *pp, float *null2);
1361 extern int p7_GNull2_ByTrace (const P7_PROFILE *gm, const P7_TRACE *tr, int zstart, int zend, P7_GMX *wrk, float *null2);
1362
1363 /* generic_optacc.c */
1364 extern int p7_GOptimalAccuracy(const P7_PROFILE *gm, const P7_GMX *pp, P7_GMX *gx, float *ret_e);
1365 extern int p7_GOATrace (const P7_PROFILE *gm, const P7_GMX *pp, const P7_GMX *gx, P7_TRACE *tr);
1366
1367 /* generic_stotrace.c */
1368 extern int p7_GStochasticTrace(ESL_RANDOMNESS *r, const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, const P7_GMX *gx, P7_TRACE *tr);
1369
1370 /* generic_viterbi.c */
1371 extern int p7_GViterbi (const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, P7_GMX *gx, float *ret_sc);
1372
1373 /* generic_vtrace.c */
1374 extern int p7_GTrace (const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, const P7_GMX *gx, P7_TRACE *tr);
1375 extern int p7_GViterbi_longtarget(const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, P7_GMX *gx,
1376 float filtersc, double P, P7_HMM_WINDOWLIST *windowlist);
1377
1378
1379 /* heatmap.c (evolving now, intend to move this to Easel in the future) */
1380 extern double dmx_upper_max(ESL_DMATRIX *D);
1381 extern double dmx_upper_min(ESL_DMATRIX *D);
1382 extern double dmx_upper_element_sum(ESL_DMATRIX *D);
1383 extern double dmx_upper_norm(ESL_DMATRIX *D);
1384 extern int dmx_Visualize(FILE *fp, ESL_DMATRIX *D, double min, double max);
1385
1386 /* hmmdutils.c */
1387 extern void p7_openlog(const char *ident, int option, int facility);
1388 extern void p7_syslog(int priority, const char *format, ...);
1389 extern void p7_closelog(void);
1390
1391 /* hmmlogo.c */
1392 extern float hmmlogo_maxHeight (P7_BG *bg);
1393 extern int hmmlogo_RelativeEntropy_all (P7_HMM *hmm, P7_BG *bg, float *rel_ents, float **probs, float **heights );
1394 extern int hmmlogo_RelativeEntropy_above_bg (P7_HMM *hmm, P7_BG *bg, float *rel_ents, float **probs, float **heights );
1395 extern int hmmlogo_ScoreHeights (P7_HMM *hmm, P7_BG *bg, float **heights );
1396 extern int hmmlogo_IndelValues (P7_HMM *hmm, float *insert_P, float *insert_expL, float *delete_P );
1397
1398
1399
1400 /* hmmpgmd2msa.c */
1401 extern int hmmpgmd2msa(void *data, P7_HMM *hmm, ESL_SQ *qsq, int *incl, int incl_size, int *excl, int excl_size, int excl_all, ESL_MSA **ret_msa);
1402
1403
1404
1405 /* island.c */
1406 extern int p7_island_Viterbi(ESL_DSQ *dsq, int L, P7_PROFILE *gm, P7_GMX *mx, ESL_HISTOGRAM *h);
1407
1408 /* h2_io.c */
1409 extern int p7_h2io_WriteASCII(FILE *fp, P7_HMM *hmm);
1410
1411 /* hmmer.c */
1412 extern void p7_banner(FILE *fp, const char *progname, char *banner);
1413 extern ESL_GETOPTS *p7_CreateDefaultApp(ESL_OPTIONS *options, int nargs, int argc, char **argv, char *banner, char *usage);
1414 extern int p7_AminoFrequencies(float *f);
1415
1416 /* logsum.c */
1417 extern int p7_FLogsumInit(void);
1418 extern float p7_FLogsum(float a, float b);
1419 extern float p7_FLogsumError(float a, float b);
1420 extern int p7_ILogsumInit(void);
1421 extern int p7_ILogsum(int s1, int s2);
1422
1423
1424 /* modelconfig.c */
1425 extern int p7_ProfileConfig(const P7_HMM *hmm, const P7_BG *bg, P7_PROFILE *gm, int L, int mode);
1426 extern int p7_ReconfigLength (P7_PROFILE *gm, int L);
1427 extern int p7_ReconfigMultihit(P7_PROFILE *gm, int L);
1428 extern int p7_ReconfigUnihit (P7_PROFILE *gm, int L);
1429
1430 /* modelstats.c */
1431 extern double p7_MeanMatchInfo (const P7_HMM *hmm, const P7_BG *bg);
1432 extern double p7_MeanMatchEntropy (const P7_HMM *hmm);
1433 extern double p7_MeanMatchRelativeEntropy(const P7_HMM *hmm, const P7_BG *bg);
1434 extern double p7_MeanForwardScore (const P7_HMM *hmm, const P7_BG *bg);
1435 extern int p7_MeanPositionRelativeEntropy(const P7_HMM *hmm, const P7_BG *bg, double *ret_entropy);
1436 extern int p7_hmm_CompositionKLD(const P7_HMM *hmm, const P7_BG *bg, float *ret_KL, float **opt_avp);
1437
1438
1439 /* mpisupport.c */
1440 #ifdef HMMER_MPI
1441 extern int p7_hmm_MPISend(P7_HMM *hmm, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc);
1442 extern int p7_hmm_MPIPackSize(P7_HMM *hmm, MPI_Comm comm, int *ret_n);
1443 extern int p7_hmm_MPIPack(P7_HMM *hmm, char *buf, int n, int *position, MPI_Comm comm);
1444 extern int p7_hmm_MPIUnpack(char *buf, int n, int *pos, MPI_Comm comm, ESL_ALPHABET **abc, P7_HMM **ret_hmm);
1445 extern int p7_hmm_MPIRecv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, ESL_ALPHABET **abc, P7_HMM **ret_hmm);
1446
1447 extern int p7_profile_MPISend(P7_PROFILE *gm, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc);
1448 extern int p7_profile_MPIRecv(int source, int tag, MPI_Comm comm, const ESL_ALPHABET *abc, const P7_BG *bg,
1449 char **buf, int *nalloc, P7_PROFILE **ret_gm);
1450
1451 extern int p7_pipeline_MPISend(P7_PIPELINE *pli, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc);
1452 extern int p7_pipeline_MPIRecv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, ESL_GETOPTS *go, P7_PIPELINE **ret_pli);
1453
1454 extern int p7_tophits_MPISend(P7_TOPHITS *th, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc);
1455 extern int p7_tophits_MPIRecv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, P7_TOPHITS **ret_th);
1456
1457 extern int p7_oprofile_MPISend(P7_OPROFILE *om, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc);
1458 extern int p7_oprofile_MPIPackSize(P7_OPROFILE *om, MPI_Comm comm, int *ret_n);
1459 extern int p7_oprofile_MPIPack(P7_OPROFILE *om, char *buf, int n, int *pos, MPI_Comm comm);
1460 extern int p7_oprofile_MPIUnpack(char *buf, int n, int *pos, MPI_Comm comm, ESL_ALPHABET **abc, P7_OPROFILE **ret_om);
1461 extern int p7_oprofile_MPIRecv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, ESL_ALPHABET **abc, P7_OPROFILE **ret_om);
1462 #endif /*HMMER_MPI*/
1463
1464 /* tracealign.c */
1465 extern int p7_tracealign_Seqs(ESL_SQ **sq, P7_TRACE **tr, int nseq, int M, int optflags, P7_HMM *hmm, ESL_MSA **ret_msa);
1466 extern int p7_tracealign_MSA (const ESL_MSA *premsa, P7_TRACE **tr, int M, int optflags, ESL_MSA **ret_postmsa);
1467 extern int p7_tracealign_computeTraces(P7_HMM *hmm, ESL_SQ **sq, int offset, int N, P7_TRACE **tr);
1468 extern int p7_tracealign_getMSAandStats(P7_HMM *hmm, ESL_SQ **sq, int N, ESL_MSA **ret_msa, float **ret_pp, float **ret_relent, float **ret_scores );
1469
1470 /* p7_alidisplay.c */
1471 extern P7_ALIDISPLAY *p7_alidisplay_Create(const P7_TRACE *tr, int which, const P7_OPROFILE *om, const ESL_SQ *sq, const ESL_SQ *ntsq);
1472 extern P7_ALIDISPLAY *p7_alidisplay_Create_empty();
1473 extern P7_ALIDISPLAY *p7_alidisplay_Clone(const P7_ALIDISPLAY *ad);
1474 extern size_t p7_alidisplay_Sizeof(const P7_ALIDISPLAY *ad);
1475 extern int p7_alidisplay_Serialize(const P7_ALIDISPLAY *obj, uint8_t **buf, uint32_t *n, uint32_t *nalloc);
1476 extern int p7_alidisplay_Deserialize(const uint8_t *buf, uint32_t *n, P7_ALIDISPLAY *ret_obj);
1477 extern int p7_alidisplay_Serialize_old(P7_ALIDISPLAY *ad);
1478 extern int p7_alidisplay_Deserialize_old(P7_ALIDISPLAY *ad);
1479 extern void p7_alidisplay_Destroy(P7_ALIDISPLAY *ad);
1480 extern char p7_alidisplay_EncodePostProb(float p);
1481 extern float p7_alidisplay_DecodePostProb(char pc);
1482 extern char p7_alidisplay_EncodeAliPostProb(float p, float hi, float med, float lo);
1483
1484 extern int p7_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, P7_PIPELINE *pli);
1485 extern int p7_translated_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, P7_PIPELINE *pli);
1486 extern int p7_nontranslated_alidisplay_Print(FILE *fp, P7_ALIDISPLAY *ad, int min_aliwidth, int linewidth, int show_accessions);
1487
1488 extern int p7_alidisplay_Backconvert(const P7_ALIDISPLAY *ad, const ESL_ALPHABET *abc, ESL_SQ **ret_sq, P7_TRACE **ret_tr);
1489 extern int p7_alidisplay_Sample(ESL_RANDOMNESS *rng, int N, P7_ALIDISPLAY **ret_ad);
1490 extern int p7_alidisplay_Dump(FILE *fp, const P7_ALIDISPLAY *ad);
1491 extern int p7_alidisplay_Compare(const P7_ALIDISPLAY *ad1, const P7_ALIDISPLAY *ad2);
1492
1493 /* p7_bg.c */
1494 extern P7_BG *p7_bg_Create(const ESL_ALPHABET *abc);
1495 extern P7_BG *p7_bg_CreateUniform(const ESL_ALPHABET *abc);
1496 extern P7_BG *p7_bg_Clone(const P7_BG *bg);
1497 extern int p7_bg_Dump(FILE *ofp, const P7_BG *bg);
1498 extern void p7_bg_Destroy(P7_BG *bg);
1499 extern int p7_bg_SetLength(P7_BG *bg, int L);
1500 extern int p7_bg_NullOne(const P7_BG *bg, const ESL_DSQ *dsq, int L, float *ret_sc);
1501
1502 extern int p7_bg_Read(char *bgfile, P7_BG *bg, char *errbuf);
1503 extern int p7_bg_Write(FILE *fp, P7_BG *bg);
1504
1505 extern int p7_bg_SetFilter (P7_BG *bg, int M, const float *compo);
1506 extern int p7_bg_FilterScore(P7_BG *bg, const ESL_DSQ *dsq, int L, float *ret_sc);
1507
1508 /* p7_builder.c */
1509 extern P7_BUILDER *p7_builder_Create(const ESL_GETOPTS *go, const ESL_ALPHABET *abc);
1510 extern int p7_builder_LoadScoreSystem(P7_BUILDER *bld, const char *matrix, double popen, double pextend, P7_BG *bg);
1511 extern int p7_builder_SetScoreSystem (P7_BUILDER *bld, const char *mxfile, const char *env, double popen, double pextend, P7_BG *bg);
1512 extern void p7_builder_Destroy(P7_BUILDER *bld);
1513
1514 extern int p7_Builder (P7_BUILDER *bld, ESL_MSA *msa, P7_BG *bg, P7_HMM **opt_hmm, P7_TRACE ***opt_trarr, P7_PROFILE **opt_gm, P7_OPROFILE **opt_om, ESL_MSA **opt_postmsa);
1515 extern int p7_SingleBuilder(P7_BUILDER *bld, ESL_SQ *sq, P7_BG *bg, P7_HMM **opt_hmm, P7_TRACE **opt_tr, P7_PROFILE **opt_gm, P7_OPROFILE **opt_om);
1516 extern int p7_Builder_MaxLength (P7_HMM *hmm, double emit_thresh);
1517
1518 /* p7_domain.c */
1519 extern P7_DOMAIN *p7_domain_Create_empty();
1520 extern void p7_domain_Destroy(P7_DOMAIN *obj);
1521 extern int p7_domain_Copy(const P7_DOMAIN *src, P7_DOMAIN *dst);
1522 extern int p7_domain_Serialize(const P7_DOMAIN *obj, uint8_t **buf, uint32_t *n, uint32_t *nalloc);
1523 extern int p7_domain_Deserialize(const uint8_t *buf, uint32_t *n, P7_DOMAIN *ret_obj);
1524 extern int p7_domain_TestSample(ESL_RAND64 *rng, P7_DOMAIN **ret_obj);
1525 extern int p7_domain_Compare(P7_DOMAIN *first, P7_DOMAIN *second, double atol, double rtol);
1526
1527 /* p7_domaindef.c */
1528 extern P7_DOMAINDEF *p7_domaindef_Create (ESL_RANDOMNESS *r);
1529 extern int p7_domaindef_Fetch (P7_DOMAINDEF *ddef, int which, int *opt_i, int *opt_j, float *opt_sc, P7_ALIDISPLAY **opt_ad);
1530 extern int p7_domaindef_GrowTo (P7_DOMAINDEF *ddef, int L);
1531 extern int p7_domaindef_Reuse (P7_DOMAINDEF *ddef);
1532 extern int p7_domaindef_DumpPosteriors(FILE *ofp, P7_DOMAINDEF *ddef);
1533 extern void p7_domaindef_Destroy(P7_DOMAINDEF *ddef);
1534
1535 extern int p7_domaindef_ByViterbi (P7_PROFILE *gm, const ESL_SQ *sq, const ESL_SQ *ntsq, P7_GMX *gx1, P7_GMX *gx2, P7_DOMAINDEF *ddef);
1536 extern int p7_domaindef_ByPosteriorHeuristics(const ESL_SQ *sq, const ESL_SQ *ntsq, P7_OPROFILE *om, P7_OMX *oxf, P7_OMX *oxb, P7_OMX *fwd, P7_OMX *bck,
1537 P7_DOMAINDEF *ddef, P7_BG *bg, int long_target,
1538 P7_BG *bg_tmp, float *scores_arr, float *fwd_emissions_arr);
1539
1540
1541 /* p7_gmx.c */
1542 extern P7_GMX *p7_gmx_Create (int allocM, int allocL);
1543 extern int p7_gmx_GrowTo (P7_GMX *gx, int allocM, int allocL);
1544 extern size_t p7_gmx_Sizeof (P7_GMX *gx);
1545 extern int p7_gmx_Reuse (P7_GMX *gx);
1546 extern void p7_gmx_Destroy(P7_GMX *gx);
1547 extern int p7_gmx_Compare(P7_GMX *gx1, P7_GMX *gx2, float tolerance);
1548 extern int p7_gmx_Dump(FILE *fp, P7_GMX *gx, int flags);
1549 extern int p7_gmx_DumpWindow(FILE *fp, P7_GMX *gx, int istart, int iend, int kstart, int kend, int show_specials);
1550
1551 /* p7_hit.c */
1552 extern P7_HIT *p7_hit_Create_empty();
1553 extern void p7_hit_Destroy(P7_HIT *the_hit);
1554 extern int p7_hit_Copy(const P7_HIT *src, P7_HIT *dst);
1555 extern int p7_hit_Serialize(const P7_HIT *obj, uint8_t **buf, uint32_t *n, uint32_t *nalloc);
1556 extern int p7_hit_Deserialize(const uint8_t *buf, uint32_t *n, P7_HIT *ret_obj);
1557 extern int p7_hit_TestSample(ESL_RAND64 *rng, P7_HIT **ret_obj);
1558 extern int p7_hit_Compare(P7_HIT *first, P7_HIT *second, double atol, double rtol);
1559
1560 /* p7_hmm.c */
1561 /* 1. The P7_HMM object: allocation, initialization, destruction. */
1562 extern P7_HMM *p7_hmm_Create(int M, const ESL_ALPHABET *abc);
1563 extern P7_HMM *p7_hmm_CreateShell(void);
1564 extern int p7_hmm_CreateBody(P7_HMM *hmm, int M, const ESL_ALPHABET *abc);
1565 extern void p7_hmm_Destroy(P7_HMM *hmm);
1566 extern int p7_hmm_CopyParameters(const P7_HMM *src, P7_HMM *dest);
1567 extern P7_HMM *p7_hmm_Clone(const P7_HMM *hmm);
1568 extern int p7_hmm_Zero(P7_HMM *hmm);
1569 extern char p7_hmm_EncodeStatetype(char *typestring);
1570 extern char *p7_hmm_DecodeStatetype(char st);
1571 /* 2. Convenience routines for setting fields in an HMM. */
1572 extern int p7_hmm_SetName (P7_HMM *hmm, char *name);
1573 extern int p7_hmm_SetAccession (P7_HMM *hmm, char *acc);
1574 extern int p7_hmm_SetDescription(P7_HMM *hmm, char *desc);
1575 extern int p7_hmm_AppendComlog (P7_HMM *hmm, int argc, char **argv);
1576 extern int p7_hmm_SetCtime (P7_HMM *hmm);
1577 extern int p7_hmm_SetComposition(P7_HMM *hmm);
1578 extern int p7_hmm_SetConsensus (P7_HMM *hmm, ESL_SQ *sq);
1579 /* 3. Renormalization and rescaling counts in core HMMs. */
1580 extern int p7_hmm_Scale (P7_HMM *hmm, double scale);
1581 extern int p7_hmm_ScaleExponential(P7_HMM *hmm, double exp);
1582 extern int p7_hmm_Renormalize(P7_HMM *hmm);
1583 /* 4. Debugging and development code. */
1584 extern int p7_hmm_Dump(FILE *fp, P7_HMM *hmm);
1585 extern int p7_hmm_Sample (ESL_RANDOMNESS *r, int M, const ESL_ALPHABET *abc, P7_HMM **ret_hmm);
1586 extern int p7_hmm_SampleUngapped (ESL_RANDOMNESS *r, int M, const ESL_ALPHABET *abc, P7_HMM **ret_hmm);
1587 extern int p7_hmm_SampleEnumerable(ESL_RANDOMNESS *r, int M, const ESL_ALPHABET *abc, P7_HMM **ret_hmm);
1588 extern int p7_hmm_SampleUniform (ESL_RANDOMNESS *r, int M, const ESL_ALPHABET *abc,
1589 float tmi, float tii, float tmd, float tdd, P7_HMM **ret_hmm);
1590 extern int p7_hmm_Compare(P7_HMM *h1, P7_HMM *h2, float tol);
1591 extern int p7_hmm_Validate(P7_HMM *hmm, char *errbuf, float tol);
1592 /* 5. Other routines in the API */
1593 extern int p7_hmm_CalculateOccupancy(const P7_HMM *hmm, float *mocc, float *iocc);
1594
1595
1596
1597 /* p7_hmmfile.c */
1598 extern int p7_hmmfile_Open (const char *filename, char *env, P7_HMMFILE **ret_hfp, char *errbuf);
1599 extern int p7_hmmfile_OpenNoDB (const char *filename, char *env, P7_HMMFILE **ret_hfp, char *errbuf);
1600 extern int p7_hmmfile_OpenBuffer(const char *buffer, int size, P7_HMMFILE **ret_hfp);
1601 extern void p7_hmmfile_Close(P7_HMMFILE *hfp);
1602 #ifdef HMMER_THREADS
1603 extern int p7_hmmfile_CreateLock(P7_HMMFILE *hfp);
1604 #endif
1605 extern int p7_hmmfile_WriteBinary(FILE *fp, int format, P7_HMM *hmm);
1606 extern int p7_hmmfile_WriteASCII (FILE *fp, int format, P7_HMM *hmm);
1607 extern int p7_hmmfile_WriteToString (char **s, int format, P7_HMM *hmm);
1608 extern int p7_hmmfile_Read(P7_HMMFILE *hfp, ESL_ALPHABET **ret_abc, P7_HMM **opt_hmm);
1609 extern int p7_hmmfile_PositionByKey(P7_HMMFILE *hfp, const char *key);
1610 extern int p7_hmmfile_Position(P7_HMMFILE *hfp, const off_t offset);
1611
1612
1613 /* p7_hmmwindow.c */
1614 int p7_hmmwindow_init (P7_HMM_WINDOWLIST *list);
1615 P7_HMM_WINDOW *p7_hmmwindow_new (P7_HMM_WINDOWLIST *list, uint32_t id, uint32_t pos, uint32_t fm_pos, uint16_t k, uint32_t length, float score, uint8_t complementarity, uint32_t target_len);
1616
1617
1618
1619 /* p7_msvdata.c */
1620 extern P7_SCOREDATA *p7_hmm_ScoreDataCreate(P7_OPROFILE *om, P7_PROFILE *gm );
1621 extern P7_SCOREDATA *p7_hmm_ScoreDataClone(P7_SCOREDATA *src, int K);
1622 extern int p7_hmm_ScoreDataComputeRest(P7_OPROFILE *om, P7_SCOREDATA *data );
1623 extern void p7_hmm_ScoreDataDestroy( P7_SCOREDATA *data );
1624 extern int p7_hmm_initWindows (P7_HMM_WINDOWLIST *list);
1625 extern P7_HMM_WINDOW *p7_hmm_newWindow (P7_HMM_WINDOWLIST *list, uint32_t id, uint32_t pos, uint32_t fm_pos, uint16_t k, uint32_t length, float score, uint8_t complementarity);
1626
1627
1628
1629 /* p7_null3.c */
1630 extern void p7_null3_score(const ESL_ALPHABET *abc, const ESL_DSQ *dsq, P7_TRACE *tr, int start, int stop, P7_BG *bg, float *ret_sc);
1631 extern void p7_null3_windowed_score(const ESL_ALPHABET *abc, const ESL_DSQ *dsq, int start, int stop, P7_BG *bg, float *ret_sc);
1632
1633 /* p7_pipeline.c */
1634 extern P7_PIPELINE *p7_pipeline_Create(const ESL_GETOPTS *go, int M_hint, int L_hint, int long_targets, enum p7_pipemodes_e mode);
1635 extern int p7_pipeline_Reuse (P7_PIPELINE *pli);
1636 extern void p7_pipeline_Destroy(P7_PIPELINE *pli);
1637 extern int p7_pipeline_Merge (P7_PIPELINE *p1, P7_PIPELINE *p2);
1638
1639 extern int p7_pli_ExtendAndMergeWindows (P7_OPROFILE *om, const P7_SCOREDATA *msvdata, P7_HMM_WINDOWLIST *windowlist, float pct_overlap);
1640 extern int p7_pli_TargetReportable (P7_PIPELINE *pli, float score, double lnP);
1641 extern int p7_pli_DomainReportable (P7_PIPELINE *pli, float dom_score, double lnP);
1642
1643 extern int p7_pli_TargetIncludable (P7_PIPELINE *pli, float score, double lnP);
1644 extern int p7_pli_DomainIncludable (P7_PIPELINE *pli, float dom_score, double lnP);
1645 extern int p7_pli_NewModel (P7_PIPELINE *pli, const P7_OPROFILE *om, P7_BG *bg);
1646 extern int p7_pli_NewModelThresholds(P7_PIPELINE *pli, const P7_OPROFILE *om);
1647 extern int p7_pli_NewSeq (P7_PIPELINE *pli, const ESL_SQ *sq);
1648 extern int p7_Pipeline (P7_PIPELINE *pli, P7_OPROFILE *om, P7_BG *bg, const ESL_SQ *sq, const ESL_SQ *ntsq, P7_TOPHITS *th);
1649 extern int p7_Pipeline_LongTarget (P7_PIPELINE *pli, P7_OPROFILE *om, P7_SCOREDATA *data,
1650 P7_BG *bg, P7_TOPHITS *hitlist, int64_t seqidx,
1651 const ESL_SQ *sq, int complementarity,
1652 const FM_DATA *fmf, const FM_DATA *fmb, FM_CFG *fm_cfg
1653 );
1654
1655
1656
1657 extern int p7_pli_Statistics(FILE *ofp, P7_PIPELINE *pli, ESL_STOPWATCH *w);
1658
1659
1660 /* p7_prior.c */
1661 extern P7_PRIOR *p7_prior_CreateAmino(void);
1662 extern P7_PRIOR *p7_prior_CreateNucleic(void);
1663 extern P7_PRIOR *p7_prior_CreateLaplace(const ESL_ALPHABET *abc);
1664 extern void p7_prior_Destroy(P7_PRIOR *pri);
1665
1666 extern int p7_ParameterEstimation(P7_HMM *hmm, const P7_PRIOR *pri);
1667
1668 /* p7_profile.c */
1669 extern P7_PROFILE *p7_profile_Create(int M, const ESL_ALPHABET *abc);
1670 extern P7_PROFILE *p7_profile_Clone(const P7_PROFILE *gm);
1671 extern int p7_profile_Copy(const P7_PROFILE *src, P7_PROFILE *dst);
1672 extern int p7_profile_SetNullEmissions(P7_PROFILE *gm);
1673 extern int p7_profile_Reuse(P7_PROFILE *gm);
1674 extern size_t p7_profile_Sizeof(P7_PROFILE *gm);
1675 extern void p7_profile_Destroy(P7_PROFILE *gm);
1676 extern int p7_profile_IsLocal(const P7_PROFILE *gm);
1677 extern int p7_profile_IsMultihit(const P7_PROFILE *gm);
1678 extern int p7_profile_GetT(const P7_PROFILE *gm, char st1, int k1,
1679 char st2, int k2, float *ret_tsc);
1680 extern int p7_profile_Validate(const P7_PROFILE *gm, char *errbuf, float tol);
1681 extern int p7_profile_Compare(P7_PROFILE *gm1, P7_PROFILE *gm2, float tol);
1682
1683 /* p7_spensemble.c */
1684 P7_SPENSEMBLE *p7_spensemble_Create(int init_n, int init_epc, int init_sigc);
1685 extern int p7_spensemble_Reuse(P7_SPENSEMBLE *sp);
1686 extern int p7_spensemble_Add(P7_SPENSEMBLE *sp, int sampleidx, int i, int j, int k, int m);
1687 extern int p7_spensemble_Cluster(P7_SPENSEMBLE *sp,
1688 float min_overlap, int of_smaller, int max_diagdiff,
1689 float min_posterior, float min_endpointp,
1690 int *ret_nclusters);
1691 extern int p7_spensemble_GetClusterCoords(P7_SPENSEMBLE *sp, int which,
1692 int *ret_i, int *ret_j, int *ret_k, int *ret_m, float *ret_p);
1693 extern void p7_spensemble_Destroy(P7_SPENSEMBLE *sp);
1694
1695 /* p7_tophits.c */
1696 extern P7_TOPHITS *p7_tophits_Create(void);
1697 extern int p7_tophits_Grow(P7_TOPHITS *h);
1698 extern P7_TOPHITS *p7_tophits_Clone(const P7_TOPHITS *h);
1699 extern int p7_tophits_CreateNextHit(P7_TOPHITS *h, P7_HIT **ret_hit);
1700 extern int p7_tophits_Add(P7_TOPHITS *h,
1701 char *name, char *acc, char *desc,
1702 double sortkey,
1703 float score, double lnP,
1704 float mothersc, double mother_lnP,
1705 int sqfrom, int sqto, int sqlen,
1706 int hmmfrom, int hmmto, int hmmlen,
1707 int domidx, int ndom,
1708 P7_ALIDISPLAY *ali);
1709 extern int p7_tophits_SortBySortkey(P7_TOPHITS *h);
1710 extern int p7_tophits_SortBySeqidxAndAlipos(P7_TOPHITS *h);
1711 extern int p7_tophits_SortByModelnameAndAlipos(P7_TOPHITS *h);
1712
1713 extern int p7_tophits_Merge(P7_TOPHITS *h1, P7_TOPHITS *h2);
1714 extern int p7_tophits_GetMaxPositionLength(P7_TOPHITS *h);
1715 extern int p7_tophits_GetMaxNameLength(P7_TOPHITS *h);
1716 extern int p7_tophits_GetMaxAccessionLength(P7_TOPHITS *h);
1717 extern int p7_tophits_GetMaxShownLength(P7_TOPHITS *h);
1718 extern void p7_tophits_Destroy(P7_TOPHITS *h);
1719
1720 extern int p7_tophits_ComputeNhmmerEvalues(P7_TOPHITS *th, double N, int W);
1721 extern int p7_tophits_RemoveDuplicates(P7_TOPHITS *th, int using_bit_cutoffs);
1722 extern int p7_tophits_Threshold(P7_TOPHITS *th, P7_PIPELINE *pli);
1723 extern int p7_tophits_CompareRanking(P7_TOPHITS *th, ESL_KEYHASH *kh, int *opt_nnew);
1724 extern int p7_tophits_Targets(FILE *ofp, P7_TOPHITS *th, P7_PIPELINE *pli, int textw);
1725 extern int p7_tophits_Domains(FILE *ofp, P7_TOPHITS *th, P7_PIPELINE *pli, int textw);
1726
1727
1728 extern int p7_tophits_Alignment(const P7_TOPHITS *th, const ESL_ALPHABET *abc,
1729 ESL_SQ **inc_sqarr, P7_TRACE **inc_trarr, int inc_n, int optflags,
1730 ESL_MSA **ret_msa);
1731 extern int p7_tophits_TabularTargets(FILE *ofp, char *qname, char *qacc, P7_TOPHITS *th, P7_PIPELINE *pli, int show_header);
1732 extern int p7_tophits_TabularDomains(FILE *ofp, char *qname, char *qacc, P7_TOPHITS *th, P7_PIPELINE *pli, int show_header);
1733 extern int p7_tophits_TabularXfam(FILE *ofp, char *qname, char *qacc, P7_TOPHITS *th, P7_PIPELINE *pli);
1734 extern int p7_tophits_TabularTail(FILE *ofp, const char *progname, enum p7_pipemodes_e pipemode,
1735 const char *qfile, const char *tfile, const ESL_GETOPTS *go);
1736 extern int p7_tophits_AliScores(FILE *ofp, char *qname, P7_TOPHITS *th );
1737
1738 /* p7_trace.c */
1739 extern P7_TRACE *p7_trace_Create(void);
1740 extern P7_TRACE *p7_trace_CreateWithPP(void);
1741 extern int p7_trace_Reuse(P7_TRACE *tr);
1742 extern int p7_trace_Grow(P7_TRACE *tr);
1743 extern int p7_trace_GrowIndex(P7_TRACE *tr);
1744 extern int p7_trace_GrowTo(P7_TRACE *tr, int N);
1745 extern int p7_trace_GrowIndexTo(P7_TRACE *tr, int ndom);
1746 extern void p7_trace_Destroy(P7_TRACE *tr);
1747 extern void p7_trace_DestroyArray(P7_TRACE **tr, int N);
1748
1749 extern int p7_trace_GetDomainCount (const P7_TRACE *tr, int *ret_ndom);
1750 extern int p7_trace_GetStateUseCounts(const P7_TRACE *tr, int *counts);
1751 extern int p7_trace_GetDomainCoords (const P7_TRACE *tr, int which, int *ret_i1, int *ret_i2,
1752 int *ret_k1, int *ret_k2);
1753
1754 extern int p7_trace_Validate(const P7_TRACE *tr, const ESL_ALPHABET *abc, const ESL_DSQ *dsq, char *errbuf);
1755 extern int p7_trace_Dump(FILE *fp, const P7_TRACE *tr, const P7_PROFILE *gm, const ESL_DSQ *dsq);
1756 extern int p7_trace_Compare(P7_TRACE *tr1, P7_TRACE *tr2, float pptol);
1757 extern int p7_trace_Score(P7_TRACE *tr, ESL_DSQ *dsq, P7_PROFILE *gm, float *ret_sc);
1758 extern int p7_trace_SetPP(P7_TRACE *tr, const P7_GMX *pp);
1759 extern float p7_trace_GetExpectedAccuracy(const P7_TRACE *tr);
1760
1761 extern int p7_trace_Append(P7_TRACE *tr, char st, int k, int i);
1762 extern int p7_trace_AppendWithPP(P7_TRACE *tr, char st, int k, int i, float pp);
1763 extern int p7_trace_Reverse(P7_TRACE *tr);
1764 extern int p7_trace_Index(P7_TRACE *tr);
1765
1766 extern int p7_trace_FauxFromMSA(ESL_MSA *msa, int *matassign, int optflags, P7_TRACE **tr);
1767 extern int p7_trace_Doctor(P7_TRACE *tr, int *opt_ndi, int *opt_nid);
1768
1769 extern int p7_trace_Count(P7_HMM *hmm, ESL_DSQ *dsq, float wt, P7_TRACE *tr);
1770
1771
1772 /* seqmodel.c */
1773 extern int p7_Seqmodel(const ESL_ALPHABET *abc, ESL_DSQ *dsq, int M, char *name,
1774 ESL_DMATRIX *P, float *f, double popen, double pextend,
1775 P7_HMM **ret_hmm);
1776
1777 /* fm_alphabet.c */
1778 extern int fm_alphabetCreate (FM_METADATA *meta, uint8_t *alph_bits);
1779 extern int fm_alphabetDestroy (FM_METADATA *meta);
1780 extern int fm_reverseString (char *str, int N);
1781 extern int fm_getComplement (char c, uint8_t alph_type);
1782
1783
1784 /* fm_general.c */
1785 extern uint64_t fm_computeSequenceOffset (const FM_DATA *fms, const FM_METADATA *meta, int block, uint64_t pos);
1786 extern int fm_getOriginalPosition (const FM_DATA *fms, const FM_METADATA *meta, int fm_id, int length, int direction, uint64_t fm_pos,
1787 uint32_t *segment_id, uint64_t *seg_pos);
1788 extern int fm_readFMmeta( FM_METADATA *meta);
1789 extern int fm_FM_read( FM_DATA *fm, FM_METADATA *meta, int getAll );
1790 extern void fm_FM_destroy ( FM_DATA *fm, int isMainFM);
1791 extern uint8_t fm_getChar(uint8_t alph_type, int j, const uint8_t *B );
1792 extern int fm_getSARangeReverse( const FM_DATA *fm, FM_CFG *cfg, char *query, char *inv_alph, FM_INTERVAL *interval);
1793 extern int fm_getSARangeForward( const FM_DATA *fm, FM_CFG *cfg, char *query, char *inv_alph, FM_INTERVAL *interval);
1794 extern int fm_configAlloc(FM_CFG **cfg);
1795 extern int fm_configDestroy(FM_CFG *cfg);
1796 extern int fm_metaDestroy(FM_METADATA *meta );
1797 extern int fm_updateIntervalForward( const FM_DATA *fm, const FM_CFG *cfg, char c, FM_INTERVAL *interval_f, FM_INTERVAL *interval_bk);
1798 extern int fm_updateIntervalReverse( const FM_DATA *fm, const FM_CFG *cfg, char c, FM_INTERVAL *interval);
1799 extern int fm_initSeeds (FM_DIAGLIST *list) ;
1800 extern FM_DIAG * fm_newSeed (FM_DIAGLIST *list);
1801 extern int fm_initAmbiguityList (FM_AMBIGLIST *list);
1802 extern int fm_addAmbiguityRange (FM_AMBIGLIST *list, uint32_t start, uint32_t stop);
1803 extern int fm_convertRange2DSQ(const FM_DATA *fm, const FM_METADATA *meta, uint64_t first, int length, int complementarity, ESL_SQ *sq, int fix_ambiguities );
1804 extern int fm_initConfigGeneric( FM_CFG *cfg, ESL_GETOPTS *go);
1805
1806 /* fm_ssv.c */
1807 extern int p7_SSVFM_longlarget( P7_OPROFILE *om, float nu, P7_BG *bg, double F1,
1808 const FM_DATA *fmf, const FM_DATA *fmb, FM_CFG *fm_cfg, const P7_SCOREDATA *ssvdata,
1809 int strands, ESL_RANDOMNESS *r, P7_HMM_WINDOWLIST *windowlist);
1810
1811
1812 /* fm_sse.c */
1813 extern int fm_configInit (FM_CFG *cfg, ESL_GETOPTS *go);
1814 extern int fm_getOccCount (const FM_DATA *fm, const FM_CFG *cfg, int pos, uint8_t c);
1815 extern int fm_getOccCountLT (const FM_DATA *fm, const FM_CFG *cfg, int pos, uint8_t c, uint32_t *cnteq, uint32_t *cntlt);
1816
1817 #endif /*P7_HMMERH_INCLUDED*/
1818
1819