| 1127 | */ |
| 1128 | template<class iterator, class oiterator> |
| 1129 | static bool |
| 1130 | alignCoordinates( |
| 1131 | const Lengths& lengths, |
| 1132 | iterator& first1, |
| 1133 | iterator last1, |
| 1134 | iterator& first2, |
| 1135 | iterator last2, |
| 1136 | oiterator& result) |
| 1137 | { |
| 1138 | oiterator out = result; |
| 1139 | |
| 1140 | int ambiguous1 = 0, ambiguous2 = 0; |
| 1141 | iterator it1 = first1, it2 = first2; |
| 1142 | while (it1 != last1 && it2 != last2) { |
| 1143 | if (it1->ambiguous()) { |
| 1144 | ambiguous1 += it1->length(); |
| 1145 | ++it1; |
| 1146 | assert(it1 != last1); |
| 1147 | assert(!it1->ambiguous()); |
| 1148 | } |
| 1149 | if (it2->ambiguous()) { |
| 1150 | ambiguous2 += it2->length(); |
| 1151 | ++it2; |
| 1152 | assert(it2 != last2); |
| 1153 | assert(!it2->ambiguous()); |
| 1154 | } |
| 1155 | |
| 1156 | if (ambiguous1 > 0 && ambiguous2 > 0) { |
| 1157 | if (ambiguous1 > ambiguous2) { |
| 1158 | *out++ = ContigNode(ambiguous2, 'N'); |
| 1159 | ambiguous1 -= ambiguous2; |
| 1160 | ambiguous2 = 0; |
| 1161 | } else { |
| 1162 | *out++ = ContigNode(ambiguous1, 'N'); |
| 1163 | ambiguous2 -= ambiguous1; |
| 1164 | ambiguous1 = 0; |
| 1165 | } |
| 1166 | } else if (ambiguous1 > 0) { |
| 1167 | ambiguous1 -= getLength(lengths, *it2); |
| 1168 | *out++ = *it2++; |
| 1169 | } else if (ambiguous2 > 0) { |
| 1170 | ambiguous2 -= getLength(lengths, *it1); |
| 1171 | *out++ = *it1++; |
| 1172 | } else |
| 1173 | assert(false); |
| 1174 | |
| 1175 | if (ambiguous1 == 0 && ambiguous2 == 0) |
| 1176 | break; |
| 1177 | if (ambiguous1 < 0 || ambiguous2 < 0) |
| 1178 | return false; |
| 1179 | } |
| 1180 | |
| 1181 | assert(ambiguous1 == 0 || ambiguous2 == 0); |
| 1182 | int ambiguous = ambiguous1 + ambiguous2; |
| 1183 | assert(out > result); |
| 1184 | if (out[-1].ambiguous()) |
| 1185 | assert(ambiguous == 0); |
| 1186 | else |
no test coverage detected