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  GB_ERROR err = init(gb_main, use, ref);
64 
65  free(ref);
66  free(use);
67 
68  return err;
69 }
70 
72  GB_transaction ta(gb_main);
73 
74  GB_ERROR err = NULp;
75  long size = GBT_get_alignment_len(gb_main, alignment_name);
76 
77  if (size<=0) {
78  err = size<0 ? GB_await_error() : "no data in alignment";
79  }
80  else {
81  GBDATA *gb_ref_con = GBT_find_SAI(gb_main, ref_name);
82  if (!gb_ref_con) err = GBS_global_string("I cannot find the SAI '%s'", ref_name);
83  else {
84  GBDATA *gb_ref = GBT_find_sequence(gb_ref_con, alignment_name);
85  if (!gb_ref) err = GBS_global_string("Your SAI '%s' has no sequence '%s/data'", ref_name, alignment_name);
86  else {
87  const char *data = GB_read_char_pntr(gb_ref); // @@@ NOT_ALL_SAI_HAVE_DATA
88  if (!data) {
89  err = GB_await_error();
90  }
91  else {
92  init(data, size);
93  }
94  }
95  }
96  }
97  return err;
98 }
99 
void initialize(const char *seq, int size)
Definition: BI_basepos.cxx:22
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:706
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:353
#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:670
bool is_Gap(char c)
Definition: BI_basepos.cxx:17
bool is_std_gap(const char c)
#define NULp
Definition: cxxforward.h:97
char * GBT_get_default_alignment(GBDATA *gb_main)
Definition: adali.cxx:675
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
Definition: arbdb.cxx:898
GBDATA * gb_main
Definition: adname.cxx:33
bool applies(char c) const
Definition: BI_basepos.hxx:39