~ubuntu-branches/ubuntu/raring/libbpp-phyl/raring

« back to all changes in this revision

Viewing changes to src/Bpp/Phyl/Distance/HierarchicalClustering.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: HierarchicalClustering.h
 
3
// From file Cluster.h in CoMap package.
 
4
// Created by: Julien Dutheil
 
5
// Created on: Tue Aug 30 17:19 2005
 
6
//
 
7
 
 
8
/*
 
9
Copyright or © or Copr. Bio++ Development Team, (November 16, 2004, 2005, 2006)
 
10
 
 
11
This software is a computer program whose purpose is to map substitutions
 
12
on a tree and to detect co-evolving positions in a dataset.
 
13
 
 
14
This software is governed by the CeCILL  license under French law and
 
15
abiding by the rules of distribution of free software.  You can  use, 
 
16
modify and/ or redistribute the software under the terms of the CeCILL
 
17
license as circulated by CEA, CNRS and INRIA at the following URL
 
18
"http://www.cecill.info". 
 
19
 
 
20
As a counterpart to the access to the source code and  rights to copy,
 
21
modify and redistribute granted by the license, users are provided only
 
22
with a limited warranty  and the software's author,  the holder of the
 
23
economic rights,  and the successive licensors  have only  limited
 
24
liability. 
 
25
 
 
26
In this respect, the user's attention is drawn to the risks associated
 
27
with loading,  using,  modifying and/or developing or reproducing the
 
28
software by the user in light of its specific status of free software,
 
29
that may mean  that it is complicated to manipulate,  and  that  also
 
30
therefore means  that it is reserved for developers  and  experienced
 
31
professionals having in-depth computer knowledge. Users are therefore
 
32
encouraged to load and test the software's suitability as regards their
 
33
requirements in conditions enabling the security of their systems and/or 
 
34
data to be ensured and,  more generally, to use and operate it in the 
 
35
same conditions as regards security. 
 
36
 
 
37
The fact that you are presently reading this means that you have had
 
38
knowledge of the CeCILL license and that you accept its terms.
 
39
*/
 
40
 
 
41
#ifndef _HIERARCHICALCLUSTERING_H_
 
42
#define _HIERARCHICALCLUSTERING_H_
 
43
 
 
44
#include "AbstractAgglomerativeDistanceMethod.h"
 
45
 
 
46
namespace bpp {
 
47
 
 
48
class ClusterInfos
 
49
{
 
50
  public:
 
51
        unsigned int numberOfLeaves;
 
52
          double length;
 
53
  public:
 
54
    ClusterInfos(): numberOfLeaves(0), length(0) {}
 
55
};
 
56
 
 
57
/**
 
58
 * @brief Hierarchical clustering.
 
59
 *
 
60
 * This class implements the complete, single, average (= UPGMA), median, ward and centroid linkage methods.
 
61
 */
 
62
class HierarchicalClustering:
 
63
  public AbstractAgglomerativeDistanceMethod
 
64
{
 
65
        public:
 
66
                static const std::string COMPLETE; 
 
67
                static const std::string SINGLE; 
 
68
                static const std::string AVERAGE; 
 
69
                static const std::string MEDIAN; 
 
70
                static const std::string WARD; 
 
71
                static const std::string CENTROID; 
 
72
        
 
73
        protected:
 
74
    std::string method_;
 
75
        
 
76
        public:
 
77
    /**
 
78
     * @brief Builds a new clustering object.
 
79
     *
 
80
     * @param method The linkage method to use. should be one of COMPLETE, SINGLE, AVERAGE, MEDIAN, WARD, CENTROID.
 
81
     * @param verbose Tell if some progress information should be displayed.
 
82
     */
 
83
                HierarchicalClustering(const std::string& method, bool verbose = false):
 
84
      AbstractAgglomerativeDistanceMethod(verbose), method_(method) {}
 
85
                HierarchicalClustering(const std::string& method, const DistanceMatrix& matrix, bool verbose = false) throw (Exception): AbstractAgglomerativeDistanceMethod(matrix, verbose), method_(method) 
 
86
                {
 
87
                        computeTree(true);
 
88
                }
 
89
 
 
90
                virtual ~HierarchicalClustering() {}
 
91
 
 
92
        public:
 
93
                TreeTemplate<Node>* getTree() const;
 
94
 
 
95
        protected:
 
96
    std::vector<unsigned int> getBestPair() throw (Exception);
 
97
    std::vector<double> computeBranchLengthsForPair(const std::vector<unsigned int>& pair);
 
98
                double computeDistancesFromPair(const std::vector<unsigned int>& pair, const std::vector<double> & branchLengths, unsigned int pos);
 
99
                void finalStep(int idRoot);     
 
100
                virtual Node* getLeafNode(int id, const std::string& name);
 
101
                virtual Node* getParentNode(int id, Node* son1, Node* son2);
 
102
};
 
103
 
 
104
} //end of namespace bpp.
 
105
 
 
106
#endif //_HIERARCHICALCLUSTERING_H_
 
107