Egglib 2.1.11
C++ library reference manual
LinkageDisequilibrium.hpp
1 /*
2  Copyright 2009 Stéphane De Mita, Mathieu Siol
3 
4  This file is part of the EggLib library.
5 
6  EggLib is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  EggLib is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with EggLib. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef EGGLIB_LINKAGEDISEQUILIBRUM_HPP
21 #define EGGLIB_LINKAGEDISEQUILIBRUM_HPP
22 
23 
24 #include "BaseDiversity.hpp"
25 #include "EggException.hpp"
26 
27 
28 namespace egglib {
29 
44 
45  public:
46 
49 
51  virtual ~LinkageDisequilibrium();
52 
90  void load(CharMatrix& data,
91  double minimumExploitableData=1.,
92  unsigned int ignoreFrequency=0,
93  std::string characterMapping=dnaMapping);
94 
95 
97  unsigned int numberOfPairs() const;
98 
100  int d(unsigned int pair_index);
101 
103  double D(unsigned int pair_index);
104 
106  double Dp(unsigned int pair_index);
107 
109  double r(unsigned int pair_index);
110 
112  double r2(unsigned int pair_index);
113 
115  unsigned int site1(unsigned int pair_index);
116 
118  unsigned int site2(unsigned int pair_index);
119 
121  double correl() const;
122 
140  unsigned int Rmin(CharMatrix& data) const;
141 
142 
143 
144  protected:
145 
146  // adds a pair of polymorphic sites
147  // assume position2>position1,
148  // sites are polymorphic with exactly 2 alleles
149  void add(CharMatrix& data, unsigned int position1, unsigned int position2);
150 
151  // Constructor help
152  void init();
153 
154  // Destructor helper
155  void clear();
156 
157  // Resizes arrays
158  void reset();
159 
160  // Small helper
161  inline double min(double a, double b) { return (a>b)?a:b;}
162 
163  // Small helper
164  inline double max(double a, double b) { return (a>b)?b:a;}
165 
166  // Small helper
167  inline void check(unsigned int pos) { if (pos>=_n) throw EggRuntimeError("tried to access an invalid index"); }
168 
169  /* Performs correlation
170  *
171  * This function works independently from the rest of the class.
172  *
173  * \param n length of data arrays.
174  * \param x first data vector.
175  * \param y second data vector.
176  * \param r variable to receive the correlation coefficient.
177  * \param a variable to receive the regression slope.
178  */
179  static void _correl(unsigned int n, const int* x, const double* y, double& r, double& a);
180 
181  // Distance between pairs
182  int* _d;
183 
184  // D (classical) measure of LD
185  double *_D;
186 
187  // D'
188  double *_Dp;
189 
190  // r, correlation coefficient
191  double *_r;
192 
193  // square r
194  double *_r2;
195 
196  // Data array (not managed by the instance)
197  unsigned int *_site1;
198 
199  // Data array (not managed by the instance)
200  unsigned int *_site2;
201 
202  // Number of pairs
203  unsigned int _n;
204 
205  private:
206 
209 
211  LinkageDisequilibrium& operator=(const LinkageDisequilibrium&) {
212  return *this;
213  }
214 
215 
216  class Interval {
217  public:
218  Interval(unsigned int, unsigned int);
219  unsigned int a() const;
220  unsigned int b() const;
221  bool good() const;
222  void set_false();
223  private:
224  unsigned int _a;
225  unsigned int _b;
226  unsigned int _good;
227  };
228 
229 
230  };
231 }
232 
233 #endif
Exception type for runtime errors.
Definition: EggException.hpp:86
Base class of diversity classes.
Definition: BaseDiversity.hpp:60
double correl() const
correlation coefficient between r2 and distance
Definition: LinkageDisequilibrium.cpp:210
unsigned int site1(unsigned int pair_index)
position of the first site for a given pair
Definition: LinkageDisequilibrium.cpp:200
Analyzes linkage disequilibrium per pair of polymorphic sites.
Definition: LinkageDisequilibrium.hpp:43
double r(unsigned int pair_index)
r statistic for a given pair
Definition: LinkageDisequilibrium.cpp:190
unsigned int site2(unsigned int pair_index)
position of the second site for a given pair
Definition: LinkageDisequilibrium.cpp:205
unsigned int Rmin(CharMatrix &data) const
Computes the minimal number of recombination events.
Definition: LinkageDisequilibrium.cpp:248
void load(CharMatrix &data, double minimumExploitableData=1., unsigned int ignoreFrequency=0, std::string characterMapping=dnaMapping)
Analyzes polymorphic sites of an alignment.
Definition: LinkageDisequilibrium.cpp:86
double Dp(unsigned int pair_index)
D' statistic for a given pair.
Definition: LinkageDisequilibrium.cpp:185
virtual ~LinkageDisequilibrium()
Destructor.
Definition: LinkageDisequilibrium.cpp:79
unsigned int numberOfPairs() const
Number of pairs contained in the instance.
Definition: LinkageDisequilibrium.cpp:171
LinkageDisequilibrium()
Default constructor.
Definition: LinkageDisequilibrium.cpp:74
double r2(unsigned int pair_index)
r2 statistic for a given pair
Definition: LinkageDisequilibrium.cpp:195
double D(unsigned int pair_index)
D statistic for a given pair.
Definition: LinkageDisequilibrium.cpp:180
Definition: ABC.cpp:37
static const std::string dnaMapping
Predefined mapping string for DNA data.
Definition: BaseDiversity.hpp:98
int d(unsigned int pair_index)
Alignment distance between a given pair.
Definition: LinkageDisequilibrium.cpp:175
void reset()
Clears and re-initializes object.
Definition: LinkageDisequilibrium.cpp:44
Interface for classes usable as a square matrix of characters.
Definition: CharMatrix.hpp:31

Hosted by 
Get EggLib at SourceForge.net. Fast, secure and Free Open Source software downloads