bpp-phyl  2.1.0
bpp::NeighborJoining Class Reference

The neighbor joining distance method. More...

#include <Bpp/Phyl/Distance/NeighborJoining.h>

+ Inheritance diagram for bpp::NeighborJoining:
+ Collaboration diagram for bpp::NeighborJoining:

List of all members.

Public Member Functions

 NeighborJoining (bool rooted=false, bool positiveLengths=false, bool verbose=true)
 Create a new NeighborJoining object instance, without performing any computation.
 NeighborJoining (const DistanceMatrix &matrix, bool rooted=false, bool positiveLengths=false, bool verbose=true) throw (Exception)
 Create a new NeighborJoining object instance and compute a tree from a distance matrix.
virtual ~NeighborJoining ()
NeighborJoiningclone () const
std::string getName () const
virtual void setDistanceMatrix (const DistanceMatrix &matrix)
 Set the distance matrix to use.
virtual void outputPositiveLengths (bool yn)
virtual TreeTemplate< Node > * getTree () const
 Get the computed tree, if there is one.
virtual void computeTree () throw (Exception)
 Compute the tree corresponding to the distance matrix.
void setVerbose (bool yn)
bool isVerbose () const

Protected Member Functions

std::vector< size_t > getBestPair () throw (Exception)
 Get the best pair of nodes to agglomerate.
std::vector< double > computeBranchLengthsForPair (const std::vector< size_t > &pair)
 Compute the branch lengths for two nodes to agglomerate.
double computeDistancesFromPair (const std::vector< size_t > &pair, const std::vector< double > &branchLengths, size_t pos)
 Actualizes the distance matrix according to a given pair and the corresponding branch lengths.
void finalStep (int idRoot)
 Method called when there ar eonly three remaining node to agglomerate, and creates the root node of the tree.
Specific methods.
virtual NodegetLeafNode (int id, const std::string &name)
 Get a leaf node.
virtual NodegetParentNode (int id, Node *son1, Node *son2)
 Get an inner node.

Protected Attributes

std::vector< double > sumDist_
bool positiveLengths_
DistanceMatrix matrix_
Treetree_
std::map< size_t, Node * > currentNodes_
bool verbose_
bool rootTree_

Detailed Description

The neighbor joining distance method.

Reference: N Saitou and M Nei (1987), _Molecular Biology and Evolution_ 4(4) 406-25.

Definition at line 55 of file NeighborJoining.h.


Constructor & Destructor Documentation

bpp::NeighborJoining::NeighborJoining ( bool  rooted = false,
bool  positiveLengths = false,
bool  verbose = true 
) [inline]

Create a new NeighborJoining object instance, without performing any computation.

Parameters:
rootedTell if the output tree should be rooted.
positiveLengthsTell if negative lengths should be avoided.
verboseAllow to display extra information, like progress bars.

Definition at line 70 of file NeighborJoining.h.

Referenced by clone().

bpp::NeighborJoining::NeighborJoining ( const DistanceMatrix matrix,
bool  rooted = false,
bool  positiveLengths = false,
bool  verbose = true 
) throw (Exception) [inline]

Create a new NeighborJoining object instance and compute a tree from a distance matrix.

Parameters:
matrixInput distance matrix.
rootedTell if the output tree should be rooted.
positiveLengthsTell if negative lengths should be avoided.
verboseAllow to display extra information, like progress bars.

Definition at line 84 of file NeighborJoining.h.

References bpp::AbstractAgglomerativeDistanceMethod::computeTree().

virtual bpp::NeighborJoining::~NeighborJoining ( ) [inline, virtual]

Definition at line 93 of file NeighborJoining.h.


Member Function Documentation

NeighborJoining* bpp::NeighborJoining::clone ( ) const [inline, virtual]

Implements bpp::Clonable.

Reimplemented in bpp::BioNJ.

Definition at line 95 of file NeighborJoining.h.

References NeighborJoining().

std::vector< double > NeighborJoining::computeBranchLengthsForPair ( const std::vector< size_t > &  pair) [protected, virtual]

Compute the branch lengths for two nodes to agglomerate.

 +---l1-----N1
 |
 +---l2-----N2

This method compute l1 and l2 given N1 and N2.

Parameters:
pairThe indices of the nodes to be agglomerated.
Returns:
A size 2 vector with branch lengths.

Implements bpp::AbstractAgglomerativeDistanceMethod.

Definition at line 92 of file NeighborJoining.cpp.

double NeighborJoining::computeDistancesFromPair ( const std::vector< size_t > &  pair,
const std::vector< double > &  branchLengths,
size_t  pos 
) [protected, virtual]

Actualizes the distance matrix according to a given pair and the corresponding branch lengths.

Parameters:
pairThe indices of the nodes to be agglomerated.
branchLengthsThe corresponding branch lengths.
posThe index of the node whose distance ust be updated.
Returns:
The distance between the 'pos' node and the agglomerated pair.

Implements bpp::AbstractAgglomerativeDistanceMethod.

Reimplemented in bpp::BioNJ.

Definition at line 109 of file NeighborJoining.cpp.

void AbstractAgglomerativeDistanceMethod::computeTree ( ) throw (Exception) [virtual, inherited]

Compute the tree corresponding to the distance matrix.

This method implements the following algorithm: 1) Build all leaf nodes (getLeafNode method) 2) Get the best pair to agglomerate (getBestPair method) 3) Compute the branch lengths for this pair (computeBranchLengthsForPair method) 4) Build the parent node of the pair (getParentNode method) 5) For each remaining node, update distances from the pair (computeDistancesFromPair method) 6) Return to step 2 while there are more than 3 remaining nodes. 7) Perform the final step, and send a rooted or unrooted tree.

Implements bpp::DistanceMethod.

Reimplemented in bpp::BioNJ.

Definition at line 60 of file AbstractAgglomerativeDistanceMethod.cpp.

References bpp::ApplicationTools::displayGauge(), and bpp::Node::setDistanceToFather().

Referenced by bpp::HierarchicalClustering::HierarchicalClustering(), NeighborJoining(), and bpp::PGMA::PGMA().

void NeighborJoining::finalStep ( int  idRoot) [protected, virtual]

Method called when there ar eonly three remaining node to agglomerate, and creates the root node of the tree.

Parameters:
idRootThe id of the root node.

Implements bpp::AbstractAgglomerativeDistanceMethod.

Definition at line 117 of file NeighborJoining.cpp.

References bpp::Node::addSon(), and bpp::Node::setDistanceToFather().

std::vector< size_t > NeighborJoining::getBestPair ( ) throw (Exception) [protected, virtual]

Get the best pair of nodes to agglomerate.

Define the criterion to chose the next pair of nodes to agglomerate. This criterion uses the matrix_ distance matrix.

Returns:
A size 2 vector with the indices of the nodes.
Exceptions:
ExceptionIf an error occured.

Implements bpp::AbstractAgglomerativeDistanceMethod.

Definition at line 51 of file NeighborJoining.cpp.

Node * AbstractAgglomerativeDistanceMethod::getLeafNode ( int  id,
const std::string &  name 
) [protected, virtual, inherited]

Get a leaf node.

Create a new node with the given id and name.

Parameters:
idThe id of the node.
nameThe name of the node.
Returns:
A pointer toward a new node object.

Reimplemented in bpp::PGMA, and bpp::HierarchicalClustering.

Definition at line 109 of file AbstractAgglomerativeDistanceMethod.cpp.

std::string bpp::NeighborJoining::getName ( ) const [inline, virtual]
Returns:
The name of the distance method.

Implements bpp::DistanceMethod.

Reimplemented in bpp::BioNJ.

Definition at line 98 of file NeighborJoining.h.

Node * AbstractAgglomerativeDistanceMethod::getParentNode ( int  id,
Node son1,
Node son2 
) [protected, virtual, inherited]

Get an inner node.

Create a new node with the given id, and set its sons.

Parameters:
idThe id of the node.
son1The first son of the node.
son2The second son of the node.
Returns:
A pointer toward a new node object.

Reimplemented in bpp::PGMA, and bpp::HierarchicalClustering.

Definition at line 114 of file AbstractAgglomerativeDistanceMethod.cpp.

References bpp::Node::addSon().

virtual TreeTemplate<Node>* bpp::AbstractAgglomerativeDistanceMethod::getTree ( ) const [inline, virtual, inherited]

Get the computed tree, if there is one.

Returns:
A copy of the computed tree if there is one, 0 otherwise.

Implements bpp::DistanceMethod.

Reimplemented in bpp::HierarchicalClustering, and bpp::PGMA.

Definition at line 127 of file AbstractAgglomerativeDistanceMethod.h.

References bpp::AbstractAgglomerativeDistanceMethod::tree_.

Referenced by bpp::TreeTools::MRP().

bool bpp::AbstractAgglomerativeDistanceMethod::isVerbose ( ) const [inline, virtual, inherited]
Returns:
True if verbose mode is enabled.

Implements bpp::DistanceMethod.

Definition at line 149 of file AbstractAgglomerativeDistanceMethod.h.

References bpp::AbstractAgglomerativeDistanceMethod::verbose_.

virtual void bpp::NeighborJoining::outputPositiveLengths ( bool  yn) [inline, virtual]

Definition at line 106 of file NeighborJoining.h.

References positiveLengths_.

Referenced by bpp::BioNJ::BioNJ().

virtual void bpp::NeighborJoining::setDistanceMatrix ( const DistanceMatrix matrix) [inline, virtual]

Set the distance matrix to use.

Parameters:
matrixThe matrix to use.

Reimplemented from bpp::AbstractAgglomerativeDistanceMethod.

Reimplemented in bpp::BioNJ.

Definition at line 100 of file NeighborJoining.h.

References bpp::DistanceMatrix::size(), and sumDist_.

void bpp::AbstractAgglomerativeDistanceMethod::setVerbose ( bool  yn) [inline, virtual, inherited]
Parameters:
ynEnable/Disable verbose mode.

Implements bpp::DistanceMethod.

Definition at line 148 of file AbstractAgglomerativeDistanceMethod.h.

References bpp::AbstractAgglomerativeDistanceMethod::verbose_.


Member Data Documentation

Definition at line 60 of file NeighborJoining.h.

Referenced by outputPositiveLengths().

std::vector<double> bpp::NeighborJoining::sumDist_ [protected]

Definition at line 59 of file NeighborJoining.h.

Referenced by setDistanceMatrix().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Friends