#include "alg/conserved_path.hpp"
-#include <stdexcept>
+#include "mussa_exceptions.hpp"
using namespace std;
/////////////////////
ConservedPath::ConservedPath()
- : score(0.0),
+ : window_size(0),
+ score(0.0),
track_indexes()
{
}
ConservedPath::ConservedPath(const ConservedPath::ConservedPath& other)
- : score(other.score),
+ : window_size(other.window_size),
+ score(other.score),
track_indexes(other.track_indexes)
{
}
-ConservedPath::ConservedPath(double s, ConservedPath::path_type path)
- : score(s),
+ConservedPath::ConservedPath(size_t win_size, double s, ConservedPath::path_type path)
+ : window_size(win_size),
+ score(s),
track_indexes(path)
{
}
void ConservedPath::clear()
{
+ window_size = 0;
score = 0.0;
track_indexes.clear();
}
return not (a == b);
}
+bool operator<(const ConservedPath& a, const ConservedPath &b)
+{
+ ConservedPath::const_iterator a_i = a.begin();
+ ConservedPath::const_iterator b_i = b.begin();
+ for(; a_i != a.end() and b_i != b.end(); ++a_i, ++b_i)
+ {
+ if (*a_i < *b_i) {
+ return true;
+ } else if (*a_i > *b_i) {
+ return false;
+ }
+ // else they're equal and we continue to loop
+ }
+ // now handle mismatched lengths
+ if (a_i == a.end() and b_i == b.end()) {
+ return false; // since the two paths are equal
+ } else if (a_i == a.end()) {
+ return true; // a is shorter than b
+ } else if (b_i == b.end()) {
+ return false; // b is shorter than a
+ } else {
+ // something went horribly wrong
+ throw std::runtime_error("ConservedPath operator< had a fatal logic error");
+ }
+}
+
std::ostream& operator<<(std::ostream& out, const ConservedPath& path)
{
- out << "<path score=" << path.score
+ out << "<path win_size" << path.window_size
+ << " score=" << path.score
<< " len=" << path.track_indexes.size();
if (path.track_indexes.size() > 0)
{
bool ConservedPath::nextTo(const ConservedPath& next) const
{
if (size() != next.size() ) {
- throw runtime_error("paths must be the same length");
+ throw conserved_path_size_mismatch("paths must be the same length");
}
ConservedPath::const_iterator this_itor = begin();
ConservedPath::const_iterator next_itor = next.begin();
}
-/////////////////////
-ExtendedConservedPath::ExtendedConservedPath()
- : ConservedPath(),
- window_size(0)
-{
-}
-
-ExtendedConservedPath::ExtendedConservedPath(const ExtendedConservedPath& other)
- : ConservedPath(other),
- window_size(other.window_size)
-{
-}
-
-ExtendedConservedPath::ExtendedConservedPath(int win_size, ConservedPath other)
- : ConservedPath(other),
- window_size(win_size)
-{
-}
-
-ExtendedConservedPath::ExtendedConservedPath(int win_size,
- double s,
- ConservedPath::path_type p)
- : ConservedPath(s, p),
- window_size(win_size)
+std::vector<ConservedPath::path_element> ConservedPath::normalizedIndexes() const
{
+ vector<path_element> paths;
+ for (ConservedPath::const_iterator this_itor = begin();
+ this_itor != end();
+ ++this_itor)
+ {
+ if (*this_itor < 0) {
+ paths.push_back(-(*this_itor)-window_size);
+ } else {
+ paths.push_back(*this_itor);
+ }
+ }
+ return paths;
}
-ExtendedConservedPath& ExtendedConservedPath::extend(int growth)
+ConservedPath& ConservedPath::extend(int growth)
{
window_size += growth;
return *this;
}
-std::ostream& operator<<(std::ostream& out, const ExtendedConservedPath& path)
-{
- out << "<extended_path size=" << path.window_size;
- out << (ConservedPath&)path;
- return out;
-}
-