source: tags/arb_5.3/ALIV3/a3_arbdb.cxx

Last change on this file was 5894, checked in by westram, 15 years ago
  • reactivated original GB_close
  • removed GB_exit (use GB_close)
  • gb_delete_entry now takes and invalidates a GBDATA (to avoid further undetected usage)
  • gb_do_callback_list called with GB_MAIN_TYPE (instead of possibly already deleted gb_main)
  • added some missing transactions
  • moved declaration of GBDATA into arbdb_base.h (and include where needed)
  • GB_MAIN_TYPE is no longer void
  • AW_default is no longer void
  • replaced the 3 differing ways to exit EDIT4 by ED4_exit()
  • added AW_root::unlink_awars_from_DB() and call in arb_ntree, arb_dist, arb_edit4, arb_pars and arb_phylo
  • rewrote arb_2_ascii, arb_2_bin, arb_perf_test, arb_read_tree (single exit point, error handling)
  • unlinked AWARs now return "" not "?????"
  • AW_awar::read_string works only with awars of type AW_STRING. Added assertion + fixed one wrong usage.
  • inlined AW_awar::get()
  • added AW_awar::remove_all_callbacks() and AW_awar::remove_all_target_vars()
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
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// -----------------------------------------------------------------------------
45void 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
80int 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}
Note: See TracBrowser for help on using the repository browser.