| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <p7_config.h> |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <string.h> |
| 11 |
#include <math.h> |
| 12 |
|
| 13 |
#ifdef HMMER_MPI |
| 14 |
#include "mpi.h" |
| 15 |
#endif |
| 16 |
|
| 17 |
#include "easel.h" |
| 18 |
#include "esl_alphabet.h" |
| 19 |
#include "esl_stats.h" |
| 20 |
#include "esl_exponential.h" |
| 21 |
#include "esl_dmatrix.h" |
| 22 |
#include "esl_getopts.h" |
| 23 |
#include "esl_gumbel.h" |
| 24 |
#include "esl_histogram.h" |
| 25 |
#include "esl_mpi.h" |
| 26 |
#include "esl_random.h" |
| 27 |
#include "esl_randomseq.h" |
| 28 |
#include "esl_ratematrix.h" |
| 29 |
#include "esl_stopwatch.h" |
| 30 |
#include "esl_vectorops.h" |
| 31 |
|
| 32 |
#include "hmmer.h" |
| 33 |
|
| 34 |
#define ALGORITHMS "--fwd,--vit,--hyb,--msv" |
| 35 |
#define STYLES "--fs,--sw,--ls,--s" |
| 36 |
|
| 37 |
static ESL_OPTIONS options[] = { |
| 38 |
|
| 39 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 1 }, |
| 40 |
{ "-a", eslARG_NONE, FALSE, NULL, NULL, NULL,"--vit",NULL, "obtain alignment length statistics too", 1 }, |
| 41 |
{ "-v", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "verbose: print scores", 1 }, |
| 42 |
{ "-L", eslARG_INT, "100", NULL, "n>0", NULL, NULL, NULL, "length of random target seqs", 1 }, |
| 43 |
{ "-N", eslARG_INT, "1000", NULL, "n>0", NULL, NULL, NULL, "number of random target seqs", 1 }, |
| 44 |
#ifdef HMMER_MPI |
| 45 |
{ "--mpi", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "run as an MPI parallel program", 1 }, |
| 46 |
#endif |
| 47 |
{ "-o", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "direct output to file <f>, not stdout", 2 }, |
| 48 |
{ "--afile", eslARG_OUTFILE, NULL, NULL, NULL, NULL, "-a", NULL, "output alignment lengths to file <f>", 2 }, |
| 49 |
{ "--efile", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "output E vs. E plots to <f> in xy format", 2 }, |
| 50 |
{ "--ffile", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "output filter fraction: # seqs passing P thresh", 2 }, |
| 51 |
{ "--pfile", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "output P(S>x) plots to <f> in xy format", 2 }, |
| 52 |
{ "--xfile", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "output bitscores as binary double vector to <f>", 2 }, |
| 53 |
|
| 54 |
{ "--fs", eslARG_NONE,"default",NULL, NULL, STYLES, NULL, NULL, "multihit local alignment", 3 }, |
| 55 |
{ "--sw", eslARG_NONE, FALSE, NULL, NULL, STYLES, NULL, NULL, "unihit local alignment", 3 }, |
| 56 |
{ "--ls", eslARG_NONE, FALSE, NULL, NULL, STYLES, NULL, NULL, "multihit glocal alignment", 3 }, |
| 57 |
{ "--s", eslARG_NONE, FALSE, NULL, NULL, STYLES, NULL, NULL, "unihit glocal alignment", 3 }, |
| 58 |
|
| 59 |
{ "--vit", eslARG_NONE,"default",NULL, NULL, ALGORITHMS, NULL, NULL, "score seqs with the Viterbi algorithm", 4 }, |
| 60 |
{ "--fwd", eslARG_NONE, FALSE, NULL, NULL, ALGORITHMS, NULL, NULL, "score seqs with the Forward algorithm", 4 }, |
| 61 |
{ "--hyb", eslARG_NONE, FALSE, NULL, NULL, ALGORITHMS, NULL, NULL, "score seqs with the Hybrid algorithm", 4 }, |
| 62 |
{ "--msv", eslARG_NONE, FALSE, NULL, NULL, ALGORITHMS, NULL, NULL, "score seqs with the MSV algorithm", 4 }, |
| 63 |
{ "--fast", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use the optimized versions of the above", 4 }, |
| 64 |
|
| 65 |
{ "--tmin", eslARG_REAL, "0.02", NULL, NULL, NULL, NULL, NULL, "set lower bound tail mass for fwd,island", 5 }, |
| 66 |
{ "--tmax", eslARG_REAL, "0.02", NULL, NULL, NULL, NULL, NULL, "set lower bound tail mass for fwd,island", 5 }, |
| 67 |
{ "--tpoints", eslARG_INT, "1", NULL, NULL, NULL, NULL, NULL, "set number of tail probs to try", 5 }, |
| 68 |
{ "--tlinear", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use linear not log spacing of tail probs", 5 }, |
| 69 |
|
| 70 |
{ "--EmL", eslARG_INT, "200", NULL, "n>0", NULL, NULL, NULL, "length of sequences for MSV Gumbel mu fit", 6 }, |
| 71 |
{ "--EmN", eslARG_INT, "200", NULL, "n>0", NULL, NULL, NULL, "number of sequences for MSV Gumbel mu fit", 6 }, |
| 72 |
{ "--EvL", eslARG_INT, "200", NULL, "n>0", NULL, NULL, NULL, "length of sequences for Viterbi Gumbel mu fit", 6 }, |
| 73 |
{ "--EvN", eslARG_INT, "200", NULL, "n>0", NULL, NULL, NULL, "number of sequences for Viterbi Gumbel mu fit", 6 }, |
| 74 |
{ "--EfL", eslARG_INT, "100", NULL, "n>0", NULL, NULL, NULL, "length of sequences for Forward exp tail tau fit", 6 }, |
| 75 |
{ "--EfN", eslARG_INT, "200", NULL, "n>0", NULL, NULL, NULL, "number of sequences for Forward exp tail tau fit", 6 }, |
| 76 |
{ "--Eft", eslARG_REAL, "0.04", NULL, "0<x<1", NULL, NULL, NULL, "tail mass for Forward exponential tail tau fit", 6 }, |
| 77 |
|
| 78 |
{ "--stall", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "arrest after start: for debugging MPI under gdb", 7 }, |
| 79 |
{ "--seed", eslARG_INT, "0", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 7 }, |
| 80 |
|
| 81 |
{ "--bgflat", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "set uniform background frequencies", 8 }, |
| 82 |
{ "--bgcomp", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "set bg frequencies to model's average composition", 8 }, |
| 83 |
{ "--x-no-lengthmodel", eslARG_NONE, FALSE,NULL,NULL, NULL, NULL, NULL, "turn the H3 length model off", 8 }, |
| 84 |
{ "--nu", eslARG_REAL, "2.0", NULL, NULL, NULL,"--msv","--fast", "set nu parameter (# expected HSPs) for GMSV", 8 }, |
| 85 |
{ "--pthresh", eslARG_REAL, "0.02",NULL, NULL, NULL,"--ffile", NULL, "set P-value threshold for --ffile", 8 }, |
| 86 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 87 |
}; |
| 88 |
|
| 89 |
static char usage[] = "[-options] <hmmfile>"; |
| 90 |
static char banner[] = "collect profile HMM score distributions on random sequences"; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
struct cfg_s { |
| 100 |
|
| 101 |
char *hmmfile; |
| 102 |
ESL_RANDOMNESS *r; |
| 103 |
ESL_ALPHABET *abc; |
| 104 |
P7_BG *bg; |
| 105 |
int my_rank; |
| 106 |
int nproc; |
| 107 |
int do_mpi; |
| 108 |
int do_stall; |
| 109 |
int N; |
| 110 |
int L; |
| 111 |
|
| 112 |
|
| 113 |
P7_HMMFILE *hfp; |
| 114 |
FILE *ofp; |
| 115 |
FILE *survfp; |
| 116 |
FILE *efp; |
| 117 |
FILE *ffp; |
| 118 |
FILE *xfp; |
| 119 |
FILE *alfp; |
| 120 |
}; |
| 121 |
|
| 122 |
|
| 123 |
static int init_master_cfg(ESL_GETOPTS *go, struct cfg_s *cfg, char *errbuf); |
| 124 |
|
| 125 |
static void serial_master (ESL_GETOPTS *go, struct cfg_s *cfg); |
| 126 |
#ifdef HMMER_MPI |
| 127 |
static void mpi_master (ESL_GETOPTS *go, struct cfg_s *cfg); |
| 128 |
static void mpi_worker (ESL_GETOPTS *go, struct cfg_s *cfg); |
| 129 |
static int minimum_mpi_working_buffer(ESL_GETOPTS *go, int N, int *ret_wn); |
| 130 |
#endif |
| 131 |
static int process_workunit (ESL_GETOPTS *go, struct cfg_s *cfg, char *errbuf, P7_HMM *hmm, double *scores, int *alilens, double *ret_mu, double *ret_lambda); |
| 132 |
static int output_result (ESL_GETOPTS *go, struct cfg_s *cfg, char *errbuf, P7_HMM *hmm, double *scores, int *alilens, double mu, double lambda); |
| 133 |
static int output_filter_power(ESL_GETOPTS *go, struct cfg_s *cfg, char *errbuf, P7_HMM *hmm, double *scores, double mu, double lambda); |
| 134 |
|
| 135 |
static int elide_length_model(P7_PROFILE *gm, P7_BG *bg); |
| 136 |
|
| 137 |
int |
| 138 |
main(int argc, char **argv) |
| 139 |
{ |
| 140 |
ESL_GETOPTS *go = NULL; |
| 141 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 142 |
struct cfg_s cfg; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
go = esl_getopts_Create(options); |
| 148 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK || |
| 149 |
esl_opt_VerifyConfig(go) != eslOK) |
| 150 |
{ |
| 151 |
printf("Failed to parse command line: %s\n", go->errbuf); |
| 152 |
esl_usage(stdout, argv[0], usage); |
| 153 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 154 |
exit(1); |
| 155 |
} |
| 156 |
if (esl_opt_GetBoolean(go, "-h") == TRUE) |
| 157 |
{ |
| 158 |
p7_banner(stdout, argv[0], banner); |
| 159 |
esl_usage(stdout, argv[0], usage); |
| 160 |
puts("\nCommon options:"); |
| 161 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 162 |
puts("\nOutput options (only in serial mode, for single HMM input):"); |
| 163 |
esl_opt_DisplayHelp(stdout, go, 2, 2, 80); |
| 164 |
puts("\nAlternative alignment styles :"); |
| 165 |
esl_opt_DisplayHelp(stdout, go, 3, 2, 80); |
| 166 |
puts("\nAlternative scoring algorithms :"); |
| 167 |
esl_opt_DisplayHelp(stdout, go, 4, 2, 80); |
| 168 |
puts("\nControlling range of fitted tail masses :"); |
| 169 |
esl_opt_DisplayHelp(stdout, go, 5, 2, 80); |
| 170 |
puts("\nControlling E-value calibration :"); |
| 171 |
esl_opt_DisplayHelp(stdout, go, 6, 2, 80); |
| 172 |
puts("\nDebugging :"); |
| 173 |
esl_opt_DisplayHelp(stdout, go, 7, 2, 80); |
| 174 |
puts("\nExperiments :"); |
| 175 |
esl_opt_DisplayHelp(stdout, go, 8, 2, 80); |
| 176 |
exit(0); |
| 177 |
} |
| 178 |
if (esl_opt_ArgNumber(go) != 1) |
| 179 |
{ |
| 180 |
puts("Incorrect number of command line arguments."); |
| 181 |
esl_usage(stdout, argv[0], usage); |
| 182 |
puts("\nwhere general options are:"); |
| 183 |
esl_opt_DisplayHelp(stdout, go, 1, 2, 80); |
| 184 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 185 |
exit(1); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
cfg.hmmfile = esl_opt_GetArg(go, 1); |
| 193 |
cfg.r = esl_randomness_Create(esl_opt_GetInteger(go, "--seed")); |
| 194 |
cfg.abc = NULL; |
| 195 |
|
| 196 |
cfg.my_rank = 0; |
| 197 |
cfg.nproc = 0; |
| 198 |
cfg.do_mpi = FALSE; |
| 199 |
cfg.do_stall = esl_opt_GetBoolean(go, "--stall"); |
| 200 |
cfg.N = esl_opt_GetInteger(go, "-N"); |
| 201 |
cfg.L = esl_opt_GetInteger(go, "-L"); |
| 202 |
cfg.hfp = NULL; |
| 203 |
cfg.ofp = NULL; |
| 204 |
cfg.survfp = NULL; |
| 205 |
cfg.efp = NULL; |
| 206 |
cfg.ffp = NULL; |
| 207 |
cfg.xfp = NULL; |
| 208 |
cfg.alfp = NULL; |
| 209 |
cfg.bg = NULL; |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
while (cfg.do_stall); |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
esl_stopwatch_Start(w); |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
#ifdef HMMER_MPI |
| 226 |
if (esl_opt_GetBoolean(go, "--mpi")) |
| 227 |
{ |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
cfg.do_mpi = TRUE; |
| 232 |
MPI_Init(&argc, &argv); |
| 233 |
MPI_Comm_rank(MPI_COMM_WORLD, &(cfg.my_rank)); |
| 234 |
MPI_Comm_size(MPI_COMM_WORLD, &(cfg.nproc)); |
| 235 |
if (cfg.my_rank == 0 && cfg.nproc < 2) p7_Fail("Need at least 2 MPI processes to run --mpi mode."); |
| 236 |
|
| 237 |
if (cfg.my_rank > 0) mpi_worker(go, &cfg); |
| 238 |
else mpi_master(go, &cfg); |
| 239 |
|
| 240 |
esl_stopwatch_Stop(w); |
| 241 |
esl_stopwatch_MPIReduce(w, 0, MPI_COMM_WORLD); |
| 242 |
MPI_Finalize(); |
| 243 |
} |
| 244 |
else |
| 245 |
#endif |
| 246 |
{ |
| 247 |
|
| 248 |
serial_master(go, &cfg); |
| 249 |
esl_stopwatch_Stop(w); |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
if (cfg.my_rank == 0) esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 254 |
|
| 255 |
|
| 256 |
if (cfg.my_rank == 0) { |
| 257 |
if (cfg.hfp != NULL) p7_hmmfile_Close(cfg.hfp); |
| 258 |
if (esl_opt_IsOn(go, "-o")) fclose(cfg.ofp); |
| 259 |
if (cfg.survfp != NULL) fclose(cfg.survfp); |
| 260 |
if (cfg.efp != NULL) fclose(cfg.efp); |
| 261 |
if (cfg.ffp != NULL) fclose(cfg.ffp); |
| 262 |
if (cfg.xfp != NULL) fclose(cfg.xfp); |
| 263 |
if (cfg.alfp != NULL) fclose(cfg.alfp); |
| 264 |
} |
| 265 |
p7_bg_Destroy(cfg.bg); |
| 266 |
esl_alphabet_Destroy(cfg.abc); |
| 267 |
esl_randomness_Destroy(cfg.r); |
| 268 |
esl_getopts_Destroy(go); |
| 269 |
esl_stopwatch_Destroy(w); |
| 270 |
return eslOK; |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
static int |
| 295 |
init_master_cfg(ESL_GETOPTS *go, struct cfg_s *cfg, char *errbuf) |
| 296 |
{ |
| 297 |
char *filename; |
| 298 |
int status; |
| 299 |
|
| 300 |
status = p7_hmmfile_Open(cfg->hmmfile, NULL, &(cfg->hfp), NULL); |
| 301 |
if (status == eslENOTFOUND) ESL_FAIL(eslFAIL, errbuf, "Failed to open HMM file %s for reading.\n", cfg->hmmfile); |
| 302 |
else if (status == eslEFORMAT) ESL_FAIL(eslFAIL, errbuf, "File %s does not appear to be in a recognized HMM format.\n", cfg->hmmfile); |
| 303 |
else if (status != eslOK) ESL_FAIL(eslFAIL, errbuf, "Unexpected error %d in opening HMM file %s.\n", status, cfg->hmmfile); |
| 304 |
|
| 305 |
filename = esl_opt_GetString(go, "-o"); |
| 306 |
if (filename != NULL) |
| 307 |
{ |
| 308 |
if ((cfg->ofp = fopen(filename, "w")) == NULL) |
| 309 |
ESL_FAIL(eslFAIL, errbuf, "Failed to open -o output file %s\n", filename); |
| 310 |
} |
| 311 |
else cfg->ofp = stdout; |
| 312 |
|
| 313 |
filename = esl_opt_GetString(go, "--pfile"); |
| 314 |
if (filename != NULL) |
| 315 |
{ |
| 316 |
if ((cfg->survfp = fopen(filename, "w")) == NULL) |
| 317 |
ESL_FAIL(eslFAIL, errbuf, "Failed to open --pfile output file %s\n", filename); |
| 318 |
} |
| 319 |
|
| 320 |
filename = esl_opt_GetString(go, "--efile"); |
| 321 |
if (filename != NULL) |
| 322 |
{ |
| 323 |
if ((cfg->efp = fopen(filename, "w")) == NULL) |
| 324 |
ESL_FAIL(eslFAIL, errbuf, "Failed to open --efile output file %s\n", filename); |
| 325 |
} |
| 326 |
|
| 327 |
filename = esl_opt_GetString(go, "--ffile"); |
| 328 |
if (filename != NULL) |
| 329 |
{ |
| 330 |
if ((cfg->ffp = fopen(filename, "w")) == NULL) |
| 331 |
ESL_FAIL(eslFAIL, errbuf, "Failed to open --ffile output file %s\n", filename); |
| 332 |
} |
| 333 |
|
| 334 |
filename = esl_opt_GetString(go, "--xfile"); |
| 335 |
if (filename != NULL) |
| 336 |
{ |
| 337 |
if ((cfg->xfp = fopen(filename, "w")) == NULL) |
| 338 |
ESL_FAIL(eslFAIL, errbuf, "Failed to open --xfile output file %s\n", filename); |
| 339 |
} |
| 340 |
|
| 341 |
filename = esl_opt_GetString(go, "--afile"); |
| 342 |
if (filename != NULL) |
| 343 |
{ |
| 344 |
if ((cfg->alfp = fopen(filename, "w")) == NULL) |
| 345 |
ESL_FAIL(eslFAIL, errbuf, "Failed to open --afile output file %s\n", filename); |
| 346 |
} |
| 347 |
|
| 348 |
return eslOK; |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
static void |
| 355 |
serial_master(ESL_GETOPTS *go, struct cfg_s *cfg) |
| 356 |
{ |
| 357 |
P7_HMM *hmm = NULL; |
| 358 |
double *xv = NULL; |
| 359 |
int *av = NULL; |
| 360 |
double mu, lambda; |
| 361 |
char errbuf[eslERRBUFSIZE]; |
| 362 |
int status; |
| 363 |
|
| 364 |
|
| 365 |
if ((status = init_master_cfg(go, cfg, errbuf)) != eslOK) p7_Fail(errbuf); |
| 366 |
if ((xv = malloc(sizeof(double) * cfg->N)) == NULL) p7_Fail("allocation failed"); |
| 367 |
if (esl_opt_GetBoolean(go, "-a") && |
| 368 |
(av = malloc(sizeof(int) * cfg->N)) == NULL) p7_Fail("allocation failed"); |
| 369 |
|
| 370 |
while ((status = p7_hmmfile_Read(cfg->hfp, &(cfg->abc), &hmm)) != eslEOF) |
| 371 |
{ |
| 372 |
if (status == eslEOD) p7_Fail("read failed, HMM file %s may be truncated?", cfg->hmmfile); |
| 373 |
else if (status == eslEFORMAT) p7_Fail("bad file format in HMM file %s", cfg->hmmfile); |
| 374 |
else if (status == eslEINCOMPAT) p7_Fail("HMM file %s contains different alphabets", cfg->hmmfile); |
| 375 |
else if (status != eslOK) p7_Fail("Unexpected error in reading HMMs from %s", cfg->hmmfile); |
| 376 |
|
| 377 |
if (cfg->bg == NULL) { |
| 378 |
if (esl_opt_GetBoolean(go, "--bgflat")) cfg->bg = p7_bg_CreateUniform(cfg->abc); |
| 379 |
else cfg->bg = p7_bg_Create(cfg->abc); |
| 380 |
p7_bg_SetLength(cfg->bg, esl_opt_GetInteger(go, "-L")); |
| 381 |
} |
| 382 |
|
| 383 |
if (process_workunit(go, cfg, errbuf, hmm, xv, av, &mu, &lambda) != eslOK) p7_Fail(errbuf); |
| 384 |
if (output_result (go, cfg, errbuf, hmm, xv, av, mu, lambda) != eslOK) p7_Fail(errbuf); |
| 385 |
|
| 386 |
p7_hmm_Destroy(hmm); |
| 387 |
} |
| 388 |
free(xv); |
| 389 |
if (av != NULL) free(av); |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
#ifdef HMMER_MPI |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
static void |
| 413 |
mpi_master(ESL_GETOPTS *go, struct cfg_s *cfg) |
| 414 |
{ |
| 415 |
int xstatus = eslOK; |
| 416 |
P7_HMM *hmm = NULL; |
| 417 |
P7_HMM **hmmlist = NULL; |
| 418 |
char *wbuf = NULL; |
| 419 |
int wn = 0; |
| 420 |
double *xv = NULL; |
| 421 |
int *av = NULL; |
| 422 |
int have_work = TRUE; |
| 423 |
int nproc_working = 0; |
| 424 |
int wi; |
| 425 |
int pos; |
| 426 |
double mu, lambda; |
| 427 |
char errbuf[eslERRBUFSIZE]; |
| 428 |
int status; |
| 429 |
MPI_Status mpistatus; |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
if (init_master_cfg(go, cfg, errbuf) != eslOK) p7_Fail(errbuf); |
| 434 |
if (minimum_mpi_working_buffer(go, cfg->N, &wn) != eslOK) p7_Fail("mpi pack sizes must have failed"); |
| 435 |
ESL_ALLOC(wbuf, sizeof(char) * wn); |
| 436 |
ESL_ALLOC(xv, sizeof(double) * cfg->N); |
| 437 |
if (esl_opt_GetBoolean(go, "-a")) |
| 438 |
ESL_ALLOC(av, sizeof(int) * cfg->N); |
| 439 |
ESL_ALLOC(hmmlist, sizeof(P7_HMM *) * cfg->nproc); |
| 440 |
for (wi = 0; wi < cfg->nproc; wi++) hmmlist[wi] = NULL; |
| 441 |
|
| 442 |
|
| 443 |
wi = 1; |
| 444 |
while (have_work || nproc_working) |
| 445 |
{ |
| 446 |
|
| 447 |
if (have_work) |
| 448 |
{ |
| 449 |
if ((status = p7_hmmfile_Read(cfg->hfp, &(cfg->abc), &hmm)) != eslOK) |
| 450 |
{ |
| 451 |
have_work = FALSE; |
| 452 |
if (status == eslEOD) { xstatus = status; snprintf(errbuf, eslERRBUFSIZE, "read failed, HMM file %s may be truncated?", cfg->hmmfile); } |
| 453 |
else if (status == eslEFORMAT) { xstatus = status; snprintf(errbuf, eslERRBUFSIZE, "bad file format in HMM file %s", cfg->hmmfile); } |
| 454 |
else if (status == eslEINCOMPAT) { xstatus = status; snprintf(errbuf, eslERRBUFSIZE, "HMM file %s contains different alphabets", cfg->hmmfile); } |
| 455 |
else if (status != eslEOF) { xstatus = status; snprintf(errbuf, eslERRBUFSIZE, "Unexpected error in reading HMMs from %s", cfg->hmmfile); } |
| 456 |
|
| 457 |
if (cfg->bg == NULL) { |
| 458 |
if (esl_opt_GetBoolean(go, "--bgflat")) cfg->bg = p7_bg_CreateUniform(cfg->abc); |
| 459 |
else cfg->bg = p7_bg_Create(cfg->abc); |
| 460 |
} |
| 461 |
|
| 462 |
p7_bg_SetLength(cfg->bg, esl_opt_GetInteger(go, "-L")); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
if ( (have_work && nproc_working == cfg->nproc-1) || (! have_work && nproc_working > 0)) |
| 470 |
{ |
| 471 |
if (MPI_Recv(wbuf, wn, MPI_PACKED, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &mpistatus) != 0) p7_Fail("mpi recv failed"); |
| 472 |
wi = mpistatus.MPI_SOURCE; |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
if (xstatus == eslOK) |
| 478 |
{ |
| 479 |
pos = 0; |
| 480 |
if (MPI_Unpack(wbuf, wn, &pos, &xstatus, 1, MPI_INT, MPI_COMM_WORLD) != 0) p7_Fail("mpi unpack failed"); |
| 481 |
if (xstatus == eslOK) |
| 482 |
{ |
| 483 |
if (MPI_Unpack(wbuf, wn, &pos, xv, cfg->N, MPI_DOUBLE, MPI_COMM_WORLD) != 0) p7_Fail("score vector unpack failed"); |
| 484 |
if (esl_opt_GetBoolean(go, "-a") && |
| 485 |
MPI_Unpack(wbuf, wn, &pos, av, cfg->N, MPI_INT, MPI_COMM_WORLD) != 0) p7_Fail("alilen vector unpack failed"); |
| 486 |
if (MPI_Unpack(wbuf, wn, &pos, &mu, 1, MPI_DOUBLE, MPI_COMM_WORLD) != 0) p7_Fail("mu param unpack failed"); |
| 487 |
if (MPI_Unpack(wbuf, wn, &pos, &lambda, 1, MPI_DOUBLE, MPI_COMM_WORLD) != 0) p7_Fail("lambda param unpack failed"); |
| 488 |
if ((status = output_result(go, cfg, errbuf, hmmlist[wi], xv, av, mu, lambda)) != eslOK) xstatus = status; |
| 489 |
} |
| 490 |
else |
| 491 |
{ |
| 492 |
if (MPI_Unpack(wbuf, wn, &pos, errbuf, eslERRBUFSIZE, MPI_CHAR, MPI_COMM_WORLD) != 0) p7_Fail("mpi unpack of errbuf failed"); |
| 493 |
have_work = FALSE; |
| 494 |
p7_hmm_Destroy(hmm); |
| 495 |
} |
| 496 |
} |
| 497 |
p7_hmm_Destroy(hmmlist[wi]); |
| 498 |
hmmlist[wi] = NULL; |
| 499 |
nproc_working--; |
| 500 |
} |
| 501 |
|
| 502 |
|
| 503 |
if (have_work) |
| 504 |
{ |
| 505 |
p7_hmm_MPISend(hmm, wi, 0, MPI_COMM_WORLD, &wbuf, &wn); |
| 506 |
hmmlist[wi] = hmm; |
| 507 |
wi++; |
| 508 |
nproc_working++; |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
for (wi = 1; wi < cfg->nproc; wi++) |
| 514 |
if (p7_hmm_MPISend(NULL, wi, 0, MPI_COMM_WORLD, &wbuf, &wn) != eslOK) p7_Fail("MPI HMM send failed"); |
| 515 |
|
| 516 |
|
| 517 |
free(hmmlist); |
| 518 |
free(wbuf); |
| 519 |
free(xv); |
| 520 |
if (av != NULL) free(av); |
| 521 |
if (xstatus != eslOK) p7_Fail(errbuf); |
| 522 |
else return; |
| 523 |
|
| 524 |
ERROR: |
| 525 |
if (hmmlist != NULL) free(hmmlist); |
| 526 |
if (wbuf != NULL) free(wbuf); |
| 527 |
if (xv != NULL) free(xv); |
| 528 |
if (av != NULL) free(av); |
| 529 |
p7_Fail("Fatal error in mpi_master"); |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
static void |
| 537 |
mpi_worker(ESL_GETOPTS *go, struct cfg_s *cfg) |
| 538 |
{ |
| 539 |
int status; |
| 540 |
P7_HMM *hmm = NULL; |
| 541 |
char *wbuf = NULL; |
| 542 |
double *xv = NULL; |
| 543 |
int *av = NULL; |
| 544 |
int wn = 0; |
| 545 |
char errbuf[eslERRBUFSIZE]; |
| 546 |
int pos; |
| 547 |
double mu, lambda; |
| 548 |
|
| 549 |
|
| 550 |
if ((status = minimum_mpi_working_buffer(go, cfg->N, &wn)) != eslOK) goto ERROR; |
| 551 |
ESL_ALLOC(wbuf, wn * sizeof(char)); |
| 552 |
ESL_ALLOC(xv, cfg->N * sizeof(double) + 2); |
| 553 |
if (esl_opt_GetBoolean(go, "-a")) |
| 554 |
ESL_ALLOC(av, cfg->N * sizeof(int)); |
| 555 |
|
| 556 |
|
| 557 |
while (p7_hmm_MPIRecv(0, 0, MPI_COMM_WORLD, &wbuf, &wn, &(cfg->abc), &hmm) == eslOK) |
| 558 |
{ |
| 559 |
if (cfg->bg == NULL) { |
| 560 |
if (esl_opt_GetBoolean(go, "--bgflat")) cfg->bg = p7_bg_CreateUniform(cfg->abc); |
| 561 |
else cfg->bg = p7_bg_Create(cfg->abc); |
| 562 |
} |
| 563 |
if ((status = process_workunit(go, cfg, errbuf, hmm, xv, av, &mu, &lambda)) != eslOK) goto CLEANERROR; |
| 564 |
|
| 565 |
pos = 0; |
| 566 |
MPI_Pack(&status, 1, MPI_INT, wbuf, wn, &pos, MPI_COMM_WORLD); |
| 567 |
MPI_Pack(xv, cfg->N, MPI_DOUBLE, wbuf, wn, &pos, MPI_COMM_WORLD); |
| 568 |
if (esl_opt_GetBoolean(go, "-a")) |
| 569 |
MPI_Pack(av, cfg->N, MPI_INT, wbuf, wn, &pos, MPI_COMM_WORLD); |
| 570 |
MPI_Pack(&mu, 1, MPI_DOUBLE, wbuf, wn, &pos, MPI_COMM_WORLD); |
| 571 |
MPI_Pack(&lambda, 1, MPI_DOUBLE, wbuf, wn, &pos, MPI_COMM_WORLD); |
| 572 |
MPI_Send(wbuf, pos, MPI_PACKED, 0, 0, MPI_COMM_WORLD); |
| 573 |
|
| 574 |
p7_hmm_Destroy(hmm); |
| 575 |
} |
| 576 |
|
| 577 |
free(wbuf); |
| 578 |
free(xv); |
| 579 |
if (av != NULL) free(av); |
| 580 |
return; |
| 581 |
|
| 582 |
CLEANERROR: |
| 583 |
pos = 0; |
| 584 |
MPI_Pack(&status, 1, MPI_INT, wbuf, wn, &pos, MPI_COMM_WORLD); |
| 585 |
MPI_Pack(errbuf, eslERRBUFSIZE, MPI_CHAR, wbuf, wn, &pos, MPI_COMM_WORLD); |
| 586 |
MPI_Send(wbuf, pos, MPI_PACKED, 0, 0, MPI_COMM_WORLD); |
| 587 |
if (wbuf != NULL) free(wbuf); |
| 588 |
if (hmm != NULL) p7_hmm_Destroy(hmm); |
| 589 |
if (xv != NULL) free(xv); |
| 590 |
if (av != NULL) free(av); |
| 591 |
return; |
| 592 |
|
| 593 |
ERROR: |
| 594 |
p7_Fail("Allocation error in mpi_worker"); |
| 595 |
} |
| 596 |
#endif |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
static int |
| 609 |
process_workunit(ESL_GETOPTS *go, struct cfg_s *cfg, char *errbuf, P7_HMM *hmm, double *scores, int *alilens, double *ret_mu, double *ret_lambda) |
| 610 |
{ |
| 611 |
int L = esl_opt_GetInteger(go, "-L"); |
| 612 |
P7_PROFILE *gm = NULL; |
| 613 |
P7_OPROFILE *om = NULL; |
| 614 |
P7_GMX *gx = NULL; |
| 615 |
P7_OMX *ox = NULL; |
| 616 |
P7_TRACE *tr = NULL; |
| 617 |
ESL_DSQ *dsq = NULL; |
| 618 |
int i; |
| 619 |
int status; |
| 620 |
int scounts[p7T_NSTATETYPES]; |
| 621 |
float sc; |
| 622 |
float nullsc; |
| 623 |
double mu, lambda; |
| 624 |
int EmL = esl_opt_GetInteger(go, "--EmL"); |
| 625 |
int EmN = esl_opt_GetInteger(go, "--EmN"); |
| 626 |
int EvL = esl_opt_GetInteger(go, "--EvL"); |
| 627 |
int EvN = esl_opt_GetInteger(go, "--EvN"); |
| 628 |
int EfL = esl_opt_GetInteger(go, "--EfL"); |
| 629 |
int EfN = esl_opt_GetInteger(go, "--EfN"); |
| 630 |
double Eft = esl_opt_GetReal (go, "--Eft"); |
| 631 |
float nu = esl_opt_GetReal (go, "--nu"); |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
esl_randomness_Init(cfg->r, esl_opt_GetInteger(go, "--seed")); |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
if (esl_opt_GetBoolean(go, "--bgcomp")) |
| 640 |
{ |
| 641 |
float *p = NULL; |
| 642 |
float KL; |
| 643 |
|
| 644 |
p7_hmm_CompositionKLD(hmm, cfg->bg, &KL, &p); |
| 645 |
esl_vec_FCopy(p, cfg->abc->K, cfg->bg->f); |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
gm = p7_profile_Create(hmm->M, cfg->abc); |
| 650 |
p7_ProfileConfig(hmm, cfg->bg, gm, L, p7_LOCAL); |
| 651 |
om = p7_oprofile_Create(gm->M, cfg->abc); |
| 652 |
p7_oprofile_Convert(gm, om); |
| 653 |
|
| 654 |
|
| 655 |
p7_Lambda(hmm, cfg->bg, &lambda); |
| 656 |
if (esl_opt_GetBoolean(go, "--vit")) p7_ViterbiMu(cfg->r, om, cfg->bg, EvL, EvN, lambda, &mu); |
| 657 |
else if (esl_opt_GetBoolean(go, "--msv")) p7_MSVMu (cfg->r, om, cfg->bg, EmL, EmN, lambda, &mu); |
| 658 |
else if (esl_opt_GetBoolean(go, "--fwd")) p7_Tau (cfg->r, om, cfg->bg, EfL, EfN, lambda, Eft, &mu); |
| 659 |
else mu = 0.0; |
| 660 |
|
| 661 |
|
| 662 |
if (esl_opt_GetBoolean(go, "--fs")) p7_ProfileConfig(hmm, cfg->bg, gm, L, p7_LOCAL); |
| 663 |
else if (esl_opt_GetBoolean(go, "--sw")) p7_ProfileConfig(hmm, cfg->bg, gm, L, p7_UNILOCAL); |
| 664 |
else if (esl_opt_GetBoolean(go, "--ls")) p7_ProfileConfig(hmm, cfg->bg, gm, L, p7_GLOCAL); |
| 665 |
else if (esl_opt_GetBoolean(go, "--s")) p7_ProfileConfig(hmm, cfg->bg, gm, L, p7_UNIGLOCAL); |
| 666 |
|
| 667 |
if (esl_opt_GetBoolean(go, "--x-no-lengthmodel")) elide_length_model(gm, cfg->bg); |
| 668 |
|
| 669 |
p7_oprofile_Convert(gm, om); |
| 670 |
p7_bg_SetLength (cfg->bg, L); |
| 671 |
|
| 672 |
|
| 673 |
gx = p7_gmx_Create(gm->M, L); |
| 674 |
ox = p7_omx_Create(gm->M, 0, L); |
| 675 |
ESL_ALLOC(dsq, sizeof(ESL_DSQ) * (L+2)); |
| 676 |
tr = p7_trace_Create(); |
| 677 |
|
| 678 |
|
| 679 |
for (i = 0; i < cfg->N; i++) |
| 680 |
{ |
| 681 |
esl_rsq_xfIID(cfg->r, cfg->bg->f, cfg->abc->K, L, dsq); |
| 682 |
|
| 683 |
if (esl_opt_GetBoolean(go, "--fast")) |
| 684 |
{ |
| 685 |
if (esl_opt_GetBoolean(go, "--vit")) p7_ViterbiFilter(dsq, L, om, ox, &sc); |
| 686 |
else if (esl_opt_GetBoolean(go, "--fwd")) p7_ForwardParser(dsq, L, om, ox, &sc); |
| 687 |
else if (esl_opt_GetBoolean(go, "--msv")) p7_MSVFilter (dsq, L, om, ox, &sc); |
| 688 |
} |
| 689 |
|
| 690 |
if (! esl_opt_GetBoolean(go, "--fast") || sc == eslINFINITY) |
| 691 |
{ |
| 692 |
if (esl_opt_GetBoolean(go, "--vit")) p7_GViterbi(dsq, L, gm, gx, &sc); |
| 693 |
else if (esl_opt_GetBoolean(go, "--fwd")) p7_GForward(dsq, L, gm, gx, &sc); |
| 694 |
else if (esl_opt_GetBoolean(go, "--hyb")) p7_GHybrid (dsq, L, gm, gx, NULL, &sc); |
| 695 |
else if (esl_opt_GetBoolean(go, "--msv")) p7_GMSV (dsq, L, gm, gx, nu, &sc); |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
if (esl_opt_GetBoolean(go, "-a")) |
| 700 |
{ |
| 701 |
p7_GTrace(dsq, L, gm, gx, tr); |
| 702 |
p7_trace_GetStateUseCounts(tr, scounts); |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
alilens[i] = scounts[p7T_M] + scounts[p7T_D] + scounts[p7T_I]; |
| 710 |
|
| 711 |
p7_trace_Reuse(tr); |
| 712 |
} |
| 713 |
|
| 714 |
p7_bg_NullOne(cfg->bg, dsq, L, &nullsc); |
| 715 |
scores[i] = (sc - nullsc) / eslCONST_LOG2; |
| 716 |
} |
| 717 |
|
| 718 |
*ret_mu = mu; |
| 719 |
*ret_lambda = lambda; |
| 720 |
status = eslOK; |
| 721 |
|
| 722 |
ERROR: |
| 723 |
if (dsq != NULL) free(dsq); |
| 724 |
p7_omx_Destroy(ox); |
| 725 |
p7_oprofile_Destroy(om); |
| 726 |
p7_profile_Destroy(gm); |
| 727 |
p7_gmx_Destroy(gx); |
| 728 |
p7_trace_Destroy(tr); |
| 729 |
if (status == eslEMEM) snprintf(errbuf, eslERRBUFSIZE, "allocation failure"); |
| 730 |
return status; |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
static int |
| 735 |
output_result(ESL_GETOPTS *go, struct cfg_s *cfg, char *errbuf, P7_HMM *hmm, double *scores, int *alilens, double pmu, double plambda) |
| 736 |
{ |
| 737 |
ESL_HISTOGRAM *h = NULL; |
| 738 |
int i; |
| 739 |
double tailp; |
| 740 |
double x10; |
| 741 |
double mu, lambda, E10; |
| 742 |
double mufix, E10fix; |
| 743 |
double mufix2, E10fix2; |
| 744 |
double E10p; |
| 745 |
double almean, alvar; |
| 746 |
int status; |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
if (cfg->xfp) fwrite(scores, sizeof(double), cfg->N, cfg->xfp); |
| 752 |
if (cfg->alfp) for (i = 0; i < cfg->N; i++) fprintf(cfg->alfp, "%d %.3f\n", alilens[i], scores[i]); |
| 753 |
if (esl_opt_GetBoolean(go, "-v")) for (i = 0; i < cfg->N; i++) printf("%.3f\n", scores[i]); |
| 754 |
|
| 755 |
|
| 756 |
if (cfg->ffp) output_filter_power(go, cfg, errbuf, hmm, scores, pmu, plambda); |
| 757 |
|
| 758 |
|
| 759 |
if ((h = esl_histogram_CreateFull(-50., 50., 0.2)) == NULL) ESL_XFAIL(eslEMEM, errbuf, "allocation failed"); |
| 760 |
for (i = 0; i < cfg->N; i++) esl_histogram_Add(h, scores[i]); |
| 761 |
|
| 762 |
|
| 763 |
if (esl_opt_GetBoolean(go, "--vit") || esl_opt_GetBoolean(go, "--hyb") || esl_opt_GetBoolean(go, "--msv")) |
| 764 |
{ |
| 765 |
esl_histogram_GetRank(h, 10, &x10); |
| 766 |
tailp = 1.0; |
| 767 |
|
| 768 |
|
| 769 |
esl_gumbel_FitComplete(scores, cfg->N, &mu, &lambda); |
| 770 |
E10 = cfg->N * esl_gumbel_surv(x10, mu, lambda); |
| 771 |
|
| 772 |
|
| 773 |
esl_gumbel_FitCompleteLoc(scores, cfg->N, 0.693147, &mufix); |
| 774 |
E10fix = cfg->N * esl_gumbel_surv(x10, mufix, 0.693147); |
| 775 |
|
| 776 |
|
| 777 |
esl_gumbel_FitCompleteLoc(scores, cfg->N, plambda, &mufix2); |
| 778 |
E10fix2 = cfg->N * esl_gumbel_surv(x10, mufix2, plambda); |
| 779 |
|
| 780 |
|
| 781 |
E10p = cfg->N * esl_gumbel_surv(x10, pmu, plambda); |
| 782 |
|
| 783 |
fprintf(cfg->ofp, "%-20s %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f", |
| 784 |
hmm->name, tailp, mu, lambda, E10, mufix, E10fix, mufix2, E10fix2, pmu, plambda, E10p); |
| 785 |
|
| 786 |
if (esl_opt_GetBoolean(go, "-a")) { |
| 787 |
esl_stats_IMean(alilens, cfg->N, &almean, &alvar); |
| 788 |
fprintf(cfg->ofp, " %8.4f %8.4f\n", almean, sqrt(alvar)); |
| 789 |
} else |
| 790 |
fprintf(cfg->ofp, "\n"); |
| 791 |
|
| 792 |
if (cfg->survfp != NULL) { |
| 793 |
esl_histogram_PlotSurvival(cfg->survfp, h); |
| 794 |
esl_gumbel_Plot(cfg->survfp, mu, lambda, esl_gumbel_surv, h->xmin - 5., h->xmax + 5., 0.1); |
| 795 |
esl_gumbel_Plot(cfg->survfp, mufix, 0.693147, esl_gumbel_surv, h->xmin - 5., h->xmax + 5., 0.1); |
| 796 |
} |
| 797 |
|
| 798 |
if (cfg->efp != NULL) { |
| 799 |
double x; |
| 800 |
|
| 801 |
fprintf(cfg->efp, "# %s\n", hmm->name); |
| 802 |
for (i = 1; i <= 1000 && i <= cfg->N; i++) { |
| 803 |
esl_histogram_GetRank(h, i, &x); |
| 804 |
fprintf(cfg->efp, "%d %g\n", i, cfg->N * esl_gumbel_surv(x, pmu, plambda)); |
| 805 |
} |
| 806 |
fprintf(cfg->efp, "&\n"); |
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
else if (esl_opt_GetBoolean(go, "--fwd")) |
| 812 |
{ |
| 813 |
double tmin = esl_opt_GetReal(go, "--tmin"); |
| 814 |
double tmax = esl_opt_GetReal(go, "--tmax"); |
| 815 |
double tpoints = (double) esl_opt_GetInteger(go, "--tpoints"); |
| 816 |
int do_linear = esl_opt_GetBoolean(go, "--tlinear"); |
| 817 |
double *xv; |
| 818 |
int n; |
| 819 |
|
| 820 |
esl_histogram_GetRank(h, 10, &x10); |
| 821 |
|
| 822 |
tailp = tmin; |
| 823 |
do { |
| 824 |
if (tailp > 1.0) tailp = 1.0; |
| 825 |
esl_histogram_GetTailByMass(h, tailp, &xv, &n, NULL); |
| 826 |
|
| 827 |
esl_exp_FitComplete(xv, n, &mu, &lambda); |
| 828 |
E10 = cfg->N * tailp * esl_exp_surv(x10, mu, lambda); |
| 829 |
mufix = mu; |
| 830 |
E10fix = cfg->N * tailp * esl_exp_surv(x10, mu, 0.693147); |
| 831 |
E10p = cfg->N * esl_exp_surv(x10, pmu, plambda); |
| 832 |
|
| 833 |
fprintf(cfg->ofp, "%-20s %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f\n", |
| 834 |
hmm->name, tailp, mu, lambda, E10, mufix, E10fix, pmu, plambda, E10p); |
| 835 |
|
| 836 |
if (tpoints == 1) break; |
| 837 |
else if (do_linear) tailp += (tmax-tmin) / (tpoints-1); |
| 838 |
else tailp *= exp(log(tmax/tmin) / (tpoints-1)); |
| 839 |
} while (tailp <= tmax+1e-7); |
| 840 |
|
| 841 |
if (cfg->survfp) |
| 842 |
{ |
| 843 |
esl_histogram_PlotSurvival(cfg->survfp, h); |
| 844 |
esl_exp_Plot(cfg->survfp, mu, lambda, esl_exp_surv, mu, h->xmax + 5., 0.1); |
| 845 |
esl_exp_Plot(cfg->survfp, mu, 0.693147, esl_exp_surv, mu, h->xmax + 5., 0.1); |
| 846 |
} |
| 847 |
|
| 848 |
if (cfg->efp != NULL) { |
| 849 |
double x; |
| 850 |
|
| 851 |
fprintf(cfg->efp, "# %s\n", hmm->name); |
| 852 |
for (i = 1; i <= 1000 && i <= cfg->N; i++) { |
| 853 |
esl_histogram_GetRank(h, i, &x); |
| 854 |
fprintf(cfg->efp, "%d %g\n", i, cfg->N * esl_exp_surv(x, pmu, plambda)); |
| 855 |
} |
| 856 |
fprintf(cfg->efp, "&\n"); |
| 857 |
} |
| 858 |
|
| 859 |
} |
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
status = eslOK; |
| 864 |
ERROR: |
| 865 |
esl_histogram_Destroy(h); |
| 866 |
return status; |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
static int |
| 885 |
output_filter_power(ESL_GETOPTS *go, struct cfg_s *cfg, char *errbuf, P7_HMM *hmm, double *scores, double pmu, double plambda) |
| 886 |
{ |
| 887 |
double pthresh = esl_opt_GetReal(go, "--pthresh"); |
| 888 |
double P; |
| 889 |
int npass = 0; |
| 890 |
double fpass; |
| 891 |
int i; |
| 892 |
int do_gumbel; |
| 893 |
|
| 894 |
if (esl_opt_GetBoolean(go, "--vit")) do_gumbel = TRUE; |
| 895 |
else if (esl_opt_GetBoolean(go, "--msv")) do_gumbel = TRUE; |
| 896 |
else if (esl_opt_GetBoolean(go, "--hyb")) do_gumbel = FALSE; |
| 897 |
else ESL_FAIL(eslEINVAL, errbuf, "can only use --ffile with viterbi, msv, or fwd scores"); |
| 898 |
|
| 899 |
for (i = 0; i < cfg->N; i++) |
| 900 |
{ |
| 901 |
P = (do_gumbel ? esl_gumbel_surv(scores[i], pmu, plambda) : |
| 902 |
esl_exp_surv (scores[i], pmu, plambda)); |
| 903 |
if (P <= pthresh) npass++; |
| 904 |
} |
| 905 |
fpass = (double) npass / (double) cfg->N; |
| 906 |
|
| 907 |
fprintf(cfg->ffp, "%s\t%d\t%.4f\n", hmm->name, npass, fpass); |
| 908 |
return eslOK; |
| 909 |
} |
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
#ifdef HMMER_MPI |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
static int |
| 918 |
minimum_mpi_working_buffer(ESL_GETOPTS *go, int N, int *ret_wn) |
| 919 |
{ |
| 920 |
int n; |
| 921 |
int nerr = 0; |
| 922 |
int nresult = 0; |
| 923 |
|
| 924 |
|
| 925 |
if (MPI_Pack_size(eslERRBUFSIZE, MPI_CHAR, MPI_COMM_WORLD, &nerr)!= 0) return eslESYS; |
| 926 |
|
| 927 |
|
| 928 |
if (MPI_Pack_size(N, MPI_DOUBLE, MPI_COMM_WORLD, &n) != 0) return eslESYS; else nresult += n; |
| 929 |
if (esl_opt_GetBoolean(go, "-a")) { |
| 930 |
if (MPI_Pack_size(N, MPI_INT, MPI_COMM_WORLD, &n) != 0) return eslESYS; else nresult += n; |
| 931 |
} |
| 932 |
if (MPI_Pack_size(1, MPI_DOUBLE, MPI_COMM_WORLD, &n) != 0) return eslESYS; else nresult += n*2; |
| 933 |
|
| 934 |
|
| 935 |
*ret_wn = ESL_MAX(nresult, nerr); |
| 936 |
if (MPI_Pack_size(1, MPI_INT, MPI_COMM_WORLD, &n) != 0) return eslESYS; else *ret_wn += n; |
| 937 |
return eslOK; |
| 938 |
} |
| 939 |
#endif |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
static int |
| 957 |
elide_length_model(P7_PROFILE *gm, P7_BG *bg) |
| 958 |
{ |
| 959 |
bg->p1 = 350./351.; |
| 960 |
|
| 961 |
gm->xsc[p7P_N][p7P_LOOP] = gm->xsc[p7P_C][p7P_LOOP] = gm->xsc[p7P_J][p7P_LOOP] = log(bg->p1); |
| 962 |
gm->xsc[p7P_N][p7P_MOVE] = gm->xsc[p7P_C][p7P_MOVE] = gm->xsc[p7P_J][p7P_MOVE] = log(1.0 - bg->p1); |
| 963 |
return eslOK; |
| 964 |
} |
| 965 |
|
| 966 |
|