| 1 |
#include <pbcopper/align/Seeds.h> |
| 2 |
|
| 3 |
#include <type_traits> |
| 4 |
|
| 5 |
namespace PacBio { |
| 6 |
namespace Align { |
| 7 |
|
| 8 |
bool Seeds::AddSeed(const Seed& s) |
| 9 |
{ |
| 10 |
data_.insert(s); |
| 11 |
return true; |
| 12 |
} |
| 13 |
|
| 14 |
bool Seeds::TryMergeSeed(const Seed& s) |
| 15 |
{ |
| 16 |
Seed left; |
| 17 |
for (auto it = data_.begin(); it != data_.end(); ++it) { |
| 18 |
if (CanMergeSeeds(*it, s)) { |
| 19 |
left = *it; |
| 20 |
left += s; |
| 21 |
data_.erase(it); |
| 22 |
data_.insert(left); |
| 23 |
return true; |
| 24 |
} else if (CanMergeSeeds(s, *it)) { |
| 25 |
left = s; |
| 26 |
left += *it; |
| 27 |
data_.erase(it); |
| 28 |
data_.insert(left); |
| 29 |
return true; |
| 30 |
} |
| 31 |
} |
| 32 |
return false; |
| 33 |
} |
| 34 |
|
| 35 |
bool CanMergeSeeds(const Seed& lhs, const Seed& rhs) |
| 36 |
{ |
| 37 |
// rhs must be to right of lhs AND seeds must overlap |
| 38 |
const auto ok = rhs.BeginPositionH() >= lhs.BeginPositionH() && |
| 39 |
rhs.BeginPositionV() >= lhs.BeginPositionV() && |
| 40 |
rhs.BeginPositionH() <= lhs.EndPositionH() && |
| 41 |
rhs.BeginPositionV() <= lhs.EndPositionV(); |
| 42 |
return ok; |
| 43 |
} |
| 44 |
|
| 45 |
} // namespace Align |
| 46 |
} // namespace PacBio |