1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
|
// ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2026, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Manuel Holtgrewe <manuel.holtgrewe@fu-berlin.de>
// ==========================================================================
#ifndef SEQAN_INCLUDE_SEQAN_ALIGN_GAPS_ITERATOR_ANCHOR_H_
#define SEQAN_INCLUDE_SEQAN_ALIGN_GAPS_ITERATOR_ANCHOR_H_
namespace seqan2 {
// ============================================================================
// Forwards
// ============================================================================
// ============================================================================
// Tags, Classes, Enums
// ============================================================================
// Iterator for AnchorGaps objects.
template <typename TGaps_, typename TGapAnchors_> //Gaps<TSource_, AnchorGaps<TGapAnchors_> >
class Iter<TGaps_, GapsIterator<AnchorGaps<TGapAnchors_> > >
{
public:
typedef TGaps_ TGaps;
typedef typename Source<TGaps>::Type TSource;
typedef TGapAnchors_ TGapAnchors;
// TODO(holtgrew): Why is the following commented out?
// typedef typename Value<TGapAnchors>::Type TGapAnchor;
typedef typename Size<typename Value<TGapAnchors>::Type>::Type TGapAnchorSize_;
typedef GapAnchor<typename MakeSigned_<TGapAnchorSize_>::Type> TGapAnchor;
typedef typename MakeSigned<typename Position<TGapAnchor>::Type>::Type TGapPos;
typedef typename Iterator<TGapAnchors, Standard>::Type TAnchorIter;
TGaps * data_container; //the gaps object
TGapPos seqLength;
mutable TGapAnchor current;
mutable TGapAnchor prevAnchor;
mutable TGapAnchor nextAnchor;
mutable TGapAnchor viewBegin;
mutable TGapAnchor viewEnd;
mutable int anchorIdx;
public:
Iter()
{
data_container = NULL;
seqLength = 0;
}
/* Iter(Iter const & other_):
data_container(other_.data_container),
seqLength(other_.seqLength),
current(other_.current),
prevAnchor(other_.prevAnchor),
nextAnchor(other_.nextAnchor),
anchorIdx(other_.anchorIdx)
{
}
*/ Iter(TGaps & container_):
data_container(&container_)
{
_assignSourceLength(seqLength, container_);
_goToGapAnchorIterator(*this, data_container->data_viewCutBegin + data_container->data_cutBegin);
viewBegin = current;
viewEnd.gapPos = _unclippedLength(*data_container) + data_container->data_cutBegin - data_container->data_viewCutEnd;
viewEnd.seqPos = positionGapToSeq(*data_container, viewEnd.gapPos);
}
Iter(TGaps & container_, TGapPos clippedViewPosition):
data_container(&container_)
{
_assignSourceLength(seqLength, container_);
_goToGapAnchorIterator(*this, clippedViewPosition + data_container->data_viewCutBegin + data_container->data_cutBegin);
viewBegin.gapPos = data_container->data_viewCutBegin + data_container->data_cutBegin;
viewEnd.gapPos = _unclippedLength(*data_container) + data_container->data_cutBegin - data_container->data_viewCutEnd;
viewBegin.seqPos = positionGapToSeq(*data_container, viewBegin.gapPos);
viewEnd.seqPos = positionGapToSeq(*data_container, viewEnd.gapPos);
}
~Iter()
{
}
Iter(Iter const &) = default;
Iter & operator = (Iter const &) = default;
};
// ============================================================================
// Metafunctions
// ============================================================================
// ============================================================================
// Functions
// ============================================================================
// ----------------------------------------------------------------------------
// Function container()
// ----------------------------------------------------------------------------
// TODO(holtgrew): Can go if data_container were _container, dupe in _base.h
template <typename TGaps, typename TGapsArray>
inline TGaps &
container(Iter<TGaps, GapsIterator<AnchorGaps<TGapsArray> > > & me)
{
return *me.data_container;
}
template <typename TGaps, typename TGapsArray>
inline TGaps &
container(Iter<TGaps, GapsIterator<AnchorGaps<TGapsArray> > > const & me)
{
return *me.data_container;
}
// ----------------------------------------------------------------------------
// Function source()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline typename Source<Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const>::Type
source(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > & me)
{
return begin(source(*me.data_container), Rooted()) + me.current.seqPos;
}
template <typename TGaps, typename TGapAnchors>
inline typename Source<Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > >::Type
source(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me)
{
return begin(source(*me.data_container), Rooted()) + me.current.seqPos;
}
// ----------------------------------------------------------------------------
// Function getValue()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline typename GetValue< Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > >::Type
getValue(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > & me)
{
typedef typename Value<Iter<TGaps, GapsIterator<ArrayGaps> > >::Type TValue;
if (isGap(me)) return gapValue<TValue>();
else if (isUnknown(me)) return unknownValue<TValue>();
else return *source(me);
}
template <typename TGaps, typename TGapAnchors>
inline typename GetValue< Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const>::Type
getValue(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me)
{
typedef typename Value<Iter<TGaps, GapsIterator<ArrayGaps> > const>::Type TValue;
if (isGap(me)) return gapValue<TValue>();
else if (isUnknown(me)) return unknownValue<TValue>();
else return *source(me);
}
// ----------------------------------------------------------------------------
// Function value()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline typename Reference< Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > >::Type
value(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > & it)
{
typedef typename Reference<Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > >::Type TProxy;
return TProxy(it);
}
template <typename TGaps, typename TGapAnchors>
inline typename Reference< Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const>::Type
value(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & it)
{
typedef typename Reference<Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const>::Type TProxy;
return TProxy(it);
}
// ----------------------------------------------------------------------------
// Function isGap()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
isGap(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me)
{
return me.current.seqPos == me.nextAnchor.seqPos;
}
// ----------------------------------------------------------------------------
// Function isUnknown()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
isUnknown(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me)
{
int len;
_assignSourceLength(len, *me.data_container);
return me.current.seqPos < 0 || me.current.seqPos >= len;
}
// ----------------------------------------------------------------------------
// Function isClipped()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
isClipped(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me)
{
return me.current.gapPos == me.nextAnchor.gapPos;
}
// ----------------------------------------------------------------------------
// Function countGaps()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline typename Size<TGaps>::Type
countGaps(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me, LeftOfViewPos const & /*dir*/)
{
typedef Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > TIter;
typedef typename TIter::TGapAnchor TGapAnchor;
if (isGap(me))
{
if (me.prevAnchor.gapPos < me.viewBegin.gapPos)
return me.current.gapPos - me.viewBegin.gapPos;
return me.current.gapPos - me.prevAnchor.gapPos - (me.current.seqPos - me.prevAnchor.seqPos);
}
// In case we are at the beginning of a new anchor we need to get back the previous one.
if (me.prevAnchor.gapPos == me.current.gapPos)
{
TGapAnchor tmp;
_getAnchor(tmp, *me.data_container, me.anchorIdx - 1);
if (tmp.gapPos < me.viewBegin.gapPos)
tmp.gapPos = me.viewBegin.gapPos;
return me.current.gapPos - tmp.gapPos - (me.current.seqPos - tmp.seqPos);
}
return 0;
}
template <typename TGaps, typename TGapAnchors>
inline typename Size<TGaps>::Type
countGaps(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me, RightOfViewPos const & /*dir*/)
{
if (!isGap(me))
return 0;
if (me.nextAnchor.gapPos > me.viewEnd.gapPos)
return me.viewEnd.gapPos - me.current.gapPos;
return me.nextAnchor.gapPos - me.current.gapPos;
}
// ----------------------------------------------------------------------------
// Function countCharacters()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline typename Size<TGaps>::Type
countCharacters(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me, LeftOfViewPos const & /*dir*/)
{
if (!isGap(me))
return me.current.seqPos - me.prevAnchor.seqPos;
// In case we are at the beginning of a new anchor we need to get back the previous one.
if (me.current.seqPos - me.prevAnchor.seqPos == me.current.gapPos - me.prevAnchor.gapPos)
return me.current.seqPos - me.prevAnchor.seqPos;
return 0;
}
template <typename TGaps, typename TGapAnchors>
inline typename Size<TGaps>::Type
countCharacters(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me, RightOfViewPos const & /*dir*/)
{
if (isGap(me))
return 0;
if (me.nextAnchor.seqPos > me.viewEnd.seqPos)
return me.viewEnd.seqPos - me.current.seqPos;
return me.nextAnchor.seqPos - me.current.seqPos;
}
// ----------------------------------------------------------------------------
// Function blockLength()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline typename Size<TGaps>::Type
blockLength(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > & me)
{
if (isGap(me))
return countGaps(me);
else
return countCharacters(me);
}
// ----------------------------------------------------------------------------
// Function atBegin()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
atBegin(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > & me)
{
// return me.current.seqPos == 0 && me.current.gapPos == 0;
return me.current <= me.viewBegin;
}
template <typename TGaps, typename TGapAnchors>
inline bool
atBegin(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me)
{
// return me.current.seqPos == 0 && me.current.gapPos == 0;
return me.current <= me.viewBegin;
}
// ----------------------------------------------------------------------------
// Function atEnd()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
atEnd(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > & me)
{
// return me.current == me.nextAnchor;
return me.current >= me.viewEnd;
}
template <typename TGaps, typename TGapAnchors>
inline bool
atEnd(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me)
{
// return me.current == me.nextAnchor;
return me.current >= me.viewEnd;
}
// ----------------------------------------------------------------------------
// Function operator==()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
operator == (
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & left,
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & right)
{
return left.current == right.current;
}
// ----------------------------------------------------------------------------
// Function operator!=()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
operator != (
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & left,
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & right)
{
return left.current != right.current;
}
// ----------------------------------------------------------------------------
// Function operator<()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
operator < (
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & left,
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & right)
{
return left.current < right.current;
}
// ----------------------------------------------------------------------------
// Function operator<=()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
operator<=(
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & left,
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & right)
{
return !(left.current > right.current);
}
// ----------------------------------------------------------------------------
// Function operator>()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
operator > (
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & left,
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & right)
{
return left.current > right.current;
}
// ----------------------------------------------------------------------------
// Function operator>=()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline bool
operator>=(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & lhs,
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & rhs)
{
return !(lhs < rhs);
}
// ----------------------------------------------------------------------------
// Function insertGaps()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors, typename TCount>
inline void
insertGaps(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & me,
TCount size)
{
TGapAnchors & anchors = _dataAnchors(*me.data_container);
typedef typename Iterator<TGapAnchors, Standard>::Type TIter;
if (size <= 0) return;
// insert a new anchor
if (!isGap(me))
{
if (me.prevAnchor.gapPos == me.current.gapPos)
{
me.nextAnchor = me.prevAnchor;
_getAnchor(me.prevAnchor, *me.data_container, --me.anchorIdx);
}
else
{
me.nextAnchor = me.current;
insertValue(anchors, me.anchorIdx, me.nextAnchor, Generous());
}
}
else
{
if (me.anchorIdx >= (int)length(anchors))
{
// add gap after the sequence and in (or at the right boundary of) the view
if (me.current.gapPos <= me.viewEnd.gapPos)
{
container(me).data_cutEnd -= size;
me.viewEnd.gapPos += size;
}
return;
}
if (empty(anchors))
appendValue(anchors, me.nextAnchor, Generous());
}
if (me.anchorIdx < (int)length(anchors))
{
if (me.anchorIdx >= 0)
{
me.nextAnchor.gapPos += size;
TIter it = begin(anchors, Standard());
TIter itEnd = end(anchors, Standard());
if (me.anchorIdx >= 0)
it += me.anchorIdx;
for (; it != itEnd; ++it)
(*it).gapPos += size;
}
else
// add gap before the sequence and in (or at the left boundary of) the view
if (me.current.gapPos >= me.viewBegin.gapPos)
{
container(me).data_cutBegin -= size;
me.viewBegin.gapPos -= size;
me.current.gapPos -= size;
return;
}
}
if (me.current.gapPos <= me.viewEnd.gapPos)
me.viewEnd.gapPos += size;
/*
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > it2 = begin(*me.data_container) + me.current.gapPos;
if (me.current != it2.current || me.prevAnchor != it2.prevAnchor || me.nextAnchor != it2.nextAnchor || me.anchorIdx != it2.anchorIdx)
std::cout<<"*";
*/
}
// ----------------------------------------------------------------------------
// Function removeGaps()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors, typename TCount>
inline typename Size<TGaps>::Type
removeGaps(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & it,
TCount size_)
{
TGapAnchors & anchors = _dataAnchors(*it.data_container);
typedef typename Iterator<TGapAnchors, Standard>::Type TAnchorsIter;
typedef Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > TIter;
typedef typename TIter::TGapAnchor TGapAnchor;
// typedef typename Value<TGapAnchors>::Type TGapAnchor;
typedef typename Position<TGapAnchor>::Type TPos;
if (size_ <= 0 || !isGap(it))
return 0;
TPos size = size_;
// static_cast<TGapAnchor>(Nothing());
// static_cast<TPos>(Nothing());
if (it.current.gapPos + size > it.nextAnchor.gapPos)
size = it.nextAnchor.gapPos - it.current.gapPos;
if (it.prevAnchor.gapPos + it.current.seqPos == it.current.gapPos + it.prevAnchor.seqPos &&
it.current.gapPos + size == it.nextAnchor.gapPos)
{
// remove the gap
if (it.anchorIdx < (int)length(anchors))
erase(anchors, it.anchorIdx);
_getAnchor(it.nextAnchor, *it.data_container, it.anchorIdx);
}
// shift anchors
if (it.anchorIdx < (int)length(anchors))
{
if (it.anchorIdx >= 0)
{
it.nextAnchor.gapPos -= size;
TAnchorsIter itA = begin(anchors, Standard());
TAnchorsIter itAEnd = end(anchors, Standard());
if (it.anchorIdx >= 0)
itA += it.anchorIdx;
for (; itA != itAEnd; ++itA)
(*itA).gapPos -= size;
}
else
// remove gap before the sequence and in (or at the left boundary of) the view
if (it.current.gapPos >= it.viewBegin.gapPos)
{
// assure that we don't remove more gaps than available
if (size > it.nextAnchor.gapPos - it.current.gapPos)
size = it.nextAnchor.gapPos - it.current.gapPos;
container(it).data_cutBegin += size;
it.viewBegin.gapPos += size;
it.current.gapPos += size;
return size;
}
}
else
{
if (it.current.gapPos <= it.viewEnd.gapPos)
container(it).data_cutEnd += size;
}
if (it.current.gapPos <= it.viewEnd.gapPos)
it.viewEnd.gapPos -= size;
return size;
/*
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > it2 = begin(*me.data_container) + me.current.gapPos;
if (me.current != it2.current || me.prevAnchor != it2.prevAnchor || me.nextAnchor != it2.nextAnchor || me.anchorIdx != it2.anchorIdx)
std::cout<<"*";
*/
}
// ----------------------------------------------------------------------------
// Helper Function _goNextGapAnchorIterator()
// ----------------------------------------------------------------------------
template <typename T>
inline void
_goNextGapAnchorIterator(T & me)
{
if (me.current.gapPos < me.nextAnchor.gapPos)
{
++me.current.gapPos;
if (me.current.seqPos < me.nextAnchor.seqPos)
++me.current.seqPos;
}
while (me.current.gapPos == me.nextAnchor.gapPos)
{
me.current = me.prevAnchor = me.nextAnchor;
_getAnchor(me.nextAnchor, *me.data_container, ++me.anchorIdx + 1);
}
}
// ----------------------------------------------------------------------------
// Helper Function _goPreviousGapAnchorIterator()
// ----------------------------------------------------------------------------
template <typename T>
inline void
_goPreviousGapAnchorIterator(T & me)
{
while (me.current.gapPos == me.prevAnchor.gapPos)
{
me.current = me.nextAnchor = me.prevAnchor;
_getAnchor(me.prevAnchor, *me.data_container, --me.anchorIdx);
}
--me.current.gapPos;
if (me.nextAnchor.seqPos - me.prevAnchor.seqPos > me.current.gapPos - me.prevAnchor.gapPos)
me.current.seqPos = me.prevAnchor.seqPos + (me.current.gapPos - me.prevAnchor.gapPos);
else
me.current.seqPos = me.nextAnchor.seqPos;
}
// ----------------------------------------------------------------------------
// Helper Function _goToGapAnchorIterator()
// ----------------------------------------------------------------------------
template <typename T, typename TPos>
inline void
_goToGapAnchorIterator(T & me, TPos pos)
{
typedef typename T::TGapAnchors TGapAnchors;
typedef typename Value<TGapAnchors>::Type TGapAnchor;
typedef typename Position<TGapAnchor>::Type TAnchorPos;
typedef typename MakeSigned<TAnchorPos>::Type TAnchorSPos;
if (isNegative(pos))
me.anchorIdx = -1;
else
{
TGapAnchors const & anchors = _dataAnchors(*me.data_container);
if (!empty(anchors))
{
me.anchorIdx = upperBoundGapAnchor(anchors, pos, SortGapPos()) - begin(anchors, Standard());
if (me.anchorIdx < (int)length(anchors))
if (anchors[me.anchorIdx].gapPos == (TAnchorPos)pos && anchors[me.anchorIdx].seqPos != (TAnchorPos)me.seqLength)
++me.anchorIdx;
}
else
{
me.anchorIdx = ((TAnchorSPos)pos < me.seqLength)? 0: 1;
}
}
_getAnchor(me.prevAnchor, *me.data_container, me.anchorIdx);
_getAnchor(me.nextAnchor, *me.data_container, me.anchorIdx + 1);
me.current.gapPos = pos;
if (me.nextAnchor.seqPos - me.prevAnchor.seqPos > (int)pos - me.prevAnchor.gapPos)
me.current.seqPos = me.prevAnchor.seqPos + ((int)pos - me.prevAnchor.gapPos);
else
me.current.seqPos = me.nextAnchor.seqPos;
}
// ----------------------------------------------------------------------------
// Function goNext()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline void
goNext(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > & me)
{
_goNextGapAnchorIterator(me);
}
// ----------------------------------------------------------------------------
// Function goPrevious()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline void
goPrevious(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > & me)
{
_goPreviousGapAnchorIterator(me);
}
// ----------------------------------------------------------------------------
// Function goFurther()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors, typename TSize>
inline void
goFurther(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > & me, TSize steps)
{
_goToGapAnchorIterator(me, me.current.gapPos + steps);
}
// ----------------------------------------------------------------------------
// Function position()
// ----------------------------------------------------------------------------
// Returns clipped view position of gaps iterator.
template <typename TGaps, typename TGapAnchors>
inline typename Position<Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > >::Type
position(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & it)
{
return it.current.gapPos - it.viewBegin.gapPos;
}
// ----------------------------------------------------------------------------
// Function difference()
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline typename Difference<Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > >::Type
difference(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & lhs,
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & rhs)
{
return lhs.current.gapPos - rhs.current.gapPos;
}
// ----------------------------------------------------------------------------
// Function operator-() [difference]
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors>
inline typename Difference<Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > >::Type
operator-(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & lhs,
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & rhs)
{
return difference(lhs, rhs);
}
// ----------------------------------------------------------------------------
// Function operator-() [copy movement]
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors, typename TDifference>
inline Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > >
operator-(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & lhs, TDifference d)
{
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > result = lhs;
result -= d;
return result;
}
// ----------------------------------------------------------------------------
// Function operator+() [copy movement]
// ----------------------------------------------------------------------------
template <typename TGaps, typename TGapAnchors, typename TDifference>
inline Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > >
operator+(Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > const & lhs, TDifference d)
{
Iter<TGaps, GapsIterator<AnchorGaps<TGapAnchors> > > result = lhs;
result += d;
return result;
}
} // namespace seqan2
#endif // #ifndef SEQAN_INCLUDE_SEQAN_ALIGN_GAPS_ITERATOR_ANCHOR_H_
|