ARB
SQ_physical_layout.h
Go to the documentation of this file.
1 // ==================================================================== //
2 // //
3 // File : SQ_physical_layout.h //
4 // Purpose : Class used for calculation of the phys. layout of seq. //
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_CMATH
16 #include <cmath>
17 #endif
18 
19 #ifndef ARB_ASSERT_H
20 #include <arb_assert.h>
21 #endif
22 #define seq_assert(bed) arb_assert(bed)
23 
25  double temp;
26  double count_bases;
27  double count_scores;
28  double count_dots;
29  double GC;
30  double GC_proportion;
31  int percent_bases;
32  int count_bases2;
33 
34  int roundme(double value);
35 
36 public:
38  void SQ_calc_physical_layout(const char *sequence, int size, GBDATA *gb_quality_ali);
39  int SQ_get_number_of_bases() const;
40  double SQ_get_gc_proportion() const;
41 };
42 
44  temp = 0;
45  count_bases = 0;
46  count_scores = 0;
47  count_dots = 0;
48  percent_bases = 0;
49  GC = 0;
50  GC_proportion = 0;
51  count_bases2 = 0;
52 }
53 
54 int SQ_physical_layout::roundme(double value) {
55  int x;
56  value += 0.5;
57  x = (int) floor(value);
58  return x;
59 }
60 
62  int size, GBDATA * gb_quality_ali) {
63  count_bases = size;
64 
65  for (int i = 0; i < size; i++) {
66  switch (sequence[i]) {
67  case '-': // calculate number of dots and spaces
68  count_bases--;
69  count_scores++;
70  break;
71  case '.':
72  count_bases--;
73  count_dots++;
74  break;
75  case 'G': // calculate GC layout of sequence
76  case 'g':
77  GC++;
78  break;
79  case 'C':
80  case 'c':
81  GC++;
82  break;
83  }
84  }
85 
86  // calculate layout in percent
87  if (GC != 0) {
88  GC_proportion = GC / count_bases;
89  }
90  temp = 100 - (100 * ((count_scores + count_dots) / size));
91  percent_bases = roundme(temp);
92  count_bases2 = roundme(count_bases);
93 
94  GBDATA *gb_result1 = GB_search(gb_quality_ali, "number_of_bases", GB_INT);
95  seq_assert(gb_result1);
96  GB_write_int(gb_result1, count_bases2);
97 
98  GBDATA *gb_result2 = GB_search(gb_quality_ali, "percent_of_bases", GB_INT);
99  seq_assert(gb_result2);
100  GB_write_int(gb_result2, percent_bases);
101 
102  GBDATA *gb_result3 = GB_search(gb_quality_ali, "GC_proportion", GB_FLOAT);
103  seq_assert(gb_result3);
104  GB_write_float(gb_result3, GC_proportion);
105 }
106 
108  int i;
109  i = count_bases2;
110  return i;
111 }
112 
114  double i;
115  i = GC_proportion;
116  return i;
117 }
void SQ_calc_physical_layout(const char *sequence, int size, GBDATA *gb_quality_ali)
Definition: arbdb.h:67
GB_ERROR GB_write_float(GBDATA *gbd, float f)
Definition: arbdb.cxx:1279
GB_ERROR GB_write_int(GBDATA *gbd, long i)
Definition: arbdb.cxx:1244
double SQ_get_gc_proportion() const
int SQ_get_number_of_bases() const
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
#define seq_assert(bed)
Definition: arbdb.h:66