X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Ftest%2FTest.java;h=547d9cdef4afb0419c08287cb6a45e561dee911c;hb=dfb728ba91a9112309c510d032464446cecc273e;hp=723ace88c98626a547db8a65a0ecaf0fc0e11566;hpb=756e207d17b773c707ff2315091bcef338ddcf85;p=jalview.git diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 723ace8..547d9cd 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,18 @@ 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.PhylogenyMethods.TAXONOMY_EXTRACTION; 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 +75,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 +85,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 +106,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 +140,7 @@ public final class Test { private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) { final PhylogenyMethods pm = PhylogenyMethods.getInstance(); - return pm.obtainLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent(); + return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent(); } public static boolean isEqual( final double a, final double b ) { @@ -167,6 +174,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 +247,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 +481,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 +490,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 +499,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 +526,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 +709,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 +737,7 @@ public final class Test { System.out.println( "failed [will not count towards failed tests]" ); } } + //---- System.out.print( "Next nodes with collapsed: " ); if ( Test.testNextNodeWithCollapsing() ) { System.out.println( "OK." ); @@ -693,6 +747,15 @@ public final class Test { 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." ); @@ -923,67 +986,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; } @@ -997,114 +1060,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 ); @@ -1210,67 +1165,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; } @@ -1692,6 +1647,7 @@ public final class Test { final List> tl = BasicTableParser.parse( source2.toString(), ";", false, + false, "comment:", false ); if ( tl.size() != 2 ) { @@ -1892,26 +1848,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; @@ -1996,7 +1932,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; } @@ -2111,7 +2046,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 ) ) { @@ -2839,7 +2774,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 ); @@ -3189,200 +3124,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; } @@ -3394,154 +3328,445 @@ public final class Test { return true; } - private static boolean testHmmscanOutputParser() { - final String test_dir = Test.PATH_TO_TEST_DATA; + private static boolean testGetLCA2() { try { - final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir - + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE ); - parser1.parse(); - final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir - + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE ); - final List proteins = parser2.parse(); - if ( parser2.getProteinsEncountered() != 4 ) { + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny 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 ( proteins.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 = proteins.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 p2 = proteins.get( 1 ); - if ( p2.getNumberOfProteinDomains() != 51 ) { + final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ), + p1.getNode( "A" ) ); + if ( !abc.getName().equals( "abc" ) ) { return false; } - final Protein p3 = proteins.get( 2 ); - if ( p3.getNumberOfProteinDomains() != 2 ) { + final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "C" ) ); + if ( !abc2.getName().equals( "abc" ) ) { return false; } - final Protein p4 = proteins.get( 3 ); - if ( p4.getNumberOfProteinDomains() != 1 ) { + final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "D" ) ); + if ( !abcd.getName().equals( "abcd" ) ) { return false; } - if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) { + final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ), + p1.getNode( "A" ) ); + if ( !abcd2.getName().equals( "abcd" ) ) { return false; } - if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) { + final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "F" ) ); + if ( !abcdef.getName().equals( "abcdef" ) ) { return false; } - if ( p4.getProteinDomain( 0 ).getTo() != 395 ) { + final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ), + p1.getNode( "A" ) ); + if ( !abcdef2.getName().equals( "abcdef" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) { + final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ), + p1.getNode( "F" ) ); + if ( !abcdef3.getName().equals( "abcdef" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) { + final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ), + p1.getNode( "ab" ) ); + if ( !abcdef4.getName().equals( "abcdef" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) { + final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "E" ) ); + if ( !abcde.getName().equals( "abcde" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) { + final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ), + p1.getNode( "A" ) ); + if ( !abcde2.getName().equals( "abcde" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) { + final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ), + p1.getNode( "abcdefgh" ) ); + if ( !r.getName().equals( "abcdefgh" ) ) { return false; } - if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) { + final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ), + p1.getNode( "H" ) ); + if ( !r2.getName().equals( "abcdefgh" ) ) { 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 r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ), + p1.getNode( "A" ) ); + if ( !r3.getName().equals( "abcdefgh" ) ) { return false; } - final PhylogenyNode n2 = t0.getNode( "B" ); - if ( n2.isLastExternalNode() ) { + final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ), + p1.getNode( "abcde" ) ); + if ( !abcde3.getName().equals( "abcde" ) ) { return false; } - final PhylogenyNode n3 = t0.getNode( "C" ); - if ( n3.isLastExternalNode() ) { + final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ), + p1.getNode( "E" ) ); + if ( !abcde4.getName().equals( "abcde" ) ) { return false; } - final PhylogenyNode n4 = t0.getNode( "D" ); - if ( !n4.isLastExternalNode() ) { + final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ), + p1.getNode( "B" ) ); + if ( !ab3.getName().equals( "ab" ) ) { 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 PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ), + p1.getNode( "ab" ) ); + if ( !ab4.getName().equals( "ab" ) ) { + return false; } - final PhylogenyNodeIterator it = t0.iteratorLevelOrder(); - if ( !it.next().getName().equals( "r" ) ) { + 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( "ab" ) ) { + final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ), + p2.getNode( "c" ) ); + if ( !cd2.getName().equals( "cd" ) ) { return false; } - if ( !it.next().getName().equals( "cd" ) ) { + final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ), + p2.getNode( "e" ) ); + if ( !cde.getName().equals( "cde" ) ) { return false; } - if ( !it.next().getName().equals( "A" ) ) { + final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ), + p2.getNode( "c" ) ); + if ( !cde2.getName().equals( "cde" ) ) { return false; } - if ( !it.next().getName().equals( "B" ) ) { + final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ), + p2.getNode( "f" ) ); + if ( !cdef.getName().equals( "cdef" ) ) { return false; } - if ( !it.next().getName().equals( "C" ) ) { + final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ), + p2.getNode( "f" ) ); + if ( !cdef2.getName().equals( "cdef" ) ) { return false; } - if ( !it.next().getName().equals( "D" ) ) { + final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ), + p2.getNode( "d" ) ); + if ( !cdef3.getName().equals( "cdef" ) ) { return false; } - if ( it.hasNext() ) { + final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ), + p2.getNode( "a" ) ); + if ( !rt.getName().equals( "r" ) ) { 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(); + 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; } - for( it2.reset(); it2.hasNext(); ) { - it2.next(); + 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" ) ) { @@ -4443,6 +4668,58 @@ public final class Test { if ( ( p46.length != 1 ) || !p46[ 0 ].isEmpty() ) { return false; } + final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ]; + if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { + return false; + } + final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { + return false; + } + final Phylogeny p49 = factory + .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ), + new NHXParser() )[ 0 ]; + if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) { + return false; + } + final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( p50.getNode( "A" ) == null ) { + return false; + } + if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) + .equals( "((A,B)ab:2.0[88],C);" ) ) { + return false; + } + if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) { + return false; + } + if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ) + .equals( "((A,B)88:2.0,C);" ) ) { + return false; + } + final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( p51.getNode( "A(A" ) == null ) { + return false; + } + final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ]; + if ( p52.getNode( "A(A" ) == null ) { + return false; + } + final Phylogeny p53 = factory + .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ), + new NHXParser() )[ 0 ]; + if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) { + return false; + } + // + final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ]; + if ( p54.getNode( "A" ) == null ) { + return false; + } + if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) + .equals( "((A,B)[88],C);" ) ) { + return false; + } } catch ( final Exception e ) { e.printStackTrace( System.out ); @@ -4474,11 +4751,10 @@ public final class Test { 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; } } @@ -4500,7 +4776,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() ) { @@ -4637,51 +4913,81 @@ public final class Test { if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) { return false; } - if ( NHXParser.LIMIT_SPECIES_NAMES_TO_FIVE_CHARS ) { - final PhylogenyNode a = PhylogenyNode - .createInstanceFromNhxString( "n10_ECOLI/1-2", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) { - return false; - } - final PhylogenyNode b = PhylogenyNode - .createInstanceFromNhxString( "n10_ECOLI1/1-2", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) { - return false; - } - final PhylogenyNode c = PhylogenyNode - .createInstanceFromNhxString( "n10_RATAF12/1000-2000", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) { - return false; - } - final PhylogenyNode d = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT1/1-2", - PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !d.getName().equals( "n10_RAT1/1-2" ) ) { - return false; - } - if ( !PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) { - return false; - } - final PhylogenyNode e = PhylogenyNode - .createInstanceFromNhxString( "n10_RAT1", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); - if ( !e.getName().equals( "n10_RAT1" ) ) { - return false; - } - if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) { - return false; - } + final PhylogenyNode a = PhylogenyNode + .createInstanceFromNhxString( "n10_ECOLI/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) { + return false; + } + final PhylogenyNode b = PhylogenyNode + .createInstanceFromNhxString( "n10_ECOLI1/1-2", + PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) { + return false; + } + final PhylogenyNode c = PhylogenyNode + .createInstanceFromNhxString( "n10_RATAF12/1000-2000", + PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) { + return false; + } + final PhylogenyNode c1 = PhylogenyNode + .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000", + PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) { + return false; + } + final PhylogenyNode c2 = PhylogenyNode + .createInstanceFromNhxString( "n10_Bovin_1/1000-2000", + PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) { + return false; + } + final PhylogenyNode d = PhylogenyNode + .createInstanceFromNhxString( "n10_RAT1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !d.getName().equals( "n10_RAT1/1-2" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) { + return false; + } + final PhylogenyNode e = PhylogenyNode + .createInstanceFromNhxString( "n10_RAT1", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY ); + if ( !e.getName().equals( "n10_RAT1" ) ) { + return false; + } + if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) { + return false; + } + final PhylogenyNode e2 = PhylogenyNode + .createInstanceFromNhxString( "n10_RAT1", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + if ( !e2.getName().equals( "n10_RAT1" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) { + return false; + } + final PhylogenyNode e3 = PhylogenyNode + .createInstanceFromNhxString( "n10_RAT~", PhylogenyMethods.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", @@ -4707,6 +5013,22 @@ public final class Test { if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) { return false; } + final PhylogenyNode m = PhylogenyNode + .createInstanceFromNhxString( "n10_MOUSEa", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + if ( !m.getName().equals( "n10_MOUSEa" ) ) { + return false; + } + if ( !PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) { + return false; + } + final PhylogenyNode o = PhylogenyNode + .createInstanceFromNhxString( "n10_MOUSE_", PhylogenyMethods.TAXONOMY_EXTRACTION.YES ); + if ( !o.getName().equals( "n10_MOUSE_" ) ) { + 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" ) ) { @@ -4739,7 +5061,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 ) { @@ -4748,7 +5070,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 @@ -4791,7 +5113,7 @@ public final class Test { 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 @@ -4867,7 +5189,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; @@ -4909,13 +5231,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; } } @@ -4990,7 +5312,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; } @@ -5002,7 +5324,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; } @@ -5026,6 +5348,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" ); @@ -5597,46 +5973,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; } } @@ -6452,10 +6828,32 @@ public final class Test { if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) { return false; } - p8 = null; + p8 = null; + } + catch ( final Exception e ) { + e.printStackTrace( System.out ); + return false; + } + 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( 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( System.out ); + e.printStackTrace(); return false; } return true; @@ -7328,365 +7726,10 @@ public final class Test { return true; } - private static boolean testTaxonomyAssigner() { - try { - String s0_str = "(((([&&NHX:S=A],[&&NHX:S=B])[&&NHX:S=AB],[&&NHX:S=C])[&&NHX:S=ABC],[&&NHX:S=D])[&&NHX:S=ABCD],[&&NHX:S=E])[&&NHX:S=ABCDE]"; - String g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A])a,[&&NHX:S=B])b,[&&NHX:S=C])c"; - Phylogeny s0 = ParserBasedPhylogenyFactory.getInstance().create( s0_str, new NHXParser() )[ 0 ]; - Phylogeny g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - s0.setRooted( true ); - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A])a,[&&NHX:S=A])b,[&&NHX:S=A])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=B])a,[&&NHX:S=A])b,[&&NHX:S=A])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=B])a,[&&NHX:S=C])b,[&&NHX:S=A])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=B])a,[&&NHX:S=C])b,[&&NHX:S=D])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "AB" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABC" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=E])a,[&&NHX:S=C])b,[&&NHX:S=D])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=E])a,[&&NHX:S=A])b,[&&NHX:S=A])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCDE" ) ) { - return false; - } - s0_str = "(([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=C],[&&NHX:S=D])[&&NHX:S=ABCD]," - + "([&&NHX:S=E],[&&NHX:S=F],[&&NHX:S=G],[&&NHX:S=H])[&&NHX:S=EFGH]," - + "([&&NHX:S=I],[&&NHX:S=J],[&&NHX:S=K],[&&NHX:S=L])[&&NHX:S=IJKL], " - + "([&&NHX:S=M],[&&NHX:S=N],[&&NHX:S=O],[&&NHX:S=P])[&&NHX:S=MNOP])[&&NHX:S=ROOT]"; - s0 = ParserBasedPhylogenyFactory.getInstance().create( s0_str, new NHXParser() )[ 0 ]; - s0.setRooted( true ); - g0_str = "(([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=E],[&&NHX:S=F],[&&NHX:S=G],[&&NHX:S=H])b," - + "([&&NHX:S=I],[&&NHX:S=J],[&&NHX:S=K],[&&NHX:S=L])c, " - + "([&&NHX:S=M],[&&NHX:S=N],[&&NHX:S=O],[&&NHX:S=P])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "EFGH" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "IJKL" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "MNOP" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=A],[&&NHX:S=B])a," - + "([&&NHX:S=E],[&&NHX:S=F],[&&NHX:S=F],[&&NHX:S=F])b," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=I])c, " - + "([&&NHX:S=M],[&&NHX:S=N],[&&NHX:S=O],[&&NHX:S=O])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "EFGH" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "IJKL" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "MNOP" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=A],[&&NHX:S=B])a," - + "([&&NHX:S=E],[&&NHX:S=F],[&&NHX:S=F],[&&NHX:S=F])b," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])c, " - + "([&&NHX:S=M],[&&NHX:S=N],[&&NHX:S=A],[&&NHX:S=O])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "EFGH" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])a," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])b," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])c, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A])a,[&&NHX:S=A])b,[&&NHX:S=A])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - g0_str = "((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=B])a,[&&NHX:S=I])b,[&&NHX:S=J])c"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(((([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=D],[&&NHX:S=C],[&&NHX:S=B],[&&NHX:S=A])b)ab," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])c)abc, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=D],[&&NHX:S=D],[&&NHX:S=B],[&&NHX:S=A])b)ab," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])c)abc, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=D],[&&NHX:S=D],[&&NHX:S=B],[&&NHX:S=A])b)ab," - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L])c)abc, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=A])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "L" ) ) { - return false; - } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - g0_str = "(((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=D],[&&NHX:S=D],[&&NHX:S=B],[&&NHX:S=A])b)ab," - + "([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A])c)abc, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=A])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( !g0.getNode( "a" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "b" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "ab" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - if ( !g0.getNode( "abc" ).getNodeData().getTaxonomy().getScientificName().equals( "ABCD" ) ) { - return false; - } - if ( !g0.getNode( "d" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - if ( !g0.getNode( "r" ).getNodeData().getTaxonomy().getScientificName().equals( "ROOT" ) ) { - return false; - } - s0_str = "(([&&NHX:S=A],[&&NHX:S=B],[&&NHX:S=C],[&&NHX:S=D])," - + "([&&NHX:S=E],[&&NHX:S=F],[&&NHX:S=G],[&&NHX:S=H])," - + "([&&NHX:S=I],[&&NHX:S=J],[&&NHX:S=K],[&&NHX:S=L]), " - + "([&&NHX:S=M],[&&NHX:S=N],[&&NHX:S=O],[&&NHX:S=P]))"; - s0 = ParserBasedPhylogenyFactory.getInstance().create( s0_str, new NHXParser() )[ 0 ]; - s0.setRooted( true ); - g0_str = "(((([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=C],[&&NHX:S=D])a," - + "([&&NHX:S=D],[&&NHX:S=D],[&&NHX:S=B],[&&NHX:S=A])b)ab," - + "([&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A],[&&NHX:S=A])c)abc, " - + "([&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=L],[&&NHX:S=A])d)r"; - g0 = ParserBasedPhylogenyFactory.getInstance().create( g0_str, new NHXParser() )[ 0 ]; - g0.setRooted( true ); - TaxonomyAssigner.execute( g0, s0 ); - if ( g0.getNode( "a" ).getNodeData().isHasTaxonomy() ) { - return false; - } - if ( !g0.getNode( "c" ).getNodeData().getTaxonomy().getScientificName().equals( "A" ) ) { - return false; - } - } - catch ( final Exception e ) { - e.printStackTrace( System.out ); - return false; - } - return true; - } - private static boolean testUniprotTaxonomySearch() { try { - List results = UniProtWsTools - .getTaxonomiesFromCommonNameStrict( "starlet sea anemone", 10 ); + List results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone", + 10 ); if ( results.size() != 1 ) { return false; } @@ -7706,7 +7749,7 @@ public final class Test { return false; } results = null; - results = UniProtWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 ); + results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 ); if ( results.size() != 1 ) { return false; } @@ -7726,7 +7769,7 @@ public final class Test { return false; } results = null; - results = UniProtWsTools.getTaxonomiesFromId( "45351", 10 ); + results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 ); if ( results.size() != 1 ) { return false; } @@ -7746,7 +7789,7 @@ public final class Test { return false; } results = null; - results = UniProtWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 ); + results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 ); if ( results.size() != 1 ) { return false; } @@ -7794,90 +7837,90 @@ public final class Test { //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals //Protein: 3 letters + 5 numerals //http://www.ncbi.nlm.nih.gov/Sequin/acc.html - if ( !DatabaseTools.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) { return false; } - if ( !DatabaseTools.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "AAY423861" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "AY4238612" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "AAY4238612" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "Y423861" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) { return false; } - if ( !DatabaseTools.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) { return false; } - if ( !DatabaseTools.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "|S123456" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "ABC123456" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) { return false; } - if ( !DatabaseTools.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) { return false; } - if ( !DatabaseTools.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) { + if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) { return false; } - if ( DatabaseTools.parseGenbankAccessor( "ABCD12345" ) != null ) { + if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) { return false; } return true; } private static boolean testUniprotEntryRetrieval() { - if ( !UniProtWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "EP12345" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "P12345E" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "P123455" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "EP12345E" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "AY423861" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) { return false; } - if ( !UniProtWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) { return false; } - if ( UniProtWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) { + if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) { return false; } - if ( !UniProtWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) { return false; } - if ( !UniProtWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) { return false; } - if ( !UniProtWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) { return false; } - if ( !UniProtWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) { + if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) { return false; } try { - final SequenceDatabaseEntry entry = UniProtWsTools.obtainUniProtEntry( "P12345", 200 ); + final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 ); if ( !entry.getAccession().equals( "P12345" ) ) { return false; } @@ -8060,12 +8103,48 @@ public final class Test { 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 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 ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) { + return false; + } + if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) { + return false; + } + if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) { + return false; + } + if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) { + return false; + } + if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) { + return false; + } + if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) { + return false; + } + if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) { + return false; + } + if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) { + return false; + } + if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) { + return false; + } + if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) { + return false; + } + if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) { + return false; + } 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; @@ -8104,7 +8183,7 @@ public final class Test { return true; } - private static boolean testMafft() { + private static boolean testMafft( final String path ) { try { final List opts = new ArrayList(); opts.add( "--maxiterate" ); @@ -8112,9 +8191,12 @@ public final class Test { 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 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 ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) { return false; } } @@ -8685,4 +8767,163 @@ public final class Test { } return true; } + + private static boolean testMsaQualityMethod() { + try { + 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 ); + return false; + } + return true; + } }