Bifrost: src/Unitig.hpp Source File

Bifrost

Unitig.hpp
Go to the documentation of this file.
1 #ifndef BFG_UNITIG_HPP
2 #define BFG_UNITIG_HPP
3
4 #include "Common.hpp"
5 #include "Kmer.hpp"
6 #include "CompressedSequence.hpp"
7 #include "CompressedCoverage.hpp"
8
21 template<typename T>
22 class Unitig {
23
24 public:
25
26 Unitig() : coveragesum(0) {}
27 Unitig(const char* s, bool full = false) : seq(s) { initializeCoverage(full); }
28
29 void initializeCoverage(bool full) {
30
31 const size_t ssz = seq.size(), k = Kmer::k;
32
33 coveragesum = 0;
34
35 ccov = CompressedCoverage();
36 ccov.initialize(ssz >= k ? ssz - k + 1 : 0, full);
37 }
38
39 void cover(size_t start, size_t end) {
40
41 ccov.cover(start, end);
42
43 if (end < start) swap(start, end);
44
45 __sync_add_and_fetch(&coveragesum, end - start + 1);
46 }
47
48 inline size_t numKmers() const { return seq.size( ) - Kmer::k + 1; }
49 inline size_t length() const { return seq.size(); }
50
54 inline const T* getData() const { return &data; }
55 inline T* getData() { return &data; }
56
57 uint64_t coveragesum;
58
59 CompressedCoverage ccov;
60 CompressedSequence seq;
61
62 T data;
63 };
64
66 template<>
67 class Unitig<void> {
68
69 public:
70
71 Unitig() : coveragesum(0) {}
72 Unitig(const char* s, bool full = false) : seq(s) { initializeCoverage(full); }
73
74 void initializeCoverage(bool full) {
75
76 const size_t ssz = seq.size(), k = Kmer::k;
77
78 coveragesum = 0;
79
80 ccov = CompressedCoverage();
81 ccov.initialize(ssz >= k ? ssz - k + 1 : 0, full);
82 }
83
84 void cover(size_t start, size_t end) {
85
86 ccov.cover(start, end);
87
88 if (end < start) swap(start, end);
89
90 __sync_add_and_fetch(&coveragesum, end - start + 1);
91 }
92
93 inline size_t numKmers() const { return seq.size( ) - Kmer::k + 1; }
94 inline size_t length() const { return seq.size(); }
95
96 inline const void* getData() const { return nullptr; }
97 inline void* getData() { return nullptr; }
98
99 uint64_t coveragesum;
100
101 CompressedCoverage ccov;
102 CompressedSequence seq;
103 };
105
106 #endif // BFG_CONTIG_HPP
Unitig::data
T data
Data associated with the unitigs of the graph.
Definition: Unitig.hpp:62
Kmer.hpp
Interface for the class Kmer:
Unitig::getData
const T * getData() const
Return a constant pointer to the data associated with the unitig.
Definition: Unitig.hpp:54
Unitig
Represent a unitig which is a vertex of the Compacted de Bruijn graph.
Definition: Unitig.hpp:22