bpp-phyl3  3.0.0
EvolutionSequenceSimulator.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
6 
7 #include "../Likelihood/AutoCorrelationSequenceEvolution.h"
8 #include "../Likelihood/HmmSequenceEvolution.h"
9 #include "../Likelihood/MixtureSequenceEvolution.h"
10 #include "../Likelihood/OneProcessSequenceEvolution.h"
11 #include "../Likelihood/PartitionSequenceEvolution.h"
13 
14 using namespace bpp;
15 using namespace std;
16 
17 /******************************************************************************/
18 
21  seqEvol_(&evol)
22 {}
23 
24 /******************************************************************************/
25 
26 void EvolutionSequenceSimulator::resetSiteSimulators(size_t numberOfSites) const
27 {
28  vMap_.resize(numberOfSites);
29 
30  const OneProcessSequenceEvolution* opse = dynamic_cast<const OneProcessSequenceEvolution*>(seqEvol_);
31 
32  if (opse)
33  {
34  size_t nProc = opse->getSubstitutionProcessNumbers()[0];
35  for (size_t i = 0; i < numberOfSites; i++)
36  {
37  vMap_[i] = nProc;
38  }
39  }
40  else
41  {
42  const PartitionSequenceEvolution* pse = dynamic_cast<const PartitionSequenceEvolution*>(seqEvol_);
43 
44  if (pse)
45  {
46  if (numberOfSites > pse->getNumberOfSites())
47  throw IndexOutOfBoundsException("EvolutionSequenceSimulator::resetSiteSimulators", numberOfSites, 0, pse->getNumberOfSites());
48 
49  for (size_t i = 0; i < numberOfSites; i++)
50  {
52  }
53  }
54 
55  else
56  {
57  const vector<size_t> nProc = seqEvol_->getSubstitutionProcessNumbers();
58 
59  const MixtureSequenceEvolution* mse = dynamic_cast<const MixtureSequenceEvolution*>(seqEvol_);
60 
61  if (mse)
62  {
63  const vector<double>& vprob = mse->getSubProcessProbabilities();
64 
65  RandomTools::getSample(nProc, vprob, vMap_, true);
66  }
67  else
68  {
69  const AbstractHmmTransitionMatrix* htm = 0;
70 
72 
73  if (ase)
74  htm = &ase->hmmTransitionMatrix();
75 
76  const HmmSequenceEvolution* hse = dynamic_cast<const HmmSequenceEvolution*>(seqEvol_);
77 
78  if (hse)
79  htm = &hse->hmmTransitionMatrix();
80  if (htm)
81  {
82  vector<size_t> vInd = htm->sample(numberOfSites);
83  for (size_t i = 0; i < numberOfSites; i++)
84  {
85  vMap_[i] = nProc[vInd[i]];
86  }
87  }
88  else
89  throw Exception("EvolutionSequenceSimulator::resetSiteSimulators : unknown Sequence Evolution.");
90  }
91  }
92  }
93 }
std::vector< size_t > sample(size_t size) const
Sequence evolution framework based on an auto-correlation of substitution processes.
const AutoCorrelationTransitionMatrix & hmmTransitionMatrix() const
EvolutionSequenceSimulator(const SequenceEvolution &evol)
void resetSiteSimulators(size_t numberOfSites) const
Reset the succession of site simulators (useful in case of HMM).
Sequence evolution framework based on a hmm.
const FullHmmTransitionMatrix & hmmTransitionMatrix() const
Sequence evolution framework based on a mixture of substitution processes.
const std::vector< double > & getSubProcessProbabilities() const
Evolution of a sequence performed by a unique SubstitutionProcess all along the sequence.
const std::vector< size_t > & getSubstitutionProcessNumbers() const override
Sequence evolution framework based on a mixture of substitution processes.
size_t getSubstitutionProcessNumber(size_t i) const
static void getSample(const std::vector< T > &vin, std::vector< T > &vout, bool replace=false)
This interface describes the evolution process of a sequence.
virtual const std::vector< size_t > & getSubstitutionProcessNumbers() const =0
Sequences simulation under position specific substitution process.
std::vector< size_t > vMap_
The vector of the site specific process in mProcess_; is mutable because can be changed for each simu...
Defines the basic types of data flow nodes.