+ if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
+ .equals( "Aranaeus" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 1 ].isRooted() ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
+ .equals( "Aranaeus" ) ) {
+ return false;
+ }
+ if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].isRooted() ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
+ return false;
+ }
+ if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
+ .equals( "Aranaeus" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean testNHParsing() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
+ if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
+ return false;
+ }
+ final NHXParser nhxp = new NHXParser();
+ nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
+ nhxp.setReplaceUnderscores( true );
+ final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
+ if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
+ return false;
+ }
+ if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
+ return false;
+ }
+ final Phylogeny p1b = factory
+ .create( " \n \t \b \r \f ; ( \n \t \b \r \f; A ; \n \t \b \r \f, \n \t \b \r \f; B ; \n \t \b \r \f 1 \n \t \b \r \f ; \n \t \b \r \f );;;;; \n \t \b \r \f;;; \n \t \b \r \f ",
+ new NHXParser() )[ 0 ];
+ if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
+ return false;
+ }
+ if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
+ return false;
+ }
+ final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
+ final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
+ final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
+ final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
+ final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
+ final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
+ final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
+ final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
+ final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
+ final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
+ final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
+ + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
+ + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
+ new NHXParser() );
+ if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
+ return false;
+ }
+ if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
+ return false;
+ }
+ if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
+ return false;
+ }
+ if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
+ return false;
+ }
+ final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
+ final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
+ final String p16_S = "((A,B),C)";
+ final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
+ if ( p16.length != 1 ) {
+ return false;
+ }
+ if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
+ return false;
+ }
+ final String p17_S = "(C,(A,B))";
+ final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
+ if ( p17.length != 1 ) {
+ return false;
+ }
+ if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
+ return false;
+ }
+ final String p18_S = "((A,B),(C,D))";
+ final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
+ if ( p18.length != 1 ) {
+ return false;
+ }
+ if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
+ return false;
+ }
+ final String p19_S = "(((A,B),C),D)";
+ final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
+ if ( p19.length != 1 ) {
+ return false;
+ }
+ if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
+ return false;
+ }
+ final String p20_S = "(A,(B,(C,D)))";
+ final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
+ if ( p20.length != 1 ) {
+ return false;
+ }
+ if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
+ return false;
+ }
+ final String p21_S = "(A,(B,(C,(D,E))))";
+ final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
+ if ( p21.length != 1 ) {
+ return false;
+ }
+ if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
+ return false;
+ }
+ final String p22_S = "((((A,B),C),D),E)";
+ final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
+ if ( p22.length != 1 ) {
+ return false;
+ }
+ if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
+ return false;
+ }
+ final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
+ final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
+ if ( p23.length != 1 ) {
+ System.out.println( "xl=" + p23.length );
+ System.exit( -1 );
+ return false;
+ }
+ if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
+ return false;
+ }
+ final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
+ final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
+ if ( p24.length != 1 ) {
+ return false;
+ }
+ if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
+ return false;
+ }
+ final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
+ final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
+ final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
+ if ( p241.length != 2 ) {
+ return false;
+ }
+ if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
+ return false;
+ }
+ if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
+ return false;
+ }
+ final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
+ + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
+ + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
+ + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
+ + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
+ + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
+ + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
+ + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
+ final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
+ if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
+ return false;
+ }
+ final String p26_S = "(A,B)ab";
+ final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
+ if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
+ return false;
+ }
+ final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
+ final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
+ if ( p27s.length != 1 ) {
+ System.out.println( "xxl=" + p27s.length );
+ System.exit( -1 );
+ return false;
+ }
+ if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
+ System.out.println( p27s[ 0 ].toNewHampshireX() );
+ System.exit( -1 );
+ return false;
+ }
+ final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
+ new NHXParser() );
+ if ( p27.length != 1 ) {
+ System.out.println( "yl=" + p27.length );
+ System.exit( -1 );
+ return false;
+ }
+ if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
+ System.out.println( p27[ 0 ].toNewHampshireX() );
+ System.exit( -1 );
+ return false;
+ }
+ final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
+ final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
+ final String p28_S3 = "(A,B)ab";
+ final String p28_S4 = "((((A,B),C),D),;E;)";
+ final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
+ new NHXParser() );
+ if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
+ return false;
+ }
+ if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
+ return false;
+ }
+ if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
+ return false;
+ }
+ if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
+ return false;
+ }
+ if ( p28.length != 4 ) {
+ return false;
+ }
+ final String p29_S = "((((A:0.01,B:0.684)ab:0.345,C:0.3451)abc:0.3451,D:1.5)abcd:0.134,E:0.32)abcde:0.1345";
+ final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
+ if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
+ return false;
+ }
+ final String p30_S = "((((A:0.01,B:0.02):0.93,C:0.04):0.05,D:1.4):0.06,E):0.72";
+ final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
+ if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
+ return false;
+ }
+ final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
+ final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
+ if ( ( p32.length != 0 ) ) {
+ return false;
+ }
+ final String p33_S = "A";
+ final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
+ if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
+ return false;
+ }
+ final String p34_S = "B;";
+ final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
+ if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
+ return false;
+ }
+ final String p35_S = "B:0.2";
+ final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
+ if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
+ return false;
+ }
+ final String p36_S = "(A)";
+ final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
+ if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
+ return false;
+ }
+ final String p37_S = "((A))";
+ final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
+ if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
+ return false;
+ }
+ final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
+ final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
+ if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
+ return false;
+ }
+ final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
+ final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
+ if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
+ return false;
+ }
+ final String p40_S = "(A,B,C)";
+ final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
+ if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
+ return false;
+ }
+ final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
+ final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
+ if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
+ return false;
+ }
+ final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
+ final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
+ if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {