| 1 |
// |
| 2 |
// SIMD local (Smith-Waterman) alignment |
| 3 |
// |
| 4 |
|
| 5 |
#include <pbcopper/align/LocalAlignment.h> |
| 6 |
|
| 7 |
#include <utility> |
| 8 |
|
| 9 |
#include "../../include/pbcopper/align/cssw/ssw_cpp.h" |
| 10 |
|
| 11 |
namespace PacBio { |
| 12 |
namespace Align { |
| 13 |
|
| 14 |
static LocalAlignment FromSSW(StripedSmithWaterman::Alignment&& sswAl) |
| 15 |
{ |
| 16 |
return LocalAlignment{ |
| 17 |
sswAl.ref_begin, sswAl.ref_end, sswAl.query_begin, sswAl.query_end, |
| 18 |
sswAl.mismatches, sswAl.sw_score, std::move(sswAl.cigar), std::move(sswAl.cigar_string)}; |
| 19 |
} |
| 20 |
|
| 21 |
LocalAlignConfig LocalAlignConfig::Default() { return LocalAlignConfig{2, 2, 3, 1}; } |
| 22 |
|
| 23 |
LocalAlignment::LocalAlignment(const int32_t targetBegin, const int32_t targetEnd, |
| 24 |
const int32_t queryBegin, const int32_t queryEnd, |
| 25 |
const int32_t mismatches, const uint16_t score, |
| 26 |
std::vector<uint32_t> cigar, std::string cigarString) |
| 27 |
: targetBegin_(targetBegin) |
| 28 |
, targetEnd_(targetEnd) |
| 29 |
, queryBegin_(queryBegin) |
| 30 |
, queryEnd_(queryEnd) |
| 31 |
, mismatches_(mismatches) |
| 32 |
, score_(score) |
| 33 |
, cigar_(std::move(cigar)) |
| 34 |
, cigarString_(std::move(cigarString)) |
| 35 |
{} |
| 36 |
|
| 37 |
LocalAlignment LocalAlign(const std::string& target, const std::string& query, |
| 38 |
const LocalAlignConfig& config) |
| 39 |
{ |
| 40 |
StripedSmithWaterman::Aligner aligner{config.MatchScore, config.MismatchPenalty, |
| 41 |
config.GapOpenPenalty, config.GapExtendPenalty}; |
| 42 |
StripedSmithWaterman::Filter filter; |
| 43 |
StripedSmithWaterman::Alignment alignment; |
| 44 |
|
| 45 |
aligner.Align(query.c_str(), target.c_str(), target.size(), filter, &alignment); |
| 46 |
return FromSSW(std::move(alignment)); |
| 47 |
} |
| 48 |
|
| 49 |
std::vector<LocalAlignment> LocalAlign(const std::string& target, |
| 50 |
const std::vector<std::string>& queries, |
| 51 |
const LocalAlignConfig& config) |
| 52 |
{ |
| 53 |
StripedSmithWaterman::Aligner aligner{config.MatchScore, config.MismatchPenalty, |
| 54 |
config.GapOpenPenalty, config.GapExtendPenalty}; |
| 55 |
StripedSmithWaterman::Filter filter; |
| 56 |
aligner.SetReferenceSequence(target.c_str(), target.size()); |
| 57 |
|
| 58 |
std::vector<LocalAlignment> results; |
| 59 |
results.reserve(queries.size()); |
| 60 |
for (const auto& query : queries) { |
| 61 |
StripedSmithWaterman::Alignment alignment; |
| 62 |
aligner.Align(query.c_str(), filter, &alignment); |
| 63 |
results.push_back(FromSSW(std::move(alignment))); |
| 64 |
} |
| 65 |
return results; |
| 66 |
} |
| 67 |
|
| 68 |
} // namespace Align |
| 69 |
} // namespace PacBio |