mapgd  0.4
A program for the Maximum-likelihood analysis of population genomic data.
 All Data Structures Functions Variables Friends Groups Pages
models.h
1 #ifndef _MODELS_H_
2 #define _MODELS_H_
3 /*****************************************************************************/
13 #include <cmath>
14 
15 #include "lnmultinomial.h"
16 #include "data_types/allele.h"
17 #include "typedef.h"
18 #include "quartet.h"
19 #include "locus.h"
20 
21 class models{
22 private:
23 lnmultinomial lnMM_, lnMm_, lnmm_;
24  // The '4' specifies the number of categories of the distribution.
25  // Since these represent the distribution of the four nucleotides
26  // A, C, G and T, we use 4 categories.
27 lnmultinomial lnMMP_, lnMmP_, lnmmP_;
28 
29 float_t E0_, E1_, E2_;
30 public:
31 
32  models(void);
33  ~models(void);
34 
36  float_t loglikelihood(const Locus &, const Allele &);
37 
39  float_t goodness_of_fit (Locus &, const Allele &, std::vector <float_t> &, const float_t &);
40 
42  void init_gof(const count_t *, const Allele &);
43 
45  float_t get_gof(const count_t *, const Allele &);
46 
48  float_t genotypelikelihood(const quartet_t &, const Allele &);
49 
51  inline float_t lnL(const float_t &logMM, const float_t &logMm, const float &logmm, const count_t *count){
52  /*posterior = prior x likelihood */
53  E0_=logMM+lnMMP_.lnprob(count);
54  E1_=logMm+lnMmP_.lnprob(count);
55  E2_=logmm+lnmmP_.lnprob(count);
56 
57  if (E0_>E2_) std::swap(E2_, E0_);
58  if (E1_>E2_) std::swap(E2_, E1_);
59 
60  //We make E2 the largest (i.e. least negative) value of the three. E0 and E1 will often times be
61  //extreamly small, and can even be negative infinity. So we are basically just ensuring that we
62  //don't throw away a lot of precission by returning log(exp(E2) ).
63 
64  return log(exp(E0_-E2_)+exp(E1_-E2_)+1.)+E2_;
65  }
66 
67  models& operator=(const models& rhs);
68 };
69 
71 float_t *mmModel(Allele *);
73 float_t *MmModel(Allele *);
75 float_t *MMModel(Allele *);
77 float_t *mmModelP(Allele *);
79 float_t *MmModelP(Allele *);
81 float_t *MMModelP(Allele *);
82 #endif
Definition: models.h:21
float_t lnL(const float_t &logMM, const float_t &logMm, const float &logmm, const count_t *count)
Clalculates goodness of fit likelihoods.
Definition: models.h:51
lnmultinomial lnmm_
The three multinomials we will use for probability calculations.
Definition: models.h:23
A class that stores quartet information.
Definition: quartet.h:16
float_t lnprob(const count_t *)
Returns the probability of the multinomial distribution.
Definition: lnmultinomial.cc:83
float_t loglikelihood(const Locus &, const Allele &)
Gets the log likelihood of the observations at Locus, given Allele.
Definition: models.cc:143
float_t genotypelikelihood(const quartet_t &, const Allele &)
Clalculates genotypic likelihoods. Not implement, may be depricated.
Definition: models.cc:181
void init_gof(const count_t *, const Allele &)
breif Initilizes the ? for goodness of fit calculations.
float_t goodness_of_fit(Locus &, const Allele &, std::vector< float_t > &, const float_t &)
Gets the log likelihood of the observations at Locus, given Allele.
Definition: models.cc:218
float_t get_gof(const count_t *, const Allele &)
Returns the likelihood of a ?? goodness of fit... blah blah blah.
Definition: lnmultinomial.h:24
Definition: locus.h:14
Summary statistics from the allele command.
Definition: allele.h:19
float_t E2_
Values used in calculations;.
Definition: models.h:29