bpp-phyl  2.2.0
AbstractTreeParsimonyScore.cpp
Go to the documentation of this file.
1 //
2 // File: AbstractTreeParsimonyScore.cpp
3 // Created by: Julien Dutheil
4 // Created on: Thu Jul 29 18:11 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 
41 #include "../PatternTools.h"
42 #include "../TreeTemplateTools.h"
43 
44 #include <Bpp/App/ApplicationTools.h>
45 
46 using namespace bpp;
47 using namespace std;
48 
50  const Tree& tree,
51  const SiteContainer& data,
52  bool verbose,
53  bool includeGaps)
54 throw (Exception) :
55  tree_(new TreeTemplate<Node>(tree)),
56  data_(0),
57  alphabet_(data.getAlphabet()),
58  statesMap_(0),
59  nbStates_(0)
60 {
61  statesMap_ = new CanonicalStateMap(alphabet_, includeGaps);
62  nbStates_ = statesMap_->getNumberOfModelStates();
63  init_(data, verbose);
64 }
65 
66 
68  const Tree& tree,
69  const SiteContainer& data,
70  const StateMap* statesMap,
71  bool verbose)
72 throw (Exception) :
73  tree_(new TreeTemplate<Node>(tree)),
74  data_(0),
75  alphabet_(data.getAlphabet()),
76  statesMap_(statesMap),
77  nbStates_(statesMap->getNumberOfModelStates())
78 {
79  init_(data, verbose);
80 }
81 
82 void AbstractTreeParsimonyScore::init_(const SiteContainer& data, bool verbose) throw (Exception)
83 {
84  if (tree_->isRooted())
85  {
86  if (verbose)
87  ApplicationTools::displayWarning("Tree has been unrooted.");
88  tree_->unroot();
89  }
90  TreeTemplateTools::deleteBranchLengths(*tree_->getRootNode());
91 
92  // Sequences will be in the same order than in the tree:
93  data_ = PatternTools::getSequenceSubset(data, *tree_->getRootNode());
94  if (data_->getNumberOfSequences() == 1) throw Exception("Error, only 1 sequence!");
95  if (data_->getNumberOfSequences() == 0) throw Exception("Error, no sequence!");
96  if (data_->getAlphabet()->getSize() > 20) throw Exception("Error, only alphabet with size <= 20 are supported. See the source file of AbstractTreeParsimonyScore.");
97 }
98 
99 std::vector<unsigned int> AbstractTreeParsimonyScore::getScoreForEachSite() const
100 {
101  vector<unsigned int> scores(data_->getNumberOfSites());
102  for (size_t i = 0; i < scores.size(); i++)
103  {
104  scores[i] = getScoreForSite(i);
105  }
106  return scores;
107 }
108 
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:161
AbstractTreeParsimonyScore(const Tree &tree, const SiteContainer &data, bool verbose, bool includeGaps)
STL namespace.
The phylogenetic tree class.
Interface for phylogenetic tree objects.
Definition: Tree.h:148
void init_(const SiteContainer &data, bool verbose)
static SiteContainer * getSequenceSubset(const SiteContainer &sequenceSet, const Node &node)
Extract the sequences corresponding to a given subtree.
static void deleteBranchLengths(Node &node)
Remove all the branch lengths of a subtree.
virtual std::vector< unsigned int > getScoreForEachSite() const
Get the score for each site for the current tree, i.e. the total minimum number of changes in the tre...
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:58