| 1 |
|
| 2 |
|
| 3 |
#include <p7_config.h> |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <stdlib.h> |
| 7 |
#include <string.h> |
| 8 |
|
| 9 |
#include "easel.h" |
| 10 |
#include "esl_alphabet.h" |
| 11 |
#include "esl_getopts.h" |
| 12 |
#include "esl_sq.h" |
| 13 |
#include "esl_sqio.h" |
| 14 |
#include "esl_stopwatch.h" |
| 15 |
|
| 16 |
#ifdef HMMER_THREADS |
| 17 |
#include <unistd.h> |
| 18 |
#include "esl_threads.h" |
| 19 |
#include "esl_workqueue.h" |
| 20 |
#endif |
| 21 |
|
| 22 |
#include "hmmer.h" |
| 23 |
#include "esl_vectorops.h" |
| 24 |
|
| 25 |
|
| 26 |
typedef struct { |
| 27 |
#ifdef HMMER_THREADS |
| 28 |
ESL_WORK_QUEUE *queue; |
| 29 |
#endif |
| 30 |
ESL_SQ *qsq; |
| 31 |
P7_BG *bg; |
| 32 |
P7_BG *bg_default; |
| 33 |
P7_PIPELINE *pli; |
| 34 |
P7_TOPHITS *th; |
| 35 |
float *scores; |
| 36 |
float *fwd_emissions; |
| 37 |
} WORKER_INFO; |
| 38 |
|
| 39 |
#define REPOPTS "-E,-T,--cut_ga,--cut_nc,--cut_tc" |
| 40 |
#define DOMREPOPTS "--domE,--domT,--cut_ga,--cut_nc,--cut_tc" |
| 41 |
#define INCOPTS "--incE,--incT,--cut_ga,--cut_nc,--cut_tc" |
| 42 |
#define INCDOMOPTS "--incdomE,--incdomT,--cut_ga,--cut_nc,--cut_tc" |
| 43 |
#define THRESHOPTS "-E,-T,--domE,--domT,--incE,--incT,--incdomE,--incdomT,--cut_ga,--cut_nc,--cut_tc" |
| 44 |
|
| 45 |
#define CPUOPTS NULL |
| 46 |
#define MPIOPTS NULL |
| 47 |
|
| 48 |
static ESL_OPTIONS options[] = { |
| 49 |
|
| 50 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 1 }, |
| 51 |
|
| 52 |
{ "-o", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "direct output to file <f>, not stdout", 2 }, |
| 53 |
{ "--tblout", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "save parseable table of per-sequence hits to file <f>", 2 }, |
| 54 |
{ "--dfamtblout", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "save table of hits to file, in Dfam format <f>", 2 }, |
| 55 |
{ "--acc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "prefer accessions over names in output", 2 }, |
| 56 |
{ "--noali", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "don't output alignments, so output is smaller", 2 }, |
| 57 |
{ "--notextw", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, "--textw", "unlimit ASCII text output line width", 2 }, |
| 58 |
{ "--textw", eslARG_INT, "120", NULL, "n>=120",NULL, NULL, "--notextw", "set max width of ASCII text output lines", 2 }, |
| 59 |
|
| 60 |
|
| 61 |
{ "-E", eslARG_REAL, "10.0", NULL, "x>0", NULL, NULL, REPOPTS, "report models <= this E-value threshold in output", 4 }, |
| 62 |
{ "-T", eslARG_REAL, FALSE, NULL, NULL, NULL, NULL, REPOPTS, "report models >= this score threshold in output", 4 }, |
| 63 |
|
| 64 |
{ "--incE", eslARG_REAL, "0.01", NULL, "x>0", NULL, NULL, INCOPTS, "consider models <= this E-value threshold as significant", 5 }, |
| 65 |
{ "--incT", eslARG_REAL, FALSE, NULL, NULL, NULL, NULL, INCOPTS, "consider models >= this score threshold as significant", 5 }, |
| 66 |
|
| 67 |
{ "--cut_ga", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, THRESHOPTS, "use profile's GA gathering cutoffs to set all thresholding", 6 }, |
| 68 |
{ "--cut_nc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, THRESHOPTS, "use profile's NC noise cutoffs to set all thresholding", 6 }, |
| 69 |
{ "--cut_tc", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, THRESHOPTS, "use profile's TC trusted cutoffs to set all thresholding", 6 }, |
| 70 |
|
| 71 |
{ "--max", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "--F1,--F2,--F3", "Turn all heuristic filters off (less speed, more power)", 7 }, |
| 72 |
{ "--F1", eslARG_REAL, "0.02", NULL, NULL, NULL, NULL, "--max", "MSV threshold: promote hits w/ P <= F1", 7 }, |
| 73 |
{ "--F2", eslARG_REAL, "3e-3", NULL, NULL, NULL, NULL, "--max", "Vit threshold: promote hits w/ P <= F2", 7 }, |
| 74 |
{ "--F3", eslARG_REAL, "3e-5", NULL, NULL, NULL, NULL, "--max", "Fwd threshold: promote hits w/ P <= F3", 7 }, |
| 75 |
{ "--nobias", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, "--max", "turn off composition bias filter", 7 }, |
| 76 |
|
| 77 |
|
| 78 |
{ "--qformat", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, NULL, "assert input <seqfile> is in format <s>", 12 }, |
| 79 |
{ "--nonull2", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, NULL, "turn off biased composition score corrections", 12 }, |
| 80 |
{ "-Z", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, NULL, "set # of comparisons done, for E-value calculation", 12 }, |
| 81 |
{ "--seed", eslARG_INT, "42", NULL, "n>=0", NULL, NULL, NULL, "set RNG seed to <n> (if 0: one-time arbitrary seed)", 12 }, |
| 82 |
{ "--w_beta", eslARG_REAL, NULL, NULL, NULL, NULL, NULL, NULL, "tail mass at which window length is determined", 12 }, |
| 83 |
{ "--w_length", eslARG_INT, NULL, NULL, NULL, NULL, NULL, NULL, "window length - essentially max expected hit length ", 12 }, |
| 84 |
{ "--watson", eslARG_NONE, NULL, NULL, NULL, NULL, NULL,"--crick", "only search the top strand", 12 }, |
| 85 |
{ "--crick", eslARG_NONE, NULL, NULL, NULL, NULL, NULL,"--watson", "only search the bottom strand", 12 }, |
| 86 |
#ifdef HMMER_THREADS |
| 87 |
{ "--cpu", eslARG_INT, "0","HMMER_NCPU","n>=0",NULL, NULL, CPUOPTS, "number of parallel CPU workers to use for multithreads", 12 }, |
| 88 |
#endif |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
{ "--B1", eslARG_INT, "110", NULL, NULL, NULL, NULL, "--max,--nobias", "window length for biased-composition modifier (MSV)", 99 }, |
| 95 |
{ "--B2", eslARG_INT, "240", NULL, NULL, NULL, NULL, "--max,--nobias", "window length for biased-composition modifier (Vit)", 99 }, |
| 96 |
{ "--B3", eslARG_INT, "1000", NULL, NULL, NULL, NULL, "--max,--nobias", "window length for biased-composition modifier (Fwd)", 99 }, |
| 97 |
|
| 98 |
|
| 99 |
{ "--bgfile", eslARG_INFILE, NULL, NULL, NULL, NULL, NULL, NULL, "override default background probs with values in file <f>", 99 }, |
| 100 |
|
| 101 |
|
| 102 |
{ "--domE", eslARG_REAL, "10.0", NULL, "x>0", NULL, NULL, DOMREPOPTS, "report domains <= this E-value threshold in output", 99 }, |
| 103 |
{ "--domT", eslARG_REAL, FALSE, NULL, NULL, NULL, NULL, DOMREPOPTS, "report domains >= this score cutoff in output", 99 }, |
| 104 |
{ "--incdomE", eslARG_REAL, "0.01", NULL, "x>0", NULL, NULL, INCDOMOPTS, "consider domains <= this E-value threshold as significant", 99 }, |
| 105 |
{ "--incdomT", eslARG_REAL, FALSE, NULL, NULL, NULL, NULL, INCDOMOPTS, "consider domains >= this score threshold as significant", 99 }, |
| 106 |
{ "--domZ", eslARG_REAL, FALSE, NULL, "x>0", NULL, NULL, NULL, "set # of significant seqs, for domain E-value calculation", 99 }, |
| 107 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 108 |
}; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
struct cfg_s { |
| 117 |
char *seqfile; |
| 118 |
char *hmmfile; |
| 119 |
|
| 120 |
int do_mpi; |
| 121 |
int nproc; |
| 122 |
int my_rank; |
| 123 |
}; |
| 124 |
|
| 125 |
static char usage[] = "[-options] <hmmdb> <seqfile>"; |
| 126 |
static char banner[] = "search DNA sequence(s) against a DNA profile database"; |
| 127 |
|
| 128 |
static int serial_master(ESL_GETOPTS *go, struct cfg_s *cfg); |
| 129 |
static int serial_loop (WORKER_INFO *info, P7_HMMFILE *hfp); |
| 130 |
#ifdef HMMER_THREADS |
| 131 |
#define BLOCK_SIZE 1 |
| 132 |
static int thread_loop(ESL_THREADS *obj, ESL_WORK_QUEUE *queue, P7_HMMFILE *hfp); |
| 133 |
static void pipeline_thread(void *arg); |
| 134 |
#endif |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
static int |
| 144 |
process_commandline(int argc, char **argv, ESL_GETOPTS **ret_go, char **ret_hmmfile, char **ret_seqfile) |
| 145 |
{ |
| 146 |
ESL_GETOPTS *go = esl_getopts_Create(options); |
| 147 |
int status; |
| 148 |
|
| 149 |
if (esl_opt_ProcessEnvironment(go) != eslOK) { if (printf("Failed to process environment: %s\n", go->errbuf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 150 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK) { if (printf("Failed to parse command line: %s\n", go->errbuf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 151 |
if (esl_opt_VerifyConfig(go) != eslOK) { if (printf("Failed to parse command line: %s\n", go->errbuf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 152 |
|
| 153 |
|
| 154 |
if (esl_opt_GetBoolean(go, "-h") == TRUE) |
| 155 |
{ |
| 156 |
p7_banner(stdout, argv[0], banner); |
| 157 |
esl_usage(stdout, argv[0], usage); |
| 158 |
if (puts("\nBasic options:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 159 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 160 |
|
| 161 |
if (puts("\nOptions controlling output:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 162 |
esl_opt_DisplayHelp(stdout, go, 2, 2, 80); |
| 163 |
|
| 164 |
if (puts("\nOptions controlling reporting thresholds:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 165 |
esl_opt_DisplayHelp(stdout, go, 4, 2, 80); |
| 166 |
|
| 167 |
if (puts("\nOptions controlling inclusion (significance) thresholds:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 168 |
esl_opt_DisplayHelp(stdout, go, 5, 2, 80); |
| 169 |
|
| 170 |
if (puts("\nOptions for model-specific thresholding:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 171 |
esl_opt_DisplayHelp(stdout, go, 6, 2, 80); |
| 172 |
|
| 173 |
if (puts("\nOptions controlling acceleration heuristics:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 174 |
esl_opt_DisplayHelp(stdout, go, 7, 2, 80); |
| 175 |
|
| 176 |
if (puts("\nOther expert options:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 177 |
esl_opt_DisplayHelp(stdout, go, 12, 2, 80); |
| 178 |
exit(0); |
| 179 |
} |
| 180 |
|
| 181 |
if (esl_opt_ArgNumber(go) != 2) { if (puts("Incorrect number of command line arguments.") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 182 |
if ((*ret_hmmfile = esl_opt_GetArg(go, 1)) == NULL) { if (puts("Failed to get <hmmdb> argument on command line") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 183 |
if ((*ret_seqfile = esl_opt_GetArg(go, 2)) == NULL) { if (puts("Failed to get <seqfile> argument on command line") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 184 |
|
| 185 |
|
| 186 |
if (strcmp(*ret_hmmfile, "-") == 0) |
| 187 |
{ if (puts("nhmmscan cannot read <hmm database> from stdin stream, because it must have hmmpress'ed auxfiles") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); goto FAILURE; } |
| 188 |
|
| 189 |
*ret_go = go; |
| 190 |
return eslOK; |
| 191 |
|
| 192 |
FAILURE: |
| 193 |
esl_usage(stdout, argv[0], usage); |
| 194 |
if (puts("\nwhere most common options are:") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 195 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 196 |
if (printf("\nTo see more help on available options, do %s -h\n\n", argv[0]) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "write failed"); |
| 197 |
esl_getopts_Destroy(go); |
| 198 |
exit(1); |
| 199 |
|
| 200 |
ERROR: |
| 201 |
if (go) esl_getopts_Destroy(go); |
| 202 |
exit(status); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
static int |
| 207 |
output_header(FILE *ofp, ESL_GETOPTS *go, char *hmmfile, char *seqfile) |
| 208 |
{ |
| 209 |
p7_banner(ofp, go->argv[0], banner); |
| 210 |
|
| 211 |
if (fprintf(ofp, "# query sequence file: %s\n", seqfile) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 212 |
if (fprintf(ofp, "# target HMM database: %s\n", hmmfile) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 213 |
if (esl_opt_IsUsed(go, "-o") && fprintf(ofp, "# output directed to file: %s\n", esl_opt_GetString(go, "-o")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 214 |
if (esl_opt_IsUsed(go, "--tblout") && fprintf(ofp, "# per-seq hits tabular output: %s\n", esl_opt_GetString(go, "--tblout")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 215 |
if (esl_opt_IsUsed(go, "--dfamtblout")&& fprintf(ofp, "# hits output in Dfam format: %s\n", esl_opt_GetString(go, "--dfamtblout"))< 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 216 |
|
| 217 |
if (esl_opt_IsUsed(go, "--acc") && fprintf(ofp, "# prefer accessions over names: yes\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 218 |
if (esl_opt_IsUsed(go, "--noali") && fprintf(ofp, "# show alignments in output: no\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 219 |
if (esl_opt_IsUsed(go, "--notextw") && fprintf(ofp, "# max ASCII text line length: unlimited\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 220 |
if (esl_opt_IsUsed(go, "--textw") && fprintf(ofp, "# max ASCII text line length: %d\n", esl_opt_GetInteger(go, "--textw")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 221 |
|
| 222 |
if (esl_opt_IsUsed(go, "-E") && fprintf(ofp, "# profile reporting threshold: E-value <= %g\n", esl_opt_GetReal(go, "-E")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 223 |
if (esl_opt_IsUsed(go, "-T") && fprintf(ofp, "# profile reporting threshold: score >= %g\n", esl_opt_GetReal(go, "-T")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 224 |
if (esl_opt_IsUsed(go, "--incE") && fprintf(ofp, "# profile inclusion threshold: E-value <= %g\n", esl_opt_GetReal(go, "--incE")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 225 |
if (esl_opt_IsUsed(go, "--incT") && fprintf(ofp, "# profile inclusion threshold: score >= %g\n", esl_opt_GetReal(go, "--incT")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 226 |
if (esl_opt_IsUsed(go, "--cut_ga") && fprintf(ofp, "# model-specific thresholding: GA cutoffs\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 227 |
if (esl_opt_IsUsed(go, "--cut_nc") && fprintf(ofp, "# model-specific thresholding: NC cutoffs\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 228 |
if (esl_opt_IsUsed(go, "--cut_tc") && fprintf(ofp, "# model-specific thresholding: TC cutoffs\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 229 |
if (esl_opt_IsUsed(go, "--max") && fprintf(ofp, "# Max sensitivity mode: on [all heuristic filters off]\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 230 |
if (esl_opt_IsUsed(go, "--F1") && fprintf(ofp, "# MSV filter P threshold: <= %g\n", esl_opt_GetReal(go, "--F1")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 231 |
if (esl_opt_IsUsed(go, "--F2") && fprintf(ofp, "# Vit filter P threshold: <= %g\n", esl_opt_GetReal(go, "--F2")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 232 |
if (esl_opt_IsUsed(go, "--F3") && fprintf(ofp, "# Fwd filter P threshold: <= %g\n", esl_opt_GetReal(go, "--F3")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 233 |
if (esl_opt_IsUsed(go, "--nobias") && fprintf(ofp, "# biased composition HMM filter: off\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 234 |
|
| 235 |
if (esl_opt_IsUsed(go, "--B1") && fprintf(ofp, "# biased comp MSV window len: %d\n", esl_opt_GetInteger(go, "--B1")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 236 |
if (esl_opt_IsUsed(go, "--B2") && fprintf(ofp, "# biased comp Viterbi window len: %d\n", esl_opt_GetInteger(go, "--B2")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 237 |
if (esl_opt_IsUsed(go, "--B3") && fprintf(ofp, "# biased comp Forward window len: %d\n", esl_opt_GetInteger(go, "--B3")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 238 |
if (esl_opt_IsUsed(go, "--bgfile") && fprintf(ofp, "# file with custom bg probs: %s\n", esl_opt_GetString(go, "--bgfile")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 239 |
|
| 240 |
if (esl_opt_IsUsed(go, "--nonull2") && fprintf(ofp, "# null2 bias corrections: off\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 241 |
|
| 242 |
if (esl_opt_IsUsed(go, "--watson") && fprintf(ofp, "# search only top strand: on\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 243 |
if (esl_opt_IsUsed(go, "--crick") && fprintf(ofp, "# search only bottom strand: on\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 244 |
|
| 245 |
if (esl_opt_IsUsed(go, "-Z") && fprintf(ofp, "# sequence search space set to: %.0f\n", esl_opt_GetReal(go, "-Z")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 246 |
if (esl_opt_IsUsed(go, "--seed")) { |
| 247 |
if (esl_opt_GetInteger(go, "--seed")==0 && fprintf(ofp, "# random number seed: one-time arbitrary\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 248 |
else if ( fprintf(ofp, "# random number seed set to: %d\n", esl_opt_GetInteger(go, "--seed")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 249 |
} |
| 250 |
if (esl_opt_IsUsed(go, "--qformat") && fprintf(ofp, "# input seqfile format asserted: %s\n", esl_opt_GetString(go, "--qformat")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 251 |
if (esl_opt_IsUsed(go, "--w_beta") && fprintf(ofp, "# window length beta value: %g\n", esl_opt_GetReal(go, "--w_beta")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 252 |
if (esl_opt_IsUsed(go, "--w_length") && fprintf(ofp, "# window length : %d\n", esl_opt_GetInteger(go, "--w_length")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 253 |
#ifdef HMMER_THREADS |
| 254 |
if (esl_opt_IsUsed(go, "--cpu")) { |
| 255 |
if (esl_opt_GetInteger(go, "--cpu") == 0) { if (fprintf(ofp, "# multithread parallelization: off\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); } |
| 256 |
else { if (fprintf(ofp, "# multithread parallelization: %d workers\n", esl_opt_GetInteger(go, "--cpu")) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); } |
| 257 |
} |
| 258 |
#endif |
| 259 |
if (fprintf(ofp, "# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 260 |
return eslOK; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
int |
| 265 |
main(int argc, char **argv) |
| 266 |
{ |
| 267 |
ESL_GETOPTS *go = NULL; |
| 268 |
struct cfg_s cfg; |
| 269 |
int status = eslOK; |
| 270 |
|
| 271 |
impl_Init(); |
| 272 |
p7_FLogsumInit(); |
| 273 |
|
| 274 |
|
| 275 |
cfg.hmmfile = NULL; |
| 276 |
cfg.seqfile = NULL; |
| 277 |
cfg.do_mpi = FALSE; |
| 278 |
cfg.nproc = 0; |
| 279 |
cfg.my_rank = 0; |
| 280 |
|
| 281 |
process_commandline(argc, argv, &go, &cfg.hmmfile, &cfg.seqfile); |
| 282 |
|
| 283 |
status = serial_master(go, &cfg); |
| 284 |
|
| 285 |
esl_getopts_Destroy(go); |
| 286 |
return status; |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
static int |
| 298 |
serial_master(ESL_GETOPTS *go, struct cfg_s *cfg) |
| 299 |
{ |
| 300 |
FILE *ofp = stdout; |
| 301 |
FILE *tblfp = NULL; |
| 302 |
FILE *dfamtblfp= NULL; |
| 303 |
|
| 304 |
P7_BG *bg_manual = NULL; |
| 305 |
|
| 306 |
int seqfmt = eslSQFILE_UNKNOWN; |
| 307 |
ESL_SQFILE *sqfp = NULL; |
| 308 |
P7_HMMFILE *hfp = NULL; |
| 309 |
ESL_ALPHABET *abc = NULL; |
| 310 |
P7_OPROFILE *om = NULL; |
| 311 |
ESL_STOPWATCH *w = NULL; |
| 312 |
ESL_SQ *qsq = NULL; |
| 313 |
int nquery = 0; |
| 314 |
int textw; |
| 315 |
int status = eslOK; |
| 316 |
int hstatus = eslOK; |
| 317 |
int sstatus = eslOK; |
| 318 |
int i; |
| 319 |
|
| 320 |
int ncpus = 0; |
| 321 |
|
| 322 |
int infocnt = 0; |
| 323 |
WORKER_INFO *info = NULL; |
| 324 |
#ifdef HMMER_THREADS |
| 325 |
P7_OM_BLOCK *block = NULL; |
| 326 |
ESL_THREADS *threadObj= NULL; |
| 327 |
ESL_WORK_QUEUE *queue = NULL; |
| 328 |
#endif |
| 329 |
char errbuf[eslERRBUFSIZE]; |
| 330 |
|
| 331 |
double window_beta = -1.0 ; |
| 332 |
int window_length = -1; |
| 333 |
if (esl_opt_IsUsed(go, "--w_beta")) { if ( ( window_beta = esl_opt_GetReal(go, "--w_beta") ) < 0 || window_beta > 1 ) esl_fatal("Invalid window-length beta value\n"); } |
| 334 |
if (esl_opt_IsUsed(go, "--w_length")) { if (( window_length = esl_opt_GetInteger(go, "--w_length")) < 4 ) esl_fatal("Invalid window length value\n"); } |
| 335 |
|
| 336 |
|
| 337 |
w = esl_stopwatch_Create(); |
| 338 |
|
| 339 |
if (esl_opt_GetBoolean(go, "--notextw")) textw = 0; |
| 340 |
else textw = esl_opt_GetInteger(go, "--textw"); |
| 341 |
|
| 342 |
|
| 343 |
if (esl_opt_IsOn(go, "--qformat")) { |
| 344 |
seqfmt = esl_sqio_EncodeFormat(esl_opt_GetString(go, "--qformat")); |
| 345 |
if (seqfmt == eslSQFILE_UNKNOWN) p7_Fail("%s is not a recognized input sequence file format\n", esl_opt_GetString(go, "--qformat")); |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
status = p7_hmmfile_Open(cfg->hmmfile, p7_HMMDBENV, &hfp, errbuf); |
| 350 |
if (status == eslENOTFOUND) p7_Fail("File existence/permissions problem in trying to open HMM file %s.\n%s\n", cfg->hmmfile, errbuf); |
| 351 |
else if (status == eslEFORMAT) p7_Fail("File format problem, trying to open HMM file %s.\n%s\n", cfg->hmmfile, errbuf); |
| 352 |
else if (status != eslOK) p7_Fail("Unexpected error %d in opening HMM file %s.\n%s\n", status, cfg->hmmfile, errbuf); |
| 353 |
if (! hfp->is_pressed) p7_Fail("Failed to open binary auxfiles for %s: use hmmpress first\n", hfp->fname); |
| 354 |
|
| 355 |
hstatus = p7_oprofile_ReadMSV(hfp, &abc, &om); |
| 356 |
if (hstatus == eslEFORMAT) p7_Fail("bad format, binary auxfiles, %s:\n%s", cfg->hmmfile, hfp->errbuf); |
| 357 |
else if (hstatus == eslEINCOMPAT) p7_Fail("HMM file %s contains different alphabets", cfg->hmmfile); |
| 358 |
else if (hstatus != eslOK) p7_Fail("Unexpected error in reading HMMs from %s", cfg->hmmfile); |
| 359 |
|
| 360 |
if (om->max_length == -1) p7_Fail("No MAXL field in model(s); is this an old model format?\nnhmmer/hmmscan require HMMER 3.1 models or later."); |
| 361 |
|
| 362 |
p7_oprofile_Destroy(om); |
| 363 |
p7_hmmfile_Close(hfp); |
| 364 |
|
| 365 |
|
| 366 |
status = esl_sqfile_OpenDigital(abc, cfg->seqfile, seqfmt, NULL, &sqfp); |
| 367 |
if (status == eslENOTFOUND) p7_Fail("Failed to open sequence file %s for reading\n", cfg->seqfile); |
| 368 |
else if (status == eslEFORMAT) p7_Fail("Sequence file %s is empty or misformatted\n", cfg->seqfile); |
| 369 |
else if (status == eslEINVAL) p7_Fail("Can't autodetect format of a stdin or .gz seqfile"); |
| 370 |
else if (status != eslOK) p7_Fail("Unexpected error %d opening sequence file %s\n", status, cfg->seqfile); |
| 371 |
if (sqfp->format > 100) |
| 372 |
p7_Fail("%s contains a multiple sequence alignment; expect unaligned sequences, like FASTA\n", cfg->seqfile); |
| 373 |
qsq = esl_sq_CreateDigital(abc); |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
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")); } |
| 378 |
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")); } |
| 379 |
if (esl_opt_IsOn(go, "--dfamtblout")){ if ((dfamtblfp= fopen(esl_opt_GetString(go, "--dfamtblout"),"w")) == NULL) esl_fatal("Failed to open tabular dfam output file %s for writing\n", esl_opt_GetString(go, "--dfamtblout")); } |
| 380 |
|
| 381 |
output_header(ofp, go, cfg->hmmfile, cfg->seqfile); |
| 382 |
|
| 383 |
#ifdef HMMER_THREADS |
| 384 |
|
| 385 |
ncpus = ESL_MIN(esl_opt_GetInteger(go, "--cpu"), esl_threads_GetCPUCount()); |
| 386 |
if (ncpus > 0) |
| 387 |
{ |
| 388 |
threadObj = esl_threads_Create(&pipeline_thread); |
| 389 |
queue = esl_workqueue_Create(ncpus * 2); |
| 390 |
} |
| 391 |
#endif |
| 392 |
|
| 393 |
if (esl_opt_IsOn(go, "--bgfile")) { |
| 394 |
bg_manual = p7_bg_Create(abc); |
| 395 |
status = p7_bg_Read(esl_opt_GetString(go, "--bgfile"), bg_manual, errbuf); |
| 396 |
if (status != eslOK) p7_Fail("Trouble reading bgfile: %s\n", errbuf); |
| 397 |
} |
| 398 |
|
| 399 |
infocnt = (ncpus == 0) ? 1 : ncpus; |
| 400 |
ESL_ALLOC(info, (ptrdiff_t) sizeof(*info) * infocnt); |
| 401 |
|
| 402 |
for (i = 0; i < infocnt; ++i) |
| 403 |
{ |
| 404 |
if (bg_manual != NULL) { |
| 405 |
info[i].bg = p7_bg_Clone(bg_manual); |
| 406 |
info[i].bg_default = p7_bg_Create(abc); |
| 407 |
} else { |
| 408 |
info[i].bg = p7_bg_Create(abc); |
| 409 |
info[i].bg_default = NULL; |
| 410 |
} |
| 411 |
#ifdef HMMER_THREADS |
| 412 |
info[i].queue = queue; |
| 413 |
#endif |
| 414 |
ESL_ALLOC(info[i].scores, sizeof(float) * abc->Kp * 16); |
| 415 |
} |
| 416 |
|
| 417 |
#ifdef HMMER_THREADS |
| 418 |
for (i = 0; i < ncpus * 2; ++i) |
| 419 |
{ |
| 420 |
block = p7_oprofile_CreateBlock(BLOCK_SIZE); |
| 421 |
if (block == NULL) esl_fatal("Failed to allocate sequence block"); |
| 422 |
|
| 423 |
status = esl_workqueue_Init(queue, block); |
| 424 |
if (status != eslOK) esl_fatal("Failed to add block to work queue"); |
| 425 |
} |
| 426 |
#endif |
| 427 |
|
| 428 |
|
| 429 |
while ((sstatus = esl_sqio_Read(sqfp, qsq)) == eslOK) |
| 430 |
{ |
| 431 |
if (sstatus == eslEMEM) p7_Fail("Memory allocation error reading sequence file\n", status); |
| 432 |
if (sstatus == eslEINCONCEIVABLE) p7_Fail("Unexpected error %d reading sequence file\n", status); |
| 433 |
|
| 434 |
|
| 435 |
nquery++; |
| 436 |
esl_stopwatch_Start(w); |
| 437 |
|
| 438 |
|
| 439 |
status = p7_hmmfile_Open(cfg->hmmfile, p7_HMMDBENV, &hfp, NULL); |
| 440 |
if (status != eslOK) p7_Fail("Unexpected error %d in opening hmm file %s.\n", status, cfg->hmmfile); |
| 441 |
|
| 442 |
#ifdef HMMER_THREADS |
| 443 |
|
| 444 |
if (ncpus > 0) |
| 445 |
{ |
| 446 |
status = p7_hmmfile_CreateLock(hfp); |
| 447 |
if (status != eslOK) p7_Fail("Unexpected error %d creating lock\n", status); |
| 448 |
} |
| 449 |
#endif |
| 450 |
|
| 451 |
if (fprintf(ofp, "Query: %s [L=%ld]\n", qsq->name, (long) qsq->n) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 452 |
if (qsq->acc[0] != 0 && fprintf(ofp, "Accession: %s\n", qsq->acc) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 453 |
if (qsq->desc[0] != 0 && fprintf(ofp, "Description: %s\n", qsq->desc) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 454 |
|
| 455 |
for (i = 0; i < infocnt; ++i) |
| 456 |
{ |
| 457 |
|
| 458 |
info[i].th = p7_tophits_Create(); |
| 459 |
info[i].pli = p7_pipeline_Create(go, 100, 100, TRUE, p7_SCAN_MODELS); |
| 460 |
info[i].pli->hfp = hfp; |
| 461 |
|
| 462 |
p7_pli_NewSeq(info[i].pli, qsq); |
| 463 |
info[i].qsq = qsq; |
| 464 |
|
| 465 |
if ( esl_opt_IsUsed(go, "--watson") ) |
| 466 |
info[i].pli->strands = p7_STRAND_TOPONLY; |
| 467 |
else if ( esl_opt_IsUsed(go, "--crick") ) |
| 468 |
info[i].pli->strands = p7_STRAND_BOTTOMONLY; |
| 469 |
else |
| 470 |
info[i].pli->strands = p7_STRAND_BOTH; |
| 471 |
|
| 472 |
info[i].fwd_emissions = NULL; |
| 473 |
|
| 474 |
#ifdef HMMER_THREADS |
| 475 |
if (ncpus > 0) esl_threads_AddThread(threadObj, &info[i]); |
| 476 |
#endif |
| 477 |
} |
| 478 |
|
| 479 |
#ifdef HMMER_THREADS |
| 480 |
if (ncpus > 0) hstatus = thread_loop(threadObj, queue, hfp); |
| 481 |
else hstatus = serial_loop(info, hfp); |
| 482 |
#else |
| 483 |
hstatus = serial_loop(info, hfp); |
| 484 |
#endif |
| 485 |
switch(hstatus) |
| 486 |
{ |
| 487 |
case eslEFORMAT: p7_Fail("bad file format in HMM file %s", cfg->hmmfile); break; |
| 488 |
case eslEINCOMPAT: p7_Fail("HMM file %s contains different alphabets", cfg->hmmfile); break; |
| 489 |
case eslEOF: |
| 490 |
case eslOK: |
| 491 |
break; |
| 492 |
default: p7_Fail("Unexpected error in reading HMMs from %s", cfg->hmmfile); |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
for (i = 1; i < infocnt; ++i) |
| 499 |
{ |
| 500 |
p7_tophits_Merge(info[0].th, info[i].th); |
| 501 |
p7_pipeline_Merge(info[0].pli, info[i].pli); |
| 502 |
|
| 503 |
p7_pipeline_Destroy(info[i].pli); |
| 504 |
p7_tophits_Destroy(info[i].th); |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
for (i = 0; i < info->th->N ; i++) |
| 510 |
{ |
| 511 |
info->th->unsrt[i].lnP += log((float)info->pli->nmodels); |
| 512 |
info->th->unsrt[i].dcl[0].lnP = info->th->unsrt[i].lnP; |
| 513 |
info->th->unsrt[i].sortkey = -1.0 * info->th->unsrt[i].lnP; |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
p7_tophits_SortByModelnameAndAlipos(info->th); |
| 519 |
p7_tophits_RemoveDuplicates(info->th, info->pli->use_bit_cutoffs); |
| 520 |
|
| 521 |
|
| 522 |
p7_tophits_SortBySortkey(info->th); |
| 523 |
p7_tophits_Threshold(info->th, info->pli); |
| 524 |
|
| 525 |
|
| 526 |
info->pli->n_output = info->pli->pos_output = 0; |
| 527 |
for (i = 0; i < info->th->N; i++) { |
| 528 |
if ( (info->th->hit[i]->flags & p7_IS_REPORTED) || info->th->hit[i]->flags & p7_IS_INCLUDED) { |
| 529 |
info->pli->n_output++; |
| 530 |
info->pli->pos_output += 1 + (info->th->hit[i]->dcl[0].jali > info->th->hit[i]->dcl[0].iali ? info->th->hit[i]->dcl[0].jali - info->th->hit[i]->dcl[0].iali : info->th->hit[i]->dcl[0].iali - info->th->hit[i]->dcl[0].jali) ; |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
p7_tophits_Targets(ofp, info->th, info->pli, textw); if (fprintf(ofp, "\n\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 538 |
p7_tophits_Domains(ofp, info->th, info->pli, textw); if (fprintf(ofp, "\n\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 539 |
|
| 540 |
if (tblfp) p7_tophits_TabularTargets(tblfp, qsq->name, qsq->acc, info->th, info->pli, (nquery == 1)); |
| 541 |
if (dfamtblfp) p7_tophits_TabularXfam(dfamtblfp, qsq->name, NULL, info->th, info->pli); |
| 542 |
|
| 543 |
esl_stopwatch_Stop(w); |
| 544 |
info->pli->nseqs = 1; |
| 545 |
p7_pli_Statistics(ofp, info->pli, w); |
| 546 |
if (fprintf(ofp, "//\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); |
| 547 |
fflush(ofp); |
| 548 |
|
| 549 |
p7_hmmfile_Close(hfp); |
| 550 |
p7_pipeline_Destroy(info->pli); |
| 551 |
p7_tophits_Destroy(info->th); |
| 552 |
esl_sq_Reuse(qsq); |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
if (sstatus == eslEFORMAT) esl_fatal("Parse failed (sequence file %s):\n%s\n", |
| 558 |
sqfp->filename, esl_sqfile_GetErrorBuf(sqfp)); |
| 559 |
else if (sstatus != eslEOF) esl_fatal("Unexpected error %d reading sequence file %s", |
| 560 |
sstatus, sqfp->filename); |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
if (tblfp) p7_tophits_TabularTail(tblfp, "nhmmscan", p7_SCAN_MODELS, cfg->seqfile, cfg->hmmfile, go); |
| 565 |
if (ofp) { if (fprintf(ofp, "[ok]\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "write failed"); } |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
for (i = 0; i < infocnt; ++i) { |
| 570 |
p7_bg_Destroy(info[i].bg); |
| 571 |
p7_bg_Destroy(info[i].bg_default); |
| 572 |
if (info[i].scores != NULL) free(info[i].scores); |
| 573 |
} |
| 574 |
|
| 575 |
#ifdef HMMER_THREADS |
| 576 |
if (ncpus > 0) |
| 577 |
{ |
| 578 |
esl_workqueue_Reset(queue); |
| 579 |
while (esl_workqueue_Remove(queue, (void **) &block) == eslOK) |
| 580 |
p7_oprofile_DestroyBlock(block); |
| 581 |
esl_workqueue_Destroy(queue); |
| 582 |
esl_threads_Destroy(threadObj); |
| 583 |
} |
| 584 |
#endif |
| 585 |
|
| 586 |
ERROR: |
| 587 |
p7_bg_Destroy(bg_manual); |
| 588 |
if (info) free(info); |
| 589 |
if (qsq) esl_sq_Destroy(qsq); |
| 590 |
if (w) esl_stopwatch_Destroy(w); |
| 591 |
if (abc) esl_alphabet_Destroy(abc); |
| 592 |
if (sqfp) esl_sqfile_Close(sqfp); |
| 593 |
|
| 594 |
if (ofp != stdout) fclose(ofp); |
| 595 |
if (tblfp) fclose(tblfp); |
| 596 |
if (dfamtblfp) fclose(dfamtblfp); |
| 597 |
return status; |
| 598 |
} |
| 599 |
|
| 600 |
|
| 601 |
static int |
| 602 |
serial_loop(WORKER_INFO *info, P7_HMMFILE *hfp) |
| 603 |
{ |
| 604 |
int status; |
| 605 |
int i; |
| 606 |
int seq_len = 0; |
| 607 |
int prev_hit_cnt = 0; |
| 608 |
P7_OPROFILE *om = NULL; |
| 609 |
P7_SCOREDATA *scoredata = NULL; |
| 610 |
ESL_ALPHABET *abc = NULL; |
| 611 |
ESL_SQ *sq_revcmp = NULL; |
| 612 |
|
| 613 |
if (info->pli->strands != p7_STRAND_TOPONLY && info->qsq->abc->complement != NULL ) { |
| 614 |
sq_revcmp = esl_sq_CreateDigital(info->qsq->abc); |
| 615 |
esl_sq_Copy(info->qsq,sq_revcmp); |
| 616 |
esl_sq_ReverseComplement(sq_revcmp); |
| 617 |
|
| 618 |
info->pli->nres += info->qsq->n; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
while ((status = p7_oprofile_ReadMSV(hfp, &abc, &om)) == eslOK) |
| 623 |
{ |
| 624 |
seq_len = 0; |
| 625 |
|
| 626 |
p7_pli_NewModel(info->pli, om, info->bg); |
| 627 |
p7_bg_SetLength(info->bg, info->qsq->n); |
| 628 |
p7_oprofile_ReconfigLength(om, info->qsq->n); |
| 629 |
|
| 630 |
if (info->bg_default != NULL) { |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
p7_oprofile_ReadRest(info->pli->hfp, om); |
| 637 |
if ((status = p7_pli_NewModelThresholds(info->pli, om)) != eslOK) return status; |
| 638 |
ESL_REALLOC(info->fwd_emissions, sizeof(float) * abc->Kp * (om->M+1)); |
| 639 |
p7_oprofile_GetFwdEmissionArray(om, info->bg_default, info->fwd_emissions); |
| 640 |
p7_oprofile_UpdateFwdEmissionScores(om, info->bg, info->fwd_emissions, info->scores); |
| 641 |
p7_oprofile_UpdateVitEmissionScores(om, info->bg, info->fwd_emissions, info->scores); |
| 642 |
p7_oprofile_UpdateMSVEmissionScores(om, info->bg, info->fwd_emissions, info->scores); |
| 643 |
} |
| 644 |
|
| 645 |
scoredata = p7_hmm_ScoreDataCreate(om, FALSE); |
| 646 |
|
| 647 |
|
| 648 |
if (info->pli->strands != p7_STRAND_TOPONLY && info->qsq->abc->complement != NULL ) |
| 649 |
{ |
| 650 |
status = p7_Pipeline_LongTarget(info->pli, om, scoredata, info->bg, info->th, 0, sq_revcmp, p7_COMPLEMENT, NULL, NULL, NULL); |
| 651 |
if (status != eslOK) p7_Fail(info->pli->errbuf); |
| 652 |
|
| 653 |
p7_pipeline_Reuse(info->pli); |
| 654 |
seq_len = info->qsq->n; |
| 655 |
} |
| 656 |
|
| 657 |
if (info->pli->strands != p7_STRAND_BOTTOMONLY) { |
| 658 |
status = p7_Pipeline_LongTarget(info->pli, om, scoredata, info->bg, info->th, 0, info->qsq, p7_NOCOMPLEMENT, NULL, NULL, NULL); |
| 659 |
if (status != eslOK) p7_Fail(info->pli->errbuf); |
| 660 |
|
| 661 |
p7_pipeline_Reuse(info->pli); |
| 662 |
seq_len += info->qsq->n; |
| 663 |
} |
| 664 |
|
| 665 |
for (i = prev_hit_cnt; i < info->th->N ; i++) |
| 666 |
{ |
| 667 |
info->th->unsrt[i].lnP += log((float)seq_len / (float)om->max_length); |
| 668 |
info->th->unsrt[i].dcl[0].lnP = info->th->unsrt[i].lnP; |
| 669 |
info->th->unsrt[i].sortkey = -1.0 * info->th->unsrt[i].lnP; |
| 670 |
info->th->unsrt[i].dcl[0].ad->L = om->M; |
| 671 |
} |
| 672 |
|
| 673 |
prev_hit_cnt = info->th->N; |
| 674 |
|
| 675 |
p7_oprofile_Destroy(om); |
| 676 |
p7_hmm_ScoreDataDestroy(scoredata); |
| 677 |
} |
| 678 |
|
| 679 |
esl_alphabet_Destroy(abc); |
| 680 |
esl_sq_Destroy(sq_revcmp); |
| 681 |
if (info->fwd_emissions) free(info->fwd_emissions); |
| 682 |
|
| 683 |
ERROR: |
| 684 |
return status; |
| 685 |
} |
| 686 |
|
| 687 |
#ifdef HMMER_THREADS |
| 688 |
static int |
| 689 |
thread_loop(ESL_THREADS *obj, ESL_WORK_QUEUE *queue, P7_HMMFILE *hfp) |
| 690 |
{ |
| 691 |
int status = eslOK; |
| 692 |
int sstatus = eslOK; |
| 693 |
int eofCount = 0; |
| 694 |
P7_OM_BLOCK *block; |
| 695 |
ESL_ALPHABET *abc = NULL; |
| 696 |
void *newBlock; |
| 697 |
|
| 698 |
esl_workqueue_Reset(queue); |
| 699 |
esl_threads_WaitForStart(obj); |
| 700 |
|
| 701 |
status = esl_workqueue_ReaderUpdate(queue, NULL, &newBlock); |
| 702 |
if (status != eslOK) esl_fatal("Work queue reader failed"); |
| 703 |
|
| 704 |
|
| 705 |
while (sstatus == eslOK) |
| 706 |
{ |
| 707 |
block = (P7_OM_BLOCK *) newBlock; |
| 708 |
sstatus = p7_oprofile_ReadBlockMSV(hfp, &abc, block); |
| 709 |
|
| 710 |
if (sstatus == eslEOF) |
| 711 |
{ |
| 712 |
if (eofCount < esl_threads_GetWorkerCount(obj)) sstatus = eslOK; |
| 713 |
++eofCount; |
| 714 |
} |
| 715 |
|
| 716 |
if (sstatus == eslOK) |
| 717 |
{ |
| 718 |
status = esl_workqueue_ReaderUpdate(queue, block, &newBlock); |
| 719 |
if (status != eslOK) esl_fatal("Work queue reader failed"); |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
status = esl_workqueue_ReaderUpdate(queue, block, NULL); |
| 724 |
if (status != eslOK) esl_fatal("Work queue reader failed"); |
| 725 |
|
| 726 |
if (sstatus == eslEOF) |
| 727 |
{ |
| 728 |
|
| 729 |
esl_threads_WaitForFinish(obj); |
| 730 |
esl_workqueue_Complete(queue); |
| 731 |
} |
| 732 |
|
| 733 |
esl_alphabet_Destroy(abc); |
| 734 |
return sstatus; |
| 735 |
} |
| 736 |
|
| 737 |
static void |
| 738 |
pipeline_thread(void *arg) |
| 739 |
{ |
| 740 |
int i, j; |
| 741 |
int status; |
| 742 |
int workeridx; |
| 743 |
WORKER_INFO *info; |
| 744 |
ESL_THREADS *obj; |
| 745 |
P7_OM_BLOCK *block; |
| 746 |
void *newBlock; |
| 747 |
P7_OPROFILE *om = NULL; |
| 748 |
P7_SCOREDATA *scoredata = NULL; |
| 749 |
|
| 750 |
int seq_len = 0; |
| 751 |
int prev_hit_cnt = 0; |
| 752 |
ESL_SQ *sq_revcmp = NULL; |
| 753 |
|
| 754 |
impl_Init(); |
| 755 |
|
| 756 |
obj = (ESL_THREADS *) arg; |
| 757 |
esl_threads_Started(obj, &workeridx); |
| 758 |
|
| 759 |
info = (WORKER_INFO *) esl_threads_GetData(obj, workeridx); |
| 760 |
|
| 761 |
status = esl_workqueue_WorkerUpdate(info->queue, NULL, &newBlock); |
| 762 |
if (status != eslOK) esl_fatal("Work queue worker failed"); |
| 763 |
|
| 764 |
|
| 765 |
if (info->pli->strands != p7_STRAND_TOPONLY && info->qsq->abc->complement != NULL ) { |
| 766 |
sq_revcmp = esl_sq_CreateDigital(info->qsq->abc); |
| 767 |
esl_sq_Copy(info->qsq,sq_revcmp); |
| 768 |
esl_sq_ReverseComplement(sq_revcmp); |
| 769 |
info->pli->nres += info->qsq->n; |
| 770 |
} |
| 771 |
|
| 772 |
|
| 773 |
block = (P7_OM_BLOCK *) newBlock; |
| 774 |
while (block->count > 0) |
| 775 |
{ |
| 776 |
|
| 777 |
for (i = 0; i < block->count; ++i) |
| 778 |
{ |
| 779 |
om = block->list[i]; |
| 780 |
seq_len = 0; |
| 781 |
|
| 782 |
p7_pli_NewModel(info->pli, om, info->bg); |
| 783 |
p7_bg_SetLength(info->bg, info->qsq->n); |
| 784 |
p7_oprofile_ReconfigLength(om, info->qsq->n); |
| 785 |
|
| 786 |
if (info->bg_default != NULL) { |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
p7_oprofile_ReadRest(info->pli->hfp, om); |
| 793 |
if ((status = p7_pli_NewModelThresholds(info->pli, om)) != eslOK) esl_fatal("Error setting thresholds in worker thread"); |
| 794 |
ESL_REALLOC(info->fwd_emissions, sizeof(float) * info->qsq->abc->Kp * (om->M+1)); |
| 795 |
p7_oprofile_GetFwdEmissionArray(om, info->bg_default, info->fwd_emissions); |
| 796 |
p7_oprofile_UpdateFwdEmissionScores(om, info->bg, info->fwd_emissions, info->scores); |
| 797 |
p7_oprofile_UpdateVitEmissionScores(om, info->bg, info->fwd_emissions, info->scores); |
| 798 |
p7_oprofile_UpdateMSVEmissionScores(om, info->bg, info->fwd_emissions, info->scores); |
| 799 |
} |
| 800 |
|
| 801 |
scoredata = p7_hmm_ScoreDataCreate(om, FALSE); |
| 802 |
|
| 803 |
|
| 804 |
if (info->pli->strands != p7_STRAND_TOPONLY && info->qsq->abc->complement != NULL ) |
| 805 |
{ |
| 806 |
status = p7_Pipeline_LongTarget(info->pli, om, scoredata, info->bg, info->th, 0, sq_revcmp, p7_COMPLEMENT, NULL, NULL, NULL); |
| 807 |
if (status != eslOK) p7_Fail(info->pli->errbuf); |
| 808 |
|
| 809 |
p7_pipeline_Reuse(info->pli); |
| 810 |
seq_len = info->qsq->n; |
| 811 |
} |
| 812 |
|
| 813 |
if (info->pli->strands != p7_STRAND_BOTTOMONLY) { |
| 814 |
status = p7_Pipeline_LongTarget(info->pli, om, scoredata, info->bg, info->th, 0, info->qsq, p7_NOCOMPLEMENT, NULL, NULL, NULL); |
| 815 |
if (status != eslOK) p7_Fail(info->pli->errbuf); |
| 816 |
|
| 817 |
p7_pipeline_Reuse(info->pli); |
| 818 |
seq_len += info->qsq->n; |
| 819 |
} |
| 820 |
|
| 821 |
for (j = prev_hit_cnt; j < info->th->N ; j++) |
| 822 |
{ |
| 823 |
info->th->unsrt[j].lnP += log((float)seq_len / (float)om->max_length); |
| 824 |
info->th->unsrt[j].dcl[0].lnP = info->th->unsrt[j].lnP; |
| 825 |
info->th->unsrt[j].sortkey = -1.0 * info->th->unsrt[j].lnP; |
| 826 |
info->th->unsrt[j].dcl[0].ad->L = om->M; |
| 827 |
} |
| 828 |
|
| 829 |
prev_hit_cnt = info->th->N; |
| 830 |
p7_hmm_ScoreDataDestroy(scoredata); |
| 831 |
p7_oprofile_Destroy(om); |
| 832 |
block->list[i] = NULL; |
| 833 |
} |
| 834 |
|
| 835 |
|
| 836 |
status = esl_workqueue_WorkerUpdate(info->queue, block, &newBlock); |
| 837 |
if (status != eslOK) esl_fatal("Work queue worker failed"); |
| 838 |
|
| 839 |
block = (P7_OM_BLOCK *) newBlock; |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
esl_sq_Destroy(sq_revcmp); |
| 844 |
if (info->fwd_emissions != NULL) free(info->fwd_emissions); |
| 845 |
|
| 846 |
status = esl_workqueue_WorkerUpdate(info->queue, block, NULL); |
| 847 |
if (status != eslOK) esl_fatal("Work queue worker failed"); |
| 848 |
|
| 849 |
esl_threads_Finished(obj, workeridx); |
| 850 |
return; |
| 851 |
|
| 852 |
|
| 853 |
ERROR: |
| 854 |
esl_fatal("Error allocating memory in work queue"); |
| 855 |
return; |
| 856 |
} |
| 857 |
#endif |
| 858 |
|
| 859 |
|