X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Ftest%2FTest.java;h=66f883e9e3de2d81f5a392883b45e60b7dbc5122;hb=1a6e8795d5cd4c9b137069cc47121689b83377ed;hp=637d05cdd5bb4c6211e123125aac1928e633c923;hpb=ebaa3f63d0dc201b9b5a5cd91e2cfa3c7157f143;p=jalview.git diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 637d05c..66f883e 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -38,6 +38,7 @@ import java.util.Locale; import java.util.Set; import org.forester.application.support_transfer; +import org.forester.datastructures.IntMatrix; import org.forester.development.DevelopmentTools; import org.forester.evoinference.TestPhylogenyReconstruction; import org.forester.evoinference.matrix.character.CharacterStateMatrix; @@ -54,14 +55,17 @@ import org.forester.io.parsers.nhx.NHXParser; import org.forester.io.parsers.phyloxml.PhyloXmlParser; import org.forester.io.parsers.tol.TolParser; import org.forester.io.writers.PhylogenyWriter; +import org.forester.msa.BasicMsa; import org.forester.msa.Mafft; import org.forester.msa.Msa; import org.forester.msa.MsaInferrer; +import org.forester.msa.MsaMethods; import org.forester.pccx.TestPccx; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyBranch; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; +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; @@ -70,6 +74,7 @@ import org.forester.phylogeny.data.DomainArchitecture; import org.forester.phylogeny.data.Event; import org.forester.phylogeny.data.Identifier; import org.forester.phylogeny.data.PhylogenyData; +import org.forester.phylogeny.data.PhylogenyDataUtil; import org.forester.phylogeny.data.Polygon; import org.forester.phylogeny.data.PropertiesMap; import org.forester.phylogeny.data.Property; @@ -79,14 +84,15 @@ import org.forester.phylogeny.data.Taxonomy; 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.sdi.GSDI; +import org.forester.sdi.RIO; 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; -import org.forester.surfacing.Protein; import org.forester.surfacing.TestSurfacing; import org.forester.tools.ConfidenceAssessor; import org.forester.tools.SupportCount; @@ -99,10 +105,10 @@ import org.forester.util.DescriptiveStatistics; import org.forester.util.ForesterConstants; import org.forester.util.ForesterUtil; import org.forester.util.GeneralTable; -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.util.SequenceIdParser; +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; @@ -133,7 +139,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 ) { @@ -167,6 +173,16 @@ public final class Test { System.exit( -1 ); } final long start_time = new Date().getTime(); + System.out.print( "Sequence id parsing: " ); + 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: " ); if ( testHmmscanOutputParser() ) { System.out.println( "OK." ); @@ -230,6 +246,15 @@ public final class Test { System.out.println( "failed." ); failed++; } + System.out.print( "NHX parsing (MrBayes): " ); + if ( Test.testNHXParsingMB() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } System.out.print( "Nexus characters parsing: " ); if ( Test.testNexusCharactersParsing() ) { System.out.println( "OK." ); @@ -455,8 +480,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "Calculation of distance between nodes: " ); - if ( Test.testGetDistance() ) { + System.out.print( "Finding of LCA 2: " ); + if ( Test.testGetLCA2() ) { System.out.println( "OK." ); succeeded++; } @@ -464,8 +489,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "SDIse: " ); - if ( Test.testSDIse() ) { + System.out.print( "Calculation of distance between nodes: " ); + if ( Test.testGetDistance() ) { System.out.println( "OK." ); succeeded++; } @@ -473,8 +498,8 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "Taxonomy assigner: " ); - if ( Test.testTaxonomyAssigner() ) { + System.out.print( "SDIse: " ); + if ( Test.testSDIse() ) { System.out.println( "OK." ); succeeded++; } @@ -500,6 +525,15 @@ public final class Test { System.out.println( "failed." ); failed++; } + System.out.print( "Ortholog table: " ); + if ( Test.testOrthologTable() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } System.out.print( "Descriptive statistics: " ); if ( Test.testDescriptiveStatistics() ) { System.out.println( "OK." ); @@ -674,9 +708,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++; } @@ -684,6 +736,25 @@ 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." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.print( "Simple MSA quality: " ); + if ( Test.testMsaQualityMethod() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } // System.out.print( "WABI TxSearch: " ); // if ( Test.testWabiTxSearch() ) { // System.out.println( "OK." ); @@ -785,11 +856,11 @@ public final class Test { } final PhylogenyNode n1 = new PhylogenyNode(); final PhylogenyNode n2 = PhylogenyNode - .createInstanceFromNhxString( "", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); final PhylogenyNode n3 = PhylogenyNode - .createInstanceFromNhxString( "n3", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); final PhylogenyNode n4 = PhylogenyNode - .createInstanceFromNhxString( "n4:0.01", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( n1.isHasAssignedEvent() ) { return false; } @@ -914,67 +985,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; } @@ -988,114 +1059,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 ); @@ -1201,67 +1164,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; } @@ -1683,6 +1646,7 @@ public final class Test { final List> tl = BasicTableParser.parse( source2.toString(), ";", false, + false, "comment:", false ); if ( tl.size() != 2 ) { @@ -1883,26 +1847,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; @@ -1987,7 +1931,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; } @@ -2102,7 +2045,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 ) ) { @@ -2830,7 +2773,7 @@ public final class Test { dss3.addValue( 10 ); final AsciiHistogram histo = new AsciiHistogram( dss3 ); histo.toStringBuffer( 10, '=', 40, 5 ); - histo.toStringBuffer( 3, 8, 10, '=', 40, 5 ); + histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null ); } catch ( final Exception e ) { e.printStackTrace( System.out ); @@ -3180,200 +3123,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; } @@ -3385,159 +3327,458 @@ 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 domain_collections = parser2.parse(); - if ( parser2.getProteinsEncountered() != 4 ) { + 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 ]; + PhylogenyMethods.preOrderReId( p1 ); + final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "A" ) ); + if ( !A.getName().equals( "A" ) ) { return false; } - if ( domain_collections.size() != 4 ) { + final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ), + p1.getNode( "gh" ) ); + if ( !gh.getName().equals( "gh" ) ) { return false; } - if ( parser2.getDomainsEncountered() != 69 ) { + final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "B" ) ); + if ( !ab.getName().equals( "ab" ) ) { return false; } - if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) { + final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ), + p1.getNode( "A" ) ); + if ( !ab2.getName().equals( "ab" ) ) { return false; } - if ( parser2.getDomainsIgnoredDueToEval() != 0 ) { + final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ), + p1.getNode( "G" ) ); + if ( !gh2.getName().equals( "gh" ) ) { return false; } - final Protein p1 = domain_collections.get( 0 ); - if ( p1.getNumberOfProteinDomains() != 15 ) { + final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ), + p1.getNode( "H" ) ); + if ( !gh3.getName().equals( "gh" ) ) { return false; } - final Protein p4 = domain_collections.get( 3 ); - if ( p4.getNumberOfProteinDomains() != 1 ) { + final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ), + p1.getNode( "A" ) ); + if ( !abc.getName().equals( "abc" ) ) { return false; } - if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) { + final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "C" ) ); + if ( !abc2.getName().equals( "abc" ) ) { return false; } - if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) { + final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "D" ) ); + if ( !abcd.getName().equals( "abcd" ) ) { return false; } - if ( p4.getProteinDomain( 0 ).getTo() != 395 ) { + final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ), + p1.getNode( "A" ) ); + if ( !abcd2.getName().equals( "abcd" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) { + final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "F" ) ); + if ( !abcdef.getName().equals( "abcdef" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) { + final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ), + p1.getNode( "A" ) ); + if ( !abcdef2.getName().equals( "abcdef" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) { + final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ), + p1.getNode( "F" ) ); + if ( !abcdef3.getName().equals( "abcdef" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) { + final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ), + p1.getNode( "ab" ) ); + if ( !abcdef4.getName().equals( "abcdef" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) { + final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "E" ) ); + if ( !abcde.getName().equals( "abcde" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) { + final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ), + p1.getNode( "A" ) ); + if ( !abcde2.getName().equals( "abcde" ) ) { return false; } - } - catch ( final Exception e ) { - e.printStackTrace( System.out ); - return false; - } - return true; - } - - private static boolean testLastExternalNodeMethods() { - try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', }; - final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ]; - final PhylogenyNode n1 = t0.getNode( "A" ); - if ( n1.isLastExternalNode() ) { + final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ), + p1.getNode( "abcdefgh" ) ); + if ( !r.getName().equals( "abcdefgh" ) ) { return false; } - final PhylogenyNode n2 = t0.getNode( "B" ); - if ( n2.isLastExternalNode() ) { + final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "H" ) ); + if ( !r2.getName().equals( "abcdefgh" ) ) { return false; } - final PhylogenyNode n3 = t0.getNode( "C" ); - if ( n3.isLastExternalNode() ) { + final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ), + p1.getNode( "A" ) ); + if ( !r3.getName().equals( "abcdefgh" ) ) { return false; } - final PhylogenyNode n4 = t0.getNode( "D" ); - if ( !n4.isLastExternalNode() ) { + final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ), + p1.getNode( "abcde" ) ); + if ( !abcde3.getName().equals( "abcde" ) ) { return false; } - } - catch ( final Exception e ) { - e.printStackTrace( System.out ); - return false; - } - return true; - } - - private static boolean testLevelOrderIterator() { - try { - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ]; - PhylogenyNodeIterator it0; - for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) { - it0.next(); - } - for( it0.reset(); it0.hasNext(); ) { - it0.next(); - } - final PhylogenyNodeIterator it = t0.iteratorLevelOrder(); - if ( !it.next().getName().equals( "r" ) ) { + final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ), + p1.getNode( "E" ) ); + if ( !abcde4.getName().equals( "abcde" ) ) { return false; } - if ( !it.next().getName().equals( "ab" ) ) { + final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ), + p1.getNode( "B" ) ); + if ( !ab3.getName().equals( "ab" ) ) { return false; } - if ( !it.next().getName().equals( "cd" ) ) { + final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ), + p1.getNode( "ab" ) ); + if ( !ab4.getName().equals( "ab" ) ) { return false; } - if ( !it.next().getName().equals( "A" ) ) { + 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; } - if ( !it.next().getName().equals( "B" ) ) { + final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ), + p2.getNode( "c" ) ); + if ( !cd2.getName().equals( "cd" ) ) { return false; } - if ( !it.next().getName().equals( "C" ) ) { + final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ), + p2.getNode( "e" ) ); + if ( !cde.getName().equals( "cde" ) ) { return false; } - if ( !it.next().getName().equals( "D" ) ) { + final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ), + p2.getNode( "c" ) ); + if ( !cde2.getName().equals( "cde" ) ) { return false; } - if ( it.hasNext() ) { + final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ), + p2.getNode( "f" ) ); + if ( !cdef.getName().equals( "cdef" ) ) { return false; } - final Phylogeny t2 = factory.create( "(((1,2,(a,(X,Y,Z)b)3,4,5,6)A,B,C)abc,(D,E,(f1,(f21)f2,f3)F,G)defg)r", - new NHXParser() )[ 0 ]; - PhylogenyNodeIterator it2; - for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) { - it2.next(); - } - for( it2.reset(); it2.hasNext(); ) { - it2.next(); - } - final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder(); - if ( !it3.next().getName().equals( "r" ) ) { + final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ), + p2.getNode( "f" ) ); + if ( !cdef2.getName().equals( "cdef" ) ) { return false; } - if ( !it3.next().getName().equals( "abc" ) ) { + final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ), + p2.getNode( "d" ) ); + if ( !cdef3.getName().equals( "cdef" ) ) { return false; } - if ( !it3.next().getName().equals( "defg" ) ) { + final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ), + p2.getNode( "a" ) ); + if ( !rt.getName().equals( "r" ) ) { return false; } - if ( !it3.next().getName().equals( "A" ) ) { - return false; + final Phylogeny p3 = factory + .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)", + new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p3 ); + final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ), + p3.getNode( "c" ) ); + if ( !bc_3.getName().equals( "bc" ) ) { + return false; + } + final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ), + p3.getNode( "c" ) ); + if ( !ac_3.getName().equals( "abc" ) ) { + return false; + } + final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ), + p3.getNode( "d" ) ); + if ( !ad_3.getName().equals( "abcde" ) ) { + return false; + } + final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ), + p3.getNode( "f" ) ); + if ( !af_3.getName().equals( "abcdef" ) ) { + return false; + } + final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ), + p3.getNode( "g" ) ); + if ( !ag_3.getName().equals( "" ) ) { + return false; + } + if ( !ag_3.isRoot() ) { + return false; + } + final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ), + p3.getNode( "l" ) ); + if ( !al_3.getName().equals( "" ) ) { + return false; + } + if ( !al_3.isRoot() ) { + return false; + } + final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ), + p3.getNode( "l" ) ); + if ( !kl_3.getName().equals( "" ) ) { + return false; + } + if ( !kl_3.isRoot() ) { + return false; + } + final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ), + p3.getNode( "l" ) ); + if ( !fl_3.getName().equals( "" ) ) { + return false; + } + if ( !fl_3.isRoot() ) { + return false; + } + final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ), + p3.getNode( "k" ) ); + if ( !gk_3.getName().equals( "ghijk" ) ) { + return false; + } + final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p4 ); + final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ), + p4.getNode( "c" ) ); + if ( !r_4.getName().equals( "r" ) ) { + return false; + } + final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p5 ); + final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ), + p5.getNode( "c" ) ); + if ( !r_5.getName().equals( "root" ) ) { + return false; + } + final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p6 ); + final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ), + p6.getNode( "a" ) ); + if ( !r_6.getName().equals( "rot" ) ) { + return false; + } + final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ]; + PhylogenyMethods.preOrderReId( p7 ); + final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ), + p7.getNode( "e" ) ); + if ( !r_7.getName().equals( "rott" ) ) { + return false; + } + final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ), + p7.getNode( "a" ) ); + if ( !r_71.getName().equals( "rott" ) ) { + return false; + } + final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ), + p7.getNode( "rott" ) ); + if ( !r_72.getName().equals( "rott" ) ) { + return false; + } + final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ), + p7.getNode( "a" ) ); + if ( !r_73.getName().equals( "rott" ) ) { + return false; + } + final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ), + p7.getNode( "rott" ) ); + if ( !r_74.getName().equals( "rott" ) ) { + return false; + } + final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ), + p7.getNode( "e" ) ); + if ( !r_75.getName().equals( "e" ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testHmmscanOutputParser() { + final String test_dir = Test.PATH_TO_TEST_DATA; + try { + final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir + + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE ); + parser1.parse(); + final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir + + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE ); + final List proteins = parser2.parse(); + if ( parser2.getProteinsEncountered() != 4 ) { + return false; + } + if ( proteins.size() != 4 ) { + return false; + } + if ( parser2.getDomainsEncountered() != 69 ) { + return false; + } + if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) { + return false; + } + if ( parser2.getDomainsIgnoredDueToEval() != 0 ) { + return false; + } + final Protein p1 = proteins.get( 0 ); + if ( p1.getNumberOfProteinDomains() != 15 ) { + return false; + } + if ( p1.getLength() != 850 ) { + return false; + } + final Protein p2 = proteins.get( 1 ); + if ( p2.getNumberOfProteinDomains() != 51 ) { + return false; + } + if ( p2.getLength() != 1291 ) { + return false; + } + final Protein p3 = proteins.get( 2 ); + if ( p3.getNumberOfProteinDomains() != 2 ) { + return false; + } + final Protein p4 = proteins.get( 3 ); + if ( p4.getNumberOfProteinDomains() != 1 ) { + return false; + } + if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) { + return false; + } + if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) { + return false; + } + if ( p4.getProteinDomain( 0 ).getTo() != 395 ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) { + return false; + } + if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testLastExternalNodeMethods() { + try { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', }; + final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ]; + final PhylogenyNode n1 = t0.getNode( "A" ); + if ( n1.isLastExternalNode() ) { + return false; + } + final PhylogenyNode n2 = t0.getNode( "B" ); + if ( n2.isLastExternalNode() ) { + return false; + } + final PhylogenyNode n3 = t0.getNode( "C" ); + if ( n3.isLastExternalNode() ) { + return false; + } + final PhylogenyNode n4 = t0.getNode( "D" ); + if ( !n4.isLastExternalNode() ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testLevelOrderIterator() { + try { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ]; + PhylogenyNodeIterator it0; + for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) { + it0.next(); + } + for( it0.reset(); it0.hasNext(); ) { + it0.next(); + } + final PhylogenyNodeIterator it = t0.iteratorLevelOrder(); + if ( !it.next().getName().equals( "r" ) ) { + return false; + } + if ( !it.next().getName().equals( "ab" ) ) { + return false; + } + if ( !it.next().getName().equals( "cd" ) ) { + return false; + } + if ( !it.next().getName().equals( "A" ) ) { + return false; + } + if ( !it.next().getName().equals( "B" ) ) { + return false; + } + if ( !it.next().getName().equals( "C" ) ) { + return false; + } + if ( !it.next().getName().equals( "D" ) ) { + return false; + } + if ( it.hasNext() ) { + return false; + } + final Phylogeny t2 = factory.create( "(((1,2,(a,(X,Y,Z)b)3,4,5,6)A,B,C)abc,(D,E,(f1,(f21)f2,f3)F,G)defg)r", + new NHXParser() )[ 0 ]; + PhylogenyNodeIterator it2; + for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) { + it2.next(); + } + for( it2.reset(); it2.hasNext(); ) { + it2.next(); + } + final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder(); + if ( !it3.next().getName().equals( "r" ) ) { + return false; + } + if ( !it3.next().getName().equals( "abc" ) ) { + return false; + } + if ( !it3.next().getName().equals( "defg" ) ) { + return false; + } + if ( !it3.next().getName().equals( "A" ) ) { + return false; } if ( !it3.next().getName().equals( "B" ) ) { return false; @@ -4200,7 +4441,7 @@ public final class Test { return false; } final NHXParser nhxp = new NHXParser(); - nhxp.setTaxonomyExtraction( ForesterUtil.TAXONOMY_EXTRACTION.NO ); + 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 " ) ) { @@ -4426,42 +4667,93 @@ public final class Test { if ( ( p46.length != 1 ) || !p46[ 0 ].isEmpty() ) { return false; } - } - catch ( final Exception e ) { - e.printStackTrace( System.out ); - return false; - } - return true; - } - - private static boolean testNHXconversion() { - try { - final PhylogenyNode n1 = new PhylogenyNode(); - final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" ); - 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]" ); - 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]" ); - if ( !n1.toNewHampshireX().equals( "" ) ) { + final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ]; + if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { return false; } - if ( !n2.toNewHampshireX().equals( "" ) ) { + final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { return false; } - if ( !n3.toNewHampshireX().equals( "n3" ) ) { + final Phylogeny p49 = factory + .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ), + new NHXParser() )[ 0 ]; + if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { return false; } - if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) { + 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; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testNHXconversion() { + try { + final PhylogenyNode n1 = new PhylogenyNode(); + final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" ); + 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]" ); + 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]" ); + if ( !n1.toNewHampshireX().equals( "" ) ) { + return false; + } + if ( !n2.toNewHampshireX().equals( "" ) ) { + return false; + } + if ( !n3.toNewHampshireX().equals( "n3" ) ) { + return false; + } + 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.0:W=2.0:C=10.20.30]" ) ) { + .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]" ) ) { return false; } - if ( !n6.toNewHampshireX() - .equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:XN=B=bool_tag=T:B=100.0:W=2.0:C=0.0.0]" ) ) { + 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]" ) ) { return false; } } @@ -4483,7 +4775,7 @@ public final class Test { if ( !n3.getName().equals( "n3" ) ) { return false; } - if ( n3.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) { + if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) { return false; } if ( n3.isDuplication() ) { @@ -4526,7 +4818,7 @@ public final class Test { return false; } final PhylogenyNode n8 = PhylogenyNode - .createInstanceFromNhxString( "n8_ECOLI/12:0.01", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n8.getName().equals( "n8_ECOLI/12" ) ) { return false; } @@ -4534,8 +4826,7 @@ public final class Test { return false; } final PhylogenyNode n9 = PhylogenyNode - .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01", - ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) { return false; } @@ -4543,12 +4834,12 @@ public final class Test { return false; } final PhylogenyNode n10 = PhylogenyNode - .createInstanceFromNhxString( "n10.ECOLI", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n10.getName().equals( "n10.ECOLI" ) ) { return false; } final PhylogenyNode n20 = PhylogenyNode - .createInstanceFromNhxString( "n20_ECOLI/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) { return false; } @@ -4556,7 +4847,7 @@ public final class Test { return false; } final PhylogenyNode n20x = PhylogenyNode.createInstanceFromNhxString( "n20_ECOL1/1-2", - ForesterUtil.TAXONOMY_EXTRACTION.YES ); + NHXParser.TAXONOMY_EXTRACTION.YES ); if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) { return false; } @@ -4564,7 +4855,7 @@ public final class Test { return false; } final PhylogenyNode n20xx = PhylogenyNode - .createInstanceFromNhxString( "n20_eCOL1/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) { return false; } @@ -4572,7 +4863,7 @@ public final class Test { return false; } final PhylogenyNode n20xxx = PhylogenyNode - .createInstanceFromNhxString( "n20_ecoli/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) { return false; } @@ -4580,7 +4871,7 @@ public final class Test { return false; } final PhylogenyNode n20xxxx = PhylogenyNode - .createInstanceFromNhxString( "n20_Ecoli/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) { return false; } @@ -4588,7 +4879,7 @@ public final class Test { return false; } final PhylogenyNode n21 = PhylogenyNode.createInstanceFromNhxString( "n21_PIG", - ForesterUtil.TAXONOMY_EXTRACTION.YES ); + NHXParser.TAXONOMY_EXTRACTION.YES ); if ( !n21.getName().equals( "n21_PIG" ) ) { return false; } @@ -4596,7 +4887,7 @@ public final class Test { return false; } final PhylogenyNode n21x = PhylogenyNode - .createInstanceFromNhxString( "n21_PIG", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n21x.getName().equals( "n21_PIG" ) ) { return false; } @@ -4604,7 +4895,7 @@ public final class Test { return false; } final PhylogenyNode n22 = PhylogenyNode - .createInstanceFromNhxString( "n22/PIG", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n22.getName().equals( "n22/PIG" ) ) { return false; } @@ -4612,60 +4903,91 @@ public final class Test { return false; } final PhylogenyNode n23 = PhylogenyNode - .createInstanceFromNhxString( "n23/PIG_1", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); 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", ForesterUtil.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", - ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) { - return false; - } - final PhylogenyNode c = PhylogenyNode - .createInstanceFromNhxString( "n10_RATAF12/1000-2000", - ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) { - return false; - } - final PhylogenyNode d = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT1/1-2", ForesterUtil.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", ForesterUtil.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_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", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) { + return false; + } + final PhylogenyNode c = PhylogenyNode + .createInstanceFromNhxString( "n10_RATAF12/1000-2000", + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) { + return false; + } + final PhylogenyNode c1 = PhylogenyNode + .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000", + NHXParser.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", + NHXParser.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", NHXParser.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", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !e.getName().equals( "n10_RAT1" ) ) { + return false; + } + if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) { + return false; + } + final PhylogenyNode e2 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT1", + NHXParser.TAXONOMY_EXTRACTION.YES ); + 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.YES ); + 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", - ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) { return false; } @@ -4677,7 +4999,7 @@ public final class Test { } final PhylogenyNode n12 = PhylogenyNode .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4", - ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) { return false; } @@ -4687,6 +5009,22 @@ public final class Test { if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) { return false; } + final PhylogenyNode m = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSEa", + NHXParser.TAXONOMY_EXTRACTION.YES ); + if ( !m.getName().equals( "n10_MOUSEa" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) { + return false; + } + final PhylogenyNode o = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSE_", + NHXParser.TAXONOMY_EXTRACTION.YES ); + if ( !o.getName().equals( "n10_MOUSE_" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) { + return false; + } final Property tvu1 = n5.getNodeData().getProperties().getProperty( "tag1" ); final Property tvu3 = n5.getNodeData().getProperties().getProperty( "tag3" ); if ( !tvu1.getRef().equals( "tag1" ) ) { @@ -4719,7 +5057,7 @@ public final class Test { if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) { return false; } - if ( n1.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) { + if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) { return false; } if ( n2.getName().compareTo( "" ) != 0 ) { @@ -4728,7 +5066,7 @@ public final class Test { if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) { return false; } - if ( n2.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) { + if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) { return false; } final PhylogenyNode n00 = PhylogenyNode @@ -4766,15 +5104,15 @@ public final class Test { return false; } final PhylogenyNode n13 = PhylogenyNode - .createInstanceFromNhxString( "blah_12345/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n13.getName().equals( "blah_12345/1-2" ) ) { return false; } - if ( !PhylogenyMethods.getSpecies( n13 ).equals( "" ) ) { + if ( !PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) { return false; } final PhylogenyNode n14 = PhylogenyNode - .createInstanceFromNhxString( "blah_12X45/1-2", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "blah_12X45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n14.getName().equals( "blah_12X45/1-2" ) ) { return false; } @@ -4783,7 +5121,7 @@ public final class Test { } final PhylogenyNode n15 = PhylogenyNode .createInstanceFromNhxString( "something_wicked[123]", - ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n15.getName().equals( "something_wicked" ) ) { return false; } @@ -4794,8 +5132,7 @@ public final class Test { return false; } final PhylogenyNode n16 = PhylogenyNode - .createInstanceFromNhxString( "something_wicked2[9]", - ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "something_wicked2[9]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n16.getName().equals( "something_wicked2" ) ) { return false; } @@ -4806,8 +5143,7 @@ public final class Test { return false; } final PhylogenyNode n17 = PhylogenyNode - .createInstanceFromNhxString( "something_wicked3[a]", - ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( "something_wicked3[a]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !n17.getName().equals( "something_wicked3" ) ) { return false; } @@ -4815,7 +5151,7 @@ public final class Test { return false; } final PhylogenyNode n18 = PhylogenyNode - .createInstanceFromNhxString( ":0.5[91]", ForesterUtil.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) { return false; } @@ -4845,7 +5181,7 @@ public final class Test { if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) { return false; } - final String p2b_S = "(((((((A:0.2[&NHX:S=qwerty]):0.2[&:S=uiop]):0.3[&NHX:S=asdf]):0.4[S=zxc]):0.5[]):0.6[&&NH:S=asd]):0.7[&&HX:S=za]):0.8[&&:S=zaq]"; + final String p2b_S = "(((((((A:0.2[&NHX:S=qw,erty]):0.2[&:S=u(io)p]):0.3[&NHX:S=asdf]):0.4[S=zxc]):0.5[]):0.6[&&NH:S=asd]):0.7[&&HX:S=za]):0.8[&&:S=zaq]"; final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() ); if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) { return false; @@ -4887,13 +5223,13 @@ public final class Test { return false; } final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ]; - if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91.0],C:0.1)root:0.1[&&NHX:B=100.0]" ) ) { + if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) { return false; } final Phylogeny p10 = factory .create( " [79] ( (A [co mment] :0 .2[comment],B:0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],C: 0.1)[comment]root:0.1[100] [comment]", new NHXParser() )[ 0 ]; - if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91.0],C:0.1)root:0.1[&&NHX:B=100.0]" ) ) { + if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) { return false; } } @@ -4968,7 +5304,7 @@ public final class Test { final Phylogeny p10 = factory .create( " [79] ( (\"A \n\tB \" [co mment] :0 .2[comment],'B':0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],'C (or D?\\//;,))': 0.1)[comment]'\nroot is here (cool, was! ) ':0.1[100] [comment]", new NHXParser() )[ 0 ]; - final String p10_clean_str = "(('A B':0.2,B:0.3):0.5[&&NHX:B=91.0],'C (or D?\\//;,))':0.1)'root is here (cool, was! )':0.1[&&NHX:B=100.0]"; + final String p10_clean_str = "(('A B':0.2,B:0.3):0.5[&&NHX:B=91],'C (or D?\\//;,))':0.1)'root is here (cool, was! )':0.1[&&NHX:B=100]"; if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) { return false; } @@ -4980,7 +5316,7 @@ public final class Test { final Phylogeny p12 = factory .create( " [79] ( (\"A \n\tB \" [[][] :0 .2[comment][\t&\t&\n N\tH\tX:S=mo\tnkey !],'\tB\t\b\t\n\f\rB B ':0.0\b3[])\t[com ment]: 0. 5 \t[ 9 1 ][ \ncomment],'C\t (or D?\\//;,))': 0.\b1)[comment]'\nroot \tis here (cool, \b\t\n\f\r was! ) ':0.1[100] [comment]", new NHXParser() )[ 0 ]; - final String p12_clean_str = "(('A B':0.2[&&NHX:S=monkey!],'BB B':0.03):0.5[&&NHX:B=91.0],'C (or D?\\//;,))':0.1)'root is here (cool, was! )':0.1[&&NHX:B=100.0]"; + final String p12_clean_str = "(('A B':0.2[&&NHX:S=monkey!],'BB B':0.03):0.5[&&NHX:B=91],'C (or D?\\//;,))':0.1)'root is here (cool, was! )':0.1[&&NHX:B=100]"; if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) { return false; } @@ -5004,6 +5340,60 @@ public final class Test { return true; } + private static boolean testNHXParsingMB() { + try { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00," + + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\"," + + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02," + + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02," + + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00," + + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\"," + + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02," + + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02," + + "7.369400000000000e-02}])", new NHXParser() )[ 0 ]; + if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) { + return false; + } + if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) { + return false; + } + if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(), + 0.1100000000000000e+00 ) ) { + return false; + } + if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) { + return false; + } + if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) { + return false; + } + final Phylogeny p2 = factory + .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00," + + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\"," + + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02," + + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02," + + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00," + + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\"," + + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02," + + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02," + + "7.369400000000000e-02}])", + new NHXParser() )[ 0 ]; + if ( p2.getNode( "1" ) == null ) { + return false; + } + if ( p2.getNode( "2" ) == null ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + System.exit( -1 ); + return false; + } + return true; + } + private static boolean testPhylogenyBranch() { try { final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" ); @@ -5575,46 +5965,46 @@ public final class Test { 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; } } @@ -6439,6 +6829,28 @@ public final class Test { return true; } + private static boolean testOrthologTable() { + try { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny s1 = factory.create( Test.PATH_TO_TEST_DATA + "rio_species.xml", new PhyloXmlParser() )[ 0 ]; + final NHXParser p = new NHXParser(); + p.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.YES ); + final Phylogeny g1[] = factory.create( new File( Test.PATH_TO_TEST_DATA + + "rio_Bcl-2_e1_20_mafft_05_40_fme.mlt" ), p ); + for( final Phylogeny gt : g1 ) { + gt.setRooted( true ); + final GSDI sdi = new GSDI( gt, s1, true, true, true ); + } + final IntMatrix m = RIO.calculateOrthologTable( g1 ); + // System.out.println( m.toString() ); + } + catch ( final Exception e ) { + e.printStackTrace(); + return false; + } + return true; + } + private static boolean testSplit() { try { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); @@ -7306,351 +7718,477 @@ public final class Test { return true; } - private static boolean testTaxonomyAssigner() { + private static boolean testUniprotTaxonomySearch() { 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" ) ) { + List results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone", + 10 ); + if ( results.size() != 1 ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { + if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { + if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) { 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" ) ) { + if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { + if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { + if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) { 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" ) ) { + results = null; + results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 ); + if ( results.size() != 1 ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { + if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { + if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) { 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" ) ) { + if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { + if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { + if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) { 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" ) ) { + results = null; + results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 ); + if ( results.size() != 1 ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { + if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { + if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) { 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" ) ) { + if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { + if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { + if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) { 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" ) ) { + results = null; + results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 ); + if ( results.size() != 1 ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { + if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { + if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) { 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" ) ) { + if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "EFGH" ) ) { + if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "IJKL" ) ) { + if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) { return false; } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "MNOP" ) ) { + if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) { return false; } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) { 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" ) ) { + if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 ) + .equals( "Nematostella vectensis" ) ) { + System.out.println( results.get( 0 ).getLineage() ); return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "EFGH" ) ) { + } + catch ( final IOException e ) { + System.out.println(); + System.out.println( "the following might be due to absence internet connection:" ); + e.printStackTrace( System.out ); + return true; + } + catch ( final Exception e ) { + return false; + } + return true; + } + + private static boolean testEmblEntryRetrieval() { + //The format for GenBank Accession numbers are: + //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 ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) { + return false; + } + if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) { + return false; + } + if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) { + return false; + } + if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) { + return false; + } + if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) { + return false; + } + if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) { + return false; + } + if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) { + return false; + } + if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) { + return false; + } + if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) { + return false; + } + if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) { + return false; + } + if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) { + return false; + } + if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) { + return false; + } + if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) { + return false; + } + return true; + } + + private static boolean testUniprotEntryRetrieval() { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) { + return false; + } + if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) { + return false; + } + if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) { + return false; + } + if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) { + return false; + } + if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) { + return false; + } + if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) { + return false; + } + if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) { + return false; + } + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) { + return false; + } + if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) { + return false; + } + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) { + return false; + } + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) { + return false; + } + if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) { + return false; + } + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) { + return false; + } + try { + final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 ); + if ( !entry.getAccession().equals( "P12345" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "IJKL" ) ) { + if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) { return false; } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "MNOP" ) ) { + if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) { return false; } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) { 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" ) ) { + if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) { + return false; + } + } + catch ( final IOException e ) { + System.out.println(); + System.out.println( "the following might be due to absence internet connection:" ); + e.printStackTrace( System.out ); + return true; + } + catch ( final Exception e ) { + return false; + } + return true; + } + + private static boolean testWabiTxSearch() { + try { + String result = ""; + result = TxSearch.searchSimple( "nematostella" ); + result = TxSearch.getTxId( "nematostella" ); + if ( !result.equals( "45350" ) ) { + return false; + } + result = TxSearch.getTxName( "45350" ); + if ( !result.equals( "Nematostella" ) ) { + return false; + } + result = TxSearch.getTxId( "nematostella vectensis" ); + if ( !result.equals( "45351" ) ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "EFGH" ) ) { + result = TxSearch.getTxName( "45351" ); + if ( !result.equals( "Nematostella vectensis" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { + result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" ); + if ( !result.equals( "536089" ) ) { return false; } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + result = TxSearch.getTxName( "536089" ); + if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) { return false; } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + final List queries = new ArrayList(); + queries.add( "Campylobacter coli" ); + queries.add( "Escherichia coli" ); + queries.add( "Arabidopsis" ); + queries.add( "Trichoplax" ); + queries.add( "Samanea saman" ); + queries.add( "Kluyveromyces marxianus" ); + queries.add( "Bacillus subtilis subsp. subtilis str. N170" ); + queries.add( "Bornavirus parrot/PDD/2008" ); + final List ranks = new ArrayList(); + ranks.add( RANKS.SUPERKINGDOM ); + ranks.add( RANKS.KINGDOM ); + ranks.add( RANKS.FAMILY ); + ranks.add( RANKS.GENUS ); + ranks.add( RANKS.TRIBE ); + result = TxSearch.searchLineage( queries, ranks ); + result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true ); + result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true ); + } + catch ( final Exception e ) { + System.out.println(); + System.out.println( "the following might be due to absence internet connection:" ); + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testAminoAcidSequence() { + try { + final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" ); + if ( aa1.getLength() != 13 ) { 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" ) ) { + if ( aa1.getResidueAt( 0 ) != 'A' ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { + if ( aa1.getResidueAt( 2 ) != 'K' ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { + if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) { return false; } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { + final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" ); + if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) { return false; } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { + final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" ); + if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) { 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" ) ) { + final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" ); + if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { + } + catch ( final Exception e ) { + e.printStackTrace(); + return false; + } + return true; + } + + private static boolean testCreateBalancedPhylogeny() { + try { + final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 ); + if ( p0.getRoot().getNumberOfDescendants() != 5 ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { + if ( p0.getNumberOfExternalNodes() != 15625 ) { 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" ) ) { + final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 ); + if ( p1.getRoot().getNumberOfDescendants() != 10 ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( p1.getNumberOfExternalNodes() != 100 ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + } + catch ( final Exception e ) { + e.printStackTrace(); + return false; + } + return true; + } + + private static boolean testFastaParser() { + try { + if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) { 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" ) ) { + if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { + final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ); + if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) { return false; } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { + if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { + if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) { return false; } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) { return false; } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { + if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) { return false; } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) { 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" ) ) { + } + catch ( final Exception e ) { + e.printStackTrace(); + return false; + } + return true; + } + + private static boolean testGeneralMsaParser() { + try { + final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n"; + final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) ); + final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n"; + final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) ); + final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n"; + final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) ); + final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n"; + final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) ); + if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { + if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) { return false; } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { + if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { + if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) { return false; } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) { return false; } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { + if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) { return false; } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) { 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" ) ) { + if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { + if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) { return false; } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { + if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { + if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) { return false; } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) { return false; } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) ); + if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) { return false; } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) { 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" ) ) { + if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) { return false; } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { + final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) ); + if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) { return false; } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { + if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) { return false; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { + if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) { return false; } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { + final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ); + if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) { return false; } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) { return false; } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { + if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) { 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() ) { + } + catch ( final Exception e ) { + e.printStackTrace(); + return false; + } + return true; + } + + private static boolean testMafft( final String path ) { + try { + final List opts = new ArrayList(); + opts.add( "--maxiterate" ); + opts.add( "1000" ); + opts.add( "--localpair" ); + opts.add( "--quiet" ); + Msa msa = null; + 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; } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { + if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) { return false; } } @@ -7661,438 +8199,718 @@ public final class Test { return true; } - private static boolean testUniprotTaxonomySearch() { + private static boolean testNextNodeWithCollapsing() { try { - List results = UniProtWsTools - .getTaxonomiesFromCommonNameStrict( "starlet sea anemone", 10 ); - if ( results.size() != 1 ) { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + PhylogenyNode n; + List ext = new ArrayList(); + final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" ); + final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ]; + t0.getNode( "cd" ).setCollapse( true ); + t0.getNode( "cde" ).setCollapse( true ); + n = t0.getFirstExternalNode(); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( !ext.get( 0 ).getName().equals( "a" ) ) { return false; } - if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) { + if ( !ext.get( 1 ).getName().equals( "b" ) ) { return false; } - if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) { + if ( !ext.get( 2 ).getName().equals( "cde" ) ) { return false; } - if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) { + if ( !ext.get( 3 ).getName().equals( "f" ) ) { return false; } - if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) { + if ( !ext.get( 4 ).getName().equals( "g" ) ) { return false; } - if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) { + if ( !ext.get( 5 ).getName().equals( "h" ) ) { return false; } - results = null; - results = UniProtWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 ); - if ( results.size() != 1 ) { + ext.clear(); + final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" ); + final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ]; + t1.getNode( "ab" ).setCollapse( true ); + t1.getNode( "cd" ).setCollapse( true ); + t1.getNode( "cde" ).setCollapse( true ); + n = t1.getNode( "ab" ); + ext = new ArrayList(); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( !ext.get( 0 ).getName().equals( "ab" ) ) { return false; } - if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) { + if ( !ext.get( 1 ).getName().equals( "cde" ) ) { return false; } - if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) { + if ( !ext.get( 2 ).getName().equals( "f" ) ) { return false; } - if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) { + if ( !ext.get( 3 ).getName().equals( "g" ) ) { return false; } - if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) { + if ( !ext.get( 4 ).getName().equals( "h" ) ) { return false; } - if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) { + // + // + ext.clear(); + final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" ); + final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ]; + t2.getNode( "ab" ).setCollapse( true ); + t2.getNode( "cd" ).setCollapse( true ); + t2.getNode( "cde" ).setCollapse( true ); + t2.getNode( "c" ).setCollapse( true ); + t2.getNode( "d" ).setCollapse( true ); + t2.getNode( "e" ).setCollapse( true ); + t2.getNode( "gh" ).setCollapse( true ); + n = t2.getNode( "ab" ); + ext = new ArrayList(); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( !ext.get( 0 ).getName().equals( "ab" ) ) { return false; } - results = null; - results = UniProtWsTools.getTaxonomiesFromId( "45351", 10 ); - if ( results.size() != 1 ) { + if ( !ext.get( 1 ).getName().equals( "cde" ) ) { return false; } - if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) { + if ( !ext.get( 2 ).getName().equals( "f" ) ) { return false; } - if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) { + if ( !ext.get( 3 ).getName().equals( "gh" ) ) { return false; } - if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) { + // + // + ext.clear(); + final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" ); + final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ]; + t3.getNode( "ab" ).setCollapse( true ); + t3.getNode( "cd" ).setCollapse( true ); + t3.getNode( "cde" ).setCollapse( true ); + t3.getNode( "c" ).setCollapse( true ); + t3.getNode( "d" ).setCollapse( true ); + t3.getNode( "e" ).setCollapse( true ); + t3.getNode( "gh" ).setCollapse( true ); + t3.getNode( "fgh" ).setCollapse( true ); + n = t3.getNode( "ab" ); + ext = new ArrayList(); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( !ext.get( 0 ).getName().equals( "ab" ) ) { return false; } - if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) { + if ( !ext.get( 1 ).getName().equals( "cde" ) ) { return false; } - if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) { + if ( !ext.get( 2 ).getName().equals( "fgh" ) ) { return false; } - results = null; - results = UniProtWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 ); - if ( results.size() != 1 ) { + // + // + ext.clear(); + final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" ); + final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ]; + t4.getNode( "ab" ).setCollapse( true ); + t4.getNode( "cd" ).setCollapse( true ); + t4.getNode( "cde" ).setCollapse( true ); + t4.getNode( "c" ).setCollapse( true ); + t4.getNode( "d" ).setCollapse( true ); + t4.getNode( "e" ).setCollapse( true ); + t4.getNode( "gh" ).setCollapse( true ); + t4.getNode( "fgh" ).setCollapse( true ); + t4.getNode( "abcdefgh" ).setCollapse( true ); + n = t4.getNode( "abcdefgh" ); + if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) { return false; } - if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) { + // + // + final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" ); + final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ]; + ext.clear(); + n = t5.getFirstExternalNode(); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 8 ) { return false; } - if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) { + if ( !ext.get( 0 ).getName().equals( "a" ) ) { return false; } - if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) { + if ( !ext.get( 1 ).getName().equals( "b" ) ) { return false; } - if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) { + if ( !ext.get( 2 ).getName().equals( "c" ) ) { return false; } - if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) { + if ( !ext.get( 3 ).getName().equals( "d" ) ) { return false; } - if ( !results.get( 0 ).getLineage()[ 0 ].equals( "Eukaryota" ) ) { + if ( !ext.get( 4 ).getName().equals( "e" ) ) { return false; } - if ( !results.get( 0 ).getLineage()[ 1 ].equals( "Metazoa" ) ) { + if ( !ext.get( 5 ).getName().equals( "f" ) ) { return false; } - if ( !results.get( 0 ).getLineage()[ results.get( 0 ).getLineage().length - 1 ].equals( "Nematostella" ) ) { + if ( !ext.get( 6 ).getName().equals( "g" ) ) { return false; } - } - catch ( final IOException e ) { - System.out.println(); - System.out.println( "the following might be due to absence internet connection:" ); - e.printStackTrace( System.out ); - return true; - } - catch ( final Exception e ) { - return false; - } - return true; - } - - private static boolean testEmblEntryRetrieval() { - //The format for GenBank Accession numbers are: - //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" ) ) { - return false; - } - if ( !DatabaseTools.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) { - return false; - } - if ( DatabaseTools.parseGenbankAccessor( "AAY423861" ) != null ) { - return false; - } - if ( DatabaseTools.parseGenbankAccessor( "AY4238612" ) != null ) { - return false; - } - if ( DatabaseTools.parseGenbankAccessor( "AAY4238612" ) != null ) { - return false; - } - if ( DatabaseTools.parseGenbankAccessor( "Y423861" ) != null ) { - return false; - } - if ( !DatabaseTools.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) { - return false; - } - if ( !DatabaseTools.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) { - return false; - } - if ( DatabaseTools.parseGenbankAccessor( "|S123456" ) != null ) { - return false; - } - if ( DatabaseTools.parseGenbankAccessor( "ABC123456" ) != null ) { - return false; - } - if ( !DatabaseTools.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) { - return false; - } - if ( !DatabaseTools.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) { - return false; - } - if ( DatabaseTools.parseGenbankAccessor( "ABCD12345" ) != null ) { - return false; - } - return true; - } - - private static boolean testUniprotEntryRetrieval() { - if ( !UniProtWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) { - return false; - } - if ( UniProtWsTools.parseUniProtAccessor( "EP12345" ) != null ) { - return false; - } - if ( UniProtWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) { - return false; - } - if ( UniProtWsTools.parseUniProtAccessor( "P12345E" ) != null ) { - return false; - } - if ( UniProtWsTools.parseUniProtAccessor( "P123455" ) != null ) { - return false; - } - if ( UniProtWsTools.parseUniProtAccessor( "EP12345E" ) != null ) { - return false; - } - if ( UniProtWsTools.parseUniProtAccessor( "AY423861" ) != null ) { - return false; - } - if ( !UniProtWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) { - return false; - } - if ( UniProtWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) { - return false; - } - if ( !UniProtWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) { - return false; - } - if ( !UniProtWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) { - return false; - } - if ( !UniProtWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) { - return false; - } - if ( !UniProtWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) { - return false; - } - try { - final SequenceDatabaseEntry entry = UniProtWsTools.obtainUniProtEntry( "P12345", 200 ); - if ( !entry.getAccession().equals( "P12345" ) ) { + if ( !ext.get( 7 ).getName().equals( "h" ) ) { return false; } - if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) { + // + // + final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" ); + final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ]; + ext.clear(); + t6.getNode( "ab" ).setCollapse( true ); + n = t6.getNode( "ab" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 7 ) { return false; } - if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) { + if ( !ext.get( 0 ).getName().equals( "ab" ) ) { return false; } - if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) { + if ( !ext.get( 1 ).getName().equals( "c" ) ) { return false; } - if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) { + if ( !ext.get( 2 ).getName().equals( "d" ) ) { return false; } - } - catch ( final IOException e ) { - System.out.println(); - System.out.println( "the following might be due to absence internet connection:" ); - e.printStackTrace( System.out ); - return true; - } - catch ( final Exception e ) { - return false; - } - return true; - } - - private static boolean testWabiTxSearch() { - try { - String result = ""; - result = TxSearch.searchSimple( "nematostella" ); - result = TxSearch.getTxId( "nematostella" ); - if ( !result.equals( "45350" ) ) { + if ( !ext.get( 3 ).getName().equals( "e" ) ) { return false; } - result = TxSearch.getTxName( "45350" ); - if ( !result.equals( "Nematostella" ) ) { + if ( !ext.get( 4 ).getName().equals( "f" ) ) { return false; } - result = TxSearch.getTxId( "nematostella vectensis" ); - if ( !result.equals( "45351" ) ) { + if ( !ext.get( 5 ).getName().equals( "g" ) ) { return false; } - result = TxSearch.getTxName( "45351" ); - if ( !result.equals( "Nematostella vectensis" ) ) { + if ( !ext.get( 6 ).getName().equals( "h" ) ) { return false; } - result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" ); - if ( !result.equals( "536089" ) ) { + // + // + final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" ); + final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ]; + ext.clear(); + t7.getNode( "cd" ).setCollapse( true ); + n = t7.getNode( "a" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 7 ) { return false; } - result = TxSearch.getTxName( "536089" ); - if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) { + if ( !ext.get( 0 ).getName().equals( "a" ) ) { return false; } - final List queries = new ArrayList(); - queries.add( "Campylobacter coli" ); - queries.add( "Escherichia coli" ); - queries.add( "Arabidopsis" ); - queries.add( "Trichoplax" ); - queries.add( "Samanea saman" ); - queries.add( "Kluyveromyces marxianus" ); - queries.add( "Bacillus subtilis subsp. subtilis str. N170" ); - queries.add( "Bornavirus parrot/PDD/2008" ); - final List ranks = new ArrayList(); - ranks.add( RANKS.SUPERKINGDOM ); - ranks.add( RANKS.KINGDOM ); - ranks.add( RANKS.FAMILY ); - ranks.add( RANKS.GENUS ); - ranks.add( RANKS.TRIBE ); - result = TxSearch.searchLineage( queries, ranks ); - result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true ); - result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true ); - } - catch ( final Exception e ) { - System.out.println(); - System.out.println( "the following might be due to absence internet connection:" ); - e.printStackTrace( System.out ); - return false; - } - return true; - } - - private static boolean testAminoAcidSequence() { - try { - final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" ); - if ( aa1.getLength() != 13 ) { + if ( !ext.get( 1 ).getName().equals( "b" ) ) { return false; } - if ( aa1.getResidueAt( 0 ) != 'A' ) { + if ( !ext.get( 2 ).getName().equals( "cd" ) ) { return false; } - if ( aa1.getResidueAt( 2 ) != 'K' ) { + if ( !ext.get( 3 ).getName().equals( "e" ) ) { return false; } - if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) { + if ( !ext.get( 4 ).getName().equals( "f" ) ) { return false; } - final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" ); - if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) { + if ( !ext.get( 5 ).getName().equals( "g" ) ) { return false; } - final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" ); - if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) { + if ( !ext.get( 6 ).getName().equals( "h" ) ) { return false; } - final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" ); - if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) { + // + // + final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" ); + final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ]; + ext.clear(); + t8.getNode( "cd" ).setCollapse( true ); + t8.getNode( "c" ).setCollapse( true ); + t8.getNode( "d" ).setCollapse( true ); + n = t8.getNode( "a" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 7 ) { return false; } - } - catch ( final Exception e ) { - e.printStackTrace(); - return false; - } - return true; - } - - private static boolean testCreateBalancedPhylogeny() { - try { - final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 ); - if ( p0.getRoot().getNumberOfDescendants() != 5 ) { + if ( !ext.get( 0 ).getName().equals( "a" ) ) { return false; } - if ( p0.getNumberOfExternalNodes() != 15625 ) { + if ( !ext.get( 1 ).getName().equals( "b" ) ) { return false; } - final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 ); - if ( p1.getRoot().getNumberOfDescendants() != 10 ) { + if ( !ext.get( 2 ).getName().equals( "cd" ) ) { + System.out.println( "2 fail" ); return false; } - if ( p1.getNumberOfExternalNodes() != 100 ) { + if ( !ext.get( 3 ).getName().equals( "e" ) ) { return false; } - } - catch ( final Exception e ) { - e.printStackTrace(); - return false; - } - return true; - } - - private static boolean testFastaParser() { - try { - if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) { + if ( !ext.get( 4 ).getName().equals( "f" ) ) { return false; } - if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) { + if ( !ext.get( 5 ).getName().equals( "g" ) ) { return false; } - final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ); - if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) { + if ( !ext.get( 6 ).getName().equals( "h" ) ) { return false; } - if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) { + // + // + final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" ); + final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ]; + ext.clear(); + t9.getNode( "gh" ).setCollapse( true ); + n = t9.getNode( "a" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 7 ) { return false; } - if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) { + if ( !ext.get( 0 ).getName().equals( "a" ) ) { return false; } - if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) { + if ( !ext.get( 1 ).getName().equals( "b" ) ) { return false; } - if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) { + if ( !ext.get( 2 ).getName().equals( "c" ) ) { return false; } - if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) { + if ( !ext.get( 3 ).getName().equals( "d" ) ) { return false; } - } - catch ( final Exception e ) { - e.printStackTrace(); - return false; - } - return true; - } - - private static boolean testGeneralMsaParser() { - try { - final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n"; - final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) ); - final String msa_str_1 = "seq_1 abc\nseq2 ghi\nseq_1 def\nseq2 jkm\n"; - final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) ); - final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n"; - final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) ); - final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n"; - final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) ); - final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) ); - if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) { + if ( !ext.get( 4 ).getName().equals( "e" ) ) { return false; } - if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) { + if ( !ext.get( 5 ).getName().equals( "f" ) ) { return false; } - if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) { + if ( !ext.get( 6 ).getName().equals( "gh" ) ) { return false; } - final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) ); - if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) { + // + // + final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" ); + final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ]; + ext.clear(); + t10.getNode( "gh" ).setCollapse( true ); + t10.getNode( "g" ).setCollapse( true ); + t10.getNode( "h" ).setCollapse( true ); + n = t10.getNode( "a" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 7 ) { return false; } - if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) { + if ( !ext.get( 0 ).getName().equals( "a" ) ) { return false; } - if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) { + if ( !ext.get( 1 ).getName().equals( "b" ) ) { return false; } - final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ); - if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) { + if ( !ext.get( 2 ).getName().equals( "c" ) ) { return false; } - if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) { + if ( !ext.get( 3 ).getName().equals( "d" ) ) { return false; } - if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) { + if ( !ext.get( 4 ).getName().equals( "e" ) ) { + return false; + } + if ( !ext.get( 5 ).getName().equals( "f" ) ) { + return false; + } + if ( !ext.get( 6 ).getName().equals( "gh" ) ) { + return false; + } + // + // + final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" ); + final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ]; + ext.clear(); + t11.getNode( "gh" ).setCollapse( true ); + t11.getNode( "fgh" ).setCollapse( true ); + n = t11.getNode( "a" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 6 ) { + return false; + } + if ( !ext.get( 0 ).getName().equals( "a" ) ) { + return false; + } + if ( !ext.get( 1 ).getName().equals( "b" ) ) { + return false; + } + if ( !ext.get( 2 ).getName().equals( "c" ) ) { + return false; + } + if ( !ext.get( 3 ).getName().equals( "d" ) ) { + return false; + } + if ( !ext.get( 4 ).getName().equals( "e" ) ) { + return false; + } + if ( !ext.get( 5 ).getName().equals( "fgh" ) ) { + return false; + } + // + // + final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" ); + final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ]; + ext.clear(); + t12.getNode( "gh" ).setCollapse( true ); + t12.getNode( "fgh" ).setCollapse( true ); + t12.getNode( "g" ).setCollapse( true ); + t12.getNode( "h" ).setCollapse( true ); + t12.getNode( "f" ).setCollapse( true ); + n = t12.getNode( "a" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 6 ) { + return false; + } + if ( !ext.get( 0 ).getName().equals( "a" ) ) { + return false; + } + if ( !ext.get( 1 ).getName().equals( "b" ) ) { + return false; + } + if ( !ext.get( 2 ).getName().equals( "c" ) ) { + return false; + } + if ( !ext.get( 3 ).getName().equals( "d" ) ) { + return false; + } + if ( !ext.get( 4 ).getName().equals( "e" ) ) { + return false; + } + if ( !ext.get( 5 ).getName().equals( "fgh" ) ) { + return false; + } + // + // + final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" ); + final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ]; + ext.clear(); + t13.getNode( "ab" ).setCollapse( true ); + t13.getNode( "b" ).setCollapse( true ); + t13.getNode( "fgh" ).setCollapse( true ); + t13.getNode( "gh" ).setCollapse( true ); + n = t13.getNode( "ab" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 5 ) { + return false; + } + if ( !ext.get( 0 ).getName().equals( "ab" ) ) { + return false; + } + if ( !ext.get( 1 ).getName().equals( "c" ) ) { + return false; + } + if ( !ext.get( 2 ).getName().equals( "d" ) ) { + return false; + } + if ( !ext.get( 3 ).getName().equals( "e" ) ) { + return false; + } + if ( !ext.get( 4 ).getName().equals( "fgh" ) ) { + return false; + } + // + // + final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" ); + final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ]; + ext.clear(); + t14.getNode( "ab" ).setCollapse( true ); + t14.getNode( "a" ).setCollapse( true ); + t14.getNode( "fgh" ).setCollapse( true ); + t14.getNode( "gh" ).setCollapse( true ); + n = t14.getNode( "ab" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 5 ) { + return false; + } + if ( !ext.get( 0 ).getName().equals( "ab" ) ) { + return false; + } + if ( !ext.get( 1 ).getName().equals( "c" ) ) { + return false; + } + if ( !ext.get( 2 ).getName().equals( "d" ) ) { + return false; + } + if ( !ext.get( 3 ).getName().equals( "e" ) ) { + return false; + } + if ( !ext.get( 4 ).getName().equals( "fgh" ) ) { + return false; + } + // + // + final StringBuffer sb15 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,x,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" ); + final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ]; + ext.clear(); + t15.getNode( "ab" ).setCollapse( true ); + t15.getNode( "a" ).setCollapse( true ); + t15.getNode( "fgh" ).setCollapse( true ); + t15.getNode( "gh" ).setCollapse( true ); + n = t15.getNode( "ab" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 6 ) { + return false; + } + if ( !ext.get( 0 ).getName().equals( "ab" ) ) { + return false; + } + if ( !ext.get( 1 ).getName().equals( "c" ) ) { + return false; + } + if ( !ext.get( 2 ).getName().equals( "d" ) ) { + return false; + } + if ( !ext.get( 3 ).getName().equals( "e" ) ) { + return false; + } + if ( !ext.get( 4 ).getName().equals( "x" ) ) { + return false; + } + if ( !ext.get( 5 ).getName().equals( "fgh" ) ) { + return false; + } + // + // + final StringBuffer sb16 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,x,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" ); + final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ]; + ext.clear(); + t16.getNode( "ab" ).setCollapse( true ); + t16.getNode( "a" ).setCollapse( true ); + t16.getNode( "fgh" ).setCollapse( true ); + t16.getNode( "gh" ).setCollapse( true ); + t16.getNode( "cd" ).setCollapse( true ); + t16.getNode( "cde" ).setCollapse( true ); + t16.getNode( "d" ).setCollapse( true ); + t16.getNode( "x" ).setCollapse( true ); + n = t16.getNode( "ab" ); + while ( n != null ) { + ext.add( n ); + n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes(); + } + if ( ext.size() != 4 ) { + return false; + } + if ( !ext.get( 0 ).getName().equals( "ab" ) ) { + return false; + } + if ( !ext.get( 1 ).getName().equals( "cde" ) ) { + return false; + } + if ( !ext.get( 2 ).getName().equals( "x" ) ) { + return false; + } + if ( !ext.get( 3 ).getName().equals( "fgh" ) ) { return false; } } catch ( final Exception e ) { - e.printStackTrace(); + e.printStackTrace( System.out ); return false; } return true; } - private static boolean testMafft() { + private static boolean testMsaQualityMethod() { try { - final List opts = new ArrayList(); - opts.add( "--maxiterate" ); - opts.add( "1000" ); - opts.add( "--localpair" ); - opts.add( "--quiet" ); - Msa msa = null; - final MsaInferrer mafft = Mafft.createInstance(); - msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi.fasta" ), opts ); - if ( ( msa == null ) || ( msa.getLength() < 10 ) || ( msa.getNumberOfSequences() != 19 ) ) { + final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" ); + 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 ); + l.add( s2 ); + l.add( s3 ); + final Msa msa = BasicMsa.createInstance( l ); + if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) { + return false; + } + if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) { + return false; + } + if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) { + return false; + } + if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + return true; + } + + private static boolean testSequenceIdParsing() { + try { + 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 );