16
16
#ifndef SQ_GROUPDATA_H
17
17
#define SQ_GROUPDATA_H
19
#ifndef _GLIBCXX_CSTDDEF
20
20
# include <cstddef>
22
#ifndef _GLIBCXX_IOSTREAM
23
23
# include <iostream>
29
25
#ifndef ARB_ASSERT_H
30
26
# include <arb_assert.h>
29
#include <cxxforward.h>
32
32
#define seq_assert(bed) arb_assert(bed)
34
struct consensus_result {
39
39
class SQ_GroupData {
42
49
virtual ~SQ_GroupData();
43
virtual SQ_GroupData& operator =(const SQ_GroupData& other) = 0;
50
virtual SQ_GroupData& operator = (const SQ_GroupData& other) = 0;
44
51
virtual SQ_GroupData *clone() const = 0;
46
53
void SQ_set_avg_bases(int bases) {
47
54
avg_bases += bases;
49
56
int SQ_get_avg_bases() const {
50
return (avg_bases/nr_sequences );
57
return (avg_bases/nr_sequences);
52
59
void SQ_set_avg_gc(double gc) {
55
62
double SQ_get_avg_gc() const {
56
return (gc_prop/nr_sequences );
63
return (gc_prop/nr_sequences);
58
65
void SQ_count_sequences() {
65
72
return initialized;
68
virtual void SQ_init_consensus(int size) = 0;
69
virtual int SQ_print_on_screen() = 0;
75
virtual void SQ_init_consensus(int size) = 0;
76
virtual int SQ_print_on_screen() = 0;
70
77
virtual consensus_result SQ_calc_consensus(const char *sequence) const = 0;
71
virtual void SQ_add_sequence(const char *sequence) = 0;
72
virtual void SQ_add(const SQ_GroupData& other) = 0;
78
virtual void SQ_add_sequence(const char *sequence) = 0;
79
virtual void SQ_add(const SQ_GroupData& other) = 0;
74
81
int getSize() const {
86
87
template <int I> class Int {
97
98
memset(i, 0, I*sizeof(int));
100
Int& operator +=(const Int& other) {
101
Int& operator += (const Int& other) {
101
102
const int *otheri = other.i;
102
103
for (int j = 0; j<I; ++j) {
103
104
i[j] += otheri[j];
114
115
template <int I> class SQ_GroupData_Impl : public SQ_GroupData {
115
116
SQ_GroupData_Impl(const SQ_GroupData_Impl& other);
117
SQ_GroupData_Impl& operator = (const SQ_GroupData_Impl& Other);
118
120
SQ_GroupData_Impl() {
122
virtual ~SQ_GroupData_Impl();
124
SQ_GroupData_Impl& operator=(const SQ_GroupData_Impl& other) {
125
seq_assert ( other.size>0 && other.initialized );
127
SQ_init_consensus(other.size);seq_assert ( size==other.size );
123
virtual ~SQ_GroupData_Impl() OVERRIDE;
125
SQ_GroupData_Impl& operator = (const SQ_GroupData& Other) OVERRIDE {
126
const SQ_GroupData_Impl& other = dynamic_cast<const SQ_GroupData_Impl&>(Other);
127
seq_assert(other.size>0 && other.initialized);
129
if (!initialized) SQ_init_consensus(other.size);
130
seq_assert(size==other.size);
128
132
avg_bases = other.avg_bases;
129
gc_prop = other.gc_prop;
133
gc_prop = other.gc_prop;
130
135
for (int s=0; s<size; ++s) {
131
136
consensus[s] = other.consensus[s];
137
void SQ_init_consensus(int size);
138
int SQ_print_on_screen();
139
void SQ_add_column(int col);
140
void SQ_add(const SQ_GroupData& other); // add's other to this
142
void SQ_init_consensus(int size) OVERRIDE;
143
int SQ_print_on_screen() OVERRIDE;
144
void SQ_add(const SQ_GroupData& other) OVERRIDE; // add's other to this
143
147
Int<I> *consensus;
146
150
class SQ_GroupData_RNA : public SQ_GroupData_Impl<6> {
151
typedef SQ_GroupData_Impl<6> Base;
147
152
SQ_GroupData_RNA(const SQ_GroupData_RNA& other); // copying not allowed
149
154
SQ_GroupData_RNA() {
152
SQ_GroupData_RNA *clone() const {
157
SQ_GroupData_RNA *clone() const OVERRIDE {
153
158
return new SQ_GroupData_RNA;
155
SQ_GroupData_RNA& operator=(const SQ_GroupData& other) {
156
return static_cast<SQ_GroupData_RNA&> (SQ_GroupData_Impl<6>::operator=
157
( static_cast<const SQ_GroupData_Impl<6>&> ( other ) ) );
160
SQ_GroupData_RNA& operator = (const SQ_GroupData& other) OVERRIDE {
161
Base::operator=(other);
160
consensus_result SQ_calc_consensus ( const char *sequence ) const;
161
void SQ_add_sequence ( const char *sequence );
165
consensus_result SQ_calc_consensus (const char *sequence) const OVERRIDE;
166
void SQ_add_sequence (const char *sequence) OVERRIDE;
163
168
static int class_counter;
166
171
class SQ_GroupData_PRO : public SQ_GroupData_Impl<20> {
172
typedef SQ_GroupData_Impl<20> Base;
167
173
SQ_GroupData_PRO(const SQ_GroupData_PRO& other); // copying not allowed
169
175
SQ_GroupData_PRO() {
172
SQ_GroupData_PRO *clone() const {
178
SQ_GroupData_PRO *clone() const OVERRIDE {
173
179
return new SQ_GroupData_PRO;
175
SQ_GroupData_PRO& operator=(const SQ_GroupData& other) {
176
return static_cast<SQ_GroupData_PRO&> (SQ_GroupData_Impl<20>::operator=
177
( static_cast<const SQ_GroupData_Impl<20>&> ( other ) ) );
181
SQ_GroupData_PRO& operator = (const SQ_GroupData& other) OVERRIDE {
182
Base::operator=(other);
180
consensus_result SQ_calc_consensus ( const char *sequence ) const;
181
void SQ_add_sequence ( const char *sequence );
186
consensus_result SQ_calc_consensus (const char *sequence) const OVERRIDE;
187
void SQ_add_sequence (const char *sequence) OVERRIDE;
184
190
// -----------------------
185
191
// implementation
186
// -----------------------
189
193
template <int I> SQ_GroupData_Impl<I>::~SQ_GroupData_Impl() {
190
194
delete [] consensus;
193
197
template <int I> void SQ_GroupData_Impl<I>::SQ_init_consensus(int size_) {
194
seq_assert ( !initialized );
198
seq_assert (!initialized);
197
201
consensus = new Int<I>[size];
201
205
template <int I> void SQ_GroupData_Impl<I>::SQ_add(
202
206
const SQ_GroupData& other_base) {
203
207
const SQ_GroupData_Impl<I>& other =
204
dynamic_cast<const SQ_GroupData_Impl<I>&> (other_base );
205
seq_assert ( size==other.size );
208
dynamic_cast<const SQ_GroupData_Impl<I>&> (other_base);
209
seq_assert (size==other.size);
206
210
for (int i = 0; i<size; ++i) {
207
211
consensus[i] += other.consensus[i];