- /**
- * Calculates the distance between PhylogenyNodes node1 and node2.
- *
- *
- * @param node1
- * @param node2
- * @return distance between node1 and node2
- */
- public double calculateDistance( final PhylogenyNode node1, final PhylogenyNode node2 ) {
- final PhylogenyNode lca = calculateLCA( node1, node2 );
- final PhylogenyNode n1 = node1;
- final PhylogenyNode n2 = node2;
- return ( PhylogenyMethods.getDistance( n1, lca ) + PhylogenyMethods.getDistance( n2, lca ) );
- }
-
- public double calculateFurthestDistance( final Phylogeny phylogeny ) {
- if ( phylogeny.getNumberOfExternalNodes() < 2 ) {
- return 0.0;
- }
- _farthest_1 = null;
- _farthest_2 = null;
- PhylogenyNode node_1 = null;
- PhylogenyNode node_2 = null;
- double farthest_d = -Double.MAX_VALUE;
- final PhylogenyMethods methods = PhylogenyMethods.getInstance();
- final List<PhylogenyNode> ext_nodes = phylogeny.getRoot().getAllExternalDescendants();
- for( int i = 1; i < ext_nodes.size(); ++i ) {
- for( int j = 0; j < i; ++j ) {
- final double d = methods.calculateDistance( ext_nodes.get( i ), ext_nodes.get( j ) );
- if ( d < 0.0 ) {
- throw new RuntimeException( "distance cannot be negative" );
- }
- if ( d > farthest_d ) {
- farthest_d = d;
- node_1 = ext_nodes.get( i );
- node_2 = ext_nodes.get( j );
- }
- }
- }
- _farthest_1 = node_1;
- _farthest_2 = node_2;
- return farthest_d;
- }
-