bpp-phyl3  3.0.0
HmmPhyloEmissionProbabilities.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 using namespace bpp;
8 using namespace std;
9 
10 HmmPhyloEmissionProbabilities::HmmPhyloEmissionProbabilities(std::shared_ptr<HmmPhyloAlphabet> alphabet) :
12  context_(alphabet->getContext()),
13  phylAlph_(alphabet),
14  emProb_(),
15  nbSites_(alphabet->getNumberOfSites())
16 {
17  setHmmStateAlphabet(alphabet);
18 }
19 
20 
21 void HmmPhyloEmissionProbabilities::setHmmStateAlphabet(std::shared_ptr<HmmStateAlphabet> stateAlphabet)
22 {
23  if (!stateAlphabet)
24  throw HmmUnvalidAlphabetException("Null alphabet in HmmPhyloEmissionProbabilities::setHmmStateAlphabet");
25  if (!dynamic_cast<const HmmPhyloAlphabet*>(stateAlphabet.get()))
26  throw HmmUnvalidAlphabetException("Non PhyloLikelihood alphabet in HmmPhyloEmissionProbabilities::setHmmStateAlphabet");
27 
28  phylAlph_ = dynamic_pointer_cast<HmmPhyloAlphabet>(stateAlphabet);
29 
30  std::vector<std::shared_ptr<Node_DF>> vEM;
31 
32  auto nbStates = phylAlph_->getNumberOfStates();
33 
34  for (size_t i = 0; i < nbStates; i++)
35  {
36  auto tmp = phylAlph_->alignedPhyloLikelihood(i).alignedLikelihoodCalculation().getSiteLikelihoods(false);
37  vEM.push_back(tmp);
38  }
39 
40  // Compound to put site log lik of different processes in a matrix
41 
42  emProb_ = EmissionLogk::create(context_, std::move(vEM), Dimension<MatrixLik>(Eigen::Index(nbStates), Eigen::Index(nbSites_)));
43 }
Hidden states alphabet.
HmmPhyloEmissionProbabilities(std::shared_ptr< HmmPhyloAlphabet > alphabet)
void setHmmStateAlphabet(std::shared_ptr< HmmStateAlphabet > stateAlphabet)
Set the new hidden state alphabet.
std::shared_ptr< HmmPhyloAlphabet > phylAlph_
Defines the basic types of data flow nodes.
Store a dimension for type T.