ARB
SQ_helix.h
Go to the documentation of this file.
1 // ==================================================================== //
2 // //
3 // File : SQ_helix.h //
4 // Purpose : Class used for calculation of helix layout //
5 // //
6 // //
7 // Coded by Juergen Huber in July 2003 - February 2004 //
8 // Coded by Kai Bader (baderk@in.tum.de) in 2007 - 2008 //
9 // Copyright Department of Microbiology (Technical University Munich) //
10 // //
11 // Visit our web site at: http://www.arb-home.de/ //
12 // //
13 // ==================================================================== //
14 
15 #ifndef _GLIBCXX_STRING
16 #include <string>
17 #endif
18 #ifndef _GLIBCXX_MAP
19 #include <map>
20 #endif
21 
22 #ifndef BI_HELIX_HXX
23 #include <BI_helix.hxx>
24 #endif
25 #ifndef AP_FILTER_HXX
26 #include <AP_filter.hxx>
27 #endif
28 #ifndef ARBDB_H
29 #include <arbdb.h>
30 #endif
31 
32 
33 class SQ_helix : virtual Noncopyable {
34  const char *sequence;
35  int count_strong_helix;
36  int count_weak_helix;
37  int count_no_helix;
38  int size;
39 
40  static SmartPtr<BI_helix> helix;
41  static SmartPtr<BI_pairdef> pairdef;
42  static GBDATA *helix_gb_main;
43  static std::string helix_ali_name;
44 
45  static void updateHelixAndPairdef(GBDATA *gb_main, const char *ali_name);
46 
47 public:
48  SQ_helix(int size);
49  ~SQ_helix();
50 
51  void SQ_calc_helix_layout(const char *sequence, GBDATA *gb_main, char *alignment_name, GBDATA *gb_quality, AP_filter *filter);
52 
53  int SQ_get_no_helix() const {
54  return count_no_helix;
55  }
56  int SQ_get_weak_helix() const {
57  return count_weak_helix;
58  }
59  int SQ_get_strong_helix() const {
60  return count_strong_helix;
61  }
62 };
63 
64 // global data
65 SmartPtr<BI_helix> SQ_helix::helix;
66 SmartPtr<BI_pairdef> SQ_helix::pairdef;
67 GBDATA *SQ_helix::helix_gb_main = NULp;
68 std::string SQ_helix::helix_ali_name;
69 
70 // SQ_helix implementation
71 void SQ_helix::updateHelixAndPairdef(GBDATA *gb_main, const char *ali_name) {
72  if (helix.isNull() ||
73  gb_main != helix_gb_main ||
74  strcmp(helix_ali_name.c_str(), ali_name) != 0)
75  {
76  helix = new BI_helix;
77  helix->init(gb_main, ali_name);
78 
79  pairdef = new BI_pairdef;
80 
81  helix_gb_main = gb_main;
82  helix_ali_name = ali_name;
83  }
84 }
85 
86 SQ_helix::SQ_helix(int size_) :
87  sequence(NULp),
88  count_strong_helix(0),
89  count_weak_helix(0),
90  count_no_helix(0),
91  size(size_)
92 {}
93 
95 }
96 
97 void SQ_helix::SQ_calc_helix_layout(const char *seq, GBDATA *gb_main, char *alignment_name, GBDATA *gb_quality, AP_filter *filter) {
98  updateHelixAndPairdef(gb_main, alignment_name);
99 
100  size_t filterLen = filter->get_filtered_length();
101  const size_t *filterpos_2_seqpos = filter->get_filterpos_2_seqpos();
102 
103  std::map<int, int> filterMap;
104  for (size_t filter_pos = 0; filter_pos < filterLen; filter_pos++) {
105  filterMap[filterpos_2_seqpos[filter_pos]] = filter_pos;
106  }
107 
108  if (!helix->has_entries()) {
109  count_strong_helix = 1;
110  count_weak_helix = 1;
111  count_no_helix = 1;
112  }
113  else {
114  // calculate the number of strong, weak and no helixes
115  std::map<int, int>::iterator it;
116 
117  for (size_t filter_pos = 0; filter_pos < filterLen; filter_pos++) {
118  int seq_pos = filterpos_2_seqpos[filter_pos];
119 
120  if (helix->is_pairpos(seq_pos)) {
121  int v_seq_pos = helix->opposite_position(seq_pos);
122 
123  if (v_seq_pos > seq_pos) { // ignore right helix positions
124  it = filterMap.find(v_seq_pos);
125 
126  if (it != filterMap.end()) {
127  char left = seq[filter_pos];
128  char right = seq[it->second];
129 
130  int strength = pairdef->pair_strength(left, right);
131 
132  switch (strength) {
133  case 3:
134  case 2:
135  count_strong_helix++;
136  break;
137  case 1:
138  count_weak_helix++;
139  break;
140  case 0:
141  if (!((left == '-') && (right == '-')))
142  count_no_helix++;
143  break;
144  default:
145  seq_assert(0);
146  break;
147  }
148  }
149  }
150  }
151  }
152  }
153 
154  GBDATA *gb_result1 = GB_search(gb_quality, "number_of_no_helix", GB_INT);
155  seq_assert(gb_result1);
156  GB_write_int(gb_result1, count_no_helix);
157 
158  GBDATA *gb_result2 = GB_search(gb_quality, "number_of_weak_helix", GB_INT);
159  seq_assert(gb_result2);
160  GB_write_int(gb_result2, count_weak_helix);
161 
162  GBDATA *gb_result3 = GB_search(gb_quality, "number_of_strong_helix", GB_INT);
163  seq_assert(gb_result3);
164  GB_write_int(gb_result3, count_strong_helix);
165 }
bool is_pairpos(size_t pos) const
Definition: BI_helix.hxx:117
const size_t * get_filterpos_2_seqpos() const
Definition: AP_filter.hxx:91
return string(buffer, length)
int SQ_get_no_helix() const
Definition: SQ_helix.h:53
int SQ_get_strong_helix() const
Definition: SQ_helix.h:59
int pair_strength(char left, char right)
Definition: BI_helix.cxx:94
size_t opposite_position(size_t pos) const
Definition: BI_helix.hxx:113
static char * alignment_name
int SQ_get_weak_helix() const
Definition: SQ_helix.h:56
bool isNull() const
test if SmartPtr is NULp
Definition: smartptr.h:248
FILE * seq
Definition: rns.c:46
~SQ_helix()
Definition: SQ_helix.h:94
void SQ_calc_helix_layout(const char *sequence, GBDATA *gb_main, char *alignment_name, GBDATA *gb_quality, AP_filter *filter)
Definition: SQ_helix.h:97
#define seq_assert(bed)
GB_ERROR GB_write_int(GBDATA *gbd, long i)
Definition: arbdb.cxx:1250
size_t get_filtered_length() const
Definition: AP_filter.hxx:82
SQ_helix(int size)
Definition: SQ_helix.h:86
bool has_entries() const
Definition: BI_helix.hxx:106
#define NULp
Definition: cxxforward.h:116
GBDATA * gb_main
Definition: adname.cxx:32
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
GB_ERROR init(GBDATA *gb_main)
Definition: BI_helix.cxx:327
Definition: arbdb.h:66