1 #ifndef theplu_yat_omic_pileup
2 #define theplu_yat_omic_pileup
27 #include "yat/utility/CigarIterator.h"
28 #include "yat/utility/yat_assert.h"
30 #include <boost/iterator/iterator_traits.hpp>
31 #include <boost/iterator/iterator_concepts.hpp>
32 #include <boost/concept/assert.hpp>
33 #include <boost/shared_ptr.hpp>
56 template<
typename Iterator>
83 YAT_ASSERT(bam_.get());
90 uint8_t
cigar_op(
void)
const {
return *cigar_; }
98 YAT_ASSERT(bam_.get());
99 YAT_ASSERT(cigar_.
base() >= bam_->cigar());
100 return bam_cigar_oplen(*cigar_.
base());
107 unsigned short qual(
void)
const
109 YAT_ASSERT(bam_.get());
110 YAT_ASSERT(qpos_ < bam_->sequence_length());
111 return bam_->qual(qpos_);
130 return cigar_type()==2;
136 size_t qpos(
void)
const {
return qpos_; }
138 boost::shared_ptr<BamRead> bam_;
144 uint8_t cigar_type(
void)
const {
return bam_cigar_type(
cigar_op()); }
166 Pileup(Iterator first, Iterator last);
186 bool good(
void)
const {
return !(bam_ == bam_end_ && data_.empty()); }
203 int32_t
tid(
void)
const {
return tid_; }
208 int32_t
pos(
void)
const {
return pos_; }
216 typedef typename std::list<Entry>::iterator iterator;
222 std::list<Entry> data_;
232 template<
typename Iterator>
240 template<
typename Iterator>
242 : bam_(first), bam_end_(last), pos_(0), tid_(0), skip_ref_(0)
244 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>));
245 BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Iterator>));
246 using boost::Convertible;
247 typedef typename boost::iterator_value<Iterator>::type value_type;
248 BOOST_CONCEPT_ASSERT((Convertible<value_type, BamRead>));
253 template<
typename Iterator>
256 return data_.begin();
260 template<
typename Iterator>
267 template<
typename Iterator>
270 if (!data_.empty()) {
273 for (iterator it = data_.begin(); it!=data_.end(); ++it) {
274 if (it->cigar_type() == 1) {
284 typename std::list<Entry>::iterator read = data_.begin();
285 while (read != data_.end()) {
288 if (read->bam().end() <= pos_) {
293 if (read->cigar_op() == BAM_CINS) {
294 skip_ref_ =
std::max(skip_ref_, read->cigar_oplen());
301 for (iterator iter=data_.begin(); iter!=data_.end(); ++iter)
302 iter->skip_ = skip_ref_;
311 tid_ = bam_->core().tid;
312 pos_ = bam_->core().pos;
316 while (bam_!=bam_end_ && bam_->core().tid==tid_ && bam_->pos()<=pos_) {
318 if (!(bam_->core().flag & BAM_FUNMAP)) {
319 data_.push_back(
Entry(*bam_));
326 template<
typename Iterator>
333 template<
typename Iterator>
335 : bam_(new
BamRead(b)), qpos_(0), cigar_(bam_->cigar()), skip_(0)
337 YAT_ASSERT(cigar_.
base() == bam_->cigar());
338 if (bam_->core().n_cigar==0)
341 while (qpos_ < bam_->sequence_length() && cigar_type() != 3) {
343 YAT_ASSERT(cigar_type()!=2);
344 if (cigar_type() == 1)
351 template<
typename Iterator>
354 YAT_ASSERT(cigar_.base() >= bam_->cigar());
355 if (cigar_type() & 1)
358 YAT_ASSERT(cigar_.base() >= bam_->cigar());
362 template<
typename Iterator>
366 if (cigar_type() & 1)
367 return bam_->sequence(qpos_);
370 if (cigar_op()!=BAM_CINS)
372 return bam_->sequence(qpos_);
std::list< Entry >::const_iterator const_iterator
Definition: Pileup.h:153
void increment(void)
step to next position.
Definition: Pileup.h:268
Class holding a bam query.
Definition: BamRead.h:53
uint8_t cigar_op(void) const
Definition: Pileup.h:90
Pileup< Iterator > make_pileup(Iterator first, Iterator last)
Definition: Pileup.h:233
T max(const T &a, const T &b, const T &c)
Definition: stl_utility.h:697
bool is_del(void) const
Definition: Pileup.h:128
int32_t tid(void) const
Definition: Pileup.h:203
BASE base(void) const
Definition: CigarIterator.h:119
size_t qpos(void) const
Definition: Pileup.h:136
bool good(void) const
Definition: Pileup.h:186
Entry(void)
default constructor
Definition: Pileup.h:70
uint32_t cigar_oplen(void) const
Definition: Pileup.h:96
bool skip_ref(void) const
Definition: Pileup.h:327
uint8_t sequence(void) const
Definition: Pileup.h:363
int32_t pos(void) const
Definition: Pileup.h:208
const_iterator begin(void) const
Definition: Pileup.h:254
void increment(void)
Definition: Pileup.h:352
const BamRead & bam(void) const
Definition: Pileup.h:81
const_iterator end(void) const
Definition: Pileup.h:261
unsigned short qual(void) const
Definition: Pileup.h:107
Pileup(void)
Definition: Pileup.h:158