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 | { |
---|
21 | if (gb_main) GB_close(gb_main); |
---|
22 | freenull(alignment); |
---|
23 | } |
---|
24 | |
---|
25 | int ALI_ARBDB::open(char *name, char *use_alignment) |
---|
26 | { |
---|
27 | gb_main = GB_open(name, "rt"); |
---|
28 | if (!gb_main) { |
---|
29 | GB_print_error(); |
---|
30 | return 1; |
---|
31 | } |
---|
32 | |
---|
33 | GB_begin_transaction(gb_main); |
---|
34 | |
---|
35 | if (use_alignment) |
---|
36 | alignment = strdup(use_alignment); |
---|
37 | else |
---|
38 | alignment = GBT_get_default_alignment(gb_main); |
---|
39 | |
---|
40 | GB_commit_transaction(gb_main); |
---|
41 | |
---|
42 | return 0; |
---|
43 | } |
---|
44 | |
---|
45 | void ALI_ARBDB::close() |
---|
46 | { |
---|
47 | GB_close(gb_main); |
---|
48 | freenull(alignment); |
---|
49 | } |
---|
50 | |
---|
51 | char *ALI_ARBDB::get_sequence_string(char *name, int and_mark) |
---|
52 | { |
---|
53 | char *sequence = 0; |
---|
54 | GBDATA *gb_species_data; |
---|
55 | GBDATA *gb_seq; |
---|
56 | |
---|
57 | gb_species_data = GBT_get_species_data(gb_main); |
---|
58 | |
---|
59 | gb_seq = GB_find_string(gb_species_data, "name", name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
60 | if (gb_seq) { |
---|
61 | if (and_mark) GB_write_flag(GB_get_father(gb_seq), 1); |
---|
62 | gb_seq = GB_brother(gb_seq, alignment); |
---|
63 | if (gb_seq) { |
---|
64 | gb_seq = GB_entry(gb_seq, "data"); |
---|
65 | if (gb_seq) |
---|
66 | sequence = GB_read_string(gb_seq); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | if (sequence == 0) |
---|
71 | return 0; |
---|
72 | |
---|
73 | return sequence; |
---|
74 | } |
---|
75 | |
---|
76 | ALI_SEQUENCE *ALI_ARBDB::get_sequence(char *name, int and_mark) |
---|
77 | { |
---|
78 | ALI_SEQUENCE *ali_seq; |
---|
79 | char *sequence = 0; |
---|
80 | GBDATA *gb_species_data; |
---|
81 | GBDATA *gb_seq; |
---|
82 | |
---|
83 | gb_species_data = GBT_get_species_data(gb_main); |
---|
84 | |
---|
85 | gb_seq = GB_find_string(gb_species_data, "name", name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
86 | if (gb_seq) { |
---|
87 | if (and_mark) GB_write_flag(GB_get_father(gb_seq), 1); |
---|
88 | gb_seq = GB_brother(gb_seq, alignment); |
---|
89 | if (gb_seq) { |
---|
90 | gb_seq = GB_entry(gb_seq, "data"); |
---|
91 | if (gb_seq) |
---|
92 | sequence = GB_read_string(gb_seq); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | if (sequence == 0) |
---|
97 | return 0; |
---|
98 | |
---|
99 | ali_seq = new ALI_SEQUENCE(name, sequence); |
---|
100 | |
---|
101 | return ali_seq; |
---|
102 | } |
---|
103 | |
---|
104 | char *ALI_ARBDB::get_SAI(char *name) { |
---|
105 | char *extended = 0; |
---|
106 | GBDATA *gb_sai_data = GBT_get_SAI_data(gb_main); |
---|
107 | GBDATA *gb_sai = GB_find_string(gb_sai_data, "name", name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
108 | |
---|
109 | if (gb_sai) { |
---|
110 | gb_sai = GB_brother(gb_sai, alignment); |
---|
111 | if (gb_sai) { |
---|
112 | gb_sai = GB_entry(gb_sai, "data"); |
---|
113 | if (gb_sai) |
---|
114 | extended = GB_read_string(gb_sai); |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | return extended; |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | int ALI_ARBDB::put_sequence_string(char *name, char *sequence) { |
---|
123 | GB_change_my_security(gb_main, 6); |
---|
124 | GBDATA *gb_species_data = GBT_get_species_data(gb_main); |
---|
125 | |
---|
126 | GBDATA *gb_seq = GB_find_string(gb_species_data, "name", name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
127 | if (gb_seq) { |
---|
128 | GBDATA *gb_ali = GB_brother(gb_seq, alignment); |
---|
129 | if (gb_ali) { |
---|
130 | GBDATA *gb_data = GB_search(gb_ali, "data", GB_STRING); |
---|
131 | GB_write_string(gb_data, sequence); |
---|
132 | free(sequence); |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | return 0; |
---|
137 | } |
---|
138 | |
---|
139 | int ALI_ARBDB::put_sequence(char *name, ALI_SEQUENCE *sequence) { |
---|
140 | GB_change_my_security(gb_main, 6); |
---|
141 | GBDATA *gb_species_data = GBT_get_species_data(gb_main); |
---|
142 | |
---|
143 | GBDATA *gb_seq = GB_find_string(gb_species_data, "name", name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); |
---|
144 | if (gb_seq) { |
---|
145 | GBDATA *gb_ali = GB_brother(gb_seq, alignment); |
---|
146 | if (gb_ali) { |
---|
147 | GBDATA *gb_data = GB_search(gb_ali, "data", GB_STRING); |
---|
148 | char *String = sequence->string(); |
---|
149 | GB_write_string(gb_data, String); |
---|
150 | free(String); |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | return 0; |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | int ALI_ARBDB::put_SAI(const char *name, char *sequence) { |
---|
159 | GB_change_my_security(gb_main, 6); |
---|
160 | |
---|
161 | GBDATA *gb_extended = GBT_find_or_create_SAI(gb_main, name); |
---|
162 | GBDATA *gb_data = GBT_add_data(gb_extended, alignment, "data", GB_STRING); |
---|
163 | GB_write_string(gb_data, sequence); |
---|
164 | |
---|
165 | return 0; |
---|
166 | } |
---|