source: tags/ms_r16q2/PRIMER_DESIGN/PRD_Design.hxx

Last change on this file was 8902, checked in by westram, 12 years ago
  • fixed cppcheck warnings
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : PRD_Design.hxx                                    //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Coded by Wolfram Foerster in February 2001                    //
7//   Institute of Microbiology (Technical University Munich)       //
8//   http://www.arb-home.de/                                       //
9//                                                                 //
10// =============================================================== //
11
12#ifndef PRD_DESIGN_HXX
13#define PRD_DESIGN_HXX
14
15#include "PRD_Range.hxx"
16#include "PRD_Node.hxx"
17#include "PRD_Pair.hxx"
18
19#include <deque>
20
21#ifndef ARBDB_H
22#include <arbdb.h>
23#endif
24
25#if defined(DEBUG)
26// # define DUMP_PRIMER
27#endif
28
29class PrimerDesign : virtual Noncopyable {
30    // zu untersuchendes Genom
31    // sequence of bases/spaces to be examined
32
33    const char* sequence;
34    long int    seqLength;
35
36    // Laenge der Primer (Anzahl der enthaltenen Basen)
37    // count of bases of primers (min/max)
38    Range primer_length;
39
40    // Position der Primer ( [min,max) )
41    // left/right position of primers
42
43    Range primer1;
44    Range primer2;
45
46    // Abstand der Primer (bzgl. der Basen dazwischen, <=0 = ignorieren)
47    // min/max distance of primers (regarding number of bases between, <=0 = ignore)
48
49    Range primer_distance;
50
51    // maximale Anzahl zurueckzuliefernder Primerpaare
52    // max. count of returned primer pairs
53
54    int   max_count_primerpairs;
55
56    // GC-Verhaeltniss der Primer in Prozent <=0 = ignorieren
57    // GC-ratio of primers in percent <=0 = ignore
58    // [ ratio = (G+C)/Basen ]
59
60    Range GC_ratio;
61
62    // Temperatur der Primer <=0 = ignorieren
63    // temperature of primers <=0 = ignore
64    // [ temperature = 4*(G+C) + 2*(A+T) ]
65
66    Range temperature;
67
68    // Faktoren zur Gewichtung von CG-Verhaeltniss und Temperatur bei der Bewertung von Primerpaaren
69    // factors to assess the GC-ratio and temperature at the evaluation of primerpairs
70    // [ 0.0 .. 1.0 ]
71
72    double GC_factor;
73    double temperature_factor;
74
75    // wird ein Primer ausserhalb dieser Distanz nocheinmal gefunden wird das Vorkommen ignoriert ( <= 0 = eindeutig )
76    // is a primer found again out of this range its occurrence is ignored ( <=0 = explicit match )
77
78    int  min_distance_to_next_match;
79
80    // erweitern der IUPAC-Codes beim matching der sequence gegen die primerbaeume ?
81    // expand IUPAC-Codes while matching sequence vs. primertrees ?
82
83    bool expand_IUPAC_Codes;
84
85
86    //
87    // INTERNAL STUFF
88    //
89    static const int FORWARD  =  1;
90    static const int BACKWARD = -1;
91
92    // primertrees
93    Node* root1;
94    Node* root2;
95
96    // primerlists
97    Item* list1;
98    Item* list2;
99
100    // primerpairs
101    Pair* pairs;
102
103    GB_ERROR error;
104
105    unsigned long int total_node_counter_left;
106    unsigned long int total_node_counter_right;
107    unsigned long int primer_node_counter_left;
108    unsigned long int primer_node_counter_right;
109
110    void reset_node_counters() {
111        total_node_counter_left   = 0;
112        total_node_counter_right  = 0;
113        primer_node_counter_left  = 0;
114        primer_node_counter_right = 0;
115    }
116
117public:
118    PrimerDesign(const char *sequence_, long int seqLength_,
119                 Range       pos1_, Range pos2_, Range length_, Range distance_,
120                  Range       ratio_, Range temperature_, int min_dist_to_next_, bool expand_IUPAC_Codes_,
121                  int         max_count_primerpairs_, double GC_factor_, double temp_factor_);
122    PrimerDesign(const char *sequence_, long int seqLength_,
123                  Range       pos1_, Range pos2_, Range length_, Range distance_,
124                  int         max_count_primerpairs_, double GC_factor_, double temp_factor_);
125
126    PrimerDesign(const char *sequence_, long int seqLength_);
127    ~PrimerDesign();
128
129    void setPositionalParameters (Range pos1_, Range pos2_, Range length_, Range distance_);
130    void setConditionalParameters(Range ratio_, Range temperature_, int min_dist_to_next_, bool expand_IUPAC_Codes_, int max_count_primerpairs_, double GC_factor_, double temp_factor_);
131
132    void buildPrimerTrees ();
133    void matchSequenceAgainstPrimerTrees ();
134    void convertTreesToLists ();
135    void evaluatePrimerPairs ();
136   
137#if defined(DUMP_PRIMER)
138    void printPrimerTrees ();
139    void printPrimerLists    ();
140    void printPrimerPairs    ();
141#endif
142
143    void run();
144
145    GB_ERROR get_error() const { return error; }
146
147    PRD_Sequence_Pos  get_max_primer_length() const { return primer_length.max(); }
148    PRD_Sequence_Pos  get_max_primer_pos()    const { return primer2.max(); }
149    const char       *get_result(int num, const char *&primers, int max_primer_length, int max_position_length, int max_length_length) const;   // return 0 if no more results (primers is set to "leftPrimer,rightPrimer")
150
151public:
152    static const int PRINT_RAW_TREES     = 1;
153    static const int PRINT_MATCHED_TREES = 2;
154    static const int PRINT_PRIMER_LISTS  = 4;
155    static const int PRINT_PRIMER_PAIRS  = 8;
156
157private:
158    void             init               (const char *sequence_, long int seqLength_, Range pos1_, Range pos2_, Range length_, Range distance_, Range ratio_, Range temperature_, int min_dist_to_next_, bool expand_IUPAC_Codes_, int max_count_primerpairs_, double GC_factor_, double temp_factor_);
159    PRD_Sequence_Pos followUp           (Node *node_, std::deque<char> *primer_, int direction_);
160    void             findNextPrimer     (Node *start_at_, int depth_, int *counter_, int delivered_);
161    int              insertNode         (Node *current_, unsigned char base_, PRD_Sequence_Pos pos_, int delivered_, int offset_, int left_, int right_);
162    void             clearTree          (Node *start, int left_, int right_);
163    bool             treeContainsPrimer (Node *start);
164    void             calcGCandAT        (int &GC_, int &AT_, Node *start_at_);
165    double           evaluatePair       (Item *one_, Item *two_);
166    void             insertPair         (double rating_, Item *one_, Item *two_);
167};
168
169#else
170#error PRD_Design.hxx included twice
171#endif // PRD_DESIGN_HXX
Note: See TracBrowser for help on using the repository browser.