ARB
changekey.cxx
Go to the documentation of this file.
1 // ==================================================================== //
2 // //
3 // File : changekey.cxx //
4 // Purpose : changekey management //
5 // //
6 // //
7 // Coded by Ralf Westram (coder@reallysoft.de) in May 2005 //
8 // Copyright Department of Microbiology (Technical University Munich) //
9 // //
10 // Visit our web site at: http://www.arb-home.de/ //
11 // //
12 // ==================================================================== //
13 
14 #include "item_sel_list.h"
15 
16 #include <arbdbt.h>
17 #include <arb_strarray.h>
18 
19 static const char GENE_DATA_PATH[] = "gene_data/gene/";
20 static const char EXPERIMENT_DATA_PATH[] = "experiment_data/experiment/";
21 
22 #define GENE_DATA_PATH_LEN (sizeof(GENE_DATA_PATH)-1)
23 #define EXPERIMENT_DATA_PATH_LEN (sizeof(EXPERIMENT_DATA_PATH)-1)
24 
25 inline bool is_in_GENE_path(const char *fieldpath) { return strncmp(fieldpath, GENE_DATA_PATH, GENE_DATA_PATH_LEN) == 0; }
26 inline bool is_in_EXPERIMENT_path(const char *fieldpath) { return strncmp(fieldpath, EXPERIMENT_DATA_PATH, EXPERIMENT_DATA_PATH_LEN) == 0; }
27 
28 inline bool is_in_reserved_path(const char *fieldpath) {
29  return
30  is_in_GENE_path(fieldpath) ||
31  is_in_EXPERIMENT_path(fieldpath);
32 }
33 
34 // --------------------------------------------------------------------------------
35 
36 
37 static void delete_unused_changekeys(GBDATA *gb_main, const CharPtrArray& names, const char *change_key_path) {
38  // deletes all keys from 'change_key_path' which are not listed in 'names'
39  GBDATA *gb_key_data = GB_search(gb_main, change_key_path, GB_CREATE_CONTAINER);
40  GBDATA *gb_key = gb_key_data ? GB_entry(gb_key_data, CHANGEKEY) : NULp;
41 
42  while (gb_key) {
43  bool found = false;
44  int key_type = *GBT_read_int(gb_key, CHANGEKEY_TYPE);
45  const char *key_name = GBT_read_char_pntr(gb_key, CHANGEKEY_NAME);
46 
47  for (int i = 0; names[i]; ++i) {
48  const char *name = names[i];
49  if (strcmp(key_name, name+1) == 0) { // key with this name exists
50  if (key_type == name[0]) {
51  found = true;
52  }
53  // otherwise key exists, but type mismatches = > delete this key
54  break;
55  }
56  }
57 
58  it_assert(GB_has_key(gb_key, CHANGEKEY));
59  GBDATA *gb_next_key = GB_nextEntry(gb_key);
60 
61  if (!found) {
62  if (key_type == GB_DB) { // it's a container
63  // test if any subkey is used
64  int keylen = strlen(key_name);
65  for (int i = 0; names[i]; ++i) {
66  const char *n = names[i]+1;
67 
68  if (strncmp(key_name, n, keylen) == 0 && n[keylen] == '/') { // found a subkey -> do not delete
69  found = true;
70  break;
71  }
72  }
73  }
74 
75  if (!found) { // key no longer exists = > delete from key list
76  GB_delete(gb_key);
77  }
78  }
79 
80  gb_key = gb_next_key;
81  }
82 }
83 
84 static void show_all_changekeys(GBDATA *gb_main, const char *change_key_path) {
85  GBDATA *gb_key_data = GB_search(gb_main, change_key_path, GB_CREATE_CONTAINER);
86  for (GBDATA *gb_key = gb_key_data ? GB_entry(gb_key_data, CHANGEKEY) : NULp;
87  gb_key;
88  gb_key = GB_nextEntry(gb_key))
89  {
90  GBDATA *gb_key_hidden = GB_entry(gb_key, CHANGEKEY_HIDDEN);
91  if (gb_key_hidden) {
92  if (GB_read_int(gb_key_hidden)) GB_write_int(gb_key_hidden, 0); // unhide
93  }
94  }
95 }
96 
98  GB_push_transaction(gb_main);
100 
101  StrArray names;
102  GBT_scan_db(names, gb_species_data, NULp);
103 
104  if (mode & RESCAN_REFRESH) delete_unused_changekeys(gb_main, names, CHANGE_KEY_PATH);
106 
107  if (mode & RESCAN_REFRESH) {
108  GBT_add_new_changekey(gb_main, "name", GB_STRING);
109  GBT_add_new_changekey(gb_main, "acc", GB_STRING);
110  GBT_add_new_changekey(gb_main, "full_name", GB_STRING);
111  GBT_add_new_changekey(gb_main, "tmp", GB_STRING);
112 
113  const long bitfilter = FIELD_FILTER_STRING_READABLE;
114  for (int i = 0; names[i]; ++i) {
115  const char *name = names[i];
116  if ((1<<name[0]) & bitfilter) { // look if already exists
117  if (!is_in_reserved_path(name+1)) { // ignore gene, experiment, ... entries
118  GBT_add_new_changekey(gb_main, name+1, (int)(name[0]));
119  }
120  }
121  }
122  }
123 
124  GB_pop_transaction(gb_main);
125 }
126 
127 
128 
130  GB_push_transaction(gb_main);
132 
133  StrArray names;
134  GBT_scan_db(names, gb_species_data, GENE_DATA_PATH);
135 
138 
139  if (mode & RESCAN_REFRESH) {
140  GBT_add_new_gene_changekey(gb_main, "name", GB_STRING);
141 
142  GBT_add_new_gene_changekey(gb_main, "pos_start", GB_STRING);
143  GBT_add_new_gene_changekey(gb_main, "pos_stop", GB_STRING);
144  GBT_add_new_gene_changekey(gb_main, "pos_complement", GB_STRING);
145 
146  GBT_add_new_gene_changekey(gb_main, "pos_joined", GB_INT);
147  GBT_add_new_gene_changekey(gb_main, "pos_certain", GB_STRING);
148 
149  const long bitfilter = FIELD_FILTER_STRING_READABLE;
150  for (int i = 0; names[i]; ++i) {
151  const char *name = names[i];
152  if ((1<<name[0]) & bitfilter) { // look if already exists
153  GBT_add_new_gene_changekey(gb_main, name+1, (int)(name[0]));
154  }
155  }
156  }
157 
158  GB_pop_transaction(gb_main);
159 }
160 
162  GB_push_transaction(gb_main);
164 
165  StrArray names;
166  GBT_scan_db(names, gb_species_data, EXPERIMENT_DATA_PATH);
167 
170 
171  if (mode & RESCAN_REFRESH) {
173 
174  const long bitfilter = FIELD_FILTER_STRING_READABLE;
175  for (int i = 0; names[i]; ++i) {
176  const char *name = names[i];
177  if ((1<<name[0]) & bitfilter) { // look if already exists
178  if (is_in_EXPERIMENT_path(name+1)) {
179  GBT_add_new_experiment_changekey(gb_main, name+1+EXPERIMENT_DATA_PATH_LEN, (int)(name[0]));
180  }
181  }
182  }
183  }
184 
185  GB_pop_transaction(gb_main);
186 }
187 
190 
193 
long GB_read_int(GBDATA *gbd)
Definition: arbdb.cxx:723
void species_field_selection_list_unhide_all_cb(AW_window *, GBDATA *gb_main)
Definition: changekey.cxx:188
GBDATA * GB_nextEntry(GBDATA *entry)
Definition: adquery.cxx:339
static const char EXPERIMENT_DATA_PATH[]
Definition: changekey.cxx:20
void gene_field_selection_list_unhide_all_cb(AW_window *, GBDATA *gb_main)
Definition: changekey.cxx:191
#define EXPERIMENT_DATA_PATH_LEN
Definition: changekey.cxx:23
#define GENE_DATA_PATH_LEN
Definition: changekey.cxx:22
GB_ERROR GBT_add_new_changekey(GBDATA *gb_main, const char *name, int type)
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2482
bool is_in_GENE_path(const char *fieldpath)
Definition: changekey.cxx:25
GB_ERROR GB_delete(GBDATA *&source)
Definition: arbdb.cxx:1904
static const char GENE_DATA_PATH[]
Definition: changekey.cxx:19
static FullNameMap names
NOT4PERL long * GBT_read_int(GBDATA *gb_container, const char *fieldpath)
Definition: adtools.cxx:327
Definition: arbdb.h:78
#define CHANGEKEY_HIDDEN
Definition: arbdbt.h:93
GBDATA * gb_species_data
Definition: adname.cxx:34
static void show_all_changekeys(GBDATA *gb_main, const char *change_key_path)
Definition: changekey.cxx:84
GB_ERROR GBT_add_new_gene_changekey(GBDATA *gb_main, const char *name, int type)
#define CHANGEKEY_NAME
Definition: arbdbt.h:91
void GBT_scan_db(StrArray &fieldNames, GBDATA *gbd, const char *datapath)
Definition: adtools.cxx:162
GB_ERROR GB_pop_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2512
bool GB_has_key(GBDATA *gbd, const char *key)
Definition: arbdb.cxx:1705
#define it_assert(cond)
Definition: items.h:25
void species_field_selection_list_update_cb(AW_window *, GBDATA *gb_main)
Definition: changekey.cxx:189
#define CHANGE_KEY_PATH_GENES
Definition: arbdbt.h:87
GB_ERROR GB_write_int(GBDATA *gbd, long i)
Definition: arbdb.cxx:1244
bool is_in_EXPERIMENT_path(const char *fieldpath)
Definition: changekey.cxx:26
void species_field_selection_list_rescan(GBDATA *gb_main, RescanMode mode)
Definition: changekey.cxx:97
static void experiment_field_selection_list_rescan(GBDATA *gb_main, RescanMode mode)
Definition: changekey.cxx:161
RescanMode
bool is_in_reserved_path(const char *fieldpath)
Definition: changekey.cxx:28
#define CHANGE_KEY_PATH
Definition: arbdbt.h:86
void gene_field_selection_list_rescan(GBDATA *gb_main, RescanMode mode)
Definition: changekey.cxx:129
#define CHANGEKEY
Definition: arbdbt.h:90
#define CHANGEKEY_TYPE
Definition: arbdbt.h:92
#define CHANGE_KEY_PATH_EXPERIMENTS
Definition: arbdbt.h:88
void gene_field_selection_list_update_cb(AW_window *, GBDATA *gb_main)
Definition: changekey.cxx:192
static void delete_unused_changekeys(GBDATA *gb_main, const CharPtrArray &names, const char *change_key_path)
Definition: changekey.cxx:37
#define NULp
Definition: cxxforward.h:97
GB_ERROR GBT_add_new_experiment_changekey(GBDATA *gb_main, const char *name, int type)
GBDATA * gb_main
Definition: adname.cxx:33
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
const char * GBT_read_char_pntr(GBDATA *gb_container, const char *fieldpath)
Definition: adtools.cxx:307
void experiment_field_selection_list_update_cb(AW_window *, GBDATA *gb_main)
Definition: changekey.cxx:195
void experiment_field_selection_list_unhide_all_cb(AW_window *, GBDATA *gb_main)
Definition: changekey.cxx:194
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
CONSTEXPR long FIELD_FILTER_STRING_READABLE
Definition: item_sel_list.h:47
Definition: arbdb.h:66
GBDATA * GBT_get_species_data(GBDATA *gb_main)
Definition: aditem.cxx:105