System.out.println( "failed." );
failed++;
}
+ System.out.print( "Node construction and parsing of NHX (node level): " );
+ if ( Test.testNHXNodeParsing2() ) {
+ System.out.println( "OK." );
+ succeeded++;
+ }
+ else {
+ System.out.println( "failed." );
+ failed++;
+ }
System.out.print( "NHX parsing iterating: " );
if ( Test.testNHParsingIter() ) {
System.out.println( "OK." );
System.out.println( "failed." );
failed++;
}
+ System.out.print( "phyloXML parsing (validating against schema): " );
+ if ( testPhyloXMLparsingValidating() ) {
+ System.out.println( "OK." );
+ succeeded++;
+ }
+ else {
+ System.out.println( "failed." );
+ failed++;
+ }
System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
System.out.println( "OK." );
}
return true;
}
+
+ private static boolean testPhyloXMLparsingValidating() {
+ try {
+ final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
+ PhyloXmlParser xml_parser = null;
+ try {
+ xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
+ }
+ catch ( final Exception e ) {
+ // Do nothing -- means were not running from jar.
+ }
+ if ( xml_parser == null ) {
+ xml_parser = PhyloXmlParser.createPhyloXmlParser();
+ if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
+ xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
+ }
+ else {
+ xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
+ }
+ }
+ final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phyloxml_test_1.xml" ),
+ xml_parser );
+ if ( xml_parser.getErrorCount() > 0 ) {
+ System.out.println( xml_parser.getErrorMessages().toString() );
+ return false;
+ }
+ if ( phylogenies_0.length != 3 ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
private static boolean testBasicProtein() {
try {
if ( t2.getNumberOfExternalNodes() != 4 ) {
return false;
}
- if ( t2.getHeight() != 8.5 ) {
+ if ( t2.calculateHeight(false) != 8.5 ) {
return false;
}
if ( !t2.isCompletelyBinary() ) {
if ( t3.getNumberOfExternalNodes() != 5 ) {
return false;
}
- if ( t3.getHeight() != 11 ) {
+ if ( t3.calculateHeight(true) != 11 ) {
return false;
}
if ( t3.isCompletelyBinary() ) {
if ( t4.getNumberOfExternalNodes() != 9 ) {
return false;
}
- if ( t4.getHeight() != 11 ) {
+ if ( t4.calculateHeight(false) != 11 ) {
return false;
}
if ( t4.isCompletelyBinary() ) {
if ( t5.getNumberOfExternalNodes() != 8 ) {
return false;
}
- if ( t5.getHeight() != 15 ) {
+ if ( t5.calculateHeight(false) != 15 ) {
return false;
}
final StringBuffer sb6 = new StringBuffer( "(X,Y,Z,(((A111)A11:2)A1:2,(X,Y,Z,A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:3,D:8)" );
final Phylogeny t6 = factory.create( sb6.toString(), new NHXParser() )[ 0 ];
- if ( t6.getHeight() != 15 ) {
+ if ( t6.calculateHeight(true) != 15 ) {
return false;
}
final StringBuffer sb7 = new StringBuffer( "(((A11:2)A1:2,(A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:15,D:8)" );
final Phylogeny t7 = factory.create( sb7.toString(), new NHXParser() )[ 0 ];
- if ( t7.getHeight() != 15 ) {
+ if ( t7.calculateHeight(true) != 15 ) {
return false;
}
final StringBuffer sb8 = new StringBuffer( "(((A11:11)A1:2,(A21:2,A22:2,A23,A24,AA:)A2:11,A3:2)A:2,B:15,C:15,D:15)" );
if ( t8.getNumberOfExternalNodes() != 10 ) {
return false;
}
- if ( t8.getHeight() != 15 ) {
+ if ( t8.calculateHeight(true) != 15 ) {
return false;
}
final char[] a9 = new char[] { 'a' };
final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
- if ( t9.getHeight() != 0 ) {
+ if ( t9.calculateHeight(true) != 0 ) {
return false;
}
final char[] a10 = new char[] { 'a', ':', '6' };
final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
- if ( t10.getHeight() != 6 ) {
+ if ( t10.calculateHeight(true) != 6 ) {
return false;
}
}
System.out.println( p61.toNewHampshire() );
return false;
}
+ final String s62 = "(1[&type=\"X\",size=123,subtree=(1,2);]:0.003,2[&type=\"(X,Y:3)\"]:0.004)[&type=\"(X,Y)\"]:0.0;";
+ final Phylogeny p62 = factory.create( s62, new NHXParser() )[ 0 ];
+ if ( !p62.toNewHampshire()
+ .equals( "(1:0.003,2:0.004):0.0;" ) ) {
+ System.out.println( p62.toNewHampshire() );
+ return false;
+ }
+ final String s63 = "(1:0.003[&type=\"X\",size=123,subtree=(1,2);],2:0.004[&type=\"(X,Y:3)\"]):0.0[&type=\"(X,Y)\"];";
+ final Phylogeny p63 = factory.create( s63, new NHXParser() )[ 0 ];
+ if ( !p63.toNewHampshire()
+ .equals( "(1:0.003,2:0.004):0.0;" ) ) {
+ System.out.println( p63.toNewHampshire() );
+ return false;
+ }
+ final String s64 = "((1,2):[95.5],3);";
+ final Phylogeny p64 = factory.create( s64, new NHXParser() )[ 0 ];
+ if ( !p64.toNewHampshireX()
+ .equals( "((1,2)[&&NHX:B=95.5],3)" ) ) {
+ System.out.println( p64.toNewHampshireX() );
+ return false;
+ }
+ final String s65 = "((1:0.1,2:0.2):0.3[10.2],3);";
+ final Phylogeny p65 = factory.create( s65, new NHXParser() )[ 0 ];
+ if ( !p65.toNewHampshireX()
+ .equals( "((1:0.1,2:0.2):0.3[&&NHX:B=10.2],3)" ) ) {
+ System.out.println( p65.toNewHampshireX() );
+ return false;
+ }
}
catch ( final Exception e ) {
e.printStackTrace( System.out );
return true;
}
+
+ private static boolean testNHXNodeParsing2() {
+ try {
+
+ final PhylogenyNode n0_0 = PhylogenyNode
+ .createInstanceFromNhxString( "n0:[ignore me 123]:1E-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n0_0.getName().equals( "n0" ) ) {
+ return false;
+ }
+ if ( !isEqual( n0_0.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ final PhylogenyNode n0_1 = PhylogenyNode
+ .createInstanceFromNhxString( "n0[ignore me 123]:1E-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n0_1.getName().equals( "n0" ) ) {
+ return false;
+ }
+ if ( !isEqual( n0_1.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ final PhylogenyNode n0_2 = PhylogenyNode
+ .createInstanceFromNhxString( "n0:1E-3[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n0_2.getName().equals( "n0" ) ) {
+ return false;
+ }
+ if ( !isEqual( n0_2.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ final PhylogenyNode n0_3 = PhylogenyNode
+ .createInstanceFromNhxString( "n0:1E-3:[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n0_3.getName().equals( "n0" ) ) {
+ return false;
+ }
+ if ( !isEqual( n0_3.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ final PhylogenyNode n0_4 = PhylogenyNode
+ .createInstanceFromNhxString( "n0:0.001:[ignore me 123]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n0_4.getName().equals( "n0" ) ) {
+ return false;
+ }
+ if ( !isEqual( n0_4.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ final PhylogenyNode n1_0 = PhylogenyNode
+ .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n1_0.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
+ return false;
+ }
+ if ( n1_0.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
+ return false;
+ }
+ final PhylogenyNode n1_1 = PhylogenyNode
+ .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&!color=#FFFFFF]:0.001", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n1_1.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
+ return false;
+ }
+ if ( n1_1.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
+ return false;
+ }
+ if ( !isEqual( n1_1.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ final PhylogenyNode n1_2 = PhylogenyNode
+ .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:0.001[&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n1_2.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
+ return false;
+ }
+ if ( n1_2.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
+ return false;
+ }
+ if ( !isEqual( n1_2.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ final PhylogenyNode n1_3 = PhylogenyNode
+ .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[&boostrap=69,&!color=#FFFFFF]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n1_3.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
+ return false;
+ }
+ if ( n1_3.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
+ return false;
+ }
+ if ( !isEqual( n1_3.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ if ( !isEqual( n1_3.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
+ return false;
+ }
+ if ( !n1_3.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
+ return false;
+ }
+ final PhylogenyNode n1_4 = PhylogenyNode
+ .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&bootstrap=69,&!colour=#FFFFFF]:1e-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n1_4.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
+ return false;
+ }
+ if ( n1_4.getBranchData().getBranchColor().getValue().getGreen()!=255 ) {
+ return false;
+ }
+ if ( !isEqual( n1_4.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ if ( !isEqual( n1_4.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
+ return false;
+ }
+ if ( !n1_4.getBranchData().getConfidence( 0 ).getType().equals( "bootstrap" ) ) {
+ return false;
+ }
+ final PhylogenyNode n1_5 = PhylogenyNode
+ .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada:1e-3[69.0]", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n1_5.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
+ return false;
+ }
+ if ( !isEqual( n1_5.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ if ( !isEqual( n1_5.getBranchData().getConfidence( 0 ).getValue(), 69 ) ) {
+ return false;
+ }
+ final PhylogenyNode n1_6 = PhylogenyNode
+ .createInstanceFromNhxString( "xyz|A/American_duck/NH/00321/|Duck|Canada[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00]:1e-3", NHXParser.TAXONOMY_EXTRACTION.NO, true, true );
+ if ( !n1_6.getName().equals( "xyz|A/American duck/NH/00321/|Duck|Canada" ) ) {
+ return false;
+ }
+
+ if ( !isEqual( n1_6.getDistanceToParent(), 0.001 ) ) {
+ return false;
+ }
+ if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getStandardDeviation(), 0.11 ) ) {
+ return false;
+ }
+ if ( !isEqual( n1_6.getBranchData().getConfidence( 0 ).getValue(), 0.95 ) ) {
+ return false;
+ }
+ if ( !n1_6.getBranchData().getConfidence( 0 ).getType().equals( "posterior probability" ) ) {
+ return false;
+ }
+ }
+ catch ( final Exception e ) {
+ e.printStackTrace( System.out );
+ return false;
+ }
+ return true;
+ }
+
private static boolean testNHXParsing() {
try {
final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();