bpp-phyl3  3.0.0
bpp::DRASDRTreeLikelihoodData Class Reference

Likelihood data structure for rate across sites models, using a double-recursive algorithm. More...

#include <Bpp/Phyl/Legacy/Likelihood/DRASDRTreeLikelihoodData.h>

+ Inheritance diagram for bpp::DRASDRTreeLikelihoodData:
+ Collaboration diagram for bpp::DRASDRTreeLikelihoodData:

Public Member Functions

 DRASDRTreeLikelihoodData (std::shared_ptr< const TreeTemplate< Node >> tree, size_t nbClasses)
 
 DRASDRTreeLikelihoodData (const DRASDRTreeLikelihoodData &data)
 
DRASDRTreeLikelihoodDataoperator= (const DRASDRTreeLikelihoodData &data)
 
virtual ~DRASDRTreeLikelihoodData ()
 
DRASDRTreeLikelihoodDataclone () const
 
void setTree (std::shared_ptr< const TreeTemplate< Node >> tree)
 Set the tree associated to the data. More...
 
DRASDRTreeLikelihoodNodeDatagetNodeData (int nodeId)
 
const DRASDRTreeLikelihoodNodeDatagetNodeData (int nodeId) const
 
DRASDRTreeLikelihoodLeafDatagetLeafData (int nodeId)
 
const DRASDRTreeLikelihoodLeafDatagetLeafData (int nodeId) const
 
size_t getArrayPosition (int parentId, int sonId, size_t currentPosition) const
 
const std::map< int, VVVdouble > & getLikelihoodArrays (int nodeId) const
 
std::map< int, VVVdouble > & getLikelihoodArrays (int nodeId)
 
VVVdoublegetLikelihoodArray (int parentId, int neighborId)
 
const VVVdoublegetLikelihoodArray (int parentId, int neighborId) const
 
VdoublegetDLikelihoodArray (int nodeId)
 
const VdoublegetDLikelihoodArray (int nodeId) const
 
VdoublegetD2LikelihoodArray (int nodeId)
 
const VdoublegetD2LikelihoodArray (int nodeId) const
 
VVdoublegetLeafLikelihoods (int nodeId)
 
const VVdoublegetLeafLikelihoods (int nodeId) const
 
VVVdoublegetRootLikelihoodArray ()
 
const VVVdoublegetRootLikelihoodArray () const
 
VVdoublegetRootSiteLikelihoodArray ()
 
const VVdoublegetRootSiteLikelihoodArray () const
 
VdoublegetRootRateSiteLikelihoodArray ()
 
const VdoublegetRootRateSiteLikelihoodArray () const
 
size_t getNumberOfDistinctSites () const
 
size_t getNumberOfSites () const
 
size_t getNumberOfStates () const
 
size_t getNumberOfClasses () const
 
std::shared_ptr< const AlignmentDataInterfacegetShrunkData () const
 
const AlignmentDataInterfaceshrunkData () const
 
void initLikelihoods (const AlignmentDataInterface &sites, const TransitionModelInterface &model)
 Resize and initialize all likelihood arrays according to the given data set and substitution model. More...
 
void reInit ()
 Rebuild likelihood arrays at inner nodes. More...
 
void reInit (const Node *node)
 
std::vector< size_t > & getRootArrayPositions ()
 
const std::vector< size_t > & getRootArrayPositions () const
 
size_t getRootArrayPosition (const size_t site) const
 
unsigned int getWeight (size_t pos) const
 
const std::vector< unsigned int > & getWeights () const
 
std::shared_ptr< const AlphabetgetAlphabet () const
 
std::shared_ptr< const TreeTemplate< Node > > getTree () const
 

Protected Member Functions

void initLikelihoods (const Node *node, const AlignmentDataInterface &sites, const TransitionModelInterface &model)
 This method initializes the leaves according to a sequence container. More...
 

Protected Attributes

std::vector< size_t > rootPatternLinks_
 Links between sites and patterns. More...
 
std::vector< unsigned int > rootWeights_
 The frequency of each site. More...
 
std::shared_ptr< const TreeTemplate< Node > > tree_
 
std::shared_ptr< const Alphabetalphabet_
 

Private Attributes

std::map< int, DRASDRTreeLikelihoodNodeDatanodeData_
 
std::map< int, DRASDRTreeLikelihoodLeafDataleafData_
 
VVVdouble rootLikelihoods_
 
VVdouble rootLikelihoodsS_
 
Vdouble rootLikelihoodsSR_
 
std::shared_ptr< AlignmentDataInterfaceshrunkData_
 
size_t nbSites_
 
size_t nbStates_
 
size_t nbClasses_
 
size_t nbDistinctSites_
 

Detailed Description

Likelihood data structure for rate across sites models, using a double-recursive algorithm.

Definition at line 183 of file DRASDRTreeLikelihoodData.h.

Constructor & Destructor Documentation

◆ DRASDRTreeLikelihoodData() [1/2]

bpp::DRASDRTreeLikelihoodData::DRASDRTreeLikelihoodData ( std::shared_ptr< const TreeTemplate< Node >>  tree,
size_t  nbClasses 
)
inline

Definition at line 200 of file DRASDRTreeLikelihoodData.h.

Referenced by clone().

◆ DRASDRTreeLikelihoodData() [2/2]

bpp::DRASDRTreeLikelihoodData::DRASDRTreeLikelihoodData ( const DRASDRTreeLikelihoodData data)
inline

Definition at line 206 of file DRASDRTreeLikelihoodData.h.

References shrunkData_.

◆ ~DRASDRTreeLikelihoodData()

virtual bpp::DRASDRTreeLikelihoodData::~DRASDRTreeLikelihoodData ( )
inlinevirtual

Definition at line 239 of file DRASDRTreeLikelihoodData.h.

Member Function Documentation

◆ clone()

DRASDRTreeLikelihoodData* bpp::DRASDRTreeLikelihoodData::clone ( ) const
inlinevirtual

Implements bpp::TreeLikelihoodData.

Definition at line 241 of file DRASDRTreeLikelihoodData.h.

References DRASDRTreeLikelihoodData().

◆ getAlphabet()

std::shared_ptr<const Alphabet> bpp::AbstractTreeLikelihoodData::getAlphabet ( ) const
inlinevirtualinherited

◆ getArrayPosition()

size_t bpp::DRASDRTreeLikelihoodData::getArrayPosition ( int  parentId,
int  sonId,
size_t  currentPosition 
) const
inlinevirtual

Implements bpp::TreeLikelihoodData.

Definition at line 288 of file DRASDRTreeLikelihoodData.h.

◆ getD2LikelihoodArray() [1/2]

Vdouble& bpp::DRASDRTreeLikelihoodData::getD2LikelihoodArray ( int  nodeId)
inline

Definition at line 323 of file DRASDRTreeLikelihoodData.h.

References nodeData_.

◆ getD2LikelihoodArray() [2/2]

const Vdouble& bpp::DRASDRTreeLikelihoodData::getD2LikelihoodArray ( int  nodeId) const
inline

Definition at line 328 of file DRASDRTreeLikelihoodData.h.

References nodeData_.

◆ getDLikelihoodArray() [1/2]

Vdouble& bpp::DRASDRTreeLikelihoodData::getDLikelihoodArray ( int  nodeId)
inline

Definition at line 313 of file DRASDRTreeLikelihoodData.h.

References nodeData_.

◆ getDLikelihoodArray() [2/2]

const Vdouble& bpp::DRASDRTreeLikelihoodData::getDLikelihoodArray ( int  nodeId) const
inline

Definition at line 318 of file DRASDRTreeLikelihoodData.h.

References nodeData_.

◆ getLeafData() [1/2]

DRASDRTreeLikelihoodLeafData& bpp::DRASDRTreeLikelihoodData::getLeafData ( int  nodeId)
inline

Definition at line 278 of file DRASDRTreeLikelihoodData.h.

References leafData_.

◆ getLeafData() [2/2]

const DRASDRTreeLikelihoodLeafData& bpp::DRASDRTreeLikelihoodData::getLeafData ( int  nodeId) const
inline

Definition at line 283 of file DRASDRTreeLikelihoodData.h.

References leafData_.

◆ getLeafLikelihoods() [1/2]

VVdouble& bpp::DRASDRTreeLikelihoodData::getLeafLikelihoods ( int  nodeId)
inline

◆ getLeafLikelihoods() [2/2]

const VVdouble& bpp::DRASDRTreeLikelihoodData::getLeafLikelihoods ( int  nodeId) const
inline

Definition at line 338 of file DRASDRTreeLikelihoodData.h.

References leafData_.

◆ getLikelihoodArray() [1/2]

VVVdouble& bpp::DRASDRTreeLikelihoodData::getLikelihoodArray ( int  parentId,
int  neighborId 
)
inline

Definition at line 303 of file DRASDRTreeLikelihoodData.h.

References nodeData_.

◆ getLikelihoodArray() [2/2]

const VVVdouble& bpp::DRASDRTreeLikelihoodData::getLikelihoodArray ( int  parentId,
int  neighborId 
) const
inline

Definition at line 308 of file DRASDRTreeLikelihoodData.h.

References nodeData_.

◆ getLikelihoodArrays() [1/2]

std::map<int, VVVdouble>& bpp::DRASDRTreeLikelihoodData::getLikelihoodArrays ( int  nodeId)
inline

Definition at line 298 of file DRASDRTreeLikelihoodData.h.

References nodeData_.

◆ getLikelihoodArrays() [2/2]

const std::map<int, VVVdouble>& bpp::DRASDRTreeLikelihoodData::getLikelihoodArrays ( int  nodeId) const
inline

Definition at line 293 of file DRASDRTreeLikelihoodData.h.

References nodeData_.

◆ getNodeData() [1/2]

DRASDRTreeLikelihoodNodeData& bpp::DRASDRTreeLikelihoodData::getNodeData ( int  nodeId)
inlinevirtual

Implements bpp::TreeLikelihoodData.

Definition at line 268 of file DRASDRTreeLikelihoodData.h.

References nodeData_.

Referenced by bpp::NNIHomogeneousTreeLikelihood::testNNI().

◆ getNodeData() [2/2]

const DRASDRTreeLikelihoodNodeData& bpp::DRASDRTreeLikelihoodData::getNodeData ( int  nodeId) const
inlinevirtual

Implements bpp::TreeLikelihoodData.

Definition at line 273 of file DRASDRTreeLikelihoodData.h.

References nodeData_.

◆ getNumberOfClasses()

size_t bpp::DRASDRTreeLikelihoodData::getNumberOfClasses ( ) const
inline

Definition at line 358 of file DRASDRTreeLikelihoodData.h.

References nbClasses_.

◆ getNumberOfDistinctSites()

size_t bpp::DRASDRTreeLikelihoodData::getNumberOfDistinctSites ( ) const
inlinevirtual
Returns
The number of non redundant patterns.

Implements bpp::TreeLikelihoodData.

Definition at line 352 of file DRASDRTreeLikelihoodData.h.

References nbDistinctSites_.

Referenced by bpp::DRTreeLikelihoodTools::getPosteriorProbabilitiesPerStatePerRate().

◆ getNumberOfSites()

size_t bpp::DRASDRTreeLikelihoodData::getNumberOfSites ( ) const
inlinevirtual
Returns
The total number of sites.

Implements bpp::TreeLikelihoodData.

Definition at line 354 of file DRASDRTreeLikelihoodData.h.

References nbSites_.

◆ getNumberOfStates()

size_t bpp::DRASDRTreeLikelihoodData::getNumberOfStates ( ) const
inlinevirtual
Returns
Get the number of states used in the model.

Implements bpp::TreeLikelihoodData.

Definition at line 356 of file DRASDRTreeLikelihoodData.h.

References nbStates_.

◆ getRootArrayPosition()

size_t bpp::AbstractTreeLikelihoodData::getRootArrayPosition ( const size_t  site) const
inlinevirtualinherited

◆ getRootArrayPositions() [1/2]

std::vector<size_t>& bpp::AbstractTreeLikelihoodData::getRootArrayPositions ( )
inlineinherited

◆ getRootArrayPositions() [2/2]

const std::vector<size_t>& bpp::AbstractTreeLikelihoodData::getRootArrayPositions ( ) const
inlineinherited

◆ getRootLikelihoodArray() [1/2]

VVVdouble& bpp::DRASDRTreeLikelihoodData::getRootLikelihoodArray ( )
inline

Definition at line 343 of file DRASDRTreeLikelihoodData.h.

References rootLikelihoods_.

◆ getRootLikelihoodArray() [2/2]

const VVVdouble& bpp::DRASDRTreeLikelihoodData::getRootLikelihoodArray ( ) const
inline

Definition at line 344 of file DRASDRTreeLikelihoodData.h.

References rootLikelihoods_.

◆ getRootRateSiteLikelihoodArray() [1/2]

Vdouble& bpp::DRASDRTreeLikelihoodData::getRootRateSiteLikelihoodArray ( )
inline

Definition at line 349 of file DRASDRTreeLikelihoodData.h.

References rootLikelihoodsSR_.

◆ getRootRateSiteLikelihoodArray() [2/2]

const Vdouble& bpp::DRASDRTreeLikelihoodData::getRootRateSiteLikelihoodArray ( ) const
inline

Definition at line 350 of file DRASDRTreeLikelihoodData.h.

References rootLikelihoodsSR_.

◆ getRootSiteLikelihoodArray() [1/2]

VVdouble& bpp::DRASDRTreeLikelihoodData::getRootSiteLikelihoodArray ( )
inline

Definition at line 346 of file DRASDRTreeLikelihoodData.h.

References rootLikelihoodsS_.

◆ getRootSiteLikelihoodArray() [2/2]

const VVdouble& bpp::DRASDRTreeLikelihoodData::getRootSiteLikelihoodArray ( ) const
inline

Definition at line 347 of file DRASDRTreeLikelihoodData.h.

References rootLikelihoodsS_.

◆ getShrunkData()

std::shared_ptr<const AlignmentDataInterface> bpp::DRASDRTreeLikelihoodData::getShrunkData ( ) const
inline

Definition at line 360 of file DRASDRTreeLikelihoodData.h.

References shrunkData_.

◆ getTree()

std::shared_ptr< const TreeTemplate<Node> > bpp::AbstractTreeLikelihoodData::getTree ( ) const
inlinevirtualinherited

◆ getWeight()

unsigned int bpp::AbstractTreeLikelihoodData::getWeight ( size_t  pos) const
inlinevirtualinherited
Returns
The frequency of a given pattern.

Implements bpp::TreeLikelihoodData.

Definition at line 91 of file AbstractTreeLikelihoodData.h.

References bpp::AbstractTreeLikelihoodData::rootWeights_.

Referenced by bpp::DRTreeLikelihoodTools::getPosteriorStateFrequencies().

◆ getWeights()

const std::vector<unsigned int>& bpp::AbstractTreeLikelihoodData::getWeights ( ) const
inlinevirtualinherited
Returns
Frequencies for each pattern.

Implements bpp::TreeLikelihoodData.

Definition at line 95 of file AbstractTreeLikelihoodData.h.

References bpp::AbstractTreeLikelihoodData::rootWeights_.

◆ initLikelihoods() [1/2]

void DRASDRTreeLikelihoodData::initLikelihoods ( const AlignmentDataInterface sites,
const TransitionModelInterface model 
)

Resize and initialize all likelihood arrays according to the given data set and substitution model.

Parameters
sitesThe sequences to use as data.
modelThe substitution model to use.
Exceptions
Exceptionif an error occurs.

Definition at line 16 of file DRASDRTreeLikelihoodData.cpp.

References bpp::BranchModelInterface::getAlphabet(), bpp::TemplateAlignmentDataInterface< class >::getAlphabet(), bpp::SitePatterns::getIndices(), bpp::TemplateAlignmentDataInterface< class >::getNumberOfSequences(), bpp::TemplateAlignmentDataInterface< class >::getNumberOfSites(), bpp::BranchModelInterface::getNumberOfStates(), bpp::SitePatterns::getSites(), and bpp::SitePatterns::getWeights().

◆ initLikelihoods() [2/2]

void DRASDRTreeLikelihoodData::initLikelihoods ( const Node node,
const AlignmentDataInterface sites,
const TransitionModelInterface model 
)
protected

This method initializes the leaves according to a sequence container.

Here the container shrunkData_ is used. Likelihood is set to 1 for the state corresponding to the sequence site, otherwise it is set to 0.

All likelihood arrays at each nodes are initialized according to alphabet size and sequences length, and filled with 1.

NB: This method is recursive.

Parameters
nodeThe node defining the subtree to analyse.
sitesThe sequence container to use.
modelThe model, used for initializing leaves' likelihoods.

Definition at line 68 of file DRASDRTreeLikelihoodData.cpp.

References bpp::BranchModelInterface::getAlphabetStateAsInt(), bpp::DRASDRTreeLikelihoodNodeData::getD2LikelihoodArray(), bpp::DRASDRTreeLikelihoodNodeData::getDLikelihoodArray(), bpp::Node::getId(), bpp::DRASDRTreeLikelihoodLeafData::getLikelihoodArray(), bpp::DRASDRTreeLikelihoodNodeData::getLikelihoodArrays(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::TemplateAlignmentDataInterface< class >::getSequencePosition(), bpp::Node::getSon(), bpp::TemplateAlignmentDataInterface< class >::getStateValueAt(), bpp::Node::hasFather(), bpp::Node::isLeaf(), bpp::DRASDRTreeLikelihoodLeafData::setNode(), and bpp::DRASDRTreeLikelihoodNodeData::setNode().

◆ operator=()

◆ reInit() [1/2]

void DRASDRTreeLikelihoodData::reInit ( )

Rebuild likelihood arrays at inner nodes.

This method is to be called when the topology of the tree has changed. Node arrays relationship are rebuilt according to the new topology of the tree. The leaves likelihood remain unchanged, so as for the first and second order derivatives.

Definition at line 176 of file DRASDRTreeLikelihoodData.cpp.

Referenced by bpp::NNIHomogeneousTreeLikelihood::topologyChangeTested().

◆ reInit() [2/2]

◆ setTree()

void bpp::DRASDRTreeLikelihoodData::setTree ( std::shared_ptr< const TreeTemplate< Node >>  tree)
inline

Set the tree associated to the data.

All node data will be actualized accordingly by calling the setNode() method on the corresponding nodes.

Warning
: the old tree and the new tree must be two clones! And particularly, they have to share the same topology and nodes id.
Parameters
treeThe tree to be associated to this data.

Definition at line 253 of file DRASDRTreeLikelihoodData.h.

References leafData_, nodeData_, and bpp::AbstractTreeLikelihoodData::tree_.

◆ shrunkData()

const AlignmentDataInterface& bpp::DRASDRTreeLikelihoodData::shrunkData ( ) const
inline

Definition at line 362 of file DRASDRTreeLikelihoodData.h.

References shrunkData_.

Member Data Documentation

◆ alphabet_

std::shared_ptr<const Alphabet> bpp::AbstractTreeLikelihoodData::alphabet_
protectedinherited

◆ leafData_

std::map<int, DRASDRTreeLikelihoodLeafData> bpp::DRASDRTreeLikelihoodData::leafData_
mutableprivate

Definition at line 188 of file DRASDRTreeLikelihoodData.h.

Referenced by getLeafData(), getLeafLikelihoods(), operator=(), and setTree().

◆ nbClasses_

size_t bpp::DRASDRTreeLikelihoodData::nbClasses_
private

Definition at line 196 of file DRASDRTreeLikelihoodData.h.

Referenced by getNumberOfClasses(), and operator=().

◆ nbDistinctSites_

size_t bpp::DRASDRTreeLikelihoodData::nbDistinctSites_
private

Definition at line 197 of file DRASDRTreeLikelihoodData.h.

Referenced by getNumberOfDistinctSites(), and operator=().

◆ nbSites_

size_t bpp::DRASDRTreeLikelihoodData::nbSites_
private

Definition at line 194 of file DRASDRTreeLikelihoodData.h.

Referenced by getNumberOfSites(), and operator=().

◆ nbStates_

size_t bpp::DRASDRTreeLikelihoodData::nbStates_
private

Definition at line 195 of file DRASDRTreeLikelihoodData.h.

Referenced by getNumberOfStates(), and operator=().

◆ nodeData_

std::map<int, DRASDRTreeLikelihoodNodeData> bpp::DRASDRTreeLikelihoodData::nodeData_
mutableprivate

◆ rootLikelihoods_

VVVdouble bpp::DRASDRTreeLikelihoodData::rootLikelihoods_
mutableprivate

Definition at line 189 of file DRASDRTreeLikelihoodData.h.

Referenced by getRootLikelihoodArray(), and operator=().

◆ rootLikelihoodsS_

VVdouble bpp::DRASDRTreeLikelihoodData::rootLikelihoodsS_
mutableprivate

Definition at line 190 of file DRASDRTreeLikelihoodData.h.

Referenced by getRootSiteLikelihoodArray(), and operator=().

◆ rootLikelihoodsSR_

Vdouble bpp::DRASDRTreeLikelihoodData::rootLikelihoodsSR_
mutableprivate

Definition at line 191 of file DRASDRTreeLikelihoodData.h.

Referenced by getRootRateSiteLikelihoodArray(), and operator=().

◆ rootPatternLinks_

std::vector<size_t> bpp::AbstractTreeLikelihoodData::rootPatternLinks_
protectedinherited

Links between sites and patterns.

The size of this vector is equal to the number of sites in the container, each element corresponds to a site in the container and points to the corresponding column in the likelihood array of the root node. If the container contains no repeated site, there will be a strict equivalence between each site and the likelihood array of the root node. However, if this is not the case, some pointers may point toward the same element in the likelihood array.

Definition at line 50 of file AbstractTreeLikelihoodData.h.

Referenced by bpp::AbstractTreeLikelihoodData::getRootArrayPosition(), bpp::DRASRTreeLikelihoodData::getRootArrayPosition(), bpp::AbstractTreeLikelihoodData::getRootArrayPositions(), and bpp::AbstractTreeLikelihoodData::operator=().

◆ rootWeights_

std::vector<unsigned int> bpp::AbstractTreeLikelihoodData::rootWeights_
protectedinherited

◆ shrunkData_

std::shared_ptr<AlignmentDataInterface> bpp::DRASDRTreeLikelihoodData::shrunkData_
private

◆ tree_

std::shared_ptr<const TreeTemplate<Node> > bpp::AbstractTreeLikelihoodData::tree_
protectedinherited

The documentation for this class was generated from the following files: