X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Ftest%2FTest.java;h=b80a5841bbf68ac7947cd951d44beaefe0ecbb90;hb=bf7ff064d7b1e3a513653f5161c9b56cfb81a74b;hp=906969308a1123dcb3db0b97d036d834fc224efa;hpb=cb4ea01dc92bafecf44c8e4fa85d07528b80943f;p=jalview.git diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 9069693..b80a584 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; @@ -51,8 +51,10 @@ 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.msa.BasicMsa; import org.forester.msa.Mafft; @@ -64,7 +66,7 @@ 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.BinaryCharacters; import org.forester.phylogeny.data.BranchWidth; import org.forester.phylogeny.data.Confidence; @@ -84,10 +86,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.TaxonomyAssigner; import org.forester.sdi.TestGSDI; import org.forester.sequence.BasicSequence; import org.forester.sequence.Sequence; @@ -104,10 +105,9 @@ import org.forester.util.ForesterConstants; import org.forester.util.ForesterUtil; import org.forester.util.GeneralTable; import org.forester.util.SequenceIdParser; -import org.forester.ws.uniprot.DatabaseTools; -import org.forester.ws.uniprot.SequenceDatabaseEntry; -import org.forester.ws.uniprot.UniProtTaxonomy; -import org.forester.ws.uniprot.UniProtWsTools; +import org.forester.ws.seqdb.SequenceDatabaseEntry; +import org.forester.ws.seqdb.SequenceDbWsTools; +import org.forester.ws.seqdb.UniProtTaxonomy; import org.forester.ws.wabi.TxSearch; import org.forester.ws.wabi.TxSearch.RANKS; import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS; @@ -137,8 +137,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 ) { @@ -172,17 +171,13 @@ public final class Test { System.exit( -1 ); } final long start_time = new Date().getTime(); - - - System.out.print( "Sequence id parsing: " ); - if ( testSequenceIdParsing() ) { + if ( testSequenceIdParsing() ) { System.out.println( "OK." ); succeeded++; } else { System.out.println( "failed." ); - System.exit( -1 ); //TODO FIXME remove me!! ~ failed++; } System.out.print( "Hmmscan output parser: " ); @@ -203,6 +198,24 @@ 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( "Taxonomy extraction (general): " ); + if ( Test.testTaxonomyExtraction() ) { + 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." ); @@ -212,6 +225,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." ); @@ -266,6 +288,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." ); @@ -356,6 +387,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." ); @@ -455,6 +495,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." ); @@ -482,6 +531,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." ); @@ -491,8 +549,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++; } @@ -500,8 +558,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "Taxonomy assigner: " ); - if ( Test.testTaxonomyAssigner() ) { + System.out.print( "Data objects and methods: " ); + if ( Test.testDataObjects() ) { System.out.println( "OK." ); succeeded++; } @@ -509,8 +567,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "SDIunrooted: " ); - if ( Test.testSDIunrooted() ) { + System.out.print( "Properties map: " ); + if ( Test.testPropertiesMap() ) { System.out.println( "OK." ); succeeded++; } @@ -518,8 +576,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "GSDI: " ); - if ( TestGSDI.test() ) { + System.out.print( "SDIse: " ); + if ( Test.testSDIse() ) { System.out.println( "OK." ); succeeded++; } @@ -527,8 +585,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "Descriptive statistics: " ); - if ( Test.testDescriptiveStatistics() ) { + System.out.print( "SDIunrooted: " ); + if ( Test.testSDIunrooted() ) { System.out.println( "OK." ); succeeded++; } @@ -536,8 +594,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "Data objects and methods: " ); - if ( Test.testDataObjects() ) { + System.out.print( "GSDI: " ); + if ( TestGSDI.test() ) { System.out.println( "OK." ); succeeded++; } @@ -545,8 +603,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "Properties map: " ); - if ( Test.testPropertiesMap() ) { + System.out.print( "RIO: " ); + if ( TestRIO.test() ) { System.out.println( "OK." ); succeeded++; } @@ -701,9 +759,27 @@ public final class Test { System.out.println( "failed." ); failed++; } - if ( Mafft.isInstalled() ) { + //---- + String path = ""; + final String os = ForesterUtil.OS_NAME.toLowerCase(); + if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) { + path = "/usr/local/bin/mafft"; + } + else if ( os.indexOf( "win" ) >= 0 ) { + path = "C:\\Program Files\\mafft-win\\mafft.bat"; + } + else { + path = "/home/czmasek/bin/mafft"; + } + if ( !MsaInferrer.isInstalled( path ) ) { + path = "mafft"; + } + if ( !MsaInferrer.isInstalled( path ) ) { + path = "/usr/local/bin/mafft"; + } + if ( MsaInferrer.isInstalled( path ) ) { System.out.print( "MAFFT (external program): " ); - if ( Test.testMafft() ) { + if ( Test.testMafft( path ) ) { System.out.println( "OK." ); succeeded++; } @@ -711,6 +787,7 @@ public final class Test { System.out.println( "failed [will not count towards failed tests]" ); } } + //---- System.out.print( "Next nodes with collapsed: " ); if ( Test.testNextNodeWithCollapsing() ) { System.out.println( "OK." ); @@ -729,15 +806,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; @@ -754,73 +822,87 @@ 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 testExtractTaxonomyCodeFromNodeName() { + try { + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "MOUSE" ) ) { + return false; + } + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "RAT" ) ) { + return false; + } + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { + return false; + } + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "MOUSE" ) ) { + return false; + } + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE_function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "MOUSE" ) ) { + return false; + } + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "MOUSE" ) ) { + return false; + } + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { + return false; + } + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { + return false; + } + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) { + return false; + } + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) { + return false; + } + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) { + return false; + } + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { + return false; + } + if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445", + TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) { + return false; + } + if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) + .equals( "RAT" ) ) { + return false; + } + 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; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; } private static boolean testBasicNodeMethods() { @@ -830,11 +912,11 @@ public final class Test { } final PhylogenyNode n1 = new PhylogenyNode(); final PhylogenyNode n2 = PhylogenyNode - .createInstanceFromNhxString( "", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); final PhylogenyNode n3 = PhylogenyNode - .createInstanceFromNhxString( "n3", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); final PhylogenyNode n4 = PhylogenyNode - .createInstanceFromNhxString( "n4:0.01", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( n1.isHasAssignedEvent() ) { return false; } @@ -959,67 +1041,67 @@ public final class Test { if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc() .equals( "apoptosis" ) ) { return false; } - if ( !( t3.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.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getSource() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource() .equals( "UniProtKB" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getEvidence() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence() .equals( "experimental" ) ) { return false; } - if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getType() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType() .equals( "function" ) ) { return false; } - if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getConfidence() + if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence() .getValue() != 1 ) { return false; } - if ( !( t3.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.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc() .equals( "apoptosis" ) ) { return false; } - if ( ( t3.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.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.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.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.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.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.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.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc() + if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc() .equals( "intracellular organelle" ) ) { return false; } @@ -1033,114 +1115,6 @@ public final class Test { if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) { 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 ); @@ -1246,67 +1220,67 @@ public final class Test { .equals( "UniProtKB" ) ) { return false; } - if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc() + if ( !( t3_rt.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_rt.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_rt.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_rt.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_rt.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_rt.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_rt.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_rt.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_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( 1 ) ).getProperties() + 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( 1 ) ).getProperties() + 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( 1 ) ).getProperties() + 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( 1 ) ).getProperties() + 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( 1 ) ).getProperties() + 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( 0 ) ).getRef() + 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( 2 ) ).getDesc() + if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc() .equals( "intracellular organelle" ) ) { return false; } @@ -1728,6 +1702,7 @@ public final class Test { final List> tl = BasicTableParser.parse( source2.toString(), ";", false, + false, "comment:", false ); if ( tl.size() != 2 ) { @@ -1928,26 +1903,6 @@ public final class Test { return false; } final PhylogenyNode n = t3.getNode( "ABC" ); - PhylogenyNodeIterator it; - for( it = n.iterateChildNodesForward(); it.hasNext(); ) { - it.next(); - } - for( it.reset(); it.hasNext(); ) { - it.next(); - } - final PhylogenyNodeIterator it2 = n.iterateChildNodesForward(); - if ( !it2.next().getName().equals( "A" ) ) { - return false; - } - if ( !it2.next().getName().equals( "B" ) ) { - return false; - } - if ( !it2.next().getName().equals( "C" ) ) { - return false; - } - if ( it2.hasNext() ) { - return false; - } final Phylogeny t4 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3,(F,G,H,I))", new NHXParser() )[ 0 ]; if ( t4.getNumberOfExternalNodes() != 9 ) { return false; @@ -1984,7 +1939,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; @@ -2002,6 +1957,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(); @@ -2032,7 +2015,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; } @@ -2147,7 +2129,7 @@ public final class Test { return false; } t2.setIdentifier( new Identifier( "ecoli" ) ); - t2.setTaxonomyCode( "other" ); + t2.setTaxonomyCode( "OTHER" ); t2.setScientificName( "what" ); t2.setCommonName( "something" ); if ( !t1.isEqual( t2 ) ) { @@ -2984,6 +2966,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 ); @@ -3083,133 +3088,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; } } @@ -3225,200 +3229,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; } @@ -3430,32 +3433,360 @@ 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; + } + 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 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; + } + final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ), + p1.getNode( "gh" ) ); + if ( !gh.getName().equals( "gh" ) ) { + return false; + } + final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "B" ) ); + if ( !ab.getName().equals( "ab" ) ) { + return false; + } + final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ), + p1.getNode( "A" ) ); + if ( !ab2.getName().equals( "ab" ) ) { + return false; + } + final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ), + p1.getNode( "G" ) ); + if ( !gh2.getName().equals( "gh" ) ) { + return false; + } + final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ), + p1.getNode( "H" ) ); + if ( !gh3.getName().equals( "gh" ) ) { + return false; + } + final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ), + p1.getNode( "A" ) ); + if ( !abc.getName().equals( "abc" ) ) { + return false; + } + final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "C" ) ); + if ( !abc2.getName().equals( "abc" ) ) { + return false; + } + final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "D" ) ); + if ( !abcd.getName().equals( "abcd" ) ) { + return false; + } + final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ), + p1.getNode( "A" ) ); + if ( !abcd2.getName().equals( "abcd" ) ) { + return false; + } + final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "F" ) ); + if ( !abcdef.getName().equals( "abcdef" ) ) { + return false; + } + final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ), + p1.getNode( "A" ) ); + if ( !abcdef2.getName().equals( "abcdef" ) ) { + return false; + } + final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ), + p1.getNode( "F" ) ); + if ( !abcdef3.getName().equals( "abcdef" ) ) { + return false; + } + final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ), + p1.getNode( "ab" ) ); + if ( !abcdef4.getName().equals( "abcdef" ) ) { + return false; + } + final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "E" ) ); + if ( !abcde.getName().equals( "abcde" ) ) { + return false; + } + final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ), + p1.getNode( "A" ) ); + if ( !abcde2.getName().equals( "abcde" ) ) { + return false; + } + final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ), + p1.getNode( "abcdefgh" ) ); + if ( !r.getName().equals( "abcdefgh" ) ) { + return false; + } + 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 ) { @@ -3711,9 +4042,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() ) { @@ -3753,6 +4122,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 ) ) { @@ -4095,152 +4465,1063 @@ public final class Test { return true; } - private static boolean testNexusTreeParsingTranslating() { + private static boolean testNexusTreeParsingIterating() { 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 ) { + final NexusPhylogeniesParser p = new NexusPhylogeniesParser(); + p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" ); + if ( !p.hasNext() ) { return false; } - if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) { + Phylogeny phy = p.next(); + if ( phy == null ) { return false; } - if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) { + if ( phy.getNumberOfExternalNodes() != 25 ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + if ( !phy.getName().equals( "" ) ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + if ( p.hasNext() ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + phy = p.next(); + if ( phy != null ) { return false; } - phylogenies = null; - phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser ); - if ( phylogenies.length != 3 ) { + // + p.reset(); + if ( !p.hasNext() ) { return false; } - if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) { + phy = p.next(); + if ( phy == null ) { return false; } - if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) { + if ( phy.getNumberOfExternalNodes() != 25 ) { return false; } - if ( phylogenies[ 0 ].isRooted() ) { + if ( !phy.getName().equals( "" ) ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + if ( p.hasNext() ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + phy = p.next(); + if ( phy != null ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + //// + p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" ); + if ( !p.hasNext() ) { return false; } - if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) { + phy = p.next(); + if ( phy == null ) { return false; } - if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) { + if ( phy.getNumberOfExternalNodes() != 10 ) { return false; } - if ( phylogenies[ 1 ].isRooted() ) { + if ( !phy.getName().equals( "name" ) ) { return false; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + if ( p.hasNext() ) { return false; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + phy = p.next(); + if ( phy != null ) { return false; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + // + p.reset(); + if ( !p.hasNext() ) { return false; } - if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) { + phy = p.next(); + if ( phy == null ) { return false; } - if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) { + 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" ) ) { + 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 ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) { return false; } - if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) { return false; } - phylogenies = null; - phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser ); - if ( phylogenies.length != 3 ) { + if ( p28.length != 4 ) { return false; } - if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) { + 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; } - if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) { + 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; } - if ( phylogenies[ 0 ].isRooted() ) { + final String p32_S = " ; ; \n \t \b \f \r ;;;;;; "; + final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() ); + if ( ( p32.length != 0 ) ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + final String p33_S = "A"; + final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() ); + if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + final String p34_S = "B;"; + final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() ); + if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) { return false; } - if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + 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; } - if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) { + final String p36_S = "(A)"; + final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() ); + if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) { return false; } - if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) { + final String p37_S = "((A))"; + final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() ); + if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) { return false; } - if ( phylogenies[ 1 ].isRooted() ) { + 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; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + 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; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + 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; } - if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + 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; } - if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) { + 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; } - if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) { + 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; } - if ( !phylogenies[ 2 ].isRooted() ) { + 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; } - if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) { + 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; } - if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) { + final String p46_S = ""; + final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() ); + if ( p46.length != 0 ) { return false; } - if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName() - .equals( "Aranaeus" ) ) { + 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; + } + 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; + } + 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; + } + final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( p50.getNode( "A" ) == null ) { + return false; + } + if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) + .equals( "((A,B)ab:2.0[88],C);" ) ) { + return false; + } + if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) { + return false; + } + if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ) + .equals( "((A,B)88:2.0,C);" ) ) { + 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 ) { + 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 ) { + 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 ) { + return false; + } + // + final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ]; + if ( p54.getNode( "A" ) == null ) { + return false; + } + if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) + .equals( "((A,B)[88],C);" ) ) { return false; } } @@ -4251,290 +5532,386 @@ public final class Test { return true; } - private static boolean testNHParsing() { + private static boolean testNHParsingIter() { try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ]; - if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) { + final String p0_str = "(A,B);"; + final NHXParser p = new NHXParser(); + p.setSource( p0_str ); + 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 " ) ) { + final Phylogeny p0 = p.next(); + if ( !p0.toNewHampshire().equals( p0_str ) ) { + System.out.println( p0.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;')" ) ) { + if ( p.next() != null ) { return false; } - if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) { + // + 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; } - 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;')" ) ) { + // + 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 ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) { + // + 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 ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) { + // + p.setSource( "(A)" ); + final Phylogeny p00000 = p.next(); + if ( !p00000.toNewHampshire().equals( "(A);" ) ) { + System.out.println( p00000.toNewHampshire() ); return false; } - if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) { + // + final String p1_str = "(A,B)(C,D)(E,F)(G,H)"; + p.setSource( p1_str ); + 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 ) ) { + final Phylogeny p1_0 = p.next(); + if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) { + System.out.println( p1_0.toNewHampshire() ); 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 ) ) { + 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 p1_1 = p.next(); + if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) { + System.out.println( "(C,D) != " + p1_1.toNewHampshire() ); 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 Phylogeny p1_2 = p.next(); + if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) { + System.out.println( "(E,F) != " + p1_2.toNewHampshire() ); + return false; + } + if ( !p.hasNext() ) { + return false; + } + final Phylogeny p1_3 = p.next(); + if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) { + System.out.println( "(G,H) != " + p1_3.toNewHampshire() ); + return false; + } + if ( p.hasNext() ) { + return false; + } + if ( p.next() != null ) { + return false; + } + // + 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; + } + Phylogeny p2_0 = p.next(); + if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) { + System.out.println( p2_0.toNewHampshire() ); + return false; + } + if ( !p.hasNext() ) { + return false; + } + Phylogeny p2_1 = p.next(); + if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) { + System.out.println( "(C,D) != " + p2_1.toNewHampshire() ); + return false; + } + if ( !p.hasNext() ) { + return false; + } + 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 ( !p.hasNext() ) { + return false; + } + Phylogeny p2_3 = p.next(); + if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) { + System.out.println( "(G,H) != " + p2_3.toNewHampshire() ); + return false; + } + if ( !p.hasNext() ) { + return false; + } + Phylogeny p2_4 = p.next(); + if ( !p2_4.toNewHampshire().equals( "(X);" ) ) { + System.out.println( "(X) != " + p2_4.toNewHampshire() ); + return false; + } + if ( p.hasNext() ) { + return false; + } + if ( p.next() != null ) { + return false; + } + //// + p.reset(); + if ( !p.hasNext() ) { + return false; + } + p2_0 = p.next(); + if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) { + System.out.println( p2_0.toNewHampshire() ); + return false; + } + if ( !p.hasNext() ) { + return false; + } + p2_1 = p.next(); + if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) { + System.out.println( "(C,D) != " + p2_1.toNewHampshire() ); + return false; + } + if ( !p.hasNext() ) { + return false; + } + p2_2 = p.next(); + if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) { + System.out.println( "(E,F)root != " + p2_2.toNewHampshire() ); + return false; + } + if ( !p.hasNext() ) { + return false; + } + p2_3 = p.next(); + if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) { + System.out.println( "(G,H) != " + p2_3.toNewHampshire() ); + return false; + } + if ( !p.hasNext() ) { + return false; + } + p2_4 = p.next(); + if ( !p2_4.toNewHampshire().equals( "(X);" ) ) { + System.out.println( "(X) != " + p2_4.toNewHampshire() ); + return false; + } + if ( p.hasNext() ) { + return false; + } + if ( p.next() != null ) { + return false; + } + // + final String p3_str = "((A,B),C)abc"; + p.setSource( p3_str ); + if ( !p.hasNext() ) { + return false; + } + final Phylogeny p3_0 = p.next(); + if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) { + return false; + } + if ( p.hasNext() ) { + return false; + } + if ( p.next() != null ) { + return false; + } + // + final String p4_str = "((A,B)ab,C)abc"; + p.setSource( p4_str ); + if ( !p.hasNext() ) { + return false; + } + final Phylogeny p4_0 = p.next(); + if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) { 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.hasNext() ) { 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 ) ) { + if ( p.next() != null ) { 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 String p5_str = "(((A,B)ab,C)abc,D)abcd"; + p.setSource( p5_str ); + if ( !p.hasNext() ) { 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 ) ) { + final Phylogeny p5_0 = p.next(); + if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) { 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.hasNext() ) { 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 ) ) { + if ( p.next() != null ) { return false; } - if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) { + // + final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde"; + p.setSource( p6_str ); + if ( !p.hasNext() ) { 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 ) ) { + Phylogeny p6_0 = p.next(); + if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) { 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.hasNext() ) { 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 ) ) { + if ( p.next() != null ) { 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 ) ) { + p.reset(); + if ( !p.hasNext() ) { return false; } - if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) { + p6_0 = p.next(); + if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) { return false; } - if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) { + if ( p.hasNext() ) { return false; } - if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) { + if ( p.next() != null ) { 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 ) ) { + // + final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde"; + p.setSource( p7_str ); + if ( !p.hasNext() ) { 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 ) ) { + Phylogeny p7_0 = p.next(); + if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) { 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.hasNext() ) { return false; } - final String p33_S = "A"; - final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() ); - if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) { + if ( p.next() != null ) { return false; } - final String p34_S = "B;"; - final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() ); - if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) { + p.reset(); + if ( !p.hasNext() ) { 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 ) ) { + p7_0 = p.next(); + if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) { 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.hasNext() ) { return false; } - final String p37_S = "((A))"; - final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() ); - if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) { + if ( p.next() != null ) { 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 ) ) { + // + 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 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 ) ) { + Phylogeny p8_0 = p.next(); + if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) { 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 ) ) { + if ( !p.hasNext() ) { 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 ) ) { + Phylogeny p8_1 = p.next(); + if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) { 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.hasNext() ) { 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 ) ) { + if ( p.next() != null ) { 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 ) ) { + p.reset(); + if ( !p.hasNext() ) { return false; } - final String p46_S = ""; - final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() ); - if ( ( p46.length != 1 ) || !p46[ 0 ].isEmpty() ) { + p8_0 = p.next(); + if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) { 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() ) ) { + if ( !p.hasNext() ) { 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() ) ) { + p8_1 = p.next(); + if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) { 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.hasNext() ) { return false; } - final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; - if ( p50.getNode( "A" ) == null ) { + if ( p.next() != null ) { return false; } - if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) - .equals( "((A,B)ab:2.0[88],C);" ) ) { + p.reset(); + // + p.setSource( "" ); + if ( p.hasNext() ) { return false; } - if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,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.AS_INTERNAL_NODE_NAMES ) - .equals( "((A,B)88: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; } - 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.hasNext() ) { 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 ) { + if ( p.next() != null ) { 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.reset(); + if ( !p.hasNext() ) { return false; } - // - final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ]; - if ( p54.getNode( "A" ) == 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; } - if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) - .equals( "((A,B)[88],C);" ) ) { + if ( p.hasNext() ) { + return false; + } + if ( p.next() != null ) { return false; } } @@ -4552,9 +5929,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; } @@ -4567,11 +5944,151 @@ 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 n2 = PhylogenyNode + .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE ); + if ( !n2.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) { + System.out.println( n2.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.PFAM_STYLE_RELAXED ); + 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.PFAM_STYLE_RELAXED ); + if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) { + System.out.println( n12.toString() ); + return false; + } + final PhylogenyNode n13 = PhylogenyNode + .createInstanceFromNhxString( "blag_Mus_musculus1", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n13.getNodeData().isHasTaxonomy() ) { + System.out.println( n13.toString() ); + return false; + } + final PhylogenyNode n14 = PhylogenyNode + .createInstanceFromNhxString( "blag_Mus_musculus_11", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n14.getNodeData().isHasTaxonomy() ) { + System.out.println( n14.toString() ); + return false; + } + final PhylogenyNode n15 = PhylogenyNode + .createInstanceFromNhxString( "blag_Mus_musculus_v11", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus v11" ) ) { + System.out.println( n15.toString() ); + return false; + } + final PhylogenyNode n16 = PhylogenyNode + .createInstanceFromNhxString( "blag_Mus_musculus_/11", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n16.getNodeData().isHasTaxonomy() ) { + System.out.println( n16.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 n17 = PhylogenyNode + .createInstanceFromNhxString( "blag_Mus_musculus_v", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( n17.getNodeData().isHasTaxonomy() ) { + System.out.println( n17.toString() ); return false; } } @@ -4629,37 +6146,30 @@ 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 ); + .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n8.getName().equals( "n8_ECOLI/12" ) ) { return false; } - if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) { + 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 ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) { return false; } - if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) { + 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 ); + .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) { return false; } @@ -4667,7 +6177,7 @@ public final class Test { return false; } final PhylogenyNode n20x = PhylogenyNode - .createInstanceFromNhxString( "n20_ECOL1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + .createInstanceFromNhxString( "n20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) { return false; } @@ -4675,7 +6185,7 @@ public final class Test { return false; } final PhylogenyNode n20xx = PhylogenyNode - .createInstanceFromNhxString( "n20_eCOL1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) { return false; } @@ -4683,7 +6193,7 @@ public final class Test { 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; } @@ -4691,7 +6201,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; } @@ -4699,7 +6209,7 @@ public final class Test { return false; } final PhylogenyNode n21 = PhylogenyNode - .createInstanceFromNhxString( "n21_PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); if ( !n21.getName().equals( "n21_PIG" ) ) { return false; } @@ -4707,7 +6217,7 @@ public final class Test { 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; } @@ -4715,7 +6225,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; } @@ -4723,92 +6233,103 @@ 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; } if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) { return false; } - if ( NHXParser.LIMIT_SPECIES_NAMES_TO_FIVE_CHARS ) { - final PhylogenyNode a = PhylogenyNode - .createInstanceFromNhxString( "n10_ECOLI/1-2", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !a.getName().equals( "n10_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( "" ) ) { - 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( "" ) ) { - 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" ) ) { - 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 a = PhylogenyNode + .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) { + return false; + } + final PhylogenyNode b = PhylogenyNode + .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + 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", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + 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", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) { + return false; + } + if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) { + return false; + } + final PhylogenyNode c2 = PhylogenyNode + .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( c2 ).equals( "" ) ) { + return false; + } + final PhylogenyNode d = PhylogenyNode + .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + 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", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !e.getName().equals( "n10_RAT1" ) ) { + return false; + } + if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) { + return false; + } + final PhylogenyNode e2 = PhylogenyNode + .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !e2.getName().equals( "n10_RAT1" ) ) { + return false; + } + if ( PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) { + return false; + } + final PhylogenyNode e3 = PhylogenyNode + .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !e3.getName().equals( "n10_RAT~" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) { + return false; } final PhylogenyNode n11 = PhylogenyNode .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) { return false; } if ( n11.getDistanceToParent() != 0.4 ) { return false; } - if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) { + if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) { return false; } final PhylogenyNode n12 = PhylogenyNode .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) { return false; } @@ -4818,30 +6339,20 @@ public final class Test { if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) { 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" ) ) { + final PhylogenyNode m = PhylogenyNode + .createInstanceFromNhxString( "n10_MOUSEa", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !m.getName().equals( "n10_MOUSEa" ) ) { return false; } - if ( !tvu3.getRef().equals( "tag3" ) ) { + if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) { return false; } - if ( !tvu3.getDataType().equals( "xsd:string" ) ) { + final PhylogenyNode o = PhylogenyNode + .createInstanceFromNhxString( "n10_MOUSE_", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ); + if ( !o.getName().equals( "n10_MOUSE_" ) ) { return false; } - if ( !tvu3.getUnit().equals( "unit3" ) ) { - return false; - } - if ( !tvu3.getValue().equals( "value3" ) ) { + if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) { return false; } if ( n1.getName().compareTo( "" ) != 0 ) { @@ -4863,60 +6374,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.AGRESSIVE ); if ( !n13.getName().equals( "blah_12345/1-2" ) ) { return false; } - if ( !PhylogenyMethods.getSpecies( n13 ).equals( "" ) ) { + 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( "blah_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + if ( !n14.getName().equals( "blah_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; } @@ -4928,7 +6421,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; } @@ -4940,7 +6433,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; } @@ -4948,7 +6441,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; } @@ -4958,6 +6451,34 @@ 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; + } } catch ( final Exception e ) { e.printStackTrace( System.out ); @@ -5757,51 +7278,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; } } @@ -6007,7 +7528,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; } @@ -6019,7 +7540,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; } @@ -6049,7 +7570,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; } @@ -6067,7 +7588,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; } @@ -6094,7 +7615,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; } @@ -6127,7 +7648,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; } @@ -6174,7 +7695,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; } @@ -6205,7 +7726,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; } @@ -7493,365 +9014,10 @@ public final class Test { return true; } - private static boolean testTaxonomyAssigner() { - try { - String s0_str = "(((([&&NHX:S=A],[&&NHX:S=B])[&&NHX:S=AB],[&&NHX:S=C])[&&NHX:S=ABC],[&&NHX:S=D])[&&NHX:S=ABCD],[&&NHX:S=E])[&&NHX:S=ABCDE]"; - String g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A])a,[&&NHX:S=B])b,[&&NHX:S=C])c"; - Phylogeny s0 = ParserBasedPhylogenyFactory.getInstance().create( s0_str, new NHXParser() )[ 0 ]; - Phylogeny g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - s0.setRooted( true ); - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A])a,[&&NHX:S=A])b,[&&NHX:S=A])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=B])a,[&&NHX:S=A])b,[&&NHX:S=A])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=B])a,[&&NHX:S=C])b,[&&NHX:S=A])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=B])a,[&&NHX:S=C])b,[&&NHX:S=D])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=E])a,[&&NHX:S=C])b,[&&NHX:S=D])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=E])a,[&&NHX:S=A])b,[&&NHX:S=A])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - s0_str = "(([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=C],[&&NHX:S=D])[&&NHX:S=ABCD]," - + "([&&NHX:S=E],[&&NHX:S=F],[&&NHX:S=G],[&&NHX:S=H])[&&NHX:S=EFGH]," - + "([&&NHX:S=I],[&&NHX:S=J],[&&NHX:S=K],[&&NHX:S=L])[&&NHX:S=IJKL], " - + "([&&NHX:S=M],[&&NHX:S=N],[&&NHX:S=O],[&&NHX:S=P])[&&NHX:S=MNOP])[&&NHX:S=ROOT]"; - s0 = ParserBasedPhylogenyFactory.getInstance().create( s0_str, new NHXParser() )[ 0 ]; - s0.setRooted( true ); - g0_str = "(([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=E],[&&NHX:S=F],[&&NHX:S=G],[&&NHX:S=H])b," - + "([&&NHX:S=I],[&&NHX:S=J],[&&NHX:S=K],[&&NHX:S=L])c, " - + "([&&NHX:S=M],[&&NHX:S=N],[&&NHX:S=O],[&&NHX:S=P])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "EFGH" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "IJKL" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "MNOP" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=A],[&&NHX:S=B])a," - + "([&&NHX:S=E],[&&NHX:S=F],[&&NHX:S=F],[&&NHX:S=F])b," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=I])c, " - + "([&&NHX:S=M],[&&NHX:S=N],[&&NHX:S=O],[&&NHX:S=O])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "EFGH" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "IJKL" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "MNOP" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=A],[&&NHX:S=B])a," - + "([&&NHX:S=E],[&&NHX:S=F],[&&NHX:S=F],[&&NHX:S=F])b," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])c, " - + "([&&NHX:S=M],[&&NHX:S=N],[&&NHX:S=A],[&&NHX:S=O])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "EFGH" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])a," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])b," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])c, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A])a,[&&NHX:S=A])b,[&&NHX:S=A])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=B])a,[&&NHX:S=I])b,[&&NHX:S=J])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(((([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=D],[&&NHX:S=C],[&&NHX:S=B],[&&NHX:S=A])b)ab," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])c)abc, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=D],[&&NHX:S=D],[&&NHX:S=B],[&&NHX:S=A])b)ab," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])c)abc, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=D],[&&NHX:S=D],[&&NHX:S=B],[&&NHX:S=A])b)ab," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])c)abc, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=A])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=D],[&&NHX:S=D],[&&NHX:S=B],[&&NHX:S=A])b)ab," - + "([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A])c)abc, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=A])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - s0_str = "(([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=C],[&&NHX:S=D])," - + "([&&NHX:S=E],[&&NHX:S=F],[&&NHX:S=G],[&&NHX:S=H])," - + "([&&NHX:S=I],[&&NHX:S=J],[&&NHX:S=K],[&&NHX:S=L]), " - + "([&&NHX:S=M],[&&NHX:S=N],[&&NHX:S=O],[&&NHX:S=P]))"; - s0 = ParserBasedPhylogenyFactory.getInstance().create( s0_str, new NHXParser() )[ 0 ]; - s0.setRooted( true ); - g0_str = "(((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=D],[&&NHX:S=D],[&&NHX:S=B],[&&NHX:S=A])b)ab," - + "([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A])c)abc, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=A])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( g0.getNode( "a" ).getNodeData().isHasTaxonomy() ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - } - catch ( final Exception e ) { - e.printStackTrace( System.out ); - return false; - } - return true; - } - private static boolean testUniprotTaxonomySearch() { try { - List results = UniProtWsTools - .getTaxonomiesFromCommonNameStrict( "starlet sea anemone", 10 ); + List results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone", + 10 ); if ( results.size() != 1 ) { return false; } @@ -7871,7 +9037,7 @@ public final class Test { return false; } results = null; - results = UniProtWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 ); + results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 ); if ( results.size() != 1 ) { return false; } @@ -7891,7 +9057,7 @@ public final class Test { return false; } results = null; - results = UniProtWsTools.getTaxonomiesFromId( "45351", 10 ); + results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 ); if ( results.size() != 1 ) { return false; } @@ -7911,7 +9077,7 @@ public final class Test { return false; } results = null; - results = UniProtWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 ); + results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 ); if ( results.size() != 1 ) { return false; } @@ -7959,90 +9125,90 @@ public final class Test { //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals //Protein: 3 letters + 5 numerals //http://www.ncbi.nlm.nih.gov/Sequin/acc.html - if ( !DatabaseTools.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) { return false; } - if ( !DatabaseTools.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "AAY423861" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "AY4238612" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "AAY4238612" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "Y423861" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) { return false; } - if ( !DatabaseTools.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) { return false; } - if ( !DatabaseTools.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "|S123456" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "ABC123456" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) { return false; } - if ( !DatabaseTools.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) { return false; } - if ( !DatabaseTools.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "ABCD12345" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) { return false; } return true; } private static boolean testUniprotEntryRetrieval() { - if ( !UniProtWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "EP12345" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "P12345E" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "P123455" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "EP12345E" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "AY423861" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) { return false; } - if ( !UniProtWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) { return false; } - if ( !UniProtWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) { return false; } - if ( !UniProtWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) { return false; } - if ( !UniProtWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) { return false; } - if ( !UniProtWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) { return false; } try { - final SequenceDatabaseEntry entry = UniProtWsTools.obtainUniProtEntry( "P12345", 200 ); + final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 ); if ( !entry.getAccession().equals( "P12345" ) ) { return false; } @@ -8305,7 +9471,7 @@ public final class Test { return true; } - private static boolean testMafft() { + private static boolean testMafft( final String path ) { try { final List opts = new ArrayList(); opts.add( "--maxiterate" ); @@ -8313,7 +9479,7 @@ public final class Test { opts.add( "--localpair" ); opts.add( "--quiet" ); Msa msa = null; - final MsaInferrer mafft = Mafft.createInstance(); + final MsaInferrer mafft = Mafft.createInstance( path ); msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts ); if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) { return false; @@ -8893,9 +10059,9 @@ public final class Test { private static boolean testMsaQualityMethod() { try { final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" ); - final Sequence s1 = BasicSequence.createAaSequence( "a", "ABBXEFGHIJ" ); - final Sequence s2 = BasicSequence.createAaSequence( "a", "AXCXEFGHIJ" ); - final Sequence s3 = BasicSequence.createAaSequence( "a", "AXDDEFGHIJ" ); + final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" ); + final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" ); + final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" ); final List l = new ArrayList(); l.add( s0 ); l.add( s1 ); @@ -8921,13 +10087,126 @@ public final class Test { } return true; } - + private static boolean testSequenceIdParsing() { try { - Identifier id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" ); - if ( id == null || ForesterUtil.isEmpty( id.getValue() ) || !id.getValue().equals( "002434188_1" ) ) { + Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + return false; + } + // + id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + return false; + } + // + id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + return false; + } + // + id = SequenceIdParser.parse( "gb_AAA96518_1" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + return false; + } + // + id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + return false; + } + // + id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + return false; + } + // + id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + return false; + } + // + id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + return false; + } + // + id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" ); + if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() ) + || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) { + if ( id != null ) { + System.out.println( "value =" + id.getValue() ); + System.out.println( "provider=" + id.getProvider() ); + } + 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_ } catch ( final Exception e ) { e.printStackTrace( System.out );