ARB
AP_seq_simple_pro.cxx
Go to the documentation of this file.
1 #include "AP_seq_simple_pro.hxx"
2 #include <AP_pro_a_nucs.hxx>
3 #include <AP_filter.hxx>
4 #include <ARB_Tree.hxx>
5 
6 
7 // #define ap_assert(bed) arb_assert(bed)
8 
10  AP_sequence(aliview)
11 {
12  sequence = NULp;
13 }
14 
16  delete [] sequence;
17 }
18 
21 }
22 
23 
24 
25 void AP_sequence_simple_protein::set(const char *isequence) {
27 
28  const struct arb_r2a_pro_2_nuc * const *s2str = translator->S2strArray();
29 
30  size_t sequence_len = get_sequence_length();
31  sequence = new ap_pro[sequence_len+1];
32  memset(sequence, s2str['.']->index, (size_t)(sizeof(ap_pro) * sequence_len));
33 
34  const char *s = isequence;
35  ap_pro *d = sequence;
36 
37  const AP_filter *filt = get_filter();
38  const uchar *simplify = filt->get_simplify_table();
39  int sindex = s2str['s']->index;
40 
41  if (filt->does_bootstrap()) {
42  int iseqlen = strlen(isequence);
43  for (int i = filt->get_filtered_length()-1; i>=0; i--) {
44  int pos = filt->bootstrapped_seqpos(i);
45  if (pos >= iseqlen) continue;
46  unsigned char c = s[pos];
47  if (! (s2str[c])) { // unknown character
48  continue;
49  }
50  int ind = s2str[simplify[c]]->index;
51  if (ind >= sindex) ind --;
52  d[i] = ind;
53  }
54  }
55  else {
56  size_t i, j;
57  size_t flen = filt->get_length();
58  for (i = j = 0; i < flen; ++i) {
59  unsigned char c = s[i];
60  if (!c) break;
61  if (filt->use_position(i)) {
62  if (s2str[c]) {
63  int ind = s2str[simplify[c]]->index;
64  if (ind >= sindex) ind--;
65  d[j] = ind;
66  }
67  j++;
68  }
69  }
70  }
71  mark_sequence_set(true);
72 }
73 
74 void AP_sequence_simple_protein::unset() {
75  delete [] sequence;
76  sequence = NULp;
77  mark_sequence_set(false);
78 }
79 
80 
81 
const uchar * get_simplify_table() const
Definition: AP_filter.hxx:100
size_t bootstrapped_seqpos(size_t bpos) const
Definition: AP_filter.hxx:111
AP_sequence_simple_protein(const AliView *aliview)
unsigned char ap_pro
bool does_bootstrap() const
Definition: AP_filter.hxx:109
const AP_filter * get_filter() const
Definition: AP_sequence.hxx:79
const arb_r2a_pro_2_nuc *const * S2strArray() const
size_t get_length() const
Definition: AP_filter.hxx:83
void mark_sequence_set(bool is_set)
Definition: AP_sequence.hxx:43
size_t get_filtered_length() const
Definition: AP_filter.hxx:82
const AliView * get_aliview() const
Definition: AP_sequence.hxx:82
AWT_translator * AWT_get_user_translator(GBDATA *gb_main)
size_t get_sequence_length() const
Definition: AP_sequence.hxx:78
unsigned char uchar
Definition: gde.hxx:21
#define NULp
Definition: cxxforward.h:97
AP_sequence * dup() const OVERRIDE
bool use_position(size_t pos) const
Definition: AP_filter.hxx:85
GBDATA * get_gb_main(DbSel db)
Definition: merge.hxx:88
GB_write_int const char s
Definition: AW_awar.cxx:156