1 | // ----------------------------------------------------------------------------- |
---|
2 | // Include-Dateien |
---|
3 | // ----------------------------------------------------------------------------- |
---|
4 | |
---|
5 | #include <stdio.h> |
---|
6 | #include <stdlib.h> |
---|
7 | #include <string.h> |
---|
8 | #include <ctype.h> |
---|
9 | #include <memory.h> |
---|
10 | |
---|
11 | #include "a3_arbdb.hxx" |
---|
12 | |
---|
13 | // ----------------------------------------------------------------------------- |
---|
14 | A3Arbdb::~A3Arbdb ( void ) |
---|
15 | // ----------------------------------------------------------------------------- |
---|
16 | { |
---|
17 | if (gb_main) GB_close(gb_main); |
---|
18 | if (alignment) free ((char *) alignment); |
---|
19 | } |
---|
20 | |
---|
21 | // ----------------------------------------------------------------------------- |
---|
22 | int A3Arbdb::open ( char *name, |
---|
23 | char *use_alignment ) |
---|
24 | // ----------------------------------------------------------------------------- |
---|
25 | { |
---|
26 | gb_main = GB_open(name,"rt"); |
---|
27 | |
---|
28 | if (!gb_main) |
---|
29 | { |
---|
30 | GB_print_error(); |
---|
31 | return 1; |
---|
32 | } |
---|
33 | |
---|
34 | GB_begin_transaction(gb_main); |
---|
35 | |
---|
36 | if (use_alignment) alignment = strdup(use_alignment); |
---|
37 | else alignment = GBT_get_default_alignment(gb_main); |
---|
38 | |
---|
39 | GB_commit_transaction(gb_main); |
---|
40 | |
---|
41 | return 0; |
---|
42 | } |
---|
43 | |
---|
44 | // ----------------------------------------------------------------------------- |
---|
45 | void A3Arbdb::close ( void ) |
---|
46 | // ----------------------------------------------------------------------------- |
---|
47 | { |
---|
48 | GB_close(gb_main); |
---|
49 | freeset(alignment, 0); |
---|
50 | } |
---|
51 | |
---|
52 | // ----------------------------------------------------------------------------- |
---|
53 | char *A3Arbdb::get_sequence_string ( const char *name, |
---|
54 | int and_mark ) |
---|
55 | // ----------------------------------------------------------------------------- |
---|
56 | { |
---|
57 | char *sequence = NULL; |
---|
58 | GBDATA *gb_species_data = GB_search(gb_main,"species_data",GB_FIND); |
---|
59 | GBDATA *gb_seq = GB_find_string(gb_species_data,"name",name,GB_IGNORE_CASE,down_2_level); |
---|
60 | |
---|
61 | if (gb_seq) |
---|
62 | { |
---|
63 | if (and_mark) GB_write_flag(GB_get_father(gb_seq),1); |
---|
64 | |
---|
65 | gb_seq = GB_brother(gb_seq,alignment); |
---|
66 | |
---|
67 | if (gb_seq) |
---|
68 | { |
---|
69 | gb_seq = GB_entry(gb_seq,"data"); |
---|
70 | |
---|
71 | if (gb_seq) sequence = GB_read_string(gb_seq); |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | if (sequence == 0) return 0; |
---|
76 | |
---|
77 | return sequence; |
---|
78 | } |
---|
79 | |
---|
80 | int A3Arbdb::put_sequence_string(char *name, char *sequence) { |
---|
81 | GB_change_my_security(gb_main,6,"passwd"); |
---|
82 | |
---|
83 | GBDATA *gb_species_data = GB_search(gb_main,"species_data",GB_FIND); |
---|
84 | GBDATA *gb_seq = GB_find_string(gb_species_data,"name",name,GB_IGNORE_CASE,down_2_level); |
---|
85 | |
---|
86 | if (gb_seq) { |
---|
87 | GBDATA *gb_ali = GB_brother(gb_seq,alignment); |
---|
88 | |
---|
89 | if (gb_ali) { |
---|
90 | GBDATA *gb_data = GB_search(gb_ali,"data",GB_STRING); |
---|
91 | |
---|
92 | GB_write_string(gb_data,sequence); |
---|
93 | free((char *) sequence); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | return 0; |
---|
98 | } |
---|