/usr/include/jellyfish/mer_qual_iterator.hpp is in libjellyfish-2.0-dev 2.2.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /* This file is part of Jellyfish.
Jellyfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Jellyfish is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Jellyfish. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MER_QUAL_ITERATOR_HPP__
#define __MER_QUAL_ITERATOR_HPP__
#include <iterator>
#include <jellyfish/mer_dna.hpp>
namespace jellyfish {
template<typename SequencePool, typename MerType>
class mer_qual_iterator : public std::iterator<std::input_iterator_tag, MerType> {
typename SequencePool::job* job_;
std::string::const_iterator cseq_, eseq_;
std::string::const_iterator cqual_, equal_;
MerType m_; // mer
MerType rcm_; // reverse complement mer
unsigned int filled_;
const char min_qual_;
const bool canonical_;
size_t index_;
public:
typedef MerType mer_type;
typedef SequencePool sequence_parser_type;
mer_qual_iterator(SequencePool& seq, char min_qual, bool canonical = false) :
job_(new typename SequencePool::job(seq)),
filled_(0), min_qual_(min_qual), canonical_(canonical), index_(0)
{
if(job_->is_empty()) {
delete job_;
job_ = 0;
} else {
init_from_job();
this->operator++();
}
}
mer_qual_iterator() : job_(0), filled_(0), canonical_(false), index_(0) { }
// mer_iterator(const mer_iterator& rhs) : job_(rhs.job_), cseq_(rhs.cseq_), m_(rhs.m_), filled_(rhs.filled_) { }
~mer_qual_iterator() {
delete job_;
}
bool operator==(const mer_qual_iterator& rhs) const { return job_ == rhs.job_; }
bool operator!=(const mer_qual_iterator& rhs) const { return job_ != rhs.job_; }
operator void*() const { return (void*)job_; }
const mer_type& operator*() const { return !canonical_ || m_ < rcm_ ? m_ : rcm_; }
const mer_type* operator->() const { return &this->operator*(); }
mer_qual_iterator& operator++() {
while(true) {
while(cseq_ == eseq_) {
++index_;
while(index_ >= (*job_)->nb_filled) {
index_ = 0;
job_->next();
if(job_->is_empty()) {
delete job_;
job_ = 0;
return *this;
}
}
init_from_job();
filled_ = 0;
}
do {
const int code = m_.code(*cseq_++);
const char qual = cqual_ < equal_ ? *cqual_++ : std::numeric_limits<char>::max();
if(code >= 0 && qual >= min_qual_) {
m_.shift_left(code);
if(canonical_)
rcm_.shift_right(rcm_.complement(code));
filled_ = std::min(filled_ + 1, mer_dna::k());
} else
filled_ = 0;
} while(filled_ < m_.k() && cseq_ < eseq_);
if(filled_ >= m_.k())
break;
}
return *this;
}
mer_qual_iterator operator++(int) {
mer_qual_iterator res(*this);
++*this;
return res;
}
private:
void init_from_job() {
std::string& seq = (*job_)->data[index_].seq;
cseq_ = seq.begin();
eseq_ = seq.end();
std::string& quals = (*job_)->data[index_].qual;
cqual_ = quals.begin();
equal_ = quals.end();
}
};
} // namespace jellyfish {
#endif /* __MER_QUAL_ITERATOR_HPP__ */
|