Exemplo n.º 1
0
static EISeq *
createEncIdxSeqFromSASeqSrc(SASeqSrc *src,
                            const GtStr *projectName,
                            const struct seqBaseParam *params,
                            size_t numExtHeaders, const uint16_t *headerIDs,
                            const uint32_t *extHeaderSizes,
                            headerWriteFunc *extHeaderCallbacks,
                            void **headerCBData, bitInsertFunc biFunc,
                            BitOffset cwExtBitsPerPos,
                            varExtBitsEstimator biVarBits, void *cbState,
                            GtError *err)
{
  SeqDataReader readSfxBWTSym;
  MRAEnc *alphabet;
  struct encIdxSeq *newSeqIdx;
  if (!SDRIsValid(readSfxBWTSym
                  = SASSCreateReader(src, SFX_REQUEST_BWTTAB)))
    return NULL;
  alphabet = SASSNewMRAEnc(src);
  newSeqIdx = createEncIdxSeqGen(SASSGetLength(src), projectName,
                                 alphabet, SASSGetSeqStats(src),
                                 readSfxBWTSym, params,
                                 numExtHeaders, headerIDs, extHeaderSizes,
                                 extHeaderCallbacks, headerCBData, biFunc,
                                 cwExtBitsPerPos, biVarBits,
                                 cbState, err);
  if (!newSeqIdx)
    MRAEncDelete(alphabet);
  return newSeqIdx;
}
Exemplo n.º 2
0
extern EISeq *
createBWTSeqGeneric(const struct bwtParam *params, indexCreateFunc createIndex,
                    SASeqSrc *src,
                    const enum rangeSortMode rangeSort[],
                    const SpecialsRankLookup *sprTable,
                    GtError *err)
{
  struct encIdxSeq *baseSeqIdx = NULL;
  struct addLocateInfoState varState;
  bool varStateIsInitialized = false;
  unsigned locateInterval;
  BWTSeqContextRetrieverFactory *buildContextMap = NULL;
  gt_assert(src && params && err);
  gt_error_check(err);
  locateInterval = params->locateInterval;
  do
  {
    struct locateHeaderWriteInfo locHeaderData
      = { src, locateInterval, params->featureToggles };
    struct sortModeHeader sortModeHeader;
    void *p[] = { &locHeaderData , &sortModeHeader };
    uint16_t headerIDs[] = { LOCATE_INFO_IN_INDEX_HEADERID,
                             RANK_SORT_HEADERID };
    uint32_t headerSizes[] = { LOCATE_HEADER_SIZE,
                               0 };
    headerWriteFunc headerFuncs[] = { writeLocateInfoHeader,
                                      writeRankSortHeader };
    size_t numHeaders = 0;
    unsigned bitsPerOrigRank = 0;
    Seqpos totalLen = SASSGetLength(src);
    const MRAEnc *alphabet = SASSGetMRAEnc(src);
    MRAEnc *baseAlphabet = SASSNewMRAEnc(src);
    /* FIXME: this  has to work also when locateInterval == 0 and
     * sprTable != NULL */
    if (params->ctxMapILog != CTX_MAP_ILOG_NOMAP)
      buildContextMap = newBWTSeqContextRetrieverFactory(totalLen,
                                                         params->ctxMapILog);
    if (locateInterval)
    {
      ++numHeaders;
      if (sortModeHeaderNeeded(alphabet, rangeSort, sprTable))
      {
        Seqpos
#ifndef NDEBUG
          origSeqLen = getencseqtotallength(SPRTGetOrigEncseq(sprTable)),
#endif
          maxRank;
        gt_assert(origSeqLen == totalLen - 1);
        maxRank = specialsRank(sprTable, totalLen - 1);
        bitsPerOrigRank = sortModeHeader.bitsPerOrigRank
          = requiredSeqposBits(maxRank);
        sortModeHeader.alphabet = alphabet;
        sortModeHeader.rangeSort = rangeSort;
        headerSizes[1] = computeSortModeHeaderSize(alphabet);
        ++numHeaders;
      }
      {
        SeqDataReader readSfxIdx = SASSCreateReader(src, SFX_REQUEST_SUFTAB);
        if (SDRIsValid(readSfxIdx))
        {
          initAddLocateInfoState(
            &varState, SASSGetOrigSeqAccessor(src), readSfxIdx,
            alphabet, SASSGetSeqStats(src), rangeSort, totalLen, params,
            bitsPerOrigRank?sprTable:NULL, bitsPerOrigRank,
            buildContextMap);
          varStateIsInitialized = true;
        }
        else
        {
          gt_error_set(err, "error: locate sampling requested but not available"
                    " for project %s\n", gt_str_get(params->projectName));
        }
      }
    }
    if (!(baseSeqIdx
          = createIndex(totalLen, params->projectName, baseAlphabet,
                        SASSGetSeqStats(src),
                        SASSCreateReader(src, SFX_REQUEST_BWTTAB),
                        &params->seqParams, numHeaders,
                        headerIDs, headerSizes, headerFuncs, p,
                        locateInterval?addLocateInfo:NULL,
                        /* one bit per position if using bitmap */
                        (params->featureToggles & BWTLocateBitmap)?1:0,
                        locateInterval?locBitsUpperBounds:NULL, &varState,
                        err)))
      break;
    if (buildContextMap)
    {
      if (!BWTSCRFFinished(buildContextMap))
      {
        fputs("error: context table construction incomplete!\n", stderr);
      }
      else
      {
        BWTSeqContextRetriever *ctxRetrieve =
          BWTSCRFGet(buildContextMap, NULL, params->projectName);
        deleteBWTSeqCR(ctxRetrieve);
      }
    }
  } while (0);
  if (buildContextMap)
    deleteBWTSeqContextRetrieverFactory(buildContextMap);
  if (varStateIsInitialized)
    destructAddLocateInfoState(&varState);
  return baseSeqIdx;
}