in progress
[jalview.git] / forester / java / src / org / forester / evoinference / distance / NeighborJoining.java
index 3d28ab7..14553ce 100644 (file)
@@ -36,6 +36,7 @@ import org.forester.util.ForesterUtil;
 
 public final class NeighborJoining {
 
+    private final static DecimalFormat     DF = new DecimalFormat( "0.00000" );
     private BasicSymmetricalDistanceMatrix _d;
     private double[][]                     _d_values;
     private final DecimalFormat            _df;
@@ -72,6 +73,7 @@ public final class NeighborJoining {
             updateM();
             final int otu1 = _min_i;
             final int otu2 = _min_j;
+            System.out.println( _min_i + " " + _min_j );
             // It is a condition that otu1 < otu2.
             final PhylogenyNode node = new PhylogenyNode();
             final double d = _d_values[ _mappings[ otu1 ] ][ _mappings[ otu2 ] ];
@@ -192,10 +194,24 @@ public final class NeighborJoining {
     }
 
     private final void printProgress( final int otu1, final int otu2 ) {
-        final PhylogenyNode n1 = getExternalPhylogenyNode( otu1 );
-        final PhylogenyNode n2 = getExternalPhylogenyNode( otu2 );
-        System.out.println( "Node " + ( ForesterUtil.isEmpty( n1.getName() ) ? n1.getId() : n1.getName() ) + " joins "
-                + ( ForesterUtil.isEmpty( n2.getName() ) ? n2.getId() : n2.getName() ) );
+        System.out.println( "Node " + printProgressNodeToString( getExternalPhylogenyNode( otu1 ) ) + " joins "
+                + ( printProgressNodeToString( getExternalPhylogenyNode( otu2 ) ) ) );
+    }
+
+    private final String printProgressNodeToString( final PhylogenyNode n ) {
+        if ( n.isExternal() ) {
+            if ( ForesterUtil.isEmpty( n.getName() ) ) {
+                return Long.toString( n.getId() );
+            }
+            return n.getName();
+        }
+        return n.getId()
+                + " ("
+                + ( ForesterUtil.isEmpty( n.getChildNode1().getName() ) ? n.getChildNode1().getId() : n.getChildNode1()
+                        .getName() )
+                + "+"
+                + ( ForesterUtil.isEmpty( n.getChildNode2().getName() ) ? n.getChildNode2().getId() : n.getChildNode2()
+                        .getName() ) + ")";
     }
 
     // only the values in the lower triangle are used.
@@ -227,12 +243,28 @@ public final class NeighborJoining {
                 }
             }
         }
+        for( int j = 1; j < _n; ++j ) {
+            final double r_j = _r[ j ];
+            final int m_j = _mappings[ j ];
+            for( int i = 0; i < j; ++i ) {
+                System.out.print( i );
+                System.out.print( "->" );
+                System.out.print( DF.format( _r[ i ] ) );
+                System.out.print( "  " );
+            }
+            System.out.println();
+        }
     }
 
     // otu2 will, in effect, be "deleted" from the matrix.
     private final void updateMappings( final int otu2 ) {
         for( int i = otu2; i < ( _mappings.length - 1 ); ++i ) {
+            System.out.print( _mappings[ i ] );
             _mappings[ i ] = _mappings[ i + 1 ];
+            System.out.println( "----->" + _mappings[ i ] );
+        }
+        for( int i = 0; i < _mappings.length; ++i ) {
+            System.out.println( i + "-->" + _mappings[ i ] );
         }
     }