~ubuntu-branches/ubuntu/precise/libbpp-phyl/precise

« back to all changes in this revision

Viewing changes to src/Bpp/Phyl/Parsimony/DRTreeParsimonyScore.h

  • Committer: Bazaar Package Importer
  • Author(s): Julien Dutheil
  • Date: 2011-06-09 11:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110609110000-yvx78svv6w7xxgph
Tags: upstream-2.0.2
Import upstream version 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// File: DRTreeParsimonyScore.h
 
3
// Created by: Julien Dutheil
 
4
// Created on: Thu Jul 28 18:31 2005
 
5
//
 
6
 
 
7
/*
 
8
Copyright or © or Copr. CNRS, (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 _DRTREEPARSIMONYSCORE_H_
 
41
#define _DRTREEPARSIMONYSCORE_H_
 
42
 
 
43
#include "AbstractTreeParsimonyScore.h"
 
44
#include "DRTreeParsimonyData.h"
 
45
#include "../NNISearchable.h"
 
46
#include "../TreeTools.h"
 
47
 
 
48
namespace bpp
 
49
{
 
50
 
 
51
/**
 
52
 * @brief Double recursive implementation of interface TreeParsimonyScore.
 
53
 *
 
54
 * Uses a DRTreeParsimonyData object for data storage.
 
55
 */
 
56
class DRTreeParsimonyScore :
 
57
        public AbstractTreeParsimonyScore,
 
58
        public virtual NNISearchable
 
59
{
 
60
        private:
 
61
                DRTreeParsimonyData *parsimonyData_;
 
62
                unsigned int         nbDistinctSites_;
 
63
                        
 
64
        public:
 
65
                DRTreeParsimonyScore(
 
66
                        const Tree& tree,
 
67
                        const SiteContainer& data,
 
68
                        bool verbose = true)
 
69
                        throw (Exception);
 
70
 
 
71
    DRTreeParsimonyScore(const DRTreeParsimonyScore& tp);
 
72
    
 
73
    DRTreeParsimonyScore& operator=(const DRTreeParsimonyScore& tp);
 
74
                                
 
75
                virtual ~DRTreeParsimonyScore();
 
76
 
 
77
#ifndef NO_VIRTUAL_COV
 
78
    DRTreeParsimonyScore*
 
79
#else
 
80
    Clonable*
 
81
#endif
 
82
    clone() const { return new DRTreeParsimonyScore(* this); }
 
83
 
 
84
        protected:
 
85
                /**
 
86
                 * @brief Compute all scores.
 
87
                 *
 
88
                 * Call the computeScoresPreorder and computeScoresPostorder methods, and then initialize rootBitsets_ and rootScores_.
 
89
                 */
 
90
                virtual void computeScores();
 
91
                /**
 
92
                 * @brief Compute scores (preorder algorithm).
 
93
                 */
 
94
                virtual void computeScoresPreorder(const Node *);
 
95
                /**
 
96
                 * @brief Compute scores (postorder algorithm).
 
97
                 */
 
98
                virtual void computeScoresPostorder(const Node *);
 
99
 
 
100
        public:
 
101
 
 
102
                unsigned int getScore() const;
 
103
                unsigned int getScoreForSite(unsigned int site) const;
 
104
                
 
105
                /**
 
106
                 * @brief Compute bitsets and scores for each site for a node, in postorder.
 
107
                 *
 
108
                 * @param pData    The node data to use.
 
109
                 * @param rBitsets The bitset array where to store the resulting bitsets.
 
110
                 * @param rScores  The score array where to write the resulting scores.
 
111
                 */
 
112
                static void computeScoresPostorderForNode(
 
113
        const DRTreeParsimonyNodeData& pData,
 
114
        std::vector<Bitset>& rBitsets,
 
115
        std::vector<unsigned int>& rScores);
 
116
                
 
117
                /**
 
118
                 * @brief Compute bitsets and scores for each site for a node, in preorder.
 
119
                 *
 
120
                 * @param pData    The node data to use.
 
121
                 * @param source   The node where we are coming from.
 
122
                 * @param rBitsets The bitset array where to store the resulting bitsets.
 
123
                 * @param rScores  The score array where to write the resulting scores.
 
124
                 */
 
125
                static void computeScoresPreorderForNode(
 
126
        const DRTreeParsimonyNodeData& pData,
 
127
        const Node* source,
 
128
        std::vector<Bitset>& rBitsets,
 
129
        std::vector<unsigned int>& rScores);
 
130
 
 
131
                /**
 
132
                 * @brief Compute bitsets and scores for each site for a node, in all directions.
 
133
                 *
 
134
                 * @param pData    The node data to use.
 
135
                 * @param rBitsets The bitset array where to store the resulting bitsets.
 
136
                 * @param rScores  The score array where to write the resulting scores.
 
137
                 */
 
138
                static void computeScoresForNode(
 
139
        const DRTreeParsimonyNodeData& pData, std::vector<Bitset>& rBitsets,
 
140
        std::vector<unsigned int>& rScores); 
 
141
 
 
142
                /**
 
143
                 * @brief Compute bitsets and scores from an array of arrays.
 
144
                 *
 
145
                 * This method is the more general score computation.
 
146
                 * Depending on what is passed as input, it may computes scroes fo a subtree
 
147
                 * or the whole tree.
 
148
                 *
 
149
                 * @param iBitsets The vector of bitset arrays to use.
 
150
                 * @param iScores  The vector of score arrays to use.
 
151
                 * @param oBitsets The bitset array where to store the resulting bitsets.
 
152
                 * @param oScores  The score array where to write the resulting scores.
 
153
                 */
 
154
                static void computeScoresFromArrays(
 
155
                                const std::vector<const std::vector<Bitset>*>& iBitsets,
 
156
                                const std::vector<const std::vector<unsigned int>*>& iScores,
 
157
                                std::vector<Bitset>& oBitsets,
 
158
                                std::vector<unsigned int>& oScores); 
 
159
 
 
160
                /**
 
161
                 * @name Thee NNISearchable interface.
 
162
                 *
 
163
                 * @{
 
164
                 */
 
165
    double getTopologyValue() const throw (Exception) { return getScore(); }
 
166
 
 
167
                double testNNI(int nodeId) const throw (NodeException);
 
168
 
 
169
                void doNNI(int nodeId) throw (NodeException);
 
170
 
 
171
                //Tree& getTopology() { return getTree(); } do we realy need this one?
 
172
                
 
173
                const Tree& getTopology() const { return getTree(); }
 
174
                
 
175
                void topologyChangeTested(const TopologyChangeEvent & event)
 
176
                {
 
177
                        parsimonyData_->reInit();
 
178
                        computeScores();
 
179
                }
 
180
 
 
181
    void topologyChangeSuccessful(const TopologyChangeEvent & event) {}
 
182
                /**@} */
 
183
 
 
184
};
 
185
 
 
186
} //end of namespace bpp.
 
187
 
 
188
#endif //_DRTREEPARSIMONYSCORE_H_
 
189