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 
32 
33  if (use_alignment)
34  alignment = ARB_strdup(use_alignment);
35  else
37 
39 
40  return 0;
41 }
42 
45  freenull(alignment);
46 }
47 
48 char *ALI_ARBDB::get_sequence_string(char *name, int and_mark) {
49  char *sequence = NULp;
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;
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 
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 
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 }
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2492
GBDATA * GB_open(const char *path, const char *opent)
Definition: ad_load.cxx:1363
GB_ERROR GB_commit_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2515
char * get_sequence_string(char *name, int and_mark=0)
Definition: ali_arbdb.cxx:48
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
Definition: arbdb.cxx:1361
int put_SAI(const char *name, char *sequence)
Definition: ali_arbdb.cxx:150
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
GBDATA * GB_get_father(GBDATA *gbd)
Definition: arbdb.cxx:1696
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:559
GBDATA * gb_main
Definition: ali_arbdb.hxx:24
GBDATA * gb_species_data
Definition: adname.cxx:34
ALI_SEQUENCE * get_sequence(char *name, int and_mark=0)
Definition: ali_arbdb.cxx:69
int put_sequence(char *name, ALI_SEQUENCE *sequence)
Definition: ali_arbdb.cxx:131
char * string()
GBDATA * GB_brother(GBDATA *entry, const char *key)
Definition: adquery.cxx:361
char * get_SAI(char *name)
Definition: ali_arbdb.cxx:96
GB_ERROR GB_print_error()
Definition: arb_msg.cxx:335
void GB_write_flag(GBDATA *gbd, long flag)
Definition: arbdb.cxx:2737
char * GB_read_string(GBDATA *gbd)
Definition: arbdb.cxx:879
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:97
int open(char *name, char *use_alignment=NULp)
Definition: ali_arbdb.cxx:24
char * GBT_get_default_alignment(GBDATA *gb_main)
Definition: adali.cxx:675
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:152
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:114
void close()
Definition: ali_arbdb.cxx:43
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
void GB_close(GBDATA *gbd)
Definition: arbdb.cxx:625
GBDATA * GBT_get_species_data(GBDATA *gb_main)
Definition: aditem.cxx:105