| 1197 | */ |
| 1198 | template<class iterator, class oiterator> |
| 1199 | static bool |
| 1200 | buildConsensus( |
| 1201 | const Lengths& lengths, |
| 1202 | iterator it1, |
| 1203 | iterator it1e, |
| 1204 | iterator it2, |
| 1205 | iterator it2e, |
| 1206 | oiterator& out) |
| 1207 | { |
| 1208 | iterator it1b = it1 + 1; |
| 1209 | assert(!it1b->ambiguous()); |
| 1210 | |
| 1211 | if (it1b == it1e) { |
| 1212 | // path2 completely fills the gap in path1. |
| 1213 | out = copy(it2, it2e, out); |
| 1214 | return true; |
| 1215 | } |
| 1216 | |
| 1217 | // The gaps of path1 and path2 overlap. |
| 1218 | iterator it2a = it2e - 1; |
| 1219 | if (it2e == it2 || !it2a->ambiguous()) { |
| 1220 | // The two paths do not agree. No alignment. |
| 1221 | return false; |
| 1222 | } |
| 1223 | |
| 1224 | unsigned ambiguous1 = it1->length(); |
| 1225 | unsigned ambiguous2 = it2a->length(); |
| 1226 | unsigned unambiguous1 = accumulate(it1b, it1e, 0, AddLength(lengths)); |
| 1227 | unsigned unambiguous2 = accumulate(it2, it2a, 0, AddLength(lengths)); |
| 1228 | if (ambiguous1 < unambiguous2 || ambiguous2 < unambiguous1) { |
| 1229 | // Two gaps overlap and either of the gaps is smaller |
| 1230 | // than the unambiguous sequence that overlaps the |
| 1231 | // gap. No alignment. |
| 1232 | return false; |
| 1233 | } |
| 1234 | |
| 1235 | unsigned n = max(1U, max(ambiguous2 - unambiguous1, ambiguous1 - unambiguous2)); |
| 1236 | out = copy(it2, it2a, out); |
| 1237 | *out++ = ContigNode(n, 'N'); |
| 1238 | out = copy(it1b, it1e, out); |
| 1239 | return true; |
| 1240 | } |
| 1241 | |
| 1242 | /** Align the ambiguous region [it1, last1) to [it2, last2) using it1e |
| 1243 | * as the seed of the alignment. The end of the alignment is returned |
no test coverage detected