~ubuntu-branches/ubuntu/precise/libbpp-phyl/precise

« back to all changes in this revision

Viewing changes to src/Bpp/Phyl/Model/CodonAsynonymousFrequenciesReversibleSubstitutionModel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Dutheil
  • Date: 2011-06-09 11:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110609110000-yvx78svv6w7xxgph
Tags: upstream-2.0.2
Import upstream version 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// File: CodonAsynonymousFrequenciesReversibleSubstitutionModel.cpp
 
3
// Created by:  Laurent Gueguen
 
4
// Created on: Feb 2009
 
5
//
 
6
 
 
7
/*
 
8
   Copyright or © or Copr. CNRS, (November 16, 2004)
 
9
   This software is a computer program whose purpose is to provide classes
 
10
   for phylogenetic data analysis.
 
11
 
 
12
   This software is governed by the CeCILL  license under French law and
 
13
   abiding by the rules of distribution of free software.  You can  use,
 
14
   modify and/ or redistribute the software under the terms of the CeCILL
 
15
   license as circulated by CEA, CNRS and INRIA at the following URL
 
16
   "http://www.cecill.info".
 
17
 
 
18
   As a counterpart to the access to the source code and  rights to copy,
 
19
   modify and redistribute granted by the license, users are provided only
 
20
   with a limited warranty  and the software's author,  the holder of the
 
21
   economic rights,  and the successive licensors  have only  limited
 
22
   liability.
 
23
 
 
24
   In this respect, the user's attention is drawn to the risks associated
 
25
   with loading,  using,  modifying and/or developing or reproducing the
 
26
   software by the user in light of its specific status of free software,
 
27
   that may mean  that it is complicated to manipulate,  and  that  also
 
28
   therefore means  that it is reserved for developers  and  experienced
 
29
   professionals having in-depth computer knowledge. Users are therefore
 
30
   encouraged to load and test the software's suitability as regards their
 
31
   requirements in conditions enabling the security of their systems and/or
 
32
   data to be ensured and,  more generally, to use and operate it in the
 
33
   same conditions as regards security.
 
34
 
 
35
   The fact that you are presently reading this means that you have had
 
36
   knowledge of the CeCILL license and that you accept its terms.
 
37
 */
 
38
 
 
39
#include "CodonAsynonymousFrequenciesReversibleSubstitutionModel.h"
 
40
 
 
41
using namespace bpp;
 
42
 
 
43
using namespace std;
 
44
 
 
45
/******************************************************************************/
 
46
 
 
47
CodonAsynonymousFrequenciesReversibleSubstitutionModel::CodonAsynonymousFrequenciesReversibleSubstitutionModel(
 
48
  const GeneticCode* palph,
 
49
  FrequenciesSet* pfreq,
 
50
  const AlphabetIndex2<double>* pdist) throw (Exception) :
 
51
  AbstractCodonFrequenciesReversibleSubstitutionModel(
 
52
    dynamic_cast<const CodonAlphabet*>(palph->getSourceAlphabet()),
 
53
    pfreq,
 
54
    "CodonAsynonymousFrequencies."),
 
55
  geneticCode_(palph),
 
56
  pdistance_(pdist)
 
57
{
 
58
  if (pdistance_)
 
59
    addParameter_(Parameter("CodonAsynonymousFrequencies.alpha", 10000, &Parameter::R_PLUS_STAR));
 
60
 
 
61
  addParameter_(Parameter("CodonAsynonymousFrequencies.beta", 1, &Parameter::R_PLUS_STAR));
 
62
  updateMatrices();
 
63
}
 
64
 
 
65
string CodonAsynonymousFrequenciesReversibleSubstitutionModel::getName() const
 
66
{
 
67
  return "CodonAsynonymousFrequenciesReversibleSubstitutionModel model : " + pfreqset_->getName();
 
68
}
 
69
 
 
70
void CodonAsynonymousFrequenciesReversibleSubstitutionModel::completeMatrices()
 
71
{
 
72
  unsigned int i, j;
 
73
  unsigned int salph = getNumberOfStates();
 
74
  double alpha = pdistance_ ? getParameterValue("alpha") : 1;
 
75
  double beta = getParameterValue("beta");
 
76
  const CodonAlphabet* ca = dynamic_cast<const CodonAlphabet*>(geneticCode_->getSourceAlphabet());
 
77
 
 
78
  for (i = 0; i < salph; i++)
 
79
  {
 
80
    for (j = 0; j < salph; j++)
 
81
    {
 
82
      if (i != j)
 
83
      {
 
84
        if (ca->isStop(j) || ca->isStop(i))
 
85
        {
 
86
          generator_(i,j) = 0;
 
87
          exchangeability_(i,j) = 0;
 
88
        }
 
89
        else
 
90
        {
 
91
          if (!geneticCode_->areSynonymous(i,j))
 
92
          {
 
93
            generator_(i,j) *= beta * (pdistance_ ? exp(-pdistance_->getIndex(geneticCode_->translate(i), geneticCode_->translate(j)) / alpha) : 1);
 
94
            exchangeability_(i,j) *= beta * (pdistance_ ? exp(-pdistance_->getIndex(geneticCode_->translate(i), geneticCode_->translate(j)) / alpha) : 1);
 
95
          }
 
96
        }
 
97
      }
 
98
    }
 
99
  }
 
100
 
 
101
  AbstractCodonFrequenciesReversibleSubstitutionModel::completeMatrices();
 
102
}
 
103