| 1 |
// The POA "alignment matrix" is a set of alignment columns |
| 2 |
// corresponding to each vertex in the graph that the read was aligned |
| 3 |
// against. |
| 4 |
|
| 5 |
#ifndef PBCOPPER_POA_ALIGNMENTMATRIX_H |
| 6 |
#define PBCOPPER_POA_ALIGNMENTMATRIX_H |
| 7 |
|
| 8 |
#include <pbcopper/PbcopperConfig.h> |
| 9 |
|
| 10 |
#include <pbcopper/poa/PoaGraph.h> |
| 11 |
#include "BoostGraph.h" |
| 12 |
#include "VectorL.h" |
| 13 |
|
| 14 |
#include <boost/utility.hpp> |
| 15 |
|
| 16 |
#include <memory> |
| 17 |
|
| 18 |
#include <cfloat> |
| 19 |
#include <cstddef> |
| 20 |
|
| 21 |
namespace PacBio { |
| 22 |
namespace Poa { |
| 23 |
namespace detail { |
| 24 |
|
| 25 |
enum MoveType |
| 26 |
{ |
| 27 |
InvalidMove, // Invalid move reaching ^ (start) |
| 28 |
StartMove, // Start move: ^ -> vertex in row 0 of local alignment |
| 29 |
EndMove, // End move: vertex -> $ in row 0 of local alignment, or |
| 30 |
// in global alignment, terminal vertex -> $ |
| 31 |
MatchMove, |
| 32 |
MismatchMove, |
| 33 |
DeleteMove, |
| 34 |
ExtraMove |
| 35 |
}; |
| 36 |
|
| 37 |
class AlignmentColumn : boost::noncopyable |
| 38 |
{ |
| 39 |
public: |
| 40 |
VD CurrentVertex; |
| 41 |
VectorL<float> Score; |
| 42 |
VectorL<MoveType> ReachingMove; |
| 43 |
VectorL<VD> PreviousVertex; |
| 44 |
|
| 45 |
explicit AlignmentColumn(VD vertex, int beginRow, int endRow) |
| 46 |
: CurrentVertex(vertex) |
| 47 |
, Score(beginRow, endRow, -FLT_MAX) |
| 48 |
, ReachingMove(beginRow, endRow, InvalidMove) |
| 49 |
, PreviousVertex(beginRow, endRow, null_vertex) |
| 50 |
{} |
| 51 |
|
| 52 |
AlignmentColumn(AlignmentColumn&& other) noexcept |
| 53 |
: CurrentVertex(std::move(other.CurrentVertex)) |
| 54 |
, Score(std::move(other.Score)) |
| 55 |
, ReachingMove(std::move(other.ReachingMove)) |
| 56 |
, PreviousVertex(std::move(other.PreviousVertex)) |
| 57 |
{} |
| 58 |
|
| 59 |
AlignmentColumn& operator=(AlignmentColumn&& other) noexcept |
| 60 |
{ |
| 61 |
CurrentVertex = std::move(other.CurrentVertex); |
| 62 |
Score = std::move(other.Score); |
| 63 |
ReachingMove = std::move(other.ReachingMove); |
| 64 |
PreviousVertex = std::move(other.PreviousVertex); |
| 65 |
return *this; |
| 66 |
} |
| 67 |
|
| 68 |
size_t BeginRow() const { return Score.BeginRow(); } |
| 69 |
size_t EndRow() const { return Score.EndRow(); } |
| 70 |
bool HasRow(size_t i) const { return (BeginRow() <= i) && (i < EndRow()); } |
| 71 |
}; |
| 72 |
|
| 73 |
using AlignmentColumnMap = std::unordered_map<VD, std::unique_ptr<const AlignmentColumn>>; |
| 74 |
|
| 75 |
class PoaAlignmentMatrixImpl : public PoaAlignmentMatrix |
| 76 |
{ |
| 77 |
public: |
| 78 |
virtual ~PoaAlignmentMatrixImpl() = default; |
| 79 |
|
| 80 |
virtual float Score() const { return score_; } |
| 81 |
size_t NumRows() const { return readSequence_.length() + 1; } |
| 82 |
size_t NumCols() const { return columns_.size(); } |
| 83 |
void Print() const; |
| 84 |
|
| 85 |
// TODO: why did I leave these public? why is there no |
| 86 |
// constructor? |
| 87 |
const PoaGraphImpl* graph_; |
| 88 |
AlignmentColumnMap columns_; |
| 89 |
std::string readSequence_; |
| 90 |
Align::AlignMode mode_; |
| 91 |
float score_; |
| 92 |
}; |
| 93 |
} // namespace detail |
| 94 |
} // namespace Poa |
| 95 |
} // namespace PacBio |
| 96 |
#endif // PBCOPPER_POA_ALIGNMENTMATRIX_H |