5 #include "../../PatternTools.h"
21 throw Exception(
"Error, only 1 sequence!");
26 throw AlphabetMismatchException(
"DRASDRTreeLikelihoodData::initLikelihoods. Data and model must have the same alphabet type.",
37 rootPatternLinks_.resize(
static_cast<size_t>(pattern.
getIndices().size()));
38 SitePatterns::IndicesType::Map(&rootPatternLinks_[0], pattern.
getIndices().size()) = pattern.
getIndices();
39 nbDistinctSites_ = shrunkData_->getNumberOfSites();
42 initLikelihoods(tree_->getRootNode(), *shrunkData_, model);
45 rootLikelihoods_.resize(nbDistinctSites_);
46 rootLikelihoodsS_.resize(nbDistinctSites_);
47 rootLikelihoodsSR_.resize(nbDistinctSites_);
48 for (
size_t i = 0; i < nbDistinctSites_; ++i)
50 VVdouble* rootLikelihoods_i_ = &rootLikelihoods_[i];
51 Vdouble* rootLikelihoodsS_i_ = &rootLikelihoodsS_[i];
52 rootLikelihoods_i_->resize(nbClasses_);
53 rootLikelihoodsS_i_->resize(nbClasses_);
54 for (
size_t c = 0; c < nbClasses_; c++)
56 Vdouble* rootLikelihoods_i_c_ = &(*rootLikelihoods_i_)[c];
57 rootLikelihoods_i_c_->resize(nbStates_);
58 for (
size_t x = 0; x < nbStates_; x++)
60 (*rootLikelihoods_i_c_)[x] = 1.;
88 leavesLikelihoods_leaf->resize(nbDistinctSites_);
89 for (
size_t i = 0; i < nbDistinctSites_; i++)
91 Vdouble* leavesLikelihoods_leaf_i = &(*leavesLikelihoods_leaf)[i];
92 leavesLikelihoods_leaf_i->resize(nbStates_);
95 for (
size_t s = 0; s < nbStates_; s++)
100 test += ( *leavesLikelihoods_leaf_i)[s];
103 std::cerr <<
"WARNING!!! Likelihood will be 0 for site " << i << std::endl;
109 for (
size_t l = 0; l < nbSonNodes; l++)
112 initLikelihoods(node->
getSon(l), sites, model);
122 for (
int n = (node->
hasFather() ? -1 : 0); n < nbSons; n++)
124 const Node* neighbor = (*node)[n];
125 VVVdouble* likelihoods_node_neighbor_ = &(*likelihoods_node_)[neighbor->
getId()];
127 likelihoods_node_neighbor_->resize(nbDistinctSites_);
131 VVdouble* leavesLikelihoods_leaf_ = &leafData_[neighbor->
getId()].getLikelihoodArray();
132 for (
size_t i = 0; i < nbDistinctSites_; i++)
134 Vdouble* leavesLikelihoods_leaf_i_ = &(*leavesLikelihoods_leaf_)[i];
135 VVdouble* likelihoods_node_neighbor_i_ = &(*likelihoods_node_neighbor_)[i];
136 likelihoods_node_neighbor_i_->resize(nbClasses_);
137 for (
size_t c = 0; c < nbClasses_; c++)
139 Vdouble* likelihoods_node_neighbor_i_c_ = &(*likelihoods_node_neighbor_i_)[c];
140 likelihoods_node_neighbor_i_c_->resize(nbStates_);
141 for (
size_t s = 0; s < nbStates_; s++)
143 (*likelihoods_node_neighbor_i_c_)[s] = (*leavesLikelihoods_leaf_i_)[s];
150 for (
size_t i = 0; i < nbDistinctSites_; i++)
152 VVdouble* likelihoods_node_neighbor_i_ = &(*likelihoods_node_neighbor_)[i];
153 likelihoods_node_neighbor_i_->resize(nbClasses_);
154 for (
size_t c = 0; c < nbClasses_; c++)
156 Vdouble* likelihoods_node_neighbor_i_c_ = &(*likelihoods_node_neighbor_i_)[c];
157 likelihoods_node_neighbor_i_c_->resize(nbStates_);
158 for (
size_t s = 0; s < nbStates_; s++)
160 (*likelihoods_node_neighbor_i_c_)[s] = 1.;
170 dLikelihoods_node_->resize(nbDistinctSites_);
171 d2Likelihoods_node_->resize(nbDistinctSites_);
178 reInit(tree_->getRootNode());
195 for (
int n = (node->
hasFather() ? -1 : 0); n < nbSons; n++)
197 const Node* neighbor = (*node)[n];
200 array->resize(nbDistinctSites_);
201 for (
size_t i = 0; i < nbDistinctSites_; i++)
204 array_i->resize(nbClasses_);
205 for (
size_t c = 0; c < nbClasses_; c++)
207 Vdouble* array_i_c = &(*array_i)[c];
208 array_i_c->resize(nbStates_);
209 for (
size_t s = 0; s < nbStates_; s++)
211 (*array_i_c)[s] = 1.;
219 for (
size_t l = 0; l < nbSonNodes; l++)
virtual int getAlphabetStateAsInt(size_t index) const =0
virtual size_t getNumberOfStates() const =0
Get the number of states.
virtual std::shared_ptr< const Alphabet > getAlphabet() const =0
void reInit()
Rebuild likelihood arrays at inner nodes.
void initLikelihoods(const AlignmentDataInterface &sites, const TransitionModelInterface &model)
Resize and initialize all likelihood arrays according to the given data set and substitution model.
Likelihood data structure for a leaf.
VVdouble & getLikelihoodArray()
void setNode(const Node *node)
Set the node associated to this data.
Likelihood data structure for a node.
Vdouble & getDLikelihoodArray()
void setNode(const Node *node)
Set the node associated to this data.
const std::map< int, VVVdouble > & getLikelihoodArrays() const
VVVdouble & getLikelihoodArrayForNeighbor(int neighborId)
void eraseNeighborArrays()
Vdouble & getD2LikelihoodArray()
The phylogenetic node class.
virtual std::string getName() const
Get the name associated to this node, if there is one, otherwise throw a NodeException.
virtual int getId() const
Get the node's id.
virtual const Node * getSon(size_t pos) const
virtual bool isLeaf() const
virtual bool hasFather() const
Tell if this node has a father node.
virtual size_t getNumberOfSons() const
Data structure for site patterns.
const std::vector< unsigned int > & getWeights() const
const IndicesType & getIndices() const
std::unique_ptr< AlignmentDataInterface > getSites() const
virtual size_t getNumberOfSites() const=0
virtual size_t getNumberOfSequences() const =0
virtual double getStateValueAt(size_t sitePosition, const std::string &sequenceKey, int state) const =0
virtual std::shared_ptr< const Alphabet > getAlphabet() const =0
virtual size_t getSequencePosition(const std::string &sequenceKey) const =0
Interface for all transition models.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
std::vector< VVdouble > VVVdouble
std::vector< Vdouble > VVdouble