X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Ftest%2FTest.java;h=598ad3a1e09f07e39af60d55f5bf9e03d41fe62d;hb=6062dfb954cafb6af22e01af89222888d9d5ba66;hp=b7eff503af9e841abd707d1215aecbd0554eb2ee;hpb=b1a74bd076c917d428002284a53a2c6f390226fb;p=jalview.git diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index b7eff50..598ad3a 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -21,7 +21,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.test; @@ -38,6 +38,7 @@ import java.util.Locale; import java.util.Set; import org.forester.application.support_transfer; +import org.forester.archaeopteryx.AptxUtil; import org.forester.development.DevelopmentTools; import org.forester.evoinference.TestPhylogenyReconstruction; import org.forester.evoinference.matrix.character.CharacterStateMatrix; @@ -51,9 +52,12 @@ import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser; import org.forester.io.parsers.nexus.NexusCharactersParser; import org.forester.io.parsers.nexus.NexusPhylogeniesParser; import org.forester.io.parsers.nhx.NHXParser; +import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION; import org.forester.io.parsers.phyloxml.PhyloXmlParser; import org.forester.io.parsers.tol.TolParser; +import org.forester.io.parsers.util.ParserUtils; import org.forester.io.writers.PhylogenyWriter; +import org.forester.io.writers.SequenceWriter; import org.forester.msa.BasicMsa; import org.forester.msa.Mafft; import org.forester.msa.Msa; @@ -64,7 +68,8 @@ import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyBranch; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; -import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE; +import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE; +import org.forester.phylogeny.data.Accession; import org.forester.phylogeny.data.BinaryCharacters; import org.forester.phylogeny.data.BranchWidth; import org.forester.phylogeny.data.Confidence; @@ -84,9 +89,9 @@ import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.phylogeny.factories.PhylogenyFactory; import org.forester.phylogeny.iterators.PhylogenyNodeIterator; import org.forester.protein.Protein; +import org.forester.rio.TestRIO; import org.forester.sdi.SDI; import org.forester.sdi.SDIR; -import org.forester.sdi.SDIse; import org.forester.sdi.TestGSDI; import org.forester.sequence.BasicSequence; import org.forester.sequence.Sequence; @@ -135,8 +140,7 @@ public final class Test { } private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) { - final PhylogenyMethods pm = PhylogenyMethods.getInstance(); - return pm.obtainLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent(); + return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent(); } public static boolean isEqual( final double a, final double b ) { @@ -170,6 +174,15 @@ public final class Test { System.exit( -1 ); } final long start_time = new Date().getTime(); + System.out.print( "Sequence writer: " ); + if ( testSequenceWriter() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } System.out.print( "Sequence id parsing: " ); if ( testSequenceIdParsing() ) { System.out.println( "OK." ); @@ -177,7 +190,6 @@ public final class Test { } else { System.out.println( "failed." ); - System.exit( -1 ); //TODO FIXME remove me!! ~ failed++; } System.out.print( "Hmmscan output parser: " ); @@ -198,6 +210,51 @@ public final class Test { System.out.println( "failed." ); failed++; } + System.out.print( "Taxonomy code extraction: " ); + if ( Test.testExtractTaxonomyCodeFromNodeName() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.print( "SN extraction: " ); + if ( Test.testExtractSNFromNodeName() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.print( "Taxonomy extraction (general): " ); + if ( Test.testTaxonomyExtraction() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.print( "UniProtKB id extraction: " ); + if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.print( "Uri for Aptx web sequence accession: " ); + if ( Test.testCreateUriForSeqWeb() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } System.out.print( "Basic node construction and parsing of NHX (node level): " ); if ( Test.testNHXNodeParsing() ) { System.out.println( "OK." ); @@ -207,6 +264,15 @@ public final class Test { System.out.println( "failed." ); failed++; } + System.out.print( "NHX parsing iterating: " ); + if ( Test.testNHParsingIter() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } System.out.print( "NH parsing: " ); if ( Test.testNHParsing() ) { System.out.println( "OK." ); @@ -261,6 +327,15 @@ public final class Test { System.out.println( "failed." ); failed++; } + System.out.print( "Nexus tree parsing iterating: " ); + if ( Test.testNexusTreeParsingIterating() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } System.out.print( "Nexus tree parsing: " ); if ( Test.testNexusTreeParsing() ) { System.out.println( "OK." ); @@ -351,6 +426,15 @@ public final class Test { System.out.println( "failed." ); failed++; } + System.out.print( "Tree methods: " ); + if ( Test.testTreeMethods() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } System.out.print( "Postorder Iterator: " ); if ( Test.testPostOrderIterator() ) { System.out.println( "OK." ); @@ -450,6 +534,15 @@ public final class Test { System.out.println( "failed." ); failed++; } + System.out.print( "Node removal: " ); + if ( Test.testNodeRemoval() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } System.out.print( "Support count: " ); if ( Test.testSupportCount() ) { System.out.println( "OK." ); @@ -477,6 +570,15 @@ public final class Test { System.out.println( "failed." ); failed++; } + System.out.print( "Finding of LCA 2: " ); + if ( Test.testGetLCA2() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } System.out.print( "Calculation of distance between nodes: " ); if ( Test.testGetDistance() ) { System.out.println( "OK." ); @@ -486,8 +588,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "SDIse: " ); - if ( Test.testSDIse() ) { + System.out.print( "Descriptive statistics: " ); + if ( Test.testDescriptiveStatistics() ) { System.out.println( "OK." ); succeeded++; } @@ -495,8 +597,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "SDIunrooted: " ); - if ( Test.testSDIunrooted() ) { + System.out.print( "Data objects and methods: " ); + if ( Test.testDataObjects() ) { System.out.println( "OK." ); succeeded++; } @@ -504,8 +606,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "GSDI: " ); - if ( TestGSDI.test() ) { + System.out.print( "Properties map: " ); + if ( Test.testPropertiesMap() ) { System.out.println( "OK." ); succeeded++; } @@ -513,8 +615,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "Descriptive statistics: " ); - if ( Test.testDescriptiveStatistics() ) { + System.out.print( "SDIse: " ); + if ( Test.testSDIse() ) { System.out.println( "OK." ); succeeded++; } @@ -522,8 +624,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "Data objects and methods: " ); - if ( Test.testDataObjects() ) { + System.out.print( "SDIunrooted: " ); + if ( Test.testSDIunrooted() ) { System.out.println( "OK." ); succeeded++; } @@ -531,8 +633,17 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "Properties map: " ); - if ( Test.testPropertiesMap() ) { + System.out.print( "GSDI: " ); + if ( TestGSDI.test() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.print( "RIO: " ); + if ( TestRIO.test() ) { System.out.println( "OK." ); succeeded++; } @@ -699,13 +810,13 @@ public final class Test { else { path = "/home/czmasek/bin/mafft"; } - if ( !Mafft.isInstalled( path ) ) { + if ( !MsaInferrer.isInstalled( path ) ) { path = "mafft"; } - if ( !Mafft.isInstalled( path ) ) { + if ( !MsaInferrer.isInstalled( path ) ) { path = "/usr/local/bin/mafft"; } - if ( Mafft.isInstalled( path ) ) { + if ( MsaInferrer.isInstalled( path ) ) { System.out.print( "MAFFT (external program): " ); if ( Test.testMafft( path ) ) { System.out.println( "OK." ); @@ -734,15 +845,6 @@ public final class Test { System.out.println( "failed." ); failed++; } - // System.out.print( "WABI TxSearch: " ); - // if ( Test.testWabiTxSearch() ) { - // System.out.println( "OK." ); - // succeeded++; - // } - // else { - // System.out - // .println( "failed [will not count towards failed tests since it might be due to absence internet connection]" ); - // } System.out.println(); final Runtime rt = java.lang.Runtime.getRuntime(); final long free_memory = rt.freeMemory() / 1000000; @@ -759,106 +861,172 @@ public final class Test { else { System.out.println( "Not OK." ); } - // System.out.println(); - // Development.setTime( true ); - //try { - // final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - // final String clc = System.getProperty( "user.dir" ) + ForesterUtil.getFileSeparator() - // + "examples" + ForesterUtil.getFileSeparator() + "CLC.nhx"; - // final String multi = Test.PATH_TO_EXAMPLE_FILES + - // "multifurcations_ex_1.nhx"; - // final String domains = Test.PATH_TO_EXAMPLE_FILES + "domains1.nhx"; - // final Phylogeny t1 = factory.create( new File( domains ), new - // NHXParser() )[ 0 ]; - // final Phylogeny t2 = factory.create( new File( clc ), new NHXParser() )[ 0 ]; - // } - // catch ( final Exception e ) { - // e.printStackTrace(); - // } - // t1.getRoot().preorderPrint(); - // final PhylogenyFactory factory = ParserBasedPhylogenyFactory - // .getInstance(); - // try { - // - // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES - // + "\\AtNBSpos.nhx" ) ); - // factory.create( - // new File( PATH_TO_EXAMPLE_FILES + "\\AtNBSpos.nhx" ), - // new NHXParser() ); - // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES - // + "\\AtNBSpos.nhx" ) ); - // factory.create( - // new File( PATH_TO_EXAMPLE_FILES + "\\AtNBSpos.nhx" ), - // new NHXParser() ); - // - // - // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES - // + "\\big_tree.nhx" ) ); - // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES - // + "\\big_tree.nhx" ) ); - // factory.create( - // new File( PATH_TO_EXAMPLE_FILES + "\\big_tree.nhx" ), - // new NHXParser() ); - // factory.create( - // new File( PATH_TO_EXAMPLE_FILES + "\\big_tree.nhx" ), - // new NHXParser() ); - // - // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES - // + "\\big_tree.nhx" ) ); - // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES - // + "\\big_tree.nhx" ) ); - // - // factory.create( - // new File( PATH_TO_EXAMPLE_FILES + "\\big_tree.nhx" ), - // new NHXParser() ); - // factory.create( - // new File( PATH_TO_EXAMPLE_FILES + "\\big_tree.nhx" ), - // new NHXParser() ); - // - // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES - // + "\\AtNBSpos.nhx" ) ); - // factory.create( - // new File( PATH_TO_EXAMPLE_FILES + "\\AtNBSpos.nhx" ), - // new NHXParser() ); - // - // } - // catch ( IOException e ) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } } - private static boolean testBasicNodeMethods() { + private static boolean testExtractUniProtKbProteinSeqIdentifier() { try { - if ( PhylogenyNode.getNodeCount() != 0 ) { + PhylogenyNode n = new PhylogenyNode(); + n.setName( "tr|B3RJ64" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { return false; } - final PhylogenyNode n1 = new PhylogenyNode(); - final PhylogenyNode n2 = PhylogenyNode - .createInstanceFromNhxString( "", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - final PhylogenyNode n3 = PhylogenyNode - .createInstanceFromNhxString( "n3", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - final PhylogenyNode n4 = PhylogenyNode - .createInstanceFromNhxString( "n4:0.01", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( n1.isHasAssignedEvent() ) { + n.setName( "tr.B3RJ64" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { return false; } - if ( PhylogenyNode.getNodeCount() != 4 ) { + n.setName( "tr=B3RJ64" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { return false; } - if ( n3.getIndicator() != 0 ) { + n.setName( "tr-B3RJ64" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { return false; } - if ( n3.getNumberOfExternalNodes() != 1 ) { + n.setName( "tr/B3RJ64" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { return false; } - if ( !n3.isExternal() ) { + n.setName( "tr\\B3RJ64" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { return false; } - if ( !n3.isRoot() ) { + n.setName( "tr_B3RJ64" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { return false; } - if ( !n4.getName().equals( "n4" ) ) { + n.setName( " tr|B3RJ64 " ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { + return false; + } + n.setName( "-tr|B3RJ64-" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { + return false; + } + n.setName( "-tr=B3RJ64-" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { + return false; + } + n.setName( "_tr=B3RJ64_" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { + return false; + } + n.setName( " tr_tr|B3RJ64_sp|123 " ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { + return false; + } + n.setName( "sp|B3RJ64" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { + return false; + } + n.setName( "ssp|B3RJ64" ); + if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) { + return false; + } + n.setName( "sp|B3RJ64C" ); + if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) { + return false; + } + n.setName( "sp B3RJ64" ); + if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) { + return false; + } + n.setName( "sp|B3RJ6X" ); + if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) { + return false; + } + n.setName( "sp|B3RJ6" ); + if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) { + return false; + } + n.setName( "K1PYK7_CRAGI" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) { + return false; + } + n.setName( "K1PYK7_PEA" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) { + return false; + } + n.setName( "K1PYK7_RAT" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) { + return false; + } + n.setName( "K1PYK7_PIG" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) { + return false; + } + n.setName( "~K1PYK7_PIG~" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) { + return false; + } + n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) { + return false; + } + n.setName( "K1PYKX_CRAGI" ); + if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) { + return false; + } + n.setName( "XXXXX_CRAGI" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) { + return false; + } + n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) { + return false; + } + n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" ); + if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) { + return false; + } + n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) { + return false; + } + n = new PhylogenyNode(); + org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence(); + seq.setSymbol( "K1PYK7_CRAGI" ); + n.getNodeData().addSequence( seq ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) { + return false; + } + seq.setSymbol( "tr|B3RJ64" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { + return false; + } + n = new PhylogenyNode(); + seq = new org.forester.phylogeny.data.Sequence(); + seq.setName( "K1PYK7_CRAGI" ); + n.getNodeData().addSequence( seq ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) { + return false; + } + seq.setName( "tr|B3RJ64" ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { + return false; + } + n = new PhylogenyNode(); + seq = new org.forester.phylogeny.data.Sequence(); + seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) ); + n.getNodeData().addSequence( seq ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) { + return false; + } + n = new PhylogenyNode(); + seq = new org.forester.phylogeny.data.Sequence(); + seq.setAccession( new Accession( "tr|B3RJ64", "?" ) ); + n.getNodeData().addSequence( seq ); + if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) { + return false; + } + // + n = new PhylogenyNode(); + n.setName( "ACP19736" ); + if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) { + return false; + } + n = new PhylogenyNode(); + n.setName( "_ACP19736_" ); + if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) { return false; } } @@ -869,283 +1037,224 @@ public final class Test { return true; } - private static boolean testBasicPhyloXMLparsing() { + private static boolean testCreateUriForSeqWeb() { try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final PhyloXmlParser xml_parser = new PhyloXmlParser(); - final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml", - xml_parser ); - if ( xml_parser.getErrorCount() > 0 ) { - System.out.println( xml_parser.getErrorMessages().toString() ); + final PhylogenyNode n = new PhylogenyNode(); + n.setName( "tr|B3RJ64" ); + if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) { return false; } - if ( phylogenies_0.length != 4 ) { + n.setName( "B0LM41_HUMAN" ); + if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) { return false; } - final Phylogeny t1 = phylogenies_0[ 0 ]; - final Phylogeny t2 = phylogenies_0[ 1 ]; - final Phylogeny t3 = phylogenies_0[ 2 ]; - final Phylogeny t4 = phylogenies_0[ 3 ]; - if ( t1.getNumberOfExternalNodes() != 1 ) { + n.setName( "NP_001025424" ); + if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) { return false; } - if ( !t1.isRooted() ) { + n.setName( "_NM_001030253-" ); + if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) { return false; } - if ( t1.isRerootable() ) { + n.setName( "XM_002122186" ); + if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) { return false; } - if ( !t1.getType().equals( "gene_tree" ) ) { + n.setName( "dgh_AAA34956_gdg" ); + if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) { return false; } - if ( t2.getNumberOfExternalNodes() != 2 ) { + n.setName( "j40f4_Q06891.1_fndn2 fnr3" ); + if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891.1" ) ) { return false; } - if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) { + n.setName( "GI:394892" ); + if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) { + System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) ); return false; } - if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) { + n.setName( "gi_394892" ); + if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) { + System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) ); return false; } - if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) { + n.setName( "gi6335_gi_394892_56635_Gi_43" ); + if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) { + System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) ); return false; } - if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) { + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testExtractSNFromNodeName() { + try { + if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) { return false; } - if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) { + if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" ) + .equals( "Mus musculus musculus" ) ) { return false; } - if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) { + if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" ) + .equals( "Mus musculus musculus" ) ) { return false; } - if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence() - .startsWith( "actgtgggggt" ) ) { + if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) { return false; } - if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence() - .startsWith( "ctgtgatgcat" ) ) { + if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" ) + .equals( "Mus musculus" ) ) { return false; } - if ( t3.getNumberOfExternalNodes() != 4 ) { + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testExtractTaxonomyCodeFromNodeName() { + try { + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { return false; } - if ( !t1.getName().equals( "t1" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "SOYBN" ) ) { return false; } - if ( !t2.getName().equals( "t2" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "ARATH" ) ) { return false; } - if ( !t3.getName().equals( "t3" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "ARATH" ) ) { return false; } - if ( !t4.getName().equals( "t4" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) { return false; } - if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) { return false; } - if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) { + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { return false; } - if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "SOYBN" ) ) { return false; } - if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName() - .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "SOYBN" ) ) { return false; } - if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "SOYBN" ) ) { return false; } - if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "SOYBN" ) ) { return false; } - if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "SOYBN" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc() - .equals( "apoptosis" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "SOYBN" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef() - .equals( "GO:0006915" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "SOYBN" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getSource() - .equals( "UniProtKB" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "SOYBN" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getEvidence() - .equals( "experimental" ) ) { + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getType() - .equals( "function" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "SOYBN" ) ) { return false; } - if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getConfidence() - .getValue() != 1 ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01", + TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getConfidence() - .getType().equals( "ml" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE ) + .equals( "9YX45" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc() - .equals( "apoptosis" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "MOUSE" ) ) { return false; } - if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() - .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "MOUSE" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() - .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "MOUSE" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() - .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) { + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() - .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) { + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() - .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() - .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getRef() - .equals( "GO:0005829" ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc() - .equals( "intracellular organelle" ) ) { + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) { + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription() - .equals( "UniProt link" ) ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "RAT" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ) + .equals( "PIG" ) ) { + return false; + } + if ( !ParserUtils + .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "MOUSE" ) ) { + return false; + } + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ) + .equals( "MOUSE" ) ) { + return false; + } + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { return false; } - //if ( !( t3.getNode( "root node" ).getNodeData().getDistribution().getDesc().equals( "irgendwo" ) ) ) { - // return false; - //} - // if ( !( t3.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1074/jbc.M005889200" ) ) ) { - // return false; - // } - // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getType().equals( "host" ) ) { - // return false; - // } - // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) { - // return false; - // } - // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) { - // return false; - // } - // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) { - // return false; - // } - // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) { - // return false; - // } - // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getType().equals( "ncbi" ) ) { - // return false; - // } - // if ( t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) { - // return false; - // } - // if ( !t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getName() - // .equals( "B" ) ) { - // return false; - // } - // if ( t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getFrom() != 21 ) { - // return false; - // } - // if ( t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) { - // return false; - // } - // if ( t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getLength() != 24 ) { - // return false; - // } - // if ( t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ) - // .getConfidence() != 2144 ) { - // return false; - // } - // if ( !t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId() - // .equals( "pfam" ) ) { - // return false; - // } - // if ( t3.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) { - // return false; - // } - // if ( t3.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) { - // return false; - // } - // if ( t3.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) { - // return false; - // } - // if ( !t3.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) { - // return false; - // } - // if ( ( ( BinaryCharacters ) t3.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() ) - // .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) { - // ; - // return false; - // } - // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) { - // return false; - // } - // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) { - // return false; - // } - // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) { - // return false; - // } - // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) { - // return false; - // } - // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) { - // return false; - // } - // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) { - // return false; - // } - // if ( !t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) { - // return false; - // } - // final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml", - // xml_parser ); - // if ( xml_parser.getErrorCount() > 0 ) { - // System.out.println( xml_parser.getErrorMessages().toString() ); - // return false; - // } - // if ( phylogenies_1.length != 2 ) { - // return false; - // } - // final Phylogeny a = phylogenies_1[ 0 ]; - // if ( !a.getName().equals( "tree 4" ) ) { - // return false; - // } - // if ( a.getNumberOfExternalNodes() != 3 ) { - // return false; - // } - // if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) { - // return false; - // } - // if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) { - // return false; - // } } catch ( final Exception e ) { e.printStackTrace( System.out ); @@ -1154,16 +1263,51 @@ public final class Test { return true; } - private static boolean testBasicPhyloXMLparsingRoundtrip() { + private static boolean testBasicNodeMethods() { try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final PhyloXmlParser xml_parser = new PhyloXmlParser(); - if ( USE_LOCAL_PHYLOXML_SCHEMA ) { - xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD ); + if ( PhylogenyNode.getNodeCount() != 0 ) { + return false; } - else { - xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD ); + final PhylogenyNode n1 = new PhylogenyNode(); + final PhylogenyNode n2 = PhylogenyNode + .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + final PhylogenyNode n3 = PhylogenyNode + .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + final PhylogenyNode n4 = PhylogenyNode + .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( n1.isHasAssignedEvent() ) { + return false; + } + if ( PhylogenyNode.getNodeCount() != 4 ) { + return false; + } + if ( n3.getIndicator() != 0 ) { + return false; } + if ( n3.getNumberOfExternalNodes() != 1 ) { + return false; + } + if ( !n3.isExternal() ) { + return false; + } + if ( !n3.isRoot() ) { + return false; + } + if ( !n4.getName().equals( "n4" ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testBasicPhyloXMLparsing() { + try { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final PhyloXmlParser xml_parser = new PhyloXmlParser(); final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml", xml_parser ); if ( xml_parser.getErrorCount() > 0 ) { @@ -1173,197 +1317,380 @@ public final class Test { if ( phylogenies_0.length != 4 ) { return false; } - final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) ); - final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser ); - if ( phylogenies_t1.length != 1 ) { + final Phylogeny t1 = phylogenies_0[ 0 ]; + final Phylogeny t2 = phylogenies_0[ 1 ]; + final Phylogeny t3 = phylogenies_0[ 2 ]; + final Phylogeny t4 = phylogenies_0[ 3 ]; + if ( t1.getNumberOfExternalNodes() != 1 ) { return false; } - final Phylogeny t1_rt = phylogenies_t1[ 0 ]; - if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) { + if ( !t1.isRooted() ) { return false; } - if ( !t1_rt.isRooted() ) { + if ( t1.isRerootable() ) { return false; } - if ( t1_rt.isRerootable() ) { + if ( !t1.getType().equals( "gene_tree" ) ) { return false; } - if ( !t1_rt.getType().equals( "gene_tree" ) ) { + if ( t2.getNumberOfExternalNodes() != 2 ) { return false; } - final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) ); - final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser ); - final Phylogeny t2_rt = phylogenies_t2[ 0 ]; - if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) { + if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) { return false; } - if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) { + if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) { return false; } - if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) { + if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) { return false; } - if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) { + if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) { return false; } - if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence() + if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) { + return false; + } + if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) { + return false; + } + if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence() .startsWith( "actgtgggggt" ) ) { return false; } - if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence() + if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence() .startsWith( "ctgtgatgcat" ) ) { return false; } - final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) ); - final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser ); - final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) ); - final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser ); - if ( phylogenies_1.length != 1 ) { + if ( t3.getNumberOfExternalNodes() != 4 ) { return false; } - final Phylogeny t3_rt = phylogenies_1[ 0 ]; - if ( !t3_rt.getName().equals( "t3" ) ) { + if ( !t1.getName().equals( "t1" ) ) { return false; } - if ( t3_rt.getNumberOfExternalNodes() != 4 ) { + if ( !t2.getName().equals( "t2" ) ) { return false; } - if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) { + if ( !t3.getName().equals( "t3" ) ) { return false; } - if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) { + if ( !t4.getName().equals( "t4" ) ) { return false; } - if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) { + if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) { return false; } - if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName() + if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) { + return false; + } + if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) { + return false; + } + if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName() .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) { return false; } - if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) { + if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) { return false; } - if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) { + if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) { return false; } - if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource() - .equals( "UniProtKB" ) ) { + if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc() .equals( "apoptosis" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef() .equals( "GO:0006915" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getSource() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource() .equals( "UniProtKB" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getEvidence() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence() .equals( "experimental" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getType() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType() .equals( "function" ) ) { return false; } - if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getConfidence() + if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence() .getValue() != 1 ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getConfidence() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence() .getType().equals( "ml" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc() .equals( "apoptosis" ) ) { return false; } - if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() + if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getRef() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef() .equals( "GO:0005829" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc() .equals( "intracellular organelle" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) { + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription() .equals( "UniProt link" ) ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) { + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) { - return false; + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testBasicPhyloXMLparsingRoundtrip() { + try { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final PhyloXmlParser xml_parser = new PhyloXmlParser(); + if ( USE_LOCAL_PHYLOXML_SCHEMA ) { + xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD ); } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() - .equals( "Aguinaldo, A. M. A.; J. M. Turbeville, L. S. Linford, M. C. Rivera, J. R. Garey, R. A. Raff, & J. A. Lake (1997). \"Evidence for a clade of nematodes, arthropods and other moulting animals\". Nature 387 (6632): 489–493." ) ) ) { + else { + xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD ); + } + final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml", + xml_parser ); + if ( xml_parser.getErrorCount() > 0 ) { + System.out.println( xml_parser.getErrorMessages().toString() ); return false; } - if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) { + if ( phylogenies_0.length != 4 ) { return false; } - if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) { + final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) ); + final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser ); + if ( phylogenies_t1.length != 1 ) { return false; } - if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) { + final Phylogeny t1_rt = phylogenies_t1[ 0 ]; + if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) { return false; } - if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) { + if ( !t1_rt.isRooted() ) { return false; } - if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider() - .equals( "ncbi" ) ) { + if ( t1_rt.isRerootable() ) { return false; } - if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) { + if ( !t1_rt.getType().equals( "gene_tree" ) ) { return false; } - if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ) - .getName().equals( "B" ) ) { + final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) ); + final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser ); + final Phylogeny t2_rt = phylogenies_t2[ 0 ]; + if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) { return false; } - if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ) - .getFrom() != 21 ) { + if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) { return false; } - if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) { + if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) { return false; } - if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ) - .getLength() != 24 ) { + if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) { + return false; + } + if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence() + .startsWith( "actgtgggggt" ) ) { + return false; + } + if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence() + .startsWith( "ctgtgatgcat" ) ) { + return false; + } + final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) ); + final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser ); + final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) ); + final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser ); + if ( phylogenies_1.length != 1 ) { + return false; + } + final Phylogeny t3_rt = phylogenies_1[ 0 ]; + if ( !t3_rt.getName().equals( "t3" ) ) { + return false; + } + if ( t3_rt.getNumberOfExternalNodes() != 4 ) { + return false; + } + if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) { + return false; + } + if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) { + return false; + } + if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) { + return false; + } + if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName() + .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) { + return false; + } + if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) { + return false; + } + if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) { + return false; + } + if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource() + .equals( "UniProtKB" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc() + .equals( "apoptosis" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef() + .equals( "GO:0006915" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource() + .equals( "UniProtKB" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence() + .equals( "experimental" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType() + .equals( "function" ) ) { + return false; + } + if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence() + .getValue() != 1 ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence() + .getType().equals( "ml" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc() + .equals( "apoptosis" ) ) { + return false; + } + if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() + .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() + .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() + .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() + .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() + .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties() + .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef() + .equals( "GO:0005829" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc() + .equals( "intracellular organelle" ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription() + .equals( "UniProt link" ) ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) { + return false; + } + if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription() + .equals( "Aguinaldo, A. M. A.; J. M. Turbeville, L. S. Linford, M. C. Rivera, J. R. Garey, R. A. Raff, & J. A. Lake (1997). \"Evidence for a clade of nematodes, arthropods and other moulting animals\". Nature 387 (6632): 489–493." ) ) ) { + return false; + } + if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) { + return false; + } + if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) { + return false; + } + if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) { + return false; + } + if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) { + return false; + } + if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider() + .equals( "ncbi" ) ) { + return false; + } + if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) { + return false; + } + if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ) + .getName().equals( "B" ) ) { + return false; + } + if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ) + .getFrom() != 21 ) { + return false; + } + if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) { + return false; + } + if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ) + .getLength() != 24 ) { return false; } if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ) @@ -1665,7 +1992,7 @@ public final class Test { source.append( "40 41 42 43" + l ); source.append( " # 1 1 1 1 1 " + l ); source.append( "50 51 52 53 54" + l ); - final BasicTable t1 = BasicTableParser.parse( source.toString(), " " ); + final BasicTable t1 = BasicTableParser.parse( source.toString(), ' ' ); if ( t1.getNumberOfColumns() != 5 ) { return false; } @@ -1694,7 +2021,7 @@ public final class Test { source1.append( "40;41;42;43" + l ); source1.append( " # 1 1 1 1 1 " + l ); source1.append( ";;;50 ; ;52; 53;;54 " + l ); - final BasicTable t2 = BasicTableParser.parse( source1.toString(), ";" ); + final BasicTable t2 = BasicTableParser.parse( source1.toString(), ';' ); if ( t2.getNumberOfColumns() != 5 ) { return false; } @@ -1731,7 +2058,8 @@ public final class Test { source2.append( " comment: 1 1 1 1 1 " + l ); source2.append( ";;;50 ; 52; 53;;54 " + l ); final List> tl = BasicTableParser.parse( source2.toString(), - ";", + ';', + false, false, "comment:", false ); @@ -1969,7 +2297,7 @@ public final class Test { if ( t8.getHeight() != 15 ) { return false; } - final char[] a9 = new char[] {}; + final char[] a9 = new char[] { 'a' }; final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ]; if ( t9.getHeight() != 0 ) { return false; @@ -1987,6 +2315,34 @@ public final class Test { return true; } + private static boolean testTreeMethods() { + try { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ]; + PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) ); + if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) { + System.out.println( t0.toNewHampshireX() ); + return false; + } + final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ]; + PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) ); + if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) { + return false; + } + if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) { + return false; + } + if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + private static boolean testConfidenceAssessor() { try { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); @@ -2017,7 +2373,6 @@ public final class Test { .create( "((A,C),X);((A,X),C);(A,C);((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd", new NHXParser() ); ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 ); - // Archaeopteryx.createApplication( t_b ); //TODO use me again me working here... if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) { return false; } @@ -2969,6 +3324,29 @@ public final class Test { for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) { final PhylogenyNode node = iter.next(); } + final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ]; + final PhylogenyNodeIterator iter = t6.iteratorExternalForward(); + if ( !iter.next().getName().equals( "A" ) ) { + return false; + } + if ( !iter.next().getName().equals( "B" ) ) { + return false; + } + if ( !iter.next().getName().equals( "C" ) ) { + return false; + } + if ( !iter.next().getName().equals( "D" ) ) { + return false; + } + if ( !iter.next().getName().equals( "E" ) ) { + return false; + } + if ( !iter.next().getName().equals( "F" ) ) { + return false; + } + if ( iter.hasNext() ) { + return false; + } } catch ( final Exception e ) { e.printStackTrace( System.out ); @@ -3068,133 +3446,132 @@ public final class Test { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final Phylogeny p1 = factory.create( "(((A:1,B:2,X:100)ab:3,C:4)abc:5,(D:7,(E:9,F:10)ef:8)def:6)r", new NHXParser() )[ 0 ]; - final PhylogenyMethods pm = PhylogenyMethods.getInstance(); - if ( pm.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) { return false; } - if ( pm.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) { + if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) { return false; } final Phylogeny p2 = factory.create( "((A:4,B:5,C:6)abc:1,(D:7,E:8,F:9)def:2,(G:10,H:11,I:12)ghi:3)r", new NHXParser() )[ 0 ]; - if ( pm.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) { return false; } - if ( pm.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) { return false; } - if ( pm.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) { return false; } - if ( pm.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) { return false; } - if ( pm.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) { return false; } - if ( pm.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) { return false; } - if ( pm.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) { return false; } - if ( pm.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) { return false; } - if ( pm.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) { return false; } - if ( pm.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) { return false; } - if ( pm.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) { + if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) { return false; } } @@ -3210,200 +3587,199 @@ public final class Test { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh", new NHXParser() )[ 0 ]; - final PhylogenyMethods pm = PhylogenyMethods.getInstance(); - final PhylogenyNode A = pm.obtainLCA( p1.getNode( "A" ), p1.getNode( "A" ) ); + final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) ); if ( !A.getName().equals( "A" ) ) { return false; } - final PhylogenyNode gh = pm.obtainLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) ); + final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) ); if ( !gh.getName().equals( "gh" ) ) { return false; } - final PhylogenyNode ab = pm.obtainLCA( p1.getNode( "A" ), p1.getNode( "B" ) ); + final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) ); if ( !ab.getName().equals( "ab" ) ) { return false; } - final PhylogenyNode ab2 = pm.obtainLCA( p1.getNode( "B" ), p1.getNode( "A" ) ); + final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) ); if ( !ab2.getName().equals( "ab" ) ) { return false; } - final PhylogenyNode gh2 = pm.obtainLCA( p1.getNode( "H" ), p1.getNode( "G" ) ); + final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) ); if ( !gh2.getName().equals( "gh" ) ) { return false; } - final PhylogenyNode gh3 = pm.obtainLCA( p1.getNode( "G" ), p1.getNode( "H" ) ); + final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) ); if ( !gh3.getName().equals( "gh" ) ) { return false; } - final PhylogenyNode abc = pm.obtainLCA( p1.getNode( "C" ), p1.getNode( "A" ) ); + final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) ); if ( !abc.getName().equals( "abc" ) ) { return false; } - final PhylogenyNode abc2 = pm.obtainLCA( p1.getNode( "A" ), p1.getNode( "C" ) ); + final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) ); if ( !abc2.getName().equals( "abc" ) ) { return false; } - final PhylogenyNode abcd = pm.obtainLCA( p1.getNode( "A" ), p1.getNode( "D" ) ); + final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) ); if ( !abcd.getName().equals( "abcd" ) ) { return false; } - final PhylogenyNode abcd2 = pm.obtainLCA( p1.getNode( "D" ), p1.getNode( "A" ) ); + final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) ); if ( !abcd2.getName().equals( "abcd" ) ) { return false; } - final PhylogenyNode abcdef = pm.obtainLCA( p1.getNode( "A" ), p1.getNode( "F" ) ); + final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) ); if ( !abcdef.getName().equals( "abcdef" ) ) { return false; } - final PhylogenyNode abcdef2 = pm.obtainLCA( p1.getNode( "F" ), p1.getNode( "A" ) ); + final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) ); if ( !abcdef2.getName().equals( "abcdef" ) ) { return false; } - final PhylogenyNode abcdef3 = pm.obtainLCA( p1.getNode( "ab" ), p1.getNode( "F" ) ); + final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) ); if ( !abcdef3.getName().equals( "abcdef" ) ) { return false; } - final PhylogenyNode abcdef4 = pm.obtainLCA( p1.getNode( "F" ), p1.getNode( "ab" ) ); + final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) ); if ( !abcdef4.getName().equals( "abcdef" ) ) { return false; } - final PhylogenyNode abcde = pm.obtainLCA( p1.getNode( "A" ), p1.getNode( "E" ) ); + final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) ); if ( !abcde.getName().equals( "abcde" ) ) { return false; } - final PhylogenyNode abcde2 = pm.obtainLCA( p1.getNode( "E" ), p1.getNode( "A" ) ); + final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) ); if ( !abcde2.getName().equals( "abcde" ) ) { return false; } - final PhylogenyNode r = pm.obtainLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) ); + final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) ); if ( !r.getName().equals( "abcdefgh" ) ) { return false; } - final PhylogenyNode r2 = pm.obtainLCA( p1.getNode( "A" ), p1.getNode( "H" ) ); + final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) ); if ( !r2.getName().equals( "abcdefgh" ) ) { return false; } - final PhylogenyNode r3 = pm.obtainLCA( p1.getNode( "H" ), p1.getNode( "A" ) ); + final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) ); if ( !r3.getName().equals( "abcdefgh" ) ) { return false; } - final PhylogenyNode abcde3 = pm.obtainLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) ); + final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) ); if ( !abcde3.getName().equals( "abcde" ) ) { return false; } - final PhylogenyNode abcde4 = pm.obtainLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) ); + final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) ); if ( !abcde4.getName().equals( "abcde" ) ) { return false; } - final PhylogenyNode ab3 = pm.obtainLCA( p1.getNode( "ab" ), p1.getNode( "B" ) ); + final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) ); if ( !ab3.getName().equals( "ab" ) ) { return false; } - final PhylogenyNode ab4 = pm.obtainLCA( p1.getNode( "B" ), p1.getNode( "ab" ) ); + final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) ); if ( !ab4.getName().equals( "ab" ) ) { return false; } final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ]; - final PhylogenyNode cd = pm.obtainLCA( p2.getNode( "c" ), p2.getNode( "d" ) ); + final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) ); if ( !cd.getName().equals( "cd" ) ) { return false; } - final PhylogenyNode cd2 = pm.obtainLCA( p2.getNode( "d" ), p2.getNode( "c" ) ); + final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) ); if ( !cd2.getName().equals( "cd" ) ) { return false; } - final PhylogenyNode cde = pm.obtainLCA( p2.getNode( "c" ), p2.getNode( "e" ) ); + final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) ); if ( !cde.getName().equals( "cde" ) ) { return false; } - final PhylogenyNode cde2 = pm.obtainLCA( p2.getNode( "e" ), p2.getNode( "c" ) ); + final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) ); if ( !cde2.getName().equals( "cde" ) ) { return false; } - final PhylogenyNode cdef = pm.obtainLCA( p2.getNode( "c" ), p2.getNode( "f" ) ); + final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) ); if ( !cdef.getName().equals( "cdef" ) ) { return false; } - final PhylogenyNode cdef2 = pm.obtainLCA( p2.getNode( "d" ), p2.getNode( "f" ) ); + final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) ); if ( !cdef2.getName().equals( "cdef" ) ) { return false; } - final PhylogenyNode cdef3 = pm.obtainLCA( p2.getNode( "f" ), p2.getNode( "d" ) ); + final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) ); if ( !cdef3.getName().equals( "cdef" ) ) { return false; } - final PhylogenyNode rt = pm.obtainLCA( p2.getNode( "c" ), p2.getNode( "a" ) ); + final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) ); if ( !rt.getName().equals( "r" ) ) { return false; } final Phylogeny p3 = factory .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)", new NHXParser() )[ 0 ]; - final PhylogenyNode bc_3 = pm.obtainLCA( p3.getNode( "b" ), p3.getNode( "c" ) ); + final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) ); if ( !bc_3.getName().equals( "bc" ) ) { return false; } - final PhylogenyNode ac_3 = pm.obtainLCA( p3.getNode( "a" ), p3.getNode( "c" ) ); + final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) ); if ( !ac_3.getName().equals( "abc" ) ) { return false; } - final PhylogenyNode ad_3 = pm.obtainLCA( p3.getNode( "a" ), p3.getNode( "d" ) ); + final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) ); if ( !ad_3.getName().equals( "abcde" ) ) { return false; } - final PhylogenyNode af_3 = pm.obtainLCA( p3.getNode( "a" ), p3.getNode( "f" ) ); + final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) ); if ( !af_3.getName().equals( "abcdef" ) ) { return false; } - final PhylogenyNode ag_3 = pm.obtainLCA( p3.getNode( "a" ), p3.getNode( "g" ) ); + final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) ); if ( !ag_3.getName().equals( "" ) ) { return false; } if ( !ag_3.isRoot() ) { return false; } - final PhylogenyNode al_3 = pm.obtainLCA( p3.getNode( "a" ), p3.getNode( "l" ) ); + final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) ); if ( !al_3.getName().equals( "" ) ) { return false; } if ( !al_3.isRoot() ) { return false; } - final PhylogenyNode kl_3 = pm.obtainLCA( p3.getNode( "k" ), p3.getNode( "l" ) ); + final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) ); if ( !kl_3.getName().equals( "" ) ) { return false; } if ( !kl_3.isRoot() ) { return false; } - final PhylogenyNode fl_3 = pm.obtainLCA( p3.getNode( "f" ), p3.getNode( "l" ) ); + final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) ); if ( !fl_3.getName().equals( "" ) ) { return false; } if ( !fl_3.isRoot() ) { return false; } - final PhylogenyNode gk_3 = pm.obtainLCA( p3.getNode( "g" ), p3.getNode( "k" ) ); + final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) ); if ( !gk_3.getName().equals( "ghijk" ) ) { return false; } final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ]; - final PhylogenyNode r_4 = pm.obtainLCA( p4.getNode( "b" ), p4.getNode( "c" ) ); + final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) ); if ( !r_4.getName().equals( "r" ) ) { return false; } final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ]; - final PhylogenyNode r_5 = pm.obtainLCA( p5.getNode( "a" ), p5.getNode( "c" ) ); + final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) ); if ( !r_5.getName().equals( "root" ) ) { return false; } final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ]; - final PhylogenyNode r_6 = pm.obtainLCA( p6.getNode( "c" ), p6.getNode( "a" ) ); + final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) ); if ( !r_6.getName().equals( "rot" ) ) { return false; } final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ]; - final PhylogenyNode r_7 = pm.obtainLCA( p7.getNode( "a" ), p7.getNode( "e" ) ); + final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) ); if ( !r_7.getName().equals( "rott" ) ) { return false; } @@ -3415,110 +3791,438 @@ public final class Test { return true; } - private static boolean testHmmscanOutputParser() { - final String test_dir = Test.PATH_TO_TEST_DATA; + private static boolean testGetLCA2() { try { - final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir - + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE ); - parser1.parse(); - final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir - + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE ); - final List proteins = parser2.parse(); - if ( parser2.getProteinsEncountered() != 4 ) { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p_a ); + final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ), + p_a.getNode( "a" ) ); + if ( !p_a_1.getName().equals( "a" ) ) { return false; } - if ( proteins.size() != 4 ) { + final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p_b ); + final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ), + p_b.getNode( "a" ) ); + if ( !p_b_1.getName().equals( "b" ) ) { return false; } - if ( parser2.getDomainsEncountered() != 69 ) { + final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ), + p_b.getNode( "b" ) ); + if ( !p_b_2.getName().equals( "b" ) ) { return false; } - if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) { + final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p_c ); + final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ), + p_c.getNode( "a" ) ); + if ( !p_c_1.getName().equals( "b" ) ) { return false; } - if ( parser2.getDomainsIgnoredDueToEval() != 0 ) { + final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ), + p_c.getNode( "c" ) ); + if ( !p_c_2.getName().equals( "c" ) ) { + System.out.println( p_c_2.getName() ); + System.exit( -1 ); return false; } - final Protein p1 = proteins.get( 0 ); - if ( p1.getNumberOfProteinDomains() != 15 ) { + final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ), + p_c.getNode( "b" ) ); + if ( !p_c_3.getName().equals( "b" ) ) { return false; } - if ( p1.getLength() != 850 ) { + final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ), + p_c.getNode( "a" ) ); + if ( !p_c_4.getName().equals( "c" ) ) { return false; } - final Protein p2 = proteins.get( 1 ); - if ( p2.getNumberOfProteinDomains() != 51 ) { + final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh", + new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p1 ); + final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "A" ) ); + if ( !A.getName().equals( "A" ) ) { return false; } - if ( p2.getLength() != 1291 ) { + final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ), + p1.getNode( "gh" ) ); + if ( !gh.getName().equals( "gh" ) ) { return false; } - final Protein p3 = proteins.get( 2 ); - if ( p3.getNumberOfProteinDomains() != 2 ) { + final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "B" ) ); + if ( !ab.getName().equals( "ab" ) ) { return false; } - final Protein p4 = proteins.get( 3 ); - if ( p4.getNumberOfProteinDomains() != 1 ) { + final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ), + p1.getNode( "A" ) ); + if ( !ab2.getName().equals( "ab" ) ) { return false; } - if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) { + final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ), + p1.getNode( "G" ) ); + if ( !gh2.getName().equals( "gh" ) ) { return false; } - if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) { + final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ), + p1.getNode( "H" ) ); + if ( !gh3.getName().equals( "gh" ) ) { return false; } - if ( p4.getProteinDomain( 0 ).getTo() != 395 ) { + final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ), + p1.getNode( "A" ) ); + if ( !abc.getName().equals( "abc" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) { + final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "C" ) ); + if ( !abc2.getName().equals( "abc" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) { + final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "D" ) ); + if ( !abcd.getName().equals( "abcd" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) { + final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ), + p1.getNode( "A" ) ); + if ( !abcd2.getName().equals( "abcd" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) { + final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "F" ) ); + if ( !abcdef.getName().equals( "abcdef" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) { + final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ), + p1.getNode( "A" ) ); + if ( !abcdef2.getName().equals( "abcdef" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) { + final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ), + p1.getNode( "F" ) ); + if ( !abcdef3.getName().equals( "abcdef" ) ) { return false; } - } - catch ( final Exception e ) { - e.printStackTrace( System.out ); - return false; - } - return true; - } - - private static boolean testLastExternalNodeMethods() { - try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', }; - final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ]; - final PhylogenyNode n1 = t0.getNode( "A" ); - if ( n1.isLastExternalNode() ) { + final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ), + p1.getNode( "ab" ) ); + if ( !abcdef4.getName().equals( "abcdef" ) ) { return false; } - final PhylogenyNode n2 = t0.getNode( "B" ); - if ( n2.isLastExternalNode() ) { + final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "E" ) ); + if ( !abcde.getName().equals( "abcde" ) ) { return false; } - final PhylogenyNode n3 = t0.getNode( "C" ); - if ( n3.isLastExternalNode() ) { + final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ), + p1.getNode( "A" ) ); + if ( !abcde2.getName().equals( "abcde" ) ) { return false; } - final PhylogenyNode n4 = t0.getNode( "D" ); - if ( !n4.isLastExternalNode() ) { + final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ), + p1.getNode( "abcdefgh" ) ); + if ( !r.getName().equals( "abcdefgh" ) ) { return false; } - } - catch ( final Exception e ) { + final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "H" ) ); + if ( !r2.getName().equals( "abcdefgh" ) ) { + return false; + } + final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ), + p1.getNode( "A" ) ); + if ( !r3.getName().equals( "abcdefgh" ) ) { + return false; + } + final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ), + p1.getNode( "abcde" ) ); + if ( !abcde3.getName().equals( "abcde" ) ) { + return false; + } + final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ), + p1.getNode( "E" ) ); + if ( !abcde4.getName().equals( "abcde" ) ) { + return false; + } + final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ), + p1.getNode( "B" ) ); + if ( !ab3.getName().equals( "ab" ) ) { + return false; + } + final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ), + p1.getNode( "ab" ) ); + if ( !ab4.getName().equals( "ab" ) ) { + return false; + } + final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p2 ); + final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ), + p2.getNode( "d" ) ); + if ( !cd.getName().equals( "cd" ) ) { + return false; + } + final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ), + p2.getNode( "c" ) ); + if ( !cd2.getName().equals( "cd" ) ) { + return false; + } + final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ), + p2.getNode( "e" ) ); + if ( !cde.getName().equals( "cde" ) ) { + return false; + } + final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ), + p2.getNode( "c" ) ); + if ( !cde2.getName().equals( "cde" ) ) { + return false; + } + final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ), + p2.getNode( "f" ) ); + if ( !cdef.getName().equals( "cdef" ) ) { + return false; + } + final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ), + p2.getNode( "f" ) ); + if ( !cdef2.getName().equals( "cdef" ) ) { + return false; + } + final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ), + p2.getNode( "d" ) ); + if ( !cdef3.getName().equals( "cdef" ) ) { + return false; + } + final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ), + p2.getNode( "a" ) ); + if ( !rt.getName().equals( "r" ) ) { + return false; + } + final Phylogeny p3 = factory + .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)", + new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p3 ); + final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ), + p3.getNode( "c" ) ); + if ( !bc_3.getName().equals( "bc" ) ) { + return false; + } + final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ), + p3.getNode( "c" ) ); + if ( !ac_3.getName().equals( "abc" ) ) { + return false; + } + final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ), + p3.getNode( "d" ) ); + if ( !ad_3.getName().equals( "abcde" ) ) { + return false; + } + final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ), + p3.getNode( "f" ) ); + if ( !af_3.getName().equals( "abcdef" ) ) { + return false; + } + final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ), + p3.getNode( "g" ) ); + if ( !ag_3.getName().equals( "" ) ) { + return false; + } + if ( !ag_3.isRoot() ) { + return false; + } + final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ), + p3.getNode( "l" ) ); + if ( !al_3.getName().equals( "" ) ) { + return false; + } + if ( !al_3.isRoot() ) { + return false; + } + final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ), + p3.getNode( "l" ) ); + if ( !kl_3.getName().equals( "" ) ) { + return false; + } + if ( !kl_3.isRoot() ) { + return false; + } + final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ), + p3.getNode( "l" ) ); + if ( !fl_3.getName().equals( "" ) ) { + return false; + } + if ( !fl_3.isRoot() ) { + return false; + } + final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ), + p3.getNode( "k" ) ); + if ( !gk_3.getName().equals( "ghijk" ) ) { + return false; + } + final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p4 ); + final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ), + p4.getNode( "c" ) ); + if ( !r_4.getName().equals( "r" ) ) { + return false; + } + final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p5 ); + final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ), + p5.getNode( "c" ) ); + if ( !r_5.getName().equals( "root" ) ) { + return false; + } + final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p6 ); + final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ), + p6.getNode( "a" ) ); + if ( !r_6.getName().equals( "rot" ) ) { + return false; + } + final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p7 ); + final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ), + p7.getNode( "e" ) ); + if ( !r_7.getName().equals( "rott" ) ) { + return false; + } + final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ), + p7.getNode( "a" ) ); + if ( !r_71.getName().equals( "rott" ) ) { + return false; + } + final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ), + p7.getNode( "rott" ) ); + if ( !r_72.getName().equals( "rott" ) ) { + return false; + } + final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ), + p7.getNode( "a" ) ); + if ( !r_73.getName().equals( "rott" ) ) { + return false; + } + final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ), + p7.getNode( "rott" ) ); + if ( !r_74.getName().equals( "rott" ) ) { + return false; + } + final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ), + p7.getNode( "e" ) ); + if ( !r_75.getName().equals( "e" ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testHmmscanOutputParser() { + final String test_dir = Test.PATH_TO_TEST_DATA; + try { + final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir + + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE ); + parser1.parse(); + final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir + + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE ); + final List proteins = parser2.parse(); + if ( parser2.getProteinsEncountered() != 4 ) { + return false; + } + if ( proteins.size() != 4 ) { + return false; + } + if ( parser2.getDomainsEncountered() != 69 ) { + return false; + } + if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) { + return false; + } + if ( parser2.getDomainsIgnoredDueToEval() != 0 ) { + return false; + } + final Protein p1 = proteins.get( 0 ); + if ( p1.getNumberOfProteinDomains() != 15 ) { + return false; + } + if ( p1.getLength() != 850 ) { + return false; + } + final Protein p2 = proteins.get( 1 ); + if ( p2.getNumberOfProteinDomains() != 51 ) { + return false; + } + if ( p2.getLength() != 1291 ) { + return false; + } + final Protein p3 = proteins.get( 2 ); + if ( p3.getNumberOfProteinDomains() != 2 ) { + return false; + } + final Protein p4 = proteins.get( 3 ); + if ( p4.getNumberOfProteinDomains() != 1 ) { + return false; + } + if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) { + return false; + } + if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) { + return false; + } + if ( p4.getProteinDomain( 0 ).getTo() != 395 ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testLastExternalNodeMethods() { + try { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', }; + final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ]; + final PhylogenyNode n1 = t0.getNode( "A" ); + if ( n1.isLastExternalNode() ) { + return false; + } + final PhylogenyNode n2 = t0.getNode( "B" ); + if ( n2.isLastExternalNode() ) { + return false; + } + final PhylogenyNode n3 = t0.getNode( "C" ); + if ( n3.isLastExternalNode() ) { + return false; + } + final PhylogenyNode n4 = t0.getNode( "D" ); + if ( !n4.isLastExternalNode() ) { + return false; + } + } + catch ( final Exception e ) { e.printStackTrace( System.out ); return false; } @@ -3696,9 +4400,47 @@ public final class Test { return true; } + private static boolean testNodeRemoval() { + try { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ]; + PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 ); + if ( !t0.toNewHampshire().equals( "(a);" ) ) { + return false; + } + final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ]; + PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 ); + if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) { + return false; + } + final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ]; + PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 ); + if ( !t2.toNewHampshire().equals( "((a),c);" ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + private static boolean testMidpointrooting() { try { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ]; + PhylogenyMethods.midpointRoot( t0 ); + if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) { + return false; + } + if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) { + return false; + } + if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(), + 1 ) ) { + return false; + } final Phylogeny t1 = factory.create( "((A:1,B:2)AB:1[&&NHX:B=55],(C:3,D:4)CD:3[&&NHX:B=10])ABCD:0.5", new NHXParser() )[ 0 ]; if ( !t1.isRooted() ) { @@ -3738,6 +4480,7 @@ public final class Test { return false; } if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) { + System.exit( -1 ); return false; } if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) { @@ -4036,40 +4779,1107 @@ public final class Test { if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) { return false; } - if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) { + if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) { + return false; + } + if ( !phylogenies[ 14 ].isRooted() ) { + return false; + } + if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) { + return false; + } + if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) { + return false; + } + if ( phylogenies[ 15 ].isRooted() ) { + return false; + } + if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) { + return false; + } + if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) { + return false; + } + if ( !phylogenies[ 16 ].isRooted() ) { + return false; + } + if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) { + return false; + } + if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) { + return false; + } + if ( phylogenies[ 17 ].isRooted() ) { + return false; + } + if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testNexusTreeParsingIterating() { + try { + final NexusPhylogeniesParser p = new NexusPhylogeniesParser(); + p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" ); + if ( !p.hasNext() ) { + return false; + } + Phylogeny phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 25 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy != null ) { + return false; + } + // + p.reset(); + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 25 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy != null ) { + return false; + } + //// + p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" ); + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 10 ) { + return false; + } + if ( !phy.getName().equals( "name" ) ) { + return false; + } + if ( p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy != null ) { + return false; + } + // + p.reset(); + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 10 ) { + return false; + } + if ( !phy.getName().equals( "name" ) ) { + return false; + } + if ( p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy != null ) { + return false; + } + //// + p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" ); + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( phy.isRooted() ) { + return false; + } + if ( p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy != null ) { + return false; + } + // + p.reset(); + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy != null ) { + return false; + } + //// + p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" ); + // if ( phylogenies.length != 18 ) { + // return false; + // } + //0 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 10 ) { + return false; + } + if ( !phy.getName().equals( "tree 0" ) ) { + return false; + } + //1 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 10 ) { + return false; + } + if ( !phy.getName().equals( "tree 1" ) ) { + return false; + } + //2 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( phy.isRooted() ) { + return false; + } + //3 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 4 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //4 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 5 ) { + System.out.println( phy.getNumberOfExternalNodes() ); + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //5 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( phy.isRooted() ) { + return false; + } + //6 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 2 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //7 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //8 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) { + return false; + } + if ( !phy.getName().equals( "tree 8" ) ) { + return false; + } + //9 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) { + return false; + } + if ( !phy.getName().equals( "tree 9" ) ) { + return false; + } + //10 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) { + return false; + } + if ( !phy.getName().equals( "tree 10" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //11 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) { + return false; + } + if ( !phy.getName().equals( "tree 11" ) ) { + return false; + } + if ( phy.isRooted() ) { + return false; + } + //12 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) { + return false; + } + if ( !phy.getName().equals( "tree 12" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //13 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) { + return false; + } + if ( !phy.getName().equals( "tree 13" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //14 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 10 ) { + System.out.println( phy.getNumberOfExternalNodes() ); + return false; + } + if ( !phy + .toNewHampshire() + .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) { + System.out.println( phy.toNewHampshire() ); + return false; + } + if ( !phy.getName().equals( "tree 14" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //15 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 10 ) { + System.out.println( phy.getNumberOfExternalNodes() ); + return false; + } + if ( !phy + .toNewHampshire() + .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) { + System.out.println( phy.toNewHampshire() ); + return false; + } + if ( !phy.getName().equals( "tree 15" ) ) { + return false; + } + if ( phy.isRooted() ) { + return false; + } + //16 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 10 ) { + System.out.println( phy.getNumberOfExternalNodes() ); + return false; + } + if ( !phy + .toNewHampshire() + .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) { + System.out.println( phy.toNewHampshire() ); + return false; + } + if ( !phy.getName().equals( "tree 16" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //17 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy.getNumberOfExternalNodes() != 10 ) { + System.out.println( phy.getNumberOfExternalNodes() ); + return false; + } + if ( !phy + .toNewHampshire() + .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) { + System.out.println( phy.toNewHampshire() ); + return false; + } + if ( !phy.getName().equals( "tree 17" ) ) { + return false; + } + if ( phy.isRooted() ) { + return false; + } + // + if ( p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy != null ) { + return false; + } + p.reset(); + //0 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 10 ) { + return false; + } + if ( !phy.getName().equals( "tree 0" ) ) { + return false; + } + //1 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 10 ) { + return false; + } + if ( !phy.getName().equals( "tree 1" ) ) { + return false; + } + //2 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( phy.isRooted() ) { + return false; + } + //3 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 4 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //4 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 5 ) { + System.out.println( phy.getNumberOfExternalNodes() ); + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( !phy.isRooted() ) { + return false; + } + //5 + if ( !p.hasNext() ) { + return false; + } + phy = p.next(); + if ( phy == null ) { + return false; + } + if ( phy.getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phy.getName().equals( "" ) ) { + return false; + } + if ( phy.isRooted() ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testNexusTreeParsingTranslating() { + try { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final NexusPhylogeniesParser parser = new NexusPhylogeniesParser(); + Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser ); + if ( phylogenies.length != 1 ) { + return false; + } + if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) { + return false; + } + if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + return false; + } + if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + return false; + } + if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() + .equals( "Aranaeus" ) ) { + return false; + } + phylogenies = null; + phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser ); + if ( phylogenies.length != 3 ) { + return false; + } + if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) { + return false; + } + if ( phylogenies[ 0 ].isRooted() ) { + return false; + } + if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + return false; + } + 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; + } + phylogenies = null; + phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser ); + if ( phylogenies.length != 3 ) { + return false; + } + if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) { + return false; + } + if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) { + return false; + } + if ( phylogenies[ 0 ].isRooted() ) { + return false; + } + if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + return false; + } + 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 ) ) { + return false; + } + final String p43_S = "(A,B,C,(AA,BB,CC,(CCC,DDD,EEE,(FFFF,GGGG)x)y,DD,EE,FF,GG,HH),D,E,(EE,FF),F,G,H,(((((5)4)3)2)1),I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,(XX,(YY)),Y,Z)"; + final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() ); + if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) { + return false; + } + final String p44_S = "(((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)))"; + final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() ); + if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) { + return false; + } + final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))"; + final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() ); + if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) { + return false; + } + final String p46_S = ""; + final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() ); + if ( p46.length != 0 ) { + return false; + } + final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ]; + if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { return false; } - if ( !phylogenies[ 14 ].isRooted() ) { + final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { return false; } - if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) { + final Phylogeny p49 = factory + .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ), + new NHXParser() )[ 0 ]; + if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { return false; } - if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) { + final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( p50.getNode( "A" ) == null ) { return false; } - if ( phylogenies[ 15 ].isRooted() ) { + if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) + .equals( "((A,B)ab:2.0[88],C);" ) ) { return false; } - if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) { + if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) { return false; } - if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) { + if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ) + .equals( "((A,B)88:2.0,C);" ) ) { return false; } - if ( !phylogenies[ 16 ].isRooted() ) { + final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( p51.getNode( "A(A" ) == null ) { return false; } - if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) { + final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( p52.getNode( "A(A" ) == null ) { return false; } - if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) { + final Phylogeny p53 = factory + .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ), + new NHXParser() )[ 0 ]; + if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) { return false; } - if ( phylogenies[ 17 ].isRooted() ) { + // + final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ]; + if ( p54.getNode( "A" ) == null ) { return false; } - if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) { + if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) + .equals( "((A,B)[88],C);" ) ) { return false; } } @@ -4080,446 +5890,386 @@ public final class Test { return true; } - private static boolean testNexusTreeParsingTranslating() { + private static boolean testNHParsingIter() { try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final NexusPhylogeniesParser parser = new NexusPhylogeniesParser(); - Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser ); - if ( phylogenies.length != 1 ) { - return false; - } - if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) { - return false; - } - if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) { - return false; - } - if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { - return false; - } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { - return false; - } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { - return false; - } - phylogenies = null; - phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser ); - if ( phylogenies.length != 3 ) { - return false; - } - if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) { - return false; - } - if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) { + final String p0_str = "(A,B);"; + final NHXParser p = new NHXParser(); + p.setSource( p0_str ); + if ( !p.hasNext() ) { return false; } - if ( phylogenies[ 0 ].isRooted() ) { + final Phylogeny p0 = p.next(); + if ( !p0.toNewHampshire().equals( p0_str ) ) { + System.out.println( p0.toNewHampshire() ); return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + if ( p.hasNext() ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + if ( p.next() != null ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + // + final String p00_str = "(A,B)root;"; + p.setSource( p00_str ); + final Phylogeny p00 = p.next(); + if ( !p00.toNewHampshire().equals( p00_str ) ) { + System.out.println( p00.toNewHampshire() ); return false; } - if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) { + // + final String p000_str = "A;"; + p.setSource( p000_str ); + final Phylogeny p000 = p.next(); + if ( !p000.toNewHampshire().equals( p000_str ) ) { + System.out.println( p000.toNewHampshire() ); return false; } - if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) { + // + final String p0000_str = "A"; + p.setSource( p0000_str ); + final Phylogeny p0000 = p.next(); + if ( !p0000.toNewHampshire().equals( "A;" ) ) { + System.out.println( p0000.toNewHampshire() ); return false; } - if ( phylogenies[ 1 ].isRooted() ) { + // + p.setSource( "(A)" ); + final Phylogeny p00000 = p.next(); + if ( !p00000.toNewHampshire().equals( "(A);" ) ) { + System.out.println( p00000.toNewHampshire() ); return false; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + // + final String p1_str = "(A,B)(C,D)(E,F)(G,H)"; + p.setSource( p1_str ); + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + final Phylogeny p1_0 = p.next(); + if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) { + System.out.println( p1_0.toNewHampshire() ); return false; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + if ( !p.hasNext() ) { return false; } - if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) { + final Phylogeny p1_1 = p.next(); + if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) { + System.out.println( "(C,D) != " + p1_1.toNewHampshire() ); return false; } - if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) { + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 2 ].isRooted() ) { + final Phylogeny p1_2 = p.next(); + if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) { + System.out.println( "(E,F) != " + p1_2.toNewHampshire() ); return false; } - if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + final Phylogeny p1_3 = p.next(); + if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) { + System.out.println( "(G,H) != " + p1_3.toNewHampshire() ); return false; } - if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + if ( p.hasNext() ) { return false; } - phylogenies = null; - phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser ); - if ( phylogenies.length != 3 ) { + if ( p.next() != null ) { return false; } - if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) { + // + final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)"; + p.setSource( p2_str ); + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) { + Phylogeny p2_0 = p.next(); + if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) { + System.out.println( p2_0.toNewHampshire() ); return false; } - if ( phylogenies[ 0 ].isRooted() ) { + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + Phylogeny p2_1 = p.next(); + if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) { + System.out.println( "(C,D) != " + p2_1.toNewHampshire() ); return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + Phylogeny p2_2 = p.next(); + if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) { + System.out.println( "(E,F)root != " + p2_2.toNewHampshire() ); return false; } - if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) { + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) { + Phylogeny p2_3 = p.next(); + if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) { + System.out.println( "(G,H) != " + p2_3.toNewHampshire() ); return false; } - if ( phylogenies[ 1 ].isRooted() ) { + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + Phylogeny p2_4 = p.next(); + if ( !p2_4.toNewHampshire().equals( "(X);" ) ) { + System.out.println( "(X) != " + p2_4.toNewHampshire() ); return false; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + if ( p.hasNext() ) { return false; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + if ( p.next() != null ) { return false; } - if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) { + //// + p.reset(); + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) { + p2_0 = p.next(); + if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) { + System.out.println( p2_0.toNewHampshire() ); return false; } - if ( !phylogenies[ 2 ].isRooted() ) { + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + p2_1 = p.next(); + if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) { + System.out.println( "(C,D) != " + p2_1.toNewHampshire() ); return false; } - if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + if ( !p.hasNext() ) { return false; } - if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + p2_2 = p.next(); + if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) { + System.out.println( "(E,F)root != " + p2_2.toNewHampshire() ); 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)" ) ) { + if ( !p.hasNext() ) { return false; } - final NHXParser nhxp = new NHXParser(); - nhxp.setTaxonomyExtraction( PhylogenyMethods.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 " ) ) { + p2_3 = p.next(); + if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) { + System.out.println( "(G,H) != " + p2_3.toNewHampshire() ); return false; } - if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) { + if ( !p.hasNext() ) { 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;')" ) ) { + p2_4 = p.next(); + if ( !p2_4.toNewHampshire().equals( "(X);" ) ) { + System.out.println( "(X) != " + p2_4.toNewHampshire() ); return false; } - if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) { + if ( p.hasNext() ) { 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;')" ) ) { + if ( p.next() != null ) { return false; } - if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) { + // + final String p3_str = "((A,B),C)abc"; + p.setSource( p3_str ); + if ( !p.hasNext() ) { return false; } - if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) { + final Phylogeny p3_0 = p.next(); + if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) { return false; } - if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) { + if ( p.hasNext() ) { 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[ 0 ].toNewHampshireX().equals( p16_S ) ) { + if ( p.next() != null ) { return false; } - final String p17_S = "(C,(A,B))"; - final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() ); - if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) { + // + final String p4_str = "((A,B)ab,C)abc"; + p.setSource( p4_str ); + if ( !p.hasNext() ) { return false; } - final String p18_S = "((A,B),(C,D))"; - final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() ); - if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) { + final Phylogeny p4_0 = p.next(); + if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) { return false; } - final String p19_S = "(((A,B),C),D)"; - final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() ); - if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) { + if ( p.hasNext() ) { return false; } - final String p20_S = "(A,(B,(C,D)))"; - final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() ); - if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) { + if ( p.next() != null ) { return false; } - final String p21_S = "(A,(B,(C,(D,E))))"; - final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() ); - if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) { + // + final String p5_str = "(((A,B)ab,C)abc,D)abcd"; + p.setSource( p5_str ); + if ( !p.hasNext() ) { return false; } - final String p22_S = "((((A,B),C),D),E)"; - final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() ); - if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) { + final Phylogeny p5_0 = p.next(); + if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) { 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[ 0 ].toNewHampshireX().equals( p23_S ) ) { + if ( p.hasNext() ) { 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[ 0 ].toNewHampshireX().equals( p24_S ) ) { + if ( p.next() != null ) { 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[ 0 ].toNewHampshireX().equals( p241_S1 ) ) { + // + final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde"; + p.setSource( p6_str ); + if ( !p.hasNext() ) { return false; } - if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) { + Phylogeny p6_0 = p.next(); + if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) { 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 ) ) { + if ( p.hasNext() ) { 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 ) ) { + if ( p.next() != null ) { return false; } - final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde"; - final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ), - new NHXParser() ); - if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) { + p.reset(); + if ( !p.hasNext() ) { 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 ) ) { + p6_0 = p.next(); + if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) { return false; } - if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) { + if ( p.hasNext() ) { return false; } - if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) { + if ( p.next() != null ) { return false; } - if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) { + // + final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde"; + p.setSource( p7_str ); + if ( !p.hasNext() ) { 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 ) ) { + Phylogeny p7_0 = p.next(); + if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) { 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 ) ) { + if ( p.hasNext() ) { return false; } - final String p32_S = " ; ; \n \t \b \f \r ;;;;;; "; - final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() ); - if ( ( p32.length != 1 ) || !p32[ 0 ].isEmpty() ) { + if ( p.next() != null ) { return false; } - final String p33_S = "A"; - final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() ); - if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) { + p.reset(); + if ( !p.hasNext() ) { return false; } - final String p34_S = "B;"; - final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() ); - if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) { + p7_0 = p.next(); + if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) { 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 ) ) { + if ( p.hasNext() ) { return false; } - final String p36_S = "(A)"; - final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() ); - if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) { + if ( p.next() != null ) { return false; } - final String p37_S = "((A))"; - final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() ); - if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) { + // + final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde"; + p.setSource( p8_str ); + if ( !p.hasNext() ) { 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 ) ) { + Phylogeny p8_0 = p.next(); + if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) { 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 ) ) { + if ( !p.hasNext() ) { 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 ) ) { + if ( !p.hasNext() ) { 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 ) ) { + Phylogeny p8_1 = p.next(); + if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) { 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 ) ) { + if ( p.hasNext() ) { return false; } - final String p43_S = "(A,B,C,(AA,BB,CC,(CCC,DDD,EEE,(FFFF,GGGG)x)y,DD,EE,FF,GG,HH),D,E,(EE,FF),F,G,H,(((((5)4)3)2)1),I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,(XX,(YY)),Y,Z)"; - final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() ); - if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) { + if ( p.next() != null ) { return false; } - final String p44_S = "(((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)))"; - final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() ); - if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) { + p.reset(); + if ( !p.hasNext() ) { return false; } - final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))"; - final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() ); - if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) { + p8_0 = p.next(); + if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) { return false; } - final String p46_S = ""; - final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() ); - if ( ( p46.length != 1 ) || !p46[ 0 ].isEmpty() ) { + if ( !p.hasNext() ) { return false; } - final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ]; - if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { + p8_1 = p.next(); + if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) { return false; } - final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; - if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { + if ( p.hasNext() ) { return false; } - final Phylogeny p49 = factory - .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ), - new NHXParser() )[ 0 ]; - if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { + if ( p.next() != null ) { return false; } - final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; - if ( p50.getNode( "A" ) == null ) { + p.reset(); + // + p.setSource( "" ); + if ( p.hasNext() ) { return false; } - if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) - .equals( "((A,B)ab:2.0[88],C);" ) ) { + // + p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) ); + if ( !p.hasNext() ) { return false; } - if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) { + Phylogeny p_27 = p.next(); + if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) { + System.out.println( p_27.toNewHampshireX() ); + System.exit( -1 ); return false; } - if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ) - .equals( "((A,B)88:2.0,C);" ) ) { + if ( p.hasNext() ) { return false; } - final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; - if ( p51.getNode( "A(A" ) == null ) { + if ( p.next() != null ) { return false; } - final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; - if ( p52.getNode( "A(A" ) == null ) { + p.reset(); + if ( !p.hasNext() ) { return false; } - final Phylogeny p53 = factory - .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ), - new NHXParser() )[ 0 ]; - if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) { + p_27 = p.next(); + if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) { + System.out.println( p_27.toNewHampshireX() ); + System.exit( -1 ); return false; } - // - final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ]; - if ( p54.getNode( "A" ) == null ) { + if ( p.hasNext() ) { return false; } - if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) - .equals( "((A,B)[88],C);" ) ) { + if ( p.next() != null ) { return false; } } @@ -4537,9 +6287,9 @@ public final class Test { final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" ); final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" ); final PhylogenyNode n5 = PhylogenyNode - .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1:W=2:C=10.20.30:XN=S=tag1=value1=unit1]" ); + .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" ); final PhylogenyNode n6 = PhylogenyNode - .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1:W=2:C=0.0.0:XN=B=bool_tag=T]" ); + .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" ); if ( !n1.toNewHampshireX().equals( "" ) ) { return false; } @@ -4552,11 +6302,116 @@ public final class Test { if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) { return false; } - if ( !n5.toNewHampshireX() - .equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:XN=S=tag1=value1=unit1:B=56:W=2.0:C=10.20.30]" ) ) { + if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) { + return false; + } + if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) { + System.out.println( n6.toNewHampshireX() ); + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testTaxonomyExtraction() { + try { + final PhylogenyNode n0 = PhylogenyNode + .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n0.getNodeData().isHasTaxonomy() ) { + return false; + } + final PhylogenyNode n1 = PhylogenyNode + .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n1.getNodeData().isHasTaxonomy() ) { + System.out.println( n1.toString() ); + return false; + } + final PhylogenyNode n2x = PhylogenyNode + .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n2x.getNodeData().isHasTaxonomy() ) { + return false; + } + final PhylogenyNode n3 = PhylogenyNode + .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) { + System.out.println( n3.toString() ); + return false; + } + final PhylogenyNode n4 = PhylogenyNode + .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n4.getNodeData().isHasTaxonomy() ) { + System.out.println( n4.toString() ); + return false; + } + final PhylogenyNode n5 = PhylogenyNode + .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n5.getNodeData().isHasTaxonomy() ) { + System.out.println( n5.toString() ); + return false; + } + final PhylogenyNode n6 = PhylogenyNode + .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n6.getNodeData().isHasTaxonomy() ) { + System.out.println( n6.toString() ); + return false; + } + final PhylogenyNode n7 = PhylogenyNode + .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n7.getNodeData().isHasTaxonomy() ) { + System.out.println( n7.toString() ); + return false; + } + final PhylogenyNode n8 = PhylogenyNode + .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) { + System.out.println( n8.toString() ); + return false; + } + final PhylogenyNode n9 = PhylogenyNode + .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) { + System.out.println( n9.toString() ); + return false; + } + final PhylogenyNode n10x = PhylogenyNode + .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n10x.getNodeData().isHasTaxonomy() ) { + System.out.println( n10x.toString() ); + return false; + } + final PhylogenyNode n10xx = PhylogenyNode + .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n10xx.getNodeData().isHasTaxonomy() ) { + System.out.println( n10xx.toString() ); + return false; + } + final PhylogenyNode n10 = PhylogenyNode + .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) { + System.out.println( n10.toString() ); + return false; + } + final PhylogenyNode n11 = PhylogenyNode + .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE ); + if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) { + System.out.println( n11.toString() ); + return false; + } + final PhylogenyNode n12 = PhylogenyNode + .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus", + NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE ); + if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) { + System.out.println( n12.toString() ); return false; } - if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:XN=B=bool_tag=T:B=100:W=2.0:C=0.0.0]" ) ) { + final PhylogenyNode n13 = PhylogenyNode + .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE ); + if ( n13.getNodeData().isHasTaxonomy() ) { + System.out.println( n13.toString() ); return false; } } @@ -4614,61 +6469,55 @@ public final class Test { if ( !n5.isHasAssignedEvent() ) { return false; } - if ( PhylogenyMethods.getBranchWidthValue( n5 ) != 2 ) { - return false; - } - if ( n5.getNodeData().getProperties().getPropertyRefs().length != 2 ) { - return false; - } final PhylogenyNode n8 = PhylogenyNode - .createInstanceFromNhxString( "n8_ECOLI/12:0.01", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !n8.getName().equals( "n8_ECOLI/12" ) ) { + .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) { return false; } final PhylogenyNode n9 = PhylogenyNode - .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) { + .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) { return false; } final PhylogenyNode n10 = PhylogenyNode - .createInstanceFromNhxString( "n10.ECOLI", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n10.getName().equals( "n10.ECOLI" ) ) { return false; } final PhylogenyNode n20 = PhylogenyNode - .createInstanceFromNhxString( "n20_ECOLI/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) { + .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) { return false; } final PhylogenyNode n20x = PhylogenyNode - .createInstanceFromNhxString( "n20_ECOL1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); - if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) { + .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) { return false; } final PhylogenyNode n20xx = PhylogenyNode - .createInstanceFromNhxString( "n20_eCOL1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) { + .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) { return false; } if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) { return false; } final PhylogenyNode n20xxx = PhylogenyNode - .createInstanceFromNhxString( "n20_ecoli/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) { return false; } @@ -4676,7 +6525,7 @@ public final class Test { return false; } final PhylogenyNode n20xxxx = PhylogenyNode - .createInstanceFromNhxString( "n20_Ecoli/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) { return false; } @@ -4684,15 +6533,15 @@ public final class Test { return false; } final PhylogenyNode n21 = PhylogenyNode - .createInstanceFromNhxString( "n21_PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); - if ( !n21.getName().equals( "n21_PIG" ) ) { + .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !n21.getName().equals( "N21_PIG" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) { return false; } final PhylogenyNode n21x = PhylogenyNode - .createInstanceFromNhxString( "n21_PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n21x.getName().equals( "n21_PIG" ) ) { return false; } @@ -4700,7 +6549,7 @@ public final class Test { return false; } final PhylogenyNode n22 = PhylogenyNode - .createInstanceFromNhxString( "n22/PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n22.getName().equals( "n22/PIG" ) ) { return false; } @@ -4708,7 +6557,7 @@ public final class Test { return false; } final PhylogenyNode n23 = PhylogenyNode - .createInstanceFromNhxString( "n23/PIG_1", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n23.getName().equals( "n23/PIG_1" ) ) { return false; } @@ -4716,75 +6565,33 @@ public final class Test { return false; } final PhylogenyNode a = PhylogenyNode - .createInstanceFromNhxString( "n10_ECOLI/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) { + .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) { return false; } - final PhylogenyNode b = PhylogenyNode - .createInstanceFromNhxString( "n10_ECOLI1/1-2", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) { - return false; - } - final PhylogenyNode c = PhylogenyNode - .createInstanceFromNhxString( "n10_RATAF12/1000-2000", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) { - return false; - } final PhylogenyNode c1 = PhylogenyNode - .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) { + .createInstanceFromNhxString( "n10_BOVIN/1000-2000", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) { return false; } final PhylogenyNode c2 = PhylogenyNode - .createInstanceFromNhxString( "n10_Bovin_1/1000-2000", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) { - return false; - } - final PhylogenyNode d = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !d.getName().equals( "n10_RAT1/1-2" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) { - return false; - } - final PhylogenyNode e = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT1", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !e.getName().equals( "n10_RAT1" ) ) { - return false; - } - if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) { - return false; - } - final PhylogenyNode e2 = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT1", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); - if ( !e2.getName().equals( "n10_RAT1" ) ) { + .createInstanceFromNhxString( "N10_Bovin_1/1000-2000", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) { return false; } - if ( !PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) { + if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) { return false; } final PhylogenyNode e3 = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT~", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); if ( !e3.getName().equals( "n10_RAT~" ) ) { return false; } @@ -4792,9 +6599,9 @@ public final class Test { return false; } final PhylogenyNode n11 = PhylogenyNode - .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) { + .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) { return false; } if ( n11.getDistanceToParent() != 0.4 ) { @@ -4804,9 +6611,9 @@ public final class Test { return false; } final PhylogenyNode n12 = PhylogenyNode - .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) { + .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) { return false; } if ( n12.getDistanceToParent() != 0.4 ) { @@ -4815,48 +6622,14 @@ public final class Test { if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) { return false; } - final PhylogenyNode m = PhylogenyNode - .createInstanceFromNhxString( "n10_MOUSEa", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); - if ( !m.getName().equals( "n10_MOUSEa" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) { - return false; - } final PhylogenyNode o = PhylogenyNode - .createInstanceFromNhxString( "n10_MOUSE_", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); - if ( !o.getName().equals( "n10_MOUSE_" ) ) { + .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !o.getName().equals( "ABCD_MOUSE" ) ) { return false; } if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) { return false; } - final Property tvu1 = n5.getNodeData().getProperties().getProperty( "tag1" ); - final Property tvu3 = n5.getNodeData().getProperties().getProperty( "tag3" ); - if ( !tvu1.getRef().equals( "tag1" ) ) { - return false; - } - if ( !tvu1.getDataType().equals( "xsd:string" ) ) { - return false; - } - if ( !tvu1.getUnit().equals( "unit1" ) ) { - return false; - } - if ( !tvu1.getValue().equals( "value1" ) ) { - return false; - } - if ( !tvu3.getRef().equals( "tag3" ) ) { - return false; - } - if ( !tvu3.getDataType().equals( "xsd:string" ) ) { - return false; - } - if ( !tvu3.getUnit().equals( "unit3" ) ) { - return false; - } - if ( !tvu3.getValue().equals( "value3" ) ) { - return false; - } if ( n1.getName().compareTo( "" ) != 0 ) { return false; } @@ -4876,60 +6649,42 @@ public final class Test { return false; } final PhylogenyNode n00 = PhylogenyNode - .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:ID=node_identifier:S=Ecoli:D=N:Co=N:B=100:T=1:On=100:SOn=100:SNn=100:W=2:C=0.0.0:XN=U=url_tag=www.yahoo.com]" ); - if ( !n00.getNodeData().getNodeIdentifier().getValue().equals( "node_identifier" ) ) { - return false; - } + .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" ); if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) { return false; } if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) { return false; } - if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getRef().equals( "url_tag" ) ) { - return false; - } - if ( n00.getNodeData().getProperties().getProperty( "url_tag" ).getAppliesTo() != Property.AppliesTo.NODE ) { - return false; - } - if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getDataType().equals( "xsd:anyURI" ) ) { - return false; - } - if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getValue().equals( "www.yahoo.com" ) ) { - return false; - } - if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getUnit().equals( "" ) ) { - return false; - } final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" ); if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) { return false; } - final PhylogenyNode nx2 = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:G=gene_2]" ); - if ( !nx2.getNodeData().getSequence().getName().equals( "gene_2" ) ) { - return false; - } final PhylogenyNode n13 = PhylogenyNode - .createInstanceFromNhxString( "blah_12345/1-2", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); if ( !n13.getName().equals( "blah_12345/1-2" ) ) { return false; } - if ( !PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) { + if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) { + return false; + } + if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) { + return false; + } + if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) { return false; } final PhylogenyNode n14 = PhylogenyNode - .createInstanceFromNhxString( "blah_12X45/1-2", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !n14.getName().equals( "blah_12X45/1-2" ) ) { + .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) { return false; } - if ( !PhylogenyMethods.getSpecies( n14 ).equals( "12X45" ) ) { + if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) { return false; } final PhylogenyNode n15 = PhylogenyNode .createInstanceFromNhxString( "something_wicked[123]", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n15.getName().equals( "something_wicked" ) ) { return false; } @@ -4941,7 +6696,7 @@ public final class Test { } final PhylogenyNode n16 = PhylogenyNode .createInstanceFromNhxString( "something_wicked2[9]", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n16.getName().equals( "something_wicked2" ) ) { return false; } @@ -4953,7 +6708,7 @@ public final class Test { } final PhylogenyNode n17 = PhylogenyNode .createInstanceFromNhxString( "something_wicked3[a]", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n17.getName().equals( "something_wicked3" ) ) { return false; } @@ -4961,7 +6716,7 @@ public final class Test { return false; } final PhylogenyNode n18 = PhylogenyNode - .createInstanceFromNhxString( ":0.5[91]", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) { return false; } @@ -4971,6 +6726,59 @@ public final class Test { if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) { return false; } + final PhylogenyNode n19 = PhylogenyNode + .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) { + return false; + } + if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) { + return false; + } + final PhylogenyNode n30 = PhylogenyNode + .createInstanceFromNhxString( "blah_1234567-roejojoej", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) { + return false; + } + if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) { + return false; + } + final PhylogenyNode n31 = PhylogenyNode + .createInstanceFromNhxString( "blah_12345678-roejojoej", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n31.getNodeData().isHasTaxonomy() ) { + return false; + } + final PhylogenyNode n32 = PhylogenyNode + .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n32.getNodeData().isHasTaxonomy() ) { + return false; + } + final PhylogenyNode n40 = PhylogenyNode + .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) { + return false; + } + final PhylogenyNode n41 = PhylogenyNode + .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n41.getNodeData().isHasTaxonomy() ) { + return false; + } + final PhylogenyNode n42 = PhylogenyNode + .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( n42.getNodeData().isHasTaxonomy() ) { + return false; + } + final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345", + NHXParser.TAXONOMY_EXTRACTION.NO ); + if ( n43.getNodeData().isHasTaxonomy() ) { + return false; + } + final PhylogenyNode n44 = PhylogenyNode + .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n44.getNodeData().isHasTaxonomy() ) { + return false; + } } catch ( final Exception e ) { e.printStackTrace( System.out ); @@ -5770,51 +7578,51 @@ public final class Test { try { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ]; - final int count = PhylogenyNode.getNodeCount(); + final long count = PhylogenyNode.getNodeCount(); p.levelOrderReID(); if ( p.getNode( "r" ).getId() != count ) { return false; } - if ( p.getNode( "A" ).getId() != count + 1 ) { + if ( p.getNode( "A" ).getId() != ( count + 1 ) ) { return false; } - if ( p.getNode( "B" ).getId() != count + 1 ) { + if ( p.getNode( "B" ).getId() != ( count + 1 ) ) { return false; } - if ( p.getNode( "C" ).getId() != count + 1 ) { + if ( p.getNode( "C" ).getId() != ( count + 1 ) ) { return false; } - if ( p.getNode( "1" ).getId() != count + 2 ) { + if ( p.getNode( "1" ).getId() != ( count + 2 ) ) { return false; } - if ( p.getNode( "2" ).getId() != count + 2 ) { + if ( p.getNode( "2" ).getId() != ( count + 2 ) ) { return false; } - if ( p.getNode( "3" ).getId() != count + 2 ) { + if ( p.getNode( "3" ).getId() != ( count + 2 ) ) { return false; } - if ( p.getNode( "4" ).getId() != count + 2 ) { + if ( p.getNode( "4" ).getId() != ( count + 2 ) ) { return false; } - if ( p.getNode( "5" ).getId() != count + 2 ) { + if ( p.getNode( "5" ).getId() != ( count + 2 ) ) { return false; } - if ( p.getNode( "6" ).getId() != count + 2 ) { + if ( p.getNode( "6" ).getId() != ( count + 2 ) ) { return false; } - if ( p.getNode( "a" ).getId() != count + 3 ) { + if ( p.getNode( "a" ).getId() != ( count + 3 ) ) { return false; } - if ( p.getNode( "b" ).getId() != count + 3 ) { + if ( p.getNode( "b" ).getId() != ( count + 3 ) ) { return false; } - if ( p.getNode( "X" ).getId() != count + 4 ) { + if ( p.getNode( "X" ).getId() != ( count + 4 ) ) { return false; } - if ( p.getNode( "Y" ).getId() != count + 4 ) { + if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) { return false; } - if ( p.getNode( "Z" ).getId() != count + 4 ) { + if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) { return false; } } @@ -6020,7 +7828,7 @@ public final class Test { final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ]; gene1.setRooted( true ); species1.setRooted( true ); - final SDI sdi = new SDIse( gene1, species1 ); + final SDI sdi = new SDI( gene1, species1 ); if ( !gene1.getRoot().isDuplication() ) { return false; } @@ -6032,7 +7840,7 @@ public final class Test { new NHXParser() )[ 0 ]; species2.setRooted( true ); gene2.setRooted( true ); - final SDI sdi2 = new SDIse( gene2, species2 ); + final SDI sdi2 = new SDI( gene2, species2 ); if ( sdi2.getDuplicationsSum() != 0 ) { return false; } @@ -6062,7 +7870,7 @@ public final class Test { new NHXParser() )[ 0 ]; species3.setRooted( true ); gene3.setRooted( true ); - final SDI sdi3 = new SDIse( gene3, species3 ); + final SDI sdi3 = new SDI( gene3, species3 ); if ( sdi3.getDuplicationsSum() != 1 ) { return false; } @@ -6080,7 +7888,7 @@ public final class Test { new NHXParser() )[ 0 ]; species4.setRooted( true ); gene4.setRooted( true ); - final SDI sdi4 = new SDIse( gene4, species4 ); + final SDI sdi4 = new SDI( gene4, species4 ); if ( sdi4.getDuplicationsSum() != 1 ) { return false; } @@ -6107,7 +7915,7 @@ public final class Test { new NHXParser() )[ 0 ]; species5.setRooted( true ); gene5.setRooted( true ); - final SDI sdi5 = new SDIse( gene5, species5 ); + final SDI sdi5 = new SDI( gene5, species5 ); if ( sdi5.getDuplicationsSum() != 2 ) { return false; } @@ -6140,7 +7948,7 @@ public final class Test { new NHXParser() )[ 0 ]; species6.setRooted( true ); gene6.setRooted( true ); - final SDI sdi6 = new SDIse( gene6, species6 ); + final SDI sdi6 = new SDI( gene6, species6 ); if ( sdi6.getDuplicationsSum() != 3 ) { return false; } @@ -6187,7 +7995,7 @@ public final class Test { final Phylogeny gene7_1 = Test .createPhylogeny( "((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2]),b1[&&NHX:S=b1]),x[&&NHX:S=x]),m1[&&NHX:S=m1]),i1[&&NHX:S=i1]),e1[&&NHX:S=e1]),y[&&NHX:S=y]),z[&&NHX:S=z])" ); gene7_1.setRooted( true ); - final SDI sdi7 = new SDIse( gene7_1, species7 ); + final SDI sdi7 = new SDI( gene7_1, species7 ); if ( sdi7.getDuplicationsSum() != 0 ) { return false; } @@ -6218,7 +8026,7 @@ public final class Test { final Phylogeny gene7_2 = Test .createPhylogeny( "(((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2]),b1[&&NHX:S=b1]),x[&&NHX:S=x]),m1[&&NHX:S=m1]),i1[&&NHX:S=i1]),j2[&&NHX:S=j2]),e1[&&NHX:S=e1]),y[&&NHX:S=y]),z[&&NHX:S=z])" ); gene7_2.setRooted( true ); - final SDI sdi7_2 = new SDIse( gene7_2, species7 ); + final SDI sdi7_2 = new SDI( gene7_2, species7 ); if ( sdi7_2.getDuplicationsSum() != 1 ) { return false; } @@ -7620,7 +9428,10 @@ public final class Test { if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) { return false; } - if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861.2" ).equals( "AY423861.2" ) ) { + return false; + } + if ( !SequenceIdParser.parseGenbankAccessor( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) { return false; } if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) { @@ -7660,45 +9471,6 @@ public final class Test { } private static boolean testUniprotEntryRetrieval() { - if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) { - return false; - } - if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) { - return false; - } - if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) { - return false; - } - if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) { - return false; - } - if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) { - return false; - } - if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) { - return false; - } - if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) { - return false; - } - if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) { - return false; - } - if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) { - return false; - } - if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) { - return false; - } - if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) { - return false; - } - if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) { - return false; - } - if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) { - return false; - } try { final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 ); if ( !entry.getAccession().equals( "P12345" ) ) { @@ -7710,9 +9482,6 @@ public final class Test { if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) { return false; } - if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) { - return false; - } if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) { return false; } @@ -7820,6 +9589,37 @@ public final class Test { return true; } + private static boolean testSequenceWriter() { + try { + final String n = ForesterUtil.LINE_SEPARATOR; + if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) { + return false; + } + if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) { + return false; + } + if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) { + return false; + } + if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) { + return false; + } + if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString() + .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) { + return false; + } + if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString() + .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace(); + return false; + } + return true; + } + private static boolean testCreateBalancedPhylogeny() { try { final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 ); @@ -8672,8 +10472,30 @@ public final class Test { return false; } // + id = SequenceIdParser.parse( "P4A123" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + return false; + } + // + id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + return false; + } + // id = SequenceIdParser.parse( "XP_12345" ); if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); return false; } // lcl_91970_unknown_