1 #include "alg/conserved_path.hpp"
2 #include "mussa_exceptions.hpp"
8 ConservedPath::ConservedPath()
15 ConservedPath::ConservedPath(const ConservedPath::ConservedPath& other)
16 : window_size(other.window_size),
18 track_indexes(other.track_indexes)
22 ConservedPath::ConservedPath(size_t win_size, double s, ConservedPath::path_type path)
23 : window_size(win_size),
29 void ConservedPath::clear()
33 track_indexes.clear();
36 ConservedPath::path_element&
37 ConservedPath::operator[](ConservedPath::size_type index)
39 return track_indexes[index];
42 bool operator==(const ConservedPath::ConservedPath& a,
43 const ConservedPath::ConservedPath& b)
45 // this isn't good as score is now a double
46 return ( (a.score == b.score)
47 and (a.track_indexes.size() == b.track_indexes.size())
48 and (a.track_indexes == b.track_indexes));
51 bool operator!=(const ConservedPath::ConservedPath& a,
52 const ConservedPath::ConservedPath& b)
57 std::ostream& operator<<(std::ostream& out, const ConservedPath& path)
59 out << "<path win_size" << path.window_size
60 << " score=" << path.score
61 << " len=" << path.track_indexes.size();
62 if (path.track_indexes.size() > 0)
64 // print the first element
65 ConservedPath::const_iterator itor = path.begin();
66 out << ">" << *itor++;
67 // print the remaining elements
78 // if we had no elements just close the block
84 void ConservedPath::push_back(const ConservedPath::path_element& element)
86 track_indexes.push_back(element);
89 void ConservedPath::pop_back()
91 track_indexes.pop_back();
94 ConservedPath::size_type ConservedPath::size() const
96 return track_indexes.size();
99 ConservedPath::iterator ConservedPath::begin()
101 return track_indexes.begin();
104 ConservedPath::const_iterator ConservedPath::begin() const
106 return track_indexes.begin();
109 ConservedPath::iterator ConservedPath::end()
111 return track_indexes.end();
114 ConservedPath::const_iterator ConservedPath::end() const
116 return track_indexes.end();
119 bool ConservedPath::nextTo(const ConservedPath& next) const
121 if (size() != next.size() ) {
122 throw conserved_path_size_mismatch("paths must be the same length");
124 ConservedPath::const_iterator this_itor = begin();
125 ConservedPath::const_iterator next_itor = next.begin();
126 for (; this_itor != end(); ++this_itor, ++next_itor)
128 if ( (*this_itor + 1) != *next_itor )
134 vector<bool> ConservedPath::reverseComplimented() const
136 vector<bool> reversed;
137 for (ConservedPath::const_iterator this_itor = begin();
142 reversed.push_back(true);
144 reversed.push_back(false);
150 std::vector<ConservedPath::path_element> ConservedPath::normalizedIndexes() const
152 vector<path_element> paths;
153 for (ConservedPath::const_iterator this_itor = begin();
157 if (*this_itor < 0) {
158 paths.push_back(-(*this_itor)-window_size);
160 paths.push_back(*this_itor);
166 ConservedPath& ConservedPath::extend(int growth)
168 window_size += growth;
170 // What does this actually do? Tristan's code was doing this operation
171 // but I don't understand how it properly adjusts reverse compliment
173 for(ConservedPath::iterator path_i = begin();