From fdabf72141b065cdfc2d9efc21774644c8696f58 Mon Sep 17 00:00:00 2001 From: Valentin Antonescu Date: Thu, 17 Apr 2014 19:19:22 -0400 Subject: [PATCH] More work. Code compilable now. --- aligner.h | 38 +++++++++++++-------------- blockwise_sa.h | 4 +-- diff_sample.h | 6 ++--- ebwt.cpp | 4 +-- ebwt.h | 53 ++++++++++++++++++------------------- ebwt_build.cpp | 4 +-- ebwt_search_backtrack.h | 10 +++---- hit.h | 6 ++--- hit_set.h | 11 ++++---- multikey_qsort.h | 2 +- range_chaser.h | 70 ++++++++++++++++++++++++------------------------- refmap.cpp | 2 +- refmap.h | 7 ++--- row_chaser.h | 38 +++++++++++++-------------- sam.cpp | 2 +- sam.h | 3 ++- 16 files changed, 131 insertions(+), 129 deletions(-) diff --git a/aligner.h b/aligner.h index 5e8ad87..b3bbabc 100644 --- a/aligner.h +++ b/aligner.h @@ -556,8 +556,8 @@ class UnpairedAlignerV2 : public Aligner { template class PairedBWAlignerV1 : public Aligner { - typedef std::pair U32Pair; - typedef std::vector U32PairVec; + typedef std::pair UPair; + typedef std::vector UPairVec; typedef std::vector TRangeVec; typedef RangeSourceDriver TDriver; typedef std::pair TU64Pair; @@ -919,7 +919,7 @@ class PairedBWAlignerV1 : public Aligner { * mate) aligns such that mating constraint is satisfied. */ bool resolveOutstandingInRef(const bool off1, - const U32Pair& off, + const UPair& off, const uint32_t tlen, const Range& range) { @@ -1364,20 +1364,20 @@ class PairedBWAlignerV1 : public Aligner { // Range-finding state for first mate TDriver* driver1Fw_; TDriver* driver1Rc_; - U32PairVec offs1FwArr_[32]; + UPairVec offs1FwArr_[32]; TRangeVec ranges1FwArr_[32]; uint32_t offs1FwSz_; // total size of all ranges found in this category - U32PairVec offs1RcArr_[32]; + UPairVec offs1RcArr_[32]; TRangeVec ranges1RcArr_[32]; uint32_t offs1RcSz_; // total size of all ranges found in this category // Range-finding state for second mate TDriver* driver2Fw_; TDriver* driver2Rc_; - U32PairVec offs2FwArr_[32]; + UPairVec offs2FwArr_[32]; TRangeVec ranges2FwArr_[32]; uint32_t offs2FwSz_; // total size of all ranges found in this category - U32PairVec offs2RcArr_[32]; + UPairVec offs2RcArr_[32]; TRangeVec ranges2RcArr_[32]; uint32_t offs2RcSz_; // total size of all ranges found in this category @@ -1387,8 +1387,8 @@ class PairedBWAlignerV1 : public Aligner { bool& delayedchaseR_fw_; TDriver& drL_fw_; TDriver& drR_fw_; - U32PairVec* offsLarr_fw_; - U32PairVec* offsRarr_fw_; + UPairVec* offsLarr_fw_; + UPairVec* offsRarr_fw_; TRangeVec* rangesLarr_fw_; TRangeVec* rangesRarr_fw_; uint32_t& offsLsz_fw_; @@ -1400,8 +1400,8 @@ class PairedBWAlignerV1 : public Aligner { bool& delayedchaseR_rc_; TDriver& drL_rc_; TDriver& drR_rc_; - U32PairVec* offsLarr_rc_; - U32PairVec* offsRarr_rc_; + UPairVec* offsLarr_rc_; + UPairVec* offsRarr_rc_; TRangeVec* rangesLarr_rc_; TRangeVec* rangesRarr_rc_; uint32_t& offsLsz_rc_; @@ -1413,8 +1413,8 @@ class PairedBWAlignerV1 : public Aligner { bool* delayedchaseR_; TDriver* drL_; TDriver* drR_; - U32PairVec* offsLarr_; - U32PairVec* offsRarr_; + UPairVec* offsLarr_; + UPairVec* offsRarr_; TRangeVec* rangesLarr_; TRangeVec* rangesRarr_; uint32_t* offsLsz_; @@ -1443,7 +1443,7 @@ class PairedBWAlignerV1 : public Aligner { */ struct RangeWithCoords { Range r; - U32Pair h; + UPair h; }; /** @@ -1453,8 +1453,8 @@ struct RangeWithCoords { template class PairedBWAlignerV2 : public Aligner { - typedef std::pair U32Pair; - typedef std::vector U32PairVec; + typedef std::pair UPair; + typedef std::vector UPairVec; typedef std::vector TRangeVec; typedef RangeSourceDriver TDriver; typedef std::pair TU64Pair; @@ -1782,7 +1782,7 @@ class PairedBWAlignerV2 : public Aligner { * a paired alignment by reporting two consecutive alignments, one * for each mate. */ - void reportSe(const Range& r, U32Pair h, uint32_t tlen) { + void reportSe(const Range& r, UPair h, uint32_t tlen) { EbwtSearchParams >*params = (r.mate1 ? paramsSe1_ : paramsSe2_); assert(!(r.mate1 ? doneSe1_ : doneSe2_)); params->setFw(r.fw); @@ -1828,7 +1828,7 @@ class PairedBWAlignerV2 : public Aligner { } } - void resolveOutstanding(const U32Pair& off, + void resolveOutstanding(const UPair& off, const uint32_t tlen, const Range& range) { @@ -1865,7 +1865,7 @@ class PairedBWAlignerV2 : public Aligner { * This function picks up to 'pick' anchors at random from the * 'offs' array. It returns the number that it actually picked. */ - bool resolveOutstandingInRef(const U32Pair& off, + bool resolveOutstandingInRef(const UPair& off, const uint32_t tlen, const Range& range) { diff --git a/blockwise_sa.h b/blockwise_sa.h index c492dde..2187a04 100644 --- a/blockwise_sa.h +++ b/blockwise_sa.h @@ -501,8 +501,8 @@ void KarkkainenBlockwiseSA::buildSamples() { // and split/merge as necessary TIndexOff added = 0; TIndexOff merged = 0; - assert_eq(bucketSzs.size(), numBuckets); - assert_eq(bucketReps.size(), numBuckets); + assert_eq(length(bucketSzs), numBuckets); + assert_eq(length(bucketReps), numBuckets); { Timer timer(cout, " Splitting and merging time: ", this->verbose()); VMSG_NL("Splitting and merging"); diff --git a/diff_sample.h b/diff_sample.h index 28e25ef..be81465 100644 --- a/diff_sample.h +++ b/diff_sample.h @@ -566,7 +566,7 @@ class DifferenceCoverSample { ostream& log() const { return _logger; } void build(); - TIndexOffU tieBreakOff(TIndexOffU i, TIndexOffU j) const; + uint32_t tieBreakOff(TIndexOffU i, TIndexOffU j) const; int64_t breakTie(TIndexOffU i, TIndexOffU j) const; bool isCovered(TIndexOffU i) const; TIndexOffU rank(TIndexOffU i) const; @@ -790,11 +790,11 @@ void DifferenceCoverSample::build() { // Extract backing-store array from sPrime and sPrimeOrder; // the mkeyQSortSuf2 routine works on the array for maximum // efficiency - TIndexOffU *sPrimeArr = (uint32_t*)begin(sPrime); + TIndexOffU *sPrimeArr = (TIndexOffU*)begin(sPrime); size_t slen = length(sPrime); assert_eq(sPrimeArr[0], sPrime[0]); assert_eq(sPrimeArr[slen-1], sPrime[slen-1]); - TIndexOffU *sPrimeOrderArr = (uint32_t*)begin(sPrimeOrder); + TIndexOffU *sPrimeOrderArr = (TIndexOffU*)begin(sPrimeOrder); assert_eq(sPrimeOrderArr[0], sPrimeOrder[0]); assert_eq(sPrimeOrderArr[slen-1], sPrimeOrder[slen-1]); // Sort sample suffixes up to the vth character using a diff --git a/ebwt.cpp b/ebwt.cpp index 947e94d..c6e6661 100644 --- a/ebwt.cpp +++ b/ebwt.cpp @@ -15,11 +15,11 @@ using namespace std; #ifdef BOWTIE_64BIT_INDEX -const std::string gEbwt_ext("bt2l"); +std::string gEbwt_ext("bt2l"); #else -const std::string gEbwt_ext("bt2"); +std::string gEbwt_ext("bt2"); #endif // BOWTIE_64BIT_INDEX diff --git a/ebwt.h b/ebwt.h index 0a1961c..d101e84 100644 --- a/ebwt.h +++ b/ebwt.h @@ -53,7 +53,6 @@ using namespace seqan; // From ccnt_lut.cpp, automatically generated by gen_lookup_tables.pl extern uint8_t cCntLUT_4[4][4][256]; -extern const std::string gEbwt_ext; static const uint64_t c_table[4] = { 0xffffffffffffffffllu, @@ -1132,16 +1131,16 @@ class Ebwt { // Searching and reporting void joinedToTextOff(TIndexOffU qlen, TIndexOffU off, TIndexOffU& tidx, TIndexOffU& textoff, TIndexOffU& tlen) const; - inline bool report(const String& query, String* quals, String* name, bool color, char primer, char trimc, bool colExEnds, int snpPhred, const BitPairReference* ref, const std::vector& mmui32, const std::vector& refcs, size_t numMms, uint32_t off, uint32_t top, uint32_t bot, uint32_t qlen, int stratum, uint16_t cost, uint32_t patid, uint32_t seed, const EbwtSearchParams& params) const; - inline bool reportChaseOne(const String& query, String* quals, String* name, bool color, char primer, char trimc, bool colExEnds, int snpPhred, const BitPairReference* ref, const std::vector& mmui32, const std::vector& refcs, size_t numMms, uint32_t i, uint32_t top, uint32_t bot, uint32_t qlen, int stratum, uint16_t cost, uint32_t patid, uint32_t seed, const EbwtSearchParams& params, SideLocus *l = NULL) const; + inline bool report(const String& query, String* quals, String* name, bool color, char primer, char trimc, bool colExEnds, int snpPhred, const BitPairReference* ref, const std::vector& mmui32, const std::vector& refcs, size_t numMms, TIndexOffU off, uint32_t top, uint32_t bot, uint32_t qlen, int stratum, uint16_t cost, uint32_t patid, uint32_t seed, const EbwtSearchParams& params) const; + inline bool reportChaseOne(const String& query, String* quals, String* name, bool color, char primer, char trimc, bool colExEnds, int snpPhred, const BitPairReference* ref, const std::vector& mmui32, const std::vector& refcs, size_t numMms, TIndexOffU i, uint32_t top, uint32_t bot, uint32_t qlen, int stratum, uint16_t cost, uint32_t patid, uint32_t seed, const EbwtSearchParams& params, SideLocus *l = NULL) const; inline bool reportReconstruct(const String& query, String* quals, String* name, String& lbuf, String& rbuf, const uint32_t *mmui32, const char* refcs, size_t numMms, uint32_t i, uint32_t top, uint32_t bot, uint32_t qlen, int stratum, const EbwtSearchParams& params, SideLocus *l = NULL) const; inline int rowL(const SideLocus& l) const; inline TIndexOffU countUpTo(const SideLocus& l, int c) const; inline void countUpToEx(const SideLocus& l, TIndexOffU* pairs) const; inline uint32_t countFwSide(const SideLocus& l, int c) const; - inline void countFwSideEx(const SideLocus& l, uint32_t *pairs) const; + inline void countFwSideEx(const SideLocus& l, TIndexOffU *pairs) const; inline uint32_t countBwSide(const SideLocus& l, int c) const; - inline void countBwSideEx(const SideLocus& l, uint32_t *pairs) const; + inline void countBwSideEx(const SideLocus& l, TIndexOffU *pairs) const; inline TIndexOffU mapLF(const SideLocus& l ASSERT_ONLY(, bool overrideSanity = false)) const; inline void mapLFEx(const SideLocus& l, TIndexOffU *pairs ASSERT_ONLY(, bool overrideSanity = false)) const; inline void mapLFEx(const SideLocus& ltop, const SideLocus& lbot, TIndexOffU *tops, TIndexOffU *bots ASSERT_ONLY(, bool overrideSanity = false)) const; @@ -1301,11 +1300,11 @@ class EbwtSearchParams { const std::vector& mmui32, // mismatch list const std::vector& refcs, // reference characters size_t numMms, // # mismatches - U32Pair h, // ref coords - U32Pair mh, // mate's ref coords + UPair h, // ref coords + UPair mh, // mate's ref coords bool mfw, // mate's orientation uint16_t mlen, // mate length - U32Pair a, // arrow pair + UPair a, // arrow pair uint32_t tlen, // length of text uint32_t qlen, // length of query int stratum, // alignment stratum @@ -1972,7 +1971,7 @@ inline static int countInU64(int c, uint64_t dw) { #ifdef POPCNT_CAPABILITY template #endif -inline static void countInU64Ex(uint64_t dw, uint32_t* arrs) { +inline static void countInU64Ex(uint64_t dw, TIndexOffU* arrs) { uint64_t c0 = c_table[0]; uint64_t x0 = dw ^ c0; uint64_t x1 = (x0 >> 1); @@ -2219,7 +2218,7 @@ inline uint32_t Ebwt::countFwSide(const SideLocus& l, int c) const { /* ch * break just prior to the side. */ template -inline void Ebwt::countFwSideEx(const SideLocus& l, uint32_t* arrs) const +inline void Ebwt::countFwSideEx(const SideLocus& l, TIndexOffU* arrs) const { assert_lt(l._by, (int)this->_eh._sideBwtSz); assert_geq(l._by, 0); @@ -2247,8 +2246,8 @@ inline void Ebwt::countFwSideEx(const SideLocus& l, uint32_t* arrs) const } } // Now factor in the occ[] count at the side break - const uint32_t *ac = reinterpret_cast(side - 8); - const uint32_t *gt = reinterpret_cast(side + this->_eh._sideSz - 8); + const TIndexOffU *ac = reinterpret_cast(side - 8); + const TIndexOffU *gt = reinterpret_cast(side + this->_eh._sideSz - 8); #ifndef NDEBUG assert_leq(ac[0], this->_fchr[1] + this->_eh.sideBwtLen()); assert_leq(ac[1], this->_fchr[2]-this->_fchr[1]); @@ -2324,7 +2323,7 @@ inline uint32_t Ebwt::countBwSide(const SideLocus& l, int c) const { * occ[] count up to the side break. */ template -inline void Ebwt::countBwSideEx(const SideLocus& l, uint32_t* arrs) const { +inline void Ebwt::countBwSideEx(const SideLocus& l, TIndexOffU* arrs) const { assert_lt(l._by, (int)this->_eh._sideBwtSz); assert_geq(l._by, 0); assert_lt(l._bp, 4); @@ -2346,8 +2345,8 @@ inline void Ebwt::countBwSideEx(const SideLocus& l, uint32_t* arrs) const } } // Now factor in the occ[] count at the side break - const uint32_t *ac = reinterpret_cast(side + this->_eh._sideSz - 8); - const uint32_t *gt = reinterpret_cast(side + (2*this->_eh._sideSz) - 8); + const TIndexOffU *ac = reinterpret_cast(side + this->_eh._sideSz - 8); + const TIndexOffU *gt = reinterpret_cast(side + (2*this->_eh._sideSz) - 8); #ifndef NDEBUG assert_leq(ac[0], this->_fchr[1] + this->_eh.sideBwtLen()); assert_leq(ac[1], this->_fchr[2]-this->_fchr[1]); @@ -2654,7 +2653,7 @@ inline bool Ebwt::report(const String& query, const std::vector& mmui32, const std::vector& refcs, size_t numMms, - uint32_t off, + TIndexOffU off, uint32_t top, uint32_t bot, uint32_t qlen, @@ -2667,11 +2666,11 @@ inline bool Ebwt::report(const String& query, VMSG_NL("In report"); assert_geq(cost, (uint32_t)(stratum << 14)); assert_lt(off, this->_eh._len); - uint32_t tidx; - uint32_t textoff; - uint32_t tlen; + TIndexOffU tidx; + TIndexOffU textoff; + TIndexOffU tlen; joinedToTextOff(qlen, off, tidx, textoff, tlen); - if(tidx == 0xffffffff) { + if(tidx == OFF_MASK) { return false; } return params.reportHit( @@ -2726,7 +2725,7 @@ inline bool Ebwt::reportChaseOne(const String& query, const std::vector& mmui32, const std::vector& refcs, size_t numMms, - uint32_t i, + TIndexOffU i, uint32_t top, uint32_t bot, uint32_t qlen, @@ -2738,13 +2737,13 @@ inline bool Ebwt::reportChaseOne(const String& query, SideLocus *l) const { VMSG_NL("In reportChaseOne"); - uint32_t off; + TIndexOffU off; uint32_t jumps = 0; ASSERT_ONLY(uint32_t origi = i); SideLocus myl; - const uint32_t offMask = this->_eh._offMask; + const TIndexOffU offMask = this->_eh._offMask; const uint32_t offRate = this->_eh._offRate; - const uint32_t* offs = this->_offs; + const TIndexOffU* offs = this->_offs; // If the caller didn't give us a pre-calculated (and prefetched) // locus, then we have to do that now if(l == NULL) { @@ -2756,7 +2755,7 @@ inline bool Ebwt::reportChaseOne(const String& query, // Walk along until we reach the next marked row to the left while(((i & offMask) != i) && i != _zOff) { // Not a marked row; walk left one more char - uint32_t newi = mapLF(*l); // calc next row + TIndexOffU newi = mapLF(*l); // calc next row assert_neq(newi, i); i = newi; // update row l->initFromRow(i, this->_eh, this->_ebwt); // update locus @@ -4283,8 +4282,8 @@ void Ebwt::buildToDisk(InorderBlockwiseSA& sa, uint8_t *absorbFtab; try { VMSG_NL("Allocating ftab, absorbFtab"); - ftab = new uint32_t[ftabLen]; - memset(ftab, 0, 4 * ftabLen); + ftab = new TIndexOffU[ftabLen]; + memset(ftab, 0, OFF_SIZE * ftabLen); absorbFtab = new uint8_t[ftabLen]; memset(absorbFtab, 0, ftabLen); } catch(bad_alloc &e) { diff --git a/ebwt_build.cpp b/ebwt_build.cpp index ad11fd1..2ccaa1b 100644 --- a/ebwt_build.cpp +++ b/ebwt_build.cpp @@ -377,7 +377,7 @@ static void driver(const string& infile, plens.clear(); // Now read in the colorspace size records; these are // the ones that were indexed - int numSeqs2 = 0; + TIndexOff numSeqs2 = 0; sztot = fastaRefReadSizes(is, szs, plens, refparams, NULL, numSeqs2); assert_geq(numSeqs, numSeqs2); } else { @@ -414,7 +414,7 @@ static void driver(const string& infile, } else { // Read in the sizes of all the unambiguous stretches of the // genome into a vector of RefRecords - int numSeqs = 0; + TIndexOff numSeqs = 0; sztot = fastaRefReadSizes(is, szs, plens, refparams, NULL, numSeqs); #ifndef NDEBUG if(refparams.color) { diff --git a/ebwt_search_backtrack.h b/ebwt_search_backtrack.h index a528635..bec0561 100644 --- a/ebwt_search_backtrack.h +++ b/ebwt_search_backtrack.h @@ -549,7 +549,7 @@ class GreedyDFSRangeSource { // Clear pairs memset(&pairs[d*8], 0, 8 * 4); // Calculate next quartet of ranges - ebwt.mapLFEx(ltop, lbot, &pairs[d*8], &pairs[(d*8)+4]); + ebwt.mapLFEx(ltop, lbot, (TIndexOffU*)&pairs[d*8], (TIndexOffU*)&pairs[(d*8)+4]); // Update top and bot if(c < 4) { top = pairTop(pairs, d, c); bot = pairBot(pairs, d, c); @@ -2217,18 +2217,18 @@ class EbwtRangeSource : public RangeSource { rs->bots[3] = 0; if(br->lbot_.valid()) { if(metrics_ != NULL) metrics_->curBwtOps_++; - ebwt.mapLFEx(br->ltop_, br->lbot_, rs->tops, rs->bots); + ebwt.mapLFEx(br->ltop_, br->lbot_, (TIndexOffU*)rs->tops, (TIndexOffU*)rs->bots); } else { #ifndef NDEBUG - uint32_t tmptops[] = {0, 0, 0, 0}; - uint32_t tmpbots[] = {0, 0, 0, 0}; + TIndexOffU tmptops[] = {0, 0, 0, 0}; + TIndexOffU tmpbots[] = {0, 0, 0, 0}; SideLocus ltop, lbot; ltop.initFromRow(otop, ebwt_->_eh, ebwt_->_ebwt); lbot.initFromRow(obot, ebwt_->_eh, ebwt_->_ebwt); ebwt.mapLFEx(ltop, lbot, tmptops, tmpbots); #endif if(metrics_ != NULL) metrics_->curBwtOps_++; - int cc = ebwt.mapLF1(otop, br->ltop_); + int cc = ebwt.mapLF1((TIndexOffU&)otop, br->ltop_); br->top_ = otop; assert(cc == -1 || (cc >= 0 && cc < 4)); if(cc >= 0) { diff --git a/hit.h b/hit.h index d1b8492..a940ab1 100644 --- a/hit.h +++ b/hit.h @@ -48,7 +48,7 @@ static const std::string output_type_names[] = { "None" }; -typedef pair U32Pair; +typedef pair UPair; /** * Encapsulates a hit, including a text-id/text-offset pair, a pattern @@ -59,8 +59,8 @@ class Hit { public: Hit() : stratum(-1) { } - U32Pair h; /// reference index & offset - U32Pair mh; /// reference index & offset for mate + UPair h; /// reference index & offset + UPair mh; /// reference index & offset for mate uint32_t patId; /// read index String patName; /// read name String patSeq; /// read sequence diff --git a/hit_set.h b/hit_set.h index b833c1b..e6795df 100644 --- a/hit_set.h +++ b/hit_set.h @@ -17,13 +17,14 @@ #include "alphabet.h" #include "annot.h" #include "refmap.h" +#include "btypes.h" /** * Encapsulates a hit contained within a HitSet that can be * (de)serialized to/from FileBufs. Used for chaining. */ struct HitSetEnt { - typedef std::pair U32Pair; + typedef std::pair UPair; HitSetEnt() { } @@ -209,7 +210,7 @@ struct HitSetEnt { */ friend std::ostream& operator << (std::ostream& os, const HitSetEnt& hse); - U32Pair h; // reference coordinates + UPair h; // reference coordinates uint8_t fw; // orientation int8_t stratum; // stratum uint16_t cost; // cost, including stratum @@ -226,7 +227,7 @@ struct HitSet { typedef std::vector EntVec; typedef EntVec::const_iterator Iter; - typedef std::pair U32Pair; + typedef std::pair UPair; HitSet() { maxedStratum = -1; @@ -438,7 +439,7 @@ struct HitSet { /** * */ - bool tryReplacing(U32Pair h, + bool tryReplacing(UPair h, bool fw, uint16_t cost, size_t& pos) @@ -454,7 +455,7 @@ struct HitSet { pos = i; return true; } else { - pos = 0xffffffff; + pos = OFF_MASK; return true; } } diff --git a/multikey_qsort.h b/multikey_qsort.h index 987499c..ec9ef36 100644 --- a/multikey_qsort.h +++ b/multikey_qsort.h @@ -801,7 +801,7 @@ inline uint8_t get_uint8(const String >& t, uint32_t off) { template static inline int char_at_suf_u8(const TStr& host, uint32_t hlen, - uint32_t* s, + TIndexOffU* s, uint32_t si, uint32_t off, uint8_t hi) diff --git a/range_chaser.h b/range_chaser.h index 918cad5..5f04e55 100644 --- a/range_chaser.h +++ b/range_chaser.h @@ -21,8 +21,8 @@ template class RangeChaser { typedef Ebwt TEbwt; - typedef std::pair U32Pair; - typedef std::vector U32PairVec; + typedef std::pair UPair; + typedef std::vector UPairVec; typedef RowChaser TRowChaser; public: @@ -33,11 +33,11 @@ class RangeChaser { ebwt_(NULL), qlen_(0), cacheThresh_(cacheThresh), - top_(0xffffffff), - bot_(0xffffffff), - irow_(0xffffffff), - row_(0xffffffff), - off_(make_pair(0xffffffff, 0)), + top_(OFF_MASK), + bot_(OFF_MASK), + irow_(OFF_MASK), + row_(OFF_MASK), + off_(make_pair(OFF_MASK, 0)), tlen_(0), chaser_(metrics), cached_(false), @@ -52,11 +52,11 @@ class RangeChaser { * a u32 pair of . */ static void toOffs(const TEbwt& ebwt, - uint32_t qlen, + TIndexOffU qlen, RandomSource& rand, - uint32_t top, - uint32_t bot, - U32PairVec& dest) + TIndexOffU top, + TIndexOffU bot, + UPairVec& dest) { RangeChaser rc(ebwt, rand); rc.setTopBot(top, bot, qlen); @@ -75,7 +75,7 @@ class RangeChaser { /** * Set the row to chase */ - void setRow(uint32_t row) { + void setRow(TIndexOffU row) { // Must be within bounds of range assert_lt(row, bot_); assert_geq(row, top_); @@ -84,7 +84,7 @@ class RangeChaser { // First thing to try is the cache if(cached_) { assert(cacheEnt_.valid()); - uint32_t cached = cacheEnt_.get(row_ - top_); + TIndexOffU cached = cacheEnt_.get(row_ - top_); assert(cacheEnt_.valid()); if(cached != RANGE_NOT_SET) { // Assert that it matches what we would have got... @@ -96,7 +96,7 @@ class RangeChaser { ebwt_->joinedToTextOff(qlen_, cached, off_.first, off_.second, tlen_); // Note: tidx may be 0xffffffff, if alignment overlaps a // reference boundary - if(off_.first != 0xffffffff) { + if(off_.first != OFF_MASK) { // Bingo, we found a valid result using the cache assert(foundOff()); return; @@ -112,7 +112,7 @@ class RangeChaser { if(chaser_.done) { // We're done immediately off_ = chaser_.off(); - if(off_.first != 0xffffffff) { + if(off_.first != OFF_MASK) { // This is a valid result if(cached_) { // Install the result in the cache @@ -138,7 +138,7 @@ class RangeChaser { if(row_ == irow_) { // Exhausted all possible rows done = true; - assert_eq(0xffffffff, off_.first); + assert_eq(OFF_MASK, off_.first); return; } } @@ -149,14 +149,14 @@ class RangeChaser { * Set the next range for us to "chase" (i.e. convert row-by-row * to reference loci). */ - void setTopBot(uint32_t top, - uint32_t bot, - uint32_t qlen, + void setTopBot(TIndexOffU top, + TIndexOffU bot, + TIndexOffU qlen, RandomSource& rand, const TEbwt* ebwt) { - assert_neq(0xffffffff, top); - assert_neq(0xffffffff, bot); + assert_neq(OFF_MASK, top); + assert_neq(OFF_MASK, bot); assert_gt(bot, top); assert_gt(qlen, 0); assert(ebwt != NULL); @@ -164,7 +164,7 @@ class RangeChaser { qlen_ = qlen; top_ = top; bot_ = bot; - uint32_t spread = bot - top; + TIndexOffU spread = bot - top; irow_ = top + (rand.nextU32() % spread); // initial row done = false; cached_ = false; @@ -207,7 +207,7 @@ class RangeChaser { if(row_ == irow_) { // Exhausted all possible rows done = true; - assert_eq(0xffffffff, off_.first); + assert_eq(OFF_MASK, off_.first); return; } setRow(row_); @@ -218,7 +218,7 @@ class RangeChaser { if(chaser_.done) { // We're done immediately off_ = chaser_.off(); - if(off_.first != 0xffffffff) { + if(off_.first != OFF_MASK) { if(cached_) { // Install the result in the cache assert(cacheEnt_.valid()); @@ -247,7 +247,7 @@ class RangeChaser { * this range. */ bool foundOff() const { - return off_.first != 0xffffffff; + return off_.first != OFF_MASK; } /** @@ -255,20 +255,20 @@ class RangeChaser { * foundOff() returns false. */ void reset() { - off_.first = 0xffffffff; + off_.first = OFF_MASK; } /** * Get the calculated offset. */ - U32Pair off() const { + UPair off() const { return off_; } /** * Get the length of the hit reference. */ - uint32_t tlen() const { + TIndexOffU tlen() const { return tlen_; } @@ -277,14 +277,14 @@ class RangeChaser { protected: const TEbwt* ebwt_; /// index to resolve row in - uint32_t qlen_; /// length of read; needed to convert to ref. coordinates + TIndexOffU qlen_; /// length of read; needed to convert to ref. coordinates uint32_t cacheThresh_; /// ranges wider than thresh use cacheing - uint32_t top_; /// range top - uint32_t bot_; /// range bottom - uint32_t irow_; /// initial randomly-chosen row within range - uint32_t row_; /// current row within range - U32Pair off_; /// calculated offset (0xffffffff if not done) - uint32_t tlen_; /// length of text hit + TIndexOffU top_; /// range top + TIndexOffU bot_; /// range bottom + TIndexOffU irow_; /// initial randomly-chosen row within range + TIndexOffU row_; /// current row within range + UPair off_; /// calculated offset (0xffffffff if not done) + TIndexOffU tlen_; /// length of text hit TRowChaser chaser_; /// stateful row chaser RangeCacheEntry cacheEnt_; /// current cache entry bool cached_; /// cacheEnt is active for current range? diff --git a/refmap.cpp b/refmap.cpp index 025d563..0867791 100644 --- a/refmap.cpp +++ b/refmap.cpp @@ -16,7 +16,7 @@ using namespace std; * reference coordinate space according to the reference mappings * provided by the user. */ -void ReferenceMap::map(U32Pair& h) const { +void ReferenceMap::map(UPair& h) const { if(h.first >= map_.size()) { cerr << "Could not find a reference-map entry for reference " << h.first << " in map file \"" << fname_ << "\"" diff --git a/refmap.h b/refmap.h index 1fadd46..cf5ba7d 100644 --- a/refmap.h +++ b/refmap.h @@ -13,9 +13,10 @@ #include #include #include +#include "btypes.h" class ReferenceMap { - typedef std::pair U32Pair; + typedef std::pair UPair; public: ReferenceMap(const char *fname, bool parseNames) { @@ -29,7 +30,7 @@ class ReferenceMap { * new reference coordinate via the reference map supplied by the * user. */ - void map(U32Pair& h) const; + void map(UPair& h) const; /** * Return true iff we have a name for reference with id 'i'. @@ -56,7 +57,7 @@ class ReferenceMap { void parse(); const char *fname_; - std::vector map_; + std::vector map_; bool parseNames_; std::vector names_; }; diff --git a/row_chaser.h b/row_chaser.h index e6fbad0..8d776ac 100644 --- a/row_chaser.h +++ b/row_chaser.h @@ -21,7 +21,7 @@ template class RowChaser { - typedef std::pair U32Pair; + typedef std::pair UPair; typedef Ebwt TEbwt; public: @@ -31,10 +31,10 @@ class RowChaser { ebwt_(NULL), qlen_(0), eh_(NULL), - row_(0xffffffff), + row_(OFF_MASK), jumps_(0), sideloc_(), - off_(0xffffffff), + off_(OFF_MASK), tlen_(0), metrics_(metrics) { } @@ -44,7 +44,7 @@ class RowChaser { * converted to understand where it is w/r/t the reference hit and * offset within it. */ - static uint32_t toFlatRefOff(const TEbwt* ebwt, uint32_t qlen, uint32_t row) { + static TIndexOffU toFlatRefOff(const TEbwt* ebwt, TIndexOffU qlen, TIndexOffU row) { RowChaser rc; rc.setRow(row, qlen, ebwt); while(!rc.done) { @@ -56,7 +56,7 @@ class RowChaser { /** * Convert a row to a reference offset. */ - static U32Pair toRefOff(const TEbwt* ebwt, uint32_t qlen, uint32_t row) { + static UPair toRefOff(const TEbwt* ebwt, TIndexOffU qlen, TIndexOffU row) { RowChaser rc; rc.setRow(row, qlen, ebwt); while(!rc.done) { @@ -69,8 +69,8 @@ class RowChaser { * Set the next row for us to "chase" (i.e. map to a reference * location using the BWT step-left operation). */ - void setRow(uint32_t row, uint32_t qlen, const TEbwt* ebwt) { - assert_neq(0xffffffff, row); + void setRow(TIndexOffU row, TIndexOffU qlen, const TEbwt* ebwt) { + assert_neq(OFF_MASK, row); assert_gt(qlen, 0); assert(ebwt != NULL); ebwt_ = ebwt; @@ -91,7 +91,7 @@ class RowChaser { } done = false; jumps_ = 0; - off_ = 0xffffffff; + off_ = OFF_MASK; prepped_ = false; prep(); } @@ -146,25 +146,25 @@ class RowChaser { * to Ebwt::joinedToTextOff() to understand where it is w/r/t the * reference hit and offset within it. */ - uint32_t flatOff() const { + TIndexOffU flatOff() const { return off_; } /** * Get the calculated offset. */ - U32Pair off() { - uint32_t off = flatOff(); - assert_neq(0xffffffff, off); - uint32_t tidx; - uint32_t textoff = 0xffffffff; + UPair off() { + TIndexOffU off = flatOff(); + assert_neq(OFF_MASK, off); + TIndexOffU tidx; + TIndexOffU textoff = OFF_MASK; ebwt_->joinedToTextOff(qlen_, off, tidx, textoff, tlen_); // Note: tidx may be 0xffffffff, if alignment overlaps a // reference boundary return make_pair(tidx, textoff); } - uint32_t tlen() const { + TIndexOffU tlen() const { return tlen_; } @@ -174,13 +174,13 @@ class RowChaser { protected: const TEbwt* ebwt_; /// index to resolve row in - uint32_t qlen_; /// length of read; needed to convert to ref. coordinates + TIndexOffU qlen_; /// length of read; needed to convert to ref. coordinates const EbwtParams* eh_; /// eh field from index - uint32_t row_; /// current row + TIndexOffU row_; /// current row uint32_t jumps_; /// # steps so far SideLocus sideloc_; /// current side locus - uint32_t off_; /// calculated offset (0xffffffff if not done) - uint32_t tlen_; /// hit text length + TIndexOffU off_; /// calculated offset (0xffffffff if not done) + TIndexOffU tlen_; /// hit text length AlignerMetrics *metrics_; }; diff --git a/sam.cpp b/sam.cpp index 326ce40..05eb9b7 100644 --- a/sam.cpp +++ b/sam.cpp @@ -23,7 +23,7 @@ void SAMHitSink::appendHeaders(OutFileBuf& os, bool color, bool nosq, ReferenceMap *rmap, - const uint32_t* plen, + const TIndexOffU* plen, bool fullRef, bool noQnameTrunc, const char *cmdline, diff --git a/sam.h b/sam.h index 27d83e1..c473c40 100644 --- a/sam.h +++ b/sam.h @@ -12,6 +12,7 @@ #include "annot.h" #include "pat.h" #include "random_source.h" +#include "btypes.h" class ReferenceMap; class AnnotationMap; @@ -121,7 +122,7 @@ class SAMHitSink : public HitSink { bool color, bool nosq, ReferenceMap *rmap, - const uint32_t* plen, + const TIndexOffU* plen, bool fullRef, bool noQnameTrunc, const char *cmdline,