Debian Codegraph @

src/cmscan.c

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