in progress
authorcmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Thu, 13 Mar 2014 05:28:34 +0000 (05:28 +0000)
committercmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Thu, 13 Mar 2014 05:28:34 +0000 (05:28 +0000)
forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java
forester/java/src/org/forester/evoinference/distance/NeighborJoiningR.java

index 2fe3a4c..f6d3975 100644 (file)
@@ -34,6 +34,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.SortedSet;
 
+import org.forester.archaeopteryx.Archaeopteryx;
 import org.forester.evoinference.distance.NeighborJoining;
 import org.forester.evoinference.distance.NeighborJoiningF;
 import org.forester.evoinference.distance.NeighborJoiningR;
@@ -90,7 +91,7 @@ public class TestPhylogenyReconstruction {
         else {
             System.out.println( "  failed." );
         }
-        //timeNeighborJoining();
+       // timeNeighborJoining();
     }
 
     public static boolean test( final File test_dir ) {
@@ -2483,6 +2484,7 @@ public class TestPhylogenyReconstruction {
             final NeighborJoining nj = NeighborJoining.createInstance( true, 6 );
             //nj = NeighborJoining.createInstance( true, 6 );
             final Phylogeny pnj = nj.execute( m );
+            Archaeopteryx.createApplication( pnj );
             //
             m = new BasicSymmetricalDistanceMatrix( 7 );
             m.setIdentifier( 0, "Bovine" );
@@ -2502,7 +2504,7 @@ public class TestPhylogenyReconstruction {
             final NeighborJoiningR nj2 = NeighborJoiningR.createInstance( true, 6 );
             //nj = NeighborJoining.createInstance( true, 6 );
             final Phylogeny p2 = nj2.execute( m );
-            //  Archaeopteryx.createApplication( p2 );
+              Archaeopteryx.createApplication( p2 );
             p2.reRoot( p2.getNode( "Bovine" ) );
             if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) {
                 return false;
index b70b55e..a9d007a 100644 (file)
@@ -87,7 +87,7 @@ public final class NeighborJoiningR {
             final PhylogenyNode node = new PhylogenyNode();
             //final double d = getDvalueUnmapped( otu1, _mappings[ otu2 ] );
             final double d = _d_values[ otu1 ][ _mappings[ otu2 ] ];
-            final double d1 = ( d / 2 ) + ( ( _r[ otu1 ] - _r[ otu2 ] ) / ( 2 * ( _n - 2 ) ) );
+            final double d1 = ( d / 2 ) + ( ( _r[  _rev_mappings[ otu1 ] ] - _r[ otu2 ] ) / ( 2 * ( _n - 2 ) ) );
             final double d2 = d - d1;
             if ( _df == null ) {
                 _external_nodes[ otu1 ].setDistanceToParent( d1 );
@@ -149,7 +149,7 @@ public final class NeighborJoiningR {
             if ( j == otu2 ) {
                 continue;
             }
-            if ( _mappings[ j ] > _mappings[ otu1 ] ) {
+            if ( otu1  < _mappings[ j ]    ) {
                 updateDvalue( otu1, otu2, j, d );
             }
         }
@@ -159,12 +159,28 @@ public final class NeighborJoiningR {
     private final void updateDvalue( final int otu1, final int otu2, final int j, final double d ) {
         final double new_d = ( getDvalueUnmapped( otu1, _mappings[ j ] ) + getDvalue( j, otu2 ) - d ) / 2;
         System.out.print( DF.format( new_d ) + " " );
-        System.out.println( "going to remove: " + getDvalueUnmapped( otu1, _mappings[ j ] ) + ", " + otu1 + ", "
-                + _mappings[ j ] );
-        _s.removePairing( getDvalueUnmapped( otu1, _mappings[ j ] ), otu1, _mappings[ j ] );
-        System.out.println( "going to remove: " + getDvalue( j, otu2 ) + ", " + _mappings[ otu2 ] + ", "
-                + _mappings[ j ] );
-        _s.removePairing( getDvalue( j, otu2 ), _mappings[ otu2 ], _mappings[ j ] );
+       // System.out.println( "going to remove: " + getDvalueUnmapped( otu1, _mappings[ j ] ) + ", " + otu1 + ", "
+       //         + _mappings[ j ] );
+        
+        if (  otu1< _mappings[ j ] ) {
+            _s.removePairing( getDvalueUnmapped( otu1, _mappings[ j ] ), otu1, _mappings[ j ] );
+        }
+        else {
+            _s.removePairing( getDvalueUnmapped( otu1, _mappings[ j ] ), _mappings[ j ] ,  otu1 );
+        }
+        
+       
+      //  System.out.println( "going to remove: " + getDvalue( j, otu2 ) + ", " +_mappings[ otu2 ] + ", "
+      //          + _mappings[ j ] );
+        
+        if (   _mappings[ otu2  ] < _mappings[ j ] ) {
+            _s.removePairing( getDvalue( j, otu2 ),    _mappings[ otu2  ] , _mappings[ j ] );
+        }
+        else {
+            _s.removePairing( getDvalue( j, otu2 )   , _mappings[ j ],   _mappings[ otu2  ] );
+            
+        }
+       
         _s.addPairing( new_d, otu1, _mappings[ j ] );
         setDvalueU( otu1, j, new_d );
     }
@@ -173,7 +189,7 @@ public final class NeighborJoiningR {
         if ( i < _mappings[ j ] ) {
             _d_values[ i ][ _mappings[ j ] ] = d;
         }
-        _d_values[ j ][ _mappings[ i ] ] = d;
+        _d_values[_mappings[ j] ][  i  ] = d;
     }
 
     private double getDvalue( final int i, final int j ) {