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
|
#ifndef __ERROR_CORRECT_READS_HPP__
#define __ERROR_CORRECT_READS_HPP__
#include <config.h>
#include <jellyfish/err.hpp>
#include <jellyfish/mapped_file.hpp>
#include <jellyfish/thread_exec.hpp>
#include <iostream>
#include <fstream>
#include <assert.h>
#include <misc.hpp>
#include <src/kmer.hpp>
#include <src/err_log.hpp>
// A forward moving pointer.
template<typename T>
class forward_ptr {
T *_p;
public:
forward_ptr(T *p) : _p(p) { }
forward_ptr operator++(int) {
return forward_ptr(_p++);
}
forward_ptr &operator++() {
++_p;
return *this;
}
forward_ptr operator--(int) {
return forward_ptr(_p--);
}
forward_ptr &operator--() {
--_p;
return *this;
}
forward_ptr operator+(int x) const {
return forward_ptr(_p + x);
}
forward_ptr operator-(int x) const {
return forward_ptr(_p - x);
}
T &operator*() { return *_p; }
bool operator<(T *e) const { return _p < e; }
bool operator<(const forward_ptr<T> &e) const { return _p < e._p; }
bool operator>=(T *e) const { return _p >= e; }
bool operator>=(const forward_ptr<T> &e) const { return _p >= e._p; }
ptrdiff_t operator-(T *s) const { return _p - s; }
T *ptr() const { return _p; }
};
// A backward moving pointer. suffix++ behaves like suffix--. < behave
// likes >. Etc.
template<typename T>
class backward_ptr {
T *_p;
public:
backward_ptr(T *p) : _p(p) {}
backward_ptr operator++(int) {
return backward_ptr(_p--);
}
backward_ptr &operator++() {
--_p;
return *this;
}
backward_ptr operator--(int) {
return backward_ptr(_p++);
}
backward_ptr &operator--() {
++_p;
return *this;
}
backward_ptr operator+(int x) const {
return backward_ptr(_p - x);
}
backward_ptr operator-(int x) const {
return backward_ptr(_p + x);
}
T &operator*() const { return *_p; }
bool operator<(T *e) const { return _p > e; }
bool operator<(const backward_ptr<T> &e) const { return _p > e._p; }
bool operator>=(T *e) const { return _p <= e; }
bool operator>=(const backward_ptr<T> &e) const { return _p <= e._p; }
ptrdiff_t operator-(T *s) const { return _p - s; }
T *ptr() const { return _p; }
};
class forward_counter {
int _c;
public:
forward_counter() {}
forward_counter(int c) : _c(c) {}
forward_counter &operator++() {
++_c;
return *this;
}
forward_counter &operator--() {
--_c;
return *this;
}
forward_counter operator+(const int x) const {
return forward_counter(_c + x);
}
forward_counter operator-(const int x) const {
return forward_counter(_c - x);
}
int operator-(const forward_counter &c) const {
return _c - c._c;
}
bool operator>(const forward_counter &c) const {
return _c > c._c;
}
bool operator>=(const forward_counter &c) const {
return _c > c._c || _c == c._c;
}
int operator*() const { return _c; }
friend std::ostream &operator<<(std::ostream &os, const forward_counter &c);
};
class backward_counter {
int _c;
public:
backward_counter() {}
backward_counter(int c) : _c(c) {}
backward_counter &operator++() {
--_c;
return *this;
}
backward_counter &operator--() {
++_c;
return *this;
}
bool operator>(const backward_counter &c) const {
return _c < c._c;
}
bool operator>=(const backward_counter &c) const {
return _c < c._c || _c == c._c;
}
backward_counter operator+(const int x) const {
return backward_counter(_c - x);
}
backward_counter operator-(const int x) const {
return backward_counter(_c + x);
}
int operator-(const backward_counter &c) const {
return c._c - _c;
}
int operator*() const { return _c; }
friend std::ostream &operator<<(std::ostream &os, const backward_counter &c);
};
inline std::ostream &operator<<(std::ostream &os, const forward_counter &c) {
return os << c._c;
}
inline std::ostream &operator<<(std::ostream &os, const backward_counter &c) {
return os << c._c;
}
class forward_log : public err_log<forward_counter> {
public:
forward_log(unsigned int window, unsigned int error) :
err_log<forward_counter>(window, error, "3_trunc") { }
};
class backward_log : public err_log<backward_counter> {
public:
backward_log(unsigned int window, unsigned int error) :
err_log<backward_counter>(window, error, "5_trunc") { }
bool truncation(backward_counter pos) {
return err_log<backward_counter>::truncation(pos - 1);
}
};
#endif
|