| 1 |
#include <pbcopper/poa/PoaConsensus.h> |
| 2 |
|
| 3 |
#include <pbcopper/align/AlignConfig.h> |
| 4 |
|
| 5 |
#include <boost/algorithm/string.hpp> |
| 6 |
#include <boost/foreach.hpp> |
| 7 |
|
| 8 |
#include <string> |
| 9 |
#include <utility> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
namespace PacBio { |
| 13 |
namespace Poa { |
| 14 |
|
| 15 |
Align::AlignConfig DefaultPoaConfig(Align::AlignMode mode) |
| 16 |
{ |
| 17 |
Align::AlignParams params{3, -5, -4, -4}; |
| 18 |
Align::AlignConfig config{params, mode}; |
| 19 |
return config; |
| 20 |
} |
| 21 |
|
| 22 |
PoaConsensus::PoaConsensus(std::string css, const PoaGraph& g, std::vector<size_t> cssPath) |
| 23 |
: Sequence(std::move(css)), Graph(g), Path(std::move(cssPath)) |
| 24 |
{} |
| 25 |
|
| 26 |
PoaConsensus::PoaConsensus(std::string css, const detail::PoaGraphImpl& gi, |
| 27 |
std::vector<size_t> cssPath) |
| 28 |
: Sequence(std::move(css)), Graph(gi), Path(std::move(cssPath)) |
| 29 |
{} |
| 30 |
|
| 31 |
const PoaConsensus* PoaConsensus::FindConsensus(const std::vector<std::string>& reads) |
| 32 |
{ |
| 33 |
return FindConsensus(reads, DefaultPoaConfig(Align::AlignMode::GLOBAL), -INT_MAX); |
| 34 |
} |
| 35 |
|
| 36 |
const PoaConsensus* PoaConsensus::FindConsensus(const std::vector<std::string>& reads, |
| 37 |
const Align::AlignConfig& config, int minCoverage) |
| 38 |
{ |
| 39 |
PoaGraph pg; |
| 40 |
for (const std::string& read : reads) { |
| 41 |
if (read.length() == 0) { |
| 42 |
throw std::invalid_argument("input sequences must have nonzero length."); |
| 43 |
} |
| 44 |
pg.AddRead(read, config); |
| 45 |
} |
| 46 |
return pg.FindConsensus(config, minCoverage); |
| 47 |
} |
| 48 |
|
| 49 |
const PoaConsensus* PoaConsensus::FindConsensus(const std::vector<std::string>& reads, |
| 50 |
Align::AlignMode mode, int minCoverage) |
| 51 |
{ |
| 52 |
return FindConsensus(reads, DefaultPoaConfig(mode), minCoverage); |
| 53 |
} |
| 54 |
|
| 55 |
std::string PoaConsensus::ToGraphViz(int flags) const { return Graph.ToGraphViz(flags, this); } |
| 56 |
|
| 57 |
void PoaConsensus::WriteGraphVizFile(std::string filename, int flags) const |
| 58 |
{ |
| 59 |
Graph.WriteGraphVizFile(filename, flags, this); |
| 60 |
} |
| 61 |
|
| 62 |
} // namespace Poa |
| 63 |
} // namespace PacBio |