예제 #1
0
static int
serial_loop(WORKER_INFO *info, struct cfg_s *cfg)
{
  P7_BUILDER *bld         = NULL;
  ESL_MSA    *msa         = NULL;
  ESL_MSA    *postmsa     = NULL;
  ESL_MSA   **postmsa_ptr = (cfg->postmsafile != NULL) ? &postmsa : NULL;
  P7_HMM     *hmm         = NULL;
  char        errmsg[eslERRBUFSIZE];
  int         status;

  double      entropy;

  cfg->nali = 0;
  while ((status = esl_msa_Read(cfg->afp, &msa)) == eslOK)
    {
      cfg->nali++;  

      if ((status = set_msa_name(cfg, errmsg, msa)) != eslOK) p7_Fail("%s\n", errmsg); /* cfg->nnamed gets incremented in this call */

                /*         bg   new-HMM trarr gm   om  */
      if ((status = p7_Builder(info->bld, msa, info->bg, &hmm, NULL, NULL, NULL, postmsa_ptr)) != eslOK) p7_Fail("build failed: %s", bld->errbuf);

      entropy = p7_MeanMatchRelativeEntropy(hmm, info->bg);
      if ((status = output_result(cfg, errmsg, cfg->nali, msa, hmm, postmsa, entropy))         != eslOK) p7_Fail(errmsg);

      p7_hmm_Destroy(hmm);
      esl_msa_Destroy(msa);
      esl_msa_Destroy(postmsa);
    }

  return status;
}
예제 #2
0
static void 
pipeline_thread(void *arg)
{
  int           workeridx;
  int           status;

  WORK_ITEM    *item;
  void         *newItem;

  WORKER_INFO  *info;
  ESL_THREADS  *obj;

  obj = (ESL_THREADS *) arg;
  esl_threads_Started(obj, &workeridx);

  info = (WORKER_INFO *) esl_threads_GetData(obj, workeridx);

  status = esl_workqueue_WorkerUpdate(info->queue, NULL, &newItem);
  if (status != eslOK) esl_fatal("Work queue worker failed");

  /* loop until all blocks have been processed */
  item = (WORK_ITEM *) newItem;
  while (item->msa != NULL)
    {
      status = p7_Builder(info->bld, item->msa, info->bg, &item->hmm, NULL, NULL, NULL, &item->postmsa);
      if (status != eslOK) p7_Fail("build failed: %s", info->bld->errbuf);

      item->entropy   = p7_MeanMatchRelativeEntropy(item->hmm, info->bg);
      item->processed = TRUE;

      status = esl_workqueue_WorkerUpdate(info->queue, item, &newItem);
      if (status != eslOK) esl_fatal("Work queue worker failed");

      item = (WORK_ITEM *) newItem;
    }

  status = esl_workqueue_WorkerUpdate(info->queue, item, NULL);
  if (status != eslOK) esl_fatal("Work queue worker failed");

  esl_threads_Finished(obj, workeridx);
  return;
}
예제 #3
0
/* if error occurs we return hmms that are already created, so caller should delete them anyway
   Note, that we do not destroy hmm->abc here, caller should delete it too.
   Don't worry, on exception we'll catch it here
 */
P7_HMM * UHMM3Build::build( const MAlignment & malignment, const UHMM3BuildSettings & settings ,TaskStateInfo & ti ) {
    ESL_ALPHABET*   abc = NULL;
    P7_BG*          bg  = NULL;
    P7_BUILDER*     bld = NULL;
    ESL_MSA*        msa = NULL;
    P7_HMM*         hmm = NULL;
    QByteArray      errStr;
    
    ti.progress = 0;
    try {
        int alType = UHMM3Utilities::convertAlphabetType( malignment.getAlphabet() );
        if( UHMM3Utilities::BAD_ALPHABET == alType ) {
            errStr = tr( "UGENE cannot determine alphabet of alignment" ).toLatin1();
            throwUHMMER3Exception( errStr.data() );
        }
        ESL_ALPHABET* abc = esl_alphabet_Create( alType );
        if( NULL == abc ) {
            errStr = tr( "Run out of memory (creating alphabet failed)" ).toLatin1();
            throwUHMMER3Exception( errStr.data() );
        }
        
        P7_BG* bg = p7_bg_Create( abc );
        if( NULL == bg ) {
            errStr = tr( "Run out of memory (creating null model failed)" ).toLatin1();
            throwUHMMER3Exception( errStr.data() );
        }
        P7_BUILDER* bld = p7_builder_Create( &settings, abc );
        if( NULL == bld ) {
            errStr = tr( "Run out of memory (creating builder failed)" ).toLatin1();
            throwUHMMER3Exception( errStr.data() );
        }
        
        ESL_MSA* msa = UHMM3Utilities::convertMSA( malignment );
        if( NULL == msa ) {
            errStr = tr( "Run out of memory (creating multiple alignment failed)" ).toLatin1();
            throwUHMMER3Exception( errStr.data() );
        }
        int ret = esl_msa_Digitize( abc, msa, NULL );
        if( eslOK != ret ) {
            errStr = tr( "Run out of memory (digitizing of alignment failed)" ).toLatin1();
            throwUHMMER3Exception( errStr.data() );
        }
        ret = p7_Builder( bld, msa, bg, &hmm, NULL, NULL, NULL, NULL, ti );
        if ( eslOK != ret ) {
            if( eslCANCELED == ret ) {
                errStr = tr( HMMER3_CANCELED_ERROR ).toLatin1();
            } else {
                errStr = tr( "Model building failed" ).toLatin1();
            }
            assert( !errStr.isEmpty() );
            throwUHMMER3Exception( errStr.data() );
        }
        
        destoryAllIfYouCan( abc, bg, bld, msa, NULL );
    } catch( const UHMMER3Exception& ex ) {
        ti.setError( ex.msg );
        destoryAllIfYouCan( abc, bg, bld, msa, hmm );
        return NULL;
    } catch(...) {
        ti.setError( tr( HMMER3_UNKNOWN_ERROR ) );
        destoryAllIfYouCan( abc, bg, bld, msa, hmm );
        return NULL;
    }
    
    return hmm;
}
예제 #4
0
static void
mpi_worker(const ESL_GETOPTS *go, struct cfg_s *cfg)
{
  int           xstatus = eslOK;
  int           status;
  int           type;
  P7_BUILDER   *bld         = NULL;
  ESL_MSA      *msa         = NULL;
  ESL_MSA      *postmsa     = NULL;
  ESL_MSA     **postmsa_ptr = (cfg->postmsafile != NULL) ? &postmsa : NULL;
  P7_HMM       *hmm         = NULL;
  P7_BG        *bg          = NULL;
  char         *wbuf        = NULL;	/* packed send/recv buffer  */
  void         *tmp;			/* for reallocation of wbuf */
  int           wn          = 0;	/* allocation size for wbuf */
  int           sz, n;		        /* size of a packed message */
  int           pos;
  char          errmsg[eslERRBUFSIZE];

  /* After master initialization: master broadcasts its status.
   */
  MPI_Bcast(&xstatus, 1, MPI_INT, 0, MPI_COMM_WORLD);
  if (xstatus != eslOK) return; /* master saw an error code; workers do an immediate normal shutdown. */
  ESL_DPRINTF2(("worker %d: sees that master has initialized\n", cfg->my_rank));
  
  /* Master now broadcasts worker initialization information (alphabet type) 
   * Workers returns their status post-initialization.
   * Initial allocation of wbuf must be large enough to guarantee that
   * we can pack an error result into it, because after initialization,
   * errors will be returned as packed (code, errmsg) messages.
   */
  MPI_Bcast(&type, 1, MPI_INT, 0, MPI_COMM_WORLD);
  if (xstatus == eslOK) { if ((cfg->abc = esl_alphabet_Create(type))      == NULL)    xstatus = eslEMEM; }
  if (xstatus == eslOK) { wn = 4096;  if ((wbuf = malloc(wn * sizeof(char))) == NULL) xstatus = eslEMEM; }
  if (xstatus == eslOK) { if ((bld = p7_builder_Create(go, cfg->abc))     == NULL)    xstatus = eslEMEM; }
  MPI_Reduce(&xstatus, &status, 1, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD); /* everyone sends xstatus back to master */
  if (xstatus != eslOK) {
    if (wbuf != NULL) free(wbuf);
    if (bld  != NULL) p7_builder_Destroy(bld);
    return; /* shutdown; we passed the error back for the master to deal with. */
  }

  bg = p7_bg_Create(cfg->abc);

  ESL_DPRINTF2(("worker %d: initialized\n", cfg->my_rank));

                      /* source = 0 (master); tag = 0 */
  while (esl_msa_MPIRecv(0, 0, MPI_COMM_WORLD, cfg->abc, &wbuf, &wn, &msa) == eslOK) 
    {
      /* Build the HMM */
      ESL_DPRINTF2(("worker %d: has received MSA %s (%d columns, %d seqs)\n", cfg->my_rank, msa->name, msa->alen, msa->nseq));
      if ((status = p7_Builder(bld, msa, bg, &hmm, NULL, NULL, NULL, postmsa_ptr)) != eslOK) { strcpy(errmsg, bld->errbuf); goto ERROR; }
      ESL_DPRINTF2(("worker %d: has produced an HMM %s\n", cfg->my_rank, hmm->name));

      /* Calculate upper bound on size of sending status, HMM, and optional postmsa; make sure wbuf can hold it. */
      n = 0;
      if (MPI_Pack_size(1,    MPI_INT, MPI_COMM_WORLD, &sz) != 0)     goto ERROR;   n += sz;
      if (p7_hmm_MPIPackSize( hmm,     MPI_COMM_WORLD, &sz) != eslOK) goto ERROR;   n += sz;
      if (esl_msa_MPIPackSize(postmsa, MPI_COMM_WORLD, &sz) != eslOK) goto ERROR;   n += sz;
      if (n > wn) { ESL_RALLOC(wbuf, tmp, sizeof(char) * n); wn = n; }
      ESL_DPRINTF2(("worker %d: has calculated that HMM will pack into %d bytes\n", cfg->my_rank, n));

      /* Send status, HMM, and optional postmsa back to the master */
      pos = 0;
      if (MPI_Pack       (&status, 1, MPI_INT, wbuf, wn, &pos, MPI_COMM_WORLD) != 0)     goto ERROR;
      if (p7_hmm_MPIPack (hmm,                 wbuf, wn, &pos, MPI_COMM_WORLD) != eslOK) goto ERROR;
      if (esl_msa_MPIPack(postmsa,             wbuf, wn, &pos, MPI_COMM_WORLD) != eslOK) goto ERROR;
      MPI_Send(wbuf, pos, MPI_PACKED, 0, 0, MPI_COMM_WORLD);
      ESL_DPRINTF2(("worker %d: has sent HMM to master in message of %d bytes\n", cfg->my_rank, pos));

      esl_msa_Destroy(msa);     msa     = NULL;
      esl_msa_Destroy(postmsa); postmsa = NULL;
      p7_hmm_Destroy(hmm);      hmm     = NULL;
    }

  if (wbuf != NULL) free(wbuf);
  p7_builder_Destroy(bld);
  return;

 ERROR:
  ESL_DPRINTF2(("worker %d: fails, is sending an error message, as follows:\n%s\n", cfg->my_rank, errmsg));
  pos = 0;
  MPI_Pack(&status, 1,                MPI_INT,  wbuf, wn, &pos, MPI_COMM_WORLD);
  MPI_Pack(errmsg,  eslERRBUFSIZE,    MPI_CHAR, wbuf, wn, &pos, MPI_COMM_WORLD);
  MPI_Send(wbuf, pos, MPI_PACKED, 0, 0, MPI_COMM_WORLD);
  if (wbuf != NULL) free(wbuf);
  if (msa  != NULL) esl_msa_Destroy(msa);
  if (hmm  != NULL) p7_hmm_Destroy(hmm);
  if (bld  != NULL) p7_builder_Destroy(bld);
  return;
}
예제 #5
0
P7_HMM * constructHMM(ESL_MSA *msa, ESL_ALPHABET *abc, int ali_hmm, int frag, P7_HMM **ret_hmm, char *errbuf){
  int status;
  ESL_GETOPTS  *go          = esl_getopts_Create(options);
  P7_BUILDER      *bld      = NULL;
  P7_BG           *bg       = NULL;

  char            *args = NULL;

  esl_strcat(&args, -1, "X ", -1);

  status = esl_msa_SetName(msa, "Query", -1);
  /* Now take this alignment and make an HMM from it */
  if(status != eslOK){
    ESL_XFAIL(status, errbuf, "Easel MSA SetNAME returned an error %d\n", status);
  }
  bg = p7_bg_Create(abc);
  if(bg == NULL){
    ESL_XFAIL(status, errbuf, "Error generating bg\n");
  }

  if (frag == 1) {
    // add --fragthresh 0
    esl_strcat(&args, -1, "--fragthresh 0 ", -1);
  }

  // if these flags are set, then we want a non standard hmm out. Used by the logo server.
  if (ali_hmm == 1) {
    // observed counts
    // arguments "X --pnone --wnone --enone"
    esl_strcat(&args, -1, "--pnone --wnone --enone --symfrac 0 ", -1);
  }
  else if (ali_hmm == 2) {
    // weighted counts
    // arguments  "X --pnone");
    esl_strcat(&args, -1, "--pnone --symfrac 0 ", -1);
  }
  else if (ali_hmm == 3) {
    // Create HMM - keep all columns
    esl_strcat(&args, -1, "--symfrac 0 ", -1);
  }
  else {
    // no arguments ?
  }


  // pass in arguments to hmm builder
  esl_opt_ProcessSpoof(go, args);

  if (args != NULL) free(args);

  bld = p7_builder_Create(go, abc);
  if(bld == NULL){
    ESL_XFAIL(eslEMEM, errbuf, "Error creating builder\n");
  }

  status = p7_Builder(bld, msa, bg, ret_hmm, NULL, NULL, NULL, NULL);


  if (status != eslOK) {
    strcpy( errbuf, bld->errbuf );
    goto ERROR;
  }


  p7_bg_Destroy(bg);
  p7_builder_Destroy(bld);
  esl_getopts_Destroy(go);
  return status;

ERROR:
  if (bg != NULL) p7_bg_Destroy(bg);
  if (bld != NULL) p7_builder_Destroy(bld);
  if (go != NULL) esl_getopts_Destroy(go);
  return status;
}