Debian Codegraph @

src/impl_sse/sse_cmsearch.c

raw symbols SCIP
1 #include <esl_config.h>
2 #include "config.h"
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <time.h>
8
9 #include "easel.h"
10 #include "esl_getopts.h"
11 #include "esl_histogram.h"
12 #include "esl_exponential.h"
13 #include "esl_gumbel.h"
14 #include "esl_random.h"
15 #include "esl_randomseq.h"
16 #include "esl_sqio.h"
17 #include "esl_stats.h"
18 #include "esl_stopwatch.h"
19 #include "esl_vectorops.h"
20 #include "esl_wuss.h"
21
22 #include "hmmer.h"
23
24 #include "infernal.h"
25
26 #include "impl_sse.h"
27
28 static ESL_OPTIONS options[] = {
29 /* name type default env range toggles reqs incomp help docgroup*/
30 /* Basic options */
31 { "-h", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 1 },
32 { "-Z", eslARG_REAL, NULL, NULL, NULL, NULL, NULL, NULL, "set Z (database size in *Mb*) to <x> for E-value calculations", 1},
33 { "--toponly",eslARG_NONE, NULL, NULL, NULL, NULL, NULL, NULL, "search only the top strand, not reverse complement", 1 },
34 /* Cutoff level options */
35 { "--s1-F",eslARG_REAL,"0.02", NULL, NULL, NULL, NULL, "--s1-E", "set stage 1 cutoff to estimated filter pass rate <x>", 2 },
36 { "--s1-T",eslARG_REAL, NULL, NULL, NULL, NULL, NULL, "--s1-E", "set stage 1 cutoff to bitscore <x>", 2 },
37 { "--s1-E",eslARG_REAL, NULL, NULL,"0<x<1", NULL, NULL, "--s1-T", "set stage 1 cutoff to e-value <x> per kb", 2 },
38 { "--s2-T",eslARG_REAL, NULL, NULL, NULL, NULL, NULL, "--s2-P", "set stage 2 cutoff to bitscore <x>", 2 },
39 { "--s2-P",eslARG_REAL,"1e-5", NULL,"0<x<1", NULL, NULL, "--s2-T", "set stage 2 cutoff to probability <x>", 2 },
40 { "--s3-T",eslARG_REAL, NULL, NULL, NULL, NULL, NULL, "--s3-E", "set stage 3 cutoff to bitscore <x>", 2 },
41 { "--s3-E",eslARG_REAL, "1", NULL, NULL, NULL, NULL, "--s3-T", "set stage 3 cutoff to e-value <x>", 2 },
42 /* Meta-model parameters */
43 { "--mmp_auto",eslARG_NONE,"default",NULL, NULL, "--mmp_manual",NULL,NULL,"automatic determination of MSCYK model parameters",3},
44 { "--mmp_manual",eslARG_NONE, FALSE,NULL, NULL, "--mmp_auto", NULL,NULL,"manual determination of MSCYK model parameters",3},
45 { "--S_Sa", eslARG_REAL, "0.25", NULL, NULL, NULL, NULL, NULL, "S emit single residue probability <x>", 3 },
46 { "--S_SM", eslARG_REAL, NULL, NULL, NULL, NULL,"--mmp_manual","--mmp_auto", "S add model segment probability <x>", 3 },
47 { "--S_e", eslARG_NONE, NULL, NULL, NULL, NULL,"--mmp_manual","--mmp_auto", "S end probability (unsettable, 1-S_Sa-S_SM)", 3 },
48 /* Output options */
49 { "--evd1",eslARG_NONE,NULL,NULL,NULL, NULL, NULL, NULL, "Output score survival plot data for MSCYK EVD", 4 },
50 { "--glbf",eslARG_INT,"0",NULL, "n<4", NULL, NULL, NULL, "GLBF-style output for stage <n>, 0 for none", 4 },
51 { "--glbf_all",eslARG_NONE,FALSE,NULL, NULL, NULL, NULL, NULL, "GLBF-style output for all stages, to separate files", 4 },
52 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
53 };
54 static char usage[] = "[-options] <cmfile> <seqfile>";
55 static char banner[] = "multistage SSE pipeline for sequence database search with an RNA CM";
56
57 int
58 main(int argc, char **argv)
59 {
60 int status;
61 ESL_GETOPTS *go = esl_getopts_CreateDefaultApp(options, 2, argc, argv, banner, usage);
62 CM_t *cm;
63 ESL_ALPHABET *abc = NULL;
64 long dbsize;
65 int i;
66 float sc, sc3;
67 float p2, p3;
68 float e3;
69 float filtersc, nullsc;
70 float null3_correction;
71 int sc2, br2, bsc2;
72 char *cmfile = esl_opt_GetArg(go, 1);
73 char *seqfile= esl_opt_GetArg(go, 2);
74 CM_FILE *cmfp; /* open input CM file stream */
75 ESL_SQFILE *sqfp;
76 ESL_SQ *seq;
77 char errbuf[eslERRBUFSIZE];
78 CM_CONSENSUS *ccm = NULL;
79 CM_OPTIMIZED *ocm = NULL;
80 uint8_t s1_cutoff;
81 int16_t s2_cutoff;
82 float s3_cutoff;
83 float s1_fcut = 0.;
84 float s2_pcut = 0;
85 float s3_pcut = 0;
86 float s3_ecut = 1;
87 float e_cutoff, f_cutoff;
88 float f_S_Sa, f_S_SM, f_S_e;
89 float nullL;
90 int format = eslSQFILE_UNKNOWN;
91 int o_glbf, o_glbf_all;
92 int do_reverse, is_reversed;
93 FILE *S0_OFILE = NULL;
94 FILE *S1_OFILE = NULL;
95 FILE *S2_OFILE = NULL;
96 FILE *S3_OFILE = NULL;
97 HitCoord_epi16 *s2_coord = NULL;
98
99 /* vars for MSCYK score distribution fitting */
100 int L = 1000; /* P-values will be per-kb, so simulate 1 kb at a time */
101 ///int samples = 10000;
102 int samples = 1000;
103 float *x;
104 double *xv;
105 int n, k, hitloop;
106 double ccm_mu, ccm_lambda;
107 double param[2];
108 ESL_RANDOMNESS *r;
109 double background[4] = {0.25, 0.25, 0.25, 0.25};
110 ESL_HISTOGRAM *hist;
111
112 /* post-MSCYK bias filter */
113 int do_biasfilter = TRUE;
114
115 CM_TOPHITS *results = NULL; /* First stage results from MSCYK */
116 CM_TOPHITS *windows = NULL; /* Expanded and merged hit candidate windows after first stage */
117 ESL_STOPWATCH *w = esl_stopwatch_Create();
118
119 ESL_ALLOC(s2_coord, sizeof(HitCoord_epi16));
120
121 o_glbf = esl_opt_GetInteger(go, "--glbf");
122 o_glbf_all = esl_opt_GetBoolean(go, "--glbf_all");
123 if (esl_opt_GetBoolean(go, "--toponly")) do_reverse = 0;
124 else do_reverse = 1;
125
126 /* Initializations: open the CM file, read one CM, and make sure there's only one. */
127 status = cm_file_Open(cmfile, NULL, FALSE, &cmfp, errbuf);
128 if (status == eslENOTFOUND) cm_Fail("File existence/permissions problem in trying to open CM file %s.\n%s\n", cmfile, errbuf);
129 else if (status == eslEFORMAT) cm_Fail("File format problem in trying to open CM file %s.\n%s\n", cmfile, errbuf);
130 else if (status != eslOK) cm_Fail("Unexpected error %d in opening CM file %s.\n%s\n", status, cmfile, errbuf);
131 status = cm_file_Read(cmfp, TRUE, &abc, &cm);
132 if(status != eslOK) cm_Fail(cmfp->errbuf);
133 status = cm_file_Read(cmfp, TRUE, &abc, NULL);
134 if(status != eslEOF) cm_Fail("CM file %s does not contain just one CM\n", cmfp->fname);
135 cm_file_Close(cmfp);
136
137 if (esl_sqfile_Open(seqfile, format, NULL, &sqfp) != eslOK) cm_Fail("Failed to open sequence database file\n");
138 if ((status = GetDBSize(sqfp, errbuf, &dbsize, NULL, NULL)) != eslOK) return status;
139 if (! esl_opt_GetBoolean(go, "--toponly")) dbsize *= 2;
140
141 /* overwrite dbsize if -Z enabled */
142 if( esl_opt_IsOn(go, "-Z")) dbsize = (long) (esl_opt_GetReal(go, "-Z") * 1000000.); /* convert Mb to bases then to a long */
143
144 /* Update dbsize in cm config */
145 if (cm->flags & CMH_EXPTAIL_STATS) {
146 if ((status = UpdateExpsForDBSize(cm, errbuf, dbsize)) != eslOK) cm_Fail(errbuf);
147 }
148 else {
149 cm_Fail("Filters require calibration; please run cmcalibrate before continuing.");
150 }
151
152 cm->config_opts |= CM_CONFIG_LOCAL;
153 cm->config_opts |= CM_CONFIG_SCANMX;
154 cm->search_opts |= CM_SEARCH_NONBANDED;
155 cm->search_opts |= CM_SEARCH_NULL3;
156 if ((status = cm_Configure(cm, errbuf, -1)) != eslOK) cm_Fail(errbuf);
157 ccm = cm_consensus_Convert(cm);
158 ocm = cm_optimized_Convert(cm);
159
160 if(ccm == NULL) cm_Fail("ccm NULL!\n");
161 if(ccm->oesc == NULL) cm_Fail("oesc NULL!\n");
162
163 /* Set meta-model parameters */
164 if (esl_opt_IsOn(go, "--mmp_auto")) {
165 f_S_Sa = esl_opt_GetReal(go, "--S_Sa");
166 f_S_SM = (cm->clen - f_S_Sa*(cm->clen + 1))/((1+ccm->p_rfrag)*cm->clen + ccm->e_fraglen);
167 f_S_e = 1. - f_S_Sa - f_S_SM;
168 nullL = (float) cm->clen;
169 }
170 else {
171 f_S_Sa = esl_opt_GetReal(go, "--S_Sa");
172 if (esl_opt_IsOn(go, "--S_SM")) f_S_SM = esl_opt_GetReal(go, "--S_SM");
173 else f_S_SM = 0.24;
174 f_S_e = 1. - f_S_Sa - f_S_SM;
175 nullL = ccm_explen(ccm,f_S_Sa,f_S_SM,f_S_e);
176 }
177 ccm->bg->p1 = nullL/(nullL+1.);
178 if (f_S_Sa <= 0 || f_S_Sa >= 1) cm_Fail("S->Sa must be between zero and 1\n");
179 if (f_S_SM <= 0 || f_S_SM >= 1) cm_Fail("S->SM must be between zero and 1\n");
180 if (f_S_e <= 0) cm_Fail("Error: S->e out of range\n");
181 ccm->tsb_S_Sa = unbiased_byteify(ccm,sreLOG2(f_S_Sa));
182 ccm->tsb_S_SM = unbiased_byteify(ccm,sreLOG2(f_S_SM));
183 ccm->tsb_S_e = unbiased_byteify(ccm,sreLOG2(f_S_e ));
184 ccm->tsb_M_S = unbiased_byteify(ccm,ccm->sc_frag);
185
186 /* Set bg model */
187 if (do_biasfilter) {
188 ccm_SetCompo(ccm, f_S_Sa, f_S_SM, f_S_e);
189 ccm_bg_SetFilter(ccm, nullL, cm->smx->W);
190 }
191
192 /* Set output files */
193 if (o_glbf_all) {
194 int length = 7;
195 char *fname;
196 ESL_ALLOC(fname, 25*sizeof(char));
197 if (strlen(cmfile) - 3 < length) length = strlen(cmfile) - 3;
198 strncpy(fname,&cmfile[strlen(cmfile)-(length+4)],length);
199 fname[length] = '\0';
200 if ((S0_OFILE = fopen(strcat(fname,".s0.glbf"),"w")) == NULL) { cm_Fail("Couldn't open stage 0 glbf file for writing!"); }
201 fname[length] = '\0';
202 if ((S1_OFILE = fopen(strcat(fname,".s1.glbf"),"w")) == NULL) { cm_Fail("Couldn't open stage 1 glbf file for writing!"); }
203 fname[length] = '\0';
204 if ((S2_OFILE = fopen(strcat(fname,".s2.glbf"),"w")) == NULL) { cm_Fail("Couldn't open stage 2 glbf file for writing!"); }
205 fname[length] = '\0';
206 if ((S3_OFILE = fopen(strcat(fname,".s3.glbf"),"w")) == NULL) { cm_Fail("Couldn't open stage 3 glbf file for writing!"); }
207 }
208
209 /* Set filtering cutoff parameters */
210 if (esl_opt_IsOn(go, "--s1-T")) {
211 f_cutoff = esl_opt_GetReal(go, "--s1-T");
212 fprintf(stderr,"Stage 1: score cutoff %.2f\n",f_cutoff);
213 /* Need to scale and offset, but not change sign -> switch sign ahead of time */
214 s1_fcut = f_cutoff;
215 s1_cutoff = ccm->base_b + unbiased_byteify(ccm,-f_cutoff);
216 if (s1_cutoff == BYTEMAX) {
217 s1_cutoff--;
218 f_cutoff = (s1_cutoff - (float) ccm->base_b)/ccm->scale_b;
219 fprintf(stderr,"Stage 1: Warning - score cutoff out of range, setting to max of %.2f\n",f_cutoff);
220 }
221 }
222 else {
223 /* Simulation to determine score distribution tail for MSCYK/CM combined model */
224 esl_stopwatch_Start(w);
225 hist = esl_histogram_CreateFull(-50., 50., 0.5);
226 seq = esl_sq_Create();
227 r = esl_randomness_CreateTimeseeded();
228 ESL_ALLOC(x, sizeof(float) * samples);
229 ESL_ALLOC(seq->dsq, sizeof(ESL_DSQ) * (L+2));
230 for (k = 0; k < samples; k++) {
231 esl_rsq_xIID(r, background, 4, L, seq->dsq);
232 if((status = SSE_MSCYK(ccm, errbuf, cm->smx->W, seq->dsq, 1, L, 0x00, NULL, FALSE, NULL, &(x[k]))) != eslOK) cm_Fail(errbuf);
233 esl_histogram_Add(hist, x[k]);
234 }
235 esl_histogram_GetTailByMass(hist, 0.2, &xv, &n, NULL);
236 esl_exp_FitComplete(xv, n, &ccm_mu, &ccm_lambda);
237 param[0] = ccm_mu; param[1] = ccm_lambda;
238 esl_histogram_SetExpectedTail(hist, ccm_mu, 0.2, &esl_exp_generic_cdf, &param);
239 esl_stopwatch_Stop(w);
240 if (esl_opt_IsOn(go, "--evd1")) esl_histogram_PlotSurvival(stdout, hist);
241 fprintf(stderr,"Stage 1: EVD parameters mu = %7.3f\t lambda = %7.3f; ",ccm_mu,ccm_lambda);
242 esl_stopwatch_Display(stderr, w, " CPU time: ");
243
244 float ccm_mu_extrap = ccm_mu + (log(0.2) / ccm_lambda);
245 if (esl_opt_IsOn(go, "--s1-E")) {
246 e_cutoff = esl_opt_GetReal(go,"--s1-E");
247 f_cutoff = esl_exp_invcdf(1.-e_cutoff,ccm_mu_extrap,ccm_lambda);
248 fprintf(stderr,"Stage 1: E-value cutoff %.2e per kb -> score cutoff %.2f\n",e_cutoff,f_cutoff);
249 }
250 else /*if (esl_opt_IsOn(go, "--s1-F"))*/ {
251 e_cutoff = esl_opt_GetReal(go,"--s1-F")*500/cm->smx->W;
252 f_cutoff = esl_exp_invcdf(1.-e_cutoff,ccm_mu_extrap,ccm_lambda);
253 fprintf(stderr,"Stage 1: Filter pass rate %f -> E-value cutoff %.2e per kb -> score cutoff %.2f\n",esl_opt_GetReal(go,"--s1-F"),e_cutoff,f_cutoff);
254 }
255
256 s1_fcut = f_cutoff;
257 /* Need to scale and offset, but not change sign -> switch sign ahead of time */
258 s1_cutoff = ccm->base_b + unbiased_byteify(ccm,-f_cutoff);
259 if (s1_cutoff >= BYTEMAX) {
260 s1_cutoff = BYTEMAX;
261 s1_cutoff--;
262 f_cutoff = ((float) (s1_cutoff - ccm->base_b))/ccm->scale_b;
263 fprintf(stderr,"Stage 1: Warning - score cutoff out of range, setting to max of %.2f\n",f_cutoff);
264 e_cutoff = esl_exp_cdf(f_cutoff,ccm_mu,ccm_lambda);
265 fprintf(stderr,"Stage 1: Warning - equivalent max p-value of %.2e\n",e_cutoff);
266 }
267 free(x);
268 esl_randomness_Destroy(r);
269 esl_sq_Destroy(seq);
270 esl_histogram_Destroy(hist);
271 }
272
273 if (esl_opt_IsOn(go, "--s2-T")) {
274 f_cutoff = esl_opt_GetReal(go, "--s2-T");
275 fprintf(stderr,"Stage 2: score cutoff %.2f\n",f_cutoff);
276 s2_cutoff = wordify(ocm->scale_w, f_cutoff);
277 if (s2_cutoff == WORDMAX) {
278 s2_cutoff--;
279 f_cutoff = s2_cutoff/ocm->scale_w;
280 fprintf(stderr,"Stage 2: Warning - score cutoff out of range, setting to max of %.2f\n",f_cutoff);
281 }
282 }
283 else {
284 s2_pcut = esl_opt_GetReal(go,"--s2-P");
285 // FIXME FIXME FIXME 1.-p_cutoff rounds to 1 in the range of 1e-18 -> f_cutoff = inf, even though the
286 // FIXME FIXME FIXME effective possible range goes as far as about 1e-24 (for RF00037 at least)
287 f_cutoff = esl_exp_invcdf(1.-s2_pcut,cm->expA[EXP_CM_LC]->mu_extrap,cm->expA[EXP_CM_LC]->lambda);
288 fprintf(stderr,"Stage 2: P-value cutoff %.2e\n",e_cutoff);
289 s2_cutoff = wordify(ocm->scale_w, f_cutoff);
290 /* fprintf(stderr,"s2 %e %f %e %d\n",e_cutoff,f_cutoff,s2_pcut,s2_cutoff); */
291 if (s2_cutoff == WORDMAX) {
292 s2_cutoff--;
293 f_cutoff = s2_cutoff/ocm->scale_w;
294 s2_pcut = esl_exp_surv(f_cutoff,cm->expA[EXP_CM_LC]->mu_extrap,cm->expA[EXP_CM_LC]->lambda);
295 /* fprintf(stderr,"s2 %e %f %e %d\n",e_cutoff,f_cutoff,s2_pcut,s2_cutoff); */
296 fprintf(stderr,"Stage 2: Warning - score cutoff out of range, setting to max of %.2e\n",s2_pcut);
297 }
298 }
299 /* Need to scale */
300
301 if (esl_opt_IsOn(go, "--s3-T")) {
302 f_cutoff = esl_opt_GetReal(go, "--s3-T");
303 fprintf(stderr,"Stage 3: score cutoff %.2f\n",f_cutoff);
304 }
305 else {
306 e_cutoff = esl_opt_GetReal(go,"--s3-E");
307 s3_ecut = e_cutoff;
308 s3_pcut = e_cutoff/cm->expA[EXP_CM_LC]->cur_eff_dbsize;
309 f_cutoff = esl_exp_invcdf(1.-s3_pcut,cm->expA[EXP_CM_LC]->mu_extrap,cm->expA[EXP_CM_LC]->lambda);
310 fprintf(stderr,"Stage 3: E-value cutoff %.2e\n",e_cutoff);
311 }
312 s3_cutoff = f_cutoff;
313
314 seq = esl_sq_Create();
315 while ( esl_sqio_Read(sqfp, seq) == eslOK)
316 {
317 is_reversed = 0;
318 if (seq->n == 0) continue;
319 if (seq->dsq == NULL) esl_sq_Digitize(abc, seq);
320
321 PIPELINE:
322 /* Stage 1: MSCYK */
323 results = cm_tophits_Create();
324 esl_stopwatch_Start(w);
325 if((status = SSE_MSCYK(ccm, errbuf, cm->smx->W, seq->dsq, 1, seq->n, s1_cutoff, results, FALSE, NULL, &sc)) != eslOK) cm_Fail(errbuf);
326 esl_stopwatch_Stop(w);
327 fprintf(stderr,"Stage 1: %-24s %-22s",seq->name,is_reversed?"(reverse complement)":"");
328 esl_stopwatch_Display(stderr, w, " CPU time: ");
329
330 if (o_glbf_all) {
331 for (i = 0; i < results->N; i++) {
332 if (!is_reversed) fprintf(S0_OFILE,"%-24s %-6f %" PRId64 " %" PRId64 " %d\n", seq->name, (float) results->unsrt[i].score, results->unsrt[i].start, results->unsrt[i].stop, 0);
333 else fprintf(S0_OFILE,"%-24s %-6f %" PRId64 " %" PRId64 " %d\n", seq->name, (float) results->unsrt[i].score, (int) seq->n-results->unsrt[i].stop+1, (int) seq->n-results->unsrt[i].start+1, 1);
334 }
335 }
336
337 if (do_biasfilter) {
338 for (i = 0; i < results->N; i++) {
339 ccm_bg_FilterScore(ccm->bg, seq->dsq+results->unsrt[i].start-1, results->unsrt[i].stop-results->unsrt[i].start+1, &filtersc);
340 results->unsrt[i].score -= filtersc/eslCONST_LOG2;
341 ccm_bg_NullOne(ccm->bg, results->unsrt[i].stop-results->unsrt[i].start+1, &nullsc);
342 results->unsrt[i].score += nullsc/eslCONST_LOG2;
343 }
344 }
345 /*cm_tophits_Dump(stdout, results);*/
346
347 /* Convert hits to windows for next stage */
348 windows = ResolveMSCYK(results, 1, seq->n, cm->smx->W, s1_fcut);
349 cm_tophits_Destroy(results);
350 /*cm_tophits_Dump(stdout, windows);*/
351
352 if (o_glbf == 1) {
353 for (i = 0; i < windows->N; i++) {
354 if (!is_reversed)
355 printf("%-24s %-6f %" PRId64 " %" PRId64 " %d\n", seq->name, (float) windows->unsrt[i].score, windows->unsrt[i].start, windows->unsrt[i].stop, 0);
356 else
357 printf("%-24s %-6f %" PRId64 " %" PRId64 " %d\n", seq->name, (float) windows->unsrt[i].score, (int) seq->n-windows->unsrt[i].stop+1, (int) seq->n-windows->unsrt[i].start+1, 1);
358 }
359 }
360 else if (o_glbf_all) {
361 for (i = 0; i < windows->N; i++) {
362 if (!is_reversed)
363 fprintf(S1_OFILE,"%-24s %-6f %" PRId64 " %" PRId64 " %d\n", seq->name, (float) windows->unsrt[i].score, windows->unsrt[i].start, windows->unsrt[i].stop, 0);
364 else
365 fprintf(S1_OFILE,"%-24s %-6f %" PRId64 " %" PRId64 " %d\n", seq->name, (float) windows->unsrt[i].score, (int) seq->n-windows->unsrt[i].stop+1, (int) seq->n-windows->unsrt[i].start+1, 1);
366 }
367 }
368
369 for (i = 0; i < windows->N; i++) {
370 int64_t start, stop;
371 s2_coord->j = -1; s2_coord->d = 0;
372 /* Stage 2: medium-precision CYK */
373 sc2 = SSE_CYKFilter_epi16(ocm, seq->dsq, seq->n, 0, ocm->M-1, windows->unsrt[i].start, windows->unsrt[i].stop, TRUE, &br2, &bsc2, s2_coord);
374 stop = s2_coord->j;
375 start = stop - s2_coord->d + 1;
376
377 ScoreCorrectionNull3CompUnknown(cm->abc,cm->null,seq->dsq,start,stop,cm->null3_omega,&null3_correction);
378 p2 = esl_exp_surv((float)sc2/ocm->scale_w-null3_correction,cm->expA[EXP_CM_LC]->mu_extrap,cm->expA[EXP_CM_LC]->lambda);
379 if ((esl_opt_IsOn(go,"--s2-T") && (sc2 > s2_cutoff)) || (p2 < s2_pcut) || (sc2 > WORDMAX-10*ocm->scale_w)) {
380 if (o_glbf == 2) {
381 if (!is_reversed)
382 printf("%-24s %-6f %" PRId64 " %" PRId64 " %d\n", seq->name, (float)sc2/ocm->scale_w, start, stop, 0);
383 else
384 printf("%-24s %-6f %" PRId64 " %" PRId64 " %d\n", seq->name, (float)sc2/ocm->scale_w, (int) seq->n-stop+1, (int) seq->n-start+1, 1);
385 }
386 else if (o_glbf_all) {
387 if (!is_reversed)
388 fprintf(S2_OFILE,"%-24s %-6f %" PRId64 " %" PRId64 " %d\n", seq->name, (float)sc2/ocm->scale_w, start, stop, 0);
389 else
390 fprintf(S2_OFILE,"%-24s %-6f %" PRId64 " %" PRId64 " %d\n", seq->name, (float)sc2/ocm->scale_w, (int) seq->n-stop+1, (int) seq->n-start+1, 1);
391 }
392
393 /* Stage 3: full-precision CYK */
394 //sc3 = SSE_CYKInsideScore(cm, seq->dsq, seq->n, 0, start, stop);
395 results = cm_tophits_Create();
396 if((status = SSE_CYKScan(cm, errbuf, cm->smx, seq->dsq, windows->unsrt[i].start, windows->unsrt[i].stop, s3_cutoff, results, TRUE, NULL, &sc3)) != eslOK) cm_Fail(errbuf);;
397 /*cm_tophits_Dump(stdout, results);*/
398
399 for (hitloop = 0; hitloop < results->N; hitloop++) {
400 sc3 = results->unsrt[hitloop].score;
401 start = results->unsrt[hitloop].start;
402 stop = results->unsrt[hitloop].stop;
403 /* ScoreCorrectionNull3CompUnknown(cm->abc,cm->null,seq->dsq,start,stop,cm->null3_omega,&null3_correction); */
404 null3_correction = 0.; /* Hit resolution in CYKSCan already applies null3 */
405 p3 = esl_exp_surv((float)sc3-null3_correction,cm->expA[EXP_CM_LC]->mu_extrap,cm->expA[EXP_CM_LC]->lambda);
406 e3 = p3 * cm->expA[EXP_CM_LC]->cur_eff_dbsize;
407 if ((esl_opt_IsOn(go,"--s3-T") && (sc3 >= s3_cutoff)) || (e3 < s3_ecut)) {
408 /* Report hit */
409 if (o_glbf == 3) {
410 if (!is_reversed)
411 //printf("%-24s %-6e %" PRId64 " %" PRId64 " %d\n", seq->name, p3, start, stop, 0);
412 printf("%-24s %-6e %" PRId64 " %" PRId64 " %d\n", seq->name, e3, start, stop, 0);
413 else
414 //printf("%-24s %-6e %" PRId64 " %" PRId64 " %d\n", seq->name, p3, (int) seq->n-stop+1, (int) seq->n-start+1, 1);
415 printf("%-24s %-6e %" PRId64 " %" PRId64 " %d\n", seq->name, e3, (int) seq->n-stop+1, (int) seq->n-start+1, 1);
416 }
417 else if (o_glbf_all) {
418 if (!is_reversed)
419 fprintf(S3_OFILE,"%-24s %-6e %" PRId64 " %" PRId64 " %d\n", seq->name, e3, start, stop, 0);
420 else
421 fprintf(S3_OFILE,"%-24s %-6e %" PRId64 " %" PRId64 " %d\n", seq->name, e3, (int) seq->n-stop+1, (int) seq->n-start+1, 1);
422 }
423 }
424 }
425 cm_tophits_Destroy(results);
426 }
427 }
428
429 cm_tophits_Destroy(windows);
430
431 if (do_reverse && !is_reversed) {
432 revcomp(seq->abc, seq, seq);
433 is_reversed = 1;
434 goto PIPELINE;
435 }
436
437 esl_sq_Destroy(seq);
438 seq = esl_sq_Create();
439 }
440 esl_sq_Destroy(seq);
441
442 if (o_glbf_all) {
443 fclose(S0_OFILE);
444 fclose(S1_OFILE);
445 fclose(S2_OFILE);
446 fclose(S3_OFILE);
447 }
448
449 free(s2_coord);
450 if (ccm != NULL) cm_consensus_Free(ccm);
451 if (ocm != NULL) { cm_optimized_Free(ocm); free(ocm); }
452 FreeCM(cm);
453 esl_alphabet_Destroy(abc);
454 esl_sqfile_Close(sqfp);
455 esl_getopts_Destroy(go);
456 esl_stopwatch_Destroy(w);
457
458 return 0;
459
460 ERROR:
461 cm_Fail("memory allocation error");
462 return 0;
463 }