source: tags/ms_r16q3/GENOM_IMPORT/SequenceBuffer.h

Last change on this file was 8251, checked in by westram, 12 years ago
  • removed using decls from headers
File size: 2.8 KB
Line 
1// ================================================================ //
2//                                                                  //
3//   File      : SequenceBuffer.h                                   //
4//   Purpose   :                                                    //
5//                                                                  //
6//   Coded by Ralf Westram (coder@reallysoft.de) in December 2006   //
7//   Institute of Microbiology (Technical University Munich)        //
8//   http://www.arb-home.de/                                        //
9//                                                                  //
10// ================================================================ //
11#ifndef SEQUENCEBUFFER_H
12#define SEQUENCEBUFFER_H
13
14#ifndef TYPES_H
15#include "types.h"
16#endif
17#ifndef SMARTPTR_H
18#include <smartptr.h>
19#endif
20
21class CharCounter {
22    size_t count[256];
23    size_t all;
24
25public:
26    CharCounter() { clear(); }
27
28    size_t getCount(unsigned char idx) const { return count[idx]; }
29    size_t getCount() const { return all; }
30    void countChars(const std::string& line);
31
32    void clear();
33};
34
35
36enum Base { BC_A, BC_C, BC_G, BC_T, BC_OTHER, BC_ALL, BC_COUNTERS };
37
38class BaseCounter {
39    std::string source;             // where does information originate from
40    size_t      count[BC_COUNTERS]; // number of occurrences of single bases
41
42    SmartPtr<CharCounter> char_count; // character counter (used by addLine)
43
44    void catchUpWithLineCounter() const;
45
46public:
47    BaseCounter(const std::string& Source)
48        : source(Source)
49    {
50        for (int i = 0; i<BC_COUNTERS; ++i) count[i] = 0;
51    }
52
53    void addCount(Base base, size_t amount) { count[base] += amount; }
54    void checkOverallCounter() const;
55    void calcOverallCounter();
56
57    void startLineCounter();
58    void addLine(const std::string& line) {
59        gi_assert(!char_count.isNull()); // call startLineCounter before!
60        char_count->countChars(line);
61    }
62
63    void expectEqual(const BaseCounter& other) const;
64    size_t getCount(Base base) const {
65        catchUpWithLineCounter();
66        return count[base];
67    }
68};
69
70class SequenceBuffer : virtual Noncopyable {
71    stringVector  lines;        // stores input lines
72    BaseCounter   baseCounter;
73    mutable char *seq;
74
75public:
76    SequenceBuffer(size_t expectedSize)
77        : baseCounter("sequence data"), seq(0)
78    {
79        lines.reserve(expectedSize/60+1); // flatfiles use 60 bases per sequence line
80        baseCounter.startLineCounter();
81    }
82    ~SequenceBuffer();
83
84    void addLine(const std::string& line) {
85        lines.push_back(line);
86        baseCounter.addLine(line);
87    }
88
89    const BaseCounter& getBaseCounter() const { return baseCounter; }
90    BaseCounter& getBaseCounter() { return baseCounter; }
91
92    const char *getSequence() const;
93};
94
95
96#else
97#error SequenceBuffer.h included twice
98#endif // SEQUENCEBUFFER_H
99
Note: See TracBrowser for help on using the repository browser.