bpp-phyl  2.2.0
MarginalAncestralStateReconstruction.h
Go to the documentation of this file.
1 //
2 // File: MarginalAncestralStateReconstruction.h
3 // Created by: Julien Dutheil
4 // Created on: Fri Jul 08 13:32 2005
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
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 _MARGINALANCESTRALSTATESRECONSTRUCTION_H_
41 #define _MARGINALANCESTRALSTATESRECONSTRUCTION_H_
42 
43 #include "../AncestralStateReconstruction.h"
44 #include "DRTreeLikelihood.h"
45 
46 // From SeqLib:
47 #include <Bpp/Seq/Alphabet/Alphabet.h>
48 #include <Bpp/Seq/Container/AlignedSequenceContainer.h>
49 #include <Bpp/Seq/Sequence.h>
50 
51 // From the STL:
52 #include <vector>
53 
54 namespace bpp
55 {
56 
64  public virtual AncestralStateReconstruction
65 {
66  private:
69  const Alphabet* alphabet_;
70  size_t nbSites_;
72  size_t nbClasses_;
73  size_t nbStates_;
74  std::vector<size_t> rootPatternLinks_;
75  std::vector<double> r_;
76  std::vector<double> l_;
77 
78  public:
80  likelihood_ (drl),
81  tree_ (drl->getTree()),
82  alphabet_ (drl->getAlphabet()),
83  nbSites_ (drl->getLikelihoodData()->getNumberOfSites()),
84  nbDistinctSites_ (drl->getLikelihoodData()->getNumberOfDistinctSites()),
85  nbClasses_ (drl->getLikelihoodData()->getNumberOfClasses()),
86  nbStates_ (drl->getLikelihoodData()->getNumberOfStates()),
87  rootPatternLinks_(drl->getLikelihoodData()->getRootArrayPositions()),
88  r_ (drl->getRateDistribution()->getProbabilities()),
89  l_ (drl->getLikelihoodData()->getRootRateSiteLikelihoodArray())
90  {}
91 
93  likelihood_ (masr.likelihood_),
94  tree_ (masr.tree_),
95  alphabet_ (masr.alphabet_),
96  nbSites_ (masr.nbSites_),
98  nbClasses_ (masr.nbClasses_),
99  nbStates_ (masr.nbStates_),
101  r_ (masr.r_),
102  l_ (masr.l_)
103  {}
104 
106  {
107  likelihood_ = masr.likelihood_;
108  tree_ = masr.tree_;
109  alphabet_ = masr.alphabet_;
110  nbSites_ = masr.nbSites_;
112  nbClasses_ = masr.nbClasses_;
113  nbStates_ = masr.nbStates_;
115  r_ = masr.r_;
116  l_ = masr.l_;
117  return *this;
118  }
119 
120 
121 #ifndef NO_VIRTUAL_COV
123 #else
124  Clonable*
125 #endif
126  clone() const { return new MarginalAncestralStateReconstruction(*this); }
127 
129 
130  public:
131 
147  std::vector<size_t> getAncestralStatesForNode(int nodeId, VVdouble& probs, bool sample) const;
148 
149  std::vector<size_t> getAncestralStatesForNode(int nodeId) const
150  {
151  VVdouble probs(nbSites_);
152  return getAncestralStatesForNode(nodeId, probs, false);
153  }
154 
155  std::map<int, std::vector<size_t> > getAllAncestralStates() const;
156 
168  Sequence* getAncestralSequenceForNode(int nodeId, VVdouble* probs, bool sample) const;
169 
170  Sequence* getAncestralSequenceForNode(int nodeId) const
171  {
172  return getAncestralSequenceForNode(nodeId, 0, false);
173  }
174 
175  AlignedSequenceContainer* getAncestralSequences() const
176  {
177  return getAncestralSequences(false);
178  }
179 
180 #ifndef NO_VIRTUAL_COV
181  AlignedSequenceContainer *
182 #else
183  SequenceContainer *
184 #endif
185  getAncestralSequences(bool sample) const;
186 
187  private:
189  const Node* node,
190  std::map<int, std::vector<size_t> >& ancestors,
191  AlignedSequenceContainer& data) const;
192 
193 
194 };
195 
196 } //end of namespace bpp.
197 
198 #endif // _MARGINALANCESTRALSTATESRECONSTRUCTION_H_
199 
Likelihood ancestral states reconstruction: marginal method.
std::vector< size_t > getAncestralStatesForNode(int nodeId) const
Get ancestral states for a given node as a vector of int.
Interface for ancestral states reconstruction methods.
std::map< int, std::vector< size_t > > getAllAncestralStates() const
Get all ancestral states for all nodes.
Sequence * getAncestralSequenceForNode(int nodeId) const
Get the ancestral sequence for a given node.
void recursiveMarginalAncestralStates(const Node *node, std::map< int, std::vector< size_t > > &ancestors, AlignedSequenceContainer &data) const
The phylogenetic tree class.
AlignedSequenceContainer * getAncestralSequences() const
Get all the ancestral sequences for all nodes.
The phylogenetic node class.
Definition: Node.h:90
MarginalAncestralStateReconstruction(const MarginalAncestralStateReconstruction &masr)
Interface for double-recursive (DR) implementation of the likelihood computation. ...
MarginalAncestralStateReconstruction * clone() const
MarginalAncestralStateReconstruction & operator=(const MarginalAncestralStateReconstruction &masr)
Sequence * getAncestralSequenceForNode(int nodeId, VVdouble *probs, bool sample) const
Get the ancestral sequence for a given node.
std::vector< size_t > getAncestralStatesForNode(int nodeId, VVdouble &probs, bool sample) const
Get ancestral states for a given node as a vector of int.