source: tags/testbuild/SL/HELIX/BI_basepos.cxx

Last change on this file was 12803, checked in by westram, 10 years ago
File size: 2.7 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
15
16static bool is_Gap(char c) { return c == '-' || c == '.'; }
17
18// ---------------------
19//      BasePosition
20
21void BasePosition::initialize(const char *seq, int size) {
22    static CharPredicate pred_is_gap(is_Gap);
23    initialize(seq, size, pred_is_gap);
24}
25
26void BasePosition::initialize(const char *seq, int size, const CharPredicate& is_gap) {
27    cleanup();
28
29    bi_assert(size >= 0);
30
31    absLen  = size;
32    abs2rel = new int[absLen+1];
33
34    int i;
35    for (i = 0; i<size && seq[i]; ++i) {
36        abs2rel[i] = baseCount;
37        if (!is_gap.applies(seq[i])) ++baseCount;
38    }
39    bi_assert(baseCount >= 0);
40
41    for (; i <= size; ++i) {
42        abs2rel[i] = baseCount;
43    }
44
45    rel2abs = new int[baseCount+1];
46    for (i = size; i>0; --i) {
47        int rel = abs2rel[i];
48        if (rel) {
49            rel2abs[rel-1] = i-1;
50        }
51    }
52}
53
54// ---------------------
55//      BI_ecoli_ref
56
57GB_ERROR BI_ecoli_ref::init(GBDATA *gb_main) {
58    GB_transaction ta(gb_main);
59
60    char     *ref = GBT_get_default_ref(gb_main);
61    char     *use = GBT_get_default_alignment(gb_main);
62    GB_ERROR  err = init(gb_main, use, ref);
63
64    free(ref);
65    free(use);
66
67    return err;
68}
69
70GB_ERROR BI_ecoli_ref::init(GBDATA *gb_main, char *alignment_name, char *ref_name) {
71    GB_transaction ta(gb_main);
72
73    GB_ERROR err  = 0;
74    long     size = GBT_get_alignment_len(gb_main, alignment_name);
75
76    if (size<=0) err = GB_await_error();
77    else {
78        GBDATA *gb_ref_con   = GBT_find_SAI(gb_main, ref_name);
79        if (!gb_ref_con) err = GBS_global_string("I cannot find the SAI '%s'", ref_name);
80        else {
81            GBDATA *gb_ref   = GBT_find_sequence(gb_ref_con, alignment_name);
82            if (!gb_ref) err = GBS_global_string("Your SAI '%s' has no sequence '%s/data'", ref_name, alignment_name);
83            else {
84                const char *data = GB_read_char_pntr(gb_ref);
85                if (!data) {
86                    err = GB_await_error();
87                }
88                else {
89                    init(data, size);
90                }
91            }
92        }
93    }
94    return err;
95}
96
Note: See TracBrowser for help on using the repository browser.