source: trunk/SEQ_QUALITY/SQ_physical_layout.h

Last change on this file was 19409, checked in by westram, 17 months ago
  • mostly cosmetic changes to SEQ_QUALITY:
    • compact else-if cascades.
      • avoid using abs() repeatedly in cascades
    • unwrap lines.
    • use GB_end_transaction.
    • whitespace fixes.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
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
24class SQ_physical_layout {
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
36public:
37    SQ_physical_layout();
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
43SQ_physical_layout::SQ_physical_layout() {
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
54int SQ_physical_layout::roundme(double value) {
55    int x;
56    value += 0.5;
57    x = (int) floor(value);
58    return x;
59}
60
61void SQ_physical_layout::SQ_calc_physical_layout(const char *sequence, int size, GBDATA *gb_quality_ali) {
62    count_bases = size;
63
64    for (int i = 0; i < size; i++) {
65        switch (sequence[i]) {
66        case '-': // calculate number of dots and spaces
67            count_bases--;
68            count_scores++;
69            break;
70        case '.':
71            count_bases--;
72            count_dots++;
73            break;
74        case 'G': // calculate GC layout of sequence
75        case 'g':
76            GC++;
77            break;
78        case 'C':
79        case 'c':
80            GC++;
81            break;
82        }
83    }
84
85    // calculate layout in percent
86    if (GC != 0) {
87        GC_proportion = GC / count_bases;
88    }
89    temp = 100 - (100 * ((count_scores + count_dots) / size));
90    percent_bases = roundme(temp);
91    count_bases2 = roundme(count_bases);
92
93    GBDATA *gb_result1 = GB_search(gb_quality_ali, "number_of_bases", GB_INT);
94    seq_assert(gb_result1);
95    GB_write_int(gb_result1, count_bases2);
96
97    GBDATA *gb_result2 = GB_search(gb_quality_ali, "percent_of_bases", GB_INT);
98    seq_assert(gb_result2);
99    GB_write_int(gb_result2, percent_bases);
100
101    GBDATA *gb_result3 = GB_search(gb_quality_ali, "GC_proportion", GB_FLOAT);
102    seq_assert(gb_result3);
103    GB_write_float(gb_result3, GC_proportion);
104}
105
106inline int SQ_physical_layout::SQ_get_number_of_bases() const {
107    int i;
108    i = count_bases2;
109    return i;
110}
111
112inline double SQ_physical_layout::SQ_get_gc_proportion() const {
113    double i;
114    i = GC_proportion;
115    return i;
116}
Note: See TracBrowser for help on using the repository browser.