2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.test;
28 import java.io.ByteArrayInputStream;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
40 import org.forester.application.support_transfer;
41 import org.forester.development.DevelopmentTools;
42 import org.forester.evoinference.TestPhylogenyReconstruction;
43 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
44 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
45 import org.forester.go.TestGo;
46 import org.forester.io.parsers.FastaParser;
47 import org.forester.io.parsers.GeneralMsaParser;
48 import org.forester.io.parsers.HmmscanPerDomainTableParser;
49 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
50 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
51 import org.forester.io.parsers.nexus.NexusCharactersParser;
52 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
53 import org.forester.io.parsers.nhx.NHXParser;
54 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
55 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
56 import org.forester.io.parsers.tol.TolParser;
57 import org.forester.io.parsers.util.ParserUtils;
58 import org.forester.io.writers.PhylogenyWriter;
59 import org.forester.msa.BasicMsa;
60 import org.forester.msa.Mafft;
61 import org.forester.msa.Msa;
62 import org.forester.msa.MsaInferrer;
63 import org.forester.msa.MsaMethods;
64 import org.forester.pccx.TestPccx;
65 import org.forester.phylogeny.Phylogeny;
66 import org.forester.phylogeny.PhylogenyBranch;
67 import org.forester.phylogeny.PhylogenyMethods;
68 import org.forester.phylogeny.PhylogenyNode;
69 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
70 import org.forester.phylogeny.data.BinaryCharacters;
71 import org.forester.phylogeny.data.BranchWidth;
72 import org.forester.phylogeny.data.Confidence;
73 import org.forester.phylogeny.data.Distribution;
74 import org.forester.phylogeny.data.DomainArchitecture;
75 import org.forester.phylogeny.data.Event;
76 import org.forester.phylogeny.data.Identifier;
77 import org.forester.phylogeny.data.PhylogenyData;
78 import org.forester.phylogeny.data.PhylogenyDataUtil;
79 import org.forester.phylogeny.data.Polygon;
80 import org.forester.phylogeny.data.PropertiesMap;
81 import org.forester.phylogeny.data.Property;
82 import org.forester.phylogeny.data.Property.AppliesTo;
83 import org.forester.phylogeny.data.ProteinDomain;
84 import org.forester.phylogeny.data.Taxonomy;
85 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
86 import org.forester.phylogeny.factories.PhylogenyFactory;
87 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
88 import org.forester.protein.Protein;
89 import org.forester.rio.TestRIO;
90 import org.forester.sdi.SDI;
91 import org.forester.sdi.SDIR;
92 import org.forester.sdi.TestGSDI;
93 import org.forester.sequence.BasicSequence;
94 import org.forester.sequence.Sequence;
95 import org.forester.surfacing.TestSurfacing;
96 import org.forester.tools.ConfidenceAssessor;
97 import org.forester.tools.SupportCount;
98 import org.forester.tools.TreeSplitMatrix;
99 import org.forester.util.AsciiHistogram;
100 import org.forester.util.BasicDescriptiveStatistics;
101 import org.forester.util.BasicTable;
102 import org.forester.util.BasicTableParser;
103 import org.forester.util.DescriptiveStatistics;
104 import org.forester.util.ForesterConstants;
105 import org.forester.util.ForesterUtil;
106 import org.forester.util.GeneralTable;
107 import org.forester.util.SequenceIdParser;
108 import org.forester.ws.seqdb.SequenceDatabaseEntry;
109 import org.forester.ws.seqdb.SequenceDbWsTools;
110 import org.forester.ws.seqdb.UniProtTaxonomy;
111 import org.forester.ws.wabi.TxSearch;
112 import org.forester.ws.wabi.TxSearch.RANKS;
113 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
114 import org.forester.ws.wabi.TxSearch.TAX_RANK;
116 @SuppressWarnings( "unused")
117 public final class Test {
119 private final static double ZERO_DIFF = 1.0E-9;
120 private final static String PATH_TO_TEST_DATA = System.getProperty( "user.dir" )
121 + ForesterUtil.getFileSeparator() + "test_data"
122 + ForesterUtil.getFileSeparator();
123 private final static String PATH_TO_RESOURCES = System.getProperty( "user.dir" )
124 + ForesterUtil.getFileSeparator() + "resources"
125 + ForesterUtil.getFileSeparator();
126 private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
127 private static final String PHYLOXML_REMOTE_XSD = ForesterConstants.PHYLO_XML_LOCATION + "/"
128 + ForesterConstants.PHYLO_XML_VERSION + "/"
129 + ForesterConstants.PHYLO_XML_XSD;
130 private static final String PHYLOXML_LOCAL_XSD = PATH_TO_RESOURCES + "phyloxml_schema/"
131 + ForesterConstants.PHYLO_XML_VERSION + "/"
132 + ForesterConstants.PHYLO_XML_XSD;
134 private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
135 final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
139 private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
140 return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
143 public static boolean isEqual( final double a, final double b ) {
144 return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
147 public static void main( final String[] args ) {
148 System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
149 System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
151 Locale.setDefault( Locale.US );
152 System.out.println( "[Locale: " + Locale.getDefault() + "]" );
155 System.out.print( "[Test if directory with files for testing exists/is readable: " );
156 if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
157 System.out.println( "OK.]" );
160 System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
161 System.out.println( "Testing aborted." );
164 System.out.print( "[Test if resources directory exists/is readable: " );
165 if ( testDir( PATH_TO_RESOURCES ) ) {
166 System.out.println( "OK.]" );
169 System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
170 System.out.println( "Testing aborted." );
173 final long start_time = new Date().getTime();
174 System.out.print( "Sequence id parsing: " );
175 if ( testSequenceIdParsing() ) {
176 System.out.println( "OK." );
180 System.out.println( "failed." );
183 System.out.print( "Hmmscan output parser: " );
184 if ( testHmmscanOutputParser() ) {
185 System.out.println( "OK." );
189 System.out.println( "failed." );
192 System.out.print( "Basic node methods: " );
193 if ( Test.testBasicNodeMethods() ) {
194 System.out.println( "OK." );
198 System.out.println( "failed." );
201 System.out.print( "Taxonomy extraction: " );
202 if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
203 System.out.println( "OK." );
207 System.out.println( "failed." );
210 System.out.print( "Basic node construction and parsing of NHX (node level): " );
211 if ( Test.testNHXNodeParsing() ) {
212 System.out.println( "OK." );
216 System.out.println( "failed." );
219 System.out.print( "NH parsing: " );
220 if ( Test.testNHParsing() ) {
221 System.out.println( "OK." );
225 System.out.println( "failed." );
228 System.out.print( "Conversion to NHX (node level): " );
229 if ( Test.testNHXconversion() ) {
230 System.out.println( "OK." );
234 System.out.println( "failed." );
237 System.out.print( "NHX parsing: " );
238 if ( Test.testNHXParsing() ) {
239 System.out.println( "OK." );
243 System.out.println( "failed." );
246 System.out.print( "NHX parsing with quotes: " );
247 if ( Test.testNHXParsingQuotes() ) {
248 System.out.println( "OK." );
252 System.out.println( "failed." );
255 System.out.print( "NHX parsing (MrBayes): " );
256 if ( Test.testNHXParsingMB() ) {
257 System.out.println( "OK." );
261 System.out.println( "failed." );
264 System.out.print( "Nexus characters parsing: " );
265 if ( Test.testNexusCharactersParsing() ) {
266 System.out.println( "OK." );
270 System.out.println( "failed." );
273 System.out.print( "Nexus tree parsing: " );
274 if ( Test.testNexusTreeParsing() ) {
275 System.out.println( "OK." );
279 System.out.println( "failed." );
282 System.out.print( "Nexus tree parsing (translating): " );
283 if ( Test.testNexusTreeParsingTranslating() ) {
284 System.out.println( "OK." );
288 System.out.println( "failed." );
291 System.out.print( "Nexus matrix parsing: " );
292 if ( Test.testNexusMatrixParsing() ) {
293 System.out.println( "OK." );
297 System.out.println( "failed." );
300 System.out.print( "Basic phyloXML parsing: " );
301 if ( Test.testBasicPhyloXMLparsing() ) {
302 System.out.println( "OK." );
306 System.out.println( "failed." );
309 System.out.print( "Basic phyloXML parsing (validating against schema): " );
310 if ( testBasicPhyloXMLparsingValidating() ) {
311 System.out.println( "OK." );
315 System.out.println( "failed." );
318 System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
319 if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
320 System.out.println( "OK." );
324 System.out.println( "failed." );
327 System.out.print( "phyloXML Distribution Element: " );
328 if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
329 System.out.println( "OK." );
333 System.out.println( "failed." );
336 System.out.print( "Tol XML parsing: " );
337 if ( Test.testBasicTolXMLparsing() ) {
338 System.out.println( "OK." );
342 System.out.println( "failed." );
345 System.out.print( "Copying of node data: " );
346 if ( Test.testCopyOfNodeData() ) {
347 System.out.println( "OK." );
351 System.out.println( "failed." );
354 System.out.print( "Basic tree methods: " );
355 if ( Test.testBasicTreeMethods() ) {
356 System.out.println( "OK." );
360 System.out.println( "failed." );
363 System.out.print( "Postorder Iterator: " );
364 if ( Test.testPostOrderIterator() ) {
365 System.out.println( "OK." );
369 System.out.println( "failed." );
372 System.out.print( "Preorder Iterator: " );
373 if ( Test.testPreOrderIterator() ) {
374 System.out.println( "OK." );
378 System.out.println( "failed." );
381 System.out.print( "Levelorder Iterator: " );
382 if ( Test.testLevelOrderIterator() ) {
383 System.out.println( "OK." );
387 System.out.println( "failed." );
390 System.out.print( "Re-id methods: " );
391 if ( Test.testReIdMethods() ) {
392 System.out.println( "OK." );
396 System.out.println( "failed." );
399 System.out.print( "Methods on last external nodes: " );
400 if ( Test.testLastExternalNodeMethods() ) {
401 System.out.println( "OK." );
405 System.out.println( "failed." );
408 System.out.print( "Methods on external nodes: " );
409 if ( Test.testExternalNodeRelatedMethods() ) {
410 System.out.println( "OK." );
414 System.out.println( "failed." );
417 System.out.print( "Deletion of external nodes: " );
418 if ( Test.testDeletionOfExternalNodes() ) {
419 System.out.println( "OK." );
423 System.out.println( "failed." );
426 System.out.print( "Subtree deletion: " );
427 if ( Test.testSubtreeDeletion() ) {
428 System.out.println( "OK." );
432 System.out.println( "failed." );
435 System.out.print( "Phylogeny branch: " );
436 if ( Test.testPhylogenyBranch() ) {
437 System.out.println( "OK." );
441 System.out.println( "failed." );
444 System.out.print( "Rerooting: " );
445 if ( Test.testRerooting() ) {
446 System.out.println( "OK." );
450 System.out.println( "failed." );
453 System.out.print( "Mipoint rooting: " );
454 if ( Test.testMidpointrooting() ) {
455 System.out.println( "OK." );
459 System.out.println( "failed." );
462 System.out.print( "Node removal: " );
463 if ( Test.testNodeRemoval() ) {
464 System.out.println( "OK." );
468 System.out.println( "failed." );
471 System.out.print( "Support count: " );
472 if ( Test.testSupportCount() ) {
473 System.out.println( "OK." );
477 System.out.println( "failed." );
480 System.out.print( "Support transfer: " );
481 if ( Test.testSupportTransfer() ) {
482 System.out.println( "OK." );
486 System.out.println( "failed." );
489 System.out.print( "Finding of LCA: " );
490 if ( Test.testGetLCA() ) {
491 System.out.println( "OK." );
495 System.out.println( "failed." );
498 System.out.print( "Finding of LCA 2: " );
499 if ( Test.testGetLCA2() ) {
500 System.out.println( "OK." );
504 System.out.println( "failed." );
507 System.out.print( "Calculation of distance between nodes: " );
508 if ( Test.testGetDistance() ) {
509 System.out.println( "OK." );
513 System.out.println( "failed." );
516 System.out.print( "Descriptive statistics: " );
517 if ( Test.testDescriptiveStatistics() ) {
518 System.out.println( "OK." );
522 System.out.println( "failed." );
525 System.out.print( "Data objects and methods: " );
526 if ( Test.testDataObjects() ) {
527 System.out.println( "OK." );
531 System.out.println( "failed." );
534 System.out.print( "Properties map: " );
535 if ( Test.testPropertiesMap() ) {
536 System.out.println( "OK." );
540 System.out.println( "failed." );
543 System.out.print( "SDIse: " );
544 if ( Test.testSDIse() ) {
545 System.out.println( "OK." );
549 System.out.println( "failed." );
552 System.out.print( "SDIunrooted: " );
553 if ( Test.testSDIunrooted() ) {
554 System.out.println( "OK." );
558 System.out.println( "failed." );
561 System.out.print( "GSDI: " );
562 if ( TestGSDI.test() ) {
563 System.out.println( "OK." );
567 System.out.println( "failed." );
570 System.out.print( "RIO: " );
571 if ( TestRIO.test() ) {
572 System.out.println( "OK." );
576 System.out.println( "failed." );
579 System.out.print( "Phylogeny reconstruction:" );
580 System.out.println();
581 if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
582 System.out.println( "OK." );
586 System.out.println( "failed." );
589 System.out.print( "Analysis of domain architectures: " );
590 System.out.println();
591 if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
592 System.out.println( "OK." );
596 System.out.println( "failed." );
599 System.out.print( "GO: " );
600 System.out.println();
601 if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
602 System.out.println( "OK." );
606 System.out.println( "failed." );
609 System.out.print( "Modeling tools: " );
610 if ( TestPccx.test() ) {
611 System.out.println( "OK." );
615 System.out.println( "failed." );
618 System.out.print( "Split Matrix strict: " );
619 if ( Test.testSplitStrict() ) {
620 System.out.println( "OK." );
624 System.out.println( "failed." );
627 System.out.print( "Split Matrix: " );
628 if ( Test.testSplit() ) {
629 System.out.println( "OK." );
633 System.out.println( "failed." );
636 System.out.print( "Confidence Assessor: " );
637 if ( Test.testConfidenceAssessor() ) {
638 System.out.println( "OK." );
642 System.out.println( "failed." );
645 System.out.print( "Basic table: " );
646 if ( Test.testBasicTable() ) {
647 System.out.println( "OK." );
651 System.out.println( "failed." );
654 System.out.print( "General table: " );
655 if ( Test.testGeneralTable() ) {
656 System.out.println( "OK." );
660 System.out.println( "failed." );
663 System.out.print( "Amino acid sequence: " );
664 if ( Test.testAminoAcidSequence() ) {
665 System.out.println( "OK." );
669 System.out.println( "failed." );
672 System.out.print( "General MSA parser: " );
673 if ( Test.testGeneralMsaParser() ) {
674 System.out.println( "OK." );
678 System.out.println( "failed." );
681 System.out.print( "Fasta parser for msa: " );
682 if ( Test.testFastaParser() ) {
683 System.out.println( "OK." );
687 System.out.println( "failed." );
690 System.out.print( "Creation of balanced phylogeny: " );
691 if ( Test.testCreateBalancedPhylogeny() ) {
692 System.out.println( "OK." );
696 System.out.println( "failed." );
699 System.out.print( "EMBL Entry Retrieval: " );
700 if ( Test.testEmblEntryRetrieval() ) {
701 System.out.println( "OK." );
705 System.out.println( "failed." );
708 System.out.print( "Uniprot Entry Retrieval: " );
709 if ( Test.testUniprotEntryRetrieval() ) {
710 System.out.println( "OK." );
714 System.out.println( "failed." );
717 System.out.print( "Uniprot Taxonomy Search: " );
718 if ( Test.testUniprotTaxonomySearch() ) {
719 System.out.println( "OK." );
723 System.out.println( "failed." );
728 final String os = ForesterUtil.OS_NAME.toLowerCase();
729 if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
730 path = "/usr/local/bin/mafft";
732 else if ( os.indexOf( "win" ) >= 0 ) {
733 path = "C:\\Program Files\\mafft-win\\mafft.bat";
736 path = "/home/czmasek/bin/mafft";
738 if ( !MsaInferrer.isInstalled( path ) ) {
741 if ( !MsaInferrer.isInstalled( path ) ) {
742 path = "/usr/local/bin/mafft";
744 if ( MsaInferrer.isInstalled( path ) ) {
745 System.out.print( "MAFFT (external program): " );
746 if ( Test.testMafft( path ) ) {
747 System.out.println( "OK." );
751 System.out.println( "failed [will not count towards failed tests]" );
755 System.out.print( "Next nodes with collapsed: " );
756 if ( Test.testNextNodeWithCollapsing() ) {
757 System.out.println( "OK." );
761 System.out.println( "failed." );
764 System.out.print( "Simple MSA quality: " );
765 if ( Test.testMsaQualityMethod() ) {
766 System.out.println( "OK." );
770 System.out.println( "failed." );
773 System.out.println();
774 final Runtime rt = java.lang.Runtime.getRuntime();
775 final long free_memory = rt.freeMemory() / 1000000;
776 final long total_memory = rt.totalMemory() / 1000000;
777 System.out.println( "Running time : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
778 + free_memory + "MB, total memory: " + total_memory + "MB)" );
779 System.out.println();
780 System.out.println( "Successful tests: " + succeeded );
781 System.out.println( "Failed tests: " + failed );
782 System.out.println();
784 System.out.println( "OK." );
787 System.out.println( "Not OK." );
791 private static boolean testExtractTaxonomyCodeFromNodeName() {
793 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.YES ).equals( "MOUSE" ) ) {
796 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.YES ).equals( "RAT" ) ) {
799 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.YES ) != null ) {
802 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445", TAXONOMY_EXTRACTION.YES )
803 .equals( "MOUSE" ) ) {
806 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE_function = 23445", TAXONOMY_EXTRACTION.YES )
807 .equals( "MOUSE" ) ) {
810 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445", TAXONOMY_EXTRACTION.YES )
811 .equals( "MOUSE" ) ) {
814 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
817 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
820 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445", TAXONOMY_EXTRACTION.YES )
824 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445", TAXONOMY_EXTRACTION.YES )
828 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445", TAXONOMY_EXTRACTION.YES )
832 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
835 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
838 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.YES ).equals( "RAT" ) ) {
841 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY )
845 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.YES )
846 .equals( "MOUSE" ) ) {
849 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY )
850 .equals( "MOUSE" ) ) {
854 catch ( final Exception e ) {
855 e.printStackTrace( System.out );
861 private static boolean testBasicNodeMethods() {
863 if ( PhylogenyNode.getNodeCount() != 0 ) {
866 final PhylogenyNode n1 = new PhylogenyNode();
867 final PhylogenyNode n2 = PhylogenyNode
868 .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
869 final PhylogenyNode n3 = PhylogenyNode
870 .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
871 final PhylogenyNode n4 = PhylogenyNode
872 .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
873 if ( n1.isHasAssignedEvent() ) {
876 if ( PhylogenyNode.getNodeCount() != 4 ) {
879 if ( n3.getIndicator() != 0 ) {
882 if ( n3.getNumberOfExternalNodes() != 1 ) {
885 if ( !n3.isExternal() ) {
888 if ( !n3.isRoot() ) {
891 if ( !n4.getName().equals( "n4" ) ) {
895 catch ( final Exception e ) {
896 e.printStackTrace( System.out );
902 private static boolean testBasicPhyloXMLparsing() {
904 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
905 final PhyloXmlParser xml_parser = new PhyloXmlParser();
906 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
908 if ( xml_parser.getErrorCount() > 0 ) {
909 System.out.println( xml_parser.getErrorMessages().toString() );
912 if ( phylogenies_0.length != 4 ) {
915 final Phylogeny t1 = phylogenies_0[ 0 ];
916 final Phylogeny t2 = phylogenies_0[ 1 ];
917 final Phylogeny t3 = phylogenies_0[ 2 ];
918 final Phylogeny t4 = phylogenies_0[ 3 ];
919 if ( t1.getNumberOfExternalNodes() != 1 ) {
922 if ( !t1.isRooted() ) {
925 if ( t1.isRerootable() ) {
928 if ( !t1.getType().equals( "gene_tree" ) ) {
931 if ( t2.getNumberOfExternalNodes() != 2 ) {
934 if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
937 if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
940 if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
943 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
946 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
949 if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
952 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
953 .startsWith( "actgtgggggt" ) ) {
956 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
957 .startsWith( "ctgtgatgcat" ) ) {
960 if ( t3.getNumberOfExternalNodes() != 4 ) {
963 if ( !t1.getName().equals( "t1" ) ) {
966 if ( !t2.getName().equals( "t2" ) ) {
969 if ( !t3.getName().equals( "t3" ) ) {
972 if ( !t4.getName().equals( "t4" ) ) {
975 if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
978 if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
981 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
984 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
985 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
988 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
991 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
994 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
997 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
998 .equals( "apoptosis" ) ) {
1001 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1002 .equals( "GO:0006915" ) ) {
1005 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1006 .equals( "UniProtKB" ) ) {
1009 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1010 .equals( "experimental" ) ) {
1013 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1014 .equals( "function" ) ) {
1017 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1018 .getValue() != 1 ) {
1021 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1022 .getType().equals( "ml" ) ) {
1025 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1026 .equals( "apoptosis" ) ) {
1029 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1030 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1033 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1034 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1037 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1038 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1041 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1042 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1045 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1046 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1049 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1050 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1053 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1054 .equals( "GO:0005829" ) ) {
1057 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1058 .equals( "intracellular organelle" ) ) {
1061 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1064 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1065 .equals( "UniProt link" ) ) ) {
1068 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1072 catch ( final Exception e ) {
1073 e.printStackTrace( System.out );
1079 private static boolean testBasicPhyloXMLparsingRoundtrip() {
1081 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1082 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1083 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1084 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1087 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1089 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1091 if ( xml_parser.getErrorCount() > 0 ) {
1092 System.out.println( xml_parser.getErrorMessages().toString() );
1095 if ( phylogenies_0.length != 4 ) {
1098 final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1099 final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1100 if ( phylogenies_t1.length != 1 ) {
1103 final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1104 if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1107 if ( !t1_rt.isRooted() ) {
1110 if ( t1_rt.isRerootable() ) {
1113 if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1116 final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1117 final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1118 final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1119 if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1122 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1125 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1128 if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1131 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1132 .startsWith( "actgtgggggt" ) ) {
1135 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1136 .startsWith( "ctgtgatgcat" ) ) {
1139 final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1140 final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1141 final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1142 final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1143 if ( phylogenies_1.length != 1 ) {
1146 final Phylogeny t3_rt = phylogenies_1[ 0 ];
1147 if ( !t3_rt.getName().equals( "t3" ) ) {
1150 if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1153 if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1156 if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1159 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1162 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1163 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1166 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1169 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1172 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1173 .equals( "UniProtKB" ) ) {
1176 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1177 .equals( "apoptosis" ) ) {
1180 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1181 .equals( "GO:0006915" ) ) {
1184 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1185 .equals( "UniProtKB" ) ) {
1188 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1189 .equals( "experimental" ) ) {
1192 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1193 .equals( "function" ) ) {
1196 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1197 .getValue() != 1 ) {
1200 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1201 .getType().equals( "ml" ) ) {
1204 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1205 .equals( "apoptosis" ) ) {
1208 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1209 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1212 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1213 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1216 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1217 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1220 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1221 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1224 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1225 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1228 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1229 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1232 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1233 .equals( "GO:0005829" ) ) {
1236 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1237 .equals( "intracellular organelle" ) ) {
1240 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1243 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1244 .equals( "UniProt link" ) ) ) {
1247 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1250 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1253 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1254 .equals( "Aguinaldo, A. M. A.; J. M. Turbeville, L. S. Linford, M. C. Rivera, J. R. Garey, R. A. Raff, & J. A. Lake (1997). \"Evidence for a clade of nematodes, arthropods and other moulting animals\". Nature 387 (6632): 489–493." ) ) ) {
1257 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1260 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1263 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1266 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1269 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1270 .equals( "ncbi" ) ) {
1273 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1276 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1277 .getName().equals( "B" ) ) {
1280 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1281 .getFrom() != 21 ) {
1284 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1287 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1288 .getLength() != 24 ) {
1291 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1292 .getConfidence() != 2144 ) {
1295 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1296 .equals( "pfam" ) ) {
1299 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1302 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1305 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1308 if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1311 final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1312 if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1315 if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1318 if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1321 if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1324 if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1327 if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1330 if ( taxbb.getSynonyms().size() != 2 ) {
1333 if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1336 if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1339 if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1342 if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1345 if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1348 if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1349 .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1353 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1356 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1359 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1362 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1365 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1368 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1371 if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1375 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1378 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1379 .equalsIgnoreCase( "435" ) ) {
1382 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1385 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1386 .equalsIgnoreCase( "443.7" ) ) {
1389 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1392 if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1395 if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1396 .equalsIgnoreCase( "433" ) ) {
1400 catch ( final Exception e ) {
1401 e.printStackTrace( System.out );
1407 private static boolean testBasicPhyloXMLparsingValidating() {
1409 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1410 PhyloXmlParser xml_parser = null;
1412 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1414 catch ( final Exception e ) {
1415 // Do nothing -- means were not running from jar.
1417 if ( xml_parser == null ) {
1418 xml_parser = new PhyloXmlParser();
1419 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1420 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1423 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1426 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1428 if ( xml_parser.getErrorCount() > 0 ) {
1429 System.out.println( xml_parser.getErrorMessages().toString() );
1432 if ( phylogenies_0.length != 4 ) {
1435 final Phylogeny t1 = phylogenies_0[ 0 ];
1436 final Phylogeny t2 = phylogenies_0[ 1 ];
1437 final Phylogeny t3 = phylogenies_0[ 2 ];
1438 final Phylogeny t4 = phylogenies_0[ 3 ];
1439 if ( !t1.getName().equals( "t1" ) ) {
1442 if ( !t2.getName().equals( "t2" ) ) {
1445 if ( !t3.getName().equals( "t3" ) ) {
1448 if ( !t4.getName().equals( "t4" ) ) {
1451 if ( t1.getNumberOfExternalNodes() != 1 ) {
1454 if ( t2.getNumberOfExternalNodes() != 2 ) {
1457 if ( t3.getNumberOfExternalNodes() != 4 ) {
1460 final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1461 final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1462 if ( xml_parser.getErrorCount() > 0 ) {
1463 System.out.println( "errors:" );
1464 System.out.println( xml_parser.getErrorMessages().toString() );
1467 if ( phylogenies_1.length != 4 ) {
1470 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1472 if ( xml_parser.getErrorCount() > 0 ) {
1473 System.out.println( "errors:" );
1474 System.out.println( xml_parser.getErrorMessages().toString() );
1477 if ( phylogenies_2.length != 1 ) {
1480 if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1483 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1485 if ( xml_parser.getErrorCount() > 0 ) {
1486 System.out.println( xml_parser.getErrorMessages().toString() );
1489 if ( phylogenies_3.length != 2 ) {
1492 final Phylogeny a = phylogenies_3[ 0 ];
1493 if ( !a.getName().equals( "tree 4" ) ) {
1496 if ( a.getNumberOfExternalNodes() != 3 ) {
1499 if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1502 if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1505 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1507 if ( xml_parser.getErrorCount() > 0 ) {
1508 System.out.println( xml_parser.getErrorMessages().toString() );
1511 if ( phylogenies_4.length != 1 ) {
1514 final Phylogeny s = phylogenies_4[ 0 ];
1515 if ( s.getNumberOfExternalNodes() != 6 ) {
1518 s.getNode( "first" );
1520 s.getNode( "\"<a'b&c'd\">\"" );
1521 s.getNode( "'''\"" );
1522 s.getNode( "\"\"\"" );
1523 s.getNode( "dick & doof" );
1525 catch ( final Exception e ) {
1526 e.printStackTrace( System.out );
1532 private static boolean testBasicTable() {
1534 final BasicTable<String> t0 = new BasicTable<String>();
1535 if ( t0.getNumberOfColumns() != 0 ) {
1538 if ( t0.getNumberOfRows() != 0 ) {
1541 t0.setValue( 3, 2, "23" );
1542 t0.setValue( 10, 1, "error" );
1543 t0.setValue( 10, 1, "110" );
1544 t0.setValue( 9, 1, "19" );
1545 t0.setValue( 1, 10, "101" );
1546 t0.setValue( 10, 10, "1010" );
1547 t0.setValue( 100, 10, "10100" );
1548 t0.setValue( 0, 0, "00" );
1549 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1552 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1555 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1558 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1561 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1564 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1567 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1570 if ( t0.getNumberOfColumns() != 101 ) {
1573 if ( t0.getNumberOfRows() != 11 ) {
1576 if ( t0.getValueAsString( 49, 4 ) != null ) {
1579 final String l = ForesterUtil.getLineSeparator();
1580 final StringBuffer source = new StringBuffer();
1581 source.append( "" + l );
1582 source.append( "# 1 1 1 1 1 1 1 1" + l );
1583 source.append( " 00 01 02 03" + l );
1584 source.append( " 10 11 12 13 " + l );
1585 source.append( "20 21 22 23 " + l );
1586 source.append( " 30 31 32 33" + l );
1587 source.append( "40 41 42 43" + l );
1588 source.append( " # 1 1 1 1 1 " + l );
1589 source.append( "50 51 52 53 54" + l );
1590 final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), " " );
1591 if ( t1.getNumberOfColumns() != 5 ) {
1594 if ( t1.getNumberOfRows() != 6 ) {
1597 if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1600 if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1603 if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1606 if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1609 final StringBuffer source1 = new StringBuffer();
1610 source1.append( "" + l );
1611 source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1612 source1.append( " 00; 01 ;02;03" + l );
1613 source1.append( " 10; 11; 12; 13 " + l );
1614 source1.append( "20; 21; 22; 23 " + l );
1615 source1.append( " 30; 31; 32; 33" + l );
1616 source1.append( "40;41;42;43" + l );
1617 source1.append( " # 1 1 1 1 1 " + l );
1618 source1.append( ";;;50 ; ;52; 53;;54 " + l );
1619 final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ";" );
1620 if ( t2.getNumberOfColumns() != 5 ) {
1623 if ( t2.getNumberOfRows() != 6 ) {
1626 if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1629 if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1632 if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1635 if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1638 if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1641 if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1644 final StringBuffer source2 = new StringBuffer();
1645 source2.append( "" + l );
1646 source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1647 source2.append( " 00; 01 ;02;03" + l );
1648 source2.append( " 10; 11; 12; 13 " + l );
1649 source2.append( "20; 21; 22; 23 " + l );
1650 source2.append( " " + l );
1651 source2.append( " 30; 31; 32; 33" + l );
1652 source2.append( "40;41;42;43" + l );
1653 source2.append( " comment: 1 1 1 1 1 " + l );
1654 source2.append( ";;;50 ; 52; 53;;54 " + l );
1655 final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1661 if ( tl.size() != 2 ) {
1664 final BasicTable<String> t3 = tl.get( 0 );
1665 final BasicTable<String> t4 = tl.get( 1 );
1666 if ( t3.getNumberOfColumns() != 4 ) {
1669 if ( t3.getNumberOfRows() != 3 ) {
1672 if ( t4.getNumberOfColumns() != 4 ) {
1675 if ( t4.getNumberOfRows() != 3 ) {
1678 if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1681 if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
1685 catch ( final Exception e ) {
1686 e.printStackTrace( System.out );
1692 private static boolean testBasicTolXMLparsing() {
1694 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1695 final TolParser parser = new TolParser();
1696 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
1697 if ( parser.getErrorCount() > 0 ) {
1698 System.out.println( parser.getErrorMessages().toString() );
1701 if ( phylogenies_0.length != 1 ) {
1704 final Phylogeny t1 = phylogenies_0[ 0 ];
1705 if ( t1.getNumberOfExternalNodes() != 5 ) {
1708 if ( !t1.isRooted() ) {
1711 if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
1714 if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
1717 if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
1720 if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
1723 final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
1724 if ( parser.getErrorCount() > 0 ) {
1725 System.out.println( parser.getErrorMessages().toString() );
1728 if ( phylogenies_1.length != 1 ) {
1731 final Phylogeny t2 = phylogenies_1[ 0 ];
1732 if ( t2.getNumberOfExternalNodes() != 664 ) {
1735 if ( !t2.isRooted() ) {
1738 if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
1741 if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
1744 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
1747 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
1750 if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
1753 if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
1754 .equals( "Aquifex" ) ) {
1757 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
1758 if ( parser.getErrorCount() > 0 ) {
1759 System.out.println( parser.getErrorMessages().toString() );
1762 if ( phylogenies_2.length != 1 ) {
1765 final Phylogeny t3 = phylogenies_2[ 0 ];
1766 if ( t3.getNumberOfExternalNodes() != 184 ) {
1769 if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
1772 if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
1775 if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
1778 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
1779 if ( parser.getErrorCount() > 0 ) {
1780 System.out.println( parser.getErrorMessages().toString() );
1783 if ( phylogenies_3.length != 1 ) {
1786 final Phylogeny t4 = phylogenies_3[ 0 ];
1787 if ( t4.getNumberOfExternalNodes() != 1 ) {
1790 if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
1793 if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
1796 if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
1799 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
1800 if ( parser.getErrorCount() > 0 ) {
1801 System.out.println( parser.getErrorMessages().toString() );
1804 if ( phylogenies_4.length != 1 ) {
1807 final Phylogeny t5 = phylogenies_4[ 0 ];
1808 if ( t5.getNumberOfExternalNodes() != 13 ) {
1811 if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
1814 if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
1817 if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
1821 catch ( final Exception e ) {
1822 e.printStackTrace( System.out );
1828 private static boolean testBasicTreeMethods() {
1830 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1831 final Phylogeny t1 = factory.create();
1832 if ( !t1.isEmpty() ) {
1835 final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
1836 if ( t2.getNumberOfExternalNodes() != 4 ) {
1839 if ( t2.getHeight() != 8.5 ) {
1842 if ( !t2.isCompletelyBinary() ) {
1845 if ( t2.isEmpty() ) {
1848 final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
1849 if ( t3.getNumberOfExternalNodes() != 5 ) {
1852 if ( t3.getHeight() != 11 ) {
1855 if ( t3.isCompletelyBinary() ) {
1858 final PhylogenyNode n = t3.getNode( "ABC" );
1859 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 ];
1860 if ( t4.getNumberOfExternalNodes() != 9 ) {
1863 if ( t4.getHeight() != 11 ) {
1866 if ( t4.isCompletelyBinary() ) {
1869 final StringBuffer sb5 = new StringBuffer( "(((A11:2)A1:2,(A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:3,D:8)" );
1870 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
1871 if ( t5.getNumberOfExternalNodes() != 8 ) {
1874 if ( t5.getHeight() != 15 ) {
1877 final StringBuffer sb6 = new StringBuffer( "(X,Y,Z,(((A111)A11:2)A1:2,(X,Y,Z,A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:3,D:8)" );
1878 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
1879 if ( t6.getHeight() != 15 ) {
1882 final StringBuffer sb7 = new StringBuffer( "(((A11:2)A1:2,(A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:15,D:8)" );
1883 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
1884 if ( t7.getHeight() != 15 ) {
1887 final StringBuffer sb8 = new StringBuffer( "(((A11:11)A1:2,(A21:2,A22:2,A23,A24,AA:)A2:11,A3:2)A:2,B:15,C:15,D:15)" );
1888 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
1889 if ( t8.getNumberOfExternalNodes() != 10 ) {
1892 if ( t8.getHeight() != 15 ) {
1895 final char[] a9 = new char[] {};
1896 final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
1897 if ( t9.getHeight() != 0 ) {
1900 final char[] a10 = new char[] { 'a', ':', '6' };
1901 final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
1902 if ( t10.getHeight() != 6 ) {
1906 catch ( final Exception e ) {
1907 e.printStackTrace( System.out );
1913 private static boolean testConfidenceAssessor() {
1915 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1916 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1917 final Phylogeny[] ev0 = factory
1918 .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
1920 ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
1921 if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
1924 if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
1927 final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1928 final Phylogeny[] ev1 = factory
1929 .create( "((((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)));",
1931 ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
1932 if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
1935 if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1938 final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
1939 final Phylogeny[] ev_b = factory
1940 .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",
1942 ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
1943 if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
1946 if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1950 final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1951 final Phylogeny[] ev1x = factory
1952 .create( "((((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)));",
1954 ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
1955 if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1958 if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1961 final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
1962 final Phylogeny[] ev_bx = factory
1963 .create( "((((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",
1965 ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
1966 if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1969 if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1973 final Phylogeny[] t2 = factory
1974 .create( "((((a,b),c),d),e);(((a,b),c),(d,e));(((((a,b),c),d),e),f);((((a,b),c),(d,e)),f);(((a,b),c),d,e);((a,b,c),d,e);",
1976 final Phylogeny[] ev2 = factory
1977 .create( "((((a,b),c),d),e);((((a,b),c),d),e);((((a,b),e),d),c);((((a,b),e),d),c);(((a,b),(c,d)),e);((a,b),x);((a,b),(x,y));(a,b);(a,e);(a,b,c);",
1979 for( final Phylogeny target : t2 ) {
1980 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
1983 final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
1984 new NHXParser() )[ 0 ];
1985 final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
1986 ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
1987 if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1990 if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
1993 if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1997 catch ( final Exception e ) {
1998 e.printStackTrace();
2004 private static boolean testCopyOfNodeData() {
2006 final PhylogenyNode n1 = PhylogenyNode
2007 .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1:O=22:SO=33:SN=44:W=2:C=10.20.30:XN=S=tag1=value1=unit1]" );
2008 final PhylogenyNode n2 = n1.copyNodeData();
2009 if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2013 catch ( final Exception e ) {
2014 e.printStackTrace();
2020 private static boolean testDataObjects() {
2022 final Confidence s0 = new Confidence();
2023 final Confidence s1 = new Confidence();
2024 if ( !s0.isEqual( s1 ) ) {
2027 final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2028 final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2029 if ( s2.isEqual( s1 ) ) {
2032 if ( !s2.isEqual( s3 ) ) {
2035 final Confidence s4 = ( Confidence ) s3.copy();
2036 if ( !s4.isEqual( s3 ) ) {
2043 final Taxonomy t1 = new Taxonomy();
2044 final Taxonomy t2 = new Taxonomy();
2045 final Taxonomy t3 = new Taxonomy();
2046 final Taxonomy t4 = new Taxonomy();
2047 final Taxonomy t5 = new Taxonomy();
2048 t1.setIdentifier( new Identifier( "ecoli" ) );
2049 t1.setTaxonomyCode( "ECOLI" );
2050 t1.setScientificName( "E. coli" );
2051 t1.setCommonName( "coli" );
2052 final Taxonomy t0 = ( Taxonomy ) t1.copy();
2053 if ( !t1.isEqual( t0 ) ) {
2056 t2.setIdentifier( new Identifier( "ecoli" ) );
2057 t2.setTaxonomyCode( "OTHER" );
2058 t2.setScientificName( "what" );
2059 t2.setCommonName( "something" );
2060 if ( !t1.isEqual( t2 ) ) {
2063 t2.setIdentifier( new Identifier( "nemve" ) );
2064 if ( t1.isEqual( t2 ) ) {
2067 t1.setIdentifier( null );
2068 t3.setTaxonomyCode( "ECOLI" );
2069 t3.setScientificName( "what" );
2070 t3.setCommonName( "something" );
2071 if ( !t1.isEqual( t3 ) ) {
2074 t1.setIdentifier( null );
2075 t1.setTaxonomyCode( "" );
2076 t4.setScientificName( "E. ColI" );
2077 t4.setCommonName( "something" );
2078 if ( !t1.isEqual( t4 ) ) {
2081 t4.setScientificName( "B. subtilis" );
2082 t4.setCommonName( "something" );
2083 if ( t1.isEqual( t4 ) ) {
2086 t1.setIdentifier( null );
2087 t1.setTaxonomyCode( "" );
2088 t1.setScientificName( "" );
2089 t5.setCommonName( "COLI" );
2090 if ( !t1.isEqual( t5 ) ) {
2093 t5.setCommonName( "vibrio" );
2094 if ( t1.isEqual( t5 ) ) {
2099 final Identifier id0 = new Identifier( "123", "pfam" );
2100 final Identifier id1 = ( Identifier ) id0.copy();
2101 if ( !id1.isEqual( id1 ) ) {
2104 if ( !id1.isEqual( id0 ) ) {
2107 if ( !id0.isEqual( id1 ) ) {
2114 final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2115 final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2116 if ( !pd1.isEqual( pd1 ) ) {
2119 if ( !pd1.isEqual( pd0 ) ) {
2124 final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2125 final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2126 if ( !pd3.isEqual( pd3 ) ) {
2129 if ( !pd2.isEqual( pd3 ) ) {
2132 if ( !pd0.isEqual( pd3 ) ) {
2137 // DomainArchitecture
2138 // ------------------
2139 final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2140 final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2141 final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2142 final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2143 final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2144 final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2149 final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2150 if ( ds0.getNumberOfDomains() != 4 ) {
2153 final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2154 if ( !ds0.isEqual( ds0 ) ) {
2157 if ( !ds0.isEqual( ds1 ) ) {
2160 if ( ds1.getNumberOfDomains() != 4 ) {
2163 final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2168 final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2169 if ( ds0.isEqual( ds2 ) ) {
2175 final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2176 if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2177 System.out.println( ds3.toNHX() );
2180 if ( ds3.getNumberOfDomains() != 3 ) {
2185 final Event e1 = new Event( Event.EventType.fusion );
2186 if ( e1.isDuplication() ) {
2189 if ( !e1.isFusion() ) {
2192 if ( !e1.asText().toString().equals( "fusion" ) ) {
2195 if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2198 final Event e11 = new Event( Event.EventType.fusion );
2199 if ( !e11.isEqual( e1 ) ) {
2202 if ( !e11.toNHX().toString().equals( "" ) ) {
2205 final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2206 if ( e2.isDuplication() ) {
2209 if ( !e2.isSpeciationOrDuplication() ) {
2212 if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2215 if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2218 if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2221 if ( e11.isEqual( e2 ) ) {
2224 final Event e2c = ( Event ) e2.copy();
2225 if ( !e2c.isEqual( e2 ) ) {
2228 Event e3 = new Event( 1, 2, 3 );
2229 if ( e3.isDuplication() ) {
2232 if ( e3.isSpeciation() ) {
2235 if ( e3.isGeneLoss() ) {
2238 if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2241 final Event e3c = ( Event ) e3.copy();
2242 final Event e3cc = ( Event ) e3c.copy();
2243 if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2247 if ( !e3c.isEqual( e3cc ) ) {
2250 Event e4 = new Event( 1, 2, 3 );
2251 if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2254 if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2257 final Event e4c = ( Event ) e4.copy();
2259 final Event e4cc = ( Event ) e4c.copy();
2260 if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2263 if ( !e4c.isEqual( e4cc ) ) {
2266 final Event e5 = new Event();
2267 if ( !e5.isUnassigned() ) {
2270 if ( !e5.asText().toString().equals( "unassigned" ) ) {
2273 if ( !e5.asSimpleText().toString().equals( "" ) ) {
2276 final Event e6 = new Event( 1, 0, 0 );
2277 if ( !e6.asText().toString().equals( "duplication" ) ) {
2280 if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2283 final Event e7 = new Event( 0, 1, 0 );
2284 if ( !e7.asText().toString().equals( "speciation" ) ) {
2287 if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2290 final Event e8 = new Event( 0, 0, 1 );
2291 if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2294 if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2298 catch ( final Exception e ) {
2299 e.printStackTrace( System.out );
2305 private static boolean testDeletionOfExternalNodes() {
2307 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2308 final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2309 final PhylogenyWriter w = new PhylogenyWriter();
2310 if ( t0.isEmpty() ) {
2313 if ( t0.getNumberOfExternalNodes() != 1 ) {
2316 t0.deleteSubtree( t0.getNode( "A" ), false );
2317 if ( t0.getNumberOfExternalNodes() != 0 ) {
2320 if ( !t0.isEmpty() ) {
2323 final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2324 if ( t1.getNumberOfExternalNodes() != 2 ) {
2327 t1.deleteSubtree( t1.getNode( "A" ), false );
2328 if ( t1.getNumberOfExternalNodes() != 1 ) {
2331 if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2334 t1.deleteSubtree( t1.getNode( "B" ), false );
2335 if ( t1.getNumberOfExternalNodes() != 1 ) {
2338 t1.deleteSubtree( t1.getNode( "r" ), false );
2339 if ( !t1.isEmpty() ) {
2342 final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2343 if ( t2.getNumberOfExternalNodes() != 3 ) {
2346 t2.deleteSubtree( t2.getNode( "B" ), false );
2347 if ( t2.getNumberOfExternalNodes() != 2 ) {
2350 t2.toNewHampshireX();
2351 PhylogenyNode n = t2.getNode( "A" );
2352 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2355 t2.deleteSubtree( t2.getNode( "A" ), false );
2356 if ( t2.getNumberOfExternalNodes() != 2 ) {
2359 t2.deleteSubtree( t2.getNode( "C" ), true );
2360 if ( t2.getNumberOfExternalNodes() != 1 ) {
2363 final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2364 if ( t3.getNumberOfExternalNodes() != 4 ) {
2367 t3.deleteSubtree( t3.getNode( "B" ), true );
2368 if ( t3.getNumberOfExternalNodes() != 3 ) {
2371 n = t3.getNode( "A" );
2372 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2375 n = n.getNextExternalNode();
2376 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2379 t3.deleteSubtree( t3.getNode( "A" ), true );
2380 if ( t3.getNumberOfExternalNodes() != 2 ) {
2383 n = t3.getNode( "C" );
2384 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2387 t3.deleteSubtree( t3.getNode( "C" ), true );
2388 if ( t3.getNumberOfExternalNodes() != 1 ) {
2391 t3.deleteSubtree( t3.getNode( "D" ), true );
2392 if ( t3.getNumberOfExternalNodes() != 0 ) {
2395 final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2396 if ( t4.getNumberOfExternalNodes() != 6 ) {
2399 t4.deleteSubtree( t4.getNode( "B2" ), true );
2400 if ( t4.getNumberOfExternalNodes() != 5 ) {
2403 String s = w.toNewHampshire( t4, false, true ).toString();
2404 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2407 t4.deleteSubtree( t4.getNode( "B11" ), true );
2408 if ( t4.getNumberOfExternalNodes() != 4 ) {
2411 t4.deleteSubtree( t4.getNode( "C" ), true );
2412 if ( t4.getNumberOfExternalNodes() != 3 ) {
2415 n = t4.getNode( "A" );
2416 n = n.getNextExternalNode();
2417 if ( !n.getName().equals( "B12" ) ) {
2420 n = n.getNextExternalNode();
2421 if ( !n.getName().equals( "D" ) ) {
2424 s = w.toNewHampshire( t4, false, true ).toString();
2425 if ( !s.equals( "((A,B12),D);" ) ) {
2428 final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2429 t5.deleteSubtree( t5.getNode( "A" ), true );
2430 if ( t5.getNumberOfExternalNodes() != 5 ) {
2433 s = w.toNewHampshire( t5, false, true ).toString();
2434 if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2437 final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2438 t6.deleteSubtree( t6.getNode( "B11" ), true );
2439 if ( t6.getNumberOfExternalNodes() != 5 ) {
2442 s = w.toNewHampshire( t6, false, false ).toString();
2443 if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2446 final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2447 t7.deleteSubtree( t7.getNode( "B12" ), true );
2448 if ( t7.getNumberOfExternalNodes() != 5 ) {
2451 s = w.toNewHampshire( t7, false, true ).toString();
2452 if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2455 final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2456 t8.deleteSubtree( t8.getNode( "B2" ), true );
2457 if ( t8.getNumberOfExternalNodes() != 5 ) {
2460 s = w.toNewHampshire( t8, false, false ).toString();
2461 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2464 final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2465 t9.deleteSubtree( t9.getNode( "C" ), true );
2466 if ( t9.getNumberOfExternalNodes() != 5 ) {
2469 s = w.toNewHampshire( t9, false, true ).toString();
2470 if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2473 final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2474 t10.deleteSubtree( t10.getNode( "D" ), true );
2475 if ( t10.getNumberOfExternalNodes() != 5 ) {
2478 s = w.toNewHampshire( t10, false, true ).toString();
2479 if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2482 final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2483 t11.deleteSubtree( t11.getNode( "A" ), true );
2484 if ( t11.getNumberOfExternalNodes() != 2 ) {
2487 s = w.toNewHampshire( t11, false, true ).toString();
2488 if ( !s.equals( "(B,C);" ) ) {
2491 t11.deleteSubtree( t11.getNode( "C" ), true );
2492 if ( t11.getNumberOfExternalNodes() != 1 ) {
2495 s = w.toNewHampshire( t11, false, false ).toString();
2496 if ( !s.equals( "B;" ) ) {
2499 final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2500 t12.deleteSubtree( t12.getNode( "B2" ), true );
2501 if ( t12.getNumberOfExternalNodes() != 8 ) {
2504 s = w.toNewHampshire( t12, false, true ).toString();
2505 if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2508 t12.deleteSubtree( t12.getNode( "B3" ), true );
2509 if ( t12.getNumberOfExternalNodes() != 7 ) {
2512 s = w.toNewHampshire( t12, false, true ).toString();
2513 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2516 t12.deleteSubtree( t12.getNode( "C3" ), true );
2517 if ( t12.getNumberOfExternalNodes() != 6 ) {
2520 s = w.toNewHampshire( t12, false, true ).toString();
2521 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2524 t12.deleteSubtree( t12.getNode( "A1" ), true );
2525 if ( t12.getNumberOfExternalNodes() != 5 ) {
2528 s = w.toNewHampshire( t12, false, true ).toString();
2529 if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2532 t12.deleteSubtree( t12.getNode( "B1" ), true );
2533 if ( t12.getNumberOfExternalNodes() != 4 ) {
2536 s = w.toNewHampshire( t12, false, true ).toString();
2537 if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2540 t12.deleteSubtree( t12.getNode( "A3" ), true );
2541 if ( t12.getNumberOfExternalNodes() != 3 ) {
2544 s = w.toNewHampshire( t12, false, true ).toString();
2545 if ( !s.equals( "(A2,(C1,C2));" ) ) {
2548 t12.deleteSubtree( t12.getNode( "A2" ), true );
2549 if ( t12.getNumberOfExternalNodes() != 2 ) {
2552 s = w.toNewHampshire( t12, false, true ).toString();
2553 if ( !s.equals( "(C1,C2);" ) ) {
2556 final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2557 t13.deleteSubtree( t13.getNode( "D" ), true );
2558 if ( t13.getNumberOfExternalNodes() != 4 ) {
2561 s = w.toNewHampshire( t13, false, true ).toString();
2562 if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2565 final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2566 t14.deleteSubtree( t14.getNode( "E" ), true );
2567 if ( t14.getNumberOfExternalNodes() != 5 ) {
2570 s = w.toNewHampshire( t14, false, true ).toString();
2571 if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2574 final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2575 t15.deleteSubtree( t15.getNode( "B2" ), true );
2576 if ( t15.getNumberOfExternalNodes() != 11 ) {
2579 t15.deleteSubtree( t15.getNode( "B1" ), true );
2580 if ( t15.getNumberOfExternalNodes() != 10 ) {
2583 t15.deleteSubtree( t15.getNode( "B3" ), true );
2584 if ( t15.getNumberOfExternalNodes() != 9 ) {
2587 t15.deleteSubtree( t15.getNode( "B4" ), true );
2588 if ( t15.getNumberOfExternalNodes() != 8 ) {
2591 t15.deleteSubtree( t15.getNode( "A1" ), true );
2592 if ( t15.getNumberOfExternalNodes() != 7 ) {
2595 t15.deleteSubtree( t15.getNode( "C4" ), true );
2596 if ( t15.getNumberOfExternalNodes() != 6 ) {
2600 catch ( final Exception e ) {
2601 e.printStackTrace( System.out );
2607 private static boolean testDescriptiveStatistics() {
2609 final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2610 dss1.addValue( 82 );
2611 dss1.addValue( 78 );
2612 dss1.addValue( 70 );
2613 dss1.addValue( 58 );
2614 dss1.addValue( 42 );
2615 if ( dss1.getN() != 5 ) {
2618 if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2621 if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2624 if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2627 if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2630 if ( !Test.isEqual( dss1.median(), 70 ) ) {
2633 if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2636 if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2639 if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2642 if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2645 if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2648 if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2651 dss1.addValue( 123 );
2652 if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
2655 if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
2658 if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
2661 final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
2662 dss2.addValue( -1.85 );
2663 dss2.addValue( 57.5 );
2664 dss2.addValue( 92.78 );
2665 dss2.addValue( 57.78 );
2666 if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
2669 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
2672 final double[] a = dss2.getDataAsDoubleArray();
2673 if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
2676 dss2.addValue( -100 );
2677 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
2680 if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
2683 final double[] ds = new double[ 14 ];
2698 final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
2699 if ( bins.length != 4 ) {
2702 if ( bins[ 0 ] != 2 ) {
2705 if ( bins[ 1 ] != 3 ) {
2708 if ( bins[ 2 ] != 4 ) {
2711 if ( bins[ 3 ] != 5 ) {
2714 final double[] ds1 = new double[ 9 ];
2724 final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
2725 if ( bins1.length != 4 ) {
2728 if ( bins1[ 0 ] != 2 ) {
2731 if ( bins1[ 1 ] != 3 ) {
2734 if ( bins1[ 2 ] != 0 ) {
2737 if ( bins1[ 3 ] != 4 ) {
2740 final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
2741 if ( bins1_1.length != 3 ) {
2744 if ( bins1_1[ 0 ] != 3 ) {
2747 if ( bins1_1[ 1 ] != 2 ) {
2750 if ( bins1_1[ 2 ] != 4 ) {
2753 final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
2754 if ( bins1_2.length != 3 ) {
2757 if ( bins1_2[ 0 ] != 2 ) {
2760 if ( bins1_2[ 1 ] != 2 ) {
2763 if ( bins1_2[ 2 ] != 2 ) {
2766 final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
2780 dss3.addValue( 10 );
2781 dss3.addValue( 10 );
2782 dss3.addValue( 10 );
2783 final AsciiHistogram histo = new AsciiHistogram( dss3 );
2784 histo.toStringBuffer( 10, '=', 40, 5 );
2785 histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
2787 catch ( final Exception e ) {
2788 e.printStackTrace( System.out );
2794 private static boolean testDir( final String file ) {
2796 final File f = new File( file );
2797 if ( !f.exists() ) {
2800 if ( !f.isDirectory() ) {
2803 if ( !f.canRead() ) {
2807 catch ( final Exception e ) {
2813 private static boolean testExternalNodeRelatedMethods() {
2815 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2816 final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2817 PhylogenyNode n = t1.getNode( "A" );
2818 n = n.getNextExternalNode();
2819 if ( !n.getName().equals( "B" ) ) {
2822 n = n.getNextExternalNode();
2823 if ( !n.getName().equals( "C" ) ) {
2826 n = n.getNextExternalNode();
2827 if ( !n.getName().equals( "D" ) ) {
2830 n = t1.getNode( "B" );
2831 while ( !n.isLastExternalNode() ) {
2832 n = n.getNextExternalNode();
2834 final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
2835 n = t2.getNode( "A" );
2836 n = n.getNextExternalNode();
2837 if ( !n.getName().equals( "B" ) ) {
2840 n = n.getNextExternalNode();
2841 if ( !n.getName().equals( "C" ) ) {
2844 n = n.getNextExternalNode();
2845 if ( !n.getName().equals( "D" ) ) {
2848 n = t2.getNode( "B" );
2849 while ( !n.isLastExternalNode() ) {
2850 n = n.getNextExternalNode();
2852 final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
2853 n = t3.getNode( "A" );
2854 n = n.getNextExternalNode();
2855 if ( !n.getName().equals( "B" ) ) {
2858 n = n.getNextExternalNode();
2859 if ( !n.getName().equals( "C" ) ) {
2862 n = n.getNextExternalNode();
2863 if ( !n.getName().equals( "D" ) ) {
2866 n = n.getNextExternalNode();
2867 if ( !n.getName().equals( "E" ) ) {
2870 n = n.getNextExternalNode();
2871 if ( !n.getName().equals( "F" ) ) {
2874 n = n.getNextExternalNode();
2875 if ( !n.getName().equals( "G" ) ) {
2878 n = n.getNextExternalNode();
2879 if ( !n.getName().equals( "H" ) ) {
2882 n = t3.getNode( "B" );
2883 while ( !n.isLastExternalNode() ) {
2884 n = n.getNextExternalNode();
2886 final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2887 for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
2888 final PhylogenyNode node = iter.next();
2890 final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
2891 for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
2892 final PhylogenyNode node = iter.next();
2894 final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
2895 final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
2896 if ( !iter.next().getName().equals( "A" ) ) {
2899 if ( !iter.next().getName().equals( "B" ) ) {
2902 if ( !iter.next().getName().equals( "C" ) ) {
2905 if ( !iter.next().getName().equals( "D" ) ) {
2908 if ( !iter.next().getName().equals( "E" ) ) {
2911 if ( !iter.next().getName().equals( "F" ) ) {
2914 if ( iter.hasNext() ) {
2918 catch ( final Exception e ) {
2919 e.printStackTrace( System.out );
2925 private static boolean testGeneralTable() {
2927 final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
2928 t0.setValue( 3, 2, "23" );
2929 t0.setValue( 10, 1, "error" );
2930 t0.setValue( 10, 1, "110" );
2931 t0.setValue( 9, 1, "19" );
2932 t0.setValue( 1, 10, "101" );
2933 t0.setValue( 10, 10, "1010" );
2934 t0.setValue( 100, 10, "10100" );
2935 t0.setValue( 0, 0, "00" );
2936 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2939 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2942 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2945 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2948 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2951 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2954 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2957 if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
2960 if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
2963 final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
2964 t1.setValue( "3", "2", "23" );
2965 t1.setValue( "10", "1", "error" );
2966 t1.setValue( "10", "1", "110" );
2967 t1.setValue( "9", "1", "19" );
2968 t1.setValue( "1", "10", "101" );
2969 t1.setValue( "10", "10", "1010" );
2970 t1.setValue( "100", "10", "10100" );
2971 t1.setValue( "0", "0", "00" );
2972 t1.setValue( "qwerty", "zxcvbnm", "asdef" );
2973 if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
2976 if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
2979 if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
2982 if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
2985 if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
2988 if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
2991 if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
2994 if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
2997 if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3000 if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3004 catch ( final Exception e ) {
3005 e.printStackTrace( System.out );
3011 private static boolean testGetDistance() {
3013 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3014 final Phylogeny p1 = factory.create( "(((A:1,B:2,X:100)ab:3,C:4)abc:5,(D:7,(E:9,F:10)ef:8)def:6)r",
3015 new NHXParser() )[ 0 ];
3016 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3019 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3022 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3025 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3028 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3031 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3034 if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3037 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3040 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3043 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3046 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3049 if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3052 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3055 if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3058 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3061 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3064 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3067 if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3070 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3073 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3076 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3079 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3082 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3085 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3088 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3091 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3094 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3097 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3100 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3103 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3106 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3109 final Phylogeny p2 = factory.create( "((A:4,B:5,C:6)abc:1,(D:7,E:8,F:9)def:2,(G:10,H:11,I:12)ghi:3)r",
3110 new NHXParser() )[ 0 ];
3111 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3114 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3117 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3120 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3123 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3126 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3129 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3132 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3135 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3138 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3141 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3145 catch ( final Exception e ) {
3146 e.printStackTrace( System.out );
3152 private static boolean testGetLCA() {
3154 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3155 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3156 new NHXParser() )[ 0 ];
3157 final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3158 if ( !A.getName().equals( "A" ) ) {
3161 final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3162 if ( !gh.getName().equals( "gh" ) ) {
3165 final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3166 if ( !ab.getName().equals( "ab" ) ) {
3169 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3170 if ( !ab2.getName().equals( "ab" ) ) {
3173 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3174 if ( !gh2.getName().equals( "gh" ) ) {
3177 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3178 if ( !gh3.getName().equals( "gh" ) ) {
3181 final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3182 if ( !abc.getName().equals( "abc" ) ) {
3185 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3186 if ( !abc2.getName().equals( "abc" ) ) {
3189 final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3190 if ( !abcd.getName().equals( "abcd" ) ) {
3193 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3194 if ( !abcd2.getName().equals( "abcd" ) ) {
3197 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3198 if ( !abcdef.getName().equals( "abcdef" ) ) {
3201 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3202 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3205 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3206 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3209 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3210 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3213 final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3214 if ( !abcde.getName().equals( "abcde" ) ) {
3217 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3218 if ( !abcde2.getName().equals( "abcde" ) ) {
3221 final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3222 if ( !r.getName().equals( "abcdefgh" ) ) {
3225 final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3226 if ( !r2.getName().equals( "abcdefgh" ) ) {
3229 final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3230 if ( !r3.getName().equals( "abcdefgh" ) ) {
3233 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3234 if ( !abcde3.getName().equals( "abcde" ) ) {
3237 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3238 if ( !abcde4.getName().equals( "abcde" ) ) {
3241 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3242 if ( !ab3.getName().equals( "ab" ) ) {
3245 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3246 if ( !ab4.getName().equals( "ab" ) ) {
3249 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3250 final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3251 if ( !cd.getName().equals( "cd" ) ) {
3254 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3255 if ( !cd2.getName().equals( "cd" ) ) {
3258 final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3259 if ( !cde.getName().equals( "cde" ) ) {
3262 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3263 if ( !cde2.getName().equals( "cde" ) ) {
3266 final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3267 if ( !cdef.getName().equals( "cdef" ) ) {
3270 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3271 if ( !cdef2.getName().equals( "cdef" ) ) {
3274 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3275 if ( !cdef3.getName().equals( "cdef" ) ) {
3278 final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3279 if ( !rt.getName().equals( "r" ) ) {
3282 final Phylogeny p3 = factory
3283 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3284 new NHXParser() )[ 0 ];
3285 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3286 if ( !bc_3.getName().equals( "bc" ) ) {
3289 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3290 if ( !ac_3.getName().equals( "abc" ) ) {
3293 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3294 if ( !ad_3.getName().equals( "abcde" ) ) {
3297 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3298 if ( !af_3.getName().equals( "abcdef" ) ) {
3301 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3302 if ( !ag_3.getName().equals( "" ) ) {
3305 if ( !ag_3.isRoot() ) {
3308 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3309 if ( !al_3.getName().equals( "" ) ) {
3312 if ( !al_3.isRoot() ) {
3315 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3316 if ( !kl_3.getName().equals( "" ) ) {
3319 if ( !kl_3.isRoot() ) {
3322 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3323 if ( !fl_3.getName().equals( "" ) ) {
3326 if ( !fl_3.isRoot() ) {
3329 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3330 if ( !gk_3.getName().equals( "ghijk" ) ) {
3333 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3334 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3335 if ( !r_4.getName().equals( "r" ) ) {
3338 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3339 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3340 if ( !r_5.getName().equals( "root" ) ) {
3343 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3344 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3345 if ( !r_6.getName().equals( "rot" ) ) {
3348 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3349 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3350 if ( !r_7.getName().equals( "rott" ) ) {
3354 catch ( final Exception e ) {
3355 e.printStackTrace( System.out );
3361 private static boolean testGetLCA2() {
3363 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3364 final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3365 PhylogenyMethods.preOrderReId( p_a );
3366 final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3367 p_a.getNode( "a" ) );
3368 if ( !p_a_1.getName().equals( "a" ) ) {
3371 final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3372 PhylogenyMethods.preOrderReId( p_b );
3373 final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3374 p_b.getNode( "a" ) );
3375 if ( !p_b_1.getName().equals( "b" ) ) {
3378 final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3379 p_b.getNode( "b" ) );
3380 if ( !p_b_2.getName().equals( "b" ) ) {
3383 final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3384 PhylogenyMethods.preOrderReId( p_c );
3385 final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3386 p_c.getNode( "a" ) );
3387 if ( !p_c_1.getName().equals( "b" ) ) {
3390 final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3391 p_c.getNode( "c" ) );
3392 if ( !p_c_2.getName().equals( "c" ) ) {
3393 System.out.println( p_c_2.getName() );
3397 final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3398 p_c.getNode( "b" ) );
3399 if ( !p_c_3.getName().equals( "b" ) ) {
3402 final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3403 p_c.getNode( "a" ) );
3404 if ( !p_c_4.getName().equals( "c" ) ) {
3407 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3408 new NHXParser() )[ 0 ];
3409 PhylogenyMethods.preOrderReId( p1 );
3410 final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3411 p1.getNode( "A" ) );
3412 if ( !A.getName().equals( "A" ) ) {
3415 final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3416 p1.getNode( "gh" ) );
3417 if ( !gh.getName().equals( "gh" ) ) {
3420 final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3421 p1.getNode( "B" ) );
3422 if ( !ab.getName().equals( "ab" ) ) {
3425 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3426 p1.getNode( "A" ) );
3427 if ( !ab2.getName().equals( "ab" ) ) {
3430 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3431 p1.getNode( "G" ) );
3432 if ( !gh2.getName().equals( "gh" ) ) {
3435 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3436 p1.getNode( "H" ) );
3437 if ( !gh3.getName().equals( "gh" ) ) {
3440 final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3441 p1.getNode( "A" ) );
3442 if ( !abc.getName().equals( "abc" ) ) {
3445 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3446 p1.getNode( "C" ) );
3447 if ( !abc2.getName().equals( "abc" ) ) {
3450 final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3451 p1.getNode( "D" ) );
3452 if ( !abcd.getName().equals( "abcd" ) ) {
3455 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3456 p1.getNode( "A" ) );
3457 if ( !abcd2.getName().equals( "abcd" ) ) {
3460 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3461 p1.getNode( "F" ) );
3462 if ( !abcdef.getName().equals( "abcdef" ) ) {
3465 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3466 p1.getNode( "A" ) );
3467 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3470 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3471 p1.getNode( "F" ) );
3472 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3475 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3476 p1.getNode( "ab" ) );
3477 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3480 final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3481 p1.getNode( "E" ) );
3482 if ( !abcde.getName().equals( "abcde" ) ) {
3485 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3486 p1.getNode( "A" ) );
3487 if ( !abcde2.getName().equals( "abcde" ) ) {
3490 final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3491 p1.getNode( "abcdefgh" ) );
3492 if ( !r.getName().equals( "abcdefgh" ) ) {
3495 final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3496 p1.getNode( "H" ) );
3497 if ( !r2.getName().equals( "abcdefgh" ) ) {
3500 final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3501 p1.getNode( "A" ) );
3502 if ( !r3.getName().equals( "abcdefgh" ) ) {
3505 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3506 p1.getNode( "abcde" ) );
3507 if ( !abcde3.getName().equals( "abcde" ) ) {
3510 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3511 p1.getNode( "E" ) );
3512 if ( !abcde4.getName().equals( "abcde" ) ) {
3515 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3516 p1.getNode( "B" ) );
3517 if ( !ab3.getName().equals( "ab" ) ) {
3520 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3521 p1.getNode( "ab" ) );
3522 if ( !ab4.getName().equals( "ab" ) ) {
3525 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3526 PhylogenyMethods.preOrderReId( p2 );
3527 final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3528 p2.getNode( "d" ) );
3529 if ( !cd.getName().equals( "cd" ) ) {
3532 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3533 p2.getNode( "c" ) );
3534 if ( !cd2.getName().equals( "cd" ) ) {
3537 final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3538 p2.getNode( "e" ) );
3539 if ( !cde.getName().equals( "cde" ) ) {
3542 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3543 p2.getNode( "c" ) );
3544 if ( !cde2.getName().equals( "cde" ) ) {
3547 final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3548 p2.getNode( "f" ) );
3549 if ( !cdef.getName().equals( "cdef" ) ) {
3552 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3553 p2.getNode( "f" ) );
3554 if ( !cdef2.getName().equals( "cdef" ) ) {
3557 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3558 p2.getNode( "d" ) );
3559 if ( !cdef3.getName().equals( "cdef" ) ) {
3562 final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3563 p2.getNode( "a" ) );
3564 if ( !rt.getName().equals( "r" ) ) {
3567 final Phylogeny p3 = factory
3568 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3569 new NHXParser() )[ 0 ];
3570 PhylogenyMethods.preOrderReId( p3 );
3571 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3572 p3.getNode( "c" ) );
3573 if ( !bc_3.getName().equals( "bc" ) ) {
3576 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3577 p3.getNode( "c" ) );
3578 if ( !ac_3.getName().equals( "abc" ) ) {
3581 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3582 p3.getNode( "d" ) );
3583 if ( !ad_3.getName().equals( "abcde" ) ) {
3586 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3587 p3.getNode( "f" ) );
3588 if ( !af_3.getName().equals( "abcdef" ) ) {
3591 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3592 p3.getNode( "g" ) );
3593 if ( !ag_3.getName().equals( "" ) ) {
3596 if ( !ag_3.isRoot() ) {
3599 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3600 p3.getNode( "l" ) );
3601 if ( !al_3.getName().equals( "" ) ) {
3604 if ( !al_3.isRoot() ) {
3607 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3608 p3.getNode( "l" ) );
3609 if ( !kl_3.getName().equals( "" ) ) {
3612 if ( !kl_3.isRoot() ) {
3615 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3616 p3.getNode( "l" ) );
3617 if ( !fl_3.getName().equals( "" ) ) {
3620 if ( !fl_3.isRoot() ) {
3623 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3624 p3.getNode( "k" ) );
3625 if ( !gk_3.getName().equals( "ghijk" ) ) {
3628 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3629 PhylogenyMethods.preOrderReId( p4 );
3630 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3631 p4.getNode( "c" ) );
3632 if ( !r_4.getName().equals( "r" ) ) {
3635 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3636 PhylogenyMethods.preOrderReId( p5 );
3637 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3638 p5.getNode( "c" ) );
3639 if ( !r_5.getName().equals( "root" ) ) {
3642 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3643 PhylogenyMethods.preOrderReId( p6 );
3644 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3645 p6.getNode( "a" ) );
3646 if ( !r_6.getName().equals( "rot" ) ) {
3649 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3650 PhylogenyMethods.preOrderReId( p7 );
3651 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
3652 p7.getNode( "e" ) );
3653 if ( !r_7.getName().equals( "rott" ) ) {
3656 final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3657 p7.getNode( "a" ) );
3658 if ( !r_71.getName().equals( "rott" ) ) {
3661 final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3662 p7.getNode( "rott" ) );
3663 if ( !r_72.getName().equals( "rott" ) ) {
3666 final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3667 p7.getNode( "a" ) );
3668 if ( !r_73.getName().equals( "rott" ) ) {
3671 final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3672 p7.getNode( "rott" ) );
3673 if ( !r_74.getName().equals( "rott" ) ) {
3676 final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3677 p7.getNode( "e" ) );
3678 if ( !r_75.getName().equals( "e" ) ) {
3682 catch ( final Exception e ) {
3683 e.printStackTrace( System.out );
3689 private static boolean testHmmscanOutputParser() {
3690 final String test_dir = Test.PATH_TO_TEST_DATA;
3692 final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
3693 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
3695 final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
3696 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
3697 final List<Protein> proteins = parser2.parse();
3698 if ( parser2.getProteinsEncountered() != 4 ) {
3701 if ( proteins.size() != 4 ) {
3704 if ( parser2.getDomainsEncountered() != 69 ) {
3707 if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
3710 if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
3713 final Protein p1 = proteins.get( 0 );
3714 if ( p1.getNumberOfProteinDomains() != 15 ) {
3717 if ( p1.getLength() != 850 ) {
3720 final Protein p2 = proteins.get( 1 );
3721 if ( p2.getNumberOfProteinDomains() != 51 ) {
3724 if ( p2.getLength() != 1291 ) {
3727 final Protein p3 = proteins.get( 2 );
3728 if ( p3.getNumberOfProteinDomains() != 2 ) {
3731 final Protein p4 = proteins.get( 3 );
3732 if ( p4.getNumberOfProteinDomains() != 1 ) {
3735 if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
3738 if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
3741 if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
3744 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
3747 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
3750 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
3753 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
3756 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
3759 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
3763 catch ( final Exception e ) {
3764 e.printStackTrace( System.out );
3770 private static boolean testLastExternalNodeMethods() {
3772 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3773 final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
3774 final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
3775 final PhylogenyNode n1 = t0.getNode( "A" );
3776 if ( n1.isLastExternalNode() ) {
3779 final PhylogenyNode n2 = t0.getNode( "B" );
3780 if ( n2.isLastExternalNode() ) {
3783 final PhylogenyNode n3 = t0.getNode( "C" );
3784 if ( n3.isLastExternalNode() ) {
3787 final PhylogenyNode n4 = t0.getNode( "D" );
3788 if ( !n4.isLastExternalNode() ) {
3792 catch ( final Exception e ) {
3793 e.printStackTrace( System.out );
3799 private static boolean testLevelOrderIterator() {
3801 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3802 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
3803 PhylogenyNodeIterator it0;
3804 for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
3807 for( it0.reset(); it0.hasNext(); ) {
3810 final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
3811 if ( !it.next().getName().equals( "r" ) ) {
3814 if ( !it.next().getName().equals( "ab" ) ) {
3817 if ( !it.next().getName().equals( "cd" ) ) {
3820 if ( !it.next().getName().equals( "A" ) ) {
3823 if ( !it.next().getName().equals( "B" ) ) {
3826 if ( !it.next().getName().equals( "C" ) ) {
3829 if ( !it.next().getName().equals( "D" ) ) {
3832 if ( it.hasNext() ) {
3835 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",
3836 new NHXParser() )[ 0 ];
3837 PhylogenyNodeIterator it2;
3838 for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
3841 for( it2.reset(); it2.hasNext(); ) {
3844 final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
3845 if ( !it3.next().getName().equals( "r" ) ) {
3848 if ( !it3.next().getName().equals( "abc" ) ) {
3851 if ( !it3.next().getName().equals( "defg" ) ) {
3854 if ( !it3.next().getName().equals( "A" ) ) {
3857 if ( !it3.next().getName().equals( "B" ) ) {
3860 if ( !it3.next().getName().equals( "C" ) ) {
3863 if ( !it3.next().getName().equals( "D" ) ) {
3866 if ( !it3.next().getName().equals( "E" ) ) {
3869 if ( !it3.next().getName().equals( "F" ) ) {
3872 if ( !it3.next().getName().equals( "G" ) ) {
3875 if ( !it3.next().getName().equals( "1" ) ) {
3878 if ( !it3.next().getName().equals( "2" ) ) {
3881 if ( !it3.next().getName().equals( "3" ) ) {
3884 if ( !it3.next().getName().equals( "4" ) ) {
3887 if ( !it3.next().getName().equals( "5" ) ) {
3890 if ( !it3.next().getName().equals( "6" ) ) {
3893 if ( !it3.next().getName().equals( "f1" ) ) {
3896 if ( !it3.next().getName().equals( "f2" ) ) {
3899 if ( !it3.next().getName().equals( "f3" ) ) {
3902 if ( !it3.next().getName().equals( "a" ) ) {
3905 if ( !it3.next().getName().equals( "b" ) ) {
3908 if ( !it3.next().getName().equals( "f21" ) ) {
3911 if ( !it3.next().getName().equals( "X" ) ) {
3914 if ( !it3.next().getName().equals( "Y" ) ) {
3917 if ( !it3.next().getName().equals( "Z" ) ) {
3920 if ( it3.hasNext() ) {
3923 final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
3924 PhylogenyNodeIterator it4;
3925 for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
3928 for( it4.reset(); it4.hasNext(); ) {
3931 final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
3932 if ( !it5.next().getName().equals( "r" ) ) {
3935 if ( !it5.next().getName().equals( "A" ) ) {
3938 if ( !it5.next().getName().equals( "B" ) ) {
3941 if ( !it5.next().getName().equals( "C" ) ) {
3944 if ( !it5.next().getName().equals( "D" ) ) {
3947 final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
3948 PhylogenyNodeIterator it6;
3949 for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
3952 for( it6.reset(); it6.hasNext(); ) {
3955 final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
3956 if ( !it7.next().getName().equals( "A" ) ) {
3959 if ( it.hasNext() ) {
3963 catch ( final Exception e ) {
3964 e.printStackTrace( System.out );
3971 private static boolean testNodeRemoval() {
3973 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3974 final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3975 PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
3977 if ( !t0.toNewHampshire().equals( "(a);" ) ) {
3980 final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
3981 PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
3983 if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
3986 final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
3987 PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
3989 if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
3994 catch ( final Exception e ) {
3995 e.printStackTrace( System.out );
4001 private static boolean testMidpointrooting() {
4003 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4004 final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4005 PhylogenyMethods.midpointRoot( t0 );
4006 if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4009 if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4012 if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4016 final Phylogeny t1 = factory.create( "((A:1,B:2)AB:1[&&NHX:B=55],(C:3,D:4)CD:3[&&NHX:B=10])ABCD:0.5",
4017 new NHXParser() )[ 0 ];
4018 if ( !t1.isRooted() ) {
4021 PhylogenyMethods.midpointRoot( t1 );
4022 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4025 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4028 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4031 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4034 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4037 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4040 t1.reRoot( t1.getNode( "A" ) );
4041 PhylogenyMethods.midpointRoot( t1 );
4042 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4045 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4048 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4051 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4054 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4058 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4062 catch ( final Exception e ) {
4063 e.printStackTrace( System.out );
4069 private static boolean testNexusCharactersParsing() {
4071 final NexusCharactersParser parser = new NexusCharactersParser();
4072 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4074 String[] labels = parser.getCharStateLabels();
4075 if ( labels.length != 7 ) {
4078 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4081 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4084 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4087 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4090 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4093 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4096 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4099 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4101 labels = parser.getCharStateLabels();
4102 if ( labels.length != 7 ) {
4105 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4108 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4111 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4114 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4117 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4120 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4123 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4127 catch ( final Exception e ) {
4128 e.printStackTrace( System.out );
4134 private static boolean testNexusMatrixParsing() {
4136 final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4137 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4139 final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4140 if ( m.getNumberOfCharacters() != 9 ) {
4143 if ( m.getNumberOfIdentifiers() != 5 ) {
4146 if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4149 if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4152 if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4155 if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4158 if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4161 if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4164 if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4167 // if ( labels.length != 7 ) {
4170 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4173 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4176 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4179 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4182 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4185 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4188 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4191 // parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4193 // labels = parser.getCharStateLabels();
4194 // if ( labels.length != 7 ) {
4197 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4200 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4203 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4206 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4209 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4212 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4215 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4219 catch ( final Exception e ) {
4220 e.printStackTrace( System.out );
4226 private static boolean testNexusTreeParsing() {
4228 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4229 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4230 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4231 if ( phylogenies.length != 1 ) {
4234 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4237 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4241 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4242 if ( phylogenies.length != 1 ) {
4245 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4248 if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4252 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4253 if ( phylogenies.length != 1 ) {
4256 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4259 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4262 if ( phylogenies[ 0 ].isRooted() ) {
4266 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4267 if ( phylogenies.length != 18 ) {
4270 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4273 if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4276 if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4279 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4282 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4285 if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4288 if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4291 if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4294 if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4297 if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4300 if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4303 if ( phylogenies[ 8 ].isRooted() ) {
4306 if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4309 if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4312 if ( !phylogenies[ 9 ].isRooted() ) {
4315 if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4318 if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4321 if ( !phylogenies[ 10 ].isRooted() ) {
4324 if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4327 if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4330 if ( phylogenies[ 11 ].isRooted() ) {
4333 if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4336 if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4339 if ( !phylogenies[ 12 ].isRooted() ) {
4342 if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4345 if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4348 if ( !phylogenies[ 13 ].isRooted() ) {
4351 if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4354 if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4357 if ( !phylogenies[ 14 ].isRooted() ) {
4360 if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4363 if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4366 if ( phylogenies[ 15 ].isRooted() ) {
4369 if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4372 if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4375 if ( !phylogenies[ 16 ].isRooted() ) {
4378 if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4381 if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4384 if ( phylogenies[ 17 ].isRooted() ) {
4387 if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4391 catch ( final Exception e ) {
4392 e.printStackTrace( System.out );
4398 private static boolean testNexusTreeParsingTranslating() {
4400 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4401 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4402 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
4403 if ( phylogenies.length != 1 ) {
4406 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4409 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4412 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4415 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4418 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4419 .equals( "Aranaeus" ) ) {
4423 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
4424 if ( phylogenies.length != 3 ) {
4427 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4430 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4433 if ( phylogenies[ 0 ].isRooted() ) {
4436 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4439 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4442 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4443 .equals( "Aranaeus" ) ) {
4446 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
4449 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
4452 if ( phylogenies[ 1 ].isRooted() ) {
4455 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4458 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4461 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4462 .equals( "Aranaeus" ) ) {
4465 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4468 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
4471 if ( !phylogenies[ 2 ].isRooted() ) {
4474 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4477 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4480 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4481 .equals( "Aranaeus" ) ) {
4485 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
4486 if ( phylogenies.length != 3 ) {
4489 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4492 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4495 if ( phylogenies[ 0 ].isRooted() ) {
4498 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4501 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4504 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4505 .equals( "Aranaeus" ) ) {
4508 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
4511 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
4514 if ( phylogenies[ 1 ].isRooted() ) {
4517 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4520 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4523 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4524 .equals( "Aranaeus" ) ) {
4527 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4530 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
4533 if ( !phylogenies[ 2 ].isRooted() ) {
4536 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4539 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4542 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4543 .equals( "Aranaeus" ) ) {
4547 catch ( final Exception e ) {
4548 e.printStackTrace( System.out );
4554 private static boolean testNHParsing() {
4556 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4557 final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
4558 if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
4561 final NHXParser nhxp = new NHXParser();
4562 nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
4563 nhxp.setReplaceUnderscores( true );
4564 final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
4565 if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
4568 if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
4571 final Phylogeny p1b = factory
4572 .create( " \n \t \b \r \f ; ( \n \t \b \r \f; A ; \n \t \b \r \f, \n \t \b \r \f; B ; \n \t \b \r \f 1 \n \t \b \r \f ; \n \t \b \r \f );;;;; \n \t \b \r \f;;; \n \t \b \r \f ",
4573 new NHXParser() )[ 0 ];
4574 if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
4577 if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
4580 final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
4581 final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
4582 final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
4583 final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
4584 final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
4585 final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
4586 final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
4587 final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
4588 final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
4589 final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
4590 final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
4591 + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
4592 + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
4594 if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
4597 if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
4600 if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
4603 if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
4606 final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
4607 final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
4608 final String p16_S = "((A,B),C)";
4609 final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
4610 if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
4613 final String p17_S = "(C,(A,B))";
4614 final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
4615 if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
4618 final String p18_S = "((A,B),(C,D))";
4619 final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
4620 if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
4623 final String p19_S = "(((A,B),C),D)";
4624 final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
4625 if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
4628 final String p20_S = "(A,(B,(C,D)))";
4629 final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
4630 if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
4633 final String p21_S = "(A,(B,(C,(D,E))))";
4634 final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
4635 if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
4638 final String p22_S = "((((A,B),C),D),E)";
4639 final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
4640 if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
4643 final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4644 final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
4645 if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
4648 final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4649 final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
4650 if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
4653 final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4654 final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4655 final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
4656 if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
4659 if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
4662 final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
4663 + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
4664 + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
4665 + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
4666 + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
4667 + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
4668 + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
4669 + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
4670 final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
4671 if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
4674 final String p26_S = "(A,B)ab";
4675 final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
4676 if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
4679 final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4680 final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
4682 if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
4685 final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4686 final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4687 final String p28_S3 = "(A,B)ab";
4688 final String p28_S4 = "((((A,B),C),D),;E;)";
4689 final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
4691 if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
4694 if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
4697 if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
4700 if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
4703 final String p29_S = "((((A:0.01,B:0.684)ab:0.345,C:0.3451)abc:0.3451,D:1.5)abcd:0.134,E:0.32)abcde:0.1345";
4704 final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
4705 if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
4708 final String p30_S = "((((A:0.01,B:0.02):0.93,C:0.04):0.05,D:1.4):0.06,E):0.72";
4709 final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
4710 if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
4713 final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
4714 final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
4715 if ( ( p32.length != 1 ) || !p32[ 0 ].isEmpty() ) {
4718 final String p33_S = "A";
4719 final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
4720 if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
4723 final String p34_S = "B;";
4724 final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
4725 if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
4728 final String p35_S = "B:0.2";
4729 final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
4730 if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
4733 final String p36_S = "(A)";
4734 final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
4735 if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
4738 final String p37_S = "((A))";
4739 final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
4740 if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
4743 final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
4744 final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
4745 if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
4748 final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
4749 final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
4750 if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
4753 final String p40_S = "(A,B,C)";
4754 final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
4755 if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
4758 final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
4759 final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
4760 if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
4763 final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
4764 final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
4765 if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
4768 final String p43_S = "(A,B,C,(AA,BB,CC,(CCC,DDD,EEE,(FFFF,GGGG)x)y,DD,EE,FF,GG,HH),D,E,(EE,FF),F,G,H,(((((5)4)3)2)1),I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,(XX,(YY)),Y,Z)";
4769 final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
4770 if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
4773 final String p44_S = "(((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)))";
4774 final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
4775 if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
4778 final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
4779 final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
4780 if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
4783 final String p46_S = "";
4784 final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
4785 if ( ( p46.length != 1 ) || !p46[ 0 ].isEmpty() ) {
4788 final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
4789 if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4792 final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4793 if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4796 final Phylogeny p49 = factory
4797 .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
4798 new NHXParser() )[ 0 ];
4799 if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4802 final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4803 if ( p50.getNode( "A" ) == null ) {
4806 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
4807 .equals( "((A,B)ab:2.0[88],C);" ) ) {
4810 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
4813 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
4814 .equals( "((A,B)88:2.0,C);" ) ) {
4817 final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4818 if ( p51.getNode( "A(A" ) == null ) {
4821 final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4822 if ( p52.getNode( "A(A" ) == null ) {
4825 final Phylogeny p53 = factory
4826 .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
4827 new NHXParser() )[ 0 ];
4828 if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
4832 final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
4833 if ( p54.getNode( "A" ) == null ) {
4836 if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
4837 .equals( "((A,B)[88],C);" ) ) {
4841 catch ( final Exception e ) {
4842 e.printStackTrace( System.out );
4848 private static boolean testNHXconversion() {
4850 final PhylogenyNode n1 = new PhylogenyNode();
4851 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
4852 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
4853 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
4854 final PhylogenyNode n5 = PhylogenyNode
4855 .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1:W=2:C=10.20.30:XN=S=tag1=value1=unit1]" );
4856 final PhylogenyNode n6 = PhylogenyNode
4857 .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1:W=2:C=0.0.0:XN=B=bool_tag=T]" );
4858 if ( !n1.toNewHampshireX().equals( "" ) ) {
4861 if ( !n2.toNewHampshireX().equals( "" ) ) {
4864 if ( !n3.toNewHampshireX().equals( "n3" ) ) {
4867 if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
4870 if ( !n5.toNewHampshireX()
4871 .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]" ) ) {
4874 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]" ) ) {
4878 catch ( final Exception e ) {
4879 e.printStackTrace( System.out );
4885 private static boolean testNHXNodeParsing() {
4887 final PhylogenyNode n1 = new PhylogenyNode();
4888 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
4889 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
4890 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
4891 final PhylogenyNode n5 = PhylogenyNode
4892 .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:B=56:T=1:On=22:SOn=33:SNn=44:W=2:C=10.20.30:XN=S=tag1=value1=unit1:XN=S=tag3=value3=unit3]" );
4893 if ( !n3.getName().equals( "n3" ) ) {
4896 if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
4899 if ( n3.isDuplication() ) {
4902 if ( n3.isHasAssignedEvent() ) {
4905 if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
4908 if ( !n4.getName().equals( "n4" ) ) {
4911 if ( n4.getDistanceToParent() != 0.01 ) {
4914 if ( !n5.getName().equals( "n5" ) ) {
4917 if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
4920 if ( n5.getDistanceToParent() != 0.1 ) {
4923 if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
4926 if ( !n5.isDuplication() ) {
4929 if ( !n5.isHasAssignedEvent() ) {
4932 if ( PhylogenyMethods.getBranchWidthValue( n5 ) != 2 ) {
4935 if ( n5.getNodeData().getProperties().getPropertyRefs().length != 2 ) {
4938 final PhylogenyNode n8 = PhylogenyNode
4939 .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4940 if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
4943 if ( PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
4946 final PhylogenyNode n9 = PhylogenyNode
4947 .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4948 if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
4951 if ( PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
4954 final PhylogenyNode n10 = PhylogenyNode
4955 .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4956 if ( !n10.getName().equals( "n10.ECOLI" ) ) {
4959 final PhylogenyNode n20 = PhylogenyNode
4960 .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4961 if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
4964 if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
4967 final PhylogenyNode n20x = PhylogenyNode.createInstanceFromNhxString( "n20_ECOL1/1-2",
4968 NHXParser.TAXONOMY_EXTRACTION.YES );
4969 if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
4972 if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
4975 final PhylogenyNode n20xx = PhylogenyNode
4976 .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4977 if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
4980 if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
4983 final PhylogenyNode n20xxx = PhylogenyNode
4984 .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4985 if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
4988 if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
4991 final PhylogenyNode n20xxxx = PhylogenyNode
4992 .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4993 if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
4996 if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
4999 final PhylogenyNode n21 = PhylogenyNode.createInstanceFromNhxString( "n21_PIG",
5000 NHXParser.TAXONOMY_EXTRACTION.YES );
5001 if ( !n21.getName().equals( "n21_PIG" ) ) {
5004 if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
5007 final PhylogenyNode n21x = PhylogenyNode
5008 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5009 if ( !n21x.getName().equals( "n21_PIG" ) ) {
5012 if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
5015 final PhylogenyNode n22 = PhylogenyNode
5016 .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5017 if ( !n22.getName().equals( "n22/PIG" ) ) {
5020 if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
5023 final PhylogenyNode n23 = PhylogenyNode
5024 .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5025 if ( !n23.getName().equals( "n23/PIG_1" ) ) {
5028 if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
5031 final PhylogenyNode a = PhylogenyNode
5032 .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5033 if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
5036 if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
5039 final PhylogenyNode b = PhylogenyNode
5040 .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5041 if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
5044 if ( PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
5047 final PhylogenyNode c = PhylogenyNode
5048 .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
5049 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5050 if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
5053 if ( PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
5056 final PhylogenyNode c1 = PhylogenyNode
5057 .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
5058 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5059 if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
5062 if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
5065 final PhylogenyNode c2 = PhylogenyNode
5066 .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
5067 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5068 if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
5071 if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
5074 final PhylogenyNode d = PhylogenyNode
5075 .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5076 if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
5079 if ( PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
5082 final PhylogenyNode e = PhylogenyNode
5083 .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5084 if ( !e.getName().equals( "n10_RAT1" ) ) {
5087 if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
5090 final PhylogenyNode e2 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT1",
5091 NHXParser.TAXONOMY_EXTRACTION.YES );
5092 if ( !e2.getName().equals( "n10_RAT1" ) ) {
5095 if ( !PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
5098 final PhylogenyNode e3 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT~",
5099 NHXParser.TAXONOMY_EXTRACTION.YES );
5100 if ( !e3.getName().equals( "n10_RAT~" ) ) {
5103 if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
5106 final PhylogenyNode n11 = PhylogenyNode
5107 .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
5108 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5109 if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
5112 if ( n11.getDistanceToParent() != 0.4 ) {
5115 if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
5118 final PhylogenyNode n12 = PhylogenyNode
5119 .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
5120 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5121 if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
5124 if ( n12.getDistanceToParent() != 0.4 ) {
5127 if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
5130 final PhylogenyNode m = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSEa",
5131 NHXParser.TAXONOMY_EXTRACTION.YES );
5132 if ( !m.getName().equals( "n10_MOUSEa" ) ) {
5135 if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
5138 final PhylogenyNode o = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSE_",
5139 NHXParser.TAXONOMY_EXTRACTION.YES );
5140 if ( !o.getName().equals( "n10_MOUSE_" ) ) {
5143 if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
5146 final Property tvu1 = n5.getNodeData().getProperties().getProperty( "tag1" );
5147 final Property tvu3 = n5.getNodeData().getProperties().getProperty( "tag3" );
5148 if ( !tvu1.getRef().equals( "tag1" ) ) {
5151 if ( !tvu1.getDataType().equals( "xsd:string" ) ) {
5154 if ( !tvu1.getUnit().equals( "unit1" ) ) {
5157 if ( !tvu1.getValue().equals( "value1" ) ) {
5160 if ( !tvu3.getRef().equals( "tag3" ) ) {
5163 if ( !tvu3.getDataType().equals( "xsd:string" ) ) {
5166 if ( !tvu3.getUnit().equals( "unit3" ) ) {
5169 if ( !tvu3.getValue().equals( "value3" ) ) {
5172 if ( n1.getName().compareTo( "" ) != 0 ) {
5175 if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5178 if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
5181 if ( n2.getName().compareTo( "" ) != 0 ) {
5184 if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5187 if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
5190 final PhylogenyNode n00 = PhylogenyNode
5191 .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:ID=node_identifier:S=Ecoli:D=N:Co=N:B=100:T=1:On=100:SOn=100:SNn=100:W=2:C=0.0.0:XN=U=url_tag=www.yahoo.com]" );
5192 if ( !n00.getNodeData().getNodeIdentifier().getValue().equals( "node_identifier" ) ) {
5195 if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
5198 if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
5201 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getRef().equals( "url_tag" ) ) {
5204 if ( n00.getNodeData().getProperties().getProperty( "url_tag" ).getAppliesTo() != Property.AppliesTo.NODE ) {
5207 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getDataType().equals( "xsd:anyURI" ) ) {
5210 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getValue().equals( "www.yahoo.com" ) ) {
5213 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getUnit().equals( "" ) ) {
5216 final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
5217 if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
5220 final PhylogenyNode nx2 = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:G=gene_2]" );
5221 if ( !nx2.getNodeData().getSequence().getName().equals( "gene_2" ) ) {
5224 final PhylogenyNode n13 = PhylogenyNode
5225 .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5226 if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
5229 if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
5232 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
5235 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
5238 final PhylogenyNode n14 = PhylogenyNode
5239 .createInstanceFromNhxString( "blah_12X45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5240 if ( !n14.getName().equals( "blah_12X45/1-2" ) ) {
5243 if ( !PhylogenyMethods.getSpecies( n14 ).equals( "12X45" ) ) {
5246 final PhylogenyNode n15 = PhylogenyNode
5247 .createInstanceFromNhxString( "something_wicked[123]",
5248 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5249 if ( !n15.getName().equals( "something_wicked" ) ) {
5252 if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
5255 if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
5258 final PhylogenyNode n16 = PhylogenyNode
5259 .createInstanceFromNhxString( "something_wicked2[9]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5260 if ( !n16.getName().equals( "something_wicked2" ) ) {
5263 if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
5266 if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
5269 final PhylogenyNode n17 = PhylogenyNode
5270 .createInstanceFromNhxString( "something_wicked3[a]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5271 if ( !n17.getName().equals( "something_wicked3" ) ) {
5274 if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
5277 final PhylogenyNode n18 = PhylogenyNode
5278 .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5279 if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
5282 if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
5285 if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
5291 final PhylogenyNode n19 = PhylogenyNode
5292 .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.YES );
5295 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
5298 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
5301 final PhylogenyNode n30 = PhylogenyNode
5302 .createInstanceFromNhxString( "blah_1234567-roejojoej", NHXParser.TAXONOMY_EXTRACTION.YES );
5305 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
5308 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
5311 final PhylogenyNode n31 = PhylogenyNode
5312 .createInstanceFromNhxString( "blah_12345678-roejojoej", NHXParser.TAXONOMY_EXTRACTION.YES );
5315 if ( n31.getNodeData().isHasTaxonomy() ) {
5318 // if ( !n31.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
5322 catch ( final Exception e ) {
5323 e.printStackTrace( System.out );
5329 private static boolean testNHXParsing() {
5331 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5332 final Phylogeny p1 = factory.create( "(A [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
5333 if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
5336 final String p2_S = "(((((((A:0.2[&&NHX:S=qwerty]):0.2[&&NHX:S=uiop]):0.3[&&NHX:S=asdf]):0.4[&&NHX:S=zxc]):0.5[&&NHX:S=a]):0.6[&&NHX:S=asd]):0.7[&&NHX:S=za]):0.8[&&NHX:S=zaq]";
5337 final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
5338 if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5341 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]";
5342 final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
5343 if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
5346 final Phylogeny[] p3 = factory
5347 .create( "[ comment&&NHX,())))](((((((A:0.2[&&NHX:S=qwerty]):0.2[&&NHX:S=uiop]):0.3[&&NHX:S=asdf]):0.4[&&NHX:S=zxc]):0.5[&&NHX:S=a]):0.6[&&NHX:S=asd]):0.7[&&NHX:S=za]):0.8[&&NHX:S=zaq]",
5349 if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5352 final Phylogeny[] p4 = factory
5353 .create( "(((((((A:0.2[&&NHX:S=qwerty]):0.2[&&NHX:S=uiop]):0.3[&&NHX:S=asdf]):0.4[&&NHX:S=zxc]):0.5[&&NHX:S=a]):0.6[&&NHX:S=asd]):0.7[&&NHX:S=za]):0.8[&&NHX:S=zaq][comment(]",
5355 if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5358 final Phylogeny[] p5 = factory
5359 .create( "[] ( [][ ][ ] ([((( &&NHXcomment only![[[[[[]([]((((A:0.2[&&NHX:S=q[comment )))]werty][,,,,))]):0.2[&&NHX:S=uiop]):0.3[&&NHX:S=a[comment,,))]sdf])[comment(((]:0.4[&&NHX:S=zxc][comment(((][comment(((]):0.5[&&NHX:S=a]):0.6[&&NHX:S=a[comment(((]sd]):0.7[&&NHX:S=za]):0.8[&&NHX:S=zaq][comment(((]",
5361 if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5364 final String p6_S_C = "(A[][][][1][22][333][4444][55555][666666][&&NHX:S=Aspecies],B[))],C,(AA,BB,CC,(CCC,DDD,EEE,[comment](FFFF,GGGG)x)y,D[comment]D,EE,FF,GG,HH),D,E,(EE,FF),F,G,H,(((((5)4)3)2)1),I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,(XX,(YY)),Y,Z)";
5365 final String p6_S_WO_C = "(A[&&NHX:S=Aspecies],B,C,(AA,BB,CC,(CCC,DDD,EEE,(FFFF,GGGG)x)y,DD,EE,FF,GG,HH),D,E,(EE,FF),F,G,H,(((((5)4)3)2)1),I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,(XX,(YY)),Y,Z)";
5366 final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
5367 if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
5370 final String p7_S_C = "(((A [&&NHX:S=species_a], B [&&NHX:S=Vstorri] , C , D),(A,B,C,D[comment])[],[c][]([xxx]A[comment],[comment]B[comment][comment],[comment][comment]C[comment][comment],[comment][comment]D[comment][comment])[comment][comment],[comment] [comment](A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C[comment][comment][comment][comment][comment] [comment],D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),[comment][comment]((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)))";
5371 final String p7_S_WO_C = "(((A[&&NHX:S=species_a],B[&&NHX:S=Vstorri],C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)))";
5372 final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
5373 if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
5376 final String p8_S_C = "[cmt](((([]([))))))](((((A[&&NHX:S= [a comment] a])))))))[too many comments!:)])),(((((((((B[&&NHX[ a comment in a bad place]:S =b])))))[] [] )))),(((((((((C[&&NHX:S=c]) ))[,,, ])))))))";
5377 final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
5378 final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
5379 if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
5382 final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
5383 if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
5386 final Phylogeny p10 = factory
5387 .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]",
5388 new NHXParser() )[ 0 ];
5389 if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
5393 catch ( final Exception e ) {
5394 e.printStackTrace( System.out );
5400 private static boolean testNHXParsingQuotes() {
5402 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5403 final NHXParser p = new NHXParser();
5404 final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
5405 if ( phylogenies_0.length != 5 ) {
5408 final Phylogeny phy = phylogenies_0[ 4 ];
5409 if ( phy.getNumberOfExternalNodes() != 7 ) {
5412 if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
5415 if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
5418 if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
5419 .getScientificName().equals( "hsapiens" ) ) {
5422 if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
5425 if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
5428 if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
5431 if ( phy.getNodes( "noquotes" ).size() != 1 ) {
5434 if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
5437 final NHXParser p1p = new NHXParser();
5438 p1p.setIgnoreQuotes( true );
5439 final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
5440 if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
5443 final NHXParser p2p = new NHXParser();
5444 p1p.setIgnoreQuotes( false );
5445 final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
5446 if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
5449 final NHXParser p3p = new NHXParser();
5450 p3p.setIgnoreQuotes( false );
5451 final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
5452 if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
5455 final NHXParser p4p = new NHXParser();
5456 p4p.setIgnoreQuotes( false );
5457 final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
5458 if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
5461 final Phylogeny p10 = factory
5462 .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]",
5463 new NHXParser() )[ 0 ];
5464 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]";
5465 if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
5468 final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
5469 if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
5473 final Phylogeny p12 = factory
5474 .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]",
5475 new NHXParser() )[ 0 ];
5476 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]";
5477 if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
5480 final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
5481 if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
5484 final String p12_clean_str_nh = "(('A B':0.2,'BB B':0.03):0.5,'C (or D?\\//;,))':0.1)'root is here (cool, was! )':0.1;";
5485 if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
5488 final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
5489 if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
5493 catch ( final Exception e ) {
5494 e.printStackTrace( System.out );
5500 private static boolean testNHXParsingMB() {
5502 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5503 final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
5504 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5505 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
5506 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
5507 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
5508 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5509 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
5510 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
5511 + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
5512 if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
5515 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
5518 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
5519 0.1100000000000000e+00 ) ) {
5522 if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
5525 if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
5528 final Phylogeny p2 = factory
5529 .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
5530 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5531 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
5532 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
5533 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
5534 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5535 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
5536 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
5537 + "7.369400000000000e-02}])",
5538 new NHXParser() )[ 0 ];
5539 if ( p2.getNode( "1" ) == null ) {
5542 if ( p2.getNode( "2" ) == null ) {
5546 catch ( final Exception e ) {
5547 e.printStackTrace( System.out );
5554 private static boolean testPhylogenyBranch() {
5556 final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
5557 final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
5558 final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
5559 final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
5560 if ( !a1b1.equals( a1b1 ) ) {
5563 if ( !a1b1.equals( b1a1 ) ) {
5566 if ( !b1a1.equals( a1b1 ) ) {
5569 final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
5570 final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
5571 final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
5572 if ( a1_b1.equals( b1_a1 ) ) {
5575 if ( a1_b1.equals( a1_b1_ ) ) {
5578 final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
5579 if ( !a1_b1.equals( b1_a1_ ) ) {
5582 if ( a1_b1_.equals( b1_a1_ ) ) {
5585 if ( !a1_b1_.equals( b1_a1 ) ) {
5589 catch ( final Exception e ) {
5590 e.printStackTrace( System.out );
5596 private static boolean testPhyloXMLparsingOfDistributionElement() {
5598 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5599 PhyloXmlParser xml_parser = null;
5601 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
5603 catch ( final Exception e ) {
5604 // Do nothing -- means were not running from jar.
5606 if ( xml_parser == null ) {
5607 xml_parser = new PhyloXmlParser();
5608 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
5609 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
5612 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
5615 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
5617 if ( xml_parser.getErrorCount() > 0 ) {
5618 System.out.println( xml_parser.getErrorMessages().toString() );
5621 if ( phylogenies_0.length != 1 ) {
5624 final Phylogeny t1 = phylogenies_0[ 0 ];
5625 PhylogenyNode n = null;
5626 Distribution d = null;
5627 n = t1.getNode( "root node" );
5628 if ( !n.getNodeData().isHasDistribution() ) {
5631 if ( n.getNodeData().getDistributions().size() != 1 ) {
5634 d = n.getNodeData().getDistribution();
5635 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
5638 if ( d.getPoints().size() != 1 ) {
5641 if ( d.getPolygons() != null ) {
5644 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
5647 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5650 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5653 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
5656 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
5659 n = t1.getNode( "node a" );
5660 if ( !n.getNodeData().isHasDistribution() ) {
5663 if ( n.getNodeData().getDistributions().size() != 2 ) {
5666 d = n.getNodeData().getDistribution( 1 );
5667 if ( !d.getDesc().equals( "San Diego" ) ) {
5670 if ( d.getPoints().size() != 1 ) {
5673 if ( d.getPolygons() != null ) {
5676 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
5679 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5682 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5685 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
5688 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
5691 n = t1.getNode( "node bb" );
5692 if ( !n.getNodeData().isHasDistribution() ) {
5695 if ( n.getNodeData().getDistributions().size() != 1 ) {
5698 d = n.getNodeData().getDistribution( 0 );
5699 if ( d.getPoints().size() != 3 ) {
5702 if ( d.getPolygons().size() != 2 ) {
5705 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
5708 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
5711 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
5714 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
5717 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
5720 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
5723 Polygon p = d.getPolygons().get( 0 );
5724 if ( p.getPoints().size() != 3 ) {
5727 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
5730 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
5733 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5736 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
5739 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
5742 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
5745 p = d.getPolygons().get( 1 );
5746 if ( p.getPoints().size() != 3 ) {
5749 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
5752 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
5755 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5759 final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
5760 final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
5761 if ( rt.length != 1 ) {
5764 final Phylogeny t1_rt = rt[ 0 ];
5765 n = t1_rt.getNode( "root node" );
5766 if ( !n.getNodeData().isHasDistribution() ) {
5769 if ( n.getNodeData().getDistributions().size() != 1 ) {
5772 d = n.getNodeData().getDistribution();
5773 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
5776 if ( d.getPoints().size() != 1 ) {
5779 if ( d.getPolygons() != null ) {
5782 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
5785 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5788 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5791 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
5794 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
5797 n = t1_rt.getNode( "node a" );
5798 if ( !n.getNodeData().isHasDistribution() ) {
5801 if ( n.getNodeData().getDistributions().size() != 2 ) {
5804 d = n.getNodeData().getDistribution( 1 );
5805 if ( !d.getDesc().equals( "San Diego" ) ) {
5808 if ( d.getPoints().size() != 1 ) {
5811 if ( d.getPolygons() != null ) {
5814 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
5817 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5820 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5823 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
5826 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
5829 n = t1_rt.getNode( "node bb" );
5830 if ( !n.getNodeData().isHasDistribution() ) {
5833 if ( n.getNodeData().getDistributions().size() != 1 ) {
5836 d = n.getNodeData().getDistribution( 0 );
5837 if ( d.getPoints().size() != 3 ) {
5840 if ( d.getPolygons().size() != 2 ) {
5843 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
5846 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
5849 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
5852 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
5855 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
5858 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
5861 p = d.getPolygons().get( 0 );
5862 if ( p.getPoints().size() != 3 ) {
5865 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
5868 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
5871 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5874 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
5877 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
5880 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
5883 p = d.getPolygons().get( 1 );
5884 if ( p.getPoints().size() != 3 ) {
5887 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
5890 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
5893 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5897 catch ( final Exception e ) {
5898 e.printStackTrace( System.out );
5904 private static boolean testPostOrderIterator() {
5906 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5907 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5908 PhylogenyNodeIterator it0;
5909 for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
5912 for( it0.reset(); it0.hasNext(); ) {
5915 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
5916 final PhylogenyNodeIterator it = t1.iteratorPostorder();
5917 if ( !it.next().getName().equals( "A" ) ) {
5920 if ( !it.next().getName().equals( "B" ) ) {
5923 if ( !it.next().getName().equals( "ab" ) ) {
5926 if ( !it.next().getName().equals( "C" ) ) {
5929 if ( !it.next().getName().equals( "D" ) ) {
5932 if ( !it.next().getName().equals( "cd" ) ) {
5935 if ( !it.next().getName().equals( "abcd" ) ) {
5938 if ( !it.next().getName().equals( "E" ) ) {
5941 if ( !it.next().getName().equals( "F" ) ) {
5944 if ( !it.next().getName().equals( "ef" ) ) {
5947 if ( !it.next().getName().equals( "G" ) ) {
5950 if ( !it.next().getName().equals( "H" ) ) {
5953 if ( !it.next().getName().equals( "gh" ) ) {
5956 if ( !it.next().getName().equals( "efgh" ) ) {
5959 if ( !it.next().getName().equals( "r" ) ) {
5962 if ( it.hasNext() ) {
5966 catch ( final Exception e ) {
5967 e.printStackTrace( System.out );
5973 private static boolean testPreOrderIterator() {
5975 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5976 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5977 PhylogenyNodeIterator it0;
5978 for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
5981 for( it0.reset(); it0.hasNext(); ) {
5984 PhylogenyNodeIterator it = t0.iteratorPreorder();
5985 if ( !it.next().getName().equals( "r" ) ) {
5988 if ( !it.next().getName().equals( "ab" ) ) {
5991 if ( !it.next().getName().equals( "A" ) ) {
5994 if ( !it.next().getName().equals( "B" ) ) {
5997 if ( !it.next().getName().equals( "cd" ) ) {
6000 if ( !it.next().getName().equals( "C" ) ) {
6003 if ( !it.next().getName().equals( "D" ) ) {
6006 if ( it.hasNext() ) {
6009 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
6010 it = t1.iteratorPreorder();
6011 if ( !it.next().getName().equals( "r" ) ) {
6014 if ( !it.next().getName().equals( "abcd" ) ) {
6017 if ( !it.next().getName().equals( "ab" ) ) {
6020 if ( !it.next().getName().equals( "A" ) ) {
6023 if ( !it.next().getName().equals( "B" ) ) {
6026 if ( !it.next().getName().equals( "cd" ) ) {
6029 if ( !it.next().getName().equals( "C" ) ) {
6032 if ( !it.next().getName().equals( "D" ) ) {
6035 if ( !it.next().getName().equals( "efgh" ) ) {
6038 if ( !it.next().getName().equals( "ef" ) ) {
6041 if ( !it.next().getName().equals( "E" ) ) {
6044 if ( !it.next().getName().equals( "F" ) ) {
6047 if ( !it.next().getName().equals( "gh" ) ) {
6050 if ( !it.next().getName().equals( "G" ) ) {
6053 if ( !it.next().getName().equals( "H" ) ) {
6056 if ( it.hasNext() ) {
6060 catch ( final Exception e ) {
6061 e.printStackTrace( System.out );
6067 private static boolean testPropertiesMap() {
6069 final PropertiesMap pm = new PropertiesMap();
6070 final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
6071 final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
6072 final Property p2 = new Property( "something:else",
6074 "improbable:research",
6077 pm.addProperty( p0 );
6078 pm.addProperty( p1 );
6079 pm.addProperty( p2 );
6080 if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
6083 if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
6086 if ( pm.getProperties().size() != 3 ) {
6089 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
6092 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
6095 if ( pm.getProperties().size() != 3 ) {
6098 pm.removeProperty( "dimensions:diameter" );
6099 if ( pm.getProperties().size() != 2 ) {
6102 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
6105 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
6109 catch ( final Exception e ) {
6110 e.printStackTrace( System.out );
6116 private static boolean testReIdMethods() {
6118 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6119 final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
6120 final int count = PhylogenyNode.getNodeCount();
6122 if ( p.getNode( "r" ).getId() != count ) {
6125 if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
6128 if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
6131 if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
6134 if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
6137 if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
6140 if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
6143 if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
6146 if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
6149 if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
6152 if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
6155 if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
6158 if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
6161 if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
6164 if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
6168 catch ( final Exception e ) {
6169 e.printStackTrace( System.out );
6175 private static boolean testRerooting() {
6177 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6178 final Phylogeny t1 = factory.create( "((A:1,B:2)AB:1[&&NHX:B=55],(C:3,D:5)CD:3[&&NHX:B=10])ABCD:0.5",
6179 new NHXParser() )[ 0 ];
6180 if ( !t1.isRooted() ) {
6183 t1.reRoot( t1.getNode( "D" ) );
6184 t1.reRoot( t1.getNode( "CD" ) );
6185 t1.reRoot( t1.getNode( "A" ) );
6186 t1.reRoot( t1.getNode( "B" ) );
6187 t1.reRoot( t1.getNode( "AB" ) );
6188 t1.reRoot( t1.getNode( "D" ) );
6189 t1.reRoot( t1.getNode( "C" ) );
6190 t1.reRoot( t1.getNode( "CD" ) );
6191 t1.reRoot( t1.getNode( "A" ) );
6192 t1.reRoot( t1.getNode( "B" ) );
6193 t1.reRoot( t1.getNode( "AB" ) );
6194 t1.reRoot( t1.getNode( "D" ) );
6195 t1.reRoot( t1.getNode( "D" ) );
6196 t1.reRoot( t1.getNode( "C" ) );
6197 t1.reRoot( t1.getNode( "A" ) );
6198 t1.reRoot( t1.getNode( "B" ) );
6199 t1.reRoot( t1.getNode( "AB" ) );
6200 t1.reRoot( t1.getNode( "C" ) );
6201 t1.reRoot( t1.getNode( "D" ) );
6202 t1.reRoot( t1.getNode( "CD" ) );
6203 t1.reRoot( t1.getNode( "D" ) );
6204 t1.reRoot( t1.getNode( "A" ) );
6205 t1.reRoot( t1.getNode( "B" ) );
6206 t1.reRoot( t1.getNode( "AB" ) );
6207 t1.reRoot( t1.getNode( "C" ) );
6208 t1.reRoot( t1.getNode( "D" ) );
6209 t1.reRoot( t1.getNode( "CD" ) );
6210 t1.reRoot( t1.getNode( "D" ) );
6211 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6214 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6217 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6220 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
6223 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
6226 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
6229 final Phylogeny t2 = factory.create( "(((A:1,B:2)AB:10[&&NHX:B=55],C)ABC:3[&&NHX:B=33],D:5)ABCD:0.5",
6230 new NHXParser() )[ 0 ];
6231 t2.reRoot( t2.getNode( "A" ) );
6232 t2.reRoot( t2.getNode( "D" ) );
6233 t2.reRoot( t2.getNode( "ABC" ) );
6234 t2.reRoot( t2.getNode( "A" ) );
6235 t2.reRoot( t2.getNode( "B" ) );
6236 t2.reRoot( t2.getNode( "D" ) );
6237 t2.reRoot( t2.getNode( "C" ) );
6238 t2.reRoot( t2.getNode( "ABC" ) );
6239 t2.reRoot( t2.getNode( "A" ) );
6240 t2.reRoot( t2.getNode( "B" ) );
6241 t2.reRoot( t2.getNode( "AB" ) );
6242 t2.reRoot( t2.getNode( "AB" ) );
6243 t2.reRoot( t2.getNode( "D" ) );
6244 t2.reRoot( t2.getNode( "C" ) );
6245 t2.reRoot( t2.getNode( "B" ) );
6246 t2.reRoot( t2.getNode( "AB" ) );
6247 t2.reRoot( t2.getNode( "D" ) );
6248 t2.reRoot( t2.getNode( "D" ) );
6249 t2.reRoot( t2.getNode( "ABC" ) );
6250 t2.reRoot( t2.getNode( "A" ) );
6251 t2.reRoot( t2.getNode( "B" ) );
6252 t2.reRoot( t2.getNode( "AB" ) );
6253 t2.reRoot( t2.getNode( "D" ) );
6254 t2.reRoot( t2.getNode( "C" ) );
6255 t2.reRoot( t2.getNode( "ABC" ) );
6256 t2.reRoot( t2.getNode( "A" ) );
6257 t2.reRoot( t2.getNode( "B" ) );
6258 t2.reRoot( t2.getNode( "AB" ) );
6259 t2.reRoot( t2.getNode( "D" ) );
6260 t2.reRoot( t2.getNode( "D" ) );
6261 t2.reRoot( t2.getNode( "C" ) );
6262 t2.reRoot( t2.getNode( "A" ) );
6263 t2.reRoot( t2.getNode( "B" ) );
6264 t2.reRoot( t2.getNode( "AB" ) );
6265 t2.reRoot( t2.getNode( "C" ) );
6266 t2.reRoot( t2.getNode( "D" ) );
6267 t2.reRoot( t2.getNode( "ABC" ) );
6268 t2.reRoot( t2.getNode( "D" ) );
6269 t2.reRoot( t2.getNode( "A" ) );
6270 t2.reRoot( t2.getNode( "B" ) );
6271 t2.reRoot( t2.getNode( "AB" ) );
6272 t2.reRoot( t2.getNode( "C" ) );
6273 t2.reRoot( t2.getNode( "D" ) );
6274 t2.reRoot( t2.getNode( "ABC" ) );
6275 t2.reRoot( t2.getNode( "D" ) );
6276 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6279 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6282 t2.reRoot( t2.getNode( "ABC" ) );
6283 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6286 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6289 t2.reRoot( t2.getNode( "AB" ) );
6290 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6293 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6296 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6299 t2.reRoot( t2.getNode( "AB" ) );
6300 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6303 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6306 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6309 t2.reRoot( t2.getNode( "D" ) );
6310 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6313 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6316 t2.reRoot( t2.getNode( "ABC" ) );
6317 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6320 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6323 final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
6324 new NHXParser() )[ 0 ];
6325 t3.reRoot( t3.getNode( "B" ) );
6326 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6329 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6332 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6335 t3.reRoot( t3.getNode( "B" ) );
6336 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6339 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6342 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6345 t3.reRoot( t3.getRoot() );
6346 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6349 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6352 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6356 catch ( final Exception e ) {
6357 e.printStackTrace( System.out );
6363 private static boolean testSDIse() {
6365 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6366 final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
6367 final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
6368 gene1.setRooted( true );
6369 species1.setRooted( true );
6370 final SDI sdi = new SDI( gene1, species1 );
6371 if ( !gene1.getRoot().isDuplication() ) {
6374 final Phylogeny species2 = factory
6375 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6376 new NHXParser() )[ 0 ];
6377 final Phylogeny gene2 = factory
6378 .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6379 new NHXParser() )[ 0 ];
6380 species2.setRooted( true );
6381 gene2.setRooted( true );
6382 final SDI sdi2 = new SDI( gene2, species2 );
6383 if ( sdi2.getDuplicationsSum() != 0 ) {
6386 if ( !gene2.getNode( "ab" ).isSpeciation() ) {
6389 if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
6392 if ( !gene2.getNode( "abc" ).isSpeciation() ) {
6395 if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
6398 if ( !gene2.getNode( "r" ).isSpeciation() ) {
6401 if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
6404 final Phylogeny species3 = factory
6405 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6406 new NHXParser() )[ 0 ];
6407 final Phylogeny gene3 = factory
6408 .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6409 new NHXParser() )[ 0 ];
6410 species3.setRooted( true );
6411 gene3.setRooted( true );
6412 final SDI sdi3 = new SDI( gene3, species3 );
6413 if ( sdi3.getDuplicationsSum() != 1 ) {
6416 if ( !gene3.getNode( "aa" ).isDuplication() ) {
6419 if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
6422 final Phylogeny species4 = factory
6423 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6424 new NHXParser() )[ 0 ];
6425 final Phylogeny gene4 = factory
6426 .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6427 new NHXParser() )[ 0 ];
6428 species4.setRooted( true );
6429 gene4.setRooted( true );
6430 final SDI sdi4 = new SDI( gene4, species4 );
6431 if ( sdi4.getDuplicationsSum() != 1 ) {
6434 if ( !gene4.getNode( "ac" ).isSpeciation() ) {
6437 if ( !gene4.getNode( "abc" ).isDuplication() ) {
6440 if ( gene4.getNode( "abcd" ).isDuplication() ) {
6443 if ( species4.getNumberOfExternalNodes() != 6 ) {
6446 if ( gene4.getNumberOfExternalNodes() != 6 ) {
6449 final Phylogeny species5 = factory
6450 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6451 new NHXParser() )[ 0 ];
6452 final Phylogeny gene5 = factory
6453 .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6454 new NHXParser() )[ 0 ];
6455 species5.setRooted( true );
6456 gene5.setRooted( true );
6457 final SDI sdi5 = new SDI( gene5, species5 );
6458 if ( sdi5.getDuplicationsSum() != 2 ) {
6461 if ( !gene5.getNode( "ad" ).isSpeciation() ) {
6464 if ( !gene5.getNode( "adc" ).isDuplication() ) {
6467 if ( !gene5.getNode( "abcd" ).isDuplication() ) {
6470 if ( species5.getNumberOfExternalNodes() != 6 ) {
6473 if ( gene5.getNumberOfExternalNodes() != 6 ) {
6476 // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
6477 // Conjecture for Comparing Molecular Phylogenies"
6478 // J. of Comput Bio. Vol. 4, No 2, pp.177-187
6479 final Phylogeny species6 = factory
6480 .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
6481 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6482 new NHXParser() )[ 0 ];
6483 final Phylogeny gene6 = factory
6484 .create( "(((1:0.1[&&NHX:S=1],2:0.1[&&NHX:S=2])1-2:0.1,3:0.1[&&NHX:S=3])1-2-3:0.1,"
6485 + "((4:0.1[&&NHX:S=4],(5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.1)4-5-6:0.1,"
6486 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],9:0.1[&&NHX:S=9])8-9:0.1)7-8-9:0.1)4-5-6-7-8-9:0.1)r;",
6487 new NHXParser() )[ 0 ];
6488 species6.setRooted( true );
6489 gene6.setRooted( true );
6490 final SDI sdi6 = new SDI( gene6, species6 );
6491 if ( sdi6.getDuplicationsSum() != 3 ) {
6494 if ( !gene6.getNode( "r" ).isDuplication() ) {
6497 if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
6500 if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
6503 if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
6506 if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
6509 if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
6512 if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
6515 if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
6518 sdi6.computeMappingCostL();
6519 if ( sdi6.computeMappingCostL() != 17 ) {
6522 if ( species6.getNumberOfExternalNodes() != 9 ) {
6525 if ( gene6.getNumberOfExternalNodes() != 9 ) {
6528 final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
6529 + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
6530 + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
6531 + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
6532 + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
6533 species7.setRooted( true );
6534 final Phylogeny gene7_1 = Test
6535 .createPhylogeny( "((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2]),b1[&&NHX:S=b1]),x[&&NHX:S=x]),m1[&&NHX:S=m1]),i1[&&NHX:S=i1]),e1[&&NHX:S=e1]),y[&&NHX:S=y]),z[&&NHX:S=z])" );
6536 gene7_1.setRooted( true );
6537 final SDI sdi7 = new SDI( gene7_1, species7 );
6538 if ( sdi7.getDuplicationsSum() != 0 ) {
6541 if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
6544 if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
6547 if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
6550 if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
6553 if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
6556 if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
6559 if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
6562 if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
6565 final Phylogeny gene7_2 = Test
6566 .createPhylogeny( "(((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2]),b1[&&NHX:S=b1]),x[&&NHX:S=x]),m1[&&NHX:S=m1]),i1[&&NHX:S=i1]),j2[&&NHX:S=j2]),e1[&&NHX:S=e1]),y[&&NHX:S=y]),z[&&NHX:S=z])" );
6567 gene7_2.setRooted( true );
6568 final SDI sdi7_2 = new SDI( gene7_2, species7 );
6569 if ( sdi7_2.getDuplicationsSum() != 1 ) {
6572 if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
6575 if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
6578 if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
6581 if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
6584 if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
6587 if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
6590 if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
6593 if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
6596 if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
6600 catch ( final Exception e ) {
6606 private static boolean testSDIunrooted() {
6608 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6609 final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
6610 final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
6611 final Iterator<PhylogenyBranch> iter = l.iterator();
6612 PhylogenyBranch br = iter.next();
6613 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
6616 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
6620 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
6623 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
6627 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
6630 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
6634 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6637 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6641 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6644 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6648 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
6651 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
6655 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6658 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6662 if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6665 if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6669 if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6672 if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6676 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6679 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6683 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
6686 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
6690 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
6693 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
6697 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
6700 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
6704 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
6707 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
6711 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
6714 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
6717 if ( iter.hasNext() ) {
6720 final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
6721 final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
6722 final Iterator<PhylogenyBranch> iter1 = l1.iterator();
6724 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
6727 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
6731 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6734 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6738 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6741 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6744 if ( iter1.hasNext() ) {
6747 final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
6748 final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
6749 final Iterator<PhylogenyBranch> iter2 = l2.iterator();
6751 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
6754 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
6758 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6761 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6765 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6768 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6771 if ( iter2.hasNext() ) {
6774 final Phylogeny species0 = factory
6775 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6776 new NHXParser() )[ 0 ];
6777 final Phylogeny gene1 = factory
6778 .create( "(((((A:0.6[&&NHX:S=A],B:0.1[&&NHX:S=B])ab:0.1,C:0.1[&&NHX:S=C])abc:0.3,D:1.0[&&NHX:S=D])abcd:0.2,E:0.1[&&NHX:S=E])abcde:0.2,F:0.2[&&NHX:S=F])",
6779 new NHXParser() )[ 0 ];
6780 species0.setRooted( true );
6781 gene1.setRooted( true );
6782 final SDIR sdi_unrooted = new SDIR();
6783 sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
6784 if ( sdi_unrooted.getCount() != 1 ) {
6787 if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
6790 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
6793 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
6796 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6799 final Phylogeny gene2 = factory
6800 .create( "(((((A:2.6[&&NHX:S=A],B:0.1[&&NHX:S=B])ab:0.1,C:0.1[&&NHX:S=C])abc:0.3,D:1.0[&&NHX:S=D])abcd:0.2,E:0.1[&&NHX:S=E])abcde:0.2,F:0.2[&&NHX:S=F])",
6801 new NHXParser() )[ 0 ];
6802 gene2.setRooted( true );
6803 sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
6804 if ( sdi_unrooted.getCount() != 1 ) {
6807 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6810 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6813 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
6816 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6819 final Phylogeny species6 = factory
6820 .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
6821 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6822 new NHXParser() )[ 0 ];
6823 final Phylogeny gene6 = factory
6824 .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
6825 + "(((1:0.1[&&NHX:S=1],2:0.1[&&NHX:S=2])1-2:0.1[&&NHX:S=2],3:0.25[&&NHX:S=3])1-2-3:0.2[&&NHX:S=2],"
6826 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6827 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6828 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6829 new NHXParser() )[ 0 ];
6830 species6.setRooted( true );
6831 gene6.setRooted( true );
6832 Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
6833 if ( sdi_unrooted.getCount() != 1 ) {
6836 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6839 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6842 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6845 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6848 if ( !p6[ 0 ].getRoot().isDuplication() ) {
6851 if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6854 if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6857 if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
6860 if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6863 if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
6866 if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
6869 if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6873 final Phylogeny species7 = factory
6874 .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
6875 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6876 new NHXParser() )[ 0 ];
6877 final Phylogeny gene7 = factory
6878 .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
6879 + "(((1:0.1[&&NHX:S=1],2:0.1[&&NHX:S=2])1-2:0.1[&&NHX:S=2],3:0.25[&&NHX:S=3])1-2-3:0.2[&&NHX:S=2],"
6880 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6881 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6882 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6883 new NHXParser() )[ 0 ];
6884 species7.setRooted( true );
6885 gene7.setRooted( true );
6886 Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
6887 if ( sdi_unrooted.getCount() != 1 ) {
6890 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6893 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6896 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6899 if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
6902 if ( !p7[ 0 ].getRoot().isDuplication() ) {
6905 if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6908 if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6911 if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
6914 if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6917 if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
6920 if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
6923 if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6927 final Phylogeny species8 = factory
6928 .create( "(((1:[&&NHX:S=1],5:[&&NHX:S=5])1-5,((4:[&&NHX:S=4],6:[&&NHX:S=6])4-6,2:[&&NHX:S=2])4-6-2)1-5-4-6-2,"
6929 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6930 new NHXParser() )[ 0 ];
6931 final Phylogeny gene8 = factory
6932 .create( "((5:0.1[&&NHX:S=5],6:0.1[&&NHX:S=6])5-6:0.05[&&NHX:S=6],(4:0.1[&&NHX:S=4],"
6933 + "(((1:0.1[&&NHX:S=1],2:0.1[&&NHX:S=2])1-2:0.1[&&NHX:S=2],3:0.25[&&NHX:S=3])1-2-3:0.2[&&NHX:S=2],"
6934 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6935 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6936 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6937 new NHXParser() )[ 0 ];
6938 species8.setRooted( true );
6939 gene8.setRooted( true );
6940 Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
6941 if ( sdi_unrooted.getCount() != 1 ) {
6944 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6947 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6950 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6953 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6956 if ( !p8[ 0 ].getRoot().isDuplication() ) {
6959 if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6962 if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6965 if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
6968 if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6971 if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
6974 if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
6977 if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6982 catch ( final Exception e ) {
6983 e.printStackTrace( System.out );
6989 private static boolean testSplit() {
6991 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6992 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
6993 //Archaeopteryx.createApplication( p0 );
6994 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
6995 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6996 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6997 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6998 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6999 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7000 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7001 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7002 ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7003 ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7004 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
7005 // System.out.println( s0.toString() );
7007 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
7008 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7009 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7010 if ( s0.match( query_nodes ) ) {
7013 query_nodes = new HashSet<PhylogenyNode>();
7014 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7015 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7016 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7017 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7018 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7019 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7020 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7021 if ( !s0.match( query_nodes ) ) {
7025 query_nodes = new HashSet<PhylogenyNode>();
7026 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7027 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7028 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7029 if ( !s0.match( query_nodes ) ) {
7033 query_nodes = new HashSet<PhylogenyNode>();
7034 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7035 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7036 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7037 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7038 if ( !s0.match( query_nodes ) ) {
7042 query_nodes = new HashSet<PhylogenyNode>();
7043 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7044 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7045 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7046 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7047 if ( !s0.match( query_nodes ) ) {
7051 query_nodes = new HashSet<PhylogenyNode>();
7052 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7053 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7054 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7055 if ( !s0.match( query_nodes ) ) {
7059 query_nodes = new HashSet<PhylogenyNode>();
7060 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7061 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7062 if ( !s0.match( query_nodes ) ) {
7066 query_nodes = new HashSet<PhylogenyNode>();
7067 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7068 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7069 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7070 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7071 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7072 if ( !s0.match( query_nodes ) ) {
7076 query_nodes = new HashSet<PhylogenyNode>();
7077 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7078 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7079 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7080 if ( !s0.match( query_nodes ) ) {
7084 query_nodes = new HashSet<PhylogenyNode>();
7085 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7086 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7087 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7088 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7089 if ( !s0.match( query_nodes ) ) {
7093 query_nodes = new HashSet<PhylogenyNode>();
7094 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7095 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7096 if ( s0.match( query_nodes ) ) {
7100 query_nodes = new HashSet<PhylogenyNode>();
7101 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7102 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7103 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7104 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7105 if ( s0.match( query_nodes ) ) {
7109 query_nodes = new HashSet<PhylogenyNode>();
7110 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7111 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7112 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7113 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7114 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7115 if ( s0.match( query_nodes ) ) {
7119 query_nodes = new HashSet<PhylogenyNode>();
7120 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7121 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7122 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7123 if ( s0.match( query_nodes ) ) {
7127 query_nodes = new HashSet<PhylogenyNode>();
7128 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7129 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7130 if ( s0.match( query_nodes ) ) {
7134 query_nodes = new HashSet<PhylogenyNode>();
7135 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7136 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7137 if ( s0.match( query_nodes ) ) {
7141 query_nodes = new HashSet<PhylogenyNode>();
7142 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7143 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7144 if ( s0.match( query_nodes ) ) {
7148 query_nodes = new HashSet<PhylogenyNode>();
7149 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7150 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7151 if ( s0.match( query_nodes ) ) {
7155 query_nodes = new HashSet<PhylogenyNode>();
7156 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7157 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7158 if ( s0.match( query_nodes ) ) {
7162 query_nodes = new HashSet<PhylogenyNode>();
7163 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7164 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7165 if ( s0.match( query_nodes ) ) {
7169 query_nodes = new HashSet<PhylogenyNode>();
7170 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7171 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7172 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7173 if ( s0.match( query_nodes ) ) {
7177 query_nodes = new HashSet<PhylogenyNode>();
7178 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7179 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7180 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7181 if ( s0.match( query_nodes ) ) {
7185 query_nodes = new HashSet<PhylogenyNode>();
7186 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7187 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7188 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7189 if ( s0.match( query_nodes ) ) {
7193 query_nodes = new HashSet<PhylogenyNode>();
7194 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7195 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7196 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7197 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7198 if ( s0.match( query_nodes ) ) {
7202 // query_nodes = new HashSet<PhylogenyNode>();
7203 // query_nodes.add( new PhylogenyNode( "X" ) );
7204 // query_nodes.add( new PhylogenyNode( "Y" ) );
7205 // query_nodes.add( new PhylogenyNode( "A" ) );
7206 // query_nodes.add( new PhylogenyNode( "B" ) );
7207 // query_nodes.add( new PhylogenyNode( "C" ) );
7208 // query_nodes.add( new PhylogenyNode( "D" ) );
7209 // query_nodes.add( new PhylogenyNode( "E" ) );
7210 // query_nodes.add( new PhylogenyNode( "F" ) );
7211 // query_nodes.add( new PhylogenyNode( "G" ) );
7212 // if ( !s0.match( query_nodes ) ) {
7215 // query_nodes = new HashSet<PhylogenyNode>();
7216 // query_nodes.add( new PhylogenyNode( "X" ) );
7217 // query_nodes.add( new PhylogenyNode( "Y" ) );
7218 // query_nodes.add( new PhylogenyNode( "A" ) );
7219 // query_nodes.add( new PhylogenyNode( "B" ) );
7220 // query_nodes.add( new PhylogenyNode( "C" ) );
7221 // if ( !s0.match( query_nodes ) ) {
7225 // query_nodes = new HashSet<PhylogenyNode>();
7226 // query_nodes.add( new PhylogenyNode( "X" ) );
7227 // query_nodes.add( new PhylogenyNode( "Y" ) );
7228 // query_nodes.add( new PhylogenyNode( "D" ) );
7229 // query_nodes.add( new PhylogenyNode( "E" ) );
7230 // query_nodes.add( new PhylogenyNode( "F" ) );
7231 // query_nodes.add( new PhylogenyNode( "G" ) );
7232 // if ( !s0.match( query_nodes ) ) {
7236 // query_nodes = new HashSet<PhylogenyNode>();
7237 // query_nodes.add( new PhylogenyNode( "X" ) );
7238 // query_nodes.add( new PhylogenyNode( "Y" ) );
7239 // query_nodes.add( new PhylogenyNode( "A" ) );
7240 // query_nodes.add( new PhylogenyNode( "B" ) );
7241 // query_nodes.add( new PhylogenyNode( "C" ) );
7242 // query_nodes.add( new PhylogenyNode( "D" ) );
7243 // if ( !s0.match( query_nodes ) ) {
7247 // query_nodes = new HashSet<PhylogenyNode>();
7248 // query_nodes.add( new PhylogenyNode( "X" ) );
7249 // query_nodes.add( new PhylogenyNode( "Y" ) );
7250 // query_nodes.add( new PhylogenyNode( "E" ) );
7251 // query_nodes.add( new PhylogenyNode( "F" ) );
7252 // query_nodes.add( new PhylogenyNode( "G" ) );
7253 // if ( !s0.match( query_nodes ) ) {
7257 // query_nodes = new HashSet<PhylogenyNode>();
7258 // query_nodes.add( new PhylogenyNode( "X" ) );
7259 // query_nodes.add( new PhylogenyNode( "Y" ) );
7260 // query_nodes.add( new PhylogenyNode( "F" ) );
7261 // query_nodes.add( new PhylogenyNode( "G" ) );
7262 // if ( !s0.match( query_nodes ) ) {
7266 query_nodes = new HashSet<PhylogenyNode>();
7267 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7268 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7269 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7270 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7271 if ( s0.match( query_nodes ) ) {
7275 query_nodes = new HashSet<PhylogenyNode>();
7276 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7277 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7278 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7279 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7280 if ( s0.match( query_nodes ) ) {
7283 ///////////////////////////
7285 query_nodes = new HashSet<PhylogenyNode>();
7286 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7287 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7288 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7289 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7290 if ( s0.match( query_nodes ) ) {
7294 query_nodes = new HashSet<PhylogenyNode>();
7295 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7296 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7297 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7298 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7299 if ( s0.match( query_nodes ) ) {
7303 query_nodes = new HashSet<PhylogenyNode>();
7304 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7305 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7306 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7307 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7308 if ( s0.match( query_nodes ) ) {
7312 query_nodes = new HashSet<PhylogenyNode>();
7313 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7314 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7315 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7316 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7317 if ( s0.match( query_nodes ) ) {
7321 query_nodes = new HashSet<PhylogenyNode>();
7322 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7323 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7324 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7325 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7326 if ( s0.match( query_nodes ) ) {
7330 query_nodes = new HashSet<PhylogenyNode>();
7331 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7332 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7333 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7334 if ( s0.match( query_nodes ) ) {
7338 query_nodes = new HashSet<PhylogenyNode>();
7339 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7340 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7341 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7342 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7343 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7344 if ( s0.match( query_nodes ) ) {
7348 query_nodes = new HashSet<PhylogenyNode>();
7349 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7350 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7351 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7352 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7353 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7354 if ( s0.match( query_nodes ) ) {
7358 query_nodes = new HashSet<PhylogenyNode>();
7359 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7360 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7361 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7362 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7363 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7364 if ( s0.match( query_nodes ) ) {
7368 query_nodes = new HashSet<PhylogenyNode>();
7369 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7370 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7371 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7372 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7373 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7374 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7375 if ( s0.match( query_nodes ) ) {
7379 catch ( final Exception e ) {
7380 e.printStackTrace();
7386 private static boolean testSplitStrict() {
7388 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7389 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
7390 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
7391 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7392 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7393 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7394 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7395 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7396 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7397 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7398 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
7399 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
7400 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7401 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7402 if ( s0.match( query_nodes ) ) {
7405 query_nodes = new HashSet<PhylogenyNode>();
7406 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7407 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7408 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7409 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7410 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7411 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7412 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7413 if ( !s0.match( query_nodes ) ) {
7417 query_nodes = new HashSet<PhylogenyNode>();
7418 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7419 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7420 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7421 if ( !s0.match( query_nodes ) ) {
7425 query_nodes = new HashSet<PhylogenyNode>();
7426 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7427 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7428 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7429 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7430 if ( !s0.match( query_nodes ) ) {
7434 query_nodes = new HashSet<PhylogenyNode>();
7435 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7436 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7437 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7438 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7439 if ( !s0.match( query_nodes ) ) {
7443 query_nodes = new HashSet<PhylogenyNode>();
7444 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7445 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7446 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7447 if ( !s0.match( query_nodes ) ) {
7451 query_nodes = new HashSet<PhylogenyNode>();
7452 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7453 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7454 if ( !s0.match( query_nodes ) ) {
7458 query_nodes = new HashSet<PhylogenyNode>();
7459 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7460 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7461 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7462 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7463 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7464 if ( !s0.match( query_nodes ) ) {
7468 query_nodes = new HashSet<PhylogenyNode>();
7469 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7470 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7471 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7472 if ( !s0.match( query_nodes ) ) {
7476 query_nodes = new HashSet<PhylogenyNode>();
7477 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7478 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7479 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7480 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7481 if ( !s0.match( query_nodes ) ) {
7485 query_nodes = new HashSet<PhylogenyNode>();
7486 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7487 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7488 if ( s0.match( query_nodes ) ) {
7492 query_nodes = new HashSet<PhylogenyNode>();
7493 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7494 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7495 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7496 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7497 if ( s0.match( query_nodes ) ) {
7501 query_nodes = new HashSet<PhylogenyNode>();
7502 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7503 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7504 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7505 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7506 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7507 if ( s0.match( query_nodes ) ) {
7511 query_nodes = new HashSet<PhylogenyNode>();
7512 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7513 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7514 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7515 if ( s0.match( query_nodes ) ) {
7519 query_nodes = new HashSet<PhylogenyNode>();
7520 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7521 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7522 if ( s0.match( query_nodes ) ) {
7526 query_nodes = new HashSet<PhylogenyNode>();
7527 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7528 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7529 if ( s0.match( query_nodes ) ) {
7533 query_nodes = new HashSet<PhylogenyNode>();
7534 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7535 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7536 if ( s0.match( query_nodes ) ) {
7540 query_nodes = new HashSet<PhylogenyNode>();
7541 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7542 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7543 if ( s0.match( query_nodes ) ) {
7547 query_nodes = new HashSet<PhylogenyNode>();
7548 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7549 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7550 if ( s0.match( query_nodes ) ) {
7554 query_nodes = new HashSet<PhylogenyNode>();
7555 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7556 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7557 if ( s0.match( query_nodes ) ) {
7561 query_nodes = new HashSet<PhylogenyNode>();
7562 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7563 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7564 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7565 if ( s0.match( query_nodes ) ) {
7569 query_nodes = new HashSet<PhylogenyNode>();
7570 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7571 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7572 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7573 if ( s0.match( query_nodes ) ) {
7577 query_nodes = new HashSet<PhylogenyNode>();
7578 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7579 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7580 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7581 if ( s0.match( query_nodes ) ) {
7585 query_nodes = new HashSet<PhylogenyNode>();
7586 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7587 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7588 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7589 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7590 if ( s0.match( query_nodes ) ) {
7594 catch ( final Exception e ) {
7595 e.printStackTrace();
7601 private static boolean testSubtreeDeletion() {
7603 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7604 final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
7605 t1.deleteSubtree( t1.getNode( "A" ), false );
7606 if ( t1.getNumberOfExternalNodes() != 5 ) {
7609 t1.toNewHampshireX();
7610 t1.deleteSubtree( t1.getNode( "E" ), false );
7611 if ( t1.getNumberOfExternalNodes() != 4 ) {
7614 t1.toNewHampshireX();
7615 t1.deleteSubtree( t1.getNode( "F" ), false );
7616 if ( t1.getNumberOfExternalNodes() != 3 ) {
7619 t1.toNewHampshireX();
7620 t1.deleteSubtree( t1.getNode( "D" ), false );
7621 t1.toNewHampshireX();
7622 if ( t1.getNumberOfExternalNodes() != 3 ) {
7625 t1.deleteSubtree( t1.getNode( "def" ), false );
7626 t1.toNewHampshireX();
7627 if ( t1.getNumberOfExternalNodes() != 2 ) {
7630 t1.deleteSubtree( t1.getNode( "B" ), false );
7631 t1.toNewHampshireX();
7632 if ( t1.getNumberOfExternalNodes() != 1 ) {
7635 t1.deleteSubtree( t1.getNode( "C" ), false );
7636 t1.toNewHampshireX();
7637 if ( t1.getNumberOfExternalNodes() != 1 ) {
7640 t1.deleteSubtree( t1.getNode( "abc" ), false );
7641 t1.toNewHampshireX();
7642 if ( t1.getNumberOfExternalNodes() != 1 ) {
7645 t1.deleteSubtree( t1.getNode( "r" ), false );
7646 if ( t1.getNumberOfExternalNodes() != 0 ) {
7649 if ( !t1.isEmpty() ) {
7652 final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
7653 t2.deleteSubtree( t2.getNode( "A" ), false );
7654 t2.toNewHampshireX();
7655 if ( t2.getNumberOfExternalNodes() != 5 ) {
7658 t2.deleteSubtree( t2.getNode( "abc" ), false );
7659 t2.toNewHampshireX();
7660 if ( t2.getNumberOfExternalNodes() != 3 ) {
7663 t2.deleteSubtree( t2.getNode( "def" ), false );
7664 t2.toNewHampshireX();
7665 if ( t2.getNumberOfExternalNodes() != 1 ) {
7669 catch ( final Exception e ) {
7670 e.printStackTrace( System.out );
7676 private static boolean testSupportCount() {
7678 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7679 final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
7680 final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
7681 + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
7682 + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
7683 + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
7684 + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
7686 SupportCount.count( t0_1, phylogenies_1, true, false );
7687 final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
7688 final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
7689 + "(((((A,B),C),D),E),((F,G),X))"
7690 + "(((((A,Y),B),C),D),((F,G),E))"
7691 + "(((((A,B),C),D),E),(F,G))"
7692 + "(((((A,B),C),D),E),(F,G))"
7693 + "(((((A,B),C),D),E),(F,G))"
7694 + "(((((A,B),C),D),E),(F,G),Z)"
7695 + "(((((A,B),C),D),E),(F,G))"
7696 + "((((((A,B),C),D),E),F),G)"
7697 + "(((((X,Y),F,G),E),((A,B),C)),D)",
7699 SupportCount.count( t0_2, phylogenies_2, true, false );
7700 final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
7701 while ( it.hasNext() ) {
7702 final PhylogenyNode n = it.next();
7703 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
7707 final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
7708 final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
7709 + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
7710 SupportCount.count( t0_3, phylogenies_3, true, false );
7711 t0_3.reRoot( t0_3.getNode( "def" ).getId() );
7712 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
7715 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
7718 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
7721 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
7724 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
7727 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
7730 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
7733 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
7736 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
7739 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
7742 final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7743 final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
7744 + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
7745 SupportCount.count( t0_4, phylogenies_4, true, false );
7746 t0_4.reRoot( t0_4.getNode( "F" ).getId() );
7747 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
7750 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
7753 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
7756 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
7759 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
7762 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
7765 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
7768 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
7771 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
7774 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
7777 Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7778 final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7779 double d = SupportCount.compare( b1, a, true, true, true );
7780 if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
7783 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7784 final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7785 d = SupportCount.compare( b2, a, true, true, true );
7786 if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
7789 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7790 final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
7791 d = SupportCount.compare( b3, a, true, true, true );
7792 if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
7795 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
7796 final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
7797 d = SupportCount.compare( b4, a, true, true, false );
7798 if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
7802 catch ( final Exception e ) {
7803 e.printStackTrace( System.out );
7809 private static boolean testSupportTransfer() {
7811 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7812 final Phylogeny p1 = factory.create( "(((A,B)ab:97,C)abc:57,((D,E)de:10,(F,G)fg:50,(H,I)hi:64)defghi)",
7813 new NHXParser() )[ 0 ];
7814 final Phylogeny p2 = factory
7815 .create( "(((A:0.1,B:0.3)ab:0.4,C)abc:0.5,((D,E)de,(F,G)fg,(H,I)hi:0.59)defghi)", new NHXParser() )[ 0 ];
7816 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
7819 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
7822 support_transfer.moveBranchLengthsToBootstrap( p1 );
7823 support_transfer.transferSupportValues( p1, p2 );
7824 if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
7827 if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
7830 if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
7833 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
7836 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
7839 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
7842 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
7845 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
7849 catch ( final Exception e ) {
7850 e.printStackTrace( System.out );
7856 private static boolean testUniprotTaxonomySearch() {
7858 List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
7860 if ( results.size() != 1 ) {
7863 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7866 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7869 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7872 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7875 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7879 results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
7880 if ( results.size() != 1 ) {
7883 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7886 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7889 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7892 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7895 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7899 results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
7900 if ( results.size() != 1 ) {
7903 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7906 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7909 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7912 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7915 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7919 results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
7920 if ( results.size() != 1 ) {
7923 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7926 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7929 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7932 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7935 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7938 if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
7941 if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
7944 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
7945 .equals( "Nematostella vectensis" ) ) {
7946 System.out.println( results.get( 0 ).getLineage() );
7950 catch ( final IOException e ) {
7951 System.out.println();
7952 System.out.println( "the following might be due to absence internet connection:" );
7953 e.printStackTrace( System.out );
7956 catch ( final Exception e ) {
7962 private static boolean testEmblEntryRetrieval() {
7963 //The format for GenBank Accession numbers are:
7964 //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
7965 //Protein: 3 letters + 5 numerals
7966 //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
7967 if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
7970 if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) {
7973 if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
7976 if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
7979 if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
7982 if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
7985 if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
7988 if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
7991 if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
7994 if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
7997 if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
8000 if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
8003 if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
8009 private static boolean testUniprotEntryRetrieval() {
8010 if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) {
8013 if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) {
8016 if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) {
8019 if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) {
8022 if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) {
8025 if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) {
8028 if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) {
8031 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) {
8034 if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) {
8037 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) {
8040 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) {
8043 if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) {
8046 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) {
8050 final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
8051 if ( !entry.getAccession().equals( "P12345" ) ) {
8054 if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
8057 if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
8060 if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) {
8063 if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
8067 catch ( final IOException e ) {
8068 System.out.println();
8069 System.out.println( "the following might be due to absence internet connection:" );
8070 e.printStackTrace( System.out );
8073 catch ( final Exception e ) {
8079 private static boolean testWabiTxSearch() {
8082 result = TxSearch.searchSimple( "nematostella" );
8083 result = TxSearch.getTxId( "nematostella" );
8084 if ( !result.equals( "45350" ) ) {
8087 result = TxSearch.getTxName( "45350" );
8088 if ( !result.equals( "Nematostella" ) ) {
8091 result = TxSearch.getTxId( "nematostella vectensis" );
8092 if ( !result.equals( "45351" ) ) {
8095 result = TxSearch.getTxName( "45351" );
8096 if ( !result.equals( "Nematostella vectensis" ) ) {
8099 result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
8100 if ( !result.equals( "536089" ) ) {
8103 result = TxSearch.getTxName( "536089" );
8104 if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
8107 final List<String> queries = new ArrayList<String>();
8108 queries.add( "Campylobacter coli" );
8109 queries.add( "Escherichia coli" );
8110 queries.add( "Arabidopsis" );
8111 queries.add( "Trichoplax" );
8112 queries.add( "Samanea saman" );
8113 queries.add( "Kluyveromyces marxianus" );
8114 queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
8115 queries.add( "Bornavirus parrot/PDD/2008" );
8116 final List<RANKS> ranks = new ArrayList<RANKS>();
8117 ranks.add( RANKS.SUPERKINGDOM );
8118 ranks.add( RANKS.KINGDOM );
8119 ranks.add( RANKS.FAMILY );
8120 ranks.add( RANKS.GENUS );
8121 ranks.add( RANKS.TRIBE );
8122 result = TxSearch.searchLineage( queries, ranks );
8123 result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
8124 result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
8126 catch ( final Exception e ) {
8127 System.out.println();
8128 System.out.println( "the following might be due to absence internet connection:" );
8129 e.printStackTrace( System.out );
8135 private static boolean testAminoAcidSequence() {
8137 final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
8138 if ( aa1.getLength() != 13 ) {
8141 if ( aa1.getResidueAt( 0 ) != 'A' ) {
8144 if ( aa1.getResidueAt( 2 ) != 'K' ) {
8147 if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
8150 final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
8151 if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
8154 final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
8155 if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
8158 final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
8159 if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
8163 catch ( final Exception e ) {
8164 e.printStackTrace();
8170 private static boolean testCreateBalancedPhylogeny() {
8172 final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
8173 if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
8176 if ( p0.getNumberOfExternalNodes() != 15625 ) {
8179 final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
8180 if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
8183 if ( p1.getNumberOfExternalNodes() != 100 ) {
8187 catch ( final Exception e ) {
8188 e.printStackTrace();
8194 private static boolean testFastaParser() {
8196 if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
8199 if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
8202 final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
8203 if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
8206 if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
8209 if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
8212 if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
8215 if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
8218 if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
8222 catch ( final Exception e ) {
8223 e.printStackTrace();
8229 private static boolean testGeneralMsaParser() {
8231 final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
8232 final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
8233 final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
8234 final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
8235 final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
8236 final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
8237 final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
8238 final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
8239 if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8242 if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8245 if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8248 if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8251 if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8254 if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8257 if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8260 if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8263 if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8266 if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8269 if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8272 if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8275 final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
8276 if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
8279 if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
8282 if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
8285 final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
8286 if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
8289 if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
8292 if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
8295 final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
8296 if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
8299 if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
8302 if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
8306 catch ( final Exception e ) {
8307 e.printStackTrace();
8313 private static boolean testMafft( final String path ) {
8315 final List<String> opts = new ArrayList<String>();
8316 opts.add( "--maxiterate" );
8318 opts.add( "--localpair" );
8319 opts.add( "--quiet" );
8321 final MsaInferrer mafft = Mafft.createInstance( path );
8322 msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
8323 if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
8326 if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
8330 catch ( final Exception e ) {
8331 e.printStackTrace( System.out );
8337 private static boolean testNextNodeWithCollapsing() {
8339 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8341 List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
8342 final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8343 final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
8344 t0.getNode( "cd" ).setCollapse( true );
8345 t0.getNode( "cde" ).setCollapse( true );
8346 n = t0.getFirstExternalNode();
8347 while ( n != null ) {
8349 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8351 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8354 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8357 if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
8360 if ( !ext.get( 3 ).getName().equals( "f" ) ) {
8363 if ( !ext.get( 4 ).getName().equals( "g" ) ) {
8366 if ( !ext.get( 5 ).getName().equals( "h" ) ) {
8370 final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8371 final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
8372 t1.getNode( "ab" ).setCollapse( true );
8373 t1.getNode( "cd" ).setCollapse( true );
8374 t1.getNode( "cde" ).setCollapse( true );
8375 n = t1.getNode( "ab" );
8376 ext = new ArrayList<PhylogenyNode>();
8377 while ( n != null ) {
8379 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8381 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8384 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8387 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
8390 if ( !ext.get( 3 ).getName().equals( "g" ) ) {
8393 if ( !ext.get( 4 ).getName().equals( "h" ) ) {
8399 final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8400 final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
8401 t2.getNode( "ab" ).setCollapse( true );
8402 t2.getNode( "cd" ).setCollapse( true );
8403 t2.getNode( "cde" ).setCollapse( true );
8404 t2.getNode( "c" ).setCollapse( true );
8405 t2.getNode( "d" ).setCollapse( true );
8406 t2.getNode( "e" ).setCollapse( true );
8407 t2.getNode( "gh" ).setCollapse( true );
8408 n = t2.getNode( "ab" );
8409 ext = new ArrayList<PhylogenyNode>();
8410 while ( n != null ) {
8412 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8414 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8417 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8420 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
8423 if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
8429 final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8430 final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
8431 t3.getNode( "ab" ).setCollapse( true );
8432 t3.getNode( "cd" ).setCollapse( true );
8433 t3.getNode( "cde" ).setCollapse( true );
8434 t3.getNode( "c" ).setCollapse( true );
8435 t3.getNode( "d" ).setCollapse( true );
8436 t3.getNode( "e" ).setCollapse( true );
8437 t3.getNode( "gh" ).setCollapse( true );
8438 t3.getNode( "fgh" ).setCollapse( true );
8439 n = t3.getNode( "ab" );
8440 ext = new ArrayList<PhylogenyNode>();
8441 while ( n != null ) {
8443 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8445 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8448 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8451 if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
8457 final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8458 final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
8459 t4.getNode( "ab" ).setCollapse( true );
8460 t4.getNode( "cd" ).setCollapse( true );
8461 t4.getNode( "cde" ).setCollapse( true );
8462 t4.getNode( "c" ).setCollapse( true );
8463 t4.getNode( "d" ).setCollapse( true );
8464 t4.getNode( "e" ).setCollapse( true );
8465 t4.getNode( "gh" ).setCollapse( true );
8466 t4.getNode( "fgh" ).setCollapse( true );
8467 t4.getNode( "abcdefgh" ).setCollapse( true );
8468 n = t4.getNode( "abcdefgh" );
8469 if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
8474 final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8475 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
8477 n = t5.getFirstExternalNode();
8478 while ( n != null ) {
8480 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8482 if ( ext.size() != 8 ) {
8485 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8488 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8491 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8494 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8497 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8500 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8503 if ( !ext.get( 6 ).getName().equals( "g" ) ) {
8506 if ( !ext.get( 7 ).getName().equals( "h" ) ) {
8511 final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8512 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
8514 t6.getNode( "ab" ).setCollapse( true );
8515 n = t6.getNode( "ab" );
8516 while ( n != null ) {
8518 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8520 if ( ext.size() != 7 ) {
8523 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8526 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8529 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8532 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8535 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8538 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8541 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8546 final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8547 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
8549 t7.getNode( "cd" ).setCollapse( true );
8550 n = t7.getNode( "a" );
8551 while ( n != null ) {
8553 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8555 if ( ext.size() != 7 ) {
8558 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8561 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8564 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
8567 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8570 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8573 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8576 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8581 final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8582 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
8584 t8.getNode( "cd" ).setCollapse( true );
8585 t8.getNode( "c" ).setCollapse( true );
8586 t8.getNode( "d" ).setCollapse( true );
8587 n = t8.getNode( "a" );
8588 while ( n != null ) {
8590 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8592 if ( ext.size() != 7 ) {
8595 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8598 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8601 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
8602 System.out.println( "2 fail" );
8605 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8608 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8611 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8614 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8619 final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8620 final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
8622 t9.getNode( "gh" ).setCollapse( true );
8623 n = t9.getNode( "a" );
8624 while ( n != null ) {
8626 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8628 if ( ext.size() != 7 ) {
8631 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8634 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8637 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8640 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8643 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8646 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8649 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
8654 final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8655 final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
8657 t10.getNode( "gh" ).setCollapse( true );
8658 t10.getNode( "g" ).setCollapse( true );
8659 t10.getNode( "h" ).setCollapse( true );
8660 n = t10.getNode( "a" );
8661 while ( n != null ) {
8663 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8665 if ( ext.size() != 7 ) {
8668 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8671 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8674 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8677 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8680 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8683 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8686 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
8691 final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8692 final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
8694 t11.getNode( "gh" ).setCollapse( true );
8695 t11.getNode( "fgh" ).setCollapse( true );
8696 n = t11.getNode( "a" );
8697 while ( n != null ) {
8699 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8701 if ( ext.size() != 6 ) {
8704 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8707 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8710 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8713 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8716 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8719 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8724 final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8725 final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
8727 t12.getNode( "gh" ).setCollapse( true );
8728 t12.getNode( "fgh" ).setCollapse( true );
8729 t12.getNode( "g" ).setCollapse( true );
8730 t12.getNode( "h" ).setCollapse( true );
8731 t12.getNode( "f" ).setCollapse( true );
8732 n = t12.getNode( "a" );
8733 while ( n != null ) {
8735 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8737 if ( ext.size() != 6 ) {
8740 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8743 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8746 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8749 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8752 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8755 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8760 final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8761 final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
8763 t13.getNode( "ab" ).setCollapse( true );
8764 t13.getNode( "b" ).setCollapse( true );
8765 t13.getNode( "fgh" ).setCollapse( true );
8766 t13.getNode( "gh" ).setCollapse( true );
8767 n = t13.getNode( "ab" );
8768 while ( n != null ) {
8770 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8772 if ( ext.size() != 5 ) {
8775 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8778 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8781 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8784 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8787 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
8792 final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
8793 final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
8795 t14.getNode( "ab" ).setCollapse( true );
8796 t14.getNode( "a" ).setCollapse( true );
8797 t14.getNode( "fgh" ).setCollapse( true );
8798 t14.getNode( "gh" ).setCollapse( true );
8799 n = t14.getNode( "ab" );
8800 while ( n != null ) {
8802 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8804 if ( ext.size() != 5 ) {
8807 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8810 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8813 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8816 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8819 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
8824 final StringBuffer sb15 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,x,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
8825 final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
8827 t15.getNode( "ab" ).setCollapse( true );
8828 t15.getNode( "a" ).setCollapse( true );
8829 t15.getNode( "fgh" ).setCollapse( true );
8830 t15.getNode( "gh" ).setCollapse( true );
8831 n = t15.getNode( "ab" );
8832 while ( n != null ) {
8834 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8836 if ( ext.size() != 6 ) {
8839 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8842 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8845 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8848 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8851 if ( !ext.get( 4 ).getName().equals( "x" ) ) {
8854 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8859 final StringBuffer sb16 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,x,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
8860 final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
8862 t16.getNode( "ab" ).setCollapse( true );
8863 t16.getNode( "a" ).setCollapse( true );
8864 t16.getNode( "fgh" ).setCollapse( true );
8865 t16.getNode( "gh" ).setCollapse( true );
8866 t16.getNode( "cd" ).setCollapse( true );
8867 t16.getNode( "cde" ).setCollapse( true );
8868 t16.getNode( "d" ).setCollapse( true );
8869 t16.getNode( "x" ).setCollapse( true );
8870 n = t16.getNode( "ab" );
8871 while ( n != null ) {
8873 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8875 if ( ext.size() != 4 ) {
8878 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8881 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8884 if ( !ext.get( 2 ).getName().equals( "x" ) ) {
8887 if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
8891 catch ( final Exception e ) {
8892 e.printStackTrace( System.out );
8898 private static boolean testMsaQualityMethod() {
8900 final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
8901 final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
8902 final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
8903 final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
8904 final List<Sequence> l = new ArrayList<Sequence>();
8909 final Msa msa = BasicMsa.createInstance( l );
8910 if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
8913 if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
8916 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
8919 if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
8923 catch ( final Exception e ) {
8924 e.printStackTrace( System.out );
8930 private static boolean testSequenceIdParsing() {
8932 Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
8933 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8934 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8936 System.out.println( "value =" + id.getValue() );
8937 System.out.println( "provider=" + id.getProvider() );
8942 id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
8943 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8944 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8946 System.out.println( "value =" + id.getValue() );
8947 System.out.println( "provider=" + id.getProvider() );
8952 id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
8953 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8954 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8956 System.out.println( "value =" + id.getValue() );
8957 System.out.println( "provider=" + id.getProvider() );
8962 id = SequenceIdParser.parse( "gb_AAA96518_1" );
8963 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8964 || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
8966 System.out.println( "value =" + id.getValue() );
8967 System.out.println( "provider=" + id.getProvider() );
8972 id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
8973 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8974 || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
8976 System.out.println( "value =" + id.getValue() );
8977 System.out.println( "provider=" + id.getProvider() );
8982 id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
8983 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8984 || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
8986 System.out.println( "value =" + id.getValue() );
8987 System.out.println( "provider=" + id.getProvider() );
8992 id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
8993 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8994 || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
8996 System.out.println( "value =" + id.getValue() );
8997 System.out.println( "provider=" + id.getProvider() );
9002 id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
9003 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9004 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
9006 System.out.println( "value =" + id.getValue() );
9007 System.out.println( "provider=" + id.getProvider() );
9012 id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
9013 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9014 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
9016 System.out.println( "value =" + id.getValue() );
9017 System.out.println( "provider=" + id.getProvider() );
9022 id = SequenceIdParser.parse( "P4A123" );
9023 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9024 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9026 System.out.println( "value =" + id.getValue() );
9027 System.out.println( "provider=" + id.getProvider() );
9032 id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
9033 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9034 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9036 System.out.println( "value =" + id.getValue() );
9037 System.out.println( "provider=" + id.getProvider() );
9042 id = SequenceIdParser.parse( "XP_12345" );
9044 System.out.println( "value =" + id.getValue() );
9045 System.out.println( "provider=" + id.getProvider() );
9048 // lcl_91970_unknown_
9050 catch ( final Exception e ) {
9051 e.printStackTrace( System.out );