improving GSDI, under construction...
[jalview.git] / forester / java / src / org / forester / sdi / TestGSDI.java
index 14278a9..7aae382 100644 (file)
@@ -111,28 +111,30 @@ public final class TestGSDI {
                     + "),[&&NHX:S=x],[&&NHX:S=y],[&&NHX:S=z])";
             final Phylogeny s2 = ParserBasedPhylogenyFactory.getInstance().create( s2_, new NHXParser() )[ 0 ];
             s2.setRooted( true );
-            //            final String s1_ = "((([&&NHX:S=A2],[&&NHX:S=A1]),[&&NHX:S=B],[&&NHX:S=C]),[&&NHX:S=D])";
-            //            final Phylogeny s1 = ParserBasedPhylogenyFactory.getInstance().create( s1_, new NHXParser() )[ 0 ];
-            //            s1.setRooted( true );
-            //            final Phylogeny g1 = TestGSDI
-            //                    .createPhylogeny( "((((B[&&NHX:S=B],A1[&&NHX:S=A1]),C[&&NHX:S=C]),A2[&&NHX:S=A2]),D[&&NHX:S=D])" );
-            //            final GSDI sdi1 = new GSDI( g1, s1, false );
-            //            if ( sdi1.getDuplicationsSum() != 1 ) {
-            //                return false;
-            //            }
-            //            if ( !pm.obtainLCA( g1.getNode( "B" ), g1.getNode( "A1" ) ).getNodeData().getEvent().isSpeciation() ) {
-            //                return false;
-            //            }
-            //            if ( !pm.obtainLCA( g1.getNode( "C" ), g1.getNode( "A1" ) ).getNodeData().getEvent()
-            //                    .isSpeciationOrDuplication() ) {
-            //                return false;
-            //            }
-            //            if ( !( pm.obtainLCA( g1.getNode( "A2" ), g1.getNode( "A1" ) ).getNodeData().getEvent().isDuplication() ) ) {
-            //                return false;
-            //            }
-            //            if ( !pm.obtainLCA( g1.getNode( "D" ), g1.getNode( "A1" ) ).getNodeData().getEvent().isSpeciation() ) {
-            //                return false;
-            //            }
+            final String s1_ = "((([&&NHX:S=A2],[&&NHX:S=A1]),[&&NHX:S=B],[&&NHX:S=C]),[&&NHX:S=D])";
+            final Phylogeny s1 = ParserBasedPhylogenyFactory.getInstance().create( s1_, new NHXParser() )[ 0 ];
+            s1.setRooted( true );
+            final Phylogeny g1 = TestGSDI
+                    .createPhylogeny( "((((B[&&NHX:S=B],A1[&&NHX:S=A1]),C[&&NHX:S=C]),A2[&&NHX:S=A2]),D[&&NHX:S=D])" );
+            final GSDI sdi1 = new GSDI( g1, s1, false );
+            Archaeopteryx.createApplication( g1 );
+            Archaeopteryx.createApplication( s1 );
+            if ( sdi1.getDuplicationsSum() != 1 ) {
+                return false;
+            }
+            if ( !pm.obtainLCA( g1.getNode( "B" ), g1.getNode( "A1" ) ).getNodeData().getEvent().isSpeciation() ) {
+                return false;
+            }
+            if ( !pm.obtainLCA( g1.getNode( "C" ), g1.getNode( "A1" ) ).getNodeData().getEvent()
+                    .isSpeciationOrDuplication() ) {
+                return false;
+            }
+            if ( !( pm.obtainLCA( g1.getNode( "A2" ), g1.getNode( "A1" ) ).getNodeData().getEvent().isDuplication() ) ) {
+                return false;
+            }
+            if ( !pm.obtainLCA( g1.getNode( "D" ), g1.getNode( "A1" ) ).getNodeData().getEvent().isSpeciation() ) {
+                return false;
+            }
             //            final Phylogeny g2 = TestGSDI
             //                    .createPhylogeny( "((((A2[&&NHX:S=A2],A1[&&NHX:S=A1]),B[&&NHX:S=B]),C[&&NHX:S=C]),D[&&NHX:S=D])" );
             //            final GSDI sdi2 = new GSDI( g2, s1, false );
@@ -246,7 +248,6 @@ public final class TestGSDI {
             //            if ( !TestGSDI.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
             //                return false;
             //            }
-            //           
             //            final Phylogeny g2_0 = TestGSDI.createPhylogeny( "(m1[&&NHX:S=m1],m3[&&NHX:S=m3])" );
             //            final GSDI sdi2_0 = new GSDI( g2_0, s2, false );
             //            if ( sdi2_0.getDuplicationsSum() != 0 ) {
@@ -630,6 +631,8 @@ public final class TestGSDI {
             //            final Phylogeny g2_22 = TestGSDI
             //                    .createPhylogeny( "((n1[&&NHX:S=n1],n2[&&NHX:S=n2]),(n3[&&NHX:S=n3],n4[&&NHX:S=n4]))" );
             //            final GSDI sdi2_22 = new GSDI( g2_22, s2, false );
+            //            //Archaeopteryx.createApplication( g2_22 );
+            //            //Archaeopteryx.createApplication( s2 );
             //            if ( sdi2_22.getDuplicationsSum() != 0 ) {
             //                return false;
             //            }
@@ -879,60 +882,60 @@ public final class TestGSDI {
             //            if ( !TestGSDI.getEvent( g2_32, "a1", "z" ).isSpeciationOrDuplication() ) {
             //                return false;
             //            }
-            //-
-            final Phylogeny g2_33_d = TestGSDI
-                    .createPhylogeny( "((((((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2])[&&NHX:D=N],b1[&&NHX:S=b1])[&&NHX:D=N],c1[&&NHX:S=c1])[&&NHX:D=?],d1[&&NHX:S=d1])[&&NHX:D=?],x[&&NHX:S=x])[&&NHX:D=N],p1[&&NHX:S=p1])[&&NHX:D=?],i1[&&NHX:S=i1])[&&NHX:D=?],k2[&&NHX:S=k2])[&&NHX:D=Y],e1[&&NHX:S=e1])[&&NHX:D=Y],y[&&NHX:S=y])[&&NHX:D=Y],z[&&NHX:S=z])[&&NHX:D=?],(((((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2])[&&NHX:D=N],b1[&&NHX:S=b1])[&&NHX:D=N],c1[&&NHX:S=c1])[&&NHX:D=?],d1[&&NHX:S=d1])[&&NHX:D=?],x[&&NHX:S=x])[&&NHX:D=N],p1[&&NHX:S=p1])[&&NHX:D=?],i1[&&NHX:S=i1])[&&NHX:D=?],k2[&&NHX:S=k2])[&&NHX:D=Y],e1[&&NHX:S=e1])[&&NHX:D=Y],y[&&NHX:S=y])[&&NHX:D=Y],z[&&NHX:S=z])[&&NHX:D=?])" );
-            final GSDI sdi2_33_d = new GSDI( g2_33_d, s2, false );
-            Archaeopteryx.createApplication( g2_33_d );
-            //  Archaeopteryx.createApplication( s2 );
-            //-
-            final Phylogeny g2_33 = TestGSDI
-                    .createPhylogeny( "(((((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2]),b1[&&NHX:S=b1]),c1[&&NHX:S=c1]),d1[&&NHX:S=d1]),x[&&NHX:S=x]),p1[&&NHX:S=p1]),i1[&&NHX:S=i1]),k2[&&NHX:S=k2]),e1[&&NHX:S=e1]),y[&&NHX:S=y]),z[&&NHX:S=z])" );
-            final GSDI sdi2_33 = new GSDI( g2_33, s2, false );
-            Archaeopteryx.createApplication( g2_33 );
-            // Archaeopteryx.createApplication( s2 );
-            if ( sdi2_33.getDuplicationsSum() != 1 ) {
-                return false;
-            }
-            if ( sdi2_33.getSpeciationOrDuplicationEventsSum() != 7 ) {
-                return false;
-            }
-            if ( sdi2_33.getSpeciationsSum() != 3 ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "a2" ).isSpeciation() ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "b1" ).isSpeciation() ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "c1" ).isSpeciationOrDuplication() ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "d1" ).isSpeciationOrDuplication() ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "x" ).isSpeciation() ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "p1" ).isSpeciationOrDuplication() ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "i1" ).isSpeciationOrDuplication() ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "k2" ).isDuplication() ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "e1" ).isSpeciationOrDuplication() ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "y" ).isSpeciationOrDuplication() ) {
-                return false;
-            }
-            if ( !TestGSDI.getEvent( g2_33, "a1", "z" ).isSpeciationOrDuplication() ) {
-                return false;
-            }
+            //            //            //-
+            //            final Phylogeny g2_33_d = TestGSDI
+            //                    .createPhylogeny( "((((((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2])[&&NHX:D=N],b1[&&NHX:S=b1])[&&NHX:D=N],c1[&&NHX:S=c1])[&&NHX:D=?],d1[&&NHX:S=d1])[&&NHX:D=?],x[&&NHX:S=x])[&&NHX:D=N],p1[&&NHX:S=p1])[&&NHX:D=?],i1[&&NHX:S=i1])[&&NHX:D=?],k2[&&NHX:S=k2])[&&NHX:D=Y],e1[&&NHX:S=e1])[&&NHX:D=Y],y[&&NHX:S=y])[&&NHX:D=Y],z[&&NHX:S=z])[&&NHX:D=?],(((((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2])[&&NHX:D=N],b1[&&NHX:S=b1])[&&NHX:D=N],c1[&&NHX:S=c1])[&&NHX:D=?],d1[&&NHX:S=d1])[&&NHX:D=?],x[&&NHX:S=x])[&&NHX:D=N],p1[&&NHX:S=p1])[&&NHX:D=?],i1[&&NHX:S=i1])[&&NHX:D=?],k2[&&NHX:S=k2])[&&NHX:D=Y],e1[&&NHX:S=e1])[&&NHX:D=Y],y[&&NHX:S=y])[&&NHX:D=Y],z[&&NHX:S=z])[&&NHX:D=?])" );
+            //            final GSDI sdi2_33_d = new GSDI( g2_33_d, s2, false );
+            //            Archaeopteryx.createApplication( g2_33_d );
+            //            //  Archaeopteryx.createApplication( s2 );
+            //            //-
+            //            final Phylogeny g2_33 = TestGSDI
+            //                    .createPhylogeny( "(((((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2]),b1[&&NHX:S=b1]),c1[&&NHX:S=c1]),d1[&&NHX:S=d1]),x[&&NHX:S=x]),p1[&&NHX:S=p1]),i1[&&NHX:S=i1]),k2[&&NHX:S=k2]),e1[&&NHX:S=e1]),y[&&NHX:S=y]),z[&&NHX:S=z])" );
+            //            final GSDI sdi2_33 = new GSDI( g2_33, s2, false );
+            //            Archaeopteryx.createApplication( g2_33 );
+            //            Archaeopteryx.createApplication( s2 );
+            //            if ( sdi2_33.getDuplicationsSum() != 1 ) {
+            //                return false;
+            //            }
+            //            if ( sdi2_33.getSpeciationOrDuplicationEventsSum() != 7 ) {
+            //                return false;
+            //            }
+            //            if ( sdi2_33.getSpeciationsSum() != 3 ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "a2" ).isSpeciation() ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "b1" ).isSpeciation() ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "c1" ).isSpeciationOrDuplication() ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "d1" ).isSpeciationOrDuplication() ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "x" ).isSpeciation() ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "p1" ).isSpeciationOrDuplication() ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "i1" ).isSpeciationOrDuplication() ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "k2" ).isDuplication() ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "e1" ).isSpeciationOrDuplication() ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "y" ).isSpeciationOrDuplication() ) {
+            //                return false;
+            //            }
+            //            if ( !TestGSDI.getEvent( g2_33, "a1", "z" ).isSpeciationOrDuplication() ) {
+            //                return false;
+            //            }
             //            final Phylogeny g2_34 = TestGSDI
             //                    .createPhylogeny( "(((n1_0[&&NHX:S=n1],n2_0[&&NHX:S=n2]),(n1_1[&&NHX:S=n1],n3_0[&&NHX:S=n3])),n4_0[&&NHX:S=n4])" );
             //            final GSDI sdi2_34 = new GSDI( g2_34, s2, false );
@@ -1199,23 +1202,23 @@ public final class TestGSDI {
             //                return false;
             //            }
             //---------------------
-            // final String g2_0_ =
-            // "(([&&NHX:S=a1],[&&NHX:S=a2]),([&&NHX:S=o2],[&&NHX:S=o4]))";
-            // final Phylogeny g2_0 = factory.create( g2_0_, new NHXParser() )[
-            // 0 ];
-            // g2_0.setRooted( true );
-            // final GSDI sdi2_0 = new GSDI( g2_0, s2, false );
-            // if ( sdi2_0.getDuplicationsSum() != 0 ) {
-            // return false;
-            // }
-            // final String g2_1_= "";
-            // final Phylogeny g2_1 = factory.create( g2_1_, new NHXParser() )[
-            // 0 ];
-            // g2_1.setRooted( true );
-            // final GSDI sdi2_1 = new GSDI( g2_1, s2, false );
-            // if ( sdi2_1.getDuplicationsSum() != 0 ) {
-            // return false;
-            // }
+            //             final String g2_0_ =
+            //             "(([&&NHX:S=a1],[&&NHX:S=a2]),([&&NHX:S=o2],[&&NHX:S=o4]))";
+            //             final Phylogeny g2_0 = factory.create( g2_0_, new NHXParser() )[
+            //             0 ];
+            //             g2_0.setRooted( true );
+            //             final GSDI sdi2_0 = new GSDI( g2_0, s2, false );
+            //             if ( sdi2_0.getDuplicationsSum() != 0 ) {
+            //             return false;
+            //             }
+            //             final String g2_1_= "";
+            //             final Phylogeny g2_1 = factory.create( g2_1_, new NHXParser() )[
+            //             0 ];
+            //             g2_1.setRooted( true );
+            //             final GSDI sdi2_1 = new GSDI( g2_1, s2, false );
+            //             if ( sdi2_1.getDuplicationsSum() != 0 ) {
+            //             return false;
+            //             }
         }
         catch ( final Exception e ) {
             e.printStackTrace( System.out );
@@ -1231,6 +1234,9 @@ public final class TestGSDI {
         if ( !TestGSDI.testGSDI_general() ) {
             System.out.println( "general failed" );
         }
+        else {
+            System.out.println( "general OK" );
+        }
         //        boolean success = test();
         //        if ( success ) {
         //            System.out.println( "OK" );