source: branches/stable/SL/HELIX/BI_basepos.cxx

Last change on this file was 18463, checked in by westram, 4 years ago
File size: 2.8 KB
Line 
1// ============================================================= //
2//                                                               //
3//   File      : BI_basepos.cxx                                  //
4//   Purpose   :                                                 //
5//                                                               //
6//   Institute of Microbiology (Technical University Munich)     //
7//   http://www.arb-home.de/                                     //
8//                                                               //
9// ============================================================= //
10
11#include "BI_basepos.hxx"
12
13#include <arbdbt.h>
14#include <arb_global_defs.h>
15
16
17inline bool is_Gap(char c) { return GAP::is_std_gap(c); }
18
19// ---------------------
20//      BasePosition
21
22void BasePosition::initialize(const char *seq, int size) {
23    static CharPredicate pred_is_gap(is_Gap);
24    initialize(seq, size, pred_is_gap);
25}
26
27void BasePosition::initialize(const char *seq, int size, const CharPredicate& is_gap) {
28    cleanup();
29
30    bi_assert(size >= 0);
31
32    absLen  = size;
33    abs2rel = new int[absLen+1];
34
35    int i;
36    for (i = 0; i<size && seq[i]; ++i) {
37        abs2rel[i] = baseCount;
38        if (!is_gap.applies(seq[i])) ++baseCount;
39    }
40    bi_assert(baseCount >= 0);
41
42    for (; i <= size; ++i) { // LOOP_VECTORIZED[!<5.0]
43        abs2rel[i] = baseCount;
44    }
45
46    rel2abs = new int[baseCount+1];
47    for (i = size; i>0; --i) {
48        int rel = abs2rel[i];
49        if (rel) {
50            rel2abs[rel-1] = i-1;
51        }
52    }
53}
54
55// ---------------------
56//      BI_ecoli_ref
57
58GB_ERROR BI_ecoli_ref::init(GBDATA *gb_main) {
59    GB_transaction ta(gb_main);
60
61    char     *ref = GBT_get_default_ref(gb_main);
62    char     *use = GBT_get_default_alignment(gb_main);
63    GB_ERROR  err = init(gb_main, use, ref);
64
65    free(ref);
66    free(use);
67
68    return err;
69}
70
71GB_ERROR BI_ecoli_ref::init(GBDATA *gb_main, char *alignment_name, char *ref_name) {
72    GB_transaction ta(gb_main);
73
74    GB_ERROR err  = NULp;
75    long     size = GBT_get_alignment_len(gb_main, alignment_name);
76
77    if (size<=0) {
78        err = size<0 ? GB_await_error() : "no data in alignment";
79    }
80    else {
81        GBDATA *gb_ref_con   = GBT_find_SAI(gb_main, ref_name);
82        if (!gb_ref_con) err = GBS_global_string("I cannot find the SAI '%s'", ref_name);
83        else {
84            GBDATA *gb_ref   = GBT_find_sequence(gb_ref_con, alignment_name);
85            if (!gb_ref) err = GBS_global_string("Your SAI '%s' has no sequence '%s/data'", ref_name, alignment_name);
86            else {
87                const char *data = GB_read_char_pntr(gb_ref); // @@@ NOT_ALL_SAI_HAVE_DATA
88                if (!data) {
89                    err = GB_await_error();
90                }
91                else {
92                    init(data, size);
93                }
94            }
95        }
96    }
97    return err;
98}
99
Note: See TracBrowser for help on using the repository browser.