ARB
BI_basepos.cxx
Go to the documentation of this file.
1 // ============================================================= //
2 // //
3 // File : BI_basepos.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ============================================================= //
10 
11 #include "BI_basepos.hxx"
12 
13 #include <arbdbt.h>
14 #include <arb_global_defs.h>
15 
16 
17 inline bool is_Gap(char c) { return GAP::is_std_gap(c); }
18 
19 // ---------------------
20 // BasePosition
21 
22 void BasePosition::initialize(const char *seq, int size) {
23  static CharPredicate pred_is_gap(is_Gap);
24  initialize(seq, size, pred_is_gap);
25 }
26 
27 void BasePosition::initialize(const char *seq, int size, const CharPredicate& is_gap) {
28  cleanup();
29 
30  bi_assert(size >= 0);
31 
32  absLen = size;
33  abs2rel = new int[absLen+1];
34 
35  int i;
36  for (i = 0; i<size && seq[i]; ++i) {
37  abs2rel[i] = baseCount;
38  if (!is_gap.applies(seq[i])) ++baseCount;
39  }
40  bi_assert(baseCount >= 0);
41 
42  for (; i <= size; ++i) { // LOOP_VECTORIZED[!<5.0]
43  abs2rel[i] = baseCount;
44  }
45 
46  rel2abs = new int[baseCount+1];
47  for (i = size; i>0; --i) {
48  int rel = abs2rel[i];
49  if (rel) {
50  rel2abs[rel-1] = i-1;
51  }
52  }
53 }
54 
55 // ---------------------
56 // BI_ecoli_ref
57 
59  GB_transaction ta(gb_main);
60 
61  char *ref = GBT_get_default_ref(gb_main);
62  char *use = GBT_get_default_alignment(gb_main);
63 
64  GB_ERROR err;
65  if (!use) err = GB_await_error();
66  else err = init(gb_main, use, ref);
67 
68  free(ref);
69  free(use);
70 
71  return err;
72 }
73 
75  GB_transaction ta(gb_main);
76 
77  GB_ERROR err = NULp;
78  long size = GBT_get_alignment_len(gb_main, alignment_name);
79 
80  if (size<=0) {
81  err = GB_await_error();
82  }
83  else {
84  GBDATA *gb_ref_con = GBT_find_SAI(gb_main, ref_name);
85  if (!gb_ref_con) err = GBS_global_string("I cannot find the SAI '%s'", ref_name);
86  else {
87  GBDATA *gb_ref = GBT_find_sequence(gb_ref_con, alignment_name);
88  if (!gb_ref) err = GBS_global_string("Your SAI '%s' has no sequence '%s/data'", ref_name, alignment_name);
89  else {
90  const char *data = GB_read_char_pntr(gb_ref); // @@@ NOT_ALL_SAI_HAVE_DATA
91  if (!data) {
92  err = GB_await_error();
93  }
94  else {
95  init(data, size);
96  }
97  }
98  }
99  }
100  return err;
101 }
102 
void initialize(const char *seq, int size)
Definition: BI_basepos.cxx:22
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:833
static char * alignment_name
FILE * seq
Definition: rns.c:46
GBDATA * GBT_find_SAI(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:177
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:342
#define bi_assert(bed)
Definition: BI_basepos.hxx:25
void init(const char *seq, int size)
Definition: BI_basepos.hxx:109
bool is_gap(char c)
Definition: seq_search.hxx:48
char * GBT_get_default_ref(GBDATA *)
Definition: adtools.cxx:66
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
Definition: adali.cxx:708
bool is_Gap(char c)
Definition: BI_basepos.cxx:17
bool is_std_gap(const char c)
#define NULp
Definition: cxxforward.h:116
char * GBT_get_default_alignment(GBDATA *gb_main)
Definition: adali.cxx:747
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
Definition: arbdb.cxx:904
GBDATA * gb_main
Definition: adname.cxx:32
bool applies(char c) const
Definition: BI_basepos.hxx:39