source: tags/ms_r16q4/SL/SEQUENCE/AP_sequence.hxx

Last change on this file was 13625, checked in by westram, 9 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : AP_sequence.hxx                                   //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11#ifndef AP_SEQUENCE_HXX
12#define AP_SEQUENCE_HXX
13
14#ifndef ALIVIEW_HXX
15#include <AliView.hxx>
16#endif
17#ifndef ARBTOOLS_H
18#include <arbtools.h>
19#endif
20#ifndef ARB_ASSERT_H
21#include <arb_assert.h>
22#endif
23#ifndef _STDINT_H
24#include <stdint.h>
25#endif
26
27#define ap_assert(cond) arb_assert(cond)
28
29typedef double AP_FLOAT;
30
31long AP_timer();
32
33class AP_sequence : virtual Noncopyable {
34    mutable AP_FLOAT  cached_wbc;                   // result for weighted_base_count(); <0.0 means "not initialized"
35    const AliView    *ali;
36
37    GBDATA *gb_sequence;                            // points to species/ali_xxx/data (or NULL if unbound, e.g. inner nodes in tree)
38    bool    has_sequence;                           // true -> sequence was set()
39    long    update;
40
41    static long global_combineCount;
42
43protected:
44    void mark_sequence_set(bool is_set) {
45        if (is_set != has_sequence) {
46            update   = is_set ? AP_timer() : 0;
47            has_sequence = is_set;
48            cached_wbc   = -1.0;
49        }
50    }
51
52    static void inc_combine_count() { global_combineCount++; }
53
54    virtual AP_FLOAT count_weighted_bases() const = 0;
55
56    virtual void set(const char *sequence) = 0;
57    virtual void unset()                   = 0;
58
59    void do_lazy_load() const;
60
61public:
62    AP_sequence(const AliView *aliview);
63    virtual ~AP_sequence() {}
64
65    virtual AP_sequence *dup() const = 0;                 // used to dup derived class
66
67    virtual AP_FLOAT combine(const AP_sequence* lefts, const AP_sequence *rights, char *mutation_per_site = 0) = 0;
68    virtual void partial_match(const AP_sequence* part, long *overlap, long *penalty) const                    = 0;
69    virtual uint32_t checksum() const                                                                          = 0;
70    virtual bool equals(const AP_sequence *other) const                                                        = 0;
71
72    static long combine_count() { return global_combineCount; }
73
74    GB_ERROR bind_to_species(GBDATA *gb_species);
75    void     unbind_from_species();
76    bool is_bound_to_species() const { return gb_sequence != NULL; }
77    GBDATA *get_bound_species_data() const { return gb_sequence; }
78
79    void lazy_load_sequence() const {
80        if (!has_sequence && is_bound_to_species()) do_lazy_load();
81    }
82    void ensure_sequence_loaded() const {
83        lazy_load_sequence();
84        ap_assert(has_sequence);
85    }
86
87    bool hasSequence() const { return has_sequence; }
88    void forget_sequence() { if (has_sequence) unset(); }
89
90    AP_FLOAT weighted_base_count() const { // returns < 0.0 if no sequence!
91        if (cached_wbc<0.0) cached_wbc = count_weighted_bases();
92        return cached_wbc;
93    }
94
95    size_t get_sequence_length() const { return ali->get_length(); } // filtered length
96    const AP_filter *get_filter() const { return ali->get_filter(); }
97    const AP_weights *get_weights() const { return ali->get_weights(); }
98
99    const AliView *get_aliview() const { return ali; }
100
101    AP_FLOAT noncounting_combine(const AP_sequence* lefts, const AP_sequence *rights) {
102        AP_FLOAT res = combine(lefts, rights);
103        global_combineCount--;
104        return res;
105    }
106};
107
108
109#else
110#error AP_sequence.hxx included twice
111#endif // AP_SEQUENCE_HXX
Note: See TracBrowser for help on using the repository browser.