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 | |
---|
17 | inline bool is_Gap(char c) { return GAP::is_std_gap(c); } |
---|
18 | |
---|
19 | // --------------------- |
---|
20 | // BasePosition |
---|
21 | |
---|
22 | void BasePosition::initialize(const char *seq, int size) { |
---|
23 | static CharPredicate pred_is_gap(is_Gap); |
---|
24 | initialize(seq, size, pred_is_gap); |
---|
25 | } |
---|
26 | |
---|
27 | void 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 | |
---|
58 | GB_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 | |
---|
64 | GB_ERROR err; |
---|
65 | if (!use) err = GB_await_error(); |
---|
66 | else err = init(gb_main, use, ref); |
---|
67 | |
---|
68 | free(ref); |
---|
69 | free(use); |
---|
70 | |
---|
71 | return err; |
---|
72 | } |
---|
73 | |
---|
74 | GB_ERROR BI_ecoli_ref::init(GBDATA *gb_main, char *alignment_name, char *ref_name) { |
---|
75 | GB_transaction ta(gb_main); |
---|
76 | |
---|
77 | GB_ERROR err = NULp; |
---|
78 | long size = GBT_get_alignment_len(gb_main, alignment_name); |
---|
79 | |
---|
80 | if (size<=0) { |
---|
81 | err = GB_await_error(); |
---|
82 | } |
---|
83 | else { |
---|
84 | GBDATA *gb_ref_con = GBT_find_SAI(gb_main, ref_name); |
---|
85 | if (!gb_ref_con) err = GBS_global_string("I cannot find the SAI '%s'", ref_name); |
---|
86 | else { |
---|
87 | GBDATA *gb_ref = GBT_find_sequence(gb_ref_con, alignment_name); |
---|
88 | if (!gb_ref) err = GBS_global_string("Your SAI '%s' has no sequence '%s/data'", ref_name, alignment_name); |
---|
89 | else { |
---|
90 | const char *data = GB_read_char_pntr(gb_ref); // @@@ NOT_ALL_SAI_HAVE_DATA |
---|
91 | if (!data) { |
---|
92 | err = GB_await_error(); |
---|
93 | } |
---|
94 | else { |
---|
95 | init(data, size); |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|
99 | } |
---|
100 | return err; |
---|
101 | } |
---|
102 | |
---|