bpp-phyl  2.2.0
NaiveSubstitutionCount.h
Go to the documentation of this file.
1 //
2 // File: NaiveSubstitutionCount.h
3 // Created by: Julien Dutheil
4 // Created on: Wed Apr 5 11:08 2006
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004, 2005, 2006)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _NAIVESUBSTITUTIONCOUNT_H_
41 #define _NAIVESUBSTITUTIONCOUNT_H_
42 
44 
45 #include <Bpp/Numeric/Matrix/Matrix.h>
46 
47 namespace bpp
48 {
49 
67  {
68  private:
69  bool allowSelf_;
70  std::vector<int> supportedChars_;
71 
72  public:
83  NaiveSubstitutionCount(const SubstitutionModel* model, SubstitutionRegister* reg, bool allowSelf = false, const AlphabetIndex2* weights = 0) :
85  AbstractWeightedSubstitutionCount(weights, true),
86  allowSelf_(allowSelf),
87  supportedChars_(model->getAlphabetStates()) {}
88 
90 
91  NaiveSubstitutionCount* clone() const { return new NaiveSubstitutionCount(*this); }
92 
93  public:
94  double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type = 1) const
95  {
96  if (initialState == finalState && !allowSelf_)
97  return 0;
98  else {
99  int alphabetState1 = supportedChars_[initialState];
100  int alphabetState2 = supportedChars_[finalState];
101  return (register_->getType(initialState, finalState) == type ? (weights_ ? weights_->getIndex(alphabetState1, alphabetState2) : 1.) : 0.);
102  }
103  }
104 
105  Matrix<double>* getAllNumbersOfSubstitutions(double length, size_t type = 1) const;
106 
107  std::vector<double> getNumberOfSubstitutionsForEachType(size_t initialState, size_t finalState, double length) const
108  {
109  std::vector<double> v(getNumberOfSubstitutionTypes());
110  for (size_t t = 1; t <= getNumberOfSubstitutionTypes(); ++t) {
111  v[t - 1] = getNumberOfSubstitutions(initialState, finalState, length, t);
112  }
113  return v;
114  }
115 
117  {
119  }
120 
121  private:
124 
125  };
126 
136  {
137  private:
138  LinearMatrix<double> label_;
139  std::vector<int> supportedChars_;
140 
141  public:
143 
145 
146  LabelSubstitutionCount* clone() const { return new LabelSubstitutionCount(*this); }
147 
148  public:
149  double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type = 1) const
150  {
151  return label_(initialState, finalState);
152  }
153 
154  Matrix<double>* getAllNumbersOfSubstitutions(double length, size_t type = 1) const
155  {
156  return dynamic_cast<Matrix<double>*>(label_.clone());
157  }
158 
159  std::vector<double> getNumberOfSubstitutionsForEachType(size_t initialState, size_t finalState, double length) const
160  {
161  std::vector<double> v(1);
162  v[0] = label_(initialState, finalState);
163  return v;
164  }
165 
167  {
169  }
170 
171  void setSubstitutionRegister(SubstitutionRegister* reg) throw (Exception) {
172  throw Exception("OneJumpSubstitutionCount::setSubstitutionRegister. This SubstitutionsCount only works with a TotalSubstitutionRegister.");
173  }
174 
175  private:
177 
178  };
179 
180 } //end of namespace bpp.
181 
182 #endif // _SIMPLESUBSTITUTIONCOUNT_H_
183 
Interface for all substitution models.
void setSubstitutionModel(const SubstitutionModel *model)
Set the substitution model associated with this count, if relevent.
std::auto_ptr< SubstitutionRegister > register_
LabelSubstitutionCount(const SubstitutionModel *model)
virtual const std::vector< int > & getAlphabetStates() const =0
std::vector< double > getNumberOfSubstitutionsForEachType(size_t initialState, size_t finalState, double length) const
Get the numbers of susbstitutions on a branch for all types, for an initial and final states...
Basic implementation of the the SubstitutionCount interface.
The SubstitutionRegister interface.
Matrix< double > * getAllNumbersOfSubstitutions(double length, size_t type=1) const
Get the numbers of susbstitutions on a branch, for each initial and final states, and given the branc...
std::vector< double > getNumberOfSubstitutionsForEachType(size_t initialState, size_t finalState, double length) const
Get the numbers of susbstitutions on a branch for all types, for an initial and final states...
void setSubstitutionModel(const SubstitutionModel *model)
Set the substitution model associated with this count, if relevent.
NaiveSubstitutionCount * clone() const
virtual size_t getNumberOfSubstitutionTypes() const
Short cut function, equivalent to getSubstitutionRegister().getNumberOfSubstitutionTypes().
LabelSubstitutionCount * clone() const
double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type=1) const
Get the number of susbstitutions on a branch, given the initial and final states, and the branch leng...
Labelling substitution count.
NaiveSubstitutionCount(const SubstitutionModel *model, SubstitutionRegister *reg, bool allowSelf=false, const AlphabetIndex2 *weights=0)
Build a new simple substitution count.
Naive substitution count.
double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type=1) const
Get the number of susbstitutions on a branch, given the initial and final states, and the branch leng...
void setSubstitutionRegister(SubstitutionRegister *reg)
Partial implementation of the WeightedSubstitutionCount interface.
Matrix< double > * getAllNumbersOfSubstitutions(double length, size_t type=1) const
Get the numbers of susbstitutions on a branch, for each initial and final states, and given the branc...