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_);
133 return cigar_type()==2;
139 size_t qpos(
void)
const {
return qpos_; }
141 boost::shared_ptr<BamRead> bam_;
147 uint8_t cigar_type(
void)
const {
return bam_cigar_type(
cigar_op()); }
169 Pileup(Iterator first, Iterator last);
178 const_iterator
begin(
void)
const;
184 const_iterator
end(
void)
const;
189 bool good(
void)
const {
return !(bam_ == bam_end_ && data_.empty()); }
206 int32_t
tid(
void)
const {
return tid_; }
211 int32_t
pos(
void)
const {
return pos_; }
219 typedef typename std::list<Entry>::iterator iterator;
225 std::list<Entry> data_;
235 template<
typename Iterator>
243 template<
typename Iterator>
245 : bam_(first), bam_end_(last), pos_(0), tid_(0), skip_ref_(0)
247 BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>));
248 BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Iterator>));
249 using boost::Convertible;
250 typedef typename boost::iterator_value<Iterator>::type value_type;
251 BOOST_CONCEPT_ASSERT((Convertible<value_type, BamRead>));
256 template<
typename Iterator>
259 return data_.begin();
263 template<
typename Iterator>
270 template<
typename Iterator>
273 if (!data_.empty()) {
276 for (iterator it = data_.begin(); it!=data_.end(); ++it) {
277 if (it->cigar_type() == 1) {
287 typename std::list<Entry>::iterator read = data_.begin();
288 while (read != data_.end()) {
291 if (read->bam().end() <= pos_) {
296 if (read->cigar_op() == BAM_CINS) {
297 skip_ref_ =
std::max(skip_ref_, read->cigar_oplen());
304 for (iterator iter=data_.begin(); iter!=data_.end(); ++iter)
305 iter->skip_ = skip_ref_;
314 tid_ = bam_->core().tid;
315 pos_ = bam_->core().pos;
319 while (bam_!=bam_end_ && bam_->core().tid==tid_ && bam_->pos()<=pos_) {
321 if (!(bam_->core().flag & BAM_FUNMAP)) {
322 data_.push_back(
Entry(*bam_));
329 template<
typename Iterator>
336 template<
typename Iterator>
338 : bam_(new
BamRead(b)), qpos_(0), cigar_(bam_->cigar()), skip_(0)
340 YAT_ASSERT(cigar_.
base() == bam_->cigar());
341 if (bam_->core().n_cigar==0)
344 while (qpos_ < bam_->sequence_length() && cigar_type() != 3) {
346 YAT_ASSERT(cigar_type()!=2);
347 if (cigar_type() == 1)
354 template<
typename Iterator>
357 YAT_ASSERT(cigar_.
base() >= bam_->cigar());
358 if (cigar_type() & 1)
361 YAT_ASSERT(cigar_.
base() >= bam_->cigar());
365 template<
typename Iterator>
369 if (cigar_type() & 1)
370 return bam_->sequence(qpos_);
375 return bam_->sequence(qpos_);
The Department of Theoretical Physics namespace as we define it.
std::list< Entry >::const_iterator const_iterator
Definition: Pileup.h:156
void increment(void)
step to next position.
Definition: Pileup.h:271
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:236
T max(const T &a, const T &b, const T &c)
Definition: stl_utility.h:697
bool is_del(void) const
Definition: Pileup.h:131
int32_t tid(void) const
Definition: Pileup.h:206
BASE base(void) const
Definition: CigarIterator.h:119
size_t qpos(void) const
Definition: Pileup.h:139
bool good(void) const
Definition: Pileup.h:189
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:330
uint8_t sequence(void) const
Definition: Pileup.h:366
int32_t pos(void) const
Definition: Pileup.h:211
const_iterator begin(void) const
Definition: Pileup.h:257
void increment(void)
Definition: Pileup.h:355
const BamRead & bam(void) const
Definition: Pileup.h:81
const_iterator end(void) const
Definition: Pileup.h:264
unsigned short qual(void) const
Definition: Pileup.h:107
Pileup(void)
Definition: Pileup.h:161