ARB
ali_arbdb.cxx
Go to the documentation of this file.
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 
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) {
28  return 1;
29  }
30 
31  if (use_alignment) {
32  alignment = ARB_strdup(use_alignment);
33  }
34  else {
38 
39  if (!alignment) {
41  return 1;
42  }
43  }
44 
45  return 0;
46 }
47 
50  freenull(alignment);
51 }
52 
53 char *ALI_ARBDB::get_sequence_string(char *name, int and_mark) {
54  char *sequence = NULp;
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;
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 
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 
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 }
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
GBDATA * GB_open(const char *path, const char *opent)
Definition: ad_load.cxx:1363
GB_ERROR GB_commit_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2551
char * get_sequence_string(char *name, int and_mark=0)
Definition: ali_arbdb.cxx:53
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
Definition: arbdb.cxx:1387
int put_SAI(const char *name, char *sequence)
Definition: ali_arbdb.cxx:155
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
GBDATA * GB_get_father(GBDATA *gbd)
Definition: arbdb.cxx:1722
const char * String
Definition: gb_aci_impl.h:59
NOT4PERL GBDATA * GBT_add_data(GBDATA *species, const char *ali_name, const char *key, GB_TYPES type) __ATTR__DEPRECATED_TODO("better use GBT_create_sequence_data()")
Definition: adali.cxx:597
GBDATA * gb_main
Definition: ali_arbdb.hxx:24
GBDATA * gb_species_data
Definition: adname.cxx:33
ALI_SEQUENCE * get_sequence(char *name, int and_mark=0)
Definition: ali_arbdb.cxx:74
int put_sequence(char *name, ALI_SEQUENCE *sequence)
Definition: ali_arbdb.cxx:136
char * string()
GBDATA * GB_brother(GBDATA *entry, const char *key)
Definition: adquery.cxx:361
char * get_SAI(char *name)
Definition: ali_arbdb.cxx:101
GB_ERROR GB_print_error()
Definition: arb_msg.cxx:324
void GB_write_flag(GBDATA *gbd, long flag)
Definition: arbdb.cxx:2773
char * GB_read_string(GBDATA *gbd)
Definition: arbdb.cxx:909
GBDATA * GB_find_string(GBDATA *gbd, const char *key, const char *str, GB_CASE case_sens, GB_SEARCH_TYPE gbs)
Definition: adquery.cxx:302
#define NULp
Definition: cxxforward.h:116
int open(char *name, char *use_alignment=NULp)
Definition: ali_arbdb.cxx:24
char * GBT_get_default_alignment(GBDATA *gb_main)
Definition: adali.cxx:747
GBDATA * GBT_find_or_create_SAI(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:65
GBDATA * GBT_get_SAI_data(GBDATA *gb_main)
Definition: aditem.cxx:154
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
int put_sequence_string(char *name, char *sequence)
Definition: ali_arbdb.cxx:119
void close()
Definition: ali_arbdb.cxx:48
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
void GB_close(GBDATA *gbd)
Definition: arbdb.cxx:655
GBDATA * GBT_get_species_data(GBDATA *gb_main)
Definition: aditem.cxx:105