Exemplo n.º 1
0
int runsubstringiteration(Greedygmatchforwardfunction gmatchforward,
                          const void *genericindex,
                          unsigned long totalwidth,
                          const unsigned long *leftborder,
                          const unsigned long *countspecialcodes,
                          const Alphabet *alphabet,
                          unsigned int prefixlength,
                          const GtStrArray *queryfilenames,
                          GtError *err)
{
    GtSeqIterator *seqit;
    const GtUchar *query;
    unsigned long querylen;
    char *desc = NULL;
    Substriter *substriter;
    Substring substring;
    bool haserr = false;
    int retval;
    unsigned int numofchars;
    unsigned long gmatchlength, gmatchlength2;
    GtCodetype maxcode;
    GtBucketspecification bucketspec;
    bool haserr = false;

    seqit = gt_seqiterator_new(queryfilenames,getsymbolmapAlphabet(alphabet),
                               *                          true);
    for (unitnum = 0; ; unitnum++)
    {
        retval = gt_seqiterator_next(seqit,
                                     &query,
                                     &querylen,
                                     &desc,
                                     err);
        if (retval < 0)
        {
            haserr = true;
            break;
        }
        if (retval == 0)
        {
            break;
        }
    }
    gt_seqiterator_delete(seqit);
    return haserr ? -1 : 0;
}
Exemplo n.º 2
0
int runsubstringiteration(Greedygmatchforwardfunction gmatchforward,
                          const void *genericindex,
                          unsigned long totalwidth,
                          const unsigned long *leftborder,
                          const unsigned long *countspecialcodes,
                          const Alphabet *alphabet,
                          unsigned int prefixlength,
                          const GtStrArray *queryfilenames,
                          GtError *err)
{
    Substriter *substriter;
    Substring substring;
    bool haserr = false;
    int retval;
    unsigned int numofchars;
    unsigned long gmatchlength, gmatchlength2;
    GtCodetype maxcode;
    GtBucketspecification bucketspec;

    substriter->seqit = gt_seqiterator_new(filenames,
                                           getsymbolmapAlphabet(alphabet),
                                           true);
    substriter = gt_substriter_new(queryfilenames,alphabet,prefixlength);
    numofchars = getnumofcharsAlphabet(alphabet);
    maxcode = ontheflybasepower(numofchars,prefixlength);
    while (true)
    {
        retval = gt_substriter_next(&substring,substriter,err);
        if (retval < 0)
        {
            haserr = true;
            break;
        }
        if (retval == 0)
        {
            break;
        }
        gt_assert(substring.remaining >= (unsigned long) prefixlength);
        gmatchlength = gmatchforward(genericindex,
                                     0,
                                     0,
                                     totalwidth,
                                     NULL,
                                     substring.currentptr,
                                     substring.currentptr + substring.remaining);
        if (leftborder != NULL)
        {
            gt_bcktab_calcboundaries(&bucketspec,
                                     leftborder,
                                     countspecialcodes,
                                     substring.currentcode,
                                     maxcode,
                                     totalwidth,
                                     substring.currentcode % numofchars,
                                     numofchars);
            if (bucketspec.nonspecialsinbucket > 0)
            {
                gmatchlength2 = gmatchforward(genericindex,
                                              (unsigned long) prefixlength,
                                              bucketspec.left,
                                              bucketspec.left
                                              + bucketspec.nonspecialsinbucket - 1,
                                              NULL,
                                              substring.currentptr+prefixlength,
                                              substring.currentptr+substring.remaining);
#ifndef NDEBUG
                if (gmatchlength2 != gmatchlength)
                {
                    fprintf(stderr,"at offset %lu:\n",(unsigned long)
                            (substring.currentptr -
                             substring.start));
                    fprintf(stderr,"bucketspec=(%lu,%lu)\n",
                            bucketspec.left,
                            bucketspec.left+bucketspec.nonspecialsinbucket-1);
                    fprintf(stderr,"gmatchlength2 = %lu != %lu = gmatchlength\n",
                            gmatchlength2,gmatchlength);
                    exit(GT_EXIT_PROGRAMMING_ERROR);
                }
#endif
            }
        }
    }
    gt_substriter_delete(&substriter);
    return haserr ? -1 : 0;
}
Exemplo n.º 3
0
int runidxlocali(const IdxlocaliOptions *idxlocalioptions,GtError *err)
{
  Genericindex *genericindex = NULL;
  bool haserr = false;
  Verboseinfo *verboseinfo;
  const Encodedsequence *encseq = NULL;

  verboseinfo = newverboseinfo(idxlocalioptions->verbose);

  if (idxlocalioptions->doonline)
  {
    encseq = mapencodedsequence (true,
                                 idxlocalioptions->indexname,
                                 true,
                                 false,
                                 false,
                                 true,
                                 verboseinfo,
                                 err);
    if (encseq == NULL)
    {
      haserr = true;
    }
  } else
  {
    genericindex = genericindex_new(idxlocalioptions->indexname,
                                    idxlocalioptions->withesa,
                                    idxlocalioptions->withesa ||
                                    idxlocalioptions->docompare,
                                    false,
                                    true,
                                    0,
                                    verboseinfo,
                                    err);
    if (genericindex == NULL)
    {
      haserr = true;
    } else
    {
      encseq = genericindex_getencseq(genericindex);
    }
  }
  if (!haserr)
  {
    GtSeqIterator *seqit;
    const GtUchar *query;
    unsigned long querylen;
    char *desc = NULL;
    int retval;
    Limdfsresources *limdfsresources = NULL;
    const AbstractDfstransformer *dfst;
    SWdpresource *swdpresource = NULL;
    Showmatchinfo showmatchinfo;
    Processmatch processmatch;
    void *processmatchinfoonline, *processmatchinfooffline;
    Storematchinfo storeonline, storeoffline;

    if (idxlocalioptions->docompare)
    {
      processmatch = storematch;
      initstorematch(&storeonline,encseq);
      initstorematch(&storeoffline,encseq);
      processmatchinfoonline = &storeonline;
      processmatchinfooffline = &storeoffline;
    } else
    {
      processmatch = showmatch;
      showmatchinfo.encseq = encseq;
      showmatchinfo.characters = getencseqAlphabetcharacters(encseq);
      showmatchinfo.wildcardshow = getencseqAlphabetwildcardshow(encseq);
      showmatchinfo.showalignment = idxlocalioptions->showalignment;
      processmatchinfoonline = processmatchinfooffline = &showmatchinfo;
    }
    if (idxlocalioptions->doonline || idxlocalioptions->docompare)
    {
      swdpresource = newSWdpresource(idxlocalioptions->matchscore,
                                     idxlocalioptions->mismatchscore,
                                     idxlocalioptions->gapextend,
                                     idxlocalioptions->threshold,
                                     idxlocalioptions->showalignment,
                                     processmatch,
                                     processmatchinfoonline);
    }
    dfst = locali_AbstractDfstransformer();
    if (!idxlocalioptions->doonline || idxlocalioptions->docompare)
    {
      gt_assert(genericindex != NULL);
      limdfsresources = newLimdfsresources(genericindex,
                                           true,
                                           0,
                                           0,    /* maxpathlength */
                                           true, /* keepexpandedonstack */
                                           processmatch,
                                           processmatchinfooffline,
                                           NULL, /* processresult */
                                           NULL, /* processresult info */
                                           dfst);
    }
    seqit = gt_seqiterator_new(idxlocalioptions->queryfiles, err);
    if (!seqit)
      haserr = true;
    if (!haserr)
    {
      gt_seqiterator_set_symbolmap(seqit, getencseqAlphabetsymbolmap(encseq));
      for (showmatchinfo.queryunit = 0; /* Nothing */;
           showmatchinfo.queryunit++)
      {
        retval = gt_seqiterator_next(seqit,
                                     &query,
                                     &querylen,
                                     &desc,
                                     err);
        if (retval < 0)
        {
          haserr = true;
          break;
        }
        if (retval == 0)
        {
          break;
        }
        printf("process sequence " Formatuint64_t " of length %lu\n",
                PRINTuint64_tcast(showmatchinfo.queryunit),querylen);
        if (idxlocalioptions->doonline || idxlocalioptions->docompare)
        {
          multiapplysmithwaterman(swdpresource,encseq,query,querylen);
        }
        if (!idxlocalioptions->doonline || idxlocalioptions->docompare)
        {
          indexbasedlocali(limdfsresources,
                           idxlocalioptions->matchscore,
                           idxlocalioptions->mismatchscore,
                           idxlocalioptions->gapstart,
                           idxlocalioptions->gapextend,
                           idxlocalioptions->threshold,
                           query,
                           querylen,
                           dfst);
        }
        if (idxlocalioptions->docompare)
        {
          checkandresetstorematch(showmatchinfo.queryunit,
                                  &storeonline,&storeoffline);
        }
        gt_free(desc);
      }
      if (limdfsresources != NULL)
      {
        freeLimdfsresources(&limdfsresources,dfst);
      }
      if (swdpresource != NULL)
      {
        freeSWdpresource(swdpresource);
        swdpresource = NULL;
      }
      gt_seqiterator_delete(seqit);
    }
    if (idxlocalioptions->docompare)
    {
      freestorematch(&storeonline);
      freestorematch(&storeoffline);
    }
  }
  if (genericindex == NULL)
  {
    gt_assert(encseq != NULL);
    encodedsequence_free((Encodedsequence **) &encseq);
  } else
  {
    genericindex_delete(genericindex);
  }
  freeverboseinfo(&verboseinfo);
  return haserr ? -1 : 0;
}