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