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