Go to the documentation of this file.    1 #ifndef BIFROST_COLORSET_HPP 
    2 #define BIFROST_COLORSET_HPP 
    7 #include "TinyBitmap.hpp" 
   24     struct alignas(8) Bitmap { Roaring r; };
 
   32         typedef pair<UnitigColors, size_t> SharedUnitigColors;
 
   75                     return make_pair(ck_id % um_sz, ck_id / um_sz);
 
   88                 inline size_t getColorID()
 const { 
return ck_id / um_sz; }
 
  139                 const Roaring empty_roar;
 
  144                 Roaring::const_iterator it_roar;
 
  145                 TinyBitmap::const_iterator it_t_bmp;
 
  148                                             const size_t len_unitig_km, 
const bool beg);
 
  150                 inline uint64_t get_ID()
 const { 
return ck_id; }
 
  152                 inline bool isInvalid()
 const {
 
  154                     return ((ck_id == 0xffffffffffffffff) || (it_setBits == cs_sz));
 
  284         bool write(ostream& stream_out, 
const bool copy_UnitigColors = 
true) 
const;
 
  324         uint64_t hash(
const size_t seed = 0) 
const;
 
  333         void add(
const size_t color_id);
 
  334         bool contains(
const size_t color_km_id) 
const;
 
  336         inline void releaseMemory(){
 
  338             const uintptr_t flag = setBits & flagMask;
 
  340             if (flag == ptrUnitigColors) 
delete[] getPtrUnitigColors();
 
  341             else if (flag == ptrBitmap) 
delete getPtrBitmap();
 
  342             else if (flag == ptrSharedUnitigColors){
 
  344                 SharedUnitigColors* s_uc = getPtrSharedUnitigColors();
 
  346                 if (--(s_uc->second) == 0) s_uc->first.clear();
 
  348             else if (flag == localTinyBitmap){
 
  350                 uint16_t* setPtrTinyBmp = getPtrTinyBitmap();
 
  351                 TinyBitmap t_bmp(&setPtrTinyBmp);
 
  356             setBits = localBitVector;
 
  359         inline void shrinkSize(){
 
  361             const uintptr_t flag = setBits & flagMask;
 
  363             if (flag == ptrUnitigColors){
 
  370             else if (flag == ptrBitmap) getPtrBitmap()->r.shrinkToFit();
 
  371             else if (flag == localTinyBitmap){
 
  373                 uint16_t* setPtrTinyBmp = getPtrTinyBitmap();
 
  374                 TinyBitmap t_bmp(&setPtrTinyBmp);
 
  378                 setBits = (
reinterpret_cast<uintptr_t
>(t_bmp.detach()) & pointerMask) | localTinyBitmap;
 
  388             return (isUnitigColors() ? getPtrUnitigColors() : 
nullptr);
 
  393             return (isUnitigColors() ? getPtrUnitigColors() : 
nullptr);
 
  396         inline bool isBitmap()
 const { 
return ((setBits & flagMask) == ptrBitmap); }
 
  397         inline bool isTinyBitmap()
 const { 
return ((setBits & flagMask) == localTinyBitmap); }
 
  398         inline bool isUnitigColors()
 const { 
return ((setBits & flagMask) == ptrUnitigColors); }
 
  399         inline bool isSharedUnitigColors()
 const { 
return ((setBits & flagMask) == ptrSharedUnitigColors); }
 
  405         const_iterator begin(
const size_t start_pos, 
const size_t end_pos, 
const size_t len_km_sz) 
const;
 
  407         inline Bitmap* getPtrBitmap()
 const {
 
  409             return reinterpret_cast<Bitmap*
>(setBits & pointerMask);
 
  412         inline const Bitmap* getConstPtrBitmap()
 const {
 
  414             return reinterpret_cast<const Bitmap*
>(setBits & pointerMask);
 
  417         inline uint16_t* getPtrTinyBitmap()
 const {
 
  419             return reinterpret_cast<uint16_t*
>(setBits & pointerMask);
 
  424             return reinterpret_cast<UnitigColors*
>(setBits & pointerMask);
 
  427         inline const UnitigColors* getConstPtrUnitigColors()
 const {
 
  429             return reinterpret_cast<const UnitigColors*
>(setBits & pointerMask);
 
  432         inline SharedUnitigColors* getPtrSharedUnitigColors()
 const {
 
  434             return reinterpret_cast<SharedUnitigColors*
>(setBits & pointerMask);
 
  437         inline const SharedUnitigColors* getConstPtrSharedUnitigColors()
 const {
 
  439             return reinterpret_cast<const SharedUnitigColors*
>(setBits & pointerMask);
 
  442         static const size_t maxBitVectorIDs; 
 
  443         static const size_t shiftMaskBits; 
 
  455         static const uintptr_t localTinyBitmap; 
 
  456         static const uintptr_t localBitVector; 
 
  457         static const uintptr_t localSingleInt; 
 
  458         static const uintptr_t ptrBitmap; 
 
  459         static const uintptr_t ptrUnitigColors; 
 
  460         static const uintptr_t ptrSharedUnitigColors; 
 
  462         static const uintptr_t flagMask; 
 
  463         static const uintptr_t pointerMask; 
 
 
bool isEqual(const UnitigMapBase &um, const UnitigColors &o, const UnitigMapBase &um_o) const
Check if two UnitigColors are equal.
 
bool operator==(const UnitigColors_const_iterator &o) const
Equality operator.
 
const_iterator end() const
Create a constant iterator to the "past-the-last" pair (k-mer position, color) of the UnitigColors.
 
UnitigColors_const_iterator operator++(int)
Postfix increment operator: it iterates over the next k-mer of the unitig having the current color or...
 
UnitigColors_const_iterator & operator++()
Prefix increment operator: it iterates over the next k-mer of the unitig having the current color or ...
 
size_t getKmerPosition() const
Get the k-mer position of the k-mer visited by the iterator.
Definition: ColorSet.hpp:82
 
bool read(istream &stream_in)
Read a UnitigColors from a stream.
 
size_t colorMax(const UnitigMapBase &um) const
Get the largest color index of all k-mers of a reference unitig.
 
pair< size_t, size_t > operator*() const
Indirection operator.
Definition: ColorSet.hpp:73
 
bool write(ostream &stream_out, const bool copy_UnitigColors=true) const
Write a UnitigColors to a stream.
 
bool optimizeFullColors(const UnitigMapBase &um)
If possible, decrease the memory usage of the UnitigColors by optimizing the memory for "full colors"...
 
Interface for the Compacted de Bruijn graph API.
 
void remove(const UnitigMapBase &um, const size_t color_id)
Remove a color in the current UnitigColors for all k-mers of a unitig mapping.
 
UnitigColors_const_iterator & nextColor()
Color increment operator: it iterates over the first k-mer position of the next color.
 
size_t size(const UnitigMapBase &um, const size_t color_id) const
Get the number of k-mers of a reference unitig having a given color.
 
void add(const UnitigMapBase &um, const size_t color_id)
Add a color in the current UnitigColors to all k-mers of a unitig mapping.
 
Represent the k-mer color sets of a unitig.
Definition: ColorSet.hpp:21
 
UnitigColors()
Constructor (set up an empty container of k-mer color sets).
 
~UnitigColors()
Destructor.
 
See UnitigColors::const_iterator.
Definition: ColorSet.hpp:37
 
bool contains(const UnitigMapBase &um, const size_t color_id) const
Check if a color is present on all k-mers of a unitig mapping.
 
UnitigColors & operator=(UnitigColors &&o)
Move assignment operator.
 
size_t size(const UnitigMapBase &um) const
Get the number of pairs (k-mer position, color) of a reference unitig.
 
~UnitigColors_const_iterator()
Destructor.
 
bool operator!=(const UnitigColors_const_iterator &o) const
Inequality operator.
 
UnitigColors_const_iterator & operator=(const UnitigColors_const_iterator &o)
Copy assignment operator.
 
size_t getSizeInBytes() const
Size of the UnitigColors in bytes.
 
bool isEmpty() const
Check if a UnitigColors is empty (no colors).
Definition: ColorSet.hpp:229
 
const_iterator begin(const UnitigMapBase &um) const
Create a constant iterator on all pairs (k-mer position, color) of the UnitigColors.
 
UnitigColors_const_iterator()
Constructor of an empty iterator.
 
Interface to access the colors and the data associated with a unitig of a ColoredCDBG.
Definition: DataAccessor.hpp:21
 
size_t getColorID() const
Get the color of the k-mer visited by the iterator.
Definition: ColorSet.hpp:88
 
Structure containing the basic information of a unitig mapping.
Definition: UnitigMap.hpp:33
 
UnitigColors(const UnitigColors &o)
Copy constructor.
 
Definition: ColorSet.hpp:468
 
UnitigColors_const_iterator(const UnitigColors_const_iterator &o)
Copy constructor.
 
Definition: ColorSet.hpp:16
 
UnitigColors(UnitigColors &&o)
Move constructor.
 
void clear()
Empty a UnitigColors of its content.
 
UnitigColors_const_iterator const_iterator
Iterator for the colors of a unitig.
Definition: ColorSet.hpp:164
 
UnitigColors & operator=(const UnitigColors &o)
Copy assignment operator.
 
Represent a Colored and Compacted de Bruijn graph.
Definition: ColoredCDBG.hpp:151