Debian Codegraph @

hmmer/src/hmmsim.c

raw symbols SCIP
1 /* hmmsim: scoring profile HMMs against simulated sequences.
2 *
3 * Main testbed for exploring the statistical behavior of HMMER3
4 * scores on random sequences.
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" /* Exclusive choice for scoring algorithms */
35 #define STYLES "--fs,--sw,--ls,--s" /* Exclusive choice for alignment mode */
36
37 static ESL_OPTIONS options[] = {
38 /* name type default env range toggles reqs incomp help docgroup*/
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 /* struct cfg_s : "Global" application configuration shared by all threads/processes.
95 *
96 * This structure is passed to routines within main.c, as a means of semi-encapsulation
97 * of shared data amongst different parallel processes (threads or MPI processes).
98 */
99 struct cfg_s {
100 /* Shared configuration in masters & workers */
101 char *hmmfile; /* name of input HMM file */
102 ESL_RANDOMNESS *r; /* randomness source */
103 ESL_ALPHABET *abc; /* alphabet type, eslAMINO */
104 P7_BG *bg; /* background model */
105 int my_rank; /* 0 in masters, >0 in workers */
106 int nproc; /* 1 in serial mode, >1 in MPI */
107 int do_mpi; /* TRUE if we're --mpi */
108 int do_stall; /* TRUE to stall for MPI debugging */
109 int N; /* number of simulated seqs per HMM */
110 int L; /* length of simulated seqs */
111
112 /* Masters only (i/o streams) */
113 P7_HMMFILE *hfp; /* open input HMM file stream */
114 FILE *ofp; /* output file for results (default is stdout) */
115 FILE *survfp; /* optional output for survival plots */
116 FILE *efp; /* optional output for E vs. E plots */
117 FILE *ffp; /* optional output for filter power data */
118 FILE *xfp; /* optional output for binary score vectors */
119 FILE *alfp; /* optional output for alignment lengths */
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 /* Process command line options.
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); /* 1=docgroup, 2 = indentation; 80=textwidth*/
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); /* 1=docgroup, 2 = indentation; 80=textwidth*/
184 printf("\nTo see more help on available options, do %s -h\n\n", argv[0]);
185 exit(1);
186 }
187
188
189 /* Initialize configuration shared across all kinds of masters
190 * and workers in this .c file.
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; /* MPI init will change this soon, if --mpi was set */
197 cfg.nproc = 0; /* MPI init will change this soon, if --mpi was set */
198 cfg.do_mpi = FALSE; /* --mpi will change this soon (below) if necessary */
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 /* This is our stall point, if we need to wait until we get a
212 * debugger attached to this process for debugging (especially
213 * useful for MPI):
214 */
215 while (cfg.do_stall);
216
217
218 /* Start timing. */
219 esl_stopwatch_Start(w);
220
221
222 /* Main body:
223 * Handed off to serial version or MPI masters and workers as appropriate.
224 */
225 #ifdef HMMER_MPI
226 if (esl_opt_GetBoolean(go, "--mpi"))
227 {
228 /* Initialize MPI, figure out who we are, and whether we're running
229 * this show (proc 0) or working in it (procs >0).
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(); /* both workers and masters reach this line */
243 }
244 else
245 #endif /*HMMER_MPI*/
246 {
247 /* No MPI? Then we're just the serial master. */
248 serial_master(go, &cfg);
249 esl_stopwatch_Stop(w);
250 }
251
252 /* Stop timing. */
253 if (cfg.my_rank == 0) esl_stopwatch_Display(stdout, w, "# CPU time: ");
254
255 /* Clean up and exit. */
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 /* init_master_cfg()
274 * Called by either master version, mpi or serial.
275 * Already set:
276 * cfg->hmmfile - command line arg
277 * Sets:
278 * cfg->hfp - open HMM stream
279 * cfg->ofp - open output steam
280 * cfg->survfp - open xmgrace survival plot file
281 * cfg->efp - open E vs. E plot file
282 * cfg->ffp - open filter power data file
283 * cfg->xfp - open binary score file
284 * cfg->alfp - open alignment length file
285 *
286 * Error handling relies on the result pointers being initialized to
287 * NULL by the caller.
288 *
289 * Errors in the MPI master here are considered to be "recoverable",
290 * in the sense that we'll try to delay output of the error message
291 * until we've cleanly shut down the worker processes. Therefore
292 * errors return (code, errmsg) by the ESL_FAIL mech.
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; /* results: array of N scores */
359 int *av = NULL; /* optional results: array of N alignment lengths */
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")); /* set the null model background length in both master and workers. */
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 /* mpi_master()
395 * The MPI version of hmmsim.
396 * Follows standard pattern for a master/worker load-balanced MPI program (J1/78-79).
397 *
398 * A master can only return if it's successful.
399 * Errors in an MPI master come in two classes: recoverable and nonrecoverable.
400 *
401 * Recoverable errors include all worker-side errors, and any
402 * master-side error that do not affect MPI communication. Error
403 * messages from recoverable messages are delayed until we've cleanly
404 * shut down the workers.
405 *
406 * Unrecoverable errors are master-side errors that may affect MPI
407 * communication, meaning we cannot count on being able to reach the
408 * workers and shut them down. Unrecoverable errors result in immediate
409 * p7_Fail()'s, which will cause MPI to shut down the worker processes
410 * uncleanly.
411 */
412 static void
413 mpi_master(ESL_GETOPTS *go, struct cfg_s *cfg)
414 {
415 int xstatus = eslOK; /* changes in the event of a recoverable error */
416 P7_HMM *hmm = NULL; /* query HMM */
417 P7_HMM **hmmlist = NULL; /* queue of HMMs being worked on, 1..nproc-1 */
418 char *wbuf = NULL; /* working buffer for sending packed profiles and receiving packed results. */
419 int wn = 0;
420 double *xv = NULL; /* results: array of N scores */
421 int *av = NULL; /* optional results: array of N alignment lengths */
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 /* Master initialization. */
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 /* Standard design pattern for data parallelization in a master/worker model. (J1/78-79). */
443 wi = 1;
444 while (have_work || nproc_working)
445 {
446 /* Get next work unit: one HMM, <hmm> */
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) { // first time only
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 //this next step is redundant, but it avoids a race condition above.
462 p7_bg_SetLength(cfg->bg, esl_opt_GetInteger(go, "-L")); /* set the null model background length in both master and workers. */
463 }
464 }
465
466 /* If we have work but no free workers, or we have no work but workers
467 * are still working, then wait for a result to return from any worker.
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 /* Check the xstatus before printing results.
475 * If we're in a recoverable error state, we're only clearing worker results, prior to a clean failure
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) /* worker reported success. Get the results. */
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 /* worker reported a user error. Get the errbuf. */
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 /* If we have work, assign it to a free worker; else, terminate the free worker. */
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 /* Tell all the workers (1..nproc-1) to shut down by sending them a NULL workunit. */
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 /* mpi_worker()
534 * The main control for an MPI worker process.
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; /* result: array of N scores */
543 int *av = NULL; /* optional result: array of N alignment lengths */
544 int wn = 0;
545 char errbuf[eslERRBUFSIZE];
546 int pos;
547 double mu, lambda;
548
549 /* Worker initializes */
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 /* Main worker loop */
557 while (p7_hmm_MPIRecv(0, 0, MPI_COMM_WORLD, &wbuf, &wn, &(cfg->abc), &hmm) == eslOK)
558 {
559 if (cfg->bg == NULL) { // first time only
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 /*HMMER_MPI*/
597
598
599 /* process_workunit()
600 *
601 * This is the routine that actually does the work.
602 *
603 * A work unit consists of one HMM, <hmm>.
604 * The result is the <scores> array, which contains an array of N scores;
605 * caller provides this memory.
606 * How those scores are generated is controlled by the application configuration in <cfg>.
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]; /* state usage counts from a trace */
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 // reseed the RNG to its initial value, to allow reproduction of results
635 esl_randomness_Init(cfg->r, esl_opt_GetInteger(go, "--seed"));
636 /* Optionally set a custom background, determined by model composition;
637 * an experimental hack.
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 /* First pass: configure gm, om for local until after we've determined mu, lambda, tau params */
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 /* Determine E-value parameters (in addition to any that are already in the HMM structure) */
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; /* undetermined, for Hybrid, at least for now. */
660
661 /* Now reconfig the models however we were asked to */
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 /* Remaining allocations */
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 /* Collect scores from N random sequences of length L */
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) /* note, if a filter overflows, failover to slow versions */
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 /* Optional: get Viterbi alignment length too. */
699 if (esl_opt_GetBoolean(go, "-a")) /* -a only works with Viterbi; getopts has checked this already */
700 {
701 p7_GTrace(dsq, L, gm, gx, tr);
702 p7_trace_GetStateUseCounts(tr, scounts);
703
704 /* there's various ways we could counts "alignment length".
705 * Here we'll use the total length of model used, in nodes: M+D states.
706 * score vs al would gives us relative entropy / model position.
707 */
708 /* alilens[i] = scounts[p7T_D] + scounts[p7T_I]; SRE: temporarily testing this instead */
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; /* alignment length mean and variance (optional output) */
746 int status;
747
748
749 /* Optional output of scores/alignment lengths:
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 /* optional "filter power" data file: <hmm name> <# seqs <= P threshold> <fraction of seqs <= P threshold> */
756 if (cfg->ffp) output_filter_power(go, cfg, errbuf, hmm, scores, pmu, plambda);
757
758 /* Count the scores into a histogram object. */
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 /* For viterbi, MSV, and hybrid, fit data to a Gumbel, either with known lambda or estimated lambda. */
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 /* mu, lambda, E10 fields: ML Gumbel fit to the observed data */
769 esl_gumbel_FitComplete(scores, cfg->N, &mu, &lambda);
770 E10 = cfg->N * esl_gumbel_surv(x10, mu, lambda);
771
772 /* mufix, E10fix fields: assume lambda = log2; fit an ML mu to the data */
773 esl_gumbel_FitCompleteLoc(scores, cfg->N, 0.693147, &mufix);
774 E10fix = cfg->N * esl_gumbel_surv(x10, mufix, 0.693147);
775
776 /* mufix2, E10fix2 fields: assume edge-corrected H3 lambda estimate; fit ML mu */
777 esl_gumbel_FitCompleteLoc(scores, cfg->N, plambda, &mufix2);
778 E10fix2 = cfg->N * esl_gumbel_surv(x10, mufix2, plambda);
779
780 /* pmu, plambda, E10p: use H3 estimates (pmu, plambda) */
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 /* For Forward, fit tail to exponential tails, for a range of tail mass choices. */
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); /* the pmu is relative to a P=1.0 tail origin. */
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 /* fallthrough: both normal, error cases execute same cleanup code */
863 status = eslOK;
864 ERROR:
865 esl_histogram_Destroy(h);
866 return status;
867 }
868
869
870 /* output_filter_power()
871 *
872 * Used for testing whether the filters (MSV scores, Viterbi scores)
873 * have the power they're supposed to have: for example, if MSV filter
874 * is set at a P-value threshold of 0.02, ~2% of sequences should get
875 * through, regardless of things like model and target sequence
876 * length.
877 *
878 * Output a file suitable for constructing histograms over many HMMs,
879 * for a particular choice of hmmsim'ed L and N targets:
880 * <hmm name> <# of seqs passing threshold> <fraction of seqs passing threshold>
881 *
882 * SRE, Thu Apr 9 08:57:32 2009 [Janelia] xref J4/133
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"); /* P-value threshold set for the filter score */
888 double P; /* calculated P-value (using HMM's own calibration) */
889 int npass = 0; /* number of scores that pass the P threshold */
890 double fpass; /* fraction of scores that pass the P threshold */
891 int i; /* counter over scores */
892 int do_gumbel; /* flag for how to determine P values */
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 /* the pack send/recv buffer must be big enough to hold either an error message or a result vector.
915 * it may even grow larger than that, to hold largest HMM we send.
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 /* error packet */
925 if (MPI_Pack_size(eslERRBUFSIZE, MPI_CHAR, MPI_COMM_WORLD, &nerr)!= 0) return eslESYS;
926
927 /* results packet */
928 if (MPI_Pack_size(N, MPI_DOUBLE, MPI_COMM_WORLD, &n) != 0) return eslESYS; else nresult += n; /* scores */
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; /* alignment lengths */
931 }
932 if (MPI_Pack_size(1, MPI_DOUBLE, MPI_COMM_WORLD, &n) != 0) return eslESYS; else nresult += n*2; /* mu, lambda */
933
934 /* add the shared status code to the max of the two possible kinds of packets */
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 /* elide_length_model()
943 *
944 * Fix bg->p1 to 350/351,
945 * then make the N, C, J transition probabilities p1;
946 * this removes H3's length model, and emulates H2 instead.
947 *
948 * This makes the NN, CC, JJ transitions score 0, and
949 * makes the NB, CE, and JB transitions a fixed penalty
950 * of log(1/351).
951 *
952 * In general this isn't a good idea. This code is only for
953 * experimental purposes, demonstrating the difference between
954 * H3's improved statistics and the old way.
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