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 bool operator<(const ConservedPath& a, const ConservedPath &b)
59 ConservedPath::const_iterator a_i = a.begin();
60 ConservedPath::const_iterator b_i = b.begin();
61 for(; a_i != a.end() and b_i != b.end(); ++a_i, ++b_i)
65 } else if (*a_i > *b_i) {
68 // else they're equal and we continue to loop
70 // now handle mismatched lengths
71 if (a_i == a.end() and b_i == b.end()) {
72 return false; // since the two paths are equal
73 } else if (a_i == a.end()) {
74 return true; // a is shorter than b
75 } else if (b_i == b.end()) {
76 return false; // b is shorter than a
78 // something went horribly wrong
79 throw std::runtime_error("ConservedPath operator< had a fatal logic error");
83 std::ostream& operator<<(std::ostream& out, const ConservedPath& path)
85 out << "<path win_size" << path.window_size
86 << " score=" << path.score
87 << " len=" << path.track_indexes.size();
88 if (path.track_indexes.size() > 0)
90 // print the first element
91 ConservedPath::const_iterator itor = path.begin();
92 out << ">" << *itor++;
93 // print the remaining elements
104 // if we had no elements just close the block
110 void ConservedPath::push_back(const ConservedPath::path_element& element)
112 track_indexes.push_back(element);
115 void ConservedPath::pop_back()
117 track_indexes.pop_back();
120 ConservedPath::size_type ConservedPath::size() const
122 return track_indexes.size();
125 ConservedPath::iterator ConservedPath::begin()
127 return track_indexes.begin();
130 ConservedPath::const_iterator ConservedPath::begin() const
132 return track_indexes.begin();
135 ConservedPath::iterator ConservedPath::end()
137 return track_indexes.end();
140 ConservedPath::const_iterator ConservedPath::end() const
142 return track_indexes.end();
145 bool ConservedPath::nextTo(const ConservedPath& next) const
147 if (size() != next.size() ) {
148 throw conserved_path_size_mismatch("paths must be the same length");
150 ConservedPath::const_iterator this_itor = begin();
151 ConservedPath::const_iterator next_itor = next.begin();
152 for (; this_itor != end(); ++this_itor, ++next_itor)
154 if ( (*this_itor + 1) != *next_itor )
160 vector<bool> ConservedPath::reverseComplimented() const
162 vector<bool> reversed;
163 for (ConservedPath::const_iterator this_itor = begin();
168 reversed.push_back(true);
170 reversed.push_back(false);
176 std::vector<ConservedPath::path_element> ConservedPath::normalizedIndexes() const
178 vector<path_element> paths;
179 for (ConservedPath::const_iterator this_itor = begin();
183 if (*this_itor < 0) {
184 paths.push_back(-(*this_itor)-window_size);
186 paths.push_back(*this_itor);
192 ConservedPath& ConservedPath::extend(int growth)
194 window_size += growth;
196 // What does this actually do? Tristan's code was doing this operation
197 // but I don't understand how it properly adjusts reverse compliment
199 for(ConservedPath::iterator path_i = begin();