source: trunk/SL/CONSENSUS/consensus.h

Last change on this file was 14423, checked in by westram, 9 years ago
  • discard some todos
File size: 3.6 KB
Line 
1// ================================================================= //
2//                                                                   //
3//   File      : consensus.h                                         //
4//   Purpose   : interface for consensus calculation                 //
5//                                                                   //
6//   Coded by Ralf Westram (coder@reallysoft.de) in September 2015   //
7//   http://www.arb-home.de/                                         //
8//                                                                   //
9// ================================================================= //
10
11#ifndef CONSENSUS_H
12#define CONSENSUS_H
13
14#ifndef AW_BASE_HXX
15#include <aw_base.hxx>
16#endif
17#ifndef _GLIBCXX_ALGORITHM
18#include <algorithm>
19#endif
20
21#define CAS_INTERNAL -1
22#define CAS_NTREE    1
23#define CAS_EDIT4    2
24
25#ifndef CONSENSUS_AWAR_SOURCE
26# error you need to define CONSENSUS_AWAR_SOURCE before including consensus.h (allowed values: CAS_NTREE, CAS_EDIT4)
27#endif
28
29struct ConsensusBuildParams {
30    bool countgaps;   // count gaps? (otherwise they are completely ignored)
31    int  gapbound;    // limit in % for gaps. If more gaps occur -> '-'
32    bool group;       // whether to group characters (NUC: using ambiguous IUPAC codes; AMINO: using amino groups)
33    int  considbound; // limit in %. Bases occurring that often are used to create ambiguity codes (other bases are ignored). gaps are ignored when checking this limit.
34    int  upper;       // limit in %. If explicit base (or ambiguity code) occurs that often -> use upper case character
35    int  lower;       // limit in %. If explicit base (or ambiguity code) occurs that often -> use lower case character. Otherwise use '.'
36
37    static void force_in_range(int low, int& val, int high) {
38        val = std::min(std::max(low, val), high);
39    }
40
41    void make_valid() {
42        force_in_range(0, gapbound,    100);
43        force_in_range(0, considbound, 100);
44        force_in_range(0, upper,       100);
45        force_in_range(0, lower,       100);
46    }
47
48#if (CONSENSUS_AWAR_SOURCE == CAS_NTREE)
49    ConsensusBuildParams(AW_root *awr)
50        : countgaps  (awr->awar(AWAR_CONSENSUS_COUNTGAPS)->read_int()),
51          gapbound   (awr->awar(AWAR_CONSENSUS_GAPBOUND)->read_int()),
52          group      (awr->awar(AWAR_CONSENSUS_GROUP)->read_int()),
53          considbound(awr->awar(AWAR_CONSENSUS_CONSIDBOUND)->read_int()),
54          upper      (awr->awar(AWAR_CONSENSUS_UPPER)->read_int()),
55          lower      (awr->awar(AWAR_CONSENSUS_LOWER)->read_int())
56    {
57        make_valid();
58    }
59#else
60# if (CONSENSUS_AWAR_SOURCE == CAS_EDIT4)
61    ConsensusBuildParams(AW_root *awr)
62        : countgaps  (awr->awar(ED4_AWAR_CONSENSUS_COUNTGAPS)->read_int()),
63          gapbound   (awr->awar(ED4_AWAR_CONSENSUS_GAPBOUND)->read_int()),
64          group      (awr->awar(ED4_AWAR_CONSENSUS_GROUP)->read_int()),
65          considbound(awr->awar(ED4_AWAR_CONSENSUS_CONSIDBOUND)->read_int()),
66          upper      (awr->awar(ED4_AWAR_CONSENSUS_UPPER)->read_int()),
67          lower      (awr->awar(ED4_AWAR_CONSENSUS_LOWER)->read_int())
68    {
69        make_valid();
70    }
71# else
72#  if (CONSENSUS_AWAR_SOURCE == CAS_INTERNAL)
73    ConsensusBuildParams(AW_root *awr); // produce link error if used
74#  else
75#   error CONSENSUS_AWAR_SOURCE has invalid value
76#  endif
77# endif
78#endif
79
80#if defined(UNIT_TESTS) // UT_DIFF
81    ConsensusBuildParams() // uses defaults of EDIT4 awars
82        : countgaps(true),
83          gapbound(60),
84          group(1),
85          considbound(30),
86          upper(95),
87          lower(70)
88    {
89        make_valid();
90    }
91#endif
92};
93
94#else
95#error consensus.h included twice
96#endif // CONSENSUS_H
Note: See TracBrowser for help on using the repository browser.