X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fevoinference%2FTestPhylogenyReconstruction.java;h=f1074f46eace55afdeb62bccd00ba8549ffa7866;hb=cb49ee5684c6907b3161db82ff9aea72961b8548;hp=a27d9f6e1b3f964307bce2fdc95ae33a4dfe857e;hpb=dd04eb6f09074d32b99879cbe5f6bb5aa7db0ce6;p=jalview.git diff --git a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java index a27d9f6..f1074f4 100644 --- a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java +++ b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java @@ -34,12 +34,12 @@ import java.util.Date; import java.util.List; import java.util.Set; -import org.forester.archaeopteryx.Archaeopteryx; import org.forester.evoinference.distance.NeighborJoining; import org.forester.evoinference.distance.NeighborJoiningF; import org.forester.evoinference.distance.NeighborJoiningR; import org.forester.evoinference.distance.PairwiseDistanceCalculator; -import org.forester.evoinference.distance.S; +import org.forester.evoinference.distance.Sarray; +import org.forester.evoinference.distance.Sset; import org.forester.evoinference.matrix.character.BasicCharacterStateMatrix; import org.forester.evoinference.matrix.character.CharacterStateMatrix; import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates; @@ -59,7 +59,8 @@ import org.forester.util.ForesterUtil; public class TestPhylogenyReconstruction { - private final static double ZERO_DIFF = 1.0E-9; + private final static double ZERO_DIFF = 1.0E-9; + private final static boolean VERBOSE = false; public static boolean isEqual( final double a, final double b ) { return ( ( Math.abs( a - b ) ) < ZERO_DIFF ); @@ -71,7 +72,7 @@ public class TestPhylogenyReconstruction { public static void main( final String[] args ) { System.out.println( "NJ" ); - if ( testNeighborJoining() ) { + if ( testNeighborJoining( VERBOSE ) ) { System.out.println( " OK." ); } else { @@ -84,6 +85,13 @@ public class TestPhylogenyReconstruction { else { System.out.println( " failed." ); } + System.out.println( "Sarray" ); + if ( testSarray() ) { + System.out.println( " OK." ); + } + else { + System.out.println( " failed." ); + } System.out.println( "NJR" ); if ( testNeighborJoiningR() ) { System.out.println( " OK." ); @@ -91,7 +99,7 @@ public class TestPhylogenyReconstruction { else { System.out.println( " failed." ); } - // timeNeighborJoining(); + timeNeighborJoining(); } public static boolean test( final File test_dir ) { @@ -126,7 +134,7 @@ public class TestPhylogenyReconstruction { } System.out.println( "OK." ); System.out.print( " Neighbor Joining: " ); - if ( !testNeighborJoining() ) { + if ( !testNeighborJoining( VERBOSE ) ) { System.out.println( "failed." ); return false; } @@ -1945,7 +1953,7 @@ public class TestPhylogenyReconstruction { return true; } - private static boolean testNeighborJoining() { + private static boolean testNeighborJoining( final boolean verbose ) { try { NeighborJoining nj = NeighborJoining.createInstance(); final BasicSymmetricalDistanceMatrix m0 = new BasicSymmetricalDistanceMatrix( 4 ); @@ -2072,9 +2080,9 @@ public class TestPhylogenyReconstruction { m.setRow( "1.60430 1.43890 0.61790 0.50610 0.34840 0.00000 0.26920", 5 ); m.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 ); //NeighborJoiningR njr = NeighborJoiningR.createInstance( true, 6 ); - nj = NeighborJoining.createInstance( true, 6 ); + nj = NeighborJoining.createInstance( verbose, 6 ); final Phylogeny p2 = nj.execute( m ); - Archaeopteryx.createApplication( p2 ); + //Archaeopteryx.createApplication( p2 ); p2.reRoot( p2.getNode( "Bovine" ) ); if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) { return false; @@ -2192,7 +2200,7 @@ public class TestPhylogenyReconstruction { m.setRow( "1.52430 1.44650 0.59580 0.46310 0.00000 0.34840 0.30830", 4 ); m.setRow( "1.60430 1.43890 0.61790 0.50610 0.34840 0.00000 0.26920", 5 ); m.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 ); - njf = NeighborJoiningF.createInstance( true, 5 ); + njf = NeighborJoiningF.createInstance( verbose, 5 ); final Phylogeny p2f = njf.execute( m ); p2f.reRoot( p2f.getNode( "Bovine" ) ); if ( isUnequal( p2f.getNode( "Chimp" ).getDistanceToParent(), 0.15168 ) ) { @@ -2246,7 +2254,7 @@ public class TestPhylogenyReconstruction { private static boolean testS() { try { - final S s0 = new S(); + final Sset s0 = new Sset(); s0.initialize( 1 ); s0.addPairing( 0, 1, 0 ); s0.addPairing( 7, 8, 0 ); @@ -2381,6 +2389,147 @@ public class TestPhylogenyReconstruction { return true; } + private static boolean testSarray() { + try { + final Sarray s0 = new Sarray(); + s0.initialize( 1 ); + s0.addPairing( 0, 1, 0 ); + s0.addPairing( 7, 8, 0 ); + s0.addPairing( 4, 55, 0 ); + s0.addPairing( 2, 3, 0 ); + s0.addPairing( 4, 5, 0 ); + s0.addPairing( 5, 6666, 0 ); + s0.addPairing( 5, 666, 0 ); + s0.addPairing( 5, 66, 0 ); + s0.addPairing( 5, 6, 0 ); + s0.addPairing( 6, 7, 0 ); + s0.addPairing( 3, 4, 0 ); + s0.addPairing( 1, 2, 0 ); + if ( s0.size() != 1 ) { + return false; + } + if ( s0.getS( 0 ).size() != 8 ) { + return false; + } + if ( s0.getValues( 0, 0 ).length != 1 ) { + return false; + } + if ( s0.getValues( 1, 0 ).length != 1 ) { + return false; + } + if ( s0.getValues( 2, 0 ).length != 1 ) { + return false; + } + if ( s0.getValues( 3, 0 ).length != 1 ) { + return false; + } + if ( s0.getValues( 4, 0 ).length != 2 ) { + return false; + } + if ( s0.getValues( 5, 0 ).length != 4 ) { + return false; + } + if ( s0.getValues( 6, 0 ).length != 1 ) { + return false; + } + if ( s0.getValues( 7, 0 ).length != 1 ) { + return false; + } + if ( s0.getValues( 0, 0 )[ 0 ] != 1 ) { + return false; + } + if ( s0.getValues( 5, 0 )[ 3 ] != 6 ) { + return false; + } + if ( s0.getValues( 5, 0 )[ 2 ] != 66 ) { + return false; + } + if ( s0.getValues( 5, 0 )[ 1 ] != 666 ) { + return false; + } + if ( s0.getValues( 5, 0 )[ 0 ] != 6666 ) { + return false; + } + s0.removePairing( 5, 6666, 0 ); + if ( s0.getValues( 5, 0 ).length != 3 ) { + System.out.println( s0.getValues( 5, 0 ).length ); + return false; + } + // if ( s0.getValues( 5, 0 ).contains( 6666 ) ) { + // return false; + // } + // s0.removePairing( 5, 666, 0 ); + // if ( s0.getValues( 5, 0 ).contains( 666 ) ) { + // return false; + // } + // s0.removePairing( 5, 66, 0 ); + // if ( s0.getValues( 5, 0 ).contains( 66 ) ) { + // return false; + // } + // if ( s0.getValues( 5, 0 ).size() != 1 ) { + // return false; + // } + // if ( s0.getS( 0 ).size() != 8 ) { + // return false; + // } + // s0.removePairing( 5, 6, 0 ); + // if ( s0.getS( 0 ).size() != 7 ) { + // return false; + // } + // s0.addPairing( 5, 6, 0 ); + // if ( s0.getS( 0 ).size() != 8 ) { + // return false; + // } + // if ( s0.getValues( 5, 0 ).size() != 1 ) { + // return false; + // } + // if ( !s0.getValues( 5, 0 ).contains( 6 ) ) { + // return false; + // } + // s0.addPairing( 5, 403, 0 ); + // if ( s0.getValues( 5, 0 ).size() != 2 ) { + // return false; + // } + // if ( !s0.getValues( 5, 0 ).contains( 403 ) ) { + // return false; + // } + // s0.addPairing( 693, 100, 0 ); + // s0.addPairing( 693, 101, 0 ); + // if ( s0.getValues( 693, 0 ).size() != 2 ) { + // return false; + // } + // s0.addPairing( 2, 33, 0 ); + // s0.addPairing( 2, 333, 0 ); + // final Set[] a = s0.toArray( 0 ); + // if ( !a[ 0 ].contains( 1 ) ) { + // return false; + // } + // if ( a[ 0 ].size() != 1 ) { + // return false; + // } + // if ( !a[ 1 ].contains( 2 ) ) { + // return false; + // } + // if ( a[ 1 ].size() != 1 ) { + // return false; + // } + // if ( !a[ 2 ].contains( 3 ) ) { + // return false; + // } + // if ( !a[ 2 ].contains( 33 ) ) { + // return false; + // } + // if ( !a[ 2 ].contains( 333 ) ) { + // return false; + // } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + private static boolean testNeighborJoiningR() { try { final NeighborJoiningR nj0 = NeighborJoiningR.createInstance(); @@ -2480,7 +2629,7 @@ public class TestPhylogenyReconstruction { m2.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 ); final NeighborJoiningR nj2 = NeighborJoiningR.createInstance( true, 6 ); final Phylogeny p2 = nj2.execute( m2 ); - Archaeopteryx.createApplication( p2 ); + // Archaeopteryx.createApplication( p2 ); p2.reRoot( p2.getNode( "Bovine" ) ); if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) { System.out.println( p2.getNode( "Chimp" ).getDistanceToParent() ); @@ -2970,7 +3119,7 @@ public class TestPhylogenyReconstruction { private static void timeNeighborJoining() { final NeighborJoiningR njr = NeighborJoiningR.createInstance(); - for( int n = 3; n <= 9; ++n ) { + for( int n = 3; n <= 10; ++n ) { final int x = ( int ) Math.pow( 2, n ); final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( x ); mt.randomize( new Date().getTime() ); @@ -2979,7 +3128,7 @@ public class TestPhylogenyReconstruction { System.out.println( "Size: " + x + " -> " + ( new Date().getTime() - start_time ) + "ms" ); } final NeighborJoiningF njf = NeighborJoiningF.createInstance(); - for( int n = 3; n <= 9; ++n ) { + for( int n = 3; n <= 10; ++n ) { final int x = ( int ) Math.pow( 2, n ); final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( x ); mt.randomize( new Date().getTime() ); @@ -2988,7 +3137,7 @@ public class TestPhylogenyReconstruction { System.out.println( "Size: " + x + " -> " + ( new Date().getTime() - start_time ) + "ms" ); } final NeighborJoining nj = NeighborJoining.createInstance(); - for( int n = 3; n <= 9; ++n ) { + for( int n = 3; n <= 10; ++n ) { final int x = ( int ) Math.pow( 2, n ); final BasicSymmetricalDistanceMatrix mt = new BasicSymmetricalDistanceMatrix( x ); mt.randomize( new Date().getTime() );