Debian Codegraph @

src/cmsearch.c

raw symbols SCIP
1 /* cmsearch: search CM(s) against a nucleotide sequence database,
2 * using profile HMM(s) to prefilter the database.
3 *
4 * Based on HMMER3's nhmmer.c and hmmsearch.c.
5 * EPN, Fri Sep 24 10:58:08 2010
6 */
7 #include <esl_config.h>
8 #include <p7_config.h>
9 #include "config.h"
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include "easel.h"
16 #include "esl_alphabet.h"
17 #include "esl_dmatrix.h"
18 #include "esl_getopts.h"
19 #include "esl_scorematrix.h"
20 #include "esl_sq.h"
21 #include "esl_sqio.h"
22 #include "esl_ssi.h"
23 #include "esl_stopwatch.h"
24 #include "esl_vectorops.h"
25
26 #ifdef HAVE_MPI
27 #include "mpi.h"
28 #include "esl_mpi.h"
29 #endif /*HAVE_MPI*/
30
31 #ifdef HMMER_THREADS
32 #include <unistd.h>
33 #include "esl_threads.h"
34 #include "esl_workqueue.h"
35 #endif /*HMMER_THREADS*/
36
37 #include "hmmer.h"
38
39 #include "infernal.h"
40
41 typedef struct {
42 #ifdef HMMER_THREADS
43 ESL_WORK_QUEUE *queue;
44 #endif /*HMMER_THREADS*/
45 CM_PIPELINE *pli; /* work pipeline */
46 CM_TOPHITS *th; /* top hit results */
47 CM_t *cm; /* a covariance model */
48 P7_BG *bg; /* null models */
49 P7_OPROFILE *om; /* optimized query profile HMM */
50 P7_PROFILE *gm; /* generic query profile HMM */
51 P7_PROFILE *Rgm; /* generic query profile HMM for 5' truncated hits */
52 P7_PROFILE *Lgm; /* generic query profile HMM for 3' truncated hits */
53 P7_PROFILE *Tgm; /* generic query profile HMM for 5' and 3' truncated hits */
54 P7_SCOREDATA *msvdata; /* MSV/SSV specific data structure */
55 float *p7_evparam; /* [0..CM_p7_NEVPARAM] E-value parameters */
56 float smxsize; /* max size (Mb) of allowable scan mx (only relevant if --nohmm or --max) */
57 } WORKER_INFO;
58
59 /* ** Large sets of options are InCompatible With (ICW) --max, --nohmm,
60 * --mid, --rfam, --FZ, Previously (before these were commented out) I
61 * used this defines in the 'incompatible with' field of the
62 * esl_getopts definition, but they're too long and cause a error
63 * message buffer overflow, so I now check and enforce each
64 * incompatibility within process_commandline() below, and (perhaps
65 * confusingly) the 'incompatible with' field is empty for these
66 * options which are actually incompatible with a lot of other
67 * options.
68 *
69 * #define ICWMAX "--nohmm,--mid,--default,--rfam,--FZ,--noF1,--noF2,--noF3,--noF4,--noF6,--doF1b,--noF2b,--noF3b,--noF4b,--doF5b,--F1,--F1b,--F2,--F2b,--F3,--F3b,--F4,--F4b,--F5,--F6,--ftau,--fsums,--fqdb,--fbeta,--fnonbanded,--nocykenv,--cykenvx,--tau,--sums,--nonbanded,--rt1,--rt2,--rt3,--ns,--maxtau,--anytrunc,--inttrunc,--onlytrunc,--5trunc,--3trunc,--onepass,--olonepass,--noiter"
70 * #define ICWNOHMM "--max,--mid,--default,--rfam,--FZ,--noF1,--noF2,--noF3,--noF4,--doF1b,--noF2b,--noF3b,--noF4b,--doF5b,--F1,--F1b,--F2,--F2b,--F3,--F3b,--F4,--F4b,--F5,--ftau,--fsums,--tau,--sums,--rt1,--rt2,--rt3,--ns,--maxtau,--anytrunc,--inttrunc,--onlytrunc,--5trunc,--3trunc,--onepass,--olonepass,--noiter"
71 * #define ICWMID "--max,--nohmm,--default,--rfam,--FZ,--noF1,--noF2,--noF3,--doF1b,--noF2b,--F1,--F1b,--F2,--F2b"
72 * #define ICWDF "--max,--nohmm,--mid,--rfam,--FZ"
73 * #define ICWRFAM "--max,--nohmm,--mid,--default,--FZ"
74 * #define ICWFZ "--max,--nohmm,--mid,--default,--rfam"
75 * #define ICWTRMF3 "--timeF1,--timeF2,--timeF3,--timeF4,--timeF5,--timeF6"
76 * #define ICWHMMMAX "--hmmF1,--hmmF2,--hmmF3,--hmmnobias"
77 * #define ICWFNONBANDED "--ftau,--fsums,--fqdb,--fbeta"
78 * #define ICWNONBANDED "--tau,--sums,--qdb,--beta"
79 * #define ICWOLONEPASS "--nohmm,--qdb,--fqdb,--onepass"
80 *
81 * *** The same is true for some other options combinations except
82 * instead of one option being incompatible with many others,
83 * every one in the group is incompatible with every other:
84 * #define REPOPTS "-E,-T,--cut_ga,--cut_nc,--cut_tc"
85 * #define INCOPTS "--incE,--incT,--cut_ga,--cut_nc,--cut_tc"
86 * #define THRESHOPTS "-E,-T,--incE,--incT,--cut_ga,--cut_nc,--cut_tc"
87 * #define TRUNCOPTS "-g,--notrunc,--anytrunc,--inttrunc,--onlytrunc,--5trunc,--3trunc"
88 * #define NOTRUNCOPTS "--anytrunc,--inttrunc,--onlytrunc,--5trunc,--3trunc"
89 * #define TIMINGOPTS "--timeF1,--timeF2,--timeF3,--timeF4,--timeF5,--timeF6"
90 *
91 */
92
93 #if defined (HMMER_THREADS) && defined (HAVE_MPI)
94 #define CPUOPTS "--mpi"
95 #define MPIOPTS "--cpu"
96 #else
97 #define CPUOPTS NULL
98 #define MPIOPTS NULL
99 #endif
100
101 static ESL_OPTIONS options[] = {
102 /* name type default env range toggles reqs incomp help docgroup*/
103 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 1 },
104 { "-g", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "--hmmonly", "configure CM for glocal alignment [default: local]", 1 },
105 { "-Z", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, NULL, "set search space size in *Mb* to <x> for E-value calculations", 1 },
106 { "--devhelp", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, NULL, "show list of otherwise hidden developer/expert options", 1 },
107 /* Control of output */
108 /* name type default env range toggles reqs incomp help docgroup*/
109 { "-o", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "direct output to file <f>, not stdout", 2 },
110 { "-A", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "save multiple alignment of all significant hits to file <s>", 2 },
111 { "--tblout", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "save parseable table of hits to file <s>", 2 },
112 { "--fmt", eslARG_INT, NULL, NULL, "1<=n<=3",NULL,"--tblout",NULL, "set hit table format to <n>", 2 },
113 { "--acc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "prefer accessions over names in output", 2 },
114 { "--noali", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "don't output alignments, so output is smaller", 2 },
115 { "--notextw", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, "--textw", "unlimit ASCII text output line width", 2 },
116 { "--textw", eslARG_INT, "120", NULL, "n>=120",NULL, NULL, "--notextw", "set max width of ASCII text output lines", 2 },
117 { "--verbose", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "report extra information; mainly useful for debugging", 2 },
118 { "--nomiss", eslARG_NONE, FALSE, NULL, NULL, NULL, "-A", NULL, "with -A, do not mark truncated hits with missing (~) chars", 2 },
119 /* Control of reporting thresholds */
120 /* name type default env range toggles reqs incomp help docgroup*/
121 { "-E", eslARG_REAL, "10.0", NULL, "x>0", NULL, NULL, NULL, /* see *** above */ "report sequences <= this E-value threshold in output", 3 },
122 { "-T", eslARG_REAL, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "report sequences >= this score threshold in output", 3 },
123 /* Control of inclusion (significance) thresholds */
124 /* name type default env range toggles reqs incomp help docgroup*/
125 { "--incE", eslARG_REAL, "0.01", NULL, "x>0", NULL, NULL, NULL, /* see *** above */ "consider sequences <= this E-value threshold as significant", 4 },
126 { "--incT", eslARG_REAL, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "consider sequences >= this score threshold as significant", 4 },
127 /* Model-specific thresholding for both reporting and inclusion */
128 /* name type default env range toggles reqs incomp help docgroup*/
129 { "--cut_ga", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "use CM's GA gathering cutoffs as reporting thresholds", 5 },
130 { "--cut_nc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "use CM's NC noise cutoffs as reporting thresholds", 5 },
131 { "--cut_tc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "use CM's TC trusted cutoffs as reporting thresholds", 5 },
132 /* Control of filtering mode/acceleration level */
133 /* name type default env range toggles reqs incomp help docgroup*/
134 { "--max", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see ** above */ "turn all heuristic filters off (slow)", 6 },
135 { "--nohmm", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see ** above */ "skip all HMM filter stages, use only CM (slow)", 6 },
136 { "--mid", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see ** above */ "skip first two HMM filter stages (SSV & Vit)", 6 },
137 { "--default", eslARG_NONE,"default",NULL, NULL, NULL, NULL, NULL, /* see ** above */ "default: run search space size-dependent pipeline", 6 },
138 { "--rfam", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see ** above */ "set heuristic filters at Rfam-level (fast)", 6 },
139 { "--hmmonly", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see ** above */ "use HMM only, don't use a CM at all", 6 },
140 { "--FZ", eslARG_REAL, NULL, NULL, NULL, NULL, NULL, NULL, /* see ** above */ "set filters to defaults used for a search space of size <x> Mb", 6 },
141 { "--Fmid", eslARG_REAL, "0.02", NULL, NULL, NULL,"--mid", NULL, "with --mid, set P-value threshold for HMM stages to <x>", 6 },
142 /* Other options */
143 /* name type default env range toggles reqs incomp help docgroup*/
144 { "--notrunc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "do not allow truncated hits at sequence termini", 7 },
145 { "--anytrunc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "allow full+truncated hits at terminii and anywhere within seqs", 7 },
146 { "--nonull3", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "turn off the NULL3 post hoc additional null model", 7 },
147 { "--mxsize", eslARG_REAL, NULL, NULL, "x>0.1", NULL, NULL, NULL, "set max allowed alnment mx size to <x> Mb [df: autodetermined]", 7 },
148 { "--smxsize", eslARG_REAL, "128.", NULL, "x>0.1", NULL, NULL, NULL, "set max allowed size of search DP matrices to <x> Mb", 7 },
149 { "--cyk", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use scanning CM CYK algorithm, not Inside in final stage", 7 },
150 { "--acyk", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "align hits with CYK, not optimal accuracy", 7 },
151 { "--wcx", eslARG_REAL, FALSE, NULL, "x>=1.25",NULL, NULL,"--nohmm,--qdb,--fqdb", "set W (expected max hit len) as <x> * cm->clen (model len)", 7 },
152 { "--toponly", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "only search the top strand", 7 },
153 { "--bottomonly", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "only search the bottom strand", 7 },
154 { "--tformat", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, NULL, "assert target <seqdb> is in format <s>: no autodetection", 7 },
155 { "--glist", eslARG_INFILE, NULL, NULL, NULL, NULL, NULL, NULL, "BOGUS OPTION, NEVER ALLOWED", 999 },
156 { "--clanin", eslARG_INFILE, NULL, NULL, NULL, NULL, NULL, NULL, "BOGUS OPTION, NEVER ALLOWED", 999 },
157 { "--oclan", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "BOGUS OPTION, NEVER ALLOWED", 999 },
158 { "--oskip", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "BOGUS OPTION, NEVER ALLOWED", 999 },
159 #ifdef HMMER_THREADS
160 { "--cpu", eslARG_INT, CMNCPU,"INFERNAL_NCPU","n>=0",NULL, NULL, CPUOPTS, "number of parallel CPU workers to use for multithreads", 7 },
161 #endif
162 #ifdef HAVE_MPI
163 { "--stall", eslARG_NONE, FALSE, NULL, NULL, NULL,"--mpi", NULL, "arrest after start: for debugging MPI under gdb", 7 },
164 { "--mpi", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, MPIOPTS, "run as an MPI parallel program", 7 },
165 #endif
166
167 /* All options below are developer options, only shown if --devhelp invoked */
168 /* Options for precise control of each stage of the CM filter pipeline */
169 /* name type default env range toggles reqs incomp help docgroup*/
170 { "--noF1", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "--doF1b", "skip the HMM SSV filter stage", 101 },
171 { "--noF2", eslARG_NONE, FALSE, NULL, NULL, NULL,"--noF2b", NULL, "skip the HMM Viterbi filter stage", 101 },
172 { "--noF3", eslARG_NONE, FALSE, NULL, NULL, NULL,"--noF3b", NULL, "skip the HMM Forward filter stage", 101 },
173 { "--noF4", eslARG_NONE, FALSE, NULL, NULL, NULL,"--noF4b", NULL, "skip the HMM glocal Forward filter stage", 101 },
174 { "--noF6", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "skip the CM CYK filter stage", 101 },
175 { "--doF1b", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "turn on the HMM SSV composition bias filter", 101 },
176 { "--noF2b", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "turn off the HMM Vit composition bias filter", 101 },
177 { "--noF3b", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "turn off the HMM Fwd composition bias filter", 101 },
178 { "--noF4b", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "turn off the HMM glocal Fwd composition bias filter", 101 },
179 { "--doF5b", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "turn on the HMM per-envelope composition bias filter", 101 },
180 { "--F1", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, "--noF1", "Stage 1 (SSV) threshold: promote hits w/ P <= <x>", 101 },
181 { "--F1b", eslARG_REAL, FALSE, NULL, "x>0", NULL,"--doF1b", NULL, "Stage 1 (MSV) bias threshold: promote hits w/ P <= <x>", 101 },
182 { "--F2", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, "--noF2", "Stage 2 (Vit) threshold: promote hits w/ P <= <x>", 101 },
183 { "--F2b", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, "--noF2b", "Stage 2 (Vit) bias threshold: promote hits w/ P <= <x>", 101 },
184 { "--F3", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, "--noF3", "Stage 3 (Fwd) threshold: promote hits w/ P <= <x>", 101 },
185 { "--F3b", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, "--noF3b", "Stage 3 (Fwd) bias threshold: promote hits w/ P <= <x>", 101 },
186 { "--F4", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, "--noF4", "Stage 4 (gFwd) glocal threshold: promote hits w/ P <= <x>", 101 },
187 { "--F4b", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, "--noF4b", "Stage 4 (gFwd) glocal bias thr: promote hits w/ P <= <x>", 101 },
188 { "--F5", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, NULL, "Stage 5 (env defn) threshold: promote hits w/ P <= <x>", 101 },
189 { "--F5b", eslARG_REAL, FALSE, NULL, "x>0", NULL,"--doF5b", NULL, "Stage 5 (env defn) bias thr: promote hits w/ P <= <x>", 101 },
190 { "--F6", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, "--noF6", "Stage 6 (CYK) threshold: promote hits w/ P <= <x>", 101 },
191 /* Options for precise control of each stage of the HMM-only filter pipeline */
192 /* name type default env range toggles reqs incomp help docgroup*/
193 { "--hmmmax", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see ** above */ "in HMM-only mode, turn off all filters", 102 },
194 { "--hmmF1", eslARG_REAL, "0.02", NULL, "x>0", NULL, NULL, "--nohmmonly", "in HMM-only mode, set stage 1 (SSV) P value threshold to <x>", 102 },
195 { "--hmmF2", eslARG_REAL, "1e-3", NULL, "x>0", NULL, NULL, "--nohmmonly", "in HMM-only mode, set stage 2 (Vit) P value threshold to <x>", 102 },
196 { "--hmmF3", eslARG_REAL, "1e-5", NULL, "x>0", NULL, NULL, "--nohmmonly", "in HMM-only mode, set stage 3 (Fwd) P value threshold to <x>", 102 },
197 { "--hmmnobias", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "--nohmmonly", "in HMM-only mode, turn off the bias composition filter", 102 },
198 { "--hmmnonull2", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "--nohmmonly", "in HMM-only mode, turn off the null2 score correction", 102 },
199 { "--nohmmonly", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "--hmmmax", "never run HMM-only mode, not even for models with 0 basepairs",102 },
200 /* Options for precise control of HMM envelope definition */
201 /* name type default env range toggles reqs incomp help docgroup*/
202 { "--rt1", eslARG_REAL, "0.25", NULL, NULL, NULL, NULL, "--nohmm,--max", "set domain/envelope definition rt1 parameter as <x>", 103 },
203 { "--rt2", eslARG_REAL, "0.10", NULL, NULL, NULL, NULL, "--nohmm,--max", "set domain/envelope definition rt2 parameter as <x>", 103 },
204 { "--rt3", eslARG_REAL, "0.20", NULL, NULL, NULL, NULL, "--nohmm,--max", "set domain/envelope definition rt3 parameter as <x>", 103 },
205 { "--ns", eslARG_INT, "200", NULL, NULL, NULL, NULL, "--nohmm,--max", "set number of domain/envelope tracebacks to <n>", 103 },
206 /* Options for precise control of the CYK filter round of searching */
207 /* name type default env range toggles reqs incomp help docgroup*/
208 { "--ftau", eslARG_REAL, "1e-4", NULL, "1E-18<x<1", NULL, NULL, "--fqdb", "set HMM band tail loss prob for CYK filter to <x>", 104 },
209 { "--fsums", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "--fqdb", "w/--fhbanded use posterior sums (widens bands)", 104 },
210 { "--fqdb", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use QDBs in CYK filter round, not HMM bands", 104 },
211 { "--fbeta", eslARG_REAL, "1e-7", NULL, "1E-18<x<1", NULL, NULL, NULL, "set tail loss prob for CYK filter QDB calculation to <x>", 104 },
212 { "--fnonbanded", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see ** above */ "do not use any bands for CYK filter round", 104 },
213 { "--nocykenv", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "--max", "do not redefine envelopes after stage 6 based on CYK hits", 104 },
214 { "--cykenvx", eslARG_INT, "10", NULL, "n>=1", NULL, NULL, "--max", "CYK envelope redefinition threshold multiplier, <n> * F6", 104 },
215 /* Options for precise control of the final round of searching */
216 /* name type default env range toggles reqs incomp help docgroup*/
217 { "--tau", eslARG_REAL, "5e-6", NULL, "1E-18<x<1", NULL, NULL,"--qdb", "set HMM band tail loss prob for final round to <x>", 105 },
218 { "--sums", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL,"--qdb", "w/--hbanded use posterior sums (widens bands)", 105 },
219 { "--qdb", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use QDBs (instead of HMM bands) in final Inside round", 105 },
220 { "--beta", eslARG_REAL,"1e-15", NULL, "1E-18<x<1", NULL, NULL, NULL, "set tail loss prob for final Inside QDB calculation to <x>", 105 },
221 { "--nonbanded", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see ** above */ "do not use QDBs or HMM bands in final Inside round of CM search", 105 },
222 /* Options for terminating after individual pipeline stages, currently only works for F3 */
223 { "--trmF3", eslARG_NONE, FALSE, NULL, NULL, NULL,"--noali,--hmmonly", NULL, /* see ** above */ "terminate after Stage 3 Fwd and output surviving windows", 106 },
224 /* Options for timing individual pipeline stages */
225 /* name type default env range toggles reqs incomp help docgroup*/
226 { "--timeF1", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "abort after Stage 1 SSV; for timing expts", 107 },
227 { "--timeF2", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "abort after Stage 2 Vit; for timing expts", 107 },
228 { "--timeF3", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "abort after Stage 3 Fwd; for timing expts", 107 },
229 { "--timeF4", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "abort after Stage 4 glocal Fwd; for timing expts", 107 },
230 { "--timeF5", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "abort after Stage 5 envelope def; for timing expts", 107 },
231 { "--timeF6", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "abort after Stage 6 CYK; for timing expts", 107 },
232 /* Other expert options */
233 /* name type default env range toggles reqs incomp help docgroup*/
234 { "--nogreedy", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "do not resolve hits with greedy algorithm, use optimal one", 108 },
235 { "--cp9noel", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-g", "turn off local ends in cp9 HMMs", 108 },
236 { "--cp9gloc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-g,--cp9noel", "configure cp9 HMM in glocal mode", 108 },
237 { "--null2", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "turn on null 2 biased composition HMM score corrections", 108 },
238 { "--maxtau", eslARG_REAL, "0.05", NULL,"0<x<0.5",NULL, NULL, NULL, "set max tau <x> when tightening HMM bands", 108 },
239 { "--seed", eslARG_INT, "181", NULL, "n>=0", NULL, NULL, NULL, "set RNG seed to <n> (if 0: one-time arbitrary seed)", 108 },
240 { "--block", eslARG_INT, NULL, NULL, "n>0", NULL, NULL, NULL, "BOGUS OPTION, NEVER ALLOWED", 999 },
241 { "--onepass", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL,"--nohmm,--qdb,--fqdb", "use CM only for best scoring HMM pass for full seq envelopes", 108 },
242 { "--olonepass", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see ** above */ "use CM only f. best sc'ing HMM pass f. overlapping envelopes", 108 },
243 { "--noiter", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL,"--nohmm,--qdb,--fqdb", "do not iteratively tighten bands when necessary", 108 },
244 { "--inttrunc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "allow full and truncated hits anywhere within sequences", 108 },
245 { "--onlytrunc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "allow only truncated hits, anywhere within sequences", 108 },
246 { "--5trunc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "allow truncated hits only at 5' ends of sequences", 108 },
247 { "--3trunc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, /* see *** above */ "allow truncated hits only at 3' ends of sequences", 108 },
248 #ifdef HAVE_MPI
249 /* Searching only a subset of sequences in the target database, currently requires MPI b/c SSI is required */
250 { "--sidx", eslARG_INT, NULL, NULL, "n>0", NULL,"--mpi", NULL, "start searching at sequence index <n> in target db SSI index" , 108 },
251 { "--eidx", eslARG_INT, NULL, NULL, "n>0", NULL,"--mpi", NULL, "stop searching at sequence index <n> in target db SSI index", 108 },
252 #endif
253 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
254 };
255
256 /* struct cfg_s : "Global" application configuration shared by all threads/processes
257 *
258 * This structure is passed to routines within main.c, as a means of semi-encapsulation
259 * of shared data amongst different parallel processes (threads or MPI processes).
260 */
261 struct cfg_s {
262 char *dbfile; /* target sequence database file */
263 char *cmfile; /* query HMM file */
264 int64_t Z; /* database size, in nucleotides */
265 enum cm_zsetby_e Z_setby; /* how Z was set: CM_ZSETBY_SSIINFO, CM_ZSETBY_OPTION, CM_ZSETBY_FILEINFO */
266 int do_mpi; /* TRUE if we're doing MPI parallelization */
267 int nproc; /* how many MPI processes, total */
268 int my_rank; /* who am I, in 0..nproc-1 */
269 };
270
271 static char usage[] = "[options] <cmfile> <seqdb>";
272 static char banner[] = "search CM(s) against a sequence database";
273
274 static int serial_master(ESL_GETOPTS *go, struct cfg_s *cfg);
275 static int serial_loop (WORKER_INFO *info, ESL_SQFILE *dbfp, int64_t *srcL);
276
277 #ifdef HMMER_THREADS
278 #define BLOCK_SIZE 1000
279 static int thread_loop(WORKER_INFO *info, ESL_THREADS *obj, ESL_WORK_QUEUE *queue, ESL_SQFILE *dbfp, int64_t *srcL);
280 static void pipeline_thread(void *arg);
281 #endif /*HMMER_THREADS*/
282
283 #ifdef HAVE_MPI
284 static int mpi_master (ESL_GETOPTS *go, struct cfg_s *cfg);
285 static int mpi_worker (ESL_GETOPTS *go, struct cfg_s *cfg);
286 #endif /*HAVE_MPI*/
287
288 static void process_commandline(int argc, char **argv, ESL_GETOPTS **ret_go, char **ret_cmfile, char **ret_seqfile);
289 static int output_header(FILE *ofp, const ESL_GETOPTS *go, char *cmfile, char *seqfile, int ncpus);
290
291 /* Functions to avoid code duplication for common tasks */
292 static int open_dbfile(ESL_GETOPTS *go, struct cfg_s *cfg, char *errbuf, ESL_SQFILE **ret_dbfp);
293 static int dbsize_and_seq_lengths(ESL_GETOPTS *go, struct cfg_s *cfg, ESL_SQFILE **dbfp_ptr, char *errbuf, int64_t **ret_srcL, int64_t *ret_nseqs);
294 static WORKER_INFO *create_info(const ESL_GETOPTS *go);
295 static int clone_info(ESL_GETOPTS *go, WORKER_INFO *src_info, WORKER_INFO *dest_infoA, int dest_infocnt, char *errbuf);
296 static void free_info(WORKER_INFO *info);
297 static int configure_cm(WORKER_INFO *info);
298 static int setup_hmm_filter(ESL_GETOPTS *go, WORKER_INFO *info);
299
300 #ifdef HAVE_MPI
301
302 #define MAX_BLOCK_SIZE (512*1024)
303 typedef struct mpi_block_s {
304 /* A MPI_BLOCK includes sufficient information for a worker to
305 * determine exactly where to start and stop reading its sequence
306 * block B from the file. We take advantage of SSI index
307 * information, which is required in MPI mode.
308 *
309 * A worker will start reading sequences at position <first_from> of
310 * the sequence with primary key number <first_idx> and finish
311 * reading at position <final_to> of the sequence with primary key
312 * number <final_idx>, reading complete sequences with primary keys
313 * <first_idx>+1..<final_idx>-1.
314 *
315 * Note that <first_idx> may equal <final_idx> and <first_from> and
316 * <final_to> may be interior sequence coordinates (!= 1, and != L)
317 * indicating the full block is a single subsequence of a single
318 * database sequence.
319 *
320 * The workers don't have to worry about reading overlapping chunks
321 * of the database, the master has already assured that each
322 * block is of an appropriate size and overlaps appropriately
323 * with other blocks sent to (possibly) other workers.
324 *
325 */
326 int64_t first_idx; /* first SSI primary key number in block */
327 int64_t final_idx; /* final SSI primary key number in block */
328 int64_t first_from; /* first sequence position in first sequence in block */
329 int64_t final_to; /* final sequence position in final sequence in block */
330 int64_t blockL; /* the number of total residues that exist in this block */
331 int complete; /* TRUE if this MPI_BLOCK is complete, all data should be valid */
332 } MPI_BLOCK;
333
334 typedef struct mpi_block_list_s {
335 MPI_BLOCK **blocks; /* array of MPI_BLOCKS */
336 int N; /* number of MPI_BLOCK elements in blocks */
337 int nalloc; /* number of blocks elements allocated */
338 } MPI_BLOCK_LIST;
339
340 /* workunit tags used by the MPI master/slave processes */
341 #define INFERNAL_ERROR_TAG 1
342 #define INFERNAL_BLOCK_TAG 2
343 #define INFERNAL_PIPELINE_TAG 3
344 #define INFERNAL_TOPHITS_TAG 4
345 #define INFERNAL_TERMINATING_TAG 5
346 #define INFERNAL_READY_TAG 6
347
348 static void mpi_failure(char *format, ...);
349 static int mpi_open_dbfile_ssi(ESL_GETOPTS *go, struct cfg_s *cfg, ESL_SQFILE *dbfp, char *errbuf);
350 static int mpi_dbsize_using_ssi(ESL_GETOPTS *go, struct cfg_s *cfg, ESL_SQFILE *dbfp, char *errbuf);
351 static int mpi_add_blocks(ESL_SQFILE *dbfp, ESL_SQ *sq, int64_t ncontext, char *errbuf, int64_t final_pkey_idx,
352 MPI_BLOCK_LIST *block_list, int64_t *ret_new_idx, int64_t *ret_noverlap, int64_t *ret_nseq);
353 static int mpi_inspect_next_sequence_using_ssi(ESL_SQFILE *dbfp, ESL_SQ *sq, int64_t ncontext, int64_t pkey_idx, char *errbuf,
354 MPI_BLOCK_LIST *block_list, int64_t *ret_noverlap);
355
356 static MPI_BLOCK *create_mpi_block();
357 static MPI_BLOCK_LIST *create_mpi_block_list();
358 static void free_mpi_block_list(MPI_BLOCK_LIST *list);
359 #if eslDEBUGLEVEL >= 1
360 /* useful only for debugging */
361 static void dump_mpi_block(FILE *fp, MPI_BLOCK *block);
362 static void dump_mpi_block_list(FILE *fp, MPI_BLOCK_LIST *list);
363 #endif
364
365 static int mpi_block_send(MPI_BLOCK *block, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc);
366 static int mpi_block_recv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, MPI_BLOCK **ret_block);
367 static int mpi_block_pack_size(MPI_BLOCK *block, MPI_Comm comm, int *ret_n);
368 static int mpi_block_pack(MPI_BLOCK *block, char *buf, int n, int *pos, MPI_Comm comm);
369 static int mpi_block_unpack(char *buf, int n, int *pos, MPI_Comm comm, MPI_BLOCK **ret_block);
370 #endif /*HAVE_MPI*/
371
372 int
373 main(int argc, char **argv)
374 {
375
376 int status = eslOK;
377
378 ESL_GETOPTS *go = NULL; /* command line processing */
379 struct cfg_s cfg; /* configuration data */
380
381 /* Set processor specific flags */
382 impl_Init();
383
384 /* Initialize what we can in the config structure (without knowing the alphabet yet)
385 */
386 cfg.cmfile = NULL;
387 cfg.dbfile = NULL;
388
389 cfg.do_mpi = FALSE; /* this gets reset below, if we init MPI */
390 cfg.nproc = 0; /* this gets reset below, if we init MPI */
391 cfg.my_rank = 0; /* this gets reset below, if we init MPI */
392
393 /* Initializations */
394 init_ilogsum();
395 FLogsumInit();
396 p7_FLogsumInit(); /* we're going to use table-driven Logsum() approximations at times */
397 process_commandline(argc, argv, &go, &cfg.cmfile, &cfg.dbfile);
398
399 /* Figure out who we are, and send control there:
400 * we might be an MPI master, an MPI worker, or a serial program.
401 */
402 #ifdef HAVE_MPI
403
404 #if eslDEBUGLEVEL >= 1
405 pid_t pid;
406 pid = getpid();
407 printf("#DEBUG: The process id is %d\n", pid);
408 fflush(stdout);
409 #endif
410
411 /* pause the execution of the programs execution until the user has a
412 * chance to attach with a debugger and send a signal to resume execution
413 * i.e. (gdb) signal SIGCONT
414 */
415 if (esl_opt_GetBoolean(go, "--stall")) pause();
416
417 if (esl_opt_GetBoolean(go, "--mpi"))
418 {
419 cfg.do_mpi = TRUE;
420 MPI_Init(&argc, &argv);
421 MPI_Comm_rank(MPI_COMM_WORLD, &(cfg.my_rank));
422 MPI_Comm_size(MPI_COMM_WORLD, &(cfg.nproc));
423
424 if(cfg.nproc == 1) cm_Fail("MPI mode, but only 1 processor running... (did you execute mpirun?)");
425
426 if (cfg.my_rank > 0) status = mpi_worker(go, &cfg);
427 else status = mpi_master(go, &cfg);
428
429 MPI_Finalize();
430 }
431 else
432 #endif /*HAVE_MPI*/
433 {
434 status = serial_master(go, &cfg);
435 }
436
437 esl_getopts_Destroy(go);
438
439 return status;
440 }
441
442 /* serial_master()
443 * The serial version of cmsearch.
444 * For each query CM in <cmfile> search the database for hits.
445 *
446 * A master can only return if it's successful. All errors are handled
447 * immediately and fatally with cm_Fail().
448 */
449 static int
450 serial_master(ESL_GETOPTS *go, struct cfg_s *cfg)
451 {
452 FILE *ofp = stdout; /* results output file (-o) */
453 FILE *afp = NULL; /* alignment output file (-A) */
454 FILE *tblfp = NULL; /* output stream for tabular hits (--tblout) */
455 CM_FILE *cmfp; /* open input CM file stream */
456 CM_t *cm = NULL; /* covariance model */
457 ESL_SQFILE *dbfp = NULL; /* open input sequence file */
458 ESL_ALPHABET *abc = NULL; /* digital alphabet */
459 ESL_STOPWATCH *w = NULL; /* timing one query model */
460 ESL_STOPWATCH *mw = NULL; /* timing all query models */
461 int textw = 0;
462 int64_t cm_idx = 0; /* index of CM we're currently working with */
463 int status = eslOK;
464 int qhstatus = eslOK;
465 int sstatus = eslOK;
466 int i;
467
468 int ncpus = 0;
469
470 WORKER_INFO *tinfo; /* the template info, cloned to make the worked info */
471 WORKER_INFO *info = NULL; /* the worker info */
472 int infocnt = 0; /* number of worker infos */
473
474 int64_t *srcL = NULL; /* [0..pli->nseqs-1] full length of each target sequence read */
475 int64_t nseqs_expected = 0; /* nseqs read in first pass, pli->nseqs should equal this at end of function */
476 double eZ; /* effective database size */
477 int nbps; /* number of basepairs in current CM */
478
479 #ifdef HMMER_THREADS
480 ESL_SQ_BLOCK *block = NULL;
481 ESL_THREADS *threadObj= NULL;
482 ESL_WORK_QUEUE *queue = NULL;
483 #endif
484 char errbuf[eslERRBUFSIZE];
485
486 w = esl_stopwatch_Create();
487 mw = esl_stopwatch_Create();
488 esl_stopwatch_Start(mw);
489
490 if (esl_opt_GetBoolean(go, "--notextw")) textw = 0;
491 else textw = esl_opt_GetInteger(go, "--textw");
492
493 /* Open the database file */
494 if((status = open_dbfile(go, cfg, errbuf, &dbfp)) != eslOK) esl_fatal(errbuf);
495
496 /* Open the query CM file */
497 if((status = cm_file_Open(cfg->cmfile, NULL, FALSE, &(cmfp), errbuf)) != eslOK) cm_Fail(errbuf);
498
499 /* Open the results output files */
500 if (esl_opt_IsOn(go, "-o")) { if ((ofp = fopen(esl_opt_GetString(go, "-o"), "w")) == NULL) cm_Fail("Failed to open output file %s for writing\n", esl_opt_GetString(go, "-o")); }
501 if (esl_opt_IsOn(go, "-A")) { if ((afp = fopen(esl_opt_GetString(go, "-A"), "w")) == NULL) cm_Fail("Failed to open alignment file %s for writing\n", esl_opt_GetString(go, "-A")); }
502 if (esl_opt_IsOn(go, "--tblout")) { if ((tblfp = fopen(esl_opt_GetString(go, "--tblout"), "w")) == NULL) cm_Fail("Failed to open tabular output file %s for writing\n", esl_opt_GetString(go, "--tblout")); }
503
504 #ifdef HMMER_THREADS
505 /* initialize thread data */
506 ncpus = ESL_MIN(esl_opt_GetInteger(go, "--cpu"), esl_threads_GetCPUCount());
507 if (ncpus > 0) {
508 threadObj = esl_threads_Create(&pipeline_thread);
509 queue = esl_workqueue_Create(ncpus * 2);
510 }
511 #endif
512
513 infocnt = (ncpus == 0) ? 1 : ncpus;
514 ESL_ALLOC(info, sizeof(WORKER_INFO) * infocnt);
515
516 /* <abc> is not known 'til first CM is read. Could be DNA or RNA*/
517 qhstatus = cm_file_Read(cmfp, TRUE, &abc, &cm);
518
519 if (qhstatus == eslOK) {
520 /* One-time initializations after alphabet <abc> becomes known */
521 output_header(ofp, go, cfg->cmfile, cfg->dbfile, ncpus);
522 dbfp->abc = abc;
523
524 /* Determine database size and sequence lengths (do this here and
525 * not earlier b/c it may take a little while so we make sure we
526 * get this far first) by reading the file (we purposefully don't
527 * use SSI even if it exists, as it's not significantly faster;
528 * xref: ~nawrockie/notebook/12_0221_inf_pipeline_finalize/00LOG,
529 * Feb 24). If -Z is enabled, we still need to read the sequence
530 * file to get seq lengths, we'll set Z in
531 * dbsize_and_seq_lengths() and then overwrite it based on <x>
532 * from -Z <x>.
533 */
534 if ((! esl_sqfile_IsRewindable(dbfp)) && dbfp->data.ascii.do_gzip == FALSE) {
535 cm_Fail("Target sequence file %s isn't rewindable, cmsearch needs to be able to rewind it", cfg->dbfile);
536 }
537 if((status = dbsize_and_seq_lengths(go, cfg, &dbfp, errbuf, &srcL, &nseqs_expected)) != eslOK) {
538 cm_Fail("Parse failed (sequence file %s):\n%s\n", dbfp->filename, esl_sqfile_GetErrorBuf(dbfp));
539 }
540 if(esl_opt_IsUsed(go, "-Z")) { /* -Z enabled, use that size */
541 cfg->Z = (int64_t) (esl_opt_GetReal(go, "-Z") * 1000000.);
542 cfg->Z_setby = CM_ZSETBY_OPTION;
543 }
544
545 for (i = 0; i < infocnt; ++i) {
546 info[i].pli = NULL;
547 info[i].th = NULL;
548 info[i].cm = NULL;
549 info[i].om = NULL;
550 info[i].bg = NULL;
551 ESL_ALLOC(info[i].p7_evparam, sizeof(float) * CM_p7_NEVPARAM);
552 #ifdef HMMER_THREADS
553 info[i].queue = queue;
554 #endif
555 }
556
557 #ifdef HMMER_THREADS
558 for (i = 0; i < ncpus * 2; ++i) {
559 block = esl_sq_CreateDigitalBlock(BLOCK_SIZE, abc);
560 if (block == NULL) esl_fatal("Failed to allocate sequence block");
561
562 status = esl_workqueue_Init(queue, block);
563 if (status != eslOK) esl_fatal("Failed to add block to work queue");
564 }
565 #endif
566 }
567
568 /* Outer loop: over each query CM in <cmfile>. */
569 while (qhstatus == eslOK) {
570 cm_idx++;
571 esl_stopwatch_Start(w);
572
573 /* create a new template info, and point it to the cm we just read */
574 tinfo = create_info(go);
575 tinfo->cm = cm;
576
577 /* sanity check: we better have a filter HMM */
578 if(! (tinfo->cm->flags & CMH_FP7)) cm_Fail("no filter HMM was read for CM: %s\n", tinfo->cm->name);
579
580 /* check if we have E-value stats for the CM, we require them
581 * *unless* we are going to run the pipeline in HMM-only mode.
582 * We run the pipeline in HMM-only mode if --nohmmonly is
583 * not used and -g is not used and:
584 * (a) --hmmonly used OR
585 * (b) model has 0 basepairs
586 */
587 nbps = CMCountNodetype(tinfo->cm, MATP_nd);
588 if(( esl_opt_GetBoolean(go, "--nohmmonly")) ||
589 ( esl_opt_GetBoolean(go, "-g")) ||
590 ((! esl_opt_GetBoolean(go, "--hmmonly")) && (nbps > 0))) {
591 /* we're NOT running HMM-only pipeline variant, we need CM E-value stats */
592 if(! (tinfo->cm->flags & CMH_EXPTAIL_STATS)) cm_Fail("no E-value parameters were read for CM: %s.\nYou may need to run cmcalibrate.", tinfo->cm->name);
593 }
594
595 /* seqfile may need to be rewound (multiquery mode) */
596 if (cm_idx > 1) {
597 if (! esl_sqfile_IsRewindable(dbfp))
598 esl_fatal("Target sequence file %s isn't rewindable; can't search it with multiple queries", cfg->dbfile);
599 esl_sqfile_Position(dbfp, 0);
600 }
601
602 fprintf(ofp, "Query: %s [CLEN=%d]\n", tinfo->cm->name, tinfo->cm->clen);
603 if (tinfo->cm->acc) fprintf(ofp, "Accession: %s\n", tinfo->cm->acc);
604 if (tinfo->cm->desc) fprintf(ofp, "Description: %s\n", tinfo->cm->desc);
605
606 /* configure the CM (this builds QDBs if nec) and setup HMM filters
607 * (we need to do this before clone_info()). We need a pipeline to
608 * do this only b/c we need pli->cm_config_opts.
609 */
610 tinfo->pli = cm_pipeline_Create(go, abc, tinfo->cm->clen, 100, cfg->Z, cfg->Z_setby, CM_SEARCH_SEQS); /* L_hint = 100 is just a dummy for now */
611 if((status = configure_cm(tinfo)) != eslOK) cm_Fail(tinfo->pli->errbuf);
612 if((status = setup_hmm_filter(go, tinfo)) != eslOK) cm_Fail(tinfo->pli->errbuf);
613 /* Clone all data structures in tinfo into the WORKER_INFO's in info */
614 if((status = clone_info(go, tinfo, info, infocnt, errbuf)) != eslOK) cm_Fail(errbuf);
615
616 /* Create processing pipeline and hit list */
617 for (i = 0; i < infocnt; ++i) {
618 info[i].th = cm_tophits_Create();
619 info[i].pli = cm_pipeline_Create(go, abc, tinfo->cm->clen, 100, cfg->Z, cfg->Z_setby, CM_SEARCH_SEQS); /* L_hint = 100 is just a dummy for now */
620 if((status = cm_pli_NewModel(info[i].pli, CM_NEWMODEL_CM, info[i].cm, info[i].cm->clen, info[i].cm->W, nbps,
621 info[i].om, info[i].bg, info[i].p7_evparam, info[i].om->max_length, cm_idx-1,
622 -1, NULL)) != eslOK) { /* -1 is for clan_idx, irrelevant in this context */
623 cm_Fail(info[i].pli->errbuf);
624 }
625
626 #ifdef HMMER_THREADS
627 if (ncpus > 0) esl_threads_AddThread(threadObj, &info[i]);
628 #endif
629 }
630
631 #ifdef HMMER_THREADS
632 if (ncpus > 0) sstatus = thread_loop(info, threadObj, queue, dbfp, srcL);
633 else sstatus = serial_loop(info, dbfp, srcL);
634 #else
635 sstatus = serial_loop(info, dbfp, srcL);
636 #endif
637 switch(sstatus) {
638 case eslEFORMAT:
639 esl_fatal("Parse failed (sequence file %s):\n%s\n",
640 dbfp->filename, esl_sqfile_GetErrorBuf(dbfp));
641 break;
642 case eslEOF:
643 /* do nothing */
644 break;
645 default:
646 esl_fatal("Unexpected error %d reading sequence file %s", sstatus, dbfp->filename);
647 }
648
649 /* we need to re-compute e-values before merging (when list will be sorted) */
650 for (i = 0; i < infocnt; ++i) {
651 if(info[i].pli->do_hmmonly_cur) eZ = info[i].pli->Z / (float) info[i].om->max_length;
652 else eZ = info[i].cm->expA[info[i].pli->final_cm_exp_mode]->cur_eff_dbsize;
653 cm_tophits_ComputeEvalues(info[i].th, eZ, 0);
654 }
655
656 /* merge the search results */
657 for (i = 1; i < infocnt; ++i) {
658 cm_tophits_Merge(info[0].th, info[i].th);
659 cm_pipeline_Merge(info[0].pli, info[i].pli);
660 free_info(&info[i]);
661 }
662
663 /* Sort by sequence index/position and remove duplicates */
664 cm_tophits_SortForOverlapRemoval(info[0].th);
665 if((status = cm_tophits_RemoveOrMarkOverlaps(info[0].th, FALSE, errbuf)) != eslOK) cm_Fail(errbuf);
666
667 /* Resort: by score (usually) or by position (if in special 'terminate after F3' mode) */
668 if(info[0].pli->do_trm_F3) cm_tophits_SortByPosition(info[0].th);
669 else cm_tophits_SortByEvalue(info[0].th);
670
671 /* Enforce threshold */
672 cm_tophits_Threshold(info[0].th, info[0].pli);
673
674 /* tally up total number of hits and target coverage */
675 for (i = 0; i < info->th->N; i++) {
676 if ((info[0].th->hit[i]->flags & CM_HIT_IS_REPORTED) || (info[0].th->hit[i]->flags & CM_HIT_IS_INCLUDED)) {
677 info[0].pli->acct[info[0].th->hit[i]->pass_idx].n_output++;
678 info[0].pli->acct[info[0].th->hit[i]->pass_idx].pos_output += llabs(info[0].th->hit[i]->stop - info[0].th->hit[i]->start) + 1;
679 }
680 }
681
682 /* Output */
683 if(info[0].pli->do_trm_F3) {
684 cm_tophits_F3Targets(ofp, info[0].th, info[0].pli);
685 }
686 else {
687 cm_tophits_Targets(ofp, info[0].th, info[0].pli, textw);
688 }
689 fprintf(ofp, "\n\n");
690
691 if(info[0].pli->show_alignments) {
692 if((status = cm_tophits_HitAlignments(ofp, info[0].th, info[0].pli, textw)) != eslOK) cm_Fail("Out of memory");
693 fprintf(ofp, "\n\n");
694 if(info[0].pli->be_verbose) {
695 cm_tophits_HitAlignmentStatistics(ofp, info[0].th,
696 (info[0].pli->cm_align_opts & CM_ALIGN_HBANDED),
697 (info[0].pli->cm_align_opts & CM_ALIGN_CYK),
698 info[0].pli->final_tau);
699 fprintf(ofp, "\n\n");
700 }
701 }
702
703 if (tblfp != NULL) {
704 if(info[0].pli->do_trm_F3) {
705 cm_tophits_F3TabularTargets1(tblfp, info[0].th, info[0].pli, (cm_idx == 1));
706 }
707 else {
708 if((! esl_opt_IsUsed(go, "--fmt")) || (esl_opt_GetInteger(go, "--fmt") == 1)) { /* fmt defaults to 1 */
709 cm_tophits_TabularTargets1 (tblfp, info[0].cm->name, info[0].cm->acc, info[0].th, info[0].pli, (cm_idx == 1));
710 }
711 else if(esl_opt_GetInteger(go, "--fmt") == 3) {
712 cm_tophits_TabularTargets3 (tblfp, info[0].cm->name, info[0].cm->acc, info[0].th, info[0].pli, (cm_idx == 1));
713 }
714 // --fmt 2 causes early failure
715 // --fmt 3 and --trmF3 are actually incompatible
716 }
717 fflush(tblfp);
718 }
719 esl_stopwatch_Stop(w);
720 cm_pli_Statistics(ofp, info[0].pli, w);
721
722 /* Output the results in an MSA (-A option) */
723 if (afp) {
724 ESL_MSA *msa = NULL;
725 if((status = cm_tophits_Alignment(info[0].cm, info[0].th, errbuf, /*allow_trunc=*/(! esl_opt_GetBoolean(go, "--nomiss")), &msa)) == eslOK) {
726 if(msa != NULL) {
727 if (textw > 0) esl_msafile_Write(afp, msa, eslMSAFILE_STOCKHOLM);
728 else esl_msafile_Write(afp, msa, eslMSAFILE_PFAM);
729 fprintf(ofp, "# Alignment of %d hits satisfying inclusion thresholds saved to: %s\n", msa->nseq, esl_opt_GetString(go, "-A"));
730 }
731 else {
732 fprintf(ofp, "# No hits satisfy inclusion thresholds; no alignment saved\n");
733 }
734 esl_msa_Destroy(msa);
735 }
736 else { /* status != eslOK */
737 cm_Fail(errbuf);
738 }
739 }
740 fprintf(ofp, "//\n");
741
742 free_info(tinfo);
743 free(tinfo);
744 free_info(&(info[0]));
745
746 qhstatus = cm_file_Read(cmfp, TRUE, &abc, &cm);
747 } /* end outer loop over query CMs */
748
749 switch(qhstatus) {
750 case eslEFORMAT: cm_Fail("bad file format in CM file %s\n%s", cfg->cmfile, cmfp->errbuf); break;
751 case eslEOF: /* do nothing. EOF is what we want. */ break;
752 default: cm_Fail("Unexpected error (%d) in reading CMs from %s\n%s", qhstatus, cfg->cmfile, cmfp->errbuf);
753 }
754
755 #ifdef HMMER_THREADS
756 if (ncpus > 0) {
757 esl_workqueue_Reset(queue);
758 while (esl_workqueue_Remove(queue, (void **) &block) == eslOK) {
759 esl_sq_DestroyBlock(block);
760 }
761 esl_workqueue_Destroy(queue);
762 esl_threads_Destroy(threadObj);
763 }
764 #endif
765
766 /* Terminate outputs... any last words?
767 */
768 if (tblfp) cm_tophits_TabularTail(tblfp, "cmsearch", CM_SEARCH_SEQS, cfg->cmfile, cfg->dbfile, go);
769 fprintf(ofp, "[ok]\n");
770
771 esl_stopwatch_Stop(mw);
772 if(esl_opt_GetBoolean(go, "--verbose")) esl_stopwatch_Display(stdout, mw, "# Total CPU time:");
773
774 free(info);
775 if(srcL != NULL) free(srcL);
776
777 cm_file_Close(cmfp);
778 esl_sqfile_Close(dbfp);
779 esl_alphabet_Destroy(abc);
780 if(w != NULL) esl_stopwatch_Destroy(w);
781 if(mw != NULL) esl_stopwatch_Destroy(mw);
782
783 if (ofp != stdout) fclose(ofp);
784 if (afp) fclose(afp);
785 if (tblfp) fclose(tblfp);
786
787 return eslOK;
788
789 ERROR:
790 return eslFAIL;
791 }
792
793
794 /* serial_loop():
795 *
796 * Read the sequence file one window of CM_MAX_RESIDUE_COUNT
797 * residues (or one sequence, if seqlen < CM_MAX_RESIDUE_COUNT)
798 * at a time. Search the top strand of the window, then revcomp it and
799 * search the bottom strand.
800 */
801 static int
802 serial_loop(WORKER_INFO *info, ESL_SQFILE *dbfp, int64_t *srcL)
803 {
804 int status;
805 int wstatus;
806 int prv_pli_ntophits; /* number of top hits before each cm_Pipeline() */
807 int64_t seq_idx = 0;
808 ESL_SQ *dbsq = esl_sq_CreateDigital(info->cm->abc);
809
810 wstatus = esl_sqio_ReadWindow(dbfp, info->pli->maxW, CM_MAX_RESIDUE_COUNT, dbsq);
811 seq_idx++;
812
813 while(wstatus == eslEOD) { /* this block is only necessary to chew up zero-length sequences */
814 info->pli->nseqs++;
815 esl_sq_Reuse(dbsq);
816 wstatus = esl_sqio_ReadWindow(dbfp, info->pli->maxW, CM_MAX_RESIDUE_COUNT, dbsq);
817 seq_idx++;
818 }
819
820 /*printf("SER just read seq %ld (%40s) %10ld..%10ld\n", seq_idx, dbsq->name, dbsq->start, dbsq->end);*/
821 while (wstatus == eslOK ) {
822 /* if this is the first window for this sequence, set dbsq->L */
823 if(dbsq->start == 1) dbsq->L = srcL[seq_idx-1];
824
825 cm_pli_NewSeq(info->pli, dbsq, seq_idx-1);
826
827 if (info->pli->do_top) {
828 prv_pli_ntophits = info->th->N;
829 if((status = cm_Pipeline(info->pli, info->cm->offset, info->om, info->bg, info->p7_evparam, info->msvdata, dbsq, info->th, FALSE, /* FALSE: not in reverse complement */
830 NULL, &(info->gm), &(info->Rgm), &(info->Lgm), &(info->Tgm), &(info->cm))) != eslOK) cm_Fail("cm_pipeline() failed unexpected with status code %d\n%s\n", status, info->pli->errbuf);
831 cm_pipeline_Reuse(info->pli); /* prepare for next search */
832
833 /* subtract overlapping residues from previous window */
834 if(dbsq->C > 0) cm_pli_AdjustNresForOverlaps(info->pli, dbsq->C, FALSE); /* 'FALSE': we're not on bottom strand */
835
836 /* modify hit positions to account for the position of the window in the full sequence */
837 cm_tophits_UpdateHitPositions(info->th, prv_pli_ntophits, dbsq->start, FALSE);
838 }
839
840 /* reverse complement */
841 if (info->pli->do_bot && dbsq->abc->complement != NULL) {
842 prv_pli_ntophits = info->th->N;
843 esl_sq_ReverseComplement(dbsq);
844 if((status = cm_Pipeline(info->pli, info->cm->offset, info->om, info->bg, info->p7_evparam, info->msvdata, dbsq, info->th, TRUE, /* TRUE: in reverse complement */
845 NULL, &(info->gm), &(info->Rgm), &(info->Lgm), &(info->Tgm), &(info->cm))) != eslOK) cm_Fail("cm_pipeline() failed unexpected with status code %d\n%s\n", status, info->pli->errbuf);
846 cm_pipeline_Reuse(info->pli); /* prepare for next search */
847
848 /* subtract overlapping residues from previous window */
849 if(dbsq->C > 0) cm_pli_AdjustNresForOverlaps(info->pli, dbsq->C, TRUE); /* 'TRUE': we are on bottom strand */
850
851 /* modify hit positions to account for the position of the window in the full sequence */
852 cm_tophits_UpdateHitPositions(info->th, prv_pli_ntophits, dbsq->start, TRUE);
853
854 /* Reverse complement again, to get original sequence back.
855 * This is necessary so the C overlapping context residues
856 * from previous window are as they should be (and not the
857 * reverse complement of the C residues from the other end
858 * of the sequence, which they would be if we did nothing).
859 */
860 esl_sq_ReverseComplement(dbsq);
861 }
862
863 wstatus = esl_sqio_ReadWindow(dbfp, info->pli->maxW, CM_MAX_RESIDUE_COUNT, dbsq);
864 /*printf("SER just read seq %ld (%40s) %10ld..%10ld\n", seq_idx, dbsq->name, dbsq->start, dbsq->end);*/
865 while (wstatus == eslEOD) {
866 /* no more left of this sequence ... move along to the next sequence.
867 * (this is while() instead of if() so that we will skip zero-length sequences)
868 */
869 info->pli->nseqs++;
870 esl_sq_Reuse(dbsq);
871 wstatus = esl_sqio_ReadWindow(dbfp, info->pli->maxW, CM_MAX_RESIDUE_COUNT, dbsq);
872 seq_idx++; /* because we started reading a new sequence, or reached EOF */
873 }
874 }
875
876 esl_sq_Destroy(dbsq);
877
878 return wstatus;
879 }
880
881 #ifdef HMMER_THREADS
882 static int
883 thread_loop(WORKER_INFO *info, ESL_THREADS *obj, ESL_WORK_QUEUE *queue, ESL_SQFILE *dbfp, int64_t *srcL)
884 {
885 int status = eslOK;
886 int sstatus = eslOK;
887 int eofCount = 0;
888 int i;
889 ESL_SQ *tmpsq = esl_sq_CreateDigital(info->cm->abc);
890 ESL_SQ_BLOCK *block;
891 void *newBlock;
892 int prv_block_complete = TRUE; /* in previous block, was the final sequence completed (TRUE), or probably truncated (FALSE)? */
893
894 esl_workqueue_Reset(queue);
895 esl_threads_WaitForStart(obj);
896
897 status = esl_workqueue_ReaderUpdate(queue, NULL, &newBlock);
898 if (status != eslOK) esl_fatal("Work queue reader failed");
899 ((ESL_SQ_BLOCK *)newBlock)->complete = TRUE;
900
901 /* Main loop: */
902 while (sstatus == eslOK ) {
903 block = (ESL_SQ_BLOCK *) newBlock;
904
905 /* reset block as an empty vessel, possibly keeping the first sq intact for reading in the next window */
906 for (i=0; i < block->count; i++) esl_sq_Reuse(block->list + i);
907
908 if (! prv_block_complete) {
909 esl_sq_Copy(tmpsq, block->list);
910 block->complete = FALSE; /* this lets ReadBlock know that it needs to append to a small bit of previously-read sequence */
911 block->list->C = info->pli->maxW;
912 /* Overload the ->C value, which ReadBlock uses to determine how much
913 * overlap should be retained in the ReadWindow step. */
914 }
915
916 sstatus = esl_sqio_ReadBlock(dbfp, block, CM_MAX_RESIDUE_COUNT, /*max_sequences=*/-1, /*max_init_window=*/TRUE, TRUE);
917
918 if (sstatus == eslOK) { /* we read a block */
919 if(! block->complete) {
920 /* The final sequence on the block is a probably-incomplete window of the active sequence,
921 * so capture a copy of that window to use as a template on which the next ReadWindow() call
922 * (internal to ReadBlock) will be based */
923 esl_sq_Copy(block->list + (block->count - 1) , tmpsq);
924 }
925 block->first_seqidx = info->pli->nseqs;
926 info->pli->nseqs += (block->complete) ? block->count : block->count-1; /* if there's an incomplete sequence read into the block, wait to count it until it's complete. */
927
928 /* set L parameters for all sequences in the block */
929 for(i = 0; i < block->count; i++) {
930 block->list[i].L = srcL[block->first_seqidx + i];
931 }
932 }
933
934 if (sstatus == eslEOF) {
935 if (eofCount < esl_threads_GetWorkerCount(obj)) sstatus = eslOK;
936 ++eofCount;
937 }
938 if (! block->complete ) {
939 /* The final sequence on the block was an incomplete window of the active sequence,
940 * so our next read will need a copy of it to correctly deal with overlapping
941 * regions. We capture a copy of the sequence here before sending it off to the
942 * pipeline to avoid odd race conditions that can occur otherwise.
943 *
944 * This fix is new in v1.1.5 (2023) but originates from analogous code in
945 * hmmer/src/nhmmer.c commit b3c27ff (2013)
946 */
947 esl_sq_Copy(block->list + (block->count - 1) , tmpsq);
948 }
949 /* Capture "complete" status prior to placing current block into the work
950 * queue, to avoid appearance of a race condition. With only one reader
951 * thread, there isn't really a race risk, since "complete" is only set
952 * during the esl_sqio_ReadBlock() function call earlier in this loop
953 * (i.e. "complete" isn't altered by the worker threads).
954 */
955 prv_block_complete = block->complete;
956
957 if (sstatus == eslOK) {
958 status = esl_workqueue_ReaderUpdate(queue, block, &newBlock);
959 if (status != eslOK) esl_fatal("Work queue reader failed");
960 }
961
962 /* newBlock needs all this information so the next ReadBlock call will know what to do */
963 ((ESL_SQ_BLOCK *)newBlock)->complete = prv_block_complete;
964 if (! prv_block_complete) {
965 /* Push the captured copy of the previously-read sequence into the new block,
966 * in preparation for ReadWindow (we've now copied this seq twice, to avoid the
967 * race condition.
968 */
969 esl_sq_Copy(tmpsq, ((ESL_SQ_BLOCK *)newBlock)->list);
970 ((ESL_SQ_BLOCK *)newBlock)->list->C = info->pli->maxW;
971 }
972 }
973
974 status = esl_workqueue_ReaderUpdate(queue, block, NULL);
975 if (status != eslOK) esl_fatal("Work queue reader failed");
976
977 if (sstatus == eslEOF) {
978 /* wait for all the threads to complete */
979 esl_threads_WaitForFinish(obj);
980 esl_workqueue_Complete(queue);
981 }
982
983 if(tmpsq != NULL) esl_sq_Destroy(tmpsq);
984
985 return sstatus;
986 }
987
988 /* pipeline_thread()
989 *
990 * Receive a block of sequence(s) from the master and run the search
991 * pipeline on its top strand, then reverse complement it and run the
992 * search pipeline on its bottom strand.
993 */
994
995 static void
996 pipeline_thread(void *arg)
997 {
998 int i;
999 int status;
1000 int workeridx;
1001 WORKER_INFO *info;
1002 ESL_THREADS *obj;
1003
1004 ESL_SQ_BLOCK *block = NULL;
1005 void *newBlock;
1006 int prv_pli_ntophits; /* number of top hits before each cm_Pipeline() */
1007
1008 #ifdef HAVE_FLUSH_ZERO_MODE
1009 /* In order to avoid the performance penalty dealing with sub-normal
1010 * values in the floating point calculations, set the processor flag
1011 * so sub-normals are "flushed" immediately to zero.
1012 * On OS X, need to reset this flag for each thread
1013 * (see TW notes 05/08/10 for details)
1014 */
1015 _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
1016 #endif
1017
1018 obj = (ESL_THREADS *) arg;
1019 esl_threads_Started(obj, &workeridx);
1020
1021 info = (WORKER_INFO *) esl_threads_GetData(obj, workeridx);
1022
1023 status = esl_workqueue_WorkerUpdate(info->queue, NULL, &newBlock);
1024 if (status != eslOK) esl_fatal("Work queue worker failed");
1025
1026 /* loop until all blocks have been processed */
1027 block = (ESL_SQ_BLOCK *) newBlock;
1028 while (block->count > 0) {
1029 /* Main loop: */
1030 for (i = 0; i < block->count; ++i) {
1031 ESL_SQ *dbsq = block->list + i;
1032
1033 cm_pli_NewSeq(info->pli, dbsq, block->first_seqidx + i);
1034
1035 if (info->pli->do_top) {
1036 prv_pli_ntophits = info->th->N;
1037 if((status = cm_Pipeline(info->pli, info->cm->offset, info->om, info->bg, info->p7_evparam, info->msvdata, dbsq, info->th, FALSE, /* FALSE: not in reverse complement */
1038 NULL, &(info->gm), &(info->Rgm), &(info->Lgm), &(info->Tgm), &(info->cm))) != eslOK) cm_Fail("cm_pipeline() failed unexpected with status code %d\n%s\n", status, info->pli->errbuf);
1039 cm_pipeline_Reuse(info->pli); /* prepare for next search */
1040
1041 /* subtract overlapping residues from previous window */
1042 if(dbsq->C > 0) cm_pli_AdjustNresForOverlaps(info->pli, dbsq->C, FALSE); /* 'FALSE': we're not on bottom strand */
1043
1044 /* modify hit positions to account for the position of the window in the full sequence */
1045 cm_tophits_UpdateHitPositions(info->th, prv_pli_ntophits, dbsq->start, FALSE);
1046 }
1047
1048 /* reverse complement */
1049 if (info->pli->do_bot && dbsq->abc->complement != NULL) {
1050 prv_pli_ntophits = info->th->N;
1051 esl_sq_ReverseComplement(dbsq);
1052 if((status = cm_Pipeline(info->pli, info->cm->offset, info->om, info->bg, info->p7_evparam, info->msvdata, dbsq, info->th, TRUE, /* TRUE: in reverse complement */
1053 NULL, &(info->gm), &(info->Rgm), &(info->Lgm), &(info->Tgm), &(info->cm))) != eslOK) cm_Fail("cm_pipeline() failed unexpected with status code %d\n%s\n", status, info->pli->errbuf);
1054 cm_pipeline_Reuse(info->pli); /* prepare for next search */
1055
1056 /* subtract overlapping residues from previous window */
1057 if(dbsq->C > 0) cm_pli_AdjustNresForOverlaps(info->pli, dbsq->C, TRUE); /* 'TRUE': we are on the bottom strand */
1058
1059 /* modify hit positions to account for the position of the window in the full sequence */
1060 cm_tophits_UpdateHitPositions(info->th, prv_pli_ntophits, dbsq->start, TRUE);
1061
1062 /* Reverse complement again, to get original sequence back.
1063 * This is necessary so the C overlapping context residues
1064 * from previous window are as they should be (and not the
1065 * reverse complement of the C residues from the other end
1066 * of the sequence, which they would be if we did nothing). */
1067 esl_sq_ReverseComplement(dbsq);
1068 }
1069 }
1070
1071 status = esl_workqueue_WorkerUpdate(info->queue, block, &newBlock);
1072 if (status != eslOK) esl_fatal("Work queue worker failed");
1073
1074 block = (ESL_SQ_BLOCK *) newBlock;
1075 }
1076
1077 status = esl_workqueue_WorkerUpdate(info->queue, block, NULL);
1078 if (status != eslOK) esl_fatal("Work queue worker failed");
1079
1080 esl_threads_Finished(obj, workeridx);
1081 return;
1082 }
1083 #endif /* HMMER_THREADS */
1084
1085 #if HAVE_MPI
1086 /* mpi_master()
1087 * The MPI version of cmsearch.
1088 * Follows standard pattern for a master/worker load-balanced MPI program (J1/78-79).
1089 *
1090 * A master can only return if it's successful.
1091 * Errors in an MPI master come in two classes: recoverable and nonrecoverable.
1092 *
1093 * Recoverable errors include all worker-side errors, and any
1094 * master-side error that do not affect MPI communication. Error
1095 * messages from recoverable messages are delayed until we've cleanly
1096 * shut down the workers.
1097 *
1098 * Unrecoverable errors are master-side errors that may affect MPI
1099 * communication, meaning we cannot count on being able to reach the
1100 * workers and shut them down. Unrecoverable errors result in immediate
1101 * cm_Fail()'s, which will cause MPI to shut down the worker processes
1102 * uncleanly.
1103 */
1104 static int
1105 mpi_master(ESL_GETOPTS *go, struct cfg_s *cfg)
1106 {
1107 FILE *ofp = stdout; /* results output file (-o) */
1108 FILE *afp = NULL; /* alignment output file (-A) */
1109 FILE *tblfp = NULL; /* output stream for tabular per-seq (--tblout) */
1110
1111 CM_FILE *cmfp; /* open input CM file stream */
1112 ESL_SQFILE *dbfp = NULL; /* open input sequence file */
1113 ESL_SQ *dbsq = NULL; /* one target sequence (digital) */
1114 ESL_ALPHABET *abc = NULL; /* digital alphabet */
1115 ESL_STOPWATCH *w = NULL; /* timing one query model */
1116 ESL_STOPWATCH *mw = NULL; /* timing all query models */
1117 int textw = 0;
1118 int64_t cm_idx = 0; /* index of CM we're currently working with */
1119 int status = eslOK;
1120 int hstatus = eslOK;
1121 int sstatus = eslOK;
1122 int dest;
1123
1124 WORKER_INFO *info = NULL; /* contains CM, HMMs, p7 profiles, etc */
1125
1126 int i;
1127
1128 char *mpi_buf = NULL; /* buffer used to pack/unpack structures */
1129 int mpi_size = 0; /* size of the allocated buffer */
1130 MPI_BLOCK_LIST *block_list = NULL;
1131
1132 int size;
1133 MPI_Status mpistatus;
1134 char errbuf[eslERRBUFSIZE];
1135 int64_t pkey_idx; /* sequence index, in SSI */
1136 int64_t final_pkey_idx; /* final sequence index to search, in SSI */
1137 MPI_BLOCK *cur_block = NULL; /* current block of sequence(s) */
1138 int64_t nseq = 0; /* number of sequences in one block */
1139 int64_t tot_nseq = 0; /* number of sequences in all blocks for one CM */
1140 int64_t noverlap = 0; /* number of overlapping residues in one block */
1141 int64_t tot_noverlap = 0; /* number of overlapping residues in all blocks for one CM */
1142 int nbps; /* number of basepairs in current CM */
1143
1144 w = esl_stopwatch_Create();
1145 mw = esl_stopwatch_Create();
1146 esl_stopwatch_Start(mw);
1147
1148 if (esl_opt_GetBoolean(go, "--notextw")) textw = 0;
1149 else textw = esl_opt_GetInteger(go, "--textw");
1150
1151 /* Open the database file */
1152 if((status = open_dbfile (go, cfg, errbuf, &dbfp)) != eslOK) mpi_failure(errbuf);
1153
1154 /* Open the query CM file */
1155 if((status = cm_file_Open(cfg->cmfile, NULL, FALSE, &(cmfp), errbuf)) != eslOK) mpi_failure(errbuf);
1156
1157 /* Open the results output files */
1158 if (esl_opt_IsOn(go, "-o") && (ofp = fopen(esl_opt_GetString(go, "-o"), "w")) == NULL)
1159 mpi_failure("Failed to open output file %s for writing\n", esl_opt_GetString(go, "-o"));
1160
1161 if (esl_opt_IsOn(go, "-A")) {
1162 if ((afp = fopen(esl_opt_GetString(go, "-A"), "w")) == NULL)
1163 mpi_failure("Failed to open alignment file %s for writing\n", esl_opt_GetString(go, "-A"));
1164 }
1165
1166 if (esl_opt_IsOn(go, "--tblout") && (tblfp = fopen(esl_opt_GetString(go, "--tblout"), "w")) == NULL)
1167 mpi_failure("Failed to open tabular per-seq output file %s for writing\n", esl_opt_GetString(go, "--tblout"));
1168
1169 /* allocate and initialize <info> which will hold the CMs, HMMs, etc. */
1170 if((info = create_info(go)) == NULL) mpi_failure("Out of memory");
1171
1172 /* <abc> is not known 'til first CM is read. */
1173 hstatus = cm_file_Read(cmfp, TRUE, &abc, &(info->cm));
1174 /*printf("read cm master\n");*/
1175
1176 if (hstatus == eslOK) {
1177 /* Determine db size by reading SSI index. This is the slowest
1178 * initialization step, so it's done last, after we know all other
1179 * steps have passed. This way we can exit quickly earlier if we
1180 * had a quickly detectable problem.
1181 *
1182 * MPI requires SSI indexing, we'll use it to determine db size
1183 * unless -Z is set.
1184 */
1185 if((status = mpi_open_dbfile_ssi(go, cfg, dbfp, errbuf)) != eslOK) mpi_failure(errbuf);
1186 if(esl_opt_IsUsed(go, "-Z")) {
1187 cfg->Z = (int64_t) (esl_opt_GetReal(go, "-Z") * 1000000.);
1188 cfg->Z_setby = CM_ZSETBY_OPTION;
1189 }
1190 else {
1191 esl_stopwatch_Start(w);
1192 if((status = mpi_dbsize_using_ssi(go, cfg, dbfp, errbuf)) != eslOK) mpi_failure(errbuf);
1193 esl_stopwatch_Stop(w);
1194 if(esl_opt_GetBoolean(go, "--verbose")) esl_stopwatch_Display(ofp, w, "# MPI Determining Z CPU time: ");
1195 }
1196 /* Broadcast the database size to all workers */
1197 MPI_Bcast(&(cfg->Z), 1, MPI_LONG_LONG_INT, 0, MPI_COMM_WORLD);
1198 /*printf("MPIM cfg->Z: %" PRId64 " residues\n", cfg->Z);*/
1199
1200 /* One-time initializations after alphabet <abc> becomes known */
1201 output_header(ofp, go, cfg->cmfile, cfg->dbfile, cfg->nproc);
1202 dbsq = esl_sq_CreateDigital(abc);
1203 }
1204
1205 /* Outer loop: over each query CM in <cmfile>. */
1206 while (hstatus == eslOK) {
1207 cm_idx++;
1208 esl_stopwatch_Start(w);
1209
1210 /* Sanity check: we better have a filter HMM */
1211 if(! (info->cm->flags & CMH_FP7)) mpi_failure("no filter HMM was read for CM: %s\n", info->cm->name);
1212
1213 /* check if we have E-value stats for the CM, we require them
1214 * *unless* we are going to run the pipeline in HMM-only mode.
1215 * We run the pipeline in HMM-only mode if --nohmmonly is
1216 * not used and -g is not used and:
1217 * (a) --hmmonly used OR
1218 * (b) model has 0 basepairs
1219 */
1220 nbps = CMCountNodetype(info->cm, MATP_nd);
1221 if(( esl_opt_GetBoolean(go, "--nohmmonly")) ||
1222 ( esl_opt_GetBoolean(go, "-g")) ||
1223 ((! esl_opt_GetBoolean(go, "--hmmonly")) && (nbps > 0))) {
1224 /* we're NOT running HMM-only pipeline variant, we need CM E-value stats */
1225 if(! (info->cm->flags & CMH_EXPTAIL_STATS)) mpi_failure("no E-value parameters were read for CM: %s\n", info->cm->name);
1226 }
1227
1228 fprintf(ofp, "Query: %s [CLEN=%d]\n", info->cm->name, info->cm->clen);
1229 if (info->cm->acc) fprintf(ofp, "Accession: %s\n", info->cm->acc);
1230 if (info->cm->desc) fprintf(ofp, "Description: %s\n", info->cm->desc);
1231
1232 /* Create processing pipeline and hit list */
1233 info->th = cm_tophits_Create();
1234 info->pli = cm_pipeline_Create(go, abc, info->cm->clen, 100, cfg->Z, cfg->Z_setby, CM_SEARCH_SEQS); /* L_hint = 100 is just a dummy for now */
1235
1236 /* Configure the CM and setup the HMM filter */
1237 if((status = configure_cm(info)) != eslOK) mpi_failure(info->pli->errbuf);
1238 if((status = setup_hmm_filter(go, info)) != eslOK) mpi_failure(info->pli->errbuf);
1239 if((status = cm_pli_NewModel(info->pli, CM_NEWMODEL_CM, info->cm, info->cm->clen, info->cm->W, nbps,
1240 info->om, info->bg, info->p7_evparam, info->om->max_length, cm_idx-1,
1241 -1, NULL)) != eslOK) { /* -1 is for clan_idx, irrelevant in this context */
1242 mpi_failure(info->pli->errbuf);
1243 }
1244
1245 /* Create block_list and add an empty block to it */
1246 block_list = create_mpi_block_list();
1247 block_list->blocks[0] = create_mpi_block();
1248 block_list->N = 1;
1249
1250 /* Initialize for main loop */
1251 pkey_idx = 0;
1252 final_pkey_idx = dbfp->data.ascii.ssi->nprimary - 1;
1253 sstatus = eslOK;
1254 tot_noverlap = noverlap = 0;
1255 tot_nseq = nseq = 0;
1256 #ifdef HAVE_MPI
1257 /* process --sidx and --eidx, if nec */
1258 if(esl_opt_IsUsed(go, "--sidx")) { /* start searching at sequence index <n> from --sidx <n> */
1259 pkey_idx = esl_opt_GetInteger(go, "--sidx") - 1;
1260 if(pkey_idx >= dbfp->data.ascii.ssi->nprimary) {
1261 mpi_failure("--sidx %d is invalid because only %d sequences exist in the target db", pkey_idx+1, dbfp->data.ascii.ssi->nprimary);
1262 }
1263 }
1264 if(esl_opt_IsUsed(go, "--eidx")) { /* start searching at sequence index <n> from --eidx <n> */
1265 final_pkey_idx = esl_opt_GetInteger(go, "--eidx") - 1;
1266 if(final_pkey_idx >= dbfp->data.ascii.ssi->nprimary) {
1267 mpi_failure("--eidx %d is invalid because only %d sequences exist in the target db", final_pkey_idx+1, dbfp->data.ascii.ssi->nprimary);
1268 }
1269 if(final_pkey_idx < pkey_idx) {
1270 mpi_failure("with --sidx <n1> --eidx <n2>, <n2> must be >= <n1>");
1271 }
1272 }
1273 /*printf("searching seqs %ld to %ld\n", pkey_idx, final_pkey_idx);*/
1274 #endif
1275 /* Main loop: */
1276 while((pkey_idx <= final_pkey_idx) &&
1277 ((sstatus = mpi_add_blocks(dbfp, dbsq, info->pli->maxW, errbuf, final_pkey_idx, block_list, &pkey_idx, &noverlap, &nseq)) == eslOK))
1278 {
1279 tot_noverlap += noverlap;
1280 tot_nseq += nseq;
1281
1282 cur_block = block_list->blocks[0];
1283
1284 while(cur_block != NULL && cur_block->complete) {
1285 /* cur_block points to a valid, complete block, send it to a worker */
1286 if (MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &mpistatus) != 0)
1287 mpi_failure("MPI error %d receiving message from %d\n", mpistatus.MPI_SOURCE);
1288
1289 MPI_Get_count(&mpistatus, MPI_PACKED, &size);
1290 if (mpi_buf == NULL || size > mpi_size) {
1291 void *tmp;
1292 ESL_RALLOC(mpi_buf, tmp, sizeof(char) * size);
1293 mpi_size = size;
1294 }
1295
1296 dest = mpistatus.MPI_SOURCE;
1297 MPI_Recv(mpi_buf, size, MPI_PACKED, dest, mpistatus.MPI_TAG, MPI_COMM_WORLD, &mpistatus);
1298
1299 if (mpistatus.MPI_TAG == INFERNAL_ERROR_TAG)
1300 mpi_failure("MPI client %d raised error:\n%s\n", dest, mpi_buf);
1301 if (mpistatus.MPI_TAG != INFERNAL_READY_TAG)
1302 mpi_failure("Unexpected tag %d from %d\n", mpistatus.MPI_TAG, dest);
1303
1304 mpi_block_send(cur_block, dest, INFERNAL_BLOCK_TAG, MPI_COMM_WORLD, &mpi_buf, &mpi_size);
1305
1306 /* Free the block we just sent, and remove it from block_list
1307 * by swapping pointers and decrementing N. Then update cur_block. */
1308 free(cur_block);
1309 for(i = 0; i < (block_list->N-1); i++) {
1310 block_list->blocks[i] = block_list->blocks[i+1];
1311 }
1312 block_list->blocks[(block_list->N-1)] = NULL;
1313 block_list->N--;
1314 cur_block = block_list->blocks[0];
1315 }
1316 }
1317 if(sstatus != eslOK) mpi_failure(errbuf);
1318
1319 /* create an empty block to send to workers */
1320 cur_block = create_mpi_block();
1321 cur_block->complete = TRUE;
1322
1323 /* wait for all workers to finish up their work blocks */
1324 for (i = 1; i < cfg->nproc; ++i) {
1325 if (MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &mpistatus) != 0)
1326 mpi_failure("MPI error %d receiving message from %d\n", mpistatus.MPI_SOURCE);
1327
1328 MPI_Get_count(&mpistatus, MPI_PACKED, &size);
1329 if (mpi_buf == NULL || size > mpi_size) {
1330 void *tmp;
1331 ESL_RALLOC(mpi_buf, tmp, sizeof(char) * size);
1332 mpi_size = size;
1333 }
1334
1335 dest = mpistatus.MPI_SOURCE;
1336 MPI_Recv(mpi_buf, size, MPI_PACKED, dest, mpistatus.MPI_TAG, MPI_COMM_WORLD, &mpistatus);
1337
1338 if (mpistatus.MPI_TAG == INFERNAL_ERROR_TAG)
1339 mpi_failure("MPI client %d raised error:\n%s\n", dest, mpi_buf);
1340 if (mpistatus.MPI_TAG != INFERNAL_READY_TAG)
1341 mpi_failure("Unexpected tag %d from %d\n", mpistatus.MPI_TAG, dest);
1342 }
1343
1344 /* merge the results of the search results */
1345 for (dest = 1; dest < cfg->nproc; ++dest) {
1346 CM_PIPELINE *mpi_pli = NULL;
1347 CM_TOPHITS *mpi_th = NULL;
1348
1349 /* send an empty block to signal the worker they are done */
1350 mpi_block_send(cur_block, dest, INFERNAL_BLOCK_TAG, MPI_COMM_WORLD, &mpi_buf, &mpi_size);
1351
1352 /* wait for the results */
1353 if ((status = cm_tophits_MPIRecv(dest, INFERNAL_TOPHITS_TAG, MPI_COMM_WORLD, &mpi_buf, &mpi_size, &mpi_th)) != eslOK)
1354 mpi_failure("Unexpected error %d receiving tophits from %d", status, dest);
1355
1356 if ((status = cm_pipeline_MPIRecv(dest, INFERNAL_PIPELINE_TAG, MPI_COMM_WORLD, &mpi_buf, &mpi_size, go, &mpi_pli)) != eslOK)
1357 mpi_failure("Unexpected error %d receiving pipeline from %d", status, dest);
1358
1359 /*printf("RECEIVED TOPHITS (%ld hits) FROM %d\n", mpi_th->N, dest);*/
1360 cm_tophits_Merge(info->th, mpi_th);
1361 cm_pipeline_Merge(info->pli, mpi_pli);
1362
1363 cm_pipeline_Destroy(mpi_pli, NULL);
1364 cm_tophits_Destroy(mpi_th);
1365 }
1366 free(cur_block); cur_block = NULL;
1367
1368 /* Set number of seqs, and subtract number of overlapping residues searched from total */
1369 info->pli->nseqs = tot_nseq;
1370 if(info->pli->do_top && tot_noverlap > 0) cm_pli_AdjustNresForOverlaps(info->pli, tot_noverlap, FALSE); /* 'FALSE': we're not on bottom strand */
1371 if(info->pli->do_bot && tot_noverlap > 0) cm_pli_AdjustNresForOverlaps(info->pli, tot_noverlap, TRUE); /* 'TRUE': we are on bottom strand */
1372
1373 /* Sort by sequence index/position and remove duplicates */
1374 cm_tophits_SortForOverlapRemoval(info->th);
1375 if((status = cm_tophits_RemoveOrMarkOverlaps(info->th, FALSE, errbuf)) != eslOK) mpi_failure(errbuf);
1376
1377 /* Resort: by score (usually) or by position (if in special 'terminate after F3' mode) */
1378 if(info->pli->do_trm_F3) cm_tophits_SortByPosition(info->th);
1379 else cm_tophits_SortByEvalue(info[0].th);
1380
1381 /* Enforce threshold */
1382 cm_tophits_Threshold(info[0].th, info[0].pli);
1383
1384 /* tally up total number of hits and target coverage */
1385 for (i = 0; i < info->th->N; i++) {
1386 if ((info->th->hit[i]->flags & CM_HIT_IS_REPORTED) || (info->th->hit[i]->flags & CM_HIT_IS_INCLUDED)) {
1387 info->pli->acct[info->th->hit[i]->pass_idx].n_output++;
1388 info->pli->acct[info->th->hit[i]->pass_idx].pos_output += llabs(info->th->hit[i]->stop - info->th->hit[i]->start) + 1;
1389 }
1390 }
1391
1392 if(info->pli->do_trm_F3) {
1393 cm_tophits_F3Targets(ofp, info->th, info->pli);
1394 }
1395 else {
1396 cm_tophits_Targets(ofp, info->th, info->pli, textw);
1397 }
1398 fprintf(ofp, "\n\n");
1399 if(info->pli->show_alignments) {
1400 if((status = cm_tophits_HitAlignments(ofp, info->th, info->pli, textw)) != eslOK) mpi_failure("Out of memory");
1401 fprintf(ofp, "\n\n");
1402 if(info->pli->be_verbose) {
1403 cm_tophits_HitAlignmentStatistics(ofp, info->th,
1404 (info->pli->cm_align_opts & CM_ALIGN_HBANDED),
1405 (info->pli->cm_align_opts & CM_ALIGN_CYK),
1406 info->pli->final_tau);
1407 fprintf(ofp, "\n\n");
1408 }
1409 }
1410 if (tblfp != NULL) {
1411 if(info->pli->do_trm_F3) {
1412 cm_tophits_F3TabularTargets1(tblfp, info->th, info->pli, (cm_idx == 1));
1413 }
1414 else {
1415 if((! esl_opt_IsUsed(go, "--fmt")) || (esl_opt_GetInteger(go, "--fmt") == 1)) { /* fmt defaults to 1 */
1416 cm_tophits_TabularTargets1 (tblfp, info->cm->name, info->cm->acc, info->th, info->pli, (cm_idx == 1));
1417 }
1418 else if(esl_opt_GetInteger(go, "--fmt") == 3) {
1419 cm_tophits_TabularTargets3 (tblfp, info->cm->name, info->cm->acc, info->th, info->pli, (cm_idx == 1));
1420 }
1421 // --fmt 2 causes early failure
1422 // --fmt 3 and --trmF3 are actually incompatible
1423 }
1424 fflush(tblfp);
1425 }
1426 esl_stopwatch_Stop(w);
1427 cm_pli_Statistics(ofp, info->pli, w);
1428 fflush(ofp);
1429
1430 /* Output the results in an MSA (-A option) */
1431 if (afp) {
1432 ESL_MSA *msa = NULL;
1433 if((status = cm_tophits_Alignment(info->cm, info->th, errbuf, /*allow_trunc=*/(! esl_opt_GetBoolean(go, "--nomiss")), &msa)) == eslOK) {
1434 if(msa != NULL) {
1435 if (textw > 0) esl_msafile_Write(afp, msa, eslMSAFILE_STOCKHOLM);
1436 else esl_msafile_Write(afp, msa, eslMSAFILE_PFAM);
1437 fprintf(ofp, "# Alignment of %d hits satisfying inclusion thresholds saved to: %s\n", msa->nseq, esl_opt_GetString(go, "-A"));
1438 }
1439 else {
1440 fprintf(ofp, "# No hits satisfy inclusion thresholds; no alignment saved\n");
1441 }
1442 esl_msa_Destroy(msa);
1443 }
1444 else { /* status != eslOK */
1445 mpi_failure(errbuf);
1446 }
1447 }
1448 fprintf(ofp, "//\n");
1449
1450 free_info(info);
1451 free(info);
1452 free_mpi_block_list(block_list);
1453 block_list = NULL;
1454
1455 if((info = create_info(go)) == NULL) mpi_failure("Out of memory"); /* for the next model */
1456
1457 hstatus = cm_file_Read(cmfp, TRUE, &abc, &(info->cm));
1458 if(hstatus != eslOK) { free_info(info); free(info); }
1459 } /* end outer loop over query CMs */
1460
1461 switch(hstatus) {
1462 case eslEFORMAT: mpi_failure("bad file format in CM file %s\n%s", cfg->cmfile, cmfp->errbuf); break;
1463 case eslEOF: /* do nothing. EOF is what we want. */ break;
1464 default: mpi_failure("Unexpected error (%d) in reading CMs from %s\n%s", hstatus, cfg->cmfile, cmfp->errbuf);
1465 }
1466
1467 /* monitor all the workers to make sure they have ended */
1468 for (i = 1; i < cfg->nproc; ++i)
1469 {
1470 if (MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &mpistatus) != 0)
1471 mpi_failure("MPI error %d receiving message from %d\n", mpistatus.MPI_SOURCE);
1472
1473 MPI_Get_count(&mpistatus, MPI_PACKED, &size);
1474 if (mpi_buf == NULL || size > mpi_size) {
1475 void *tmp;
1476 ESL_RALLOC(mpi_buf, tmp, sizeof(char) * size);
1477 mpi_size = size;
1478 }
1479
1480 dest = mpistatus.MPI_SOURCE;
1481 MPI_Recv(mpi_buf, size, MPI_PACKED, dest, mpistatus.MPI_TAG, MPI_COMM_WORLD, &mpistatus);
1482
1483 if (mpistatus.MPI_TAG == INFERNAL_ERROR_TAG)
1484 mpi_failure("MPI client %d raised error:\n%s\n", dest, mpi_buf);
1485 if (mpistatus.MPI_TAG != INFERNAL_TERMINATING_TAG)
1486 mpi_failure("Unexpected tag %d from %d\n", mpistatus.MPI_TAG, dest);
1487 }
1488
1489 /* Terminate outputs... any last words?
1490 */
1491 if (tblfp) cm_tophits_TabularTail(tblfp, "cmsearch", CM_SEARCH_SEQS, cfg->cmfile, cfg->dbfile, go);
1492 fprintf(ofp, "[ok]\n");
1493
1494 esl_stopwatch_Stop(mw);
1495 if(esl_opt_GetBoolean(go, "--verbose")) esl_stopwatch_Display(stdout, mw, "# Total CPU time:");
1496
1497 /* Cleanup - prepare for exit
1498 */
1499 free(block_list);
1500 if (mpi_buf != NULL) free(mpi_buf);
1501
1502 cm_file_Close(cmfp);
1503 esl_sqfile_Close(dbfp);
1504 esl_alphabet_Destroy(abc);
1505 esl_sq_Destroy(dbsq);
1506 if(w != NULL) esl_stopwatch_Destroy(w);
1507 if(mw != NULL) esl_stopwatch_Destroy(mw);
1508
1509 if (ofp != stdout) fclose(ofp);
1510 if (afp) fclose(afp);
1511 if (tblfp) fclose(tblfp);
1512
1513 return eslOK;
1514
1515 ERROR:
1516 return eslEMEM;
1517 }
1518
1519 /* mpi_worker()
1520 *
1521 * Receive information from the master on where to start reading from
1522 * the sequence file and how much to read. Read the requested sequence
1523 * and run the search pipeline on it, then reverse complement it and
1524 * rerun the pipeline on the bottom strand.
1525 */
1526 static int
1527 mpi_worker(ESL_GETOPTS *go, struct cfg_s *cfg)
1528 {
1529 ESL_ALPHABET *abc = NULL; /* digital alphabet */
1530 CM_FILE *cmfp; /* open input CM file stream */
1531 ESL_SQFILE *dbfp = NULL; /* open input sequence file */
1532 ESL_STOPWATCH *w;
1533 int status = eslOK;
1534 int hstatus = eslOK;
1535 int prv_pli_ntophits; /* number of top hits before each cm_Pipeline() */
1536 ESL_SQ *dbsq = NULL; /* one target sequence (digital) */
1537 int64_t cm_idx = 0; /* index of CM we're currently working with */
1538 double eZ; /* effective database size */
1539
1540 WORKER_INFO *info = NULL; /* contains CM, HMMs, p7 profiles, etc. */
1541
1542 char *mpi_buf = NULL; /* buffer used to pack/unpack structures */
1543 int mpi_size = 0; /* size of the allocated buffer */
1544
1545 char errbuf[eslERRBUFSIZE]; /* for reporting errors */
1546 int64_t pkey_idx; /* sequence index in SSI */
1547 int64_t L; /* length of a complete sequence, read from SSI */
1548 int64_t seq_from, seq_to; /* start/end positions of a sequence */
1549 int64_t readL; /* number of residues read in the current block */
1550 char *pkey; /* a primary key from SSI */
1551
1552 w = esl_stopwatch_Create();
1553
1554 /* Open the database file */
1555 if((status = open_dbfile (go, cfg, errbuf, &dbfp)) != eslOK) mpi_failure(errbuf);
1556
1557 /* Open the query CM file */
1558 if((status = cm_file_Open(cfg->cmfile, NULL, FALSE, &(cmfp), errbuf)) != eslOK) mpi_failure(errbuf);
1559
1560 /* allocate and initialize <info> which will hold the CMs, HMMs, etc. */
1561 if((info = create_info(go)) == NULL) mpi_failure("Out of memory");
1562
1563 /* <abc> is not known 'til first CM is read. */
1564 hstatus = cm_file_Read(cmfp, TRUE, &abc, &(info->cm));
1565
1566 if (hstatus == eslOK) {
1567 /* The master determines db size by reading SSI index. This is the
1568 * slowest initialization step, so it's done last, after we know
1569 * all other steps have passed. This way we can exit quickly
1570 * earlier if we had a quickly detectable problem.
1571 */
1572 if((status = mpi_open_dbfile_ssi(go, cfg, dbfp, errbuf)) != eslOK) mpi_failure(errbuf);
1573 /* Receive the database size broadcasted from the master */
1574 MPI_Bcast(&(cfg->Z), 1, MPI_LONG_LONG_INT, 0, MPI_COMM_WORLD);
1575 /*printf("MPIW cfg->Z: %" PRId64 " residues\n", cfg->Z);*/
1576
1577 /*printf("read cm worker\n");*/
1578 /* One-time initializations after alphabet <abc> becomes known */
1579 dbsq = esl_sq_CreateDigital(abc);
1580 }
1581
1582 /* Outer loop: over each query CM in <cmfile>. */
1583 while (hstatus == eslOK) {
1584 MPI_BLOCK *block;
1585
1586 cm_idx++;
1587 esl_stopwatch_Start(w);
1588
1589 status = 0;
1590 /* inform the master we're ready for a block of sequences */
1591 MPI_Send(&status, 1, MPI_INT, 0, INFERNAL_READY_TAG, MPI_COMM_WORLD);
1592
1593 /* Create processing pipeline and hit list */
1594 info->th = cm_tophits_Create();
1595 info->pli = cm_pipeline_Create(go, abc, info->cm->clen, 100, cfg->Z, cfg->Z_setby, CM_SEARCH_SEQS); /* L_hint = 100 is just a dummy for now */
1596
1597 /* Configure the CM and setup the HMM filter */
1598 if((status = configure_cm(info)) != eslOK) mpi_failure(info->pli->errbuf);
1599 if((status = setup_hmm_filter(go, info)) != eslOK) mpi_failure(info->pli->errbuf);
1600 if((status = cm_pli_NewModel(info->pli, CM_NEWMODEL_CM, info->cm, info->cm->clen, info->cm->W, CMCountNodetype(info->cm, MATP_nd),
1601 info->om, info->bg, info->p7_evparam, info->om->max_length, cm_idx-1,
1602 -1, NULL)) != eslOK) {
1603 mpi_failure(info->pli->errbuf);
1604 }
1605
1606 /* receive a sequence info block from the master */
1607 if((status = mpi_block_recv(0, INFERNAL_BLOCK_TAG, MPI_COMM_WORLD, &mpi_buf, &mpi_size, &block)) != eslOK) mpi_failure("Failed to receive sequence block, error status code: %d\n", status);
1608
1609 while(block->first_idx != -1) { /* receipt of a block with first_idx == -1 signals us that we're done with the database */
1610 readL = 0;
1611 pkey_idx = block->first_idx;
1612 while(pkey_idx <= block->final_idx)
1613 {
1614 /*printf("readL: %ld\n", readL);*/
1615 /* determine the primary key and length of the sequence */
1616 if((status = esl_ssi_FindNumber(dbfp->data.ascii.ssi, pkey_idx, NULL, NULL, NULL, &L, &pkey)) != eslOK) {
1617 if(status == eslENOTFOUND) mpi_failure("(worker) unable to find sequence %d in SSI index file", pkey_idx);
1618 if(status == eslEFORMAT) mpi_failure("(worker) SSI index for database file is in incorrect format.");
1619 if(status != eslOK) mpi_failure("(worker) problem with SSI index for database file.");
1620 }
1621
1622 /* determine if we're reading the full sequence or a subsequence */
1623 if((pkey_idx != block->first_idx) && (pkey_idx != block->final_idx)) {
1624 /* read full sequence */
1625 if((status = esl_sqio_Fetch(dbfp, pkey, dbsq)) != eslOK) mpi_failure("unable to fetch sequence %s\n", pkey);
1626 seq_from = 1;
1627 seq_to = L;
1628 /*printf("MPI just fetched seq %d (%40s) %10ld..%10ld\n", pkey_idx, pkey, seq_from, seq_to);*/
1629 }
1630 else {
1631 /* read first or final sequence in block, this is probably a subsequence */
1632 seq_from = (pkey_idx == block->first_idx) ? block->first_from : 1;
1633 seq_to = (pkey_idx == block->final_idx) ? block->final_to : L;
1634 if((status = esl_sqio_FetchSubseq(dbfp, pkey, seq_from, seq_to, dbsq)) != eslOK) mpi_failure("unable to fetch subsequence %ld..%ld of %s\n", seq_from, seq_to, pkey);
1635 /* FetchSubseq renames the sequence, set it back */
1636 esl_sq_SetName(dbsq, dbsq->source);
1637 /*printf("MPI just fetched seq %d (%40s) %10ld..%10ld\n", pkey_idx, pkey, seq_from, seq_to);*/
1638 }
1639 free(pkey);
1640
1641 /* tell pipeline we've got a new sequence (this updates info->pli->nres) */
1642 cm_pli_NewSeq(info->pli, dbsq, pkey_idx);
1643 readL += dbsq->n;
1644
1645 /* search top strand */
1646 if (info->pli->do_top) {
1647 prv_pli_ntophits = info->th->N;
1648 if((status = cm_Pipeline(info->pli, info->cm->offset, info->om, info->bg, info->p7_evparam, info->msvdata, dbsq, info->th, FALSE, /* FALSE: not in reverse complement */
1649 NULL, &(info->gm), &(info->Rgm), &(info->Lgm), &(info->Tgm), &(info->cm))) != eslOK)
1650 mpi_failure("cm_Pipeline() failed unexpected with status code %d\n%s\n", status, info->pli->errbuf);
1651 cm_pipeline_Reuse(info->pli); /* prepare for next search */
1652
1653 /* If we're a subsequence, update hit positions so they're relative
1654 * to the full-length sequence. */
1655 if(seq_from != 1) cm_tophits_UpdateHitPositions(info->th, prv_pli_ntophits, seq_from, FALSE);
1656 }
1657
1658 /* search reverse complement */
1659 if(info->pli->do_bot && dbsq->abc->complement != NULL) {
1660 esl_sq_ReverseComplement(dbsq);
1661 prv_pli_ntophits = info->th->N;
1662 if((status = cm_Pipeline(info->pli, info->cm->offset, info->om, info->bg, info->p7_evparam, info->msvdata, dbsq, info->th, TRUE, /* TRUE: in reverse complement */
1663 NULL, &(info->gm), &(info->Rgm), &(info->Lgm), &(info->Tgm), &(info->cm))) != eslOK)
1664 mpi_failure("cm_Pipeline() failed unexpected with status code %d\n%s\n", status, info->pli->errbuf);
1665 cm_pipeline_Reuse(info->pli); /* prepare for next search */
1666
1667 /* Hit positions will be relative to the reverse-complemented sequence
1668 * (i.e. start > end), which may be a subsequence. Update hit positions
1669 * so they're relative to the full-length original sequence (start < end). */
1670 cm_tophits_UpdateHitPositions(info->th, prv_pli_ntophits, seq_to, TRUE); /* note we use seq_to, not seq_from */
1671 }
1672 esl_sq_Reuse(dbsq);
1673
1674 pkey_idx++;
1675 }
1676 /* sanity check to make sure the blocks are the same */
1677 if (block->blockL != readL) mpi_failure("Block length mismatch - expected %ld found %ld for block idx:%ld from:%ld\n", block->blockL, readL, block->first_idx, block->first_from);
1678 /* free the block we're finished with */
1679 free(block); block = NULL;
1680
1681 /* inform the master we need another block of sequences */
1682 status = 0;
1683 MPI_Send(&status, 1, MPI_INT, 0, INFERNAL_READY_TAG, MPI_COMM_WORLD);
1684
1685 /* wait for the next block of sequences */
1686 if((status = mpi_block_recv(0, INFERNAL_BLOCK_TAG, MPI_COMM_WORLD, &mpi_buf, &mpi_size, &block)) != eslOK) mpi_failure("Failed to receive sequence block, error status code: %d\n", status);
1687 }
1688 esl_stopwatch_Stop(w);
1689 /* free the final block which was empty */
1690 free(block); block = NULL;
1691
1692 /* compute E-values before sending back to master */
1693 if(info->pli->do_hmmonly_cur) eZ = info->pli->Z / (float) info->om->max_length;
1694 else eZ = info->cm->expA[info->pli->final_cm_exp_mode]->cur_eff_dbsize;
1695 cm_tophits_ComputeEvalues(info->th, eZ, 0);
1696
1697 cm_tophits_MPISend(info->th, 0, INFERNAL_TOPHITS_TAG, MPI_COMM_WORLD, &mpi_buf, &mpi_size);
1698 cm_pipeline_MPISend(info->pli, 0, INFERNAL_PIPELINE_TAG, MPI_COMM_WORLD, &mpi_buf, &mpi_size);
1699
1700 free_info(info);
1701 free(info);
1702
1703 if((info = create_info(go)) == NULL) mpi_failure("Out of memory"); /* info is for the next model */
1704
1705 hstatus = cm_file_Read(cmfp, TRUE, &abc, &(info->cm));
1706 if(hstatus != eslOK) { free_info(info); free(info); }
1707 } /* end outer loop over query CMs */
1708
1709 switch(hstatus) {
1710 case eslEFORMAT: mpi_failure("bad file format in CM file %s\n%s", cfg->cmfile, cmfp->errbuf); break;
1711 case eslEOF: /* do nothing. EOF is what we want. */ break;
1712 default: mpi_failure("Unexpected error (%d) in reading CMs from %s\n%s", hstatus, cfg->cmfile, cmfp->errbuf);
1713 }
1714
1715 status = 0;
1716 MPI_Send(&status, 1, MPI_INT, 0, INFERNAL_TERMINATING_TAG, MPI_COMM_WORLD);
1717
1718 if (mpi_buf != NULL) free(mpi_buf);
1719
1720 cm_file_Close(cmfp);
1721 esl_sqfile_Close(dbfp);
1722
1723 esl_sq_Destroy(dbsq);
1724
1725 esl_alphabet_Destroy(abc);
1726 esl_stopwatch_Destroy(w);
1727
1728 return eslOK;
1729 }
1730 #endif /*HAVE_MPI*/
1731
1732 /* process_commandline()
1733 *
1734 * Processes the commandline, filling in fields in <cfg> and creating and returning
1735 * an <ESL_GETOPTS> options structure. The help page (cmsearch -h) is formatted
1736 * here.
1737 */
1738 static void
1739 process_commandline(int argc, char **argv, ESL_GETOPTS **ret_go, char **ret_cmfile, char **ret_seqfile)
1740 {
1741 ESL_GETOPTS *go = NULL;
1742 char *devmsg = "*";
1743 int do_dev = FALSE; /* set to TRUE if --devhelp used */
1744
1745 if ((go = esl_getopts_Create(options)) == NULL) cm_Fail("Internal failure creating options object");
1746 if (esl_opt_ProcessEnvironment(go) != eslOK) { printf("Failed to process environment: %s\n", go->errbuf); goto ERROR; }
1747 if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK) { printf("Failed to parse command line: %s\n", go->errbuf); goto ERROR; }
1748 if (esl_opt_VerifyConfig(go) != eslOK) { printf("Failed to parse command line: %s\n", go->errbuf); goto ERROR; }
1749
1750 /* help format: */
1751 do_dev = esl_opt_GetBoolean(go, "--devhelp") ? TRUE : FALSE;
1752 if (esl_opt_GetBoolean(go, "-h") || do_dev) {
1753 cm_banner(stdout, argv[0], banner);
1754 esl_usage(stdout, argv[0], usage);
1755
1756 puts("\nBasic options:");
1757 esl_opt_DisplayHelp(stdout, go, 1, 2, 80); /* 1= group; 2 = indentation; 80=textwidth*/
1758
1759 puts("\nOptions directing output:");
1760 esl_opt_DisplayHelp(stdout, go, 2, 2, 80);
1761
1762 puts("\nOptions controlling reporting thresholds:");
1763 esl_opt_DisplayHelp(stdout, go, 3, 2, 80);
1764
1765 puts("\nOptions controlling inclusion (significance) thresholds:");
1766 esl_opt_DisplayHelp(stdout, go, 4, 2, 80);
1767
1768 puts("\nOptions controlling model-specific reporting thresholds:");
1769 esl_opt_DisplayHelp(stdout, go, 5, 2, 80);
1770
1771 printf("\nOptions controlling acceleration heuristics%s:\n", do_dev ? "" : devmsg);
1772 esl_opt_DisplayHelp(stdout, go, 6, 2, 100);
1773 if(do_dev) {
1774 puts("\nOptions for precise control of the CM filter pipeline:");
1775 esl_opt_DisplayHelp(stdout, go, 101, 2, 80);
1776 puts("\nOptions controlling the HMM-only filter pipeline (run for models w/0 basepairs):");
1777 esl_opt_DisplayHelp(stdout, go, 102, 2, 80);
1778 puts("\nOptions for precise control of HMM envelope definition:");
1779 esl_opt_DisplayHelp(stdout, go, 103, 2, 80);
1780 puts("\nOptions for precise control of the CYK filter stage:");
1781 esl_opt_DisplayHelp(stdout, go, 104, 2, 80);
1782 puts("\nOptions for precise control of the final stage:");
1783 esl_opt_DisplayHelp(stdout, go, 105, 2, 80);
1784 puts("\nOptions for terminating after individual pipeline stages:");
1785 esl_opt_DisplayHelp(stdout, go, 106, 2, 80);
1786 puts("\nOptions for timing pipeline stages:");
1787 esl_opt_DisplayHelp(stdout, go, 107, 2, 80);
1788 }
1789
1790 printf("\nOther options%s:\n", do_dev ? "" : devmsg);
1791 esl_opt_DisplayHelp(stdout, go, 7, 2, 80);
1792 if(do_dev) {
1793 printf("\nOther expert options%s:\n", do_dev ? "" : devmsg);
1794 esl_opt_DisplayHelp(stdout, go, 108, 2, 80);
1795 }
1796 else {
1797 puts("\n*Use --devhelp to show additional expert options.");
1798 }
1799 exit(0);
1800 }
1801
1802 if (esl_opt_ArgNumber(go) != 2) { puts("Incorrect number of command line arguments."); goto ERROR; }
1803 if ((*ret_cmfile = esl_opt_GetArg(go, 1)) == NULL) { puts("Failed to get <cmfile> argument on command line"); goto ERROR; }
1804 if ((*ret_seqfile = esl_opt_GetArg(go, 2)) == NULL) { puts("Failed to get <seqdb> argument on command line"); goto ERROR; }
1805
1806 if (strcmp(*ret_seqfile, "-") == 0) { puts("Can't read <seqdb> from stdout: don't use '-'"); goto ERROR; }
1807
1808 /* Check for incompatible option combinations I don't know how to disallow with esl_getopts */
1809
1810 /* --glist never works, it only exists because cmscan has it, and consequently cm_pipeline_Create() expects it to */
1811 if (esl_opt_IsOn(go, "--glist")) {
1812 puts("Failed to parse command line: --glist is an invalid cmsearch option (it only works with cmscan)");
1813 goto ERROR;
1814 }
1815
1816 /* --beta only makes sense with --qdb, --nohmm or --max */
1817 if (esl_opt_IsUsed(go, "--beta") && (! esl_opt_GetBoolean(go, "--qdb")) &&
1818 (! esl_opt_GetBoolean(go, "--nohmm")) && (! esl_opt_GetBoolean(go, "--max"))) {
1819 puts("Failed to parse command line: --beta only makes sense in combination with --qdb, --nohmm or --max");
1820 goto ERROR;
1821 }
1822
1823 /* --fbeta only makes sense with --fqdb or --nohmm */
1824 if (esl_opt_IsUsed(go, "--fbeta") && (! esl_opt_GetBoolean(go, "--fqdb")) && (! esl_opt_GetBoolean(go, "--nohmm"))) {
1825 puts("Failed to parse command line: --fbeta only makes sense in combination with --fqdb or --nohmm");
1826 goto ERROR;
1827 }
1828
1829 /* If we'll be using QDBs for both the CYK filter and final round,
1830 * make sure that beta (--beta <x>) is <= filter round beta (--fbeta <x>)
1831 * There's two ways we'll need both sets of QDBs:
1832 * 1. --nohmm and neither of --fnonbanded --nonbanded (1st half of ugly if below)
1833 * 2. --qdb and --fqdb (2nd half of ugly if below)
1834 */
1835 if ((esl_opt_GetBoolean(go, "--nohmm") && (! esl_opt_GetBoolean(go, "--fnonbanded")) && (! esl_opt_GetBoolean(go, "--nonbanded"))) ||
1836 (esl_opt_GetBoolean(go, "--qdb") && esl_opt_GetBoolean(go, "--fqdb"))) {
1837 if(esl_opt_IsUsed(go, "--beta") && esl_opt_IsUsed(go, "--fbeta")) {
1838 if((esl_opt_GetReal(go, "--beta") - esl_opt_GetReal(go, "--fbeta")) > 1E-20) {
1839 puts("Failed to parse command line: with --nohmm --fbeta <x1> --beta <x2>, <x1> must be >= <x2>\n");
1840 goto ERROR;
1841 }
1842 }
1843 else if(esl_opt_IsUsed(go, "--beta")) {
1844 if((esl_opt_GetReal(go, "--beta") - esl_opt_GetReal(go, "--fbeta")) > 1E-20) {
1845 printf("Failed to parse command line: with --nohmm --beta <x> (not in combination with --fbeta), <x> must be <= %g\n", esl_opt_GetReal(go, "--fbeta"));
1846 goto ERROR;
1847 }
1848 }
1849 else if(esl_opt_IsUsed(go, "--fbeta")) {
1850 if((esl_opt_GetReal(go, "--beta") - esl_opt_GetReal(go, "--fbeta")) > 1E-20) {
1851 printf("Failed to parse command line: with --nohmm --fbeta <x> (not in combination with --beta), <x> must be >= %g\n", esl_opt_GetReal(go, "--beta"));
1852 goto ERROR;
1853 }
1854 }
1855 }
1856
1857 if((esl_opt_IsUsed(go, "--fmt")) && (esl_opt_GetInteger(go, "--fmt") == 3) && (esl_opt_IsUsed(go, "--trmF3"))) {
1858 puts("--fmt 3 doesn't make sense in combination with --trmF3");
1859 goto ERROR;
1860 }
1861 if((esl_opt_IsUsed(go, "--fmt")) && (esl_opt_GetInteger(go, "--fmt") == 2)) {
1862 puts("--fmt 2 only makes sense with cmscan, because cmsearch can't determine overlaps");
1863 goto ERROR;
1864 }
1865
1866 /* Finally, check for incompatible option combinations I *do* know
1867 * how to disallow with esl_getopts, but that would require an error
1868 * message like: "Option 'x' is incompatible with options
1869 * y1,y2,y3,y4....yn", where there's so many y's that the message is
1870 * truncated because errbuf runs out of space. As a workaround we
1871 * laboriously check for all incompatible options of that type here.
1872 */
1873 if(esl_opt_IsUsed(go, "--max")) {
1874 if(esl_opt_IsUsed(go, "--nohmm")) { puts("Failed to parse command line: Option --max is incompatible with option --nohmm"); goto ERROR; }
1875 if(esl_opt_IsUsed(go, "--mid")) { puts("Failed to parse command line: Option --max is incompatible with option --mid"); goto ERROR; }
1876 if(esl_opt_IsUsed(go, "--rfam")) { puts("Failed to parse command line: Option --max is incompatible with option --rfam"); goto ERROR; }
1877 if(esl_opt_IsUsed(go, "--FZ")) { puts("Failed to parse command line: Option --max is incompatible with option --FZ"); goto ERROR; }
1878 if(esl_opt_IsUsed(go, "--noF1")) { puts("Failed to parse command line: Option --max is incompatible with option --noF1"); goto ERROR; }
1879 if(esl_opt_IsUsed(go, "--noF2")) { puts("Failed to parse command line: Option --max is incompatible with option --noF2"); goto ERROR; }
1880 if(esl_opt_IsUsed(go, "--noF3")) { puts("Failed to parse command line: Option --max is incompatible with option --noF3"); goto ERROR; }
1881 if(esl_opt_IsUsed(go, "--noF4")) { puts("Failed to parse command line: Option --max is incompatible with option --noF4"); goto ERROR; }
1882 if(esl_opt_IsUsed(go, "--noF6")) { puts("Failed to parse command line: Option --max is incompatible with option --noF6"); goto ERROR; }
1883 if(esl_opt_IsUsed(go, "--doF1b")) { puts("Failed to parse command line: Option --max is incompatible with option --doF1b"); goto ERROR; }
1884 if(esl_opt_IsUsed(go, "--noF2b")) { puts("Failed to parse command line: Option --max is incompatible with option --noF2b"); goto ERROR; }
1885 if(esl_opt_IsUsed(go, "--noF3b")) { puts("Failed to parse command line: Option --max is incompatible with option --noF3b"); goto ERROR; }
1886 if(esl_opt_IsUsed(go, "--noF4b")) { puts("Failed to parse command line: Option --max is incompatible with option --noF4b"); goto ERROR; }
1887 if(esl_opt_IsUsed(go, "--doF5b")) { puts("Failed to parse command line: Option --max is incompatible with option --doF5b"); goto ERROR; }
1888 if(esl_opt_IsUsed(go, "--F1")) { puts("Failed to parse command line: Option --max is incompatible with option --F1"); goto ERROR; }
1889 if(esl_opt_IsUsed(go, "--F1b")) { puts("Failed to parse command line: Option --max is incompatible with option --F1b"); goto ERROR; }
1890 if(esl_opt_IsUsed(go, "--F2")) { puts("Failed to parse command line: Option --max is incompatible with option --F2"); goto ERROR; }
1891 if(esl_opt_IsUsed(go, "--F2b")) { puts("Failed to parse command line: Option --max is incompatible with option --F2b"); goto ERROR; }
1892 if(esl_opt_IsUsed(go, "--F3")) { puts("Failed to parse command line: Option --max is incompatible with option --F3"); goto ERROR; }
1893 if(esl_opt_IsUsed(go, "--F3b")) { puts("Failed to parse command line: Option --max is incompatible with option --F3b"); goto ERROR; }
1894 if(esl_opt_IsUsed(go, "--F4")) { puts("Failed to parse command line: Option --max is incompatible with option --F4"); goto ERROR; }
1895 if(esl_opt_IsUsed(go, "--F4b")) { puts("Failed to parse command line: Option --max is incompatible with option --F4b"); goto ERROR; }
1896 if(esl_opt_IsUsed(go, "--F5")) { puts("Failed to parse command line: Option --max is incompatible with option --F5"); goto ERROR; }
1897 if(esl_opt_IsUsed(go, "--F6")) { puts("Failed to parse command line: Option --max is incompatible with option --F6"); goto ERROR; }
1898 if(esl_opt_IsUsed(go, "--ftau")) { puts("Failed to parse command line: Option --max is incompatible with option --ftau"); goto ERROR; }
1899 if(esl_opt_IsUsed(go, "--fsums")) { puts("Failed to parse command line: Option --max is incompatible with option --fsums"); goto ERROR; }
1900 if(esl_opt_IsUsed(go, "--fqdb")) { puts("Failed to parse command line: Option --max is incompatible with option --fqdb"); goto ERROR; }
1901 if(esl_opt_IsUsed(go, "--fbeta")) { puts("Failed to parse command line: Option --max is incompatible with option --fbeta"); goto ERROR; }
1902 if(esl_opt_IsUsed(go, "--fnonbanded")) { puts("Failed to parse command line: Option --max is incompatible with option --fnonbanded"); goto ERROR; }
1903 if(esl_opt_IsUsed(go, "--nocykenv")) { puts("Failed to parse command line: Option --max is incompatible with option --nocykenv"); goto ERROR; }
1904 if(esl_opt_IsUsed(go, "--cykenvx")) { puts("Failed to parse command line: Option --max is incompatible with option --cykenvx"); goto ERROR; }
1905 if(esl_opt_IsUsed(go, "--tau")) { puts("Failed to parse command line: Option --max is incompatible with option --tau"); goto ERROR; }
1906 if(esl_opt_IsUsed(go, "--sums")) { puts("Failed to parse command line: Option --max is incompatible with option --sums"); goto ERROR; }
1907 if(esl_opt_IsUsed(go, "--nonbanded")) { puts("Failed to parse command line: Option --max is incompatible with option --nonbanded"); goto ERROR; }
1908 if(esl_opt_IsUsed(go, "--rt1")) { puts("Failed to parse command line: Option --max is incompatible with option --rt1"); goto ERROR; }
1909 if(esl_opt_IsUsed(go, "--rt2")) { puts("Failed to parse command line: Option --max is incompatible with option --rt2"); goto ERROR; }
1910 if(esl_opt_IsUsed(go, "--rt3")) { puts("Failed to parse command line: Option --max is incompatible with option --rt3"); goto ERROR; }
1911 if(esl_opt_IsUsed(go, "--ns")) { puts("Failed to parse command line: Option --max is incompatible with option --ns"); goto ERROR; }
1912 if(esl_opt_IsUsed(go, "--maxtau")) { puts("Failed to parse command line: Option --max is incompatible with option --maxtau"); goto ERROR; }
1913 if(esl_opt_IsUsed(go, "--anytrunc")) { puts("Failed to parse command line: Option --max is incompatible with option --anytrunc"); goto ERROR; }
1914 if(esl_opt_IsUsed(go, "--inttrunc")) { puts("Failed to parse command line: Option --max is incompatible with option --inttrunc"); goto ERROR; }
1915 if(esl_opt_IsUsed(go, "--onlytrunc")) { puts("Failed to parse command line: Option --max is incompatible with option --onlytrunc"); goto ERROR; }
1916 if(esl_opt_IsUsed(go, "--5trunc")) { puts("Failed to parse command line: Option --max is incompatible with option --5trunc"); goto ERROR; }
1917 if(esl_opt_IsUsed(go, "--3trunc")) { puts("Failed to parse command line: Option --max is incompatible with option --3trunc"); goto ERROR; }
1918 if(esl_opt_IsUsed(go, "--onepass")) { puts("Failed to parse command line: Option --max is incompatible with option --onepass"); goto ERROR; }
1919 if(esl_opt_IsUsed(go, "--olonepass")) { puts("Failed to parse command line: Option --max is incompatible with option --olonepass"); goto ERROR; }
1920 if(esl_opt_IsUsed(go, "--noiter")) { puts("Failed to parse command line: Option --max is incompatible with option --noiter"); goto ERROR; }
1921 }
1922 if(esl_opt_IsUsed(go, "--nohmm")) {
1923 if(esl_opt_IsUsed(go, "--max")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --max"); goto ERROR; }
1924 if(esl_opt_IsUsed(go, "--mid")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --mid"); goto ERROR; }
1925 if(esl_opt_IsUsed(go, "--rfam")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --rfam"); goto ERROR; }
1926 if(esl_opt_IsUsed(go, "--FZ")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --FZ"); goto ERROR; }
1927 if(esl_opt_IsUsed(go, "--noF1")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --noF1"); goto ERROR; }
1928 if(esl_opt_IsUsed(go, "--noF2")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --noF2"); goto ERROR; }
1929 if(esl_opt_IsUsed(go, "--noF3")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --noF3"); goto ERROR; }
1930 if(esl_opt_IsUsed(go, "--noF4")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --noF4"); goto ERROR; }
1931 if(esl_opt_IsUsed(go, "--doF1b")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --doF1b"); goto ERROR; }
1932 if(esl_opt_IsUsed(go, "--noF2b")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --noF2b"); goto ERROR; }
1933 if(esl_opt_IsUsed(go, "--noF3b")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --noF3b"); goto ERROR; }
1934 if(esl_opt_IsUsed(go, "--noF4b")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --noF4b"); goto ERROR; }
1935 if(esl_opt_IsUsed(go, "--doF5b")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --doF5b"); goto ERROR; }
1936 if(esl_opt_IsUsed(go, "--F1")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --F1"); goto ERROR; }
1937 if(esl_opt_IsUsed(go, "--F1b")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --F1b"); goto ERROR; }
1938 if(esl_opt_IsUsed(go, "--F2")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --F2"); goto ERROR; }
1939 if(esl_opt_IsUsed(go, "--F2b")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --F2b"); goto ERROR; }
1940 if(esl_opt_IsUsed(go, "--F3")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --F3"); goto ERROR; }
1941 if(esl_opt_IsUsed(go, "--F3b")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --F3b"); goto ERROR; }
1942 if(esl_opt_IsUsed(go, "--F4")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --F4"); goto ERROR; }
1943 if(esl_opt_IsUsed(go, "--F4b")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --F4b"); goto ERROR; }
1944 if(esl_opt_IsUsed(go, "--F5")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --F5"); goto ERROR; }
1945 if(esl_opt_IsUsed(go, "--ftau")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --ftau"); goto ERROR; }
1946 if(esl_opt_IsUsed(go, "--fsums")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --fsums"); goto ERROR; }
1947 if(esl_opt_IsUsed(go, "--tau")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --tau"); goto ERROR; }
1948 if(esl_opt_IsUsed(go, "--sums")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --sums"); goto ERROR; }
1949 if(esl_opt_IsUsed(go, "--rt1")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --rt1"); goto ERROR; }
1950 if(esl_opt_IsUsed(go, "--rt2")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --rt2"); goto ERROR; }
1951 if(esl_opt_IsUsed(go, "--rt3")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --rt3"); goto ERROR; }
1952 if(esl_opt_IsUsed(go, "--ns")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --ns"); goto ERROR; }
1953 if(esl_opt_IsUsed(go, "--maxtau")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --maxtau"); goto ERROR; }
1954 if(esl_opt_IsUsed(go, "--anytrunc")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --anytrunc"); goto ERROR; }
1955 if(esl_opt_IsUsed(go, "--inttrunc")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --inttrunc"); goto ERROR; }
1956 if(esl_opt_IsUsed(go, "--onlytrunc")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --onlytrunc"); goto ERROR; }
1957 if(esl_opt_IsUsed(go, "--5trunc")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --5trunc"); goto ERROR; }
1958 if(esl_opt_IsUsed(go, "--3trunc")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --3trunc"); goto ERROR; }
1959 if(esl_opt_IsUsed(go, "--onepass")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --onepass"); goto ERROR; }
1960 if(esl_opt_IsUsed(go, "--olonepass")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --olonepass"); goto ERROR; }
1961 if(esl_opt_IsUsed(go, "--noiter")) { puts("Failed to parse command line: Option --nohmm is incompatible with option --noiter"); goto ERROR; }
1962 }
1963 if(esl_opt_IsUsed(go, "--mid")) {
1964 if(esl_opt_IsUsed(go, "--max")) { puts("Failed to parse command line: Option --mid is incompatible with option --max"); goto ERROR; }
1965 if(esl_opt_IsUsed(go, "--nohmm")) { puts("Failed to parse command line: Option --mid is incompatible with option --nohmm"); goto ERROR; }
1966 if(esl_opt_IsUsed(go, "--rfam")) { puts("Failed to parse command line: Option --mid is incompatible with option --rfam"); goto ERROR; }
1967 if(esl_opt_IsUsed(go, "--FZ")) { puts("Failed to parse command line: Option --mid is incompatible with option --FZ"); goto ERROR; }
1968 if(esl_opt_IsUsed(go, "--noF1")) { puts("Failed to parse command line: Option --mid is incompatible with option --noF1"); goto ERROR; }
1969 if(esl_opt_IsUsed(go, "--noF2")) { puts("Failed to parse command line: Option --mid is incompatible with option --noF2"); goto ERROR; }
1970 if(esl_opt_IsUsed(go, "--noF3")) { puts("Failed to parse command line: Option --mid is incompatible with option --noF3"); goto ERROR; }
1971 if(esl_opt_IsUsed(go, "--doF1b")) { puts("Failed to parse command line: Option --mid is incompatible with option --doF1b"); goto ERROR; }
1972 if(esl_opt_IsUsed(go, "--noF2b")) { puts("Failed to parse command line: Option --mid is incompatible with option --noF2b"); goto ERROR; }
1973 if(esl_opt_IsUsed(go, "--F1")) { puts("Failed to parse command line: Option --mid is incompatible with option --F1"); goto ERROR; }
1974 if(esl_opt_IsUsed(go, "--F1b")) { puts("Failed to parse command line: Option --mid is incompatible with option --F1b"); goto ERROR; }
1975 if(esl_opt_IsUsed(go, "--F2")) { puts("Failed to parse command line: Option --mid is incompatible with option --F2"); goto ERROR; }
1976 if(esl_opt_IsUsed(go, "--F2b")) { puts("Failed to parse command line: Option --mid is incompatible with option --F2b"); goto ERROR; }
1977 }
1978 if(esl_opt_IsUsed(go, "--default")) {
1979 if(esl_opt_IsUsed(go, "--max")) { puts("Failed to parse command line: Option --default is incompatible with option --max"); goto ERROR; }
1980 if(esl_opt_IsUsed(go, "--nohmm")) { puts("Failed to parse command line: Option --default is incompatible with option --nohmm"); goto ERROR; }
1981 if(esl_opt_IsUsed(go, "--rfam")) { puts("Failed to parse command line: Option --default is incompatible with option --rfam"); goto ERROR; }
1982 if(esl_opt_IsUsed(go, "--FZ")) { puts("Failed to parse command line: Option --default is incompatible with option --FZ"); goto ERROR; }
1983 }
1984 if(esl_opt_IsUsed(go, "--rfam")) {
1985 if(esl_opt_IsUsed(go, "--max")) { puts("Failed to parse command line: Option --rfam is incompatible with option --max"); goto ERROR; }
1986 if(esl_opt_IsUsed(go, "--nohmm")) { puts("Failed to parse command line: Option --rfam is incompatible with option --nohmm"); goto ERROR; }
1987 if(esl_opt_IsUsed(go, "--default")) { puts("Failed to parse command line: Option --rfam is incompatible with option --default"); goto ERROR; }
1988 if(esl_opt_IsUsed(go, "--FZ")) { puts("Failed to parse command line: Option --rfam is incompatible with option --FZ"); goto ERROR; }
1989 }
1990 if(esl_opt_IsUsed(go, "--FZ")) {
1991 if(esl_opt_IsUsed(go, "--max")) { puts("Failed to parse command line: Option --FZ is incompatible with option --max"); goto ERROR; }
1992 if(esl_opt_IsUsed(go, "--nohmm")) { puts("Failed to parse command line: Option --FZ is incompatible with option --nohmm"); goto ERROR; }
1993 if(esl_opt_IsUsed(go, "--default")) { puts("Failed to parse command line: Option --FZ is incompatible with option --default"); goto ERROR; }
1994 if(esl_opt_IsUsed(go, "--rfam")) { puts("Failed to parse command line: Option --FZ is incompatible with option --rfam"); goto ERROR; }
1995 }
1996 if(esl_opt_IsUsed(go, "--hmmonly")) {
1997 if(esl_opt_IsUsed(go, "--max")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --max"); goto ERROR; }
1998 if(esl_opt_IsUsed(go, "--nohmm")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --nohmm"); goto ERROR; }
1999 if(esl_opt_IsUsed(go, "--mid")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --mid"); goto ERROR; }
2000 if(esl_opt_IsUsed(go, "--rfam")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --rfam"); goto ERROR; }
2001 if(esl_opt_IsUsed(go, "--FZ")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --FZ"); goto ERROR; }
2002 if(esl_opt_IsUsed(go, "--noF1")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --noF1"); goto ERROR; }
2003 if(esl_opt_IsUsed(go, "--noF2")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --noF2"); goto ERROR; }
2004 if(esl_opt_IsUsed(go, "--noF3")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --noF3"); goto ERROR; }
2005 if(esl_opt_IsUsed(go, "--noF4")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --noF4"); goto ERROR; }
2006 if(esl_opt_IsUsed(go, "--noF6")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --noF6"); goto ERROR; }
2007 if(esl_opt_IsUsed(go, "--doF1b")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --doF1b"); goto ERROR; }
2008 if(esl_opt_IsUsed(go, "--noF2b")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --noF2b"); goto ERROR; }
2009 if(esl_opt_IsUsed(go, "--noF3b")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --noF3b"); goto ERROR; }
2010 if(esl_opt_IsUsed(go, "--noF4b")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --noF4b"); goto ERROR; }
2011 if(esl_opt_IsUsed(go, "--doF5b")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --doF5b"); goto ERROR; }
2012 if(esl_opt_IsUsed(go, "--F1")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --F1"); goto ERROR; }
2013 if(esl_opt_IsUsed(go, "--F1b")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --F1b"); goto ERROR; }
2014 if(esl_opt_IsUsed(go, "--F2")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --F2"); goto ERROR; }
2015 if(esl_opt_IsUsed(go, "--F2b")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --F2b"); goto ERROR; }
2016 if(esl_opt_IsUsed(go, "--F3")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --F3"); goto ERROR; }
2017 if(esl_opt_IsUsed(go, "--F3b")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --F3b"); goto ERROR; }
2018 if(esl_opt_IsUsed(go, "--F4")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --F4"); goto ERROR; }
2019 if(esl_opt_IsUsed(go, "--F4b")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --F4b"); goto ERROR; }
2020 if(esl_opt_IsUsed(go, "--F5")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --F5"); goto ERROR; }
2021 if(esl_opt_IsUsed(go, "--F6")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --F6"); goto ERROR; }
2022 if(esl_opt_IsUsed(go, "--ftau")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --ftau"); goto ERROR; }
2023 if(esl_opt_IsUsed(go, "--fsums")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --fsums"); goto ERROR; }
2024 if(esl_opt_IsUsed(go, "--fqdb")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --fqdb"); goto ERROR; }
2025 if(esl_opt_IsUsed(go, "--fbeta")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --fbeta"); goto ERROR; }
2026 if(esl_opt_IsUsed(go, "--fnonbanded")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --fnonbanded"); goto ERROR; }
2027 if(esl_opt_IsUsed(go, "--nocykenv")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --nocykenv"); goto ERROR; }
2028 if(esl_opt_IsUsed(go, "--cykenvx")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --cykenvx"); goto ERROR; }
2029 if(esl_opt_IsUsed(go, "--tau")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --tau"); goto ERROR; }
2030 if(esl_opt_IsUsed(go, "--sums")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --sums"); goto ERROR; }
2031 if(esl_opt_IsUsed(go, "--qdb")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --qdb"); goto ERROR; }
2032 if(esl_opt_IsUsed(go, "--beta")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --beta"); goto ERROR; }
2033 if(esl_opt_IsUsed(go, "--nonbanded")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --nonbanded"); goto ERROR; }
2034 if(esl_opt_IsUsed(go, "--maxtau")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --maxtau"); goto ERROR; }
2035 if(esl_opt_IsUsed(go, "--anytrunc")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --anytrunc"); goto ERROR; }
2036 if(esl_opt_IsUsed(go, "--inttrunc")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --inttrunc"); goto ERROR; }
2037 if(esl_opt_IsUsed(go, "--onlytrunc")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --onlytrunc"); goto ERROR; }
2038 if(esl_opt_IsUsed(go, "--5trunc")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --5trunc"); goto ERROR; }
2039 if(esl_opt_IsUsed(go, "--3trunc")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --3trunc"); goto ERROR; }
2040 if(esl_opt_IsUsed(go, "--onepass")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --onepass"); goto ERROR; }
2041 if(esl_opt_IsUsed(go, "--olonepass")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --olonepass"); goto ERROR; }
2042 if(esl_opt_IsUsed(go, "--noiter")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --noiter"); goto ERROR; }
2043 if(esl_opt_IsUsed(go, "--mxsize")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --mxsize"); goto ERROR; }
2044 if(esl_opt_IsUsed(go, "--smxsize")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --smxsize"); goto ERROR; }
2045 if(esl_opt_IsUsed(go, "--nonull3")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --nonull3"); goto ERROR; }
2046 if(esl_opt_IsUsed(go, "--nohmmonly")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --nohmmonly"); goto ERROR; }
2047 if(esl_opt_IsUsed(go, "--timeF4")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --timeF4"); goto ERROR; }
2048 if(esl_opt_IsUsed(go, "--timeF5")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --timeF5"); goto ERROR; }
2049 if(esl_opt_IsUsed(go, "--timeF6")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --timeF6"); goto ERROR; }
2050 if(esl_opt_IsUsed(go, "--nogreedy")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --nogreedy"); goto ERROR; }
2051 if(esl_opt_IsUsed(go, "--cp9noel")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --cp9noel"); goto ERROR; }
2052 if(esl_opt_IsUsed(go, "--cp9gloc")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --cp9gloc"); goto ERROR; }
2053 if(esl_opt_IsUsed(go, "--null2")) { puts("Failed to parse command line: Option --hmmonly is incompatible with option --null2"); goto ERROR; }
2054 }
2055
2056 /* more incompatible combinations, listed here instead of within option definitions because the string of incompatible options is longer than errbuf */
2057 // #define REPOPTS "-E,-T,--cut_ga,--cut_nc,--cut_tc"
2058 // #define INCOPTS "--incE,--incT,--cut_ga,--cut_nc,--cut_tc"
2059 // #define THRESHOPTS "-E,-T,--incE,--incT,--cut_ga,--cut_nc,--cut_tc"
2060 if(esl_opt_IsUsed(go, "-E")) {
2061 if((esl_opt_IsUsed(go, "-T")) || (esl_opt_IsUsed(go, "--cut_ga")) || (esl_opt_IsUsed(go, "--cut_nc")) || (esl_opt_IsUsed(go, "--cut_tc"))) {
2062 puts("Failed to parse command line: Option -E is incompatible with -T,--cut_ga,--cut_nc,--cut_tc");
2063 goto ERROR;
2064 }
2065 }
2066 if(esl_opt_IsUsed(go, "-T")) {
2067 if((esl_opt_IsUsed(go, "-E")) || (esl_opt_IsUsed(go, "--cut_ga")) || (esl_opt_IsUsed(go, "--cut_nc")) || (esl_opt_IsUsed(go, "--cut_tc"))) {
2068 puts("Failed to parse command line: Option -T is incompatible with -E,--cut_ga,--cut_nc,--cut_tc");
2069 goto ERROR;
2070 }
2071 }
2072 if(esl_opt_IsUsed(go, "--incE")) {
2073 if((esl_opt_IsUsed(go, "--incT")) || (esl_opt_IsUsed(go, "--cut_ga")) || (esl_opt_IsUsed(go, "--cut_nc")) || (esl_opt_IsUsed(go, "--cut_tc"))) {
2074 puts("Failed to parse command line: Option --incE is incompatible with --incT,--cut_ga,--cut_nc,--cut_tc");
2075 goto ERROR;
2076 }
2077 }
2078 if(esl_opt_IsUsed(go, "--incT")) {
2079 if((esl_opt_IsUsed(go, "--incE")) || (esl_opt_IsUsed(go, "--cut_ga")) || (esl_opt_IsUsed(go, "--cut_nc")) || (esl_opt_IsUsed(go, "--cut_tc"))) {
2080 puts("Failed to parse command line: Option --incT is incompatible with --incE,--cut_ga,--cut_nc,--cut_tc");
2081 goto ERROR;
2082 }
2083 }
2084 if(esl_opt_IsUsed(go, "--cut_ga")) {
2085 if((esl_opt_IsUsed(go, "-E")) || (esl_opt_IsUsed(go, "-T")) || (esl_opt_IsUsed(go, "--incE")) || (esl_opt_IsUsed(go, "--incT")) || (esl_opt_IsUsed(go, "--cut_nc")) || (esl_opt_IsUsed(go, "--cut_tc"))) {
2086 puts("Failed to parse command line: Option --cut_ga is incompatible with -E,-T,--incE,--incT,--cut_nc,--cut_tc");
2087 goto ERROR;
2088 }
2089 }
2090 if(esl_opt_IsUsed(go, "--cut_nc")) {
2091 if((esl_opt_IsUsed(go, "-E")) || (esl_opt_IsUsed(go, "-T")) || (esl_opt_IsUsed(go, "--incE")) || (esl_opt_IsUsed(go, "--incT")) || (esl_opt_IsUsed(go, "--cut_ga")) || (esl_opt_IsUsed(go, "--cut_tc"))) {
2092 puts("Failed to parse command line: Option --cut_nc is incompatible with -E,-T,--incE,--incT,--cut_ga,--cut_tc");
2093 goto ERROR;
2094 }
2095 }
2096 if(esl_opt_IsUsed(go, "--cut_tc")) {
2097 if((esl_opt_IsUsed(go, "-E")) || (esl_opt_IsUsed(go, "-T")) || (esl_opt_IsUsed(go, "--incE")) || (esl_opt_IsUsed(go, "--incT")) || (esl_opt_IsUsed(go, "--cut_ga")) || (esl_opt_IsUsed(go, "--cut_nc"))) {
2098 puts("Failed to parse command line: Option --cut_tc is incompatible with -E,-T,--incE,--incT,--cut_ga,--cut_nc");
2099 goto ERROR;
2100 }
2101 }
2102
2103 // #define TRUNCOPTS "-g,--notrunc,--anytrunc,--inttrunc,--onlytrunc,--5trunc,--3trunc"
2104 // #define NOTRUNCOPTS "--anytrunc,--onlytrunc,--5trunc,--3trunc"
2105 if(esl_opt_IsUsed(go, "--notrunc")) {
2106 if((esl_opt_IsUsed(go, "--anytrunc")) || (esl_opt_IsUsed(go, "--inttrunc")) || (esl_opt_IsUsed(go, "--onlytrunc")) || (esl_opt_IsUsed(go, "--5trunc")) || (esl_opt_IsUsed(go, "--3trunc"))) {
2107 puts("Failed to parse command line: Option --notrunc is incompatible with --anytrunc,--inttrunc,--onlytrunc,--5trunc,--3trunc");
2108 goto ERROR;
2109 }
2110 }
2111 if(esl_opt_IsUsed(go, "--anytrunc")) {
2112 if((esl_opt_IsUsed(go, "-g")) || (esl_opt_IsUsed(go, "--notrunc")) || (esl_opt_IsUsed(go, "--inttrunc")) || (esl_opt_IsUsed(go, "--onlytrunc")) || (esl_opt_IsUsed(go, "--5trunc")) || (esl_opt_IsUsed(go, "--3trunc"))) {
2113 puts("Failed to parse command line: Option --anytrunc is incompatible with -g,--notrunc,--inttrunc,--onlytrunc,--5trunc,--3trunc");
2114 goto ERROR;
2115 }
2116 }
2117 if(esl_opt_IsUsed(go, "-g")) {
2118 if((esl_opt_IsUsed(go, "--anytrunc")) || (esl_opt_IsUsed(go, "--inttrunc")) || (esl_opt_IsUsed(go, "--onlytrunc")) || (esl_opt_IsUsed(go, "--5trunc")) || (esl_opt_IsUsed(go, "--3trunc"))) {
2119 puts("Failed to parse command line: Option -g is incompatible with --anytrunc,--inttrunc,--onlytrunc,--5trunc,--3trunc");
2120 goto ERROR;
2121 }
2122 }
2123 if(esl_opt_IsUsed(go, "--onlytrunc")) {
2124 if((esl_opt_IsUsed(go, "-g")) || (esl_opt_IsUsed(go, "--anytrunc")) || (esl_opt_IsUsed(go, "--inttrunc")) || (esl_opt_IsUsed(go, "--notrunc")) || (esl_opt_IsUsed(go, "--5trunc")) || (esl_opt_IsUsed(go, "--3trunc"))) {
2125 puts("Failed to parse command line: Option --onlytrunc is incompatible with -g,--anytrunc,--inttrunc,--notrunc,--5trunc,--3trunc");
2126 goto ERROR;
2127 }
2128 }
2129 if(esl_opt_IsUsed(go, "--5trunc")) {
2130 if((esl_opt_IsUsed(go, "-g")) || (esl_opt_IsUsed(go, "--anytrunc")) || (esl_opt_IsUsed(go, "--inttrunc")) || (esl_opt_IsUsed(go, "--notrunc")) || (esl_opt_IsUsed(go, "--onlytrunc")) || (esl_opt_IsUsed(go, "--3trunc"))) {
2131 puts("Failed to parse command line: Option --5trunc is incompatible with -g,--anytrunc,--inttrunc,--notrunc,--onlytrunc,--3trunc");
2132 goto ERROR;
2133 }
2134 }
2135 if(esl_opt_IsUsed(go, "--3trunc")) {
2136 if((esl_opt_IsUsed(go, "-g")) || (esl_opt_IsUsed(go, "--anytrunc")) || (esl_opt_IsUsed(go, "--inttrunc")) || (esl_opt_IsUsed(go, "--notrunc")) || (esl_opt_IsUsed(go, "--onlytrunc")) || (esl_opt_IsUsed(go, "--5trunc"))) {
2137 puts("Failed to parse command line: Option --5trunc is incompatible with -g,--anytrunc,--inttrunc,--notrunc,--onlytrunc,--5trunc");
2138 goto ERROR;
2139 }
2140 }
2141
2142 // #define TIMINGOPTS "--timeF1,--timeF2,--timeF3,--timeF4,--timeF5,--timeF6"
2143 // #define ICWTRMF3 "--timeF1,--timeF2,--timeF3,--timeF4,--timeF5,--timeF6"
2144 if(esl_opt_IsUsed(go, "--timeF1")) {
2145 if((esl_opt_IsUsed(go, "--timeF2")) || (esl_opt_IsUsed(go, "--timeF3")) || (esl_opt_IsUsed(go, "--timeF4")) || (esl_opt_IsUsed(go, "--timeF5")) || (esl_opt_IsUsed(go, "--timeF6"))) {
2146 puts("Failed to parse command line: Option --timeF1 is incompatible with --timeF2,--timeF3,--timeF4,--timeF5,--timeF6");
2147 goto ERROR;
2148 }
2149 }
2150 if(esl_opt_IsUsed(go, "--timeF2")) {
2151 if((esl_opt_IsUsed(go, "--timeF1")) || (esl_opt_IsUsed(go, "--timeF3")) || (esl_opt_IsUsed(go, "--timeF4")) || (esl_opt_IsUsed(go, "--timeF5")) || (esl_opt_IsUsed(go, "--timeF6"))) {
2152 puts("Failed to parse command line: Option --timeF2 is incompatible with --timeF1,--timeF3,--timeF4,--timeF5,--timeF6");
2153 goto ERROR;
2154 }
2155 }
2156 if(esl_opt_IsUsed(go, "--timeF3")) {
2157 if((esl_opt_IsUsed(go, "--timeF1")) || (esl_opt_IsUsed(go, "--timeF2")) || (esl_opt_IsUsed(go, "--timeF4")) || (esl_opt_IsUsed(go, "--timeF5")) || (esl_opt_IsUsed(go, "--timeF6"))) {
2158 puts("Failed to parse command line: Option --timeF2 is incompatible with --timeF1,--timeF2,--timeF4,--timeF5,--timeF6");
2159 goto ERROR;
2160 }
2161 }
2162 if(esl_opt_IsUsed(go, "--timeF4")) {
2163 if((esl_opt_IsUsed(go, "--timeF1")) || (esl_opt_IsUsed(go, "--timeF2")) || (esl_opt_IsUsed(go, "--timeF3")) || (esl_opt_IsUsed(go, "--timeF5")) || (esl_opt_IsUsed(go, "--timeF6"))) {
2164 puts("Failed to parse command line: Option --timeF4 is incompatible with --timeF1,--timeF2,--timeF3,--timeF5,--timeF6");
2165 goto ERROR;
2166 }
2167 }
2168 if(esl_opt_IsUsed(go, "--timeF5")) {
2169 if((esl_opt_IsUsed(go, "--timeF1")) || (esl_opt_IsUsed(go, "--timeF2")) || (esl_opt_IsUsed(go, "--timeF3")) || (esl_opt_IsUsed(go, "--timeF4")) || (esl_opt_IsUsed(go, "--timeF6"))) {
2170 puts("Failed to parse command line: Option --timeF5 is incompatible with --timeF1,--timeF2,--timeF3,--timeF4,--timeF6");
2171 goto ERROR;
2172 }
2173 }
2174 if(esl_opt_IsUsed(go, "--timeF6")) {
2175 if((esl_opt_IsUsed(go, "--timeF1")) || (esl_opt_IsUsed(go, "--timeF2")) || (esl_opt_IsUsed(go, "--timeF3")) || (esl_opt_IsUsed(go, "--timeF4")) || (esl_opt_IsUsed(go, "--timeF5"))) {
2176 puts("Failed to parse command line: Option --timeF6 is incompatible with --timeF1,--timeF2,--timeF3,--timeF4,--timeF5");
2177 goto ERROR;
2178 }
2179 }
2180 if(esl_opt_IsUsed(go, "--trmF3")) {
2181 if((esl_opt_IsUsed(go, "--timeF1")) || (esl_opt_IsUsed(go, "--timeF2")) || (esl_opt_IsUsed(go, "--timeF3")) || (esl_opt_IsUsed(go, "--timeF4")) || (esl_opt_IsUsed(go, "--timeF5")) || (esl_opt_IsUsed(go, "--timeF6"))) {
2182 puts("Failed to parse command line: Option --trmF3 is incompatible with --timeF1,--timeF2,--timeF3,--timeF4,--timeF5,--timeF6");
2183 goto ERROR;
2184 }
2185 }
2186
2187 // #define ICWHMMMAX "--hmmF1,--hmmF2,--hmmF3,--hmmnobias"
2188 if(esl_opt_IsUsed(go, "--hmmmax")) {
2189 if((esl_opt_IsUsed(go, "--hmmF1")) || (esl_opt_IsUsed(go, "--hmmF2")) || (esl_opt_IsUsed(go, "--hmmF3")) || (esl_opt_IsUsed(go, "--hmmnobias"))) {
2190 puts("Failed to parse command line: Option --hmmmax is incompatible with --hmmF1,--hmmF2,--hmmF3,--hmmnobias");
2191 goto ERROR;
2192 }
2193 }
2194
2195 // #define ICWFNONBANDED "--ftau,--fsums,--fqdb,--fbeta"
2196 if(esl_opt_IsUsed(go, "--fnonbanded")) {
2197 if((esl_opt_IsUsed(go, "--ftau")) || (esl_opt_IsUsed(go, "--fsums")) || (esl_opt_IsUsed(go, "--fqdb")) || (esl_opt_IsUsed(go, "--fbeta"))) {
2198 puts("Failed to parse command line: Option --fnonbanded is incompatible with --ftau,--fsums,--fqdb,--fbeta");
2199 goto ERROR;
2200 }
2201 }
2202
2203 // #define ICWNONBANDED "--tau,--sums,--qdb,--beta"
2204 if(esl_opt_IsUsed(go, "--nonbanded")) {
2205 if((esl_opt_IsUsed(go, "--tau")) || (esl_opt_IsUsed(go, "--sums")) || (esl_opt_IsUsed(go, "--qdb")) || (esl_opt_IsUsed(go, "--beta"))) {
2206 puts("Failed to parse command line: Option --nonbanded is incompatible with --tau,--sums,--qdb,--beta");
2207 goto ERROR;
2208 }
2209 }
2210
2211 // #define ICWOLONEPASS "--nohmm,--qdb,--fqdb,--onepass"
2212 if(esl_opt_IsUsed(go, "--olonepass")) {
2213 if((esl_opt_IsUsed(go, "--nohmm")) || (esl_opt_IsUsed(go, "--qdb")) || (esl_opt_IsUsed(go, "--fqdb")) || (esl_opt_IsUsed(go, "--onepass"))) {
2214 puts("Failed to parse command line: Option --olonepass is incompatible with --nohmm,--qdb,--fqdb,--onepass");
2215 goto ERROR;
2216 }
2217 }
2218
2219
2220 *ret_go = go;
2221 return;
2222
2223 ERROR: /* all errors handled here are user errors, so be polite. */
2224 esl_usage(stdout, argv[0], usage);
2225 puts("\nwhere basic options are:");
2226 esl_opt_DisplayHelp(stdout, go, 1, 2, 80); /* 1= group; 2 = indentation; 80=textwidth*/
2227 printf("\nTo see more help on available options, do %s -h\n\n", argv[0]);
2228 exit(1);
2229 }
2230
2231 static int
2232 output_header(FILE *ofp, const ESL_GETOPTS *go, char *cmfile, char *seqfile, int ncpus)
2233 {
2234 cm_banner(ofp, go->argv[0], banner);
2235
2236 fprintf(ofp, "# query CM file: %s\n", cmfile);
2237 fprintf(ofp, "# target sequence database: %s\n", seqfile);
2238 if (esl_opt_IsUsed(go, "-g")) fprintf(ofp, "# CM configuration: glocal\n");
2239 if (esl_opt_IsUsed(go, "-Z")) fprintf(ofp, "# database size is set to: %.1f Mb\n", esl_opt_GetReal(go, "-Z"));
2240 if (esl_opt_IsUsed(go, "-o")) fprintf(ofp, "# output directed to file: %s\n", esl_opt_GetString(go, "-o"));
2241 if (esl_opt_IsUsed(go, "-A")) fprintf(ofp, "# MSA of significant hits saved to file: %s\n", esl_opt_GetString(go, "-A"));
2242 if (esl_opt_IsUsed(go, "--tblout")) fprintf(ofp, "# tabular output of hits: %s\n", esl_opt_GetString(go, "--tblout"));
2243 if (esl_opt_IsUsed(go, "--acc")) fprintf(ofp, "# prefer accessions over names: yes\n");
2244 if (esl_opt_IsUsed(go, "--noali")) fprintf(ofp, "# show alignments in output: no\n");
2245 if (esl_opt_IsUsed(go, "--notextw")) fprintf(ofp, "# max ASCII text line length: unlimited\n");
2246 if (esl_opt_IsUsed(go, "--textw")) fprintf(ofp, "# max ASCII text line length: %d\n", esl_opt_GetInteger(go, "--textw"));
2247 if (esl_opt_IsUsed(go, "--verbose")) fprintf(ofp, "# verbose output mode: on\n");
2248 if (esl_opt_IsUsed(go, "-E")) fprintf(ofp, "# sequence reporting threshold: E-value <= %g\n", esl_opt_GetReal(go, "-E"));
2249 if (esl_opt_IsUsed(go, "-T")) fprintf(ofp, "# sequence reporting threshold: score >= %g\n", esl_opt_GetReal(go, "-T"));
2250 if (esl_opt_IsUsed(go, "--incE")) fprintf(ofp, "# sequence inclusion threshold: E-value <= %g\n", esl_opt_GetReal(go, "--incE"));
2251 if (esl_opt_IsUsed(go, "--incT")) fprintf(ofp, "# sequence inclusion threshold: score >= %g\n", esl_opt_GetReal(go, "--incT"));
2252 if (esl_opt_IsUsed(go, "--cut_ga")) fprintf(ofp, "# model-specific thresholding: GA cutoffs\n");
2253 if (esl_opt_IsUsed(go, "--cut_nc")) fprintf(ofp, "# model-specific thresholding: NC cutoffs\n");
2254 if (esl_opt_IsUsed(go, "--cut_tc")) fprintf(ofp, "# model-specific thresholding: TC cutoffs\n");
2255 if (esl_opt_IsUsed(go, "--max")) fprintf(ofp, "# Max sensitivity mode: on [all heuristic filters off]\n");
2256 if (esl_opt_IsUsed(go, "--nohmm")) fprintf(ofp, "# CM-only mode: on [HMM filters off]\n");
2257 if (esl_opt_IsUsed(go, "--mid")) fprintf(ofp, "# HMM MSV and Viterbi filters: off\n");
2258 if (esl_opt_IsUsed(go, "--rfam")) fprintf(ofp, "# Rfam pipeline mode: on [strict filtering]\n");
2259 if (esl_opt_IsUsed(go, "--FZ")) fprintf(ofp, "# Filters set as if DB size in Mb is: %f\n", esl_opt_GetReal(go, "--FZ"));
2260 if (esl_opt_IsUsed(go, "--Fmid")) fprintf(ofp, "# HMM Forward filter thresholds set to: %g\n", esl_opt_GetReal(go, "--Fmid"));
2261 if (esl_opt_IsUsed(go, "--hmmonly")) fprintf(ofp, "# HMM-only mode (for all models): on [CM will not be used]\n");
2262 if (esl_opt_IsUsed(go, "--notrunc")) fprintf(ofp, "# truncated sequence detection: off\n");
2263 if (esl_opt_IsUsed(go, "--anytrunc")) fprintf(ofp, "# allowing truncated sequences anywhere: on\n");
2264 if (esl_opt_IsUsed(go, "--inttrunc")) fprintf(ofp, "# allowing internally truncated seqs: on\n");
2265 if (esl_opt_IsUsed(go, "--onlytrunc")) fprintf(ofp, "# only allowing truncated seqs anywhere: on\n");
2266 if (esl_opt_IsUsed(go, "--5trunc")) fprintf(ofp, "# allowing 5' truncated seqs only: on\n");
2267 if (esl_opt_IsUsed(go, "--3trunc")) fprintf(ofp, "# allowing 3' truncated seqs only: on\n");
2268 if (esl_opt_IsUsed(go, "--nonull3")) fprintf(ofp, "# null3 bias corrections: off\n");
2269 if (esl_opt_IsUsed(go, "--mxsize")) fprintf(ofp, "# maximum DP alignment matrix size: %.1f Mb\n", esl_opt_GetReal(go, "--mxsize"));
2270 if (esl_opt_IsUsed(go, "--smxsize")) fprintf(ofp, "# maximum DP search matrix size: %.1f Mb\n", esl_opt_GetReal(go, "--smxsize"));
2271 if (esl_opt_IsUsed(go, "--cyk")) fprintf(ofp, "# use CYK for final search stage on\n");
2272 if (esl_opt_IsUsed(go, "--acyk")) fprintf(ofp, "# use CYK to align hits: on\n");
2273 if (esl_opt_IsUsed(go, "--wcx")) fprintf(ofp, "# W set as <x> * cm->clen: <x>=%g\n", esl_opt_GetReal(go, "--wcx"));
2274 if (esl_opt_IsUsed(go, "--onepass")) fprintf(ofp, "# using CM for best HMM pass only: on\n");
2275 if (esl_opt_IsUsed(go, "--olonepass")) fprintf(ofp, "# using CM for best HMM pass only (ol): on\n");
2276 if (esl_opt_IsUsed(go, "--noiter")) fprintf(ofp, "# iterative HMM band tightening: off\n");
2277 if (esl_opt_IsUsed(go, "--toponly")) fprintf(ofp, "# search top-strand only: on\n");
2278 if (esl_opt_IsUsed(go, "--bottomonly")) fprintf(ofp, "# search bottom-strand only: on\n");
2279 if (esl_opt_IsUsed(go, "--tformat")) fprintf(ofp, "# targ <seqdb> format asserted: %s\n", esl_opt_GetString(go, "--tformat"));
2280 #ifdef HAVE_MPI
2281 if (esl_opt_IsUsed(go, "--stall")) fprintf(ofp, "# MPI stall mode: on\n");
2282 #endif
2283 /* Developer options, only shown to user if --devhelp used */
2284 if (esl_opt_IsUsed(go, "--noF1")) fprintf(ofp, "# HMM MSV filter: off\n");
2285 if (esl_opt_IsUsed(go, "--noF2")) fprintf(ofp, "# HMM Vit filter: off\n");
2286 if (esl_opt_IsUsed(go, "--noF3")) fprintf(ofp, "# HMM Fwd filter: off\n");
2287 if (esl_opt_IsUsed(go, "--noF4")) fprintf(ofp, "# HMM glocal Fwd filter: off\n");
2288 if (esl_opt_IsUsed(go, "--noF6")) fprintf(ofp, "# CM CYK filter: off\n");
2289 if (esl_opt_IsUsed(go, "--doF1b")) fprintf(ofp, "# HMM MSV biased comp filter: on\n");
2290 if (esl_opt_IsUsed(go, "--noF2b")) fprintf(ofp, "# HMM Vit biased comp filter: off\n");
2291 if (esl_opt_IsUsed(go, "--noF3b")) fprintf(ofp, "# HMM Fwd biased comp filter: off\n");
2292 if (esl_opt_IsUsed(go, "--noF4b")) fprintf(ofp, "# HMM gFwd biased comp filter: off\n");
2293 if (esl_opt_IsUsed(go, "--doF5b")) fprintf(ofp, "# HMM per-envelope biased comp filter: on\n");
2294 if (esl_opt_IsUsed(go, "--F1")) fprintf(ofp, "# HMM MSV filter P threshold: <= %g\n", esl_opt_GetReal(go, "--F1"));
2295 if (esl_opt_IsUsed(go, "--F1b")) fprintf(ofp, "# HMM MSV bias P threshold: <= %g\n", esl_opt_GetReal(go, "--F1b"));
2296 if (esl_opt_IsUsed(go, "--F2")) fprintf(ofp, "# HMM Vit filter P threshold: <= %g\n", esl_opt_GetReal(go, "--F2"));
2297 if (esl_opt_IsUsed(go, "--F2b")) fprintf(ofp, "# HMM Vit bias P threshold: <= %g\n", esl_opt_GetReal(go, "--F2b"));
2298 if (esl_opt_IsUsed(go, "--F3")) fprintf(ofp, "# HMM Fwd filter P threshold: <= %g\n", esl_opt_GetReal(go, "--F3"));
2299 if (esl_opt_IsUsed(go, "--F3b")) fprintf(ofp, "# HMM Fwd bias P threshold: <= %g\n", esl_opt_GetReal(go, "--F3b"));
2300 if (esl_opt_IsUsed(go, "--F4")) fprintf(ofp, "# HMM glocal Fwd filter P threshold: <= %g\n", esl_opt_GetReal(go, "--F4"));
2301 if (esl_opt_IsUsed(go, "--F4b")) fprintf(ofp, "# HMM glocal Fwd bias P threshold: <= %g\n", esl_opt_GetReal(go, "--F4b"));
2302 if (esl_opt_IsUsed(go, "--F5")) fprintf(ofp, "# HMM env defn filter P threshold: <= %g\n", esl_opt_GetReal(go, "--F5"));
2303 if (esl_opt_IsUsed(go, "--F5b")) fprintf(ofp, "# HMM env defn bias P threshold: <= %g\n", esl_opt_GetReal(go, "--F5b"));
2304 if (esl_opt_IsUsed(go, "--F6")) fprintf(ofp, "# CM CYK filter P threshold: <= %g\n", esl_opt_GetReal(go, "--F6"));
2305
2306 if (esl_opt_IsUsed(go, "--hmmmax")) fprintf(ofp, "# max sensitivity mode (HMM-only): on [all heuristic filters off]\n");
2307 if (esl_opt_IsUsed(go, "--hmmF1")) fprintf(ofp, "# HMM MSV filter P threshold (HMM-only) <= %g\n", esl_opt_GetReal(go, "--hmmF1"));
2308 if (esl_opt_IsUsed(go, "--hmmF2")) fprintf(ofp, "# HMM Vit filter P threshold (HMM-only) <= %g\n", esl_opt_GetReal(go, "--hmmF2"));
2309 if (esl_opt_IsUsed(go, "--hmmF3")) fprintf(ofp, "# HMM Fwd filter P threshold (HMM-only) <= %g\n", esl_opt_GetReal(go, "--hmmF3"));
2310 if (esl_opt_IsUsed(go, "--hmmnobias")) fprintf(ofp, "# HMM MSV biased comp filter (HMM-only) off\n");
2311 if (esl_opt_IsUsed(go, "--hmmnonull2")) fprintf(ofp, "# null2 bias corrections (HMM-only): off\n");
2312 if (esl_opt_IsUsed(go, "--nohmmonly")) fprintf(ofp, "# HMM-only mode for 0 basepair models: no\n");
2313
2314 if (esl_opt_IsUsed(go, "--rt1")) fprintf(ofp, "# domain definition rt1 parameter %g\n", esl_opt_GetReal(go, "--rt1"));
2315 if (esl_opt_IsUsed(go, "--rt2")) fprintf(ofp, "# domain definition rt2 parameter %g\n", esl_opt_GetReal(go, "--rt2"));
2316 if (esl_opt_IsUsed(go, "--rt3")) fprintf(ofp, "# domain definition rt3 parameter %g\n", esl_opt_GetReal(go, "--rt3"));
2317 if (esl_opt_IsUsed(go, "--ns")) fprintf(ofp, "# number of envelope tracebacks sampled %d\n", esl_opt_GetInteger(go, "--ns"));
2318
2319 if (esl_opt_IsUsed(go, "--ftau")) fprintf(ofp, "# tau parameter for CYK filter stage: %g\n", esl_opt_GetReal(go, "--ftau"));
2320 if (esl_opt_IsUsed(go, "--fsums")) fprintf(ofp, "# posterior sums (CYK filter stage): on\n");
2321 if (esl_opt_IsUsed(go, "--fqdb")) fprintf(ofp, "# QDBs (CYK filter stage) on\n");
2322 if (esl_opt_IsUsed(go, "--fbeta")) fprintf(ofp, "# beta parameter for CYK filter stage: %g\n", esl_opt_GetReal(go, "--fbeta"));
2323 if (esl_opt_IsUsed(go, "--fnonbanded")) fprintf(ofp, "# no bands (CYK filter stage) on\n");
2324 if (esl_opt_IsUsed(go, "--nocykenv")) fprintf(ofp, "# CYK envelope redefinition: off\n");
2325 if (esl_opt_IsUsed(go, "--cykenvx")) fprintf(ofp, "# CYK envelope redefn P-val multiplier: %d\n", esl_opt_GetInteger(go, "--cykenvx"));
2326
2327 if (esl_opt_IsUsed(go, "--tau")) fprintf(ofp, "# tau parameter for final stage: %g\n", esl_opt_GetReal(go, "--tau"));
2328 if (esl_opt_IsUsed(go, "--sums")) fprintf(ofp, "# posterior sums (final stage): on\n");
2329 if (esl_opt_IsUsed(go, "--qdb")) fprintf(ofp, "# QDBs (final stage) on\n");
2330 if (esl_opt_IsUsed(go, "--beta")) fprintf(ofp, "# beta parameter for final stage: %g\n", esl_opt_GetReal(go, "--beta"));
2331 if (esl_opt_IsUsed(go, "--nonbanded")) fprintf(ofp, "# no bands (final stage) on\n");
2332
2333 if (esl_opt_IsUsed(go, "--timeF1")) fprintf(ofp, "# abort after Stage 1 MSV (for timing) on\n");
2334 if (esl_opt_IsUsed(go, "--timeF2")) fprintf(ofp, "# abort after Stage 2 Vit (for timing) on\n");
2335 if (esl_opt_IsUsed(go, "--timeF3")) fprintf(ofp, "# abort after Stage 3 Fwd (for timing) on\n");
2336 if (esl_opt_IsUsed(go, "--timeF4")) fprintf(ofp, "# abort after Stage 4 gFwd (for timing) on\n");
2337 if (esl_opt_IsUsed(go, "--timeF5")) fprintf(ofp, "# abort after Stage 5 env defn (for timing) on\n");
2338 if (esl_opt_IsUsed(go, "--timeF6")) fprintf(ofp, "# abort after Stage 6 CYK (for timing) on\n");
2339
2340 if (esl_opt_IsUsed(go, "--trmF3")) fprintf(ofp, "# terminate after Stage 3 Fwd: on\n");
2341
2342 if (esl_opt_IsUsed(go, "--nogreedy")) fprintf(ofp, "# greedy CM hit resolution: off\n");
2343 if (esl_opt_IsUsed(go, "--cp9noel")) fprintf(ofp, "# CP9 HMM local ends: off\n");
2344 if (esl_opt_IsUsed(go, "--cp9gloc")) fprintf(ofp, "# CP9 HMM configuration: glocal\n");
2345 if (esl_opt_IsUsed(go, "--null2")) fprintf(ofp, "# null2 bias corrections: on\n");
2346 if (esl_opt_IsUsed(go, "--maxtau")) fprintf(ofp, "# max tau during band tightening: %g\n", esl_opt_GetReal(go, "--maxtau"));
2347 if (esl_opt_IsUsed(go, "--seed")) {
2348 if (esl_opt_GetInteger(go, "--seed") == 0) fprintf(ofp, "# random number seed: one-time arbitrary\n");
2349 else fprintf(ofp, "# random number seed set to: %d\n", esl_opt_GetInteger(go, "--seed"));
2350 }
2351 #ifdef HAVE_MPI
2352 if (esl_opt_IsUsed(go, "--sidx")) fprintf(ofp, "# first target sequence to search: %d\n", esl_opt_GetInteger(go, "--sidx"));
2353 if (esl_opt_IsUsed(go, "--eidx")) fprintf(ofp, "# final target sequence to search: %d\n", esl_opt_GetInteger(go, "--eidx"));
2354 #endif
2355 /* if --max or --nohmm, truncated ends will be turned off
2356 * in cm_pipeline_Create() (hopefully this will go away soon when D&C
2357 * truncated alignment is fixed).
2358 */
2359 if(! (esl_opt_IsUsed(go, "--notrunc"))) {
2360 if(esl_opt_IsUsed(go, "--max")) { fprintf(ofp, "# truncated hit detection: off [due to --max]\n"); }
2361 if(esl_opt_IsUsed(go, "--nohmm")) { fprintf(ofp, "# truncated hit detection: off [due to --nohmm]\n"); }
2362 }
2363 /* output number of processors being used, always (this differs from H3 which only does this if --cpu) */
2364 int output_ncpu = FALSE;
2365 #ifdef HAVE_MPI
2366 if (esl_opt_IsUsed(go, "--mpi")) { fprintf(ofp, "# MPI: on [%d processors]\n", ncpus); output_ncpu = TRUE; }
2367 #endif
2368 #ifdef HMMER_THREADS
2369 if (! output_ncpu) { fprintf(ofp, "# number of worker threads: %d%s\n", ncpus, (esl_opt_IsUsed(go, "--cpu") ? " [--cpu]" : "")); output_ncpu = TRUE; }
2370 #endif
2371 if (! output_ncpu) { fprintf(ofp, "# number of worker threads: 0 [serial mode; threading unavailable]\n"); }
2372 fprintf(ofp, "# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n");
2373 return eslOK;
2374 }
2375
2376 /* Function: open_dbfile
2377 * Synopsis: Open the database file.
2378 * Incept: EPN, Mon Jun 6 09:13:08 2011
2379 *
2380 * Returns: eslOK on success. ESL_SQFILE *dbfp in *ret_dbfp.
2381 * Upon error, fills errbuf with error message and
2382 * returns error status code.
2383 */
2384 static int
2385 open_dbfile(ESL_GETOPTS *go, struct cfg_s *cfg, char *errbuf, ESL_SQFILE **ret_dbfp)
2386 {
2387 int status;
2388 int dbfmt = eslSQFILE_UNKNOWN; /* format of dbfile */
2389
2390 if (esl_opt_IsOn(go, "--tformat")) {
2391 dbfmt = esl_sqio_EncodeFormat(esl_opt_GetString(go, "--tformat"));
2392 if (dbfmt == eslSQFILE_UNKNOWN) ESL_FAIL(eslEINVAL, errbuf, "%s is not a recognized sequence database file format\n", esl_opt_GetString(go, "--tformat"));
2393 }
2394 status = esl_sqfile_Open(cfg->dbfile, dbfmt, p7_SEQDBENV, ret_dbfp);
2395 if (status == eslENOTFOUND) ESL_FAIL(status, errbuf, "Failed to open sequence file %s for reading\n", cfg->dbfile);
2396 else if (status == eslEFORMAT) ESL_FAIL(status, errbuf, "Sequence file %s is empty or misformatted\n", cfg->dbfile);
2397 else if (status == eslEINVAL) ESL_FAIL(status, errbuf, "Can't autodetect format of a stdin or .gz seqfile");
2398 else if (status != eslOK) ESL_FAIL(status, errbuf, "Unexpected error %d opening sequence file %s\n", status, cfg->dbfile);
2399
2400 if (esl_sqio_IsAlignment((*ret_dbfp)->format)) {
2401 /* file is an alignment format, we can't deal with that since it may be interleaved
2402 * and esl_sq_ReadBlock() can't handle that since it uses ReadWindow() to read
2403 * possibly non-full length subsequences and isn't implemented to handle alignments.
2404 */
2405 cm_Fail("%s autodetected as an alignment file; unaligned sequence file, like FASTA, is required\n", cfg->dbfile);
2406 }
2407
2408 return eslOK;
2409 }
2410
2411 /* Function: dbsize_and_seq_lengths()
2412 * Synopsis: Determine size of the database by reading it
2413 * (but not storing it), as well as sequence lengths.
2414 * Incept: EPN, Mon Jun 6 09:17:32 2011
2415 *
2416 *
2417 * Returns: eslOK on success:
2418 * cfg->Z is set
2419 * array of seq lengths returned in *ret_srcL
2420 * # seqs returned in *ret_nseqs
2421 * eslEFORMAT if database file is screwy.
2422 */
2423 static int
2424 dbsize_and_seq_lengths(ESL_GETOPTS *go, struct cfg_s *cfg, ESL_SQFILE **dbfp_ptr, char *errbuf, int64_t **ret_srcL, int64_t *ret_nseqs)
2425 {
2426 int status;
2427 ESL_SQ *sq = NULL;
2428 int64_t nres = 0; /* total number of residues */
2429 /* variables used to store lengths of all target sequences */
2430 int64_t *srcL = NULL; /* [0..nseqs-1] full length of each target sequence read */
2431 int64_t nseqs = 0; /* total number of sequences */
2432 int64_t nalloc_srcL = 0; /* current allocation size of srcL */
2433 int alloc_srcL = 10000; /* chunk size to increase allocation by for srcL */
2434 int64_t i; /* counter */
2435 char *tmp_filename = NULL; /* name of sqfile, used only if gzipped */
2436 int tmp_fmt; /* fmt of sqfile, used only if gzipped */
2437
2438 /* we'll only use this if seqfile is gzipped */
2439 ESL_ALLOC(tmp_filename, sizeof(char) * (strlen((*dbfp_ptr)->filename) + 1));
2440
2441 sq = esl_sq_Create();
2442 while ((status = esl_sqio_ReadInfo(*dbfp_ptr, sq)) == eslOK) {
2443 nres += sq->L;
2444 if(nseqs == nalloc_srcL) { /* reallocate */
2445 nalloc_srcL += alloc_srcL;
2446 ESL_REALLOC(srcL, sizeof(int64_t) * nalloc_srcL);
2447 for(i = nalloc_srcL-alloc_srcL; i < nalloc_srcL; i++) srcL[i] = -1; /* initialize */
2448 }
2449 srcL[nseqs++] = sq->L;
2450 esl_sq_Reuse(sq);
2451 }
2452 if(status != eslEOF) goto ERROR;
2453
2454 /* if we get here we've successfully read entire file */
2455 cfg->Z = nres;
2456 if((! esl_opt_GetBoolean(go, "--toponly")) &&
2457 (! esl_opt_GetBoolean(go, "--bottomonly"))) {
2458 cfg->Z *= 2; /* we're searching both strands */
2459 }
2460 cfg->Z_setby = CM_ZSETBY_FILEREAD;
2461
2462 if((*dbfp_ptr)->data.ascii.do_gzip == TRUE) {
2463 /* file is gzipped, close it and reopen it.
2464 we know we successfully opened it the first time, so a
2465 failure to reopen is an exception, not a user-reportable
2466 normal error. ENOTFOUND is the only normal error;
2467 EFORMAT error can't occur because we know the format and
2468 don't use autodetection.
2469 */
2470 strcpy(tmp_filename, (*dbfp_ptr)->filename);
2471 tmp_fmt = (*dbfp_ptr)->format;
2472 esl_sqfile_Close(*dbfp_ptr);
2473 status = esl_sqfile_Open(tmp_filename, tmp_fmt, NULL, dbfp_ptr);
2474 if (status == eslENOTFOUND) ESL_EXCEPTION(eslENOTFOUND, "failed to reopen alignment file");
2475 else if (status != eslOK) ESL_FAIL(status, errbuf, "unexpected error when reopening sequence file");
2476 }
2477 else {
2478 /* file is not gzipped, easier case */
2479 esl_sqfile_Position((*dbfp_ptr), 0);
2480 }
2481
2482 if(tmp_filename != NULL) free(tmp_filename);
2483 if(sq != NULL) esl_sq_Destroy(sq);
2484
2485 *ret_srcL = srcL;
2486 *ret_nseqs = nseqs;
2487
2488 return eslOK;
2489
2490 ERROR:
2491 if((*dbfp_ptr)->data.ascii.do_gzip == TRUE) { /* same as above, close and reopen */
2492 strcpy(tmp_filename, (*dbfp_ptr)->filename);
2493 tmp_fmt = (*dbfp_ptr)->format;
2494 esl_sqfile_Close((*dbfp_ptr));
2495 status = esl_sqfile_Open(tmp_filename, tmp_fmt, NULL, dbfp_ptr);
2496 if (status == eslENOTFOUND) ESL_EXCEPTION(eslENOTFOUND, "failed to reopen alignment file");
2497 else if (status != eslOK) ESL_XFAIL(status, errbuf, "unexpected error when reopening sequence file");
2498 }
2499 else {
2500 /* file is not gzipped, easier case */
2501 esl_sqfile_Position((*dbfp_ptr), 0);
2502 }
2503 if(tmp_filename != NULL) free(tmp_filename);
2504 if(sq != NULL) esl_sq_Destroy(sq);
2505
2506 *ret_srcL = NULL;
2507 *ret_nseqs = 0;
2508 return status;
2509 }
2510
2511 /* Function: create_info
2512 * Incept: EPN, Mon Jun 6 14:52:29 2011
2513 *
2514 * Purpose: Create (allocate and initalize) a WORKER_INFO object.
2515 *
2516 * Returns: The new WORKER_INFO is returned. NULL is returned upon an error.
2517 */
2518 WORKER_INFO *
2519 create_info(const ESL_GETOPTS *go)
2520 {
2521 int status;
2522 WORKER_INFO *info = NULL;
2523
2524 ESL_ALLOC(info, sizeof(WORKER_INFO));
2525 info->pli = NULL;
2526 info->th = NULL;
2527 info->cm = NULL;
2528 info->gm = NULL;
2529 info->Rgm = NULL;
2530 info->Lgm = NULL;
2531 info->Tgm = NULL;
2532 info->om = NULL;
2533 info->bg = NULL;
2534 info->msvdata = NULL;
2535 ESL_ALLOC(info->p7_evparam, sizeof(float) * CM_p7_NEVPARAM);
2536 info->smxsize = esl_opt_GetReal(go, "--smxsize");
2537 return info;
2538
2539 ERROR:
2540 if(info != NULL) free(info);
2541 return NULL;
2542 }
2543
2544 /* Function: clone_info
2545 * Incept: EPN, Mon Jun 6 10:24:21 2011
2546 *
2547 * Purpose: Given a template WORKER_INFO <tinfo>, clone it into the
2548 * <dest_infocnt> WORKER_INFOs in <dest_infoA>. After cloning the CM,
2549 * configure it.
2550 *
2551 * Returns: <eslOK> on success.
2552 * <eslEMEM> if out of memory, errbuf filled.
2553 */
2554 int
2555 clone_info(ESL_GETOPTS *go, WORKER_INFO *src_info, WORKER_INFO *dest_infoA, int dest_infocnt, char *errbuf)
2556 {
2557 int status;
2558 int i;
2559
2560 for (i = 0; i < dest_infocnt; ++i) {
2561 if((status = cm_Clone(src_info->cm, errbuf, &(dest_infoA[i].cm))) != eslOK) return status;
2562 if((dest_infoA[i].gm = p7_profile_Clone(src_info->gm)) == NULL) goto ERROR;
2563 dest_infoA[i].Rgm = dest_infoA[i].Lgm = dest_infoA[i].Tgm = NULL; /* changed below if nec */
2564 if(src_info->Rgm != NULL) { if((dest_infoA[i].Rgm = p7_profile_Clone(src_info->Rgm)) == NULL) goto ERROR; }
2565 if(src_info->Lgm != NULL) { if((dest_infoA[i].Lgm = p7_profile_Clone(src_info->Lgm)) == NULL) goto ERROR; }
2566 if(src_info->Tgm != NULL) { if((dest_infoA[i].Tgm = p7_profile_Clone(src_info->Tgm)) == NULL) goto ERROR; }
2567 if((dest_infoA[i].om = p7_oprofile_Clone(src_info->om)) == NULL) goto ERROR;
2568 if((dest_infoA[i].bg = p7_bg_Create(src_info->bg->abc)) == NULL) goto ERROR;
2569 if(dest_infoA[i].p7_evparam == NULL) ESL_ALLOC(dest_infoA[i].p7_evparam, sizeof(float) * CM_p7_NEVPARAM);
2570 esl_vec_FCopy(src_info->cm->fp7_evparam, CM_p7_NEVPARAM, dest_infoA[i].p7_evparam);
2571 dest_infoA[i].msvdata = p7_hmm_ScoreDataClone(src_info->msvdata, src_info->om->abc->Kp);
2572 }
2573 return eslOK;
2574
2575 ERROR:
2576 ESL_FAIL(status, errbuf, "clone_info(): out of memory");
2577 }
2578
2579 /* Function: free_info
2580 * Incept: EPN, Mon Jun 6 10:46:27 2011
2581 *
2582 * Purpose: Free a WORKER_INFO object.
2583 *
2584 * Returns: void. Dies immediately upon an error.
2585 */
2586 void
2587 free_info(WORKER_INFO *info)
2588 {
2589 if(info->pli != NULL) { cm_pipeline_Destroy(info->pli, info->cm); info->pli = NULL; }
2590 if(info->th != NULL) { cm_tophits_Destroy(info->th); info->th = NULL; }
2591 if(info->cm != NULL) { FreeCM(info->cm); info->cm = NULL; }
2592 if(info->om != NULL) { p7_oprofile_Destroy(info->om); info->om = NULL; }
2593 if(info->gm != NULL) { p7_profile_Destroy(info->gm); info->gm = NULL; }
2594 if(info->Rgm != NULL) { p7_profile_Destroy(info->Rgm); info->Rgm = NULL; }
2595 if(info->Lgm != NULL) { p7_profile_Destroy(info->Lgm); info->Lgm = NULL; }
2596 if(info->Tgm != NULL) { p7_profile_Destroy(info->Tgm); info->Tgm = NULL; }
2597 if(info->bg != NULL) { p7_bg_Destroy(info->bg); info->bg = NULL; }
2598 if(info->p7_evparam != NULL) { free(info->p7_evparam); info->p7_evparam = NULL; }
2599 if(info->msvdata != NULL) { p7_hmm_ScoreDataDestroy(info->msvdata); info->msvdata = NULL; }
2600
2601 return;
2602 }
2603
2604 /* Function: configure_cm()
2605 * Incept: EPN, Mon Jun 6 12:06:38 2011
2606 *
2607 * Purpose: Given a WORKER_INFO <info> with a valid CM just read from
2608 * a file and config_opts from <info->pli>, configure the CM.
2609 * We use pli->cm_config_opts created in cm_pipeline_Create()
2610 * so that cmscan and cmsearch create config_opts identically
2611 * based on their common esl_getopts object.
2612 *
2613 * Also create all the structures related to the p7 HMM
2614 * filter.
2615 *
2616 * Returns: eslOK on success. Upon an error, fills errbuf with
2617 * message and returns appropriate error status code.
2618 */
2619 int
2620 configure_cm(WORKER_INFO *info)
2621 {
2622 int status;
2623 float reqMb = 0.;
2624 int check_fcyk_beta; /* TRUE if we need to check if cm's beta1 == info->pli->fcyk_beta */
2625 int check_final_beta; /* TRUE if we need to check if cm's beta2 == info->pli->final_beta */
2626 int W_from_cmdline; /* -1 (W not set on cmdline) unless pli->use_wcx is TRUE, which means --wcx was enabled */
2627
2628 if(info->pli->cm_config_opts & CM_CONFIG_SCANMX) reqMb += cm_scan_mx_SizeNeeded(info->cm, TRUE, TRUE);
2629 if(info->pli->cm_config_opts & CM_CONFIG_TRSCANMX) reqMb += cm_tr_scan_mx_SizeNeeded(info->cm, TRUE, TRUE);
2630 if(reqMb > info->smxsize) {
2631 ESL_FAIL(eslERANGE, info->pli->errbuf, "search will require %.2f Mb > %.2f Mb limit.\nIncrease limit with --smxsize, or don't use --max,--nohmm,--qdb,--fqdb.", reqMb, info->smxsize);
2632 }
2633
2634 /* cm_pipeline_Create() sets configure/align options in pli->cm_config_opts, pli->cm_align_opts */
2635 info->cm->config_opts = info->pli->cm_config_opts;
2636 info->cm->align_opts = info->pli->cm_align_opts;
2637
2638 /* check if we need to recalculate QDBs prior to building the scan matrix in cm_Configure() */
2639 check_fcyk_beta = (info->pli->fcyk_cm_search_opts & CM_SEARCH_QDB) ? TRUE : FALSE;
2640 check_final_beta = (info->pli->final_cm_search_opts & CM_SEARCH_QDB) ? TRUE : FALSE;
2641 if((status = CheckCMQDBInfo(info->cm->qdbinfo, info->pli->fcyk_beta, check_fcyk_beta, info->pli->final_beta, check_final_beta)) != eslOK) {
2642 info->cm->config_opts |= CM_CONFIG_QDB;
2643 info->cm->qdbinfo->beta1 = info->pli->fcyk_beta;
2644 info->cm->qdbinfo->beta2 = info->pli->final_beta;
2645 }
2646 /* else we don't have to change (*opt_cm)->qdbinfo->beta1/beta2 */
2647
2648 W_from_cmdline = info->pli->do_wcx ? (int) (info->cm->clen * info->pli->wcx) : -1; /* -1: use W from CM file */
2649 if((status = cm_Configure(info->cm, info->pli->errbuf, W_from_cmdline)) != eslOK) return status;
2650
2651 return eslOK;
2652 }
2653
2654 /* Function: setup_hmm_filter()
2655 * Incept: EPN, Mon Jun 6 11:31:42 2011
2656 *
2657 * Purpose: Given a WORKER_INFO <info> with a valid non-configured
2658 * CM (just read from a file), set up the HMM
2659 * filter related data in <info>.
2660 *
2661 * Note: this is separate from cm_Configure() only
2662 * because we need to call this before we call
2663 * clone_info(), but we have to call cm_Configure()
2664 * after we call clone_info() (only because we
2665 * can't clone a configured CM, just a non-configured
2666 * one).
2667 *
2668 * Returns: <eslOK> on success. Dies immediately upon an error.
2669 */
2670 int
2671 setup_hmm_filter(ESL_GETOPTS *go, WORKER_INFO *info)
2672 {
2673 int do_trunc_ends = (esl_opt_GetBoolean(go, "--notrunc") || esl_opt_GetBoolean(go, "--inttrunc")) ? FALSE : TRUE;
2674
2675 /* set up the HMM filter-related structures */
2676 info->gm = p7_profile_Create (info->cm->fp7->M, info->cm->abc);
2677 info->om = p7_oprofile_Create(info->cm->fp7->M, info->cm->abc);
2678 info->bg = p7_bg_Create(info->cm->abc);
2679 p7_ProfileConfig(info->cm->fp7, info->bg, info->gm, 100, p7_LOCAL); /* 100 is a dummy length for now; and MSVFilter requires local mode */
2680 p7_oprofile_Convert(info->gm, info->om); /* <om> is now p7_LOCAL, multihit */
2681 /* clone gm into Tgm before putting it into glocal mode */
2682 if(do_trunc_ends) {
2683 info->Tgm = p7_profile_Clone(info->gm);
2684 }
2685 /* after om has been created, convert gm to glocal, to define envelopes in cm_pipeline() */
2686 p7_ProfileConfig(info->cm->fp7, info->bg, info->gm, 100, p7_GLOCAL);
2687
2688 if(do_trunc_ends) {
2689 /* create Rgm, Lgm, and Tgm specially-configured profiles for defining envelopes around
2690 * hits that may be truncated 5' (Rgm), 3' (Lgm) or both (Tgm). */
2691 info->Rgm = p7_profile_Clone(info->gm);
2692 info->Lgm = p7_profile_Clone(info->gm);
2693 /* info->Tgm was created when gm was still in local mode above */
2694 /* we cloned Tgm from the while profile was still locally configured, above */
2695 p7_ProfileConfig5PrimeTrunc (info->Rgm, 100);
2696 p7_ProfileConfig3PrimeTrunc (info->cm->fp7, info->Lgm, 100);
2697 p7_ProfileConfig5PrimeAnd3PrimeTrunc(info->Tgm, 100);
2698 }
2699 else {
2700 info->Rgm = NULL;
2701 info->Lgm = NULL;
2702 info->Tgm = NULL;
2703 }
2704
2705 /* copy E-value parameters */
2706 esl_vec_FCopy(info->cm->fp7_evparam, CM_p7_NEVPARAM, info->p7_evparam);
2707
2708 /* compute msvdata */
2709 info->msvdata = p7_hmm_ScoreDataCreate(info->om, FALSE);
2710
2711 return eslOK;
2712 }
2713
2714 #ifdef HAVE_MPI
2715 /* mpi_failure()
2716 * Generate an error message. If the clients rank is not 0, a
2717 * message is created with the error message and sent to the
2718 * master process for handling.
2719 */
2720 static void
2721 mpi_failure(char *format, ...)
2722 {
2723 va_list argp;
2724 int status = eslFAIL;
2725 int len;
2726 int rank;
2727 char str[512];
2728
2729 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
2730
2731 /* format the error mesg */
2732 va_start(argp, format);
2733 len = vsnprintf(str, sizeof(str), format, argp);
2734 va_end(argp);
2735
2736 /* make sure the error string is terminated */
2737 str[sizeof(str)-1] = '\0';
2738
2739 /* if the caller is the master, print the results and abort */
2740 if (rank == 0) {
2741 fprintf(stderr, "\nError: ");
2742 fprintf(stderr, "%s", str);
2743 fprintf(stderr, "\n");
2744 fflush(stderr);
2745
2746 MPI_Abort(MPI_COMM_WORLD, status);
2747 exit(1);
2748 }
2749 else {
2750 MPI_Send(str, len, MPI_CHAR, 0, INFERNAL_ERROR_TAG, MPI_COMM_WORLD);
2751 pause();
2752 }
2753 }
2754
2755 /* Function: mpi_open_dbfile_ssi
2756 * Synopsis: Open database file's SSI index. Only used in MPI mode.
2757 * Incept: EPN, Wed Jun 8 07:19:49 2011
2758 *
2759 * Returns: eslOK on succes.
2760 * Upon error, error status is returned, and errbuf is filled.
2761 */
2762 static int
2763 mpi_open_dbfile_ssi(ESL_GETOPTS *go, struct cfg_s *cfg, ESL_SQFILE *dbfp, char *errbuf)
2764 {
2765 int status;
2766
2767 if (dbfp->data.ascii.do_gzip) ESL_FAIL(eslEFORMAT, errbuf, "Reading gzipped sequence files is not supported with --mpi.");
2768 if (dbfp->data.ascii.do_stdin) ESL_FAIL(eslEFORMAT, errbuf, "Reading sequence files from stdin is not supported with --mpi.");
2769 status = esl_sqfile_OpenSSI(dbfp, NULL);
2770 if (status == eslEFORMAT) ESL_FAIL(status, errbuf, "SSI index for database file is in incorrect format\n");
2771 else if (status == eslERANGE) ESL_FAIL(status, errbuf, "SSI index for database file is in 64-bit format and we can't read it\n");
2772 else if (status != eslOK) ESL_FAIL(status, errbuf, "Failed to open SSI index, use esl-sfetch to index the database file.\n");
2773
2774 return status;
2775 }
2776
2777 /* Function: mpi_dbsize_using_ssi
2778 * Synopsis: Determine size of the database using SSI index. Only used in MPI mode.
2779 * Incept: EPN, Mon Jun 6 09:17:32 2011
2780 *
2781 * Returns: eslOK on success. cfg->Z is set.
2782 * Upon error, error status is returned and errbuf is filled.
2783 *
2784 */
2785 static int
2786 mpi_dbsize_using_ssi(ESL_GETOPTS *go, struct cfg_s *cfg, ESL_SQFILE *dbfp, char *errbuf)
2787 {
2788 int status;
2789 int64_t L;
2790 int i;
2791
2792 if(dbfp->data.ascii.ssi == NULL) ESL_FAIL(eslEINVAL, errbuf, "SSI index failed to open");
2793
2794 /* step through sequence SSI file to get database size */
2795 cfg->Z = 0;
2796 for(i = 0; i < dbfp->data.ascii.ssi->nprimary; i++) {
2797 status = esl_ssi_FindNumber(dbfp->data.ascii.ssi, i, NULL, NULL, NULL, &L, NULL);
2798 if(status == eslENOTFOUND) ESL_FAIL(status, errbuf, "unable to find sequence %d in SSI index file, try re-indexing with esl-sfetch.", i);
2799 if(status == eslEFORMAT) ESL_FAIL(status, errbuf, "SSI index for database file is in incorrect format.");
2800 if(status != eslOK) ESL_FAIL(status, errbuf, "problem with SSI index for database file.");
2801 cfg->Z += L;
2802 }
2803 if((! esl_opt_GetBoolean(go, "--toponly")) &&
2804 (! esl_opt_GetBoolean(go, "--bottomonly"))) {
2805 cfg->Z *= 2; /* we're searching both strands */
2806 }
2807 cfg->Z_setby = CM_ZSETBY_SSIINFO;
2808
2809 return eslOK;
2810 }
2811
2812
2813 /* Function: mpi_add_blocks()
2814 * Synopsis: Adds >= 1 new blocks to a MPI_BLOCK_LIST.
2815 * Incept: EPN, Tue Jun 7 09:27:34 2011
2816 *
2817 * Purpose: Determines at least 1 new MPI_BLOCK to send to a MPI
2818 * worker by inspecting (via SSI info) 1 more
2819 * sequence in the input file. If the first sequence
2820 * inspected contains more than one block, then all blocks
2821 * necessary to include that full sequence will be added to
2822 * <block_list>. If the first sequence inspected does not
2823 * contain enough residues to fill a block, more sequences
2824 * will be looked at until at least one block is filled.
2825 *
2826 * It is probable that the final block added to
2827 * <block_list> will be incomplete, in which case the next
2828 * call to this function will complete it.
2829 *
2830 * Likewise, upon entering, <block_list> should not be
2831 * empty, but rather contain exactly 1 incomplete block,
2832 * that has either been started to be calculated by a
2833 * previous call to next_block(), or that has just been
2834 * initialized (which happens when this function is called
2835 * for the first time, for example, and may happen later
2836 * if the previous call finished its final block with
2837 * the end of its sequence).
2838 *
2839 * Returns: <eslOK> on success and <block_list->blocks[0]> is
2840 * a complete block.
2841 * (i.e <block_list->blocks[0]->complete == TRUE>)
2842 * If !eslOK, errbuf is filled and caller should
2843 * exit with mpi_failure(). See 'Returns:'
2844 * section of inpsect_next_sequence_using_ssi()
2845 * for list of non-OK error return codes.
2846 */
2847 int
2848 mpi_add_blocks(ESL_SQFILE *dbfp, ESL_SQ *sq, int64_t ncontext, char *errbuf, int64_t final_pkey_idx, MPI_BLOCK_LIST *block_list, int64_t *ret_pkey_idx, int64_t *ret_noverlap, int64_t *ret_nseq)
2849 {
2850 int status = eslOK; /* error code status */
2851 int64_t pkey_idx;
2852 int64_t noverlap = 0;
2853 int64_t tot_noverlap = 0;
2854 int64_t nseq = 0;
2855
2856 /* Contract check, SSI should be valid */
2857 if(dbfp->data.ascii.ssi == NULL) ESL_FAIL(eslEINVAL, errbuf, "No SSI index available (it should've been opened earlier)");
2858 /* we should have exactly 1 non-complete block */
2859 if(block_list->N != 1 || block_list->blocks == NULL || block_list->blocks[0]->complete) {
2860 ESL_FAIL(eslFAIL, errbuf, "contract violation in next_block, block_list does not contain exactly 1 incomplete block");
2861 }
2862
2863 status = eslOK;
2864 pkey_idx = *ret_pkey_idx;
2865 /* read sequences until we have at least 1 complete block to send to a worker */
2866 while((pkey_idx <= final_pkey_idx) && (! block_list->blocks[0]->complete)) {
2867 status = mpi_inspect_next_sequence_using_ssi(dbfp, sq, ncontext, pkey_idx, errbuf, block_list, &noverlap);
2868 nseq++;
2869 if(block_list == NULL) ESL_FAIL(eslFAIL, errbuf, "error parsing database in add_blocks()");
2870 pkey_idx++;
2871 tot_noverlap += noverlap;
2872 }
2873 if(pkey_idx == (final_pkey_idx+1) && (! block_list->blocks[block_list->N-1]->complete)) {
2874 /* We reached the end of the file and didn't finish the final
2875 * block. If it's non-empty then it's valid, else it's not. */
2876 if(block_list->blocks[block_list->N-1]->blockL > 0) { /* valid */
2877 block_list->blocks[block_list->N-1]->complete = TRUE;
2878 }
2879 else {
2880 /* final block was initialized but doesn't correspond to any sequence yet, destroy it */
2881 free(block_list->blocks[block_list->N-1]);
2882 block_list->blocks[block_list->N-1] = NULL;
2883 block_list->N--;
2884 }
2885 }
2886
2887 #if eslDEBUGLEVEL >= 1
2888 printf("\nEnd of add_blocks()\n");
2889 dump_mpi_block_list(stdout, block_list);
2890 printf("\n");
2891 #endif
2892
2893 *ret_pkey_idx = pkey_idx;
2894 *ret_noverlap = tot_noverlap;
2895 *ret_nseq = nseq;
2896
2897 return status;
2898
2899 }
2900
2901 /* Function: mpi_inspect_next_sequence_using_ssi()
2902 * Synopsis: Inspect a database sequence and update MPI_BLOCK_LIST.
2903 * Incept: EPN, Tue Jun 7 07:41:02 2011
2904 *
2905 * Purpose: Uses SSI indexing to gather information on the next
2906 * sequence in <dbfp> and add that information to a
2907 * <block_list>. This will update the information in
2908 * at least one block in the list, potentially finishing
2909 * one block and creating and potentially finishing
2910 * more blocks, depending on the length of the sequence.
2911 *
2912 * Returns: <eslOK> on success and <block_list> is updated.
2913 * If we return any other status code besides eslOK or
2914 * eslEOF, errbuf will be filled and caller should
2915 * exit with mpi_failure().
2916 * <eslFAIL> if SSI index is unavailable (this shouldn't
2917 * happen though, as we checked for it before).
2918 * <eslENOTFOUND> if sequence is not in the SSI index.
2919 * <eslEFORMAT> if SSI index is in wrong format.
2920 */
2921 int
2922 mpi_inspect_next_sequence_using_ssi(ESL_SQFILE *dbfp, ESL_SQ *sq, int64_t ncontext, int64_t pkey_idx, char *errbuf, MPI_BLOCK_LIST *block_list, int64_t *ret_noverlap)
2923 {
2924 int status; /* error code status */
2925 int64_t L; /* length of sequence */
2926 int64_t ntoadd; /* max length of sequence we could still add to a incomplete block */
2927 int64_t seq_from; /* start index of subsequence */
2928 int64_t nremaining; /* number of residues for the sequence not yet assigned to any block */
2929 int64_t tot_noverlap = 0; /* number of residues that exist in more than one block due to overlaps */
2930 int64_t cur_noverlap = 0; /* for current sequence chunk, # of residues that will overlap with next chunk */
2931 MPI_BLOCK *cur_block = NULL; /* pointer to current block we are working on */
2932
2933 /* Contract check */
2934 if(dbfp->data.ascii.ssi == NULL) ESL_FAIL(eslEINVAL, errbuf, "No SSI index available (it should've been opened earlier)");
2935
2936 /* Get length of 'next' sequence (next sequence in list of
2937 * primary keys in SSI index, probably not the next sequence
2938 * in the file) */
2939 status = esl_ssi_FindNumber(dbfp->data.ascii.ssi, pkey_idx, NULL, NULL, NULL, &L, NULL);
2940 /*
2941 char *tmpname;
2942 status = esl_ssi_FindNumber(dbfp->data.ascii.ssi, pkey_idx, NULL, NULL, NULL, &L, &tmpname);
2943 printf("mpi_inspect_next_sequence_using_ssi(): sequence name: %s length %" PRId64 "\n", tmpname, L);
2944 */
2945 if(status == eslENOTFOUND) ESL_FAIL(status, errbuf, "unable to find sequence %ld in SSI index file, try re-indexing with esl-sfetch.", pkey_idx);
2946 if(status == eslEFORMAT) ESL_FAIL(status, errbuf, "SSI index for database file is in incorrect format.");
2947 if(status != eslOK) ESL_FAIL(status, errbuf, "problem with SSI index for database file.");
2948
2949
2950 /* Create a new block list if necessary */
2951 if(block_list == NULL) {
2952 /* This should only happen on first call to this function, or if
2953 * by chance the previous sequence (inspected with the previous
2954 * call to next_sequence_using_ssi()) filled its final block
2955 * exactly full, with no remaining residues with which to start a
2956 * new block. */
2957 block_list = create_mpi_block_list();
2958 /* add first block */
2959 block_list->blocks[0] = create_mpi_block();
2960 block_list->N++;
2961 }
2962
2963 /* Now fill in >= 1 blocks with this sequence.
2964 * Chop the sequence up into overlapping chunks of max size
2965 * CM_MAX_RESIDUE_COUNT (not including any overlap). The final
2966 * chunk (which may be the only chunk) will probably be less than
2967 * CM_MAX_RESIDUE_COUNT residues. Add the chunk(s) to as many
2968 * blocks as necessary, creating all blocks except the first one as
2969 * we go, to get rid of all the chunks. Each block will get exactly
2970 * 1 chunk.
2971 */
2972 cur_block = block_list->blocks[0];
2973 nremaining = L;
2974 cur_noverlap = 0; /* first chunk of this sequence, we haven't required any overlapping residues yet */
2975 while(nremaining > 0) {
2976 ntoadd = CM_MAX_RESIDUE_COUNT + cur_noverlap; /* max number residues we can add to cur_block */
2977 ntoadd = ESL_MIN(ntoadd, nremaining);
2978 if(cur_block->blockL == 0) { /* this block was just created */
2979 cur_block->first_idx = pkey_idx;
2980 }
2981 cur_block->final_idx = pkey_idx; /* this may be changed by a subsequent call to this function */
2982 if(nremaining <= ntoadd) {
2983 /* Case 1: We can fit all remaining sequence in current block */
2984 if(cur_block->blockL == 0) {
2985 cur_block->first_from = (L - nremaining) + 1;
2986 }
2987 cur_block->final_to = L;
2988 cur_block->blockL += nremaining;
2989 if(cur_block->blockL >= CM_MAX_RESIDUE_COUNT) {
2990 cur_block->complete = TRUE;
2991 }
2992 /* update nremaining, this will break us out of the while() */
2993 nremaining = 0;
2994 }
2995 else {
2996 /* Case 2: We can't fit all of the remaining sequence in current
2997 * block, add the first <ntoadd> residues to it, and
2998 * then make a new block for the remaining sequence
2999 * (plus an overlap of ncontext residues). The new block
3000 * is made below, outside of this else.
3001 */
3002 seq_from = L - nremaining + 1;
3003 if(cur_block->blockL == 0) {
3004 cur_block->first_from = seq_from;
3005 }
3006 cur_block->final_to = seq_from + ntoadd - 1;
3007 cur_block->blockL += ntoadd;
3008 cur_block->complete = TRUE;
3009
3010 /* determine the number of residues in next block that will overlap,
3011 * our current seq position end point is (seq_from + ntoadd - 1),
3012 * so cur_noverlap can't exceed this */
3013 cur_noverlap = ESL_MIN(ncontext, (seq_from + ntoadd - 1));
3014
3015 /* update nremaining */
3016 nremaining -= (ntoadd - cur_noverlap); /* <cur_noverlap> residues will overlap between this block and the next one */
3017 tot_noverlap += cur_noverlap;
3018 }
3019
3020 /* create a new block if necessary */
3021 if(cur_block->complete) {
3022 if(block_list->N == block_list->nalloc) {
3023 ESL_REALLOC(block_list->blocks, sizeof(MPI_BLOCK *) * (block_list->nalloc+100));
3024 block_list->nalloc += 100;
3025 }
3026 cur_block = create_mpi_block();
3027 block_list->blocks[block_list->N++] = cur_block;
3028 }
3029 }
3030 *ret_noverlap = tot_noverlap;
3031
3032 return status;
3033
3034 ERROR:
3035 ESL_FAIL(status, errbuf, "out of memory");
3036 }
3037
3038 MPI_BLOCK *
3039 create_mpi_block()
3040 {
3041 int status;
3042
3043 MPI_BLOCK *block = NULL;
3044 ESL_ALLOC(block, sizeof(MPI_BLOCK));
3045
3046 block->first_idx = -1;
3047 block->final_idx = -1;
3048 block->first_from = 0;
3049 block->final_to = 0;
3050 block->blockL = 0;
3051 block->complete = FALSE;
3052
3053 return block;
3054
3055 ERROR:
3056 if(block != NULL) free(block);
3057 return NULL;
3058 }
3059
3060 #if eslDEBUGLEVEL >= 1
3061 void
3062 dump_mpi_block(FILE *fp, MPI_BLOCK *block)
3063 {
3064
3065 fprintf(fp, "MPI_BLOCK:\n");
3066 fprintf(fp, "%-15s: %ld\n", "first_idx", block->first_idx);
3067 fprintf(fp, "%-15s: %ld\n", "final_idx", block->final_idx);
3068 fprintf(fp, "%-15s: %ld\n", "first_from", block->first_from);
3069 fprintf(fp, "%-15s: %ld\n", "final_to", block->final_to);
3070 fprintf(fp, "%-15s: %ld\n", "blockL", block->blockL);
3071 fprintf(fp, "%-15s: %d\n", "complete", block->complete);
3072
3073 return;
3074 }
3075
3076 void
3077 dump_mpi_block_list(FILE *fp, MPI_BLOCK_LIST *list)
3078 {
3079 int i;
3080
3081 fprintf(fp, "MPI_BLOCK_LIST:\n");
3082 fprintf(fp, "%-15s: %d\n", "N", list->N);
3083 fprintf(fp, "%-15s: %d\n", "nalloc", list->nalloc);
3084 for(i = 0; i < list->N; i++) {
3085 dump_mpi_block(fp, list->blocks[i]);
3086 }
3087
3088 return;
3089 }
3090 #endif
3091
3092 MPI_BLOCK_LIST *
3093 create_mpi_block_list()
3094 {
3095 int status;
3096
3097 MPI_BLOCK_LIST *list = NULL;
3098 ESL_ALLOC(list, sizeof(MPI_BLOCK_LIST));
3099
3100 list->blocks = NULL;
3101 ESL_ALLOC(list->blocks, sizeof(MPI_BLOCK *) * (100));
3102 list->N = 0;
3103 list->nalloc = 100;
3104
3105 return list;
3106
3107 ERROR:
3108 if(list != NULL) free(list);
3109 return NULL;
3110 }
3111
3112 void
3113 free_mpi_block_list(MPI_BLOCK_LIST *list)
3114 {
3115 int i;
3116 if(list->blocks != NULL) {
3117 for(i = 0; i < list->N; i++) {
3118 free(list->blocks[i]);
3119 }
3120 free(list->blocks);
3121 }
3122 free(list);
3123
3124 return;
3125 }
3126
3127
3128
3129 /* Function: mpi_block_send()
3130 * Synopsis: Send a MPI_BLOCK in an MPI buffer.
3131 * Incept: EPN, Mon Jun 6 19:49:44 2011
3132 */
3133 int
3134 mpi_block_send(MPI_BLOCK *block, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc)
3135 {
3136 int status;
3137 int pos;
3138 int n;
3139
3140 /* calculate the buffer size needed to hold the MPI_BLOCK */
3141 if ((status = mpi_block_pack_size(block, comm, &n)) != eslOK) goto ERROR;
3142
3143 /* Make sure the buffer is allocated appropriately */
3144 if (*buf == NULL || n > *nalloc) {
3145 void *tmp;
3146 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
3147 *nalloc = n;
3148 }
3149
3150 /* Pack the MPI_BLOCK into the buffer */
3151 pos = 0;
3152 if ((status = mpi_block_pack(block, *buf, n, &pos, comm)) != eslOK) goto ERROR;
3153
3154 /* Send the packed MPI_BLOCK to the destination. */
3155 if (MPI_Send(*buf, n, MPI_PACKED, dest, tag, comm) != 0) ESL_EXCEPTION(eslESYS, "mpi send failed");
3156
3157 return eslOK;
3158
3159 ERROR:
3160 return status;
3161
3162 }
3163
3164 /* Function: mpi_block_recv()
3165 * Synopsis: Receive a MPI_BLOCK in an MPI buffer.
3166 * Incept: EPN, Mon Jun 6 19:47:20 2011
3167 */
3168 int
3169 mpi_block_recv(int source, int tag, MPI_Comm comm, char **buf, int *nalloc, MPI_BLOCK **ret_block)
3170 {
3171 int n;
3172 int status;
3173 int pos;
3174 MPI_Status mpistatus;
3175
3176 /* Probe first, because we need to know if our buffer is big enough.
3177 */
3178 MPI_Probe(source, tag, comm, &mpistatus);
3179 MPI_Get_count(&mpistatus, MPI_PACKED, &n);
3180
3181 /* make sure we are getting the tag we expect and from whom we expect if from */
3182 if (tag != MPI_ANY_TAG && mpistatus.MPI_TAG != tag) {
3183 status = eslFAIL;
3184 goto ERROR;
3185 }
3186 if (source != MPI_ANY_SOURCE && mpistatus.MPI_SOURCE != source) {
3187 status = eslFAIL;
3188 goto ERROR;
3189 }
3190
3191 /* set the source and tag */
3192 tag = mpistatus.MPI_TAG;
3193 source = mpistatus.MPI_SOURCE;
3194
3195 /* Make sure the buffer is allocated appropriately */
3196 if (*buf == NULL || n > *nalloc) {
3197 void *tmp;
3198 ESL_RALLOC(*buf, tmp, sizeof(char) * n);
3199 *nalloc = n;
3200 }
3201
3202 /* Receive the packed top hits */
3203 MPI_Recv(*buf, n, MPI_PACKED, source, tag, comm, &mpistatus);
3204
3205 /* Unpack it - watching out for the EOD signal of M = -1. */
3206 pos = 0;
3207 if ((status = mpi_block_unpack(*buf, n, &pos, comm, ret_block)) != eslOK) goto ERROR;
3208
3209 return eslOK;
3210
3211 ERROR:
3212 return status;
3213 }
3214
3215 /* Function: mpi_block_pack_size()
3216 * Synopsis: Calculates size needed to pack a sequence block.
3217 * Incept: EPN, Mon Jun 6 19:18:15 2011
3218 *
3219 * Returns: <eslOK> on success, and <*ret_n> contains the answer.
3220 *
3221 * Throws: <eslESYS> if an MPI call fails, and <*ret_n> is 0.
3222 */
3223 int
3224 mpi_block_pack_size(MPI_BLOCK *block, MPI_Comm comm, int *ret_n)
3225 {
3226 int status;
3227 int n = 0;
3228 int sz;
3229
3230 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; /* first_idx */
3231 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; /* final_idx */
3232 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; /* first_from */
3233 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; /* final_to */
3234 if (MPI_Pack_size(1, MPI_LONG_LONG_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; /* blockL */
3235 if (MPI_Pack_size(1, MPI_INT, comm, &sz) != 0) ESL_XEXCEPTION(eslESYS, "pack size failed"); n += sz; /* complete */
3236
3237 *ret_n = n;
3238 return eslOK;
3239
3240 ERROR:
3241 *ret_n = 0;
3242 return status;
3243 }
3244
3245 /* Function: mpi_block_pack()
3246 * Synopsis: Packs a MPI_BLOCK into MPI buffer.
3247 * Incept: EPN, Mon Jun 6 19:42:01 2011
3248 *
3249 * Returns: <eslOK> on success; <buf> now contains the
3250 * packed <hit>, and <*position> is set to the byte
3251 * immediately following the last byte of the HIT
3252 * in <buf>.
3253 *
3254 * Throws: <eslESYS> if an MPI call fails; or <eslEMEM> if the
3255 * buffer's length <n> was overflowed in trying to pack
3256 * <msa> into <buf>. In either case, the state of
3257 * <buf> and <*position> is undefined, and both should
3258 * be considered to be corrupted.
3259 */
3260 int
3261 mpi_block_pack(MPI_BLOCK *block, char *buf, int n, int *pos, MPI_Comm comm)
3262 {
3263 int status;
3264
3265 if (MPI_Pack(&block->first_idx, 1, MPI_LONG_LONG_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
3266 if (MPI_Pack(&block->final_idx, 1, MPI_LONG_LONG_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
3267 if (MPI_Pack(&block->first_from, 1, MPI_LONG_LONG_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
3268 if (MPI_Pack(&block->final_to, 1, MPI_LONG_LONG_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
3269 if (MPI_Pack(&block->blockL, 1, MPI_LONG_LONG_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
3270 if (MPI_Pack(&block->complete, 1, MPI_INT, buf, n, pos, comm) != 0) ESL_XEXCEPTION(eslESYS, "pack failed");
3271
3272 if (*pos > n) ESL_EXCEPTION(eslEMEM, "buffer overflow");
3273 return eslOK;
3274
3275 ERROR:
3276 return status;
3277 }
3278
3279 /* Function: mpi_block_unpack()
3280 * Synopsis: Unpacks a MPI_BLOCK from an MPI buffer.
3281 * Incept: EPN, Mon Jun 6 19:43:49 2011
3282 *
3283 * Returns: <eslOK> on success. <*pos> is updated to the position of
3284 * the next element in <buf> to unpack (if any). <*ret_block>
3285 * contains a newly allocated MPI_BLOCK, which the caller is
3286 * responsible for free'ing.
3287 *
3288 * Throws: <eslESYS> on an MPI call failure. <eslEMEM> on allocation failure.
3289 * In either case, <*ret_hit> is <NULL>, and the state of <buf>
3290 * and <*pos> is undefined and should be considered to be corrupted.
3291 */
3292 int
3293 mpi_block_unpack(char *buf, int n, int *pos, MPI_Comm comm, MPI_BLOCK **ret_block)
3294 {
3295 int status;
3296 MPI_BLOCK *block;
3297
3298 ESL_ALLOC(block, sizeof(MPI_BLOCK));
3299
3300 if (MPI_Unpack(buf, n, pos, &block->first_idx, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
3301 if (MPI_Unpack(buf, n, pos, &block->final_idx, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
3302 if (MPI_Unpack(buf, n, pos, &block->first_from, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
3303 if (MPI_Unpack(buf, n, pos, &block->final_to, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
3304 if (MPI_Unpack(buf, n, pos, &block->blockL, 1, MPI_LONG_LONG_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
3305 if (MPI_Unpack(buf, n, pos, &block->complete, 1, MPI_INT, comm) != 0) ESL_XEXCEPTION(eslESYS, "mpi unpack failed");
3306
3307 *ret_block = block;
3308
3309 return eslOK;
3310
3311 ERROR:
3312 return status;
3313 }
3314 #endif
3315
3316