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