1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : ali_arbdb.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include "ali_sequence.hxx" |
---|
12 | #include "ali_arbdb.hxx" |
---|
13 | |
---|
14 | |
---|
15 | #define HELIX_PAIRS "helix_pairs" |
---|
16 | #define HELIX_LINE "helix_line" |
---|
17 | |
---|
18 | |
---|
19 | ALI_ARBDB::~ALI_ARBDB() { |
---|
20 | if (gb_main) GB_close(gb_main); |
---|
21 | freenull(alignment); |
---|
22 | } |
---|
23 | |
---|
24 | int ALI_ARBDB::open(char *name, char *use_alignment) { |
---|
25 | gb_main = GB_open(name, "rt"); |
---|
26 | if (!gb_main) { |
---|
27 | GB_print_error(); |
---|
28 | return 1; |
---|
29 | } |
---|
30 | |
---|
31 | if (use_alignment) { |
---|
32 | alignment = ARB_strdup(use_alignment); |
---|
33 | } |
---|
34 | else { |
---|
35 | GB_begin_transaction(gb_main); |
---|
36 | alignment = GBT_get_default_alignment(gb_main); |
---|
37 | GB_commit_transaction(gb_main); |
---|
38 | |
---|
39 | if (!alignment) { |
---|
40 | GB_print_error(); |
---|
41 | return 1; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | return 0; |
---|
46 | } |
---|
47 | |
---|
48 | void ALI_ARBDB::close() { |
---|
49 | GB_close(gb_main); |
---|
50 | freenull(alignment); |
---|
51 | } |
---|
52 | |
---|
53 | char *ALI_ARBDB::get_sequence_string(char *name, int and_mark) { |
---|
54 | char *sequence = NULp; |
---|
55 | GBDATA *gb_species_data; |
---|
56 | GBDATA *gb_seq; |
---|
57 | |
---|
58 | gb_species_data = GBT_get_species_data(gb_main); |
---|
59 | |
---|
60 | gb_seq = GB_find_string(gb_species_data, "name", name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
61 | if (gb_seq) { |
---|
62 | if (and_mark) GB_write_flag(GB_get_father(gb_seq), 1); |
---|
63 | gb_seq = GB_brother(gb_seq, alignment); |
---|
64 | if (gb_seq) { |
---|
65 | gb_seq = GB_entry(gb_seq, "data"); |
---|
66 | if (gb_seq) |
---|
67 | sequence = GB_read_string(gb_seq); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | return sequence; |
---|
72 | } |
---|
73 | |
---|
74 | ALI_SEQUENCE *ALI_ARBDB::get_sequence(char *name, int and_mark) { |
---|
75 | ALI_SEQUENCE *ali_seq; |
---|
76 | char *sequence = NULp; |
---|
77 | GBDATA *gb_species_data; |
---|
78 | GBDATA *gb_seq; |
---|
79 | |
---|
80 | gb_species_data = GBT_get_species_data(gb_main); |
---|
81 | |
---|
82 | gb_seq = GB_find_string(gb_species_data, "name", name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
83 | if (gb_seq) { |
---|
84 | if (and_mark) GB_write_flag(GB_get_father(gb_seq), 1); |
---|
85 | gb_seq = GB_brother(gb_seq, alignment); |
---|
86 | if (gb_seq) { |
---|
87 | gb_seq = GB_entry(gb_seq, "data"); |
---|
88 | if (gb_seq) |
---|
89 | sequence = GB_read_string(gb_seq); |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | if (!sequence) |
---|
94 | return NULp; |
---|
95 | |
---|
96 | ali_seq = new ALI_SEQUENCE(name, sequence); |
---|
97 | |
---|
98 | return ali_seq; |
---|
99 | } |
---|
100 | |
---|
101 | char *ALI_ARBDB::get_SAI(char *name) { |
---|
102 | char *extended = NULp; |
---|
103 | GBDATA *gb_sai_data = GBT_get_SAI_data(gb_main); |
---|
104 | GBDATA *gb_sai = GB_find_string(gb_sai_data, "name", name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
105 | |
---|
106 | if (gb_sai) { |
---|
107 | gb_sai = GB_brother(gb_sai, alignment); |
---|
108 | if (gb_sai) { |
---|
109 | gb_sai = GB_entry(gb_sai, "data"); |
---|
110 | if (gb_sai) |
---|
111 | extended = GB_read_string(gb_sai); |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | return extended; |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | int ALI_ARBDB::put_sequence_string(char *name, char *sequence) { |
---|
120 | GB_securityLevel raised(gb_main, 6); |
---|
121 | |
---|
122 | GBDATA *gb_species_data = GBT_get_species_data(gb_main); |
---|
123 | GBDATA *gb_seq = GB_find_string(gb_species_data, "name", name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
124 | if (gb_seq) { |
---|
125 | GBDATA *gb_ali = GB_brother(gb_seq, alignment); |
---|
126 | if (gb_ali) { |
---|
127 | GBDATA *gb_data = GB_search(gb_ali, "data", GB_STRING); |
---|
128 | GB_write_string(gb_data, sequence); |
---|
129 | free(sequence); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | return 0; |
---|
134 | } |
---|
135 | |
---|
136 | int ALI_ARBDB::put_sequence(char *name, ALI_SEQUENCE *sequence) { |
---|
137 | GB_securityLevel raised(gb_main, 6); |
---|
138 | |
---|
139 | GBDATA *gb_species_data = GBT_get_species_data(gb_main); |
---|
140 | GBDATA *gb_seq = GB_find_string(gb_species_data, "name", name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
141 | if (gb_seq) { |
---|
142 | GBDATA *gb_ali = GB_brother(gb_seq, alignment); |
---|
143 | if (gb_ali) { |
---|
144 | GBDATA *gb_data = GB_search(gb_ali, "data", GB_STRING); |
---|
145 | char *String = sequence->string(); |
---|
146 | GB_write_string(gb_data, String); |
---|
147 | free(String); |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | return 0; |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | int ALI_ARBDB::put_SAI(const char *name, char *sequence) { |
---|
156 | GB_securityLevel raised(gb_main, 6); |
---|
157 | |
---|
158 | GBDATA *gb_extended = GBT_find_or_create_SAI(gb_main, name); |
---|
159 | GBDATA *gb_data = GBT_add_data(gb_extended, alignment, "data", GB_STRING); |
---|
160 | GB_write_string(gb_data, sequence); |
---|
161 | |
---|
162 | return 0; |
---|
163 | } |
---|