source: trunk/yat/omic/CigarIterator.cc @ 3332

Last change on this file since 3332 was 3332, checked in by Peter, 7 years ago

In Pileup store reads in a std::list (rather than std::deque) to allow
easy erase as soon as we are one passed last base. Erasing reads
immediately implies we don't need a filter_iterator, but can use
list::const_iterator directly.

Fix a bug in Pileup::Entry, which held a BamRead? and CigarIterator? and
the latter is essentially a uint32_t* that is returned from
BamRead::cigar(). This caused problems in copy/assignment since the
BamRead? was copied by value and the CigarIterator? didn't point to
BamRead? in this class but to BamRead? in rhs. The problem was solved by
replacing the BamRead? by a shared_ptr<BamRead?>.

refs #806

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1// $Id: CigarIterator.cc 3332 2014-10-23 11:18:15Z peter $
2
3/*
4  Copyright (C) 2014 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <config.h>
23
24#include "CigarIterator.h"
25
26#include "yat/utility/Cigar.h"
27
28#include <cassert>
29
30namespace theplu {
31namespace yat {
32namespace omic {
33
34  CigarIterator::CigarIterator(void)
35    : base_(NULL) {}
36
37
38  CigarIterator::CigarIterator(const uint32_t* p, size_t x)
39    : base_(p), index_(x) {}
40
41
42  const uint32_t* CigarIterator::base(void) const
43  {
44    return base_;
45  }
46
47
48  void CigarIterator::decrement(void)
49  {
50    if (index_)
51      --index_;
52    else {
53      --base_;
54      index_ = bam_cigar_oplen(*base_)-1;
55    }
56  }
57
58
59  CigarIterator::reference CigarIterator::dereference(void) const
60  {
61    return bam_cigar_op(*base_);
62  }
63
64
65  bool CigarIterator::equal(const CigarIterator& other) const
66  {
67    return base_==other.base_ && index_==other.index_;
68  }
69
70
71  void CigarIterator::increment(void)
72  {
73    if (++index_ == bam_cigar_oplen(*base_)) {
74      index_=0;
75      ++base_;
76    }
77  }
78
79}}}
Note: See TracBrowser for help on using the repository browser.