| 257 | */ |
| 258 | template<typename It> |
| 259 | static float |
| 260 | getAlignmentIdentity(const Graph& g, vertex_descriptor t, vertex_descriptor v, It first, It last) |
| 261 | { |
| 262 | unsigned nbranches = distance(first, last); |
| 263 | vector<int> inDists(nbranches); |
| 264 | transform( |
| 265 | first, last, inDists.begin(), boost::lambda::bind(getDistance, boost::cref(g), t, _1)); |
| 266 | vector<int> outDists(nbranches); |
| 267 | transform( |
| 268 | first, last, outDists.begin(), boost::lambda::bind(getDistance, boost::cref(g), _1, v)); |
| 269 | vector<int> insertLens(nbranches); |
| 270 | transform( |
| 271 | first, |
| 272 | last, |
| 273 | insertLens.begin(), |
| 274 | boost::lambda::bind(getDistance, boost::cref(g), t, _1) + |
| 275 | boost::lambda::bind(getLength, &g, _1) + |
| 276 | boost::lambda::bind(getDistance, boost::cref(g), _1, v)); |
| 277 | |
| 278 | int max_in_overlap = -(*min_element(inDists.begin(), inDists.end())); |
| 279 | assert(max_in_overlap >= 0); |
| 280 | int max_out_overlap = -(*min_element(outDists.begin(), outDists.end())); |
| 281 | assert(max_out_overlap >= 0); |
| 282 | int min_insert_len = *min_element(insertLens.begin(), insertLens.end()); |
| 283 | int max_insert_len = *max_element(insertLens.begin(), insertLens.end()); |
| 284 | |
| 285 | float max_identity = (float)(min_insert_len + max_in_overlap + max_out_overlap) / |
| 286 | (max_insert_len + max_in_overlap + max_out_overlap); |
| 287 | if (min_insert_len <= 0 || max_identity < opt::identity) |
| 288 | return max_identity; |
| 289 | |
| 290 | vector<string> seqs(nbranches); |
| 291 | transform(first, last, seqs.begin(), boost::lambda::bind(getSequence, &g, _1)); |
| 292 | for (unsigned i = 0; i < seqs.size(); i++) { |
| 293 | // Remove the overlapping sequence. |
| 294 | int n = seqs[i].size(); |
| 295 | int l = -inDists[i], r = -outDists[i]; |
| 296 | assert(n > l + r); |
| 297 | seqs[i] = seqs[i].substr(l, n - l - r); |
| 298 | } |
| 299 | |
| 300 | unsigned matches, consensusSize; |
| 301 | tie(matches, consensusSize) = align(seqs); |
| 302 | return (float)(matches + max_in_overlap + max_out_overlap) / |
| 303 | (consensusSize + max_in_overlap + max_out_overlap); |
| 304 | } |
| 305 | |
| 306 | /** Pop the specified bubble if it is a simple bubble. |
| 307 | * @return whether the bubble is popped |
no test coverage detected