1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : AP_sequence.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include "AP_sequence.hxx" |
---|
12 | #include <arbdbt.h> |
---|
13 | |
---|
14 | long AP_sequence::global_combineCount; |
---|
15 | |
---|
16 | AP_sequence::AP_sequence(const AliView *aliview) |
---|
17 | : cached_wbc(-1.0) |
---|
18 | , ali(aliview) |
---|
19 | , gb_sequence(NULL) |
---|
20 | , has_sequence(false) |
---|
21 | , update(0) |
---|
22 | { |
---|
23 | } |
---|
24 | |
---|
25 | GB_ERROR AP_sequence::bind_to_species(GBDATA *gb_species) { |
---|
26 | GB_ERROR error = NULL; |
---|
27 | |
---|
28 | ap_assert(!gb_sequence); // already bound to species! |
---|
29 | if (!gb_sequence) { |
---|
30 | GB_transaction ta(ali->get_gb_main()); |
---|
31 | gb_sequence = GBT_find_sequence(gb_species, ali->get_aliname()); |
---|
32 | if (!gb_sequence) { |
---|
33 | error = GBS_global_string("Species '%s' has no data in alignment '%s'", |
---|
34 | GBT_get_name(gb_species), ali->get_aliname()); |
---|
35 | } |
---|
36 | unset(); |
---|
37 | } |
---|
38 | return error; |
---|
39 | } |
---|
40 | |
---|
41 | void AP_sequence::unbind_from_species() { |
---|
42 | ap_assert(gb_sequence); |
---|
43 | gb_sequence = NULL; |
---|
44 | unset(); |
---|
45 | } |
---|
46 | |
---|
47 | void AP_sequence::do_lazy_load() const { |
---|
48 | ap_assert(gb_sequence); |
---|
49 | ap_assert(!has_sequence); |
---|
50 | |
---|
51 | GB_transaction ta(gb_sequence); |
---|
52 | const char *seq = GB_read_char_pntr(gb_sequence); |
---|
53 | if (!seq) { |
---|
54 | GB_ERROR error = GB_await_error(); |
---|
55 | GBDATA *gb_species = GB_get_grandfather(gb_sequence); |
---|
56 | const char *name = GBT_get_name(gb_species); |
---|
57 | |
---|
58 | GB_warningf("Failed to load sequence of '%s'\n(Reason: %s)", name, error); |
---|
59 | seq = ""; // fake empty sequence |
---|
60 | } |
---|
61 | |
---|
62 | // this is no modification, this is lazy initialization |
---|
63 | const_cast<AP_sequence*>(this)->set(seq); |
---|
64 | } |
---|
65 | |
---|
66 | |
---|