bpp-phyl  2.4.0
SubstitutionCount.h
Go to the documentation of this file.
1 //
2 // File: SubstitutionCount.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 _SUBSTITUTIONCOUNT_H_
41 #define _SUBSTITUTIONCOUNT_H_
42 
43 #include "SubstitutionRegister.h"
45 #include "../Model/SubstitutionModel.h"
46 
48 
49 //From the STL:
50 #include <vector>
51 
52 namespace bpp
53 {
54 
72  public virtual Clonable
73  {
74  public:
76  virtual ~SubstitutionCount() {}
77  virtual SubstitutionCount* clone() const = 0;
78 
79  public:
83  virtual bool hasSubstitutionRegister() const = 0;
84 
88  virtual const SubstitutionRegister* getSubstitutionRegister() const = 0;
89 
94 
99  virtual void setSubstitutionRegister(SubstitutionRegister* reg) = 0;
100 
107 
113  virtual const Alphabet* getAlphabet() const { return getSubstitutionRegister()->getAlphabet(); }
114 
120  virtual size_t getNumberOfStates() const { return getSubstitutionRegister()->getAlphabet()->getSize(); }
121 
122 
133  virtual double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type) const = 0;
134 
142  virtual Matrix<double>* getAllNumbersOfSubstitutions(double length, size_t type) const = 0;
143 
152  virtual std::vector<double> getNumberOfSubstitutionsForEachType(size_t initialState, size_t finalState, double length) const = 0;
153 
159  virtual void setSubstitutionModel(const SubstitutionModel* model) = 0;
160  };
161 
168  public virtual SubstitutionCount
169  {
170  protected:
171  std::unique_ptr<SubstitutionRegister> register_;
172 
173  public:
175  register_(reg)
176  {}
177 
179  register_(asc.register_.get() ? asc.register_->clone() : 0)
180  {}
181 
183  if (asc.register_.get())
184  register_.reset(asc.register_->clone());
185  else
186  register_.reset();
187  return *this;
188  }
189 
191 
192  public:
193  bool hasSubstitutionRegister() const { return (register_.get() != 0); }
194 
203  register_.reset(reg);
204  substitutionRegisterHasChanged();
205  }
206 
207  const SubstitutionRegister* getSubstitutionRegister() const { return register_.get(); }
208 
209  SubstitutionRegister* getSubstitutionRegister() { return register_.get(); }
210 
211  protected:
212  virtual void substitutionRegisterHasChanged() = 0;
213  };
214 
215 } //end of namespace bpp.
216 
217 #endif //_SUBSTITUTIONCOUNT_H_
218 
const SubstitutionRegister * getSubstitutionRegister() const
Interface for all substitution models.
void setSubstitutionRegister(SubstitutionRegister *reg)
attribution of a SubstitutionRegister
AbstractSubstitutionCount & operator=(const AbstractSubstitutionCount &asc)
Basic implementation of the the SubstitutionCount interface.
The SubstitutionRegister interface.
virtual unsigned int getSize() const =0
virtual double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type) const =0
Get the number of susbstitutions on a branch, given the initial and final states, and the branch leng...
std::unique_ptr< SubstitutionRegister > register_
virtual SubstitutionCount * clone() const =0
virtual const SubstitutionRegister * getSubstitutionRegister() const =0
virtual const Alphabet * getAlphabet() const
Short cut function, equivalent to getSubstitutionRegister()->getAlphabet().
virtual std::vector< double > getNumberOfSubstitutionsForEachType(size_t initialState, size_t finalState, double length) const =0
Get the numbers of susbstitutions on a branch for all types, for an initial and final states...
AbstractSubstitutionCount(const AbstractSubstitutionCount &asc)
virtual size_t getNumberOfSubstitutionTypes() const
Short cut function, equivalent to getSubstitutionRegister().getNumberOfSubstitutionTypes().
The SubstitutionsCount interface.
virtual size_t getNumberOfSubstitutionTypes() const =0
SubstitutionRegister * getSubstitutionRegister()
AbstractSubstitutionCount(SubstitutionRegister *reg)
virtual bool hasSubstitutionRegister() const =0
virtual void setSubstitutionModel(const SubstitutionModel *model)=0
Set the substitution model associated with this count, if relevent.
virtual size_t getNumberOfStates() const
Short cut function, equivalent to getSubstitutionRegister()->getAlphabet()->getSize().
virtual Matrix< double > * getAllNumbersOfSubstitutions(double length, size_t type) const =0
Get the numbers of susbstitutions on a branch, for each initial and final states, and given the branc...
virtual void setSubstitutionRegister(SubstitutionRegister *reg)=0
virtual const Alphabet * getAlphabet() const =0