| 1 |
#include "PoaAlignmentMatrix.h" |
| 2 |
|
| 3 |
#include "PoaGraphImpl.h" |
| 4 |
|
| 5 |
#include <iomanip> |
| 6 |
#include <ios> |
| 7 |
#include <iostream> |
| 8 |
#include <sstream> |
| 9 |
#include <string> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
#include <cstddef> |
| 13 |
|
| 14 |
namespace PacBio { |
| 15 |
namespace Poa { |
| 16 |
namespace detail { |
| 17 |
|
| 18 |
void PoaAlignmentMatrixImpl::Print() const |
| 19 |
{ |
| 20 |
const int COL_WIDTH = 6; |
| 21 |
const int ROW_HEIGHT = 2; |
| 22 |
|
| 23 |
const std::map<MoveType, char> moveCode = { |
| 24 |
{InvalidMove, 'Z'}, {StartMove, 'S'}, {EndMove, 'E'}, {MatchMove, '='}, |
| 25 |
{MismatchMove, 'X'}, {DeleteMove, 'D'}, {ExtraMove, 'I'}}; |
| 26 |
|
| 27 |
// Display something like this: |
| 28 |
// |
| 29 |
// 0 2 3 4 5 6 7 8 9 1 |
| 30 |
// ^ A C G T A C G T $ |
| 31 |
// |
| 32 |
// - 0Z 0S 0S 0S -infZ |
| 33 |
// |
| 34 |
// A 0S 3= 0S 0S 0S -infZ |
| 35 |
// |
| 36 |
// C 0S 0S 6= 2D 0S 0S -infZ |
| 37 |
// |
| 38 |
// G 0S 0S 2I 9= 5D 1D 0S -infZ |
| 39 |
// |
| 40 |
// T 0S 0S 0S 5I 12= 8D 4D 0S -infZ |
| 41 |
// |
| 42 |
// A 0S 3= 0S 1I 8I 15= 11D 7D 3D -infZ |
| 43 |
// |
| 44 |
// C 0S 0S 6= 2D 4I 11I 18= 14D 10D -infZ |
| 45 |
// |
| 46 |
// G 0S 2I 9= 5D 7I 14I 21= 17D -infZ |
| 47 |
// |
| 48 |
std::ostringstream header0; // Vertex IDs |
| 49 |
std::ostringstream header1; // Vertex labels |
| 50 |
std::vector<std::ostringstream> outputRows(NumRows()); |
| 51 |
|
| 52 |
header0 << std::setw(COL_WIDTH) << std::right << ""; |
| 53 |
header1 << std::setw(COL_WIDTH) << std::right << ""; |
| 54 |
for (size_t row = 0; row < NumRows(); row++) { |
| 55 |
char readBase; |
| 56 |
if (row == 0) { |
| 57 |
readBase = '-'; |
| 58 |
} else { |
| 59 |
readBase = readSequence_[row - 1]; |
| 60 |
} |
| 61 |
outputRows[row] << std::setw(COL_WIDTH) << std::right << readBase; |
| 62 |
} |
| 63 |
|
| 64 |
for (const auto& v : graph_->sortedVertices()) { |
| 65 |
const AlignmentColumn& col = *(columns_.at(v)); |
| 66 |
const PoaNode& node = graph_->getPoaNode(v); |
| 67 |
|
| 68 |
header0 << std::setw(COL_WIDTH) << std::right << node.Id; |
| 69 |
header1 << std::setw(COL_WIDTH) << std::right << node.Base; |
| 70 |
|
| 71 |
for (size_t j = 0; j < NumRows(); j++) { |
| 72 |
if (col.HasRow(j)) { |
| 73 |
float score = col.Score[j]; |
| 74 |
std::string scoreFmt = score == -FLT_MAX ? "-inf" : std::to_string(int(score)); |
| 75 |
std::string cellFmt = scoreFmt + moveCode.at(col.ReachingMove[j]); |
| 76 |
outputRows[j] << std::setw(COL_WIDTH) << std::right << cellFmt; |
| 77 |
} else { |
| 78 |
outputRows[j] << std::setw(COL_WIDTH) << std::right << ""; |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
std::cout << header0.str() << std::endl; |
| 84 |
std::cout << header1.str() << std::endl; |
| 85 |
for (size_t row = 0; row < NumRows(); row++) { |
| 86 |
for (size_t skip = ROW_HEIGHT; skip > 1; skip--) { |
| 87 |
std::cout << std::endl; |
| 88 |
} |
| 89 |
std::cout << outputRows[row].str() << std::endl; |
| 90 |
} |
| 91 |
} |
| 92 |
} // namespace detail |
| 93 |
} // namespace Poa |
| 94 |
} // namespace PacBio |