Debian Codegraph @

src/cm_alndata.c

raw symbols SCIP
1 /* CM_ALNDATA: data structure containing information relevant to the
2 * alignment of a sequence and its output. Currently, mainly used by
3 * cmalign, but also used in cmbuild with the --refine option.
4 *
5 * Contents:
6 * 1. The CM_ALNDATA object.
7 * 2. Alignment workunit processing functions, which create and
8 * fill CM_ALNDATA objects.
9 *
10 * EPN, Fri Jan 6 09:00:31 2012
11 */
12 #include <esl_config.h>
13 #include <p7_config.h>
14 #include "config.h"
15
16 #include <stdlib.h>
17 #include <string.h>
18 #include <limits.h>
19
20 #include "easel.h"
21
22 #include "hmmer.h"
23
24 #include "infernal.h"
25
26 static int sub_alignment_prep(CM_t *orig_cm, char *errbuf, ESL_SQ *sq, CMSubMap_t **ret_submap, CM_t **ret_sub_cm);
27
28 /*****************************************************************
29 * 1. The CM_ALNDATA object
30 *****************************************************************/
31
32 /* Function: cm_alndata_Create()
33 * Synopsis: Allocate a CM_ALNDATA object.
34 * Incept: EPN, Fri Jan 6 09:01:33 2012
35 *
36 * Purpose: Allocates a new <CM_ALNDATA> and returns a pointer
37 * to it.
38 *
39 * Throws: <NULL> on allocation failure.
40 */
41 CM_ALNDATA *
42 cm_alndata_Create(void)
43 {
44 int status;
45 CM_ALNDATA *data = NULL;
46
47 ESL_ALLOC(data, sizeof(CM_ALNDATA));
48 data->sq = NULL;
49 data->idx = -1;
50 data->tr = NULL;
51 data->sc = 0.;
52 data->pp = 0.;
53 data->ppstr = NULL;
54 data->spos = -1;
55 data->epos = -1;
56 data->secs_bands = 0.;
57 data->secs_aln = 0.;
58 data->mb_tot = 0.;
59 data->tau = -1.;
60
61 return data;
62
63 ERROR:
64 return NULL;
65 }
66
67 /* Function: cm_alndata_Destroy()
68 * Synopsis: Free a CM_ALNDATA object.
69 * Incept: EPN, Fri Jan 6 09:10:55 2012
70 *
71 * Purpose: Frees a <CM_ALNDATA> object, but only frees the
72 * ESL_SQ <sq> if <free_sq> is TRUE. Often this is
73 * only a pointer to a sequence in another data
74 * structure that will be free'd with that structure.
75 *
76 * Returns: void.
77 */
78 void
79 cm_alndata_Destroy(CM_ALNDATA *data, int free_sq)
80 {
81 if(data == NULL) return;
82
83 if(free_sq && data->sq != NULL) esl_sq_Destroy(data->sq);
84 if(data->tr != NULL) FreeParsetree(data->tr);
85 if(data->ppstr != NULL) free(data->ppstr);
86 free(data);
87
88 return;
89 }
90
91 /*****************************************************************
92 * 2. Alignment workunit processing functions
93 *****************************************************************/
94
95 /* Function: sub_alignment_prep()
96 * Date: EPN, Mon Jan 9 05:25:26 2012
97 *
98 * Purpose: Prepare for an alignment workunit in sub-mode.
99 *
100 * Args: orig_cm - the covariance model
101 * errbuf - char buffer for reporting errors
102 * sq - the sequence we're creating the sub CM for
103 * ret_submap - RETURN: the sub CM to original CM map, created here
104 * ret_sub_cm - RETURN: the sub CM, created here
105 *
106 * Returns: eslOK on success;
107 * eslEMEM if we run out of memory;
108 * eslEINVAL on other error, errbuf is filled;
109 * <ret_dataA> is alloc'ed and filled with sq_block->count CM_ALNDATA objects.
110 */
111 int
112 sub_alignment_prep(CM_t *orig_cm, char *errbuf, ESL_SQ *sq, CMSubMap_t **ret_submap, CM_t **ret_sub_cm)
113 {
114 int status; /* easel status */
115 CM_t *sub_cm = NULL; /* the sub CM */
116 CMSubMap_t *submap = NULL; /* map from mother CM to sub CM, and vice versa */
117 int spos; /* HMM node most likely to have emitted posn 1 of target seq */
118 int spos_state; /* HMM state type for curr spos 0=match or 1=insert */
119 int epos; /* HMM node most likely to have emitted posn L of target seq */
120 int epos_state; /* HMM state type for curr epos 0=match or 1=insert */
121
122 /* step 1. predict start and end positions (HMM nodes) from posterior matrix */
123 if((status = cp9_Seq2Posteriors(orig_cm, errbuf, orig_cm->cp9_mx, orig_cm->cp9_bmx, orig_cm->cp9_bmx, sq->dsq, 1, sq->L, 0)) != eslOK) return status;
124 CP9NodeForPosn(orig_cm->cp9, 1, sq->L, 1, orig_cm->cp9_bmx, &spos, &spos_state, 0., TRUE, 0);
125 CP9NodeForPosn(orig_cm->cp9, 1, sq->L, sq->L, orig_cm->cp9_bmx, &epos, &epos_state, 0., FALSE, 0);
126 /* Deal with special cases for sub-CM alignment: If the most
127 * likely state to have emitted the first or last residue is the
128 * insert state in node 0, it only makes sense to start modelling
129 * at consensus column 1. */
130 if(spos == 0 && spos_state == 1) spos = 1;
131 if(epos == 0 && epos_state == 1) epos = 1;
132 /* If most-likely HMM node to emit final position comes BEFORE or
133 * EQUALS the most-likely HMM node to emit first position, our HMM
134 * alignment is crap, default to using the full CM. (note: If
135 * EQUALS we could be right, but we can't build a CM from a single
136 * consensus column (see notes in cm_modelmaker.c::cm_from_guide),
137 * and I would argue we don't really care about getting single
138 * residue alignments correct anyway.
139 */
140 if(epos <= spos) { spos = 1; epos = orig_cm->cp9->M; }
141
142 /* step 2. build the sub_cm from the original CM. */
143 if((status = build_sub_cm(orig_cm, errbuf, &sub_cm,
144 spos, epos, /* first and last col of structure kept in the sub_cm */
145 &submap, /* this maps from the sub_cm to cm and vice versa */
146 0)) != eslOK) /* don't print debugging info */
147 return status;
148
149 /* step 3. configure the sub_cm */
150 if((status = cm_ConfigureSub(sub_cm, errbuf, -1, orig_cm, submap)) != eslOK) return status;
151
152 *ret_sub_cm = sub_cm;
153 *ret_submap = submap;
154
155 return eslOK;
156 }
157
158 /* Function: DispatchSqBlockAlignment()
159 * Date: EPN, Fri Dec 30 14:59:43 2011
160 *
161 * Purpose: Given a CM and a block of sequences, align the
162 * sequence(s) using the appropriate alignment function and
163 * return relevant data for eventual output in <ret_dataA>.
164 * This function simply calls DispatchSqAlignment() serially
165 * for each sequence in the block, and creates an array
166 * of the <ret_data> DispatchSqAlignment() returns.
167 *
168 * Currently <mode>, <cp9b_valid> and <pass_idx> values sent
169 * to DispatchSqAlignment() are hard-coded to
170 * TRMODE_UNKNOWN, FALSE, and PLI_PASS_5P_AND_3P_FORCE (if
171 * cm->align_opts & CM_ALIGN_TRUNC) or PLI_PASS_STD_ANY (if
172 * (! cm->align_opts & CM_ALIGN_TRUNC)). This is because
173 * this function is only used by the alignment pipeline, in
174 * which these values are correct. If this changes, we may
175 * want caller to pass in an array of modes, cp9b_valids and
176 * pass_idx values, one per sq.
177 *
178 * If (cm->flags & CM_ALIGN_XTAU) we'll potentially tighten
179 * HMM bands until the required DP matrices are below out
180 * limit (<mxsize>). cm->maxtau is the max allowed tau value
181 * during this iterative band tightening, and cm->xtau is
182 * the factor by which we multiply cm->tau at each iteration
183 * during band tightening.
184 *
185 * Args: cm - the covariance model
186 * errbuf - char buffer for reporting errors
187 * sq_block - block of sequences to align
188 * mxsize - max size in Mb of allowable DP mx
189 * w - stopwatch for timing individual stages
190 * w_tot - stopwatch for timing total time per seq
191 * r - RNG, req'd if CM_ALIGN_SAMPLE, can be NULL otherwise
192 * ret_dataA - RETURN: newly created array of CM_ALNDATA objects
193 *
194 * Returns: eslOK on success;
195 * eslEINCOMPAT on contract violation, errbuf is filled;
196 * eslEMEM if we run out of memory;
197 * <ret_dataA> is alloc'ed and filled with sq_block->count CM_ALNDATA objects.
198 */
199 int
200 DispatchSqBlockAlignment(CM_t *cm, char *errbuf, ESL_SQ_BLOCK *sq_block, float mxsize, ESL_STOPWATCH *w,
201 ESL_STOPWATCH *w_tot, ESL_RANDOMNESS *r, CM_ALNDATA ***ret_dataA)
202 {
203 int status; /* easel status */
204 int j; /* counter over parsetrees */
205 CM_ALNDATA **dataA = NULL; /* CM_ALNDATA array we'll create and return */
206 ESL_SQ *sqp; /* ptr to a ESL_SQ */
207 int pass_idx; /* pass_idx passed to DispatchSqAlignment() */
208 char mode; /* mode passed to DispatchSqAlignment() */
209 int cp9b_valid; /* passed to DispatchSqAlignment() */
210
211 ESL_ALLOC(dataA, sizeof(CM_ALNDATA *) * ESL_MAX(1, sq_block->count)); // avoid 0 malloc
212 for(j = 0; j < sq_block->count; j++) dataA[j] = NULL;
213
214 /* DispatchSqAligment() needs a mode, pipeline pass index, and
215 * knowledge of whether cm->cp9b are valid for sequence to align
216 * (see note in 'Purpose' above). Currently the relevant values
217 * for these are as follows:
218 */
219 mode = TRMODE_UNKNOWN;
220 pass_idx = (cm->align_opts & CM_ALIGN_TRUNC) ? PLI_PASS_5P_AND_3P_FORCE : PLI_PASS_STD_ANY;
221 cp9b_valid = FALSE;
222
223 /* main loop: for each sequence, call DispatchSqAlignment() to do the work */
224 for(j = 0; j < sq_block->count; j++) {
225 sqp = sq_block->list + j;
226 if((status = DispatchSqAlignment(cm, errbuf, sqp, sq_block->first_seqidx + j, mxsize, mode, pass_idx, cp9b_valid, w, w_tot, r, &(dataA[j]))) != eslOK) goto ERROR;
227 }
228 *ret_dataA = dataA;
229
230 return eslOK;
231
232 ERROR:
233 if(dataA != NULL) {
234 for(j = 0; j < sq_block->count; j++) {
235 if(dataA[j] != NULL) cm_alndata_Destroy(dataA[j], FALSE);
236 }
237 free(dataA);
238 }
239 *ret_dataA = NULL;
240 fprintf(stderr, "Problem during alignment of sequence %s\n", sqp->name);
241 if(status == eslEMEM) ESL_FAIL(status, errbuf, "DispatchSqBlockAlignment(), out of memory");
242 else return status; /* errbuf was filled by DispatchSqAlignment() */
243 }
244
245 /* Function: DispatchSqAlignment()
246 * Date: EPN, Thu Jan 12 14:47:26 2012
247 *
248 * Purpose: Given a CM and a sequence, align the sequence(s) using
249 * the appropriate alignment function and return relevant
250 * data for eventual output in <ret_data>.
251 *
252 * This function can be called from either an alignment
253 * pipeline (i.e. cmalign) or a search/scan pipeline
254 * (i.e. cmsearch or cmscan). <idx> is the (overloaded) flag
255 * for determining which, if -1, we're a search/scan
256 * pipeline. This is only relevant because in a search/scan
257 * pipeline we don't care about determining spos/epos so we
258 * don't call ParsetreeToCMBounds().
259 *
260 * If (cm->flags & CM_ALIGN_XTAU) we'll potentially tighten
261 * HMM bands until the required DP matrices are below out
262 * limit (<mxsize>). cm->maxtau is the max allowed tau value
263 * during this iterative band tightening, and cm->xtau is
264 * the factor by which we multiply cm->tau at each iteration
265 * during band tightening.
266 *
267 * Args: cm - the covariance model
268 * errbuf - char buffer for reporting errors
269 * sq - sequence to align
270 * idx - index of sequence (may be used to reorder data later)
271 * mxsize - max size in Mb of allowable DP mx
272 * mode - preset mode of alignment (TRMODE_UNKNOWN if unknown)
273 * pass_idx - pipeline pass index, determines trunc penalty
274 * cp9b_valid - TRUE if cm->cp9b are valid, don't compute HMM bands
275 * w - stopwatch for timing individual stages, can be NULL
276 * w_tot - stopwatch for timing total time per seq, can be NULL
277 * r - RNG, req'd if CM_ALIGN_SAMPLE, can be NULL otherwise
278 * ret_data - RETURN: newly created CM_ALNDATA object
279 *
280 * Returns: eslOK on success;
281 * eslEINCOMPAT on contract violation, errbuf is filled;
282 * eslEMEM if we run out of memory;
283 * <ret_data> is alloc'ed and filled.
284 */
285 int
286 DispatchSqAlignment(CM_t *cm, char *errbuf, ESL_SQ *sq, int64_t idx, float mxsize, char mode, int pass_idx,
287 int cp9b_valid, ESL_STOPWATCH *w, ESL_STOPWATCH *w_tot, ESL_RANDOMNESS *r, CM_ALNDATA **ret_data)
288 {
289 int status; /* easel status */
290 CM_ALNDATA *data = NULL; /* CM_ALNDATA we'll create and fill */
291 float sc = 0.; /* score from alignment function */
292 float pp = 0.; /* average PP from alignment function */
293 Parsetree_t *tr = NULL; /* ptr to a parsetree */
294 char *ppstr = NULL; /* ptr to a PP string */
295 float secs_bands = 0.; /* seconds elapsed for band calculation */
296 float secs_aln = 0.; /* seconds elapsed for alignment calculation */
297 float mb_tot = 0.; /* size of all DP matrices used for alignment */
298 double tau = -1.; /* tau used for calculating bands */
299 float thresh1 = -1.; /* cp9b->thresh1 used for calculating bands */
300 float thresh2 = -1.; /* cp9b->thresh2 used for calculating bands */
301 int spos = -1; /* start posn: first non-gap CM consensus position */
302 int epos = -1; /* end posn: final non-gap CM consensus position */
303 double save_tau = cm->tau; /* cm->tau upon entrance, we restore before leaving */
304 float save_thresh1 = (cm->cp9b == NULL) ? -1. : cm->cp9b->thresh1;
305 float save_thresh2 = (cm->cp9b == NULL) ? -1. : cm->cp9b->thresh2;
306
307 /* alignment options */
308 int do_nonbanded = (cm->align_opts & CM_ALIGN_NONBANDED) ? TRUE : FALSE;
309 int do_qdb = (cm->align_opts & CM_ALIGN_QDB) ? TRUE : FALSE;
310 int do_hbanded = (do_nonbanded || do_qdb) ? FALSE : TRUE;
311 int do_optacc = (cm->align_opts & CM_ALIGN_OPTACC) ? TRUE : FALSE;
312 int do_sample = (cm->align_opts & CM_ALIGN_SAMPLE) ? TRUE : FALSE;
313 int do_post = (cm->align_opts & CM_ALIGN_POST) ? TRUE : FALSE;
314 int do_sub = (cm->align_opts & CM_ALIGN_SUB) ? TRUE : FALSE;
315 int do_small = (cm->align_opts & CM_ALIGN_SMALL) ? TRUE : FALSE;
316 int do_trunc = (cm->align_opts & CM_ALIGN_TRUNC) ? TRUE : FALSE;
317 int do_xtau = (cm->align_opts & CM_ALIGN_XTAU) ? TRUE : FALSE;
318 int doing_search = FALSE;
319
320 #if eslDEBUGLEVEL >= 1
321 printf("#DEBUG: in DispatchSqAlignment() %s\n", sq->name);
322 printf("#DEBUG: \tdo_nonbanded: %d\n", do_nonbanded);
323 printf("#DEBUG: \tdo_optacc: %d\n", do_optacc);
324 printf("#DEBUG: \tdo_sample: %d\n", do_sample);
325 printf("#DEBUG: \tdo_post: %d\n", do_post);
326 printf("#DEBUG: \tdo_sub: %d\n", do_sub);
327 printf("#DEBUG: \tdo_small: %d\n", do_small);
328 printf("#DEBUG: \tdo_trunc: %d\n", do_trunc);
329 printf("#DEBUG: \tdo_qdb: %d\n", do_qdb);
330 printf("#DEBUG: \tdoing_search: %d\n", doing_search);
331 #endif
332
333 /* sub-mode specific variables (wouldn't be needed if sub mode were not supported) */
334 CM_t *orig_cm = cm; /* pointer to the original CM */
335 CM_t *sub_cm = NULL; /* the sub CM */
336 CMSubMap_t *submap = NULL; /* map from mother CM to sub CM, and vice versa */
337 Parsetree_t *full_tr = NULL; /* converted parsetree to full CM */
338
339 /* contract check */
340 if(do_small && do_hbanded) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to do small and HMM banded alignment");
341 if(do_small && do_optacc) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to do small and opt acc alignment");
342 if(do_post && do_small) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to do PP and small alignment");
343 if(do_optacc && do_sample) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to sample and do optacc alignment");
344 if(do_sub && do_small) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to do sub and small alignment");
345 if(do_sub && do_trunc) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to do sub and truncated alignment");
346 if(do_sample && r == NULL) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to sample but RNG r == NULL");
347 if(do_xtau && ! do_hbanded) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to multiply tau without HMM banded alignment");
348 if(do_xtau && cp9b_valid) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to multiply tau but HMM bands already valid");
349 if(do_qdb && do_nonbanded) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to do qdb and nonbanded alignment");
350 if(do_qdb && do_trunc) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to use qdbs and truncated alignment");
351 /* qdb + trunc combo disallowed only b/c no function exists for it yet */
352 if(do_qdb && (! do_small)) ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to use qdbs but not divide and conquer");
353 /* qdb + small combo disallowed b/c only non-HMM banded non-small alignment functions are not set up to use QDBs */
354 if(do_qdb && cm->qdbinfo == NULL) {
355 ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to use qdbs but cm->qdbinfo is NULL");
356 }
357 if(do_qdb && (cm->qdbinfo->dmin2 == NULL || cm->qdbinfo->dmax2 == NULL)) {
358 ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to use qdbs but cm->qdbinfo is NULL");
359 }
360 if(do_trunc && (! cm_pli_PassAllowsTruncation(pass_idx))) {
361 ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() trying to do truncated alignment, but pass_idx doesn't allow truncation (PLI_PASS_STD_ANY)");
362 }
363 if(pass_idx == PLI_PASS_STD_ANY && (mode == TRMODE_L || mode == TRMODE_R || mode == TRMODE_T)) {
364 ESL_XFAIL(eslEINCOMPAT, errbuf, "DispatchSqAlignment() mode is L, R, or T, but pass_idx is PLI_PASS_STD_ANY");
365 }
366
367 if(w_tot != NULL) esl_stopwatch_Start(w_tot);
368
369 /* do sub-mode specific pre-alignment steps, if nec */
370 if(do_sub) {
371 if((status = sub_alignment_prep(cm, errbuf, sq, &submap, &sub_cm)) != eslOK) goto ERROR;
372 cm = sub_cm;
373 }
374
375 if(w != NULL) esl_stopwatch_Start(w);
376 /* do small D&C alignment, if nec */
377 if(do_small) {
378 if(do_trunc) {
379 sc = TrCYK_DnC(cm, sq->dsq, sq->L, 0, 1, sq->L, pass_idx, FALSE, &tr); /* FALSE: don't reproduce 1.0 behavior */
380 mb_tot = 4. * CYKNonQDBSmallMbNeeded(cm, sq->L); /* not sure how accurate this is */
381 }
382 else {
383 /* with QDB, always use dmin2/dmax2, the looser of the two sets of QDBs in cm->qdbinfo */
384 sc = CYKDivideAndConquer(cm, sq->dsq, sq->L, 0, 1, sq->L, &tr,
385 (do_qdb) ? cm->qdbinfo->dmin2 : NULL,
386 (do_qdb) ? cm->qdbinfo->dmax2 : NULL);
387 mb_tot = CYKNonQDBSmallMbNeeded(cm, sq->L);
388 }
389 }
390 else { /* do_small is FALSE */
391 if(do_nonbanded || do_qdb) { /* do not use HMM bands */
392 if(do_trunc) {
393 if((status = cm_TrAlignSizeNeeded(cm, errbuf, sq->L, mxsize, do_sample, do_post,
394 NULL, NULL, NULL, &mb_tot)) != eslOK) goto ERROR;
395 if((status = cm_TrAlign(cm, errbuf, sq->dsq, sq->L, mxsize, mode, pass_idx,
396 do_optacc, do_sample, cm->trnb_mx, cm->trnb_shmx, cm->trnb_omx,
397 cm->trnb_emx, r, do_post ? &ppstr : NULL, &tr, NULL, &pp, &sc)) != eslOK) goto ERROR;
398 }
399 else {
400 if((status = cm_AlignSizeNeeded(cm, errbuf, sq->L, mxsize, do_sample, do_post,
401 NULL, NULL, NULL, &mb_tot)) != eslOK) goto ERROR;
402 if((status = cm_Align(cm, errbuf, sq->dsq, sq->L, mxsize, do_optacc, do_sample, cm->nb_mx, cm->nb_shmx,
403 cm->nb_omx, cm->nb_emx, r, do_post ? &ppstr : NULL, &tr, &pp, &sc)) != eslOK) goto ERROR;
404 }
405 }
406 else { /* use HMM bands */
407 if(! cp9b_valid) {
408 if(do_xtau) { /* multiply tau (if nec) until required mx is below Mb limit (mxsize) */
409 if((status = cp9_IterateSeq2Bands(cm, errbuf, sq->dsq, 1, sq->L, pass_idx, mxsize, doing_search, do_sample, do_post, 1 /*do_iterate*/,
410 cm->maxtau, NULL)) != eslOK) goto ERROR;
411 }
412 else {
413 if((status = cp9_Seq2Bands(cm, errbuf, cm->cp9_mx, cm->cp9_bmx, cm->cp9_bmx, sq->dsq,
414 1, sq->L, cm->cp9b, doing_search, pass_idx, 0)) != eslOK) goto ERROR;
415 }
416 if(w != NULL) esl_stopwatch_Stop(w);
417 secs_bands = (w == NULL) ? 0. : w->elapsed;
418 tau = cm->tau;
419 thresh1 = cm->cp9b->thresh1;
420 thresh2 = cm->cp9b->thresh2;
421 /* note: we don't set these three if cp9b_valid is TRUE */
422 }
423
424 if(w != NULL) esl_stopwatch_Start(w);
425 if(do_trunc) {
426 if((status = cm_TrAlignSizeNeededHB(cm, errbuf, sq->L, mxsize, do_sample, do_post,
427 NULL, NULL, NULL, NULL, NULL, &mb_tot)) != eslOK) goto ERROR;
428 if((status = cm_TrAlignHB(cm, errbuf, sq->dsq, sq->L, mxsize, mode, pass_idx,
429 do_optacc, do_sample, cm->trhb_mx, cm->trhb_shmx, cm->trhb_omx,
430 cm->trhb_emx, r, do_post ? &ppstr : NULL, &tr, NULL, &pp, &sc)) != eslOK) goto ERROR;
431 }
432 else {
433 if((status = cm_AlignSizeNeededHB(cm, errbuf, sq->L, mxsize, do_sample, do_post,
434 NULL, NULL, NULL, NULL, NULL, &mb_tot)) != eslOK) goto ERROR;
435 if((status = cm_AlignHB(cm, errbuf, sq->dsq, sq->L, mxsize, do_optacc, do_sample, cm->hb_mx, cm->hb_shmx,
436 cm->hb_omx, cm->hb_emx, r, do_post ? &ppstr : NULL, &tr, &pp, &sc)) != eslOK) goto ERROR;
437 }
438 }
439 }
440
441 if(do_sub) { /* add size of original CM's CP9 matrices used for calculating start/end position */
442 mb_tot += orig_cm->cp9_mx->size_Mb;
443 mb_tot += orig_cm->cp9_bmx->size_Mb;
444 }
445
446 if(w != NULL) esl_stopwatch_Stop(w);
447 secs_aln = (w == NULL) ? 0. : w->elapsed;
448
449 if(do_sub) {
450 /* convert sub cm parsetree to a full CM parsetree */
451 if((status = sub_cm2cm_parsetree(orig_cm, cm, &full_tr, tr, submap, 0)) != eslOK) ESL_XFAIL(status, errbuf, "out of memory, converting sub parsetree to full parsetree");
452 /* free sub data structures, we're done with them */
453 FreeParsetree(tr); tr = full_tr;
454 FreeCM(cm); cm = orig_cm;
455 FreeSubMap(submap); submap = NULL;
456 }
457
458 /* determine start and end points of the parsetree,
459 * but only if we're not in a search/scan pipeline
460 */
461 if(idx != -1) { /* we're not in a search/scan pipeline */
462 if((status = ParsetreeToCMBounds(cm, tr, TRUE, TRUE, errbuf, NULL, NULL, NULL, NULL, &spos, &epos)) != eslOK) goto ERROR;
463 }
464
465 /* create and fill data */
466 ESL_ALLOC(data, sizeof(CM_ALNDATA));
467 data->sq = sq;
468 data->idx = idx;
469 data->tr = tr;
470 data->sc = sc;
471 data->pp = (do_post) ? pp : 0.;
472 data->ppstr = (do_post) ? ppstr : NULL;
473 data->spos = spos;
474 data->epos = epos;
475 data->secs_bands = (do_nonbanded) ? 0. : secs_bands;
476 data->secs_aln = secs_aln;
477 data->mb_tot = mb_tot;
478 data->tau = tau;
479 data->thresh1 = thresh1;
480 data->thresh2 = thresh2;
481 if(w_tot != NULL) esl_stopwatch_Stop(w_tot);
482 data->secs_tot = (w_tot == NULL) ? 0. : w_tot->elapsed;
483
484 *ret_data = data;
485
486 cm->tau = save_tau;
487 if(cm->cp9b != NULL) {
488 cm->cp9b->thresh1 = save_thresh1;
489 cm->cp9b->thresh2 = save_thresh2;
490 }
491 return eslOK;
492
493 ERROR:
494 cm->tau = save_tau;
495 if(cm->cp9b != NULL) {
496 cm->cp9b->thresh1 = save_thresh1;
497 cm->cp9b->thresh2 = save_thresh2;
498 }
499 if(data != NULL) cm_alndata_Destroy(data, FALSE);
500 *ret_data = NULL;
501
502 if(status == eslEMEM) ESL_FAIL(status, errbuf, "DispatchSqAlignment(), out of memory");
503
504 return status;
505 }