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( "Support count: " );
463 if ( Test.testSupportCount() ) {
464 System.out.println( "OK." );
468 System.out.println( "failed." );
471 System.out.print( "Support transfer: " );
472 if ( Test.testSupportTransfer() ) {
473 System.out.println( "OK." );
477 System.out.println( "failed." );
480 System.out.print( "Finding of LCA: " );
481 if ( Test.testGetLCA() ) {
482 System.out.println( "OK." );
486 System.out.println( "failed." );
489 System.out.print( "Finding of LCA 2: " );
490 if ( Test.testGetLCA2() ) {
491 System.out.println( "OK." );
495 System.out.println( "failed." );
498 System.out.print( "Calculation of distance between nodes: " );
499 if ( Test.testGetDistance() ) {
500 System.out.println( "OK." );
504 System.out.println( "failed." );
507 System.out.print( "Descriptive statistics: " );
508 if ( Test.testDescriptiveStatistics() ) {
509 System.out.println( "OK." );
513 System.out.println( "failed." );
516 System.out.print( "Data objects and methods: " );
517 if ( Test.testDataObjects() ) {
518 System.out.println( "OK." );
522 System.out.println( "failed." );
525 System.out.print( "Properties map: " );
526 if ( Test.testPropertiesMap() ) {
527 System.out.println( "OK." );
531 System.out.println( "failed." );
534 System.out.print( "SDIse: " );
535 if ( Test.testSDIse() ) {
536 System.out.println( "OK." );
540 System.out.println( "failed." );
543 System.out.print( "SDIunrooted: " );
544 if ( Test.testSDIunrooted() ) {
545 System.out.println( "OK." );
549 System.out.println( "failed." );
552 System.out.print( "GSDI: " );
553 if ( TestGSDI.test() ) {
554 System.out.println( "OK." );
558 System.out.println( "failed." );
561 System.out.print( "RIO: " );
562 if ( TestRIO.test() ) {
563 System.out.println( "OK." );
567 System.out.println( "failed." );
570 System.out.print( "Phylogeny reconstruction:" );
571 System.out.println();
572 if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
573 System.out.println( "OK." );
577 System.out.println( "failed." );
580 System.out.print( "Analysis of domain architectures: " );
581 System.out.println();
582 if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
583 System.out.println( "OK." );
587 System.out.println( "failed." );
590 System.out.print( "GO: " );
591 System.out.println();
592 if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
593 System.out.println( "OK." );
597 System.out.println( "failed." );
600 System.out.print( "Modeling tools: " );
601 if ( TestPccx.test() ) {
602 System.out.println( "OK." );
606 System.out.println( "failed." );
609 System.out.print( "Split Matrix strict: " );
610 if ( Test.testSplitStrict() ) {
611 System.out.println( "OK." );
615 System.out.println( "failed." );
618 System.out.print( "Split Matrix: " );
619 if ( Test.testSplit() ) {
620 System.out.println( "OK." );
624 System.out.println( "failed." );
627 System.out.print( "Confidence Assessor: " );
628 if ( Test.testConfidenceAssessor() ) {
629 System.out.println( "OK." );
633 System.out.println( "failed." );
636 System.out.print( "Basic table: " );
637 if ( Test.testBasicTable() ) {
638 System.out.println( "OK." );
642 System.out.println( "failed." );
645 System.out.print( "General table: " );
646 if ( Test.testGeneralTable() ) {
647 System.out.println( "OK." );
651 System.out.println( "failed." );
654 System.out.print( "Amino acid sequence: " );
655 if ( Test.testAminoAcidSequence() ) {
656 System.out.println( "OK." );
660 System.out.println( "failed." );
663 System.out.print( "General MSA parser: " );
664 if ( Test.testGeneralMsaParser() ) {
665 System.out.println( "OK." );
669 System.out.println( "failed." );
672 System.out.print( "Fasta parser for msa: " );
673 if ( Test.testFastaParser() ) {
674 System.out.println( "OK." );
678 System.out.println( "failed." );
681 System.out.print( "Creation of balanced phylogeny: " );
682 if ( Test.testCreateBalancedPhylogeny() ) {
683 System.out.println( "OK." );
687 System.out.println( "failed." );
690 System.out.print( "EMBL Entry Retrieval: " );
691 if ( Test.testEmblEntryRetrieval() ) {
692 System.out.println( "OK." );
696 System.out.println( "failed." );
699 System.out.print( "Uniprot Entry Retrieval: " );
700 if ( Test.testUniprotEntryRetrieval() ) {
701 System.out.println( "OK." );
705 System.out.println( "failed." );
708 System.out.print( "Uniprot Taxonomy Search: " );
709 if ( Test.testUniprotTaxonomySearch() ) {
710 System.out.println( "OK." );
714 System.out.println( "failed." );
719 final String os = ForesterUtil.OS_NAME.toLowerCase();
720 if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
721 path = "/usr/local/bin/mafft";
723 else if ( os.indexOf( "win" ) >= 0 ) {
724 path = "C:\\Program Files\\mafft-win\\mafft.bat";
727 path = "/home/czmasek/bin/mafft";
729 if ( !MsaInferrer.isInstalled( path ) ) {
732 if ( !MsaInferrer.isInstalled( path ) ) {
733 path = "/usr/local/bin/mafft";
735 if ( MsaInferrer.isInstalled( path ) ) {
736 System.out.print( "MAFFT (external program): " );
737 if ( Test.testMafft( path ) ) {
738 System.out.println( "OK." );
742 System.out.println( "failed [will not count towards failed tests]" );
746 System.out.print( "Next nodes with collapsed: " );
747 if ( Test.testNextNodeWithCollapsing() ) {
748 System.out.println( "OK." );
752 System.out.println( "failed." );
755 System.out.print( "Simple MSA quality: " );
756 if ( Test.testMsaQualityMethod() ) {
757 System.out.println( "OK." );
761 System.out.println( "failed." );
764 System.out.println();
765 final Runtime rt = java.lang.Runtime.getRuntime();
766 final long free_memory = rt.freeMemory() / 1000000;
767 final long total_memory = rt.totalMemory() / 1000000;
768 System.out.println( "Running time : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
769 + free_memory + "MB, total memory: " + total_memory + "MB)" );
770 System.out.println();
771 System.out.println( "Successful tests: " + succeeded );
772 System.out.println( "Failed tests: " + failed );
773 System.out.println();
775 System.out.println( "OK." );
778 System.out.println( "Not OK." );
782 private static boolean testExtractTaxonomyCodeFromNodeName() {
784 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.YES ).equals( "MOUSE" ) ) {
787 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.YES ).equals( "RAT" ) ) {
790 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.YES ) != null ) {
793 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445", TAXONOMY_EXTRACTION.YES )
794 .equals( "MOUSE" ) ) {
797 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE_function = 23445", TAXONOMY_EXTRACTION.YES )
798 .equals( "MOUSE" ) ) {
801 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445", TAXONOMY_EXTRACTION.YES )
802 .equals( "MOUSE" ) ) {
805 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
808 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
811 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445", TAXONOMY_EXTRACTION.YES )
815 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445", TAXONOMY_EXTRACTION.YES )
819 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445", TAXONOMY_EXTRACTION.YES )
823 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
826 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
829 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.YES ).equals( "RAT" ) ) {
832 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY )
836 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.YES )
837 .equals( "MOUSE" ) ) {
840 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY )
841 .equals( "MOUSE" ) ) {
845 catch ( final Exception e ) {
846 e.printStackTrace( System.out );
852 private static boolean testBasicNodeMethods() {
854 if ( PhylogenyNode.getNodeCount() != 0 ) {
857 final PhylogenyNode n1 = new PhylogenyNode();
858 final PhylogenyNode n2 = PhylogenyNode
859 .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
860 final PhylogenyNode n3 = PhylogenyNode
861 .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
862 final PhylogenyNode n4 = PhylogenyNode
863 .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
864 if ( n1.isHasAssignedEvent() ) {
867 if ( PhylogenyNode.getNodeCount() != 4 ) {
870 if ( n3.getIndicator() != 0 ) {
873 if ( n3.getNumberOfExternalNodes() != 1 ) {
876 if ( !n3.isExternal() ) {
879 if ( !n3.isRoot() ) {
882 if ( !n4.getName().equals( "n4" ) ) {
886 catch ( final Exception e ) {
887 e.printStackTrace( System.out );
893 private static boolean testBasicPhyloXMLparsing() {
895 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
896 final PhyloXmlParser xml_parser = new PhyloXmlParser();
897 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
899 if ( xml_parser.getErrorCount() > 0 ) {
900 System.out.println( xml_parser.getErrorMessages().toString() );
903 if ( phylogenies_0.length != 4 ) {
906 final Phylogeny t1 = phylogenies_0[ 0 ];
907 final Phylogeny t2 = phylogenies_0[ 1 ];
908 final Phylogeny t3 = phylogenies_0[ 2 ];
909 final Phylogeny t4 = phylogenies_0[ 3 ];
910 if ( t1.getNumberOfExternalNodes() != 1 ) {
913 if ( !t1.isRooted() ) {
916 if ( t1.isRerootable() ) {
919 if ( !t1.getType().equals( "gene_tree" ) ) {
922 if ( t2.getNumberOfExternalNodes() != 2 ) {
925 if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
928 if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
931 if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
934 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
937 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
940 if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
943 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
944 .startsWith( "actgtgggggt" ) ) {
947 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
948 .startsWith( "ctgtgatgcat" ) ) {
951 if ( t3.getNumberOfExternalNodes() != 4 ) {
954 if ( !t1.getName().equals( "t1" ) ) {
957 if ( !t2.getName().equals( "t2" ) ) {
960 if ( !t3.getName().equals( "t3" ) ) {
963 if ( !t4.getName().equals( "t4" ) ) {
966 if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
969 if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
972 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
975 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
976 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
979 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
982 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
985 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
988 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
989 .equals( "apoptosis" ) ) {
992 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
993 .equals( "GO:0006915" ) ) {
996 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
997 .equals( "UniProtKB" ) ) {
1000 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1001 .equals( "experimental" ) ) {
1004 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1005 .equals( "function" ) ) {
1008 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1009 .getValue() != 1 ) {
1012 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1013 .getType().equals( "ml" ) ) {
1016 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1017 .equals( "apoptosis" ) ) {
1020 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1021 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1024 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1025 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1028 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1029 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1032 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1033 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1036 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1037 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1040 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1041 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1044 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1045 .equals( "GO:0005829" ) ) {
1048 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1049 .equals( "intracellular organelle" ) ) {
1052 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1055 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1056 .equals( "UniProt link" ) ) ) {
1059 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1063 catch ( final Exception e ) {
1064 e.printStackTrace( System.out );
1070 private static boolean testBasicPhyloXMLparsingRoundtrip() {
1072 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1073 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1074 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1075 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1078 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1080 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1082 if ( xml_parser.getErrorCount() > 0 ) {
1083 System.out.println( xml_parser.getErrorMessages().toString() );
1086 if ( phylogenies_0.length != 4 ) {
1089 final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1090 final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1091 if ( phylogenies_t1.length != 1 ) {
1094 final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1095 if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1098 if ( !t1_rt.isRooted() ) {
1101 if ( t1_rt.isRerootable() ) {
1104 if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1107 final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1108 final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1109 final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1110 if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1113 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1116 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1119 if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1122 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1123 .startsWith( "actgtgggggt" ) ) {
1126 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1127 .startsWith( "ctgtgatgcat" ) ) {
1130 final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1131 final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1132 final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1133 final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1134 if ( phylogenies_1.length != 1 ) {
1137 final Phylogeny t3_rt = phylogenies_1[ 0 ];
1138 if ( !t3_rt.getName().equals( "t3" ) ) {
1141 if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1144 if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1147 if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1150 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1153 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1154 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1157 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1160 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1163 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1164 .equals( "UniProtKB" ) ) {
1167 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1168 .equals( "apoptosis" ) ) {
1171 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1172 .equals( "GO:0006915" ) ) {
1175 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1176 .equals( "UniProtKB" ) ) {
1179 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1180 .equals( "experimental" ) ) {
1183 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1184 .equals( "function" ) ) {
1187 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1188 .getValue() != 1 ) {
1191 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1192 .getType().equals( "ml" ) ) {
1195 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1196 .equals( "apoptosis" ) ) {
1199 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1200 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1203 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1204 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1207 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1208 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1211 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1212 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1215 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1216 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1219 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1220 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1223 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1224 .equals( "GO:0005829" ) ) {
1227 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1228 .equals( "intracellular organelle" ) ) {
1231 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1234 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1235 .equals( "UniProt link" ) ) ) {
1238 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1241 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1244 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1245 .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." ) ) ) {
1248 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1251 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1254 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1257 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1260 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1261 .equals( "ncbi" ) ) {
1264 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1267 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1268 .getName().equals( "B" ) ) {
1271 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1272 .getFrom() != 21 ) {
1275 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1278 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1279 .getLength() != 24 ) {
1282 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1283 .getConfidence() != 2144 ) {
1286 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1287 .equals( "pfam" ) ) {
1290 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1293 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1296 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1299 if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1302 final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1303 if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1306 if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1309 if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1312 if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1315 if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1318 if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1321 if ( taxbb.getSynonyms().size() != 2 ) {
1324 if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1327 if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1330 if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1333 if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1336 if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1339 if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1340 .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1344 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1347 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1350 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1353 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1356 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1359 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1362 if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1366 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1369 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1370 .equalsIgnoreCase( "435" ) ) {
1373 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1376 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1377 .equalsIgnoreCase( "443.7" ) ) {
1380 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1383 if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1386 if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1387 .equalsIgnoreCase( "433" ) ) {
1391 catch ( final Exception e ) {
1392 e.printStackTrace( System.out );
1398 private static boolean testBasicPhyloXMLparsingValidating() {
1400 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1401 PhyloXmlParser xml_parser = null;
1403 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1405 catch ( final Exception e ) {
1406 // Do nothing -- means were not running from jar.
1408 if ( xml_parser == null ) {
1409 xml_parser = new PhyloXmlParser();
1410 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1411 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1414 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1417 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1419 if ( xml_parser.getErrorCount() > 0 ) {
1420 System.out.println( xml_parser.getErrorMessages().toString() );
1423 if ( phylogenies_0.length != 4 ) {
1426 final Phylogeny t1 = phylogenies_0[ 0 ];
1427 final Phylogeny t2 = phylogenies_0[ 1 ];
1428 final Phylogeny t3 = phylogenies_0[ 2 ];
1429 final Phylogeny t4 = phylogenies_0[ 3 ];
1430 if ( !t1.getName().equals( "t1" ) ) {
1433 if ( !t2.getName().equals( "t2" ) ) {
1436 if ( !t3.getName().equals( "t3" ) ) {
1439 if ( !t4.getName().equals( "t4" ) ) {
1442 if ( t1.getNumberOfExternalNodes() != 1 ) {
1445 if ( t2.getNumberOfExternalNodes() != 2 ) {
1448 if ( t3.getNumberOfExternalNodes() != 4 ) {
1451 final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1452 final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1453 if ( xml_parser.getErrorCount() > 0 ) {
1454 System.out.println( "errors:" );
1455 System.out.println( xml_parser.getErrorMessages().toString() );
1458 if ( phylogenies_1.length != 4 ) {
1461 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1463 if ( xml_parser.getErrorCount() > 0 ) {
1464 System.out.println( "errors:" );
1465 System.out.println( xml_parser.getErrorMessages().toString() );
1468 if ( phylogenies_2.length != 1 ) {
1471 if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1474 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1476 if ( xml_parser.getErrorCount() > 0 ) {
1477 System.out.println( xml_parser.getErrorMessages().toString() );
1480 if ( phylogenies_3.length != 2 ) {
1483 final Phylogeny a = phylogenies_3[ 0 ];
1484 if ( !a.getName().equals( "tree 4" ) ) {
1487 if ( a.getNumberOfExternalNodes() != 3 ) {
1490 if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1493 if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1496 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1498 if ( xml_parser.getErrorCount() > 0 ) {
1499 System.out.println( xml_parser.getErrorMessages().toString() );
1502 if ( phylogenies_4.length != 1 ) {
1505 final Phylogeny s = phylogenies_4[ 0 ];
1506 if ( s.getNumberOfExternalNodes() != 6 ) {
1509 s.getNode( "first" );
1511 s.getNode( "\"<a'b&c'd\">\"" );
1512 s.getNode( "'''\"" );
1513 s.getNode( "\"\"\"" );
1514 s.getNode( "dick & doof" );
1516 catch ( final Exception e ) {
1517 e.printStackTrace( System.out );
1523 private static boolean testBasicTable() {
1525 final BasicTable<String> t0 = new BasicTable<String>();
1526 if ( t0.getNumberOfColumns() != 0 ) {
1529 if ( t0.getNumberOfRows() != 0 ) {
1532 t0.setValue( 3, 2, "23" );
1533 t0.setValue( 10, 1, "error" );
1534 t0.setValue( 10, 1, "110" );
1535 t0.setValue( 9, 1, "19" );
1536 t0.setValue( 1, 10, "101" );
1537 t0.setValue( 10, 10, "1010" );
1538 t0.setValue( 100, 10, "10100" );
1539 t0.setValue( 0, 0, "00" );
1540 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1543 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1546 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1549 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1552 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1555 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1558 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1561 if ( t0.getNumberOfColumns() != 101 ) {
1564 if ( t0.getNumberOfRows() != 11 ) {
1567 if ( t0.getValueAsString( 49, 4 ) != null ) {
1570 final String l = ForesterUtil.getLineSeparator();
1571 final StringBuffer source = new StringBuffer();
1572 source.append( "" + l );
1573 source.append( "# 1 1 1 1 1 1 1 1" + l );
1574 source.append( " 00 01 02 03" + l );
1575 source.append( " 10 11 12 13 " + l );
1576 source.append( "20 21 22 23 " + l );
1577 source.append( " 30 31 32 33" + l );
1578 source.append( "40 41 42 43" + l );
1579 source.append( " # 1 1 1 1 1 " + l );
1580 source.append( "50 51 52 53 54" + l );
1581 final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), " " );
1582 if ( t1.getNumberOfColumns() != 5 ) {
1585 if ( t1.getNumberOfRows() != 6 ) {
1588 if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1591 if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1594 if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1597 if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1600 final StringBuffer source1 = new StringBuffer();
1601 source1.append( "" + l );
1602 source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1603 source1.append( " 00; 01 ;02;03" + l );
1604 source1.append( " 10; 11; 12; 13 " + l );
1605 source1.append( "20; 21; 22; 23 " + l );
1606 source1.append( " 30; 31; 32; 33" + l );
1607 source1.append( "40;41;42;43" + l );
1608 source1.append( " # 1 1 1 1 1 " + l );
1609 source1.append( ";;;50 ; ;52; 53;;54 " + l );
1610 final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ";" );
1611 if ( t2.getNumberOfColumns() != 5 ) {
1614 if ( t2.getNumberOfRows() != 6 ) {
1617 if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1620 if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1623 if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1626 if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1629 if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1632 if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1635 final StringBuffer source2 = new StringBuffer();
1636 source2.append( "" + l );
1637 source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1638 source2.append( " 00; 01 ;02;03" + l );
1639 source2.append( " 10; 11; 12; 13 " + l );
1640 source2.append( "20; 21; 22; 23 " + l );
1641 source2.append( " " + l );
1642 source2.append( " 30; 31; 32; 33" + l );
1643 source2.append( "40;41;42;43" + l );
1644 source2.append( " comment: 1 1 1 1 1 " + l );
1645 source2.append( ";;;50 ; 52; 53;;54 " + l );
1646 final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1652 if ( tl.size() != 2 ) {
1655 final BasicTable<String> t3 = tl.get( 0 );
1656 final BasicTable<String> t4 = tl.get( 1 );
1657 if ( t3.getNumberOfColumns() != 4 ) {
1660 if ( t3.getNumberOfRows() != 3 ) {
1663 if ( t4.getNumberOfColumns() != 4 ) {
1666 if ( t4.getNumberOfRows() != 3 ) {
1669 if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1672 if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
1676 catch ( final Exception e ) {
1677 e.printStackTrace( System.out );
1683 private static boolean testBasicTolXMLparsing() {
1685 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1686 final TolParser parser = new TolParser();
1687 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
1688 if ( parser.getErrorCount() > 0 ) {
1689 System.out.println( parser.getErrorMessages().toString() );
1692 if ( phylogenies_0.length != 1 ) {
1695 final Phylogeny t1 = phylogenies_0[ 0 ];
1696 if ( t1.getNumberOfExternalNodes() != 5 ) {
1699 if ( !t1.isRooted() ) {
1702 if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
1705 if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
1708 if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
1711 if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
1714 final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
1715 if ( parser.getErrorCount() > 0 ) {
1716 System.out.println( parser.getErrorMessages().toString() );
1719 if ( phylogenies_1.length != 1 ) {
1722 final Phylogeny t2 = phylogenies_1[ 0 ];
1723 if ( t2.getNumberOfExternalNodes() != 664 ) {
1726 if ( !t2.isRooted() ) {
1729 if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
1732 if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
1735 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
1738 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
1741 if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
1744 if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
1745 .equals( "Aquifex" ) ) {
1748 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
1749 if ( parser.getErrorCount() > 0 ) {
1750 System.out.println( parser.getErrorMessages().toString() );
1753 if ( phylogenies_2.length != 1 ) {
1756 final Phylogeny t3 = phylogenies_2[ 0 ];
1757 if ( t3.getNumberOfExternalNodes() != 184 ) {
1760 if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
1763 if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
1766 if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
1769 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
1770 if ( parser.getErrorCount() > 0 ) {
1771 System.out.println( parser.getErrorMessages().toString() );
1774 if ( phylogenies_3.length != 1 ) {
1777 final Phylogeny t4 = phylogenies_3[ 0 ];
1778 if ( t4.getNumberOfExternalNodes() != 1 ) {
1781 if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
1784 if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
1787 if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
1790 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
1791 if ( parser.getErrorCount() > 0 ) {
1792 System.out.println( parser.getErrorMessages().toString() );
1795 if ( phylogenies_4.length != 1 ) {
1798 final Phylogeny t5 = phylogenies_4[ 0 ];
1799 if ( t5.getNumberOfExternalNodes() != 13 ) {
1802 if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
1805 if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
1808 if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
1812 catch ( final Exception e ) {
1813 e.printStackTrace( System.out );
1819 private static boolean testBasicTreeMethods() {
1821 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1822 final Phylogeny t1 = factory.create();
1823 if ( !t1.isEmpty() ) {
1826 final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
1827 if ( t2.getNumberOfExternalNodes() != 4 ) {
1830 if ( t2.getHeight() != 8.5 ) {
1833 if ( !t2.isCompletelyBinary() ) {
1836 if ( t2.isEmpty() ) {
1839 final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
1840 if ( t3.getNumberOfExternalNodes() != 5 ) {
1843 if ( t3.getHeight() != 11 ) {
1846 if ( t3.isCompletelyBinary() ) {
1849 final PhylogenyNode n = t3.getNode( "ABC" );
1850 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 ];
1851 if ( t4.getNumberOfExternalNodes() != 9 ) {
1854 if ( t4.getHeight() != 11 ) {
1857 if ( t4.isCompletelyBinary() ) {
1860 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)" );
1861 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
1862 if ( t5.getNumberOfExternalNodes() != 8 ) {
1865 if ( t5.getHeight() != 15 ) {
1868 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)" );
1869 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
1870 if ( t6.getHeight() != 15 ) {
1873 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)" );
1874 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
1875 if ( t7.getHeight() != 15 ) {
1878 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)" );
1879 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
1880 if ( t8.getNumberOfExternalNodes() != 10 ) {
1883 if ( t8.getHeight() != 15 ) {
1886 final char[] a9 = new char[] {};
1887 final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
1888 if ( t9.getHeight() != 0 ) {
1891 final char[] a10 = new char[] { 'a', ':', '6' };
1892 final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
1893 if ( t10.getHeight() != 6 ) {
1897 catch ( final Exception e ) {
1898 e.printStackTrace( System.out );
1904 private static boolean testConfidenceAssessor() {
1906 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1907 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1908 final Phylogeny[] ev0 = factory
1909 .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
1911 ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
1912 if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
1915 if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
1918 final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1919 final Phylogeny[] ev1 = factory
1920 .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)));",
1922 ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
1923 if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
1926 if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1929 final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
1930 final Phylogeny[] ev_b = factory
1931 .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",
1933 ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
1934 if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
1937 if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1941 final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1942 final Phylogeny[] ev1x = factory
1943 .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)));",
1945 ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
1946 if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1949 if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1952 final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
1953 final Phylogeny[] ev_bx = factory
1954 .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",
1956 ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
1957 if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1960 if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1964 final Phylogeny[] t2 = factory
1965 .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);",
1967 final Phylogeny[] ev2 = factory
1968 .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);",
1970 for( final Phylogeny target : t2 ) {
1971 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
1974 final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
1975 new NHXParser() )[ 0 ];
1976 final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
1977 ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
1978 if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1981 if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
1984 if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1988 catch ( final Exception e ) {
1989 e.printStackTrace();
1995 private static boolean testCopyOfNodeData() {
1997 final PhylogenyNode n1 = PhylogenyNode
1998 .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]" );
1999 final PhylogenyNode n2 = n1.copyNodeData();
2000 if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2004 catch ( final Exception e ) {
2005 e.printStackTrace();
2011 private static boolean testDataObjects() {
2013 final Confidence s0 = new Confidence();
2014 final Confidence s1 = new Confidence();
2015 if ( !s0.isEqual( s1 ) ) {
2018 final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2019 final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2020 if ( s2.isEqual( s1 ) ) {
2023 if ( !s2.isEqual( s3 ) ) {
2026 final Confidence s4 = ( Confidence ) s3.copy();
2027 if ( !s4.isEqual( s3 ) ) {
2034 final Taxonomy t1 = new Taxonomy();
2035 final Taxonomy t2 = new Taxonomy();
2036 final Taxonomy t3 = new Taxonomy();
2037 final Taxonomy t4 = new Taxonomy();
2038 final Taxonomy t5 = new Taxonomy();
2039 t1.setIdentifier( new Identifier( "ecoli" ) );
2040 t1.setTaxonomyCode( "ECOLI" );
2041 t1.setScientificName( "E. coli" );
2042 t1.setCommonName( "coli" );
2043 final Taxonomy t0 = ( Taxonomy ) t1.copy();
2044 if ( !t1.isEqual( t0 ) ) {
2047 t2.setIdentifier( new Identifier( "ecoli" ) );
2048 t2.setTaxonomyCode( "OTHER" );
2049 t2.setScientificName( "what" );
2050 t2.setCommonName( "something" );
2051 if ( !t1.isEqual( t2 ) ) {
2054 t2.setIdentifier( new Identifier( "nemve" ) );
2055 if ( t1.isEqual( t2 ) ) {
2058 t1.setIdentifier( null );
2059 t3.setTaxonomyCode( "ECOLI" );
2060 t3.setScientificName( "what" );
2061 t3.setCommonName( "something" );
2062 if ( !t1.isEqual( t3 ) ) {
2065 t1.setIdentifier( null );
2066 t1.setTaxonomyCode( "" );
2067 t4.setScientificName( "E. ColI" );
2068 t4.setCommonName( "something" );
2069 if ( !t1.isEqual( t4 ) ) {
2072 t4.setScientificName( "B. subtilis" );
2073 t4.setCommonName( "something" );
2074 if ( t1.isEqual( t4 ) ) {
2077 t1.setIdentifier( null );
2078 t1.setTaxonomyCode( "" );
2079 t1.setScientificName( "" );
2080 t5.setCommonName( "COLI" );
2081 if ( !t1.isEqual( t5 ) ) {
2084 t5.setCommonName( "vibrio" );
2085 if ( t1.isEqual( t5 ) ) {
2090 final Identifier id0 = new Identifier( "123", "pfam" );
2091 final Identifier id1 = ( Identifier ) id0.copy();
2092 if ( !id1.isEqual( id1 ) ) {
2095 if ( !id1.isEqual( id0 ) ) {
2098 if ( !id0.isEqual( id1 ) ) {
2105 final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2106 final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2107 if ( !pd1.isEqual( pd1 ) ) {
2110 if ( !pd1.isEqual( pd0 ) ) {
2115 final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2116 final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2117 if ( !pd3.isEqual( pd3 ) ) {
2120 if ( !pd2.isEqual( pd3 ) ) {
2123 if ( !pd0.isEqual( pd3 ) ) {
2128 // DomainArchitecture
2129 // ------------------
2130 final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2131 final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2132 final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2133 final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2134 final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2135 final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2140 final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2141 if ( ds0.getNumberOfDomains() != 4 ) {
2144 final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2145 if ( !ds0.isEqual( ds0 ) ) {
2148 if ( !ds0.isEqual( ds1 ) ) {
2151 if ( ds1.getNumberOfDomains() != 4 ) {
2154 final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2159 final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2160 if ( ds0.isEqual( ds2 ) ) {
2166 final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2167 if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2168 System.out.println( ds3.toNHX() );
2171 if ( ds3.getNumberOfDomains() != 3 ) {
2176 final Event e1 = new Event( Event.EventType.fusion );
2177 if ( e1.isDuplication() ) {
2180 if ( !e1.isFusion() ) {
2183 if ( !e1.asText().toString().equals( "fusion" ) ) {
2186 if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2189 final Event e11 = new Event( Event.EventType.fusion );
2190 if ( !e11.isEqual( e1 ) ) {
2193 if ( !e11.toNHX().toString().equals( "" ) ) {
2196 final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2197 if ( e2.isDuplication() ) {
2200 if ( !e2.isSpeciationOrDuplication() ) {
2203 if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2206 if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2209 if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2212 if ( e11.isEqual( e2 ) ) {
2215 final Event e2c = ( Event ) e2.copy();
2216 if ( !e2c.isEqual( e2 ) ) {
2219 Event e3 = new Event( 1, 2, 3 );
2220 if ( e3.isDuplication() ) {
2223 if ( e3.isSpeciation() ) {
2226 if ( e3.isGeneLoss() ) {
2229 if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2232 final Event e3c = ( Event ) e3.copy();
2233 final Event e3cc = ( Event ) e3c.copy();
2234 if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2238 if ( !e3c.isEqual( e3cc ) ) {
2241 Event e4 = new Event( 1, 2, 3 );
2242 if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2245 if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2248 final Event e4c = ( Event ) e4.copy();
2250 final Event e4cc = ( Event ) e4c.copy();
2251 if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2254 if ( !e4c.isEqual( e4cc ) ) {
2257 final Event e5 = new Event();
2258 if ( !e5.isUnassigned() ) {
2261 if ( !e5.asText().toString().equals( "unassigned" ) ) {
2264 if ( !e5.asSimpleText().toString().equals( "" ) ) {
2267 final Event e6 = new Event( 1, 0, 0 );
2268 if ( !e6.asText().toString().equals( "duplication" ) ) {
2271 if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2274 final Event e7 = new Event( 0, 1, 0 );
2275 if ( !e7.asText().toString().equals( "speciation" ) ) {
2278 if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2281 final Event e8 = new Event( 0, 0, 1 );
2282 if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2285 if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2289 catch ( final Exception e ) {
2290 e.printStackTrace( System.out );
2296 private static boolean testDeletionOfExternalNodes() {
2298 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2299 final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2300 final PhylogenyWriter w = new PhylogenyWriter();
2301 if ( t0.isEmpty() ) {
2304 if ( t0.getNumberOfExternalNodes() != 1 ) {
2307 t0.deleteSubtree( t0.getNode( "A" ), false );
2308 if ( t0.getNumberOfExternalNodes() != 0 ) {
2311 if ( !t0.isEmpty() ) {
2314 final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2315 if ( t1.getNumberOfExternalNodes() != 2 ) {
2318 t1.deleteSubtree( t1.getNode( "A" ), false );
2319 if ( t1.getNumberOfExternalNodes() != 1 ) {
2322 if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2325 t1.deleteSubtree( t1.getNode( "B" ), false );
2326 if ( t1.getNumberOfExternalNodes() != 1 ) {
2329 t1.deleteSubtree( t1.getNode( "r" ), false );
2330 if ( !t1.isEmpty() ) {
2333 final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2334 if ( t2.getNumberOfExternalNodes() != 3 ) {
2337 t2.deleteSubtree( t2.getNode( "B" ), false );
2338 if ( t2.getNumberOfExternalNodes() != 2 ) {
2341 t2.toNewHampshireX();
2342 PhylogenyNode n = t2.getNode( "A" );
2343 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2346 t2.deleteSubtree( t2.getNode( "A" ), false );
2347 if ( t2.getNumberOfExternalNodes() != 2 ) {
2350 t2.deleteSubtree( t2.getNode( "C" ), true );
2351 if ( t2.getNumberOfExternalNodes() != 1 ) {
2354 final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2355 if ( t3.getNumberOfExternalNodes() != 4 ) {
2358 t3.deleteSubtree( t3.getNode( "B" ), true );
2359 if ( t3.getNumberOfExternalNodes() != 3 ) {
2362 n = t3.getNode( "A" );
2363 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2366 n = n.getNextExternalNode();
2367 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2370 t3.deleteSubtree( t3.getNode( "A" ), true );
2371 if ( t3.getNumberOfExternalNodes() != 2 ) {
2374 n = t3.getNode( "C" );
2375 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2378 t3.deleteSubtree( t3.getNode( "C" ), true );
2379 if ( t3.getNumberOfExternalNodes() != 1 ) {
2382 t3.deleteSubtree( t3.getNode( "D" ), true );
2383 if ( t3.getNumberOfExternalNodes() != 0 ) {
2386 final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2387 if ( t4.getNumberOfExternalNodes() != 6 ) {
2390 t4.deleteSubtree( t4.getNode( "B2" ), true );
2391 if ( t4.getNumberOfExternalNodes() != 5 ) {
2394 String s = w.toNewHampshire( t4, false, true ).toString();
2395 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2398 t4.deleteSubtree( t4.getNode( "B11" ), true );
2399 if ( t4.getNumberOfExternalNodes() != 4 ) {
2402 t4.deleteSubtree( t4.getNode( "C" ), true );
2403 if ( t4.getNumberOfExternalNodes() != 3 ) {
2406 n = t4.getNode( "A" );
2407 n = n.getNextExternalNode();
2408 if ( !n.getName().equals( "B12" ) ) {
2411 n = n.getNextExternalNode();
2412 if ( !n.getName().equals( "D" ) ) {
2415 s = w.toNewHampshire( t4, false, true ).toString();
2416 if ( !s.equals( "((A,B12),D);" ) ) {
2419 final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2420 t5.deleteSubtree( t5.getNode( "A" ), true );
2421 if ( t5.getNumberOfExternalNodes() != 5 ) {
2424 s = w.toNewHampshire( t5, false, true ).toString();
2425 if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2428 final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2429 t6.deleteSubtree( t6.getNode( "B11" ), true );
2430 if ( t6.getNumberOfExternalNodes() != 5 ) {
2433 s = w.toNewHampshire( t6, false, false ).toString();
2434 if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2437 final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2438 t7.deleteSubtree( t7.getNode( "B12" ), true );
2439 if ( t7.getNumberOfExternalNodes() != 5 ) {
2442 s = w.toNewHampshire( t7, false, true ).toString();
2443 if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2446 final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2447 t8.deleteSubtree( t8.getNode( "B2" ), true );
2448 if ( t8.getNumberOfExternalNodes() != 5 ) {
2451 s = w.toNewHampshire( t8, false, false ).toString();
2452 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2455 final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2456 t9.deleteSubtree( t9.getNode( "C" ), true );
2457 if ( t9.getNumberOfExternalNodes() != 5 ) {
2460 s = w.toNewHampshire( t9, false, true ).toString();
2461 if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2464 final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2465 t10.deleteSubtree( t10.getNode( "D" ), true );
2466 if ( t10.getNumberOfExternalNodes() != 5 ) {
2469 s = w.toNewHampshire( t10, false, true ).toString();
2470 if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2473 final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2474 t11.deleteSubtree( t11.getNode( "A" ), true );
2475 if ( t11.getNumberOfExternalNodes() != 2 ) {
2478 s = w.toNewHampshire( t11, false, true ).toString();
2479 if ( !s.equals( "(B,C);" ) ) {
2482 t11.deleteSubtree( t11.getNode( "C" ), true );
2483 if ( t11.getNumberOfExternalNodes() != 1 ) {
2486 s = w.toNewHampshire( t11, false, false ).toString();
2487 if ( !s.equals( "B;" ) ) {
2490 final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2491 t12.deleteSubtree( t12.getNode( "B2" ), true );
2492 if ( t12.getNumberOfExternalNodes() != 8 ) {
2495 s = w.toNewHampshire( t12, false, true ).toString();
2496 if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2499 t12.deleteSubtree( t12.getNode( "B3" ), true );
2500 if ( t12.getNumberOfExternalNodes() != 7 ) {
2503 s = w.toNewHampshire( t12, false, true ).toString();
2504 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2507 t12.deleteSubtree( t12.getNode( "C3" ), true );
2508 if ( t12.getNumberOfExternalNodes() != 6 ) {
2511 s = w.toNewHampshire( t12, false, true ).toString();
2512 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2515 t12.deleteSubtree( t12.getNode( "A1" ), true );
2516 if ( t12.getNumberOfExternalNodes() != 5 ) {
2519 s = w.toNewHampshire( t12, false, true ).toString();
2520 if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2523 t12.deleteSubtree( t12.getNode( "B1" ), true );
2524 if ( t12.getNumberOfExternalNodes() != 4 ) {
2527 s = w.toNewHampshire( t12, false, true ).toString();
2528 if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2531 t12.deleteSubtree( t12.getNode( "A3" ), true );
2532 if ( t12.getNumberOfExternalNodes() != 3 ) {
2535 s = w.toNewHampshire( t12, false, true ).toString();
2536 if ( !s.equals( "(A2,(C1,C2));" ) ) {
2539 t12.deleteSubtree( t12.getNode( "A2" ), true );
2540 if ( t12.getNumberOfExternalNodes() != 2 ) {
2543 s = w.toNewHampshire( t12, false, true ).toString();
2544 if ( !s.equals( "(C1,C2);" ) ) {
2547 final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2548 t13.deleteSubtree( t13.getNode( "D" ), true );
2549 if ( t13.getNumberOfExternalNodes() != 4 ) {
2552 s = w.toNewHampshire( t13, false, true ).toString();
2553 if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2556 final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2557 t14.deleteSubtree( t14.getNode( "E" ), true );
2558 if ( t14.getNumberOfExternalNodes() != 5 ) {
2561 s = w.toNewHampshire( t14, false, true ).toString();
2562 if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2565 final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2566 t15.deleteSubtree( t15.getNode( "B2" ), true );
2567 if ( t15.getNumberOfExternalNodes() != 11 ) {
2570 t15.deleteSubtree( t15.getNode( "B1" ), true );
2571 if ( t15.getNumberOfExternalNodes() != 10 ) {
2574 t15.deleteSubtree( t15.getNode( "B3" ), true );
2575 if ( t15.getNumberOfExternalNodes() != 9 ) {
2578 t15.deleteSubtree( t15.getNode( "B4" ), true );
2579 if ( t15.getNumberOfExternalNodes() != 8 ) {
2582 t15.deleteSubtree( t15.getNode( "A1" ), true );
2583 if ( t15.getNumberOfExternalNodes() != 7 ) {
2586 t15.deleteSubtree( t15.getNode( "C4" ), true );
2587 if ( t15.getNumberOfExternalNodes() != 6 ) {
2591 catch ( final Exception e ) {
2592 e.printStackTrace( System.out );
2598 private static boolean testDescriptiveStatistics() {
2600 final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2601 dss1.addValue( 82 );
2602 dss1.addValue( 78 );
2603 dss1.addValue( 70 );
2604 dss1.addValue( 58 );
2605 dss1.addValue( 42 );
2606 if ( dss1.getN() != 5 ) {
2609 if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2612 if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2615 if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2618 if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2621 if ( !Test.isEqual( dss1.median(), 70 ) ) {
2624 if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2627 if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2630 if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2633 if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2636 if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2639 if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2642 dss1.addValue( 123 );
2643 if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
2646 if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
2649 if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
2652 final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
2653 dss2.addValue( -1.85 );
2654 dss2.addValue( 57.5 );
2655 dss2.addValue( 92.78 );
2656 dss2.addValue( 57.78 );
2657 if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
2660 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
2663 final double[] a = dss2.getDataAsDoubleArray();
2664 if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
2667 dss2.addValue( -100 );
2668 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
2671 if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
2674 final double[] ds = new double[ 14 ];
2689 final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
2690 if ( bins.length != 4 ) {
2693 if ( bins[ 0 ] != 2 ) {
2696 if ( bins[ 1 ] != 3 ) {
2699 if ( bins[ 2 ] != 4 ) {
2702 if ( bins[ 3 ] != 5 ) {
2705 final double[] ds1 = new double[ 9 ];
2715 final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
2716 if ( bins1.length != 4 ) {
2719 if ( bins1[ 0 ] != 2 ) {
2722 if ( bins1[ 1 ] != 3 ) {
2725 if ( bins1[ 2 ] != 0 ) {
2728 if ( bins1[ 3 ] != 4 ) {
2731 final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
2732 if ( bins1_1.length != 3 ) {
2735 if ( bins1_1[ 0 ] != 3 ) {
2738 if ( bins1_1[ 1 ] != 2 ) {
2741 if ( bins1_1[ 2 ] != 4 ) {
2744 final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
2745 if ( bins1_2.length != 3 ) {
2748 if ( bins1_2[ 0 ] != 2 ) {
2751 if ( bins1_2[ 1 ] != 2 ) {
2754 if ( bins1_2[ 2 ] != 2 ) {
2757 final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
2771 dss3.addValue( 10 );
2772 dss3.addValue( 10 );
2773 dss3.addValue( 10 );
2774 final AsciiHistogram histo = new AsciiHistogram( dss3 );
2775 histo.toStringBuffer( 10, '=', 40, 5 );
2776 histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
2778 catch ( final Exception e ) {
2779 e.printStackTrace( System.out );
2785 private static boolean testDir( final String file ) {
2787 final File f = new File( file );
2788 if ( !f.exists() ) {
2791 if ( !f.isDirectory() ) {
2794 if ( !f.canRead() ) {
2798 catch ( final Exception e ) {
2804 private static boolean testExternalNodeRelatedMethods() {
2806 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2807 final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2808 PhylogenyNode n = t1.getNode( "A" );
2809 n = n.getNextExternalNode();
2810 if ( !n.getName().equals( "B" ) ) {
2813 n = n.getNextExternalNode();
2814 if ( !n.getName().equals( "C" ) ) {
2817 n = n.getNextExternalNode();
2818 if ( !n.getName().equals( "D" ) ) {
2821 n = t1.getNode( "B" );
2822 while ( !n.isLastExternalNode() ) {
2823 n = n.getNextExternalNode();
2825 final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
2826 n = t2.getNode( "A" );
2827 n = n.getNextExternalNode();
2828 if ( !n.getName().equals( "B" ) ) {
2831 n = n.getNextExternalNode();
2832 if ( !n.getName().equals( "C" ) ) {
2835 n = n.getNextExternalNode();
2836 if ( !n.getName().equals( "D" ) ) {
2839 n = t2.getNode( "B" );
2840 while ( !n.isLastExternalNode() ) {
2841 n = n.getNextExternalNode();
2843 final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
2844 n = t3.getNode( "A" );
2845 n = n.getNextExternalNode();
2846 if ( !n.getName().equals( "B" ) ) {
2849 n = n.getNextExternalNode();
2850 if ( !n.getName().equals( "C" ) ) {
2853 n = n.getNextExternalNode();
2854 if ( !n.getName().equals( "D" ) ) {
2857 n = n.getNextExternalNode();
2858 if ( !n.getName().equals( "E" ) ) {
2861 n = n.getNextExternalNode();
2862 if ( !n.getName().equals( "F" ) ) {
2865 n = n.getNextExternalNode();
2866 if ( !n.getName().equals( "G" ) ) {
2869 n = n.getNextExternalNode();
2870 if ( !n.getName().equals( "H" ) ) {
2873 n = t3.getNode( "B" );
2874 while ( !n.isLastExternalNode() ) {
2875 n = n.getNextExternalNode();
2877 final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2878 for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
2879 final PhylogenyNode node = iter.next();
2881 final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
2882 for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
2883 final PhylogenyNode node = iter.next();
2885 final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
2886 final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
2887 if ( !iter.next().getName().equals( "A" ) ) {
2890 if ( !iter.next().getName().equals( "B" ) ) {
2893 if ( !iter.next().getName().equals( "C" ) ) {
2896 if ( !iter.next().getName().equals( "D" ) ) {
2899 if ( !iter.next().getName().equals( "E" ) ) {
2902 if ( !iter.next().getName().equals( "F" ) ) {
2905 if ( iter.hasNext() ) {
2909 catch ( final Exception e ) {
2910 e.printStackTrace( System.out );
2916 private static boolean testGeneralTable() {
2918 final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
2919 t0.setValue( 3, 2, "23" );
2920 t0.setValue( 10, 1, "error" );
2921 t0.setValue( 10, 1, "110" );
2922 t0.setValue( 9, 1, "19" );
2923 t0.setValue( 1, 10, "101" );
2924 t0.setValue( 10, 10, "1010" );
2925 t0.setValue( 100, 10, "10100" );
2926 t0.setValue( 0, 0, "00" );
2927 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2930 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2933 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2936 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2939 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2942 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2945 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2948 if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
2951 if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
2954 final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
2955 t1.setValue( "3", "2", "23" );
2956 t1.setValue( "10", "1", "error" );
2957 t1.setValue( "10", "1", "110" );
2958 t1.setValue( "9", "1", "19" );
2959 t1.setValue( "1", "10", "101" );
2960 t1.setValue( "10", "10", "1010" );
2961 t1.setValue( "100", "10", "10100" );
2962 t1.setValue( "0", "0", "00" );
2963 t1.setValue( "qwerty", "zxcvbnm", "asdef" );
2964 if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
2967 if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
2970 if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
2973 if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
2976 if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
2979 if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
2982 if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
2985 if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
2988 if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
2991 if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
2995 catch ( final Exception e ) {
2996 e.printStackTrace( System.out );
3002 private static boolean testGetDistance() {
3004 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3005 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",
3006 new NHXParser() )[ 0 ];
3007 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3010 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3013 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3016 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3019 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3022 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3025 if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3028 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3031 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3034 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3037 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3040 if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3043 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3046 if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3049 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3052 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3055 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3058 if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3061 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3064 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3067 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3070 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3073 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3076 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3079 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3082 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3085 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3088 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3091 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3094 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3097 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3100 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",
3101 new NHXParser() )[ 0 ];
3102 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3105 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3108 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3111 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3114 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3117 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3120 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3123 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3126 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3129 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3132 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3136 catch ( final Exception e ) {
3137 e.printStackTrace( System.out );
3143 private static boolean testGetLCA() {
3145 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3146 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3147 new NHXParser() )[ 0 ];
3148 final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3149 if ( !A.getName().equals( "A" ) ) {
3152 final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3153 if ( !gh.getName().equals( "gh" ) ) {
3156 final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3157 if ( !ab.getName().equals( "ab" ) ) {
3160 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3161 if ( !ab2.getName().equals( "ab" ) ) {
3164 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3165 if ( !gh2.getName().equals( "gh" ) ) {
3168 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3169 if ( !gh3.getName().equals( "gh" ) ) {
3172 final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3173 if ( !abc.getName().equals( "abc" ) ) {
3176 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3177 if ( !abc2.getName().equals( "abc" ) ) {
3180 final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3181 if ( !abcd.getName().equals( "abcd" ) ) {
3184 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3185 if ( !abcd2.getName().equals( "abcd" ) ) {
3188 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3189 if ( !abcdef.getName().equals( "abcdef" ) ) {
3192 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3193 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3196 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3197 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3200 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3201 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3204 final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3205 if ( !abcde.getName().equals( "abcde" ) ) {
3208 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3209 if ( !abcde2.getName().equals( "abcde" ) ) {
3212 final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3213 if ( !r.getName().equals( "abcdefgh" ) ) {
3216 final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3217 if ( !r2.getName().equals( "abcdefgh" ) ) {
3220 final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3221 if ( !r3.getName().equals( "abcdefgh" ) ) {
3224 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3225 if ( !abcde3.getName().equals( "abcde" ) ) {
3228 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3229 if ( !abcde4.getName().equals( "abcde" ) ) {
3232 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3233 if ( !ab3.getName().equals( "ab" ) ) {
3236 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3237 if ( !ab4.getName().equals( "ab" ) ) {
3240 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3241 final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3242 if ( !cd.getName().equals( "cd" ) ) {
3245 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3246 if ( !cd2.getName().equals( "cd" ) ) {
3249 final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3250 if ( !cde.getName().equals( "cde" ) ) {
3253 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3254 if ( !cde2.getName().equals( "cde" ) ) {
3257 final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3258 if ( !cdef.getName().equals( "cdef" ) ) {
3261 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3262 if ( !cdef2.getName().equals( "cdef" ) ) {
3265 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3266 if ( !cdef3.getName().equals( "cdef" ) ) {
3269 final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3270 if ( !rt.getName().equals( "r" ) ) {
3273 final Phylogeny p3 = factory
3274 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3275 new NHXParser() )[ 0 ];
3276 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3277 if ( !bc_3.getName().equals( "bc" ) ) {
3280 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3281 if ( !ac_3.getName().equals( "abc" ) ) {
3284 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3285 if ( !ad_3.getName().equals( "abcde" ) ) {
3288 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3289 if ( !af_3.getName().equals( "abcdef" ) ) {
3292 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3293 if ( !ag_3.getName().equals( "" ) ) {
3296 if ( !ag_3.isRoot() ) {
3299 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3300 if ( !al_3.getName().equals( "" ) ) {
3303 if ( !al_3.isRoot() ) {
3306 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3307 if ( !kl_3.getName().equals( "" ) ) {
3310 if ( !kl_3.isRoot() ) {
3313 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3314 if ( !fl_3.getName().equals( "" ) ) {
3317 if ( !fl_3.isRoot() ) {
3320 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3321 if ( !gk_3.getName().equals( "ghijk" ) ) {
3324 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3325 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3326 if ( !r_4.getName().equals( "r" ) ) {
3329 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3330 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3331 if ( !r_5.getName().equals( "root" ) ) {
3334 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3335 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3336 if ( !r_6.getName().equals( "rot" ) ) {
3339 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3340 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3341 if ( !r_7.getName().equals( "rott" ) ) {
3345 catch ( final Exception e ) {
3346 e.printStackTrace( System.out );
3352 private static boolean testGetLCA2() {
3354 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3355 final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3356 PhylogenyMethods.preOrderReId( p_a );
3357 final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3358 p_a.getNode( "a" ) );
3359 if ( !p_a_1.getName().equals( "a" ) ) {
3362 final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3363 PhylogenyMethods.preOrderReId( p_b );
3364 final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3365 p_b.getNode( "a" ) );
3366 if ( !p_b_1.getName().equals( "b" ) ) {
3369 final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3370 p_b.getNode( "b" ) );
3371 if ( !p_b_2.getName().equals( "b" ) ) {
3374 final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3375 PhylogenyMethods.preOrderReId( p_c );
3376 final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3377 p_c.getNode( "a" ) );
3378 if ( !p_c_1.getName().equals( "b" ) ) {
3381 final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3382 p_c.getNode( "c" ) );
3383 if ( !p_c_2.getName().equals( "c" ) ) {
3384 System.out.println( p_c_2.getName() );
3388 final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3389 p_c.getNode( "b" ) );
3390 if ( !p_c_3.getName().equals( "b" ) ) {
3393 final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3394 p_c.getNode( "a" ) );
3395 if ( !p_c_4.getName().equals( "c" ) ) {
3398 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3399 new NHXParser() )[ 0 ];
3400 PhylogenyMethods.preOrderReId( p1 );
3401 final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3402 p1.getNode( "A" ) );
3403 if ( !A.getName().equals( "A" ) ) {
3406 final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3407 p1.getNode( "gh" ) );
3408 if ( !gh.getName().equals( "gh" ) ) {
3411 final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3412 p1.getNode( "B" ) );
3413 if ( !ab.getName().equals( "ab" ) ) {
3416 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3417 p1.getNode( "A" ) );
3418 if ( !ab2.getName().equals( "ab" ) ) {
3421 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3422 p1.getNode( "G" ) );
3423 if ( !gh2.getName().equals( "gh" ) ) {
3426 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3427 p1.getNode( "H" ) );
3428 if ( !gh3.getName().equals( "gh" ) ) {
3431 final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3432 p1.getNode( "A" ) );
3433 if ( !abc.getName().equals( "abc" ) ) {
3436 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3437 p1.getNode( "C" ) );
3438 if ( !abc2.getName().equals( "abc" ) ) {
3441 final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3442 p1.getNode( "D" ) );
3443 if ( !abcd.getName().equals( "abcd" ) ) {
3446 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3447 p1.getNode( "A" ) );
3448 if ( !abcd2.getName().equals( "abcd" ) ) {
3451 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3452 p1.getNode( "F" ) );
3453 if ( !abcdef.getName().equals( "abcdef" ) ) {
3456 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3457 p1.getNode( "A" ) );
3458 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3461 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3462 p1.getNode( "F" ) );
3463 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3466 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3467 p1.getNode( "ab" ) );
3468 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3471 final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3472 p1.getNode( "E" ) );
3473 if ( !abcde.getName().equals( "abcde" ) ) {
3476 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3477 p1.getNode( "A" ) );
3478 if ( !abcde2.getName().equals( "abcde" ) ) {
3481 final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3482 p1.getNode( "abcdefgh" ) );
3483 if ( !r.getName().equals( "abcdefgh" ) ) {
3486 final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3487 p1.getNode( "H" ) );
3488 if ( !r2.getName().equals( "abcdefgh" ) ) {
3491 final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3492 p1.getNode( "A" ) );
3493 if ( !r3.getName().equals( "abcdefgh" ) ) {
3496 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3497 p1.getNode( "abcde" ) );
3498 if ( !abcde3.getName().equals( "abcde" ) ) {
3501 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3502 p1.getNode( "E" ) );
3503 if ( !abcde4.getName().equals( "abcde" ) ) {
3506 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3507 p1.getNode( "B" ) );
3508 if ( !ab3.getName().equals( "ab" ) ) {
3511 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3512 p1.getNode( "ab" ) );
3513 if ( !ab4.getName().equals( "ab" ) ) {
3516 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3517 PhylogenyMethods.preOrderReId( p2 );
3518 final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3519 p2.getNode( "d" ) );
3520 if ( !cd.getName().equals( "cd" ) ) {
3523 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3524 p2.getNode( "c" ) );
3525 if ( !cd2.getName().equals( "cd" ) ) {
3528 final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3529 p2.getNode( "e" ) );
3530 if ( !cde.getName().equals( "cde" ) ) {
3533 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3534 p2.getNode( "c" ) );
3535 if ( !cde2.getName().equals( "cde" ) ) {
3538 final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3539 p2.getNode( "f" ) );
3540 if ( !cdef.getName().equals( "cdef" ) ) {
3543 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3544 p2.getNode( "f" ) );
3545 if ( !cdef2.getName().equals( "cdef" ) ) {
3548 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3549 p2.getNode( "d" ) );
3550 if ( !cdef3.getName().equals( "cdef" ) ) {
3553 final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3554 p2.getNode( "a" ) );
3555 if ( !rt.getName().equals( "r" ) ) {
3558 final Phylogeny p3 = factory
3559 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3560 new NHXParser() )[ 0 ];
3561 PhylogenyMethods.preOrderReId( p3 );
3562 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3563 p3.getNode( "c" ) );
3564 if ( !bc_3.getName().equals( "bc" ) ) {
3567 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3568 p3.getNode( "c" ) );
3569 if ( !ac_3.getName().equals( "abc" ) ) {
3572 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3573 p3.getNode( "d" ) );
3574 if ( !ad_3.getName().equals( "abcde" ) ) {
3577 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3578 p3.getNode( "f" ) );
3579 if ( !af_3.getName().equals( "abcdef" ) ) {
3582 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3583 p3.getNode( "g" ) );
3584 if ( !ag_3.getName().equals( "" ) ) {
3587 if ( !ag_3.isRoot() ) {
3590 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3591 p3.getNode( "l" ) );
3592 if ( !al_3.getName().equals( "" ) ) {
3595 if ( !al_3.isRoot() ) {
3598 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3599 p3.getNode( "l" ) );
3600 if ( !kl_3.getName().equals( "" ) ) {
3603 if ( !kl_3.isRoot() ) {
3606 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3607 p3.getNode( "l" ) );
3608 if ( !fl_3.getName().equals( "" ) ) {
3611 if ( !fl_3.isRoot() ) {
3614 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3615 p3.getNode( "k" ) );
3616 if ( !gk_3.getName().equals( "ghijk" ) ) {
3619 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3620 PhylogenyMethods.preOrderReId( p4 );
3621 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3622 p4.getNode( "c" ) );
3623 if ( !r_4.getName().equals( "r" ) ) {
3626 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3627 PhylogenyMethods.preOrderReId( p5 );
3628 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3629 p5.getNode( "c" ) );
3630 if ( !r_5.getName().equals( "root" ) ) {
3633 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3634 PhylogenyMethods.preOrderReId( p6 );
3635 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3636 p6.getNode( "a" ) );
3637 if ( !r_6.getName().equals( "rot" ) ) {
3640 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3641 PhylogenyMethods.preOrderReId( p7 );
3642 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
3643 p7.getNode( "e" ) );
3644 if ( !r_7.getName().equals( "rott" ) ) {
3647 final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3648 p7.getNode( "a" ) );
3649 if ( !r_71.getName().equals( "rott" ) ) {
3652 final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3653 p7.getNode( "rott" ) );
3654 if ( !r_72.getName().equals( "rott" ) ) {
3657 final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3658 p7.getNode( "a" ) );
3659 if ( !r_73.getName().equals( "rott" ) ) {
3662 final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3663 p7.getNode( "rott" ) );
3664 if ( !r_74.getName().equals( "rott" ) ) {
3667 final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3668 p7.getNode( "e" ) );
3669 if ( !r_75.getName().equals( "e" ) ) {
3673 catch ( final Exception e ) {
3674 e.printStackTrace( System.out );
3680 private static boolean testHmmscanOutputParser() {
3681 final String test_dir = Test.PATH_TO_TEST_DATA;
3683 final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
3684 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
3686 final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
3687 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
3688 final List<Protein> proteins = parser2.parse();
3689 if ( parser2.getProteinsEncountered() != 4 ) {
3692 if ( proteins.size() != 4 ) {
3695 if ( parser2.getDomainsEncountered() != 69 ) {
3698 if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
3701 if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
3704 final Protein p1 = proteins.get( 0 );
3705 if ( p1.getNumberOfProteinDomains() != 15 ) {
3708 if ( p1.getLength() != 850 ) {
3711 final Protein p2 = proteins.get( 1 );
3712 if ( p2.getNumberOfProteinDomains() != 51 ) {
3715 if ( p2.getLength() != 1291 ) {
3718 final Protein p3 = proteins.get( 2 );
3719 if ( p3.getNumberOfProteinDomains() != 2 ) {
3722 final Protein p4 = proteins.get( 3 );
3723 if ( p4.getNumberOfProteinDomains() != 1 ) {
3726 if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
3729 if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
3732 if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
3735 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
3738 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
3741 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
3744 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
3747 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
3750 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
3754 catch ( final Exception e ) {
3755 e.printStackTrace( System.out );
3761 private static boolean testLastExternalNodeMethods() {
3763 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3764 final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
3765 final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
3766 final PhylogenyNode n1 = t0.getNode( "A" );
3767 if ( n1.isLastExternalNode() ) {
3770 final PhylogenyNode n2 = t0.getNode( "B" );
3771 if ( n2.isLastExternalNode() ) {
3774 final PhylogenyNode n3 = t0.getNode( "C" );
3775 if ( n3.isLastExternalNode() ) {
3778 final PhylogenyNode n4 = t0.getNode( "D" );
3779 if ( !n4.isLastExternalNode() ) {
3783 catch ( final Exception e ) {
3784 e.printStackTrace( System.out );
3790 private static boolean testLevelOrderIterator() {
3792 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3793 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
3794 PhylogenyNodeIterator it0;
3795 for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
3798 for( it0.reset(); it0.hasNext(); ) {
3801 final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
3802 if ( !it.next().getName().equals( "r" ) ) {
3805 if ( !it.next().getName().equals( "ab" ) ) {
3808 if ( !it.next().getName().equals( "cd" ) ) {
3811 if ( !it.next().getName().equals( "A" ) ) {
3814 if ( !it.next().getName().equals( "B" ) ) {
3817 if ( !it.next().getName().equals( "C" ) ) {
3820 if ( !it.next().getName().equals( "D" ) ) {
3823 if ( it.hasNext() ) {
3826 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",
3827 new NHXParser() )[ 0 ];
3828 PhylogenyNodeIterator it2;
3829 for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
3832 for( it2.reset(); it2.hasNext(); ) {
3835 final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
3836 if ( !it3.next().getName().equals( "r" ) ) {
3839 if ( !it3.next().getName().equals( "abc" ) ) {
3842 if ( !it3.next().getName().equals( "defg" ) ) {
3845 if ( !it3.next().getName().equals( "A" ) ) {
3848 if ( !it3.next().getName().equals( "B" ) ) {
3851 if ( !it3.next().getName().equals( "C" ) ) {
3854 if ( !it3.next().getName().equals( "D" ) ) {
3857 if ( !it3.next().getName().equals( "E" ) ) {
3860 if ( !it3.next().getName().equals( "F" ) ) {
3863 if ( !it3.next().getName().equals( "G" ) ) {
3866 if ( !it3.next().getName().equals( "1" ) ) {
3869 if ( !it3.next().getName().equals( "2" ) ) {
3872 if ( !it3.next().getName().equals( "3" ) ) {
3875 if ( !it3.next().getName().equals( "4" ) ) {
3878 if ( !it3.next().getName().equals( "5" ) ) {
3881 if ( !it3.next().getName().equals( "6" ) ) {
3884 if ( !it3.next().getName().equals( "f1" ) ) {
3887 if ( !it3.next().getName().equals( "f2" ) ) {
3890 if ( !it3.next().getName().equals( "f3" ) ) {
3893 if ( !it3.next().getName().equals( "a" ) ) {
3896 if ( !it3.next().getName().equals( "b" ) ) {
3899 if ( !it3.next().getName().equals( "f21" ) ) {
3902 if ( !it3.next().getName().equals( "X" ) ) {
3905 if ( !it3.next().getName().equals( "Y" ) ) {
3908 if ( !it3.next().getName().equals( "Z" ) ) {
3911 if ( it3.hasNext() ) {
3914 final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
3915 PhylogenyNodeIterator it4;
3916 for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
3919 for( it4.reset(); it4.hasNext(); ) {
3922 final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
3923 if ( !it5.next().getName().equals( "r" ) ) {
3926 if ( !it5.next().getName().equals( "A" ) ) {
3929 if ( !it5.next().getName().equals( "B" ) ) {
3932 if ( !it5.next().getName().equals( "C" ) ) {
3935 if ( !it5.next().getName().equals( "D" ) ) {
3938 final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
3939 PhylogenyNodeIterator it6;
3940 for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
3943 for( it6.reset(); it6.hasNext(); ) {
3946 final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
3947 if ( !it7.next().getName().equals( "A" ) ) {
3950 if ( it.hasNext() ) {
3954 catch ( final Exception e ) {
3955 e.printStackTrace( System.out );
3961 private static boolean testMidpointrooting() {
3963 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3964 final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
3965 PhylogenyMethods.midpointRoot( t0 );
3966 if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
3969 if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
3972 if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
3976 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",
3977 new NHXParser() )[ 0 ];
3978 if ( !t1.isRooted() ) {
3981 PhylogenyMethods.midpointRoot( t1 );
3982 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
3985 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
3988 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
3991 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
3994 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
3997 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4000 t1.reRoot( t1.getNode( "A" ) );
4001 PhylogenyMethods.midpointRoot( t1 );
4002 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4005 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4008 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4011 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4014 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4018 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4022 catch ( final Exception e ) {
4023 e.printStackTrace( System.out );
4029 private static boolean testNexusCharactersParsing() {
4031 final NexusCharactersParser parser = new NexusCharactersParser();
4032 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4034 String[] labels = parser.getCharStateLabels();
4035 if ( labels.length != 7 ) {
4038 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4041 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4044 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4047 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4050 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4053 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4056 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4059 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4061 labels = parser.getCharStateLabels();
4062 if ( labels.length != 7 ) {
4065 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4068 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4071 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4074 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4077 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4080 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4083 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4087 catch ( final Exception e ) {
4088 e.printStackTrace( System.out );
4094 private static boolean testNexusMatrixParsing() {
4096 final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4097 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4099 final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4100 if ( m.getNumberOfCharacters() != 9 ) {
4103 if ( m.getNumberOfIdentifiers() != 5 ) {
4106 if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4109 if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4112 if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4115 if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4118 if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4121 if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4124 if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4127 // if ( labels.length != 7 ) {
4130 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4133 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4136 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4139 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4142 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4145 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4148 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4151 // parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4153 // labels = parser.getCharStateLabels();
4154 // if ( labels.length != 7 ) {
4157 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4160 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4163 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4166 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4169 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4172 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4175 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4179 catch ( final Exception e ) {
4180 e.printStackTrace( System.out );
4186 private static boolean testNexusTreeParsing() {
4188 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4189 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4190 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4191 if ( phylogenies.length != 1 ) {
4194 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4197 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4201 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4202 if ( phylogenies.length != 1 ) {
4205 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4208 if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4212 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4213 if ( phylogenies.length != 1 ) {
4216 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4219 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4222 if ( phylogenies[ 0 ].isRooted() ) {
4226 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4227 if ( phylogenies.length != 18 ) {
4230 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4233 if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4236 if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4239 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4242 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4245 if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4248 if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4251 if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4254 if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4257 if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4260 if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4263 if ( phylogenies[ 8 ].isRooted() ) {
4266 if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4269 if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4272 if ( !phylogenies[ 9 ].isRooted() ) {
4275 if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4278 if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4281 if ( !phylogenies[ 10 ].isRooted() ) {
4284 if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4287 if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4290 if ( phylogenies[ 11 ].isRooted() ) {
4293 if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4296 if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4299 if ( !phylogenies[ 12 ].isRooted() ) {
4302 if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4305 if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4308 if ( !phylogenies[ 13 ].isRooted() ) {
4311 if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4314 if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4317 if ( !phylogenies[ 14 ].isRooted() ) {
4320 if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4323 if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4326 if ( phylogenies[ 15 ].isRooted() ) {
4329 if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4332 if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4335 if ( !phylogenies[ 16 ].isRooted() ) {
4338 if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4341 if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4344 if ( phylogenies[ 17 ].isRooted() ) {
4347 if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4351 catch ( final Exception e ) {
4352 e.printStackTrace( System.out );
4358 private static boolean testNexusTreeParsingTranslating() {
4360 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4361 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4362 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
4363 if ( phylogenies.length != 1 ) {
4366 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4369 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4372 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4375 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4378 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4379 .equals( "Aranaeus" ) ) {
4383 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
4384 if ( phylogenies.length != 3 ) {
4387 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4390 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4393 if ( phylogenies[ 0 ].isRooted() ) {
4396 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4399 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4402 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4403 .equals( "Aranaeus" ) ) {
4406 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
4409 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
4412 if ( phylogenies[ 1 ].isRooted() ) {
4415 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4418 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4421 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4422 .equals( "Aranaeus" ) ) {
4425 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4428 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
4431 if ( !phylogenies[ 2 ].isRooted() ) {
4434 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4437 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4440 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4441 .equals( "Aranaeus" ) ) {
4445 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
4446 if ( phylogenies.length != 3 ) {
4449 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4452 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4455 if ( phylogenies[ 0 ].isRooted() ) {
4458 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4461 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4464 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4465 .equals( "Aranaeus" ) ) {
4468 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
4471 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
4474 if ( phylogenies[ 1 ].isRooted() ) {
4477 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4480 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4483 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4484 .equals( "Aranaeus" ) ) {
4487 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4490 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
4493 if ( !phylogenies[ 2 ].isRooted() ) {
4496 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4499 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4502 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4503 .equals( "Aranaeus" ) ) {
4507 catch ( final Exception e ) {
4508 e.printStackTrace( System.out );
4514 private static boolean testNHParsing() {
4516 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4517 final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
4518 if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
4521 final NHXParser nhxp = new NHXParser();
4522 nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
4523 nhxp.setReplaceUnderscores( true );
4524 final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
4525 if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
4528 if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
4531 final Phylogeny p1b = factory
4532 .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 ",
4533 new NHXParser() )[ 0 ];
4534 if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
4537 if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
4540 final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
4541 final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
4542 final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
4543 final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
4544 final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
4545 final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
4546 final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
4547 final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
4548 final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
4549 final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
4550 final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
4551 + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
4552 + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
4554 if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
4557 if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
4560 if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
4563 if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
4566 final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
4567 final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
4568 final String p16_S = "((A,B),C)";
4569 final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
4570 if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
4573 final String p17_S = "(C,(A,B))";
4574 final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
4575 if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
4578 final String p18_S = "((A,B),(C,D))";
4579 final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
4580 if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
4583 final String p19_S = "(((A,B),C),D)";
4584 final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
4585 if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
4588 final String p20_S = "(A,(B,(C,D)))";
4589 final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
4590 if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
4593 final String p21_S = "(A,(B,(C,(D,E))))";
4594 final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
4595 if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
4598 final String p22_S = "((((A,B),C),D),E)";
4599 final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
4600 if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
4603 final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4604 final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
4605 if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
4608 final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4609 final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
4610 if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
4613 final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4614 final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4615 final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
4616 if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
4619 if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
4622 final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
4623 + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
4624 + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
4625 + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
4626 + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
4627 + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
4628 + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
4629 + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
4630 final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
4631 if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
4634 final String p26_S = "(A,B)ab";
4635 final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
4636 if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
4639 final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4640 final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
4642 if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
4645 final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4646 final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4647 final String p28_S3 = "(A,B)ab";
4648 final String p28_S4 = "((((A,B),C),D),;E;)";
4649 final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
4651 if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
4654 if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
4657 if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
4660 if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
4663 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";
4664 final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
4665 if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
4668 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";
4669 final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
4670 if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
4673 final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
4674 final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
4675 if ( ( p32.length != 1 ) || !p32[ 0 ].isEmpty() ) {
4678 final String p33_S = "A";
4679 final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
4680 if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
4683 final String p34_S = "B;";
4684 final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
4685 if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
4688 final String p35_S = "B:0.2";
4689 final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
4690 if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
4693 final String p36_S = "(A)";
4694 final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
4695 if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
4698 final String p37_S = "((A))";
4699 final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
4700 if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
4703 final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
4704 final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
4705 if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
4708 final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
4709 final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
4710 if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
4713 final String p40_S = "(A,B,C)";
4714 final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
4715 if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
4718 final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
4719 final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
4720 if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
4723 final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
4724 final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
4725 if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
4728 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)";
4729 final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
4730 if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
4733 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)))";
4734 final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
4735 if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
4738 final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
4739 final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
4740 if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
4743 final String p46_S = "";
4744 final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
4745 if ( ( p46.length != 1 ) || !p46[ 0 ].isEmpty() ) {
4748 final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
4749 if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4752 final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4753 if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4756 final Phylogeny p49 = factory
4757 .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
4758 new NHXParser() )[ 0 ];
4759 if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4762 final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4763 if ( p50.getNode( "A" ) == null ) {
4766 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
4767 .equals( "((A,B)ab:2.0[88],C);" ) ) {
4770 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
4773 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
4774 .equals( "((A,B)88:2.0,C);" ) ) {
4777 final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4778 if ( p51.getNode( "A(A" ) == null ) {
4781 final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4782 if ( p52.getNode( "A(A" ) == null ) {
4785 final Phylogeny p53 = factory
4786 .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
4787 new NHXParser() )[ 0 ];
4788 if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
4792 final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
4793 if ( p54.getNode( "A" ) == null ) {
4796 if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
4797 .equals( "((A,B)[88],C);" ) ) {
4801 catch ( final Exception e ) {
4802 e.printStackTrace( System.out );
4808 private static boolean testNHXconversion() {
4810 final PhylogenyNode n1 = new PhylogenyNode();
4811 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
4812 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
4813 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
4814 final PhylogenyNode n5 = PhylogenyNode
4815 .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]" );
4816 final PhylogenyNode n6 = PhylogenyNode
4817 .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]" );
4818 if ( !n1.toNewHampshireX().equals( "" ) ) {
4821 if ( !n2.toNewHampshireX().equals( "" ) ) {
4824 if ( !n3.toNewHampshireX().equals( "n3" ) ) {
4827 if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
4830 if ( !n5.toNewHampshireX()
4831 .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]" ) ) {
4834 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]" ) ) {
4838 catch ( final Exception e ) {
4839 e.printStackTrace( System.out );
4845 private static boolean testNHXNodeParsing() {
4847 final PhylogenyNode n1 = new PhylogenyNode();
4848 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
4849 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
4850 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
4851 final PhylogenyNode n5 = PhylogenyNode
4852 .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]" );
4853 if ( !n3.getName().equals( "n3" ) ) {
4856 if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
4859 if ( n3.isDuplication() ) {
4862 if ( n3.isHasAssignedEvent() ) {
4865 if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
4868 if ( !n4.getName().equals( "n4" ) ) {
4871 if ( n4.getDistanceToParent() != 0.01 ) {
4874 if ( !n5.getName().equals( "n5" ) ) {
4877 if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
4880 if ( n5.getDistanceToParent() != 0.1 ) {
4883 if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
4886 if ( !n5.isDuplication() ) {
4889 if ( !n5.isHasAssignedEvent() ) {
4892 if ( PhylogenyMethods.getBranchWidthValue( n5 ) != 2 ) {
4895 if ( n5.getNodeData().getProperties().getPropertyRefs().length != 2 ) {
4898 final PhylogenyNode n8 = PhylogenyNode
4899 .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4900 if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
4903 if ( PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
4906 final PhylogenyNode n9 = PhylogenyNode
4907 .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4908 if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
4911 if ( PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
4914 final PhylogenyNode n10 = PhylogenyNode
4915 .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4916 if ( !n10.getName().equals( "n10.ECOLI" ) ) {
4919 final PhylogenyNode n20 = PhylogenyNode
4920 .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4921 if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
4924 if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
4927 final PhylogenyNode n20x = PhylogenyNode.createInstanceFromNhxString( "n20_ECOL1/1-2",
4928 NHXParser.TAXONOMY_EXTRACTION.YES );
4929 if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
4932 if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
4935 final PhylogenyNode n20xx = PhylogenyNode
4936 .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4937 if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
4940 if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
4943 final PhylogenyNode n20xxx = PhylogenyNode
4944 .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4945 if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
4948 if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
4951 final PhylogenyNode n20xxxx = PhylogenyNode
4952 .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4953 if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
4956 if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
4959 final PhylogenyNode n21 = PhylogenyNode.createInstanceFromNhxString( "n21_PIG",
4960 NHXParser.TAXONOMY_EXTRACTION.YES );
4961 if ( !n21.getName().equals( "n21_PIG" ) ) {
4964 if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
4967 final PhylogenyNode n21x = PhylogenyNode
4968 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4969 if ( !n21x.getName().equals( "n21_PIG" ) ) {
4972 if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
4975 final PhylogenyNode n22 = PhylogenyNode
4976 .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4977 if ( !n22.getName().equals( "n22/PIG" ) ) {
4980 if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
4983 final PhylogenyNode n23 = PhylogenyNode
4984 .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4985 if ( !n23.getName().equals( "n23/PIG_1" ) ) {
4988 if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
4991 final PhylogenyNode a = PhylogenyNode
4992 .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4993 if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
4996 if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
4999 final PhylogenyNode b = PhylogenyNode
5000 .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5001 if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
5004 if ( PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
5007 final PhylogenyNode c = PhylogenyNode
5008 .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
5009 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5010 if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
5013 if ( PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
5016 final PhylogenyNode c1 = PhylogenyNode
5017 .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
5018 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5019 if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
5022 if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
5025 final PhylogenyNode c2 = PhylogenyNode
5026 .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
5027 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5028 if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
5031 if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
5034 final PhylogenyNode d = PhylogenyNode
5035 .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5036 if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
5039 if ( PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
5042 final PhylogenyNode e = PhylogenyNode
5043 .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5044 if ( !e.getName().equals( "n10_RAT1" ) ) {
5047 if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
5050 final PhylogenyNode e2 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT1",
5051 NHXParser.TAXONOMY_EXTRACTION.YES );
5052 if ( !e2.getName().equals( "n10_RAT1" ) ) {
5055 if ( !PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
5058 final PhylogenyNode e3 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT~",
5059 NHXParser.TAXONOMY_EXTRACTION.YES );
5060 if ( !e3.getName().equals( "n10_RAT~" ) ) {
5063 if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
5066 final PhylogenyNode n11 = PhylogenyNode
5067 .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
5068 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5069 if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
5072 if ( n11.getDistanceToParent() != 0.4 ) {
5075 if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
5078 final PhylogenyNode n12 = PhylogenyNode
5079 .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
5080 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5081 if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
5084 if ( n12.getDistanceToParent() != 0.4 ) {
5087 if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
5090 final PhylogenyNode m = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSEa",
5091 NHXParser.TAXONOMY_EXTRACTION.YES );
5092 if ( !m.getName().equals( "n10_MOUSEa" ) ) {
5095 if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
5098 final PhylogenyNode o = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSE_",
5099 NHXParser.TAXONOMY_EXTRACTION.YES );
5100 if ( !o.getName().equals( "n10_MOUSE_" ) ) {
5103 if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
5106 final Property tvu1 = n5.getNodeData().getProperties().getProperty( "tag1" );
5107 final Property tvu3 = n5.getNodeData().getProperties().getProperty( "tag3" );
5108 if ( !tvu1.getRef().equals( "tag1" ) ) {
5111 if ( !tvu1.getDataType().equals( "xsd:string" ) ) {
5114 if ( !tvu1.getUnit().equals( "unit1" ) ) {
5117 if ( !tvu1.getValue().equals( "value1" ) ) {
5120 if ( !tvu3.getRef().equals( "tag3" ) ) {
5123 if ( !tvu3.getDataType().equals( "xsd:string" ) ) {
5126 if ( !tvu3.getUnit().equals( "unit3" ) ) {
5129 if ( !tvu3.getValue().equals( "value3" ) ) {
5132 if ( n1.getName().compareTo( "" ) != 0 ) {
5135 if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5138 if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
5141 if ( n2.getName().compareTo( "" ) != 0 ) {
5144 if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5147 if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
5150 final PhylogenyNode n00 = PhylogenyNode
5151 .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]" );
5152 if ( !n00.getNodeData().getNodeIdentifier().getValue().equals( "node_identifier" ) ) {
5155 if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
5158 if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
5161 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getRef().equals( "url_tag" ) ) {
5164 if ( n00.getNodeData().getProperties().getProperty( "url_tag" ).getAppliesTo() != Property.AppliesTo.NODE ) {
5167 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getDataType().equals( "xsd:anyURI" ) ) {
5170 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getValue().equals( "www.yahoo.com" ) ) {
5173 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getUnit().equals( "" ) ) {
5176 final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
5177 if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
5180 final PhylogenyNode nx2 = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:G=gene_2]" );
5181 if ( !nx2.getNodeData().getSequence().getName().equals( "gene_2" ) ) {
5184 final PhylogenyNode n13 = PhylogenyNode
5185 .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5186 if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
5189 if ( !PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
5192 final PhylogenyNode n14 = PhylogenyNode
5193 .createInstanceFromNhxString( "blah_12X45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5194 if ( !n14.getName().equals( "blah_12X45/1-2" ) ) {
5197 if ( !PhylogenyMethods.getSpecies( n14 ).equals( "12X45" ) ) {
5200 final PhylogenyNode n15 = PhylogenyNode
5201 .createInstanceFromNhxString( "something_wicked[123]",
5202 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5203 if ( !n15.getName().equals( "something_wicked" ) ) {
5206 if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
5209 if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
5212 final PhylogenyNode n16 = PhylogenyNode
5213 .createInstanceFromNhxString( "something_wicked2[9]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5214 if ( !n16.getName().equals( "something_wicked2" ) ) {
5217 if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
5220 if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
5223 final PhylogenyNode n17 = PhylogenyNode
5224 .createInstanceFromNhxString( "something_wicked3[a]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5225 if ( !n17.getName().equals( "something_wicked3" ) ) {
5228 if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
5231 final PhylogenyNode n18 = PhylogenyNode
5232 .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5233 if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
5236 if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
5239 if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
5243 catch ( final Exception e ) {
5244 e.printStackTrace( System.out );
5250 private static boolean testNHXParsing() {
5252 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5253 final Phylogeny p1 = factory.create( "(A [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
5254 if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
5257 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]";
5258 final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
5259 if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5262 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]";
5263 final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
5264 if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
5267 final Phylogeny[] p3 = factory
5268 .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]",
5270 if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5273 final Phylogeny[] p4 = factory
5274 .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(]",
5276 if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5279 final Phylogeny[] p5 = factory
5280 .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(((]",
5282 if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5285 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)";
5286 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)";
5287 final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
5288 if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
5291 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)))";
5292 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)))";
5293 final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
5294 if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
5297 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]) ))[,,, ])))))))";
5298 final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
5299 final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
5300 if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
5303 final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
5304 if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
5307 final Phylogeny p10 = factory
5308 .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]",
5309 new NHXParser() )[ 0 ];
5310 if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
5314 catch ( final Exception e ) {
5315 e.printStackTrace( System.out );
5321 private static boolean testNHXParsingQuotes() {
5323 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5324 final NHXParser p = new NHXParser();
5325 final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
5326 if ( phylogenies_0.length != 5 ) {
5329 final Phylogeny phy = phylogenies_0[ 4 ];
5330 if ( phy.getNumberOfExternalNodes() != 7 ) {
5333 if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
5336 if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
5339 if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
5340 .getScientificName().equals( "hsapiens" ) ) {
5343 if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
5346 if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
5349 if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
5352 if ( phy.getNodes( "noquotes" ).size() != 1 ) {
5355 if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
5358 final NHXParser p1p = new NHXParser();
5359 p1p.setIgnoreQuotes( true );
5360 final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
5361 if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
5364 final NHXParser p2p = new NHXParser();
5365 p1p.setIgnoreQuotes( false );
5366 final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
5367 if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
5370 final NHXParser p3p = new NHXParser();
5371 p3p.setIgnoreQuotes( false );
5372 final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
5373 if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
5376 final NHXParser p4p = new NHXParser();
5377 p4p.setIgnoreQuotes( false );
5378 final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
5379 if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
5382 final Phylogeny p10 = factory
5383 .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]",
5384 new NHXParser() )[ 0 ];
5385 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]";
5386 if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
5389 final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
5390 if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
5394 final Phylogeny p12 = factory
5395 .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]",
5396 new NHXParser() )[ 0 ];
5397 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]";
5398 if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
5401 final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
5402 if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
5405 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;";
5406 if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
5409 final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
5410 if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
5414 catch ( final Exception e ) {
5415 e.printStackTrace( System.out );
5421 private static boolean testNHXParsingMB() {
5423 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5424 final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
5425 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5426 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
5427 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
5428 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
5429 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5430 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
5431 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
5432 + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
5433 if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
5436 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
5439 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
5440 0.1100000000000000e+00 ) ) {
5443 if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
5446 if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
5449 final Phylogeny p2 = factory
5450 .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
5451 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5452 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
5453 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
5454 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
5455 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5456 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
5457 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
5458 + "7.369400000000000e-02}])",
5459 new NHXParser() )[ 0 ];
5460 if ( p2.getNode( "1" ) == null ) {
5463 if ( p2.getNode( "2" ) == null ) {
5467 catch ( final Exception e ) {
5468 e.printStackTrace( System.out );
5475 private static boolean testPhylogenyBranch() {
5477 final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
5478 final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
5479 final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
5480 final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
5481 if ( !a1b1.equals( a1b1 ) ) {
5484 if ( !a1b1.equals( b1a1 ) ) {
5487 if ( !b1a1.equals( a1b1 ) ) {
5490 final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
5491 final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
5492 final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
5493 if ( a1_b1.equals( b1_a1 ) ) {
5496 if ( a1_b1.equals( a1_b1_ ) ) {
5499 final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
5500 if ( !a1_b1.equals( b1_a1_ ) ) {
5503 if ( a1_b1_.equals( b1_a1_ ) ) {
5506 if ( !a1_b1_.equals( b1_a1 ) ) {
5510 catch ( final Exception e ) {
5511 e.printStackTrace( System.out );
5517 private static boolean testPhyloXMLparsingOfDistributionElement() {
5519 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5520 PhyloXmlParser xml_parser = null;
5522 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
5524 catch ( final Exception e ) {
5525 // Do nothing -- means were not running from jar.
5527 if ( xml_parser == null ) {
5528 xml_parser = new PhyloXmlParser();
5529 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
5530 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
5533 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
5536 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
5538 if ( xml_parser.getErrorCount() > 0 ) {
5539 System.out.println( xml_parser.getErrorMessages().toString() );
5542 if ( phylogenies_0.length != 1 ) {
5545 final Phylogeny t1 = phylogenies_0[ 0 ];
5546 PhylogenyNode n = null;
5547 Distribution d = null;
5548 n = t1.getNode( "root node" );
5549 if ( !n.getNodeData().isHasDistribution() ) {
5552 if ( n.getNodeData().getDistributions().size() != 1 ) {
5555 d = n.getNodeData().getDistribution();
5556 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
5559 if ( d.getPoints().size() != 1 ) {
5562 if ( d.getPolygons() != null ) {
5565 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
5568 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5571 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5574 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
5577 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
5580 n = t1.getNode( "node a" );
5581 if ( !n.getNodeData().isHasDistribution() ) {
5584 if ( n.getNodeData().getDistributions().size() != 2 ) {
5587 d = n.getNodeData().getDistribution( 1 );
5588 if ( !d.getDesc().equals( "San Diego" ) ) {
5591 if ( d.getPoints().size() != 1 ) {
5594 if ( d.getPolygons() != null ) {
5597 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
5600 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5603 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5606 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
5609 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
5612 n = t1.getNode( "node bb" );
5613 if ( !n.getNodeData().isHasDistribution() ) {
5616 if ( n.getNodeData().getDistributions().size() != 1 ) {
5619 d = n.getNodeData().getDistribution( 0 );
5620 if ( d.getPoints().size() != 3 ) {
5623 if ( d.getPolygons().size() != 2 ) {
5626 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
5629 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
5632 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
5635 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
5638 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
5641 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
5644 Polygon p = d.getPolygons().get( 0 );
5645 if ( p.getPoints().size() != 3 ) {
5648 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
5651 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
5654 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5657 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
5660 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
5663 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
5666 p = d.getPolygons().get( 1 );
5667 if ( p.getPoints().size() != 3 ) {
5670 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
5673 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
5676 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5680 final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
5681 final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
5682 if ( rt.length != 1 ) {
5685 final Phylogeny t1_rt = rt[ 0 ];
5686 n = t1_rt.getNode( "root node" );
5687 if ( !n.getNodeData().isHasDistribution() ) {
5690 if ( n.getNodeData().getDistributions().size() != 1 ) {
5693 d = n.getNodeData().getDistribution();
5694 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
5697 if ( d.getPoints().size() != 1 ) {
5700 if ( d.getPolygons() != null ) {
5703 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
5706 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5709 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5712 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
5715 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
5718 n = t1_rt.getNode( "node a" );
5719 if ( !n.getNodeData().isHasDistribution() ) {
5722 if ( n.getNodeData().getDistributions().size() != 2 ) {
5725 d = n.getNodeData().getDistribution( 1 );
5726 if ( !d.getDesc().equals( "San Diego" ) ) {
5729 if ( d.getPoints().size() != 1 ) {
5732 if ( d.getPolygons() != null ) {
5735 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
5738 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5741 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5744 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
5747 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
5750 n = t1_rt.getNode( "node bb" );
5751 if ( !n.getNodeData().isHasDistribution() ) {
5754 if ( n.getNodeData().getDistributions().size() != 1 ) {
5757 d = n.getNodeData().getDistribution( 0 );
5758 if ( d.getPoints().size() != 3 ) {
5761 if ( d.getPolygons().size() != 2 ) {
5764 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
5767 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
5770 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
5773 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
5776 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
5779 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
5782 p = d.getPolygons().get( 0 );
5783 if ( p.getPoints().size() != 3 ) {
5786 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
5789 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
5792 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5795 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
5798 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
5801 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
5804 p = d.getPolygons().get( 1 );
5805 if ( p.getPoints().size() != 3 ) {
5808 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
5811 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
5814 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5818 catch ( final Exception e ) {
5819 e.printStackTrace( System.out );
5825 private static boolean testPostOrderIterator() {
5827 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5828 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5829 PhylogenyNodeIterator it0;
5830 for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
5833 for( it0.reset(); it0.hasNext(); ) {
5836 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
5837 final PhylogenyNodeIterator it = t1.iteratorPostorder();
5838 if ( !it.next().getName().equals( "A" ) ) {
5841 if ( !it.next().getName().equals( "B" ) ) {
5844 if ( !it.next().getName().equals( "ab" ) ) {
5847 if ( !it.next().getName().equals( "C" ) ) {
5850 if ( !it.next().getName().equals( "D" ) ) {
5853 if ( !it.next().getName().equals( "cd" ) ) {
5856 if ( !it.next().getName().equals( "abcd" ) ) {
5859 if ( !it.next().getName().equals( "E" ) ) {
5862 if ( !it.next().getName().equals( "F" ) ) {
5865 if ( !it.next().getName().equals( "ef" ) ) {
5868 if ( !it.next().getName().equals( "G" ) ) {
5871 if ( !it.next().getName().equals( "H" ) ) {
5874 if ( !it.next().getName().equals( "gh" ) ) {
5877 if ( !it.next().getName().equals( "efgh" ) ) {
5880 if ( !it.next().getName().equals( "r" ) ) {
5883 if ( it.hasNext() ) {
5887 catch ( final Exception e ) {
5888 e.printStackTrace( System.out );
5894 private static boolean testPreOrderIterator() {
5896 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5897 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5898 PhylogenyNodeIterator it0;
5899 for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
5902 for( it0.reset(); it0.hasNext(); ) {
5905 PhylogenyNodeIterator it = t0.iteratorPreorder();
5906 if ( !it.next().getName().equals( "r" ) ) {
5909 if ( !it.next().getName().equals( "ab" ) ) {
5912 if ( !it.next().getName().equals( "A" ) ) {
5915 if ( !it.next().getName().equals( "B" ) ) {
5918 if ( !it.next().getName().equals( "cd" ) ) {
5921 if ( !it.next().getName().equals( "C" ) ) {
5924 if ( !it.next().getName().equals( "D" ) ) {
5927 if ( it.hasNext() ) {
5930 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
5931 it = t1.iteratorPreorder();
5932 if ( !it.next().getName().equals( "r" ) ) {
5935 if ( !it.next().getName().equals( "abcd" ) ) {
5938 if ( !it.next().getName().equals( "ab" ) ) {
5941 if ( !it.next().getName().equals( "A" ) ) {
5944 if ( !it.next().getName().equals( "B" ) ) {
5947 if ( !it.next().getName().equals( "cd" ) ) {
5950 if ( !it.next().getName().equals( "C" ) ) {
5953 if ( !it.next().getName().equals( "D" ) ) {
5956 if ( !it.next().getName().equals( "efgh" ) ) {
5959 if ( !it.next().getName().equals( "ef" ) ) {
5962 if ( !it.next().getName().equals( "E" ) ) {
5965 if ( !it.next().getName().equals( "F" ) ) {
5968 if ( !it.next().getName().equals( "gh" ) ) {
5971 if ( !it.next().getName().equals( "G" ) ) {
5974 if ( !it.next().getName().equals( "H" ) ) {
5977 if ( it.hasNext() ) {
5981 catch ( final Exception e ) {
5982 e.printStackTrace( System.out );
5988 private static boolean testPropertiesMap() {
5990 final PropertiesMap pm = new PropertiesMap();
5991 final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
5992 final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
5993 final Property p2 = new Property( "something:else",
5995 "improbable:research",
5998 pm.addProperty( p0 );
5999 pm.addProperty( p1 );
6000 pm.addProperty( p2 );
6001 if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
6004 if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
6007 if ( pm.getProperties().size() != 3 ) {
6010 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
6013 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
6016 if ( pm.getProperties().size() != 3 ) {
6019 pm.removeProperty( "dimensions:diameter" );
6020 if ( pm.getProperties().size() != 2 ) {
6023 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
6026 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
6030 catch ( final Exception e ) {
6031 e.printStackTrace( System.out );
6037 private static boolean testReIdMethods() {
6039 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6040 final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
6041 final int count = PhylogenyNode.getNodeCount();
6043 if ( p.getNode( "r" ).getId() != count ) {
6046 if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
6049 if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
6052 if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
6055 if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
6058 if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
6061 if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
6064 if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
6067 if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
6070 if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
6073 if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
6076 if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
6079 if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
6082 if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
6085 if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
6089 catch ( final Exception e ) {
6090 e.printStackTrace( System.out );
6096 private static boolean testRerooting() {
6098 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6099 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",
6100 new NHXParser() )[ 0 ];
6101 if ( !t1.isRooted() ) {
6104 t1.reRoot( t1.getNode( "D" ) );
6105 t1.reRoot( t1.getNode( "CD" ) );
6106 t1.reRoot( t1.getNode( "A" ) );
6107 t1.reRoot( t1.getNode( "B" ) );
6108 t1.reRoot( t1.getNode( "AB" ) );
6109 t1.reRoot( t1.getNode( "D" ) );
6110 t1.reRoot( t1.getNode( "C" ) );
6111 t1.reRoot( t1.getNode( "CD" ) );
6112 t1.reRoot( t1.getNode( "A" ) );
6113 t1.reRoot( t1.getNode( "B" ) );
6114 t1.reRoot( t1.getNode( "AB" ) );
6115 t1.reRoot( t1.getNode( "D" ) );
6116 t1.reRoot( t1.getNode( "D" ) );
6117 t1.reRoot( t1.getNode( "C" ) );
6118 t1.reRoot( t1.getNode( "A" ) );
6119 t1.reRoot( t1.getNode( "B" ) );
6120 t1.reRoot( t1.getNode( "AB" ) );
6121 t1.reRoot( t1.getNode( "C" ) );
6122 t1.reRoot( t1.getNode( "D" ) );
6123 t1.reRoot( t1.getNode( "CD" ) );
6124 t1.reRoot( t1.getNode( "D" ) );
6125 t1.reRoot( t1.getNode( "A" ) );
6126 t1.reRoot( t1.getNode( "B" ) );
6127 t1.reRoot( t1.getNode( "AB" ) );
6128 t1.reRoot( t1.getNode( "C" ) );
6129 t1.reRoot( t1.getNode( "D" ) );
6130 t1.reRoot( t1.getNode( "CD" ) );
6131 t1.reRoot( t1.getNode( "D" ) );
6132 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6135 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6138 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6141 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
6144 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
6147 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
6150 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",
6151 new NHXParser() )[ 0 ];
6152 t2.reRoot( t2.getNode( "A" ) );
6153 t2.reRoot( t2.getNode( "D" ) );
6154 t2.reRoot( t2.getNode( "ABC" ) );
6155 t2.reRoot( t2.getNode( "A" ) );
6156 t2.reRoot( t2.getNode( "B" ) );
6157 t2.reRoot( t2.getNode( "D" ) );
6158 t2.reRoot( t2.getNode( "C" ) );
6159 t2.reRoot( t2.getNode( "ABC" ) );
6160 t2.reRoot( t2.getNode( "A" ) );
6161 t2.reRoot( t2.getNode( "B" ) );
6162 t2.reRoot( t2.getNode( "AB" ) );
6163 t2.reRoot( t2.getNode( "AB" ) );
6164 t2.reRoot( t2.getNode( "D" ) );
6165 t2.reRoot( t2.getNode( "C" ) );
6166 t2.reRoot( t2.getNode( "B" ) );
6167 t2.reRoot( t2.getNode( "AB" ) );
6168 t2.reRoot( t2.getNode( "D" ) );
6169 t2.reRoot( t2.getNode( "D" ) );
6170 t2.reRoot( t2.getNode( "ABC" ) );
6171 t2.reRoot( t2.getNode( "A" ) );
6172 t2.reRoot( t2.getNode( "B" ) );
6173 t2.reRoot( t2.getNode( "AB" ) );
6174 t2.reRoot( t2.getNode( "D" ) );
6175 t2.reRoot( t2.getNode( "C" ) );
6176 t2.reRoot( t2.getNode( "ABC" ) );
6177 t2.reRoot( t2.getNode( "A" ) );
6178 t2.reRoot( t2.getNode( "B" ) );
6179 t2.reRoot( t2.getNode( "AB" ) );
6180 t2.reRoot( t2.getNode( "D" ) );
6181 t2.reRoot( t2.getNode( "D" ) );
6182 t2.reRoot( t2.getNode( "C" ) );
6183 t2.reRoot( t2.getNode( "A" ) );
6184 t2.reRoot( t2.getNode( "B" ) );
6185 t2.reRoot( t2.getNode( "AB" ) );
6186 t2.reRoot( t2.getNode( "C" ) );
6187 t2.reRoot( t2.getNode( "D" ) );
6188 t2.reRoot( t2.getNode( "ABC" ) );
6189 t2.reRoot( t2.getNode( "D" ) );
6190 t2.reRoot( t2.getNode( "A" ) );
6191 t2.reRoot( t2.getNode( "B" ) );
6192 t2.reRoot( t2.getNode( "AB" ) );
6193 t2.reRoot( t2.getNode( "C" ) );
6194 t2.reRoot( t2.getNode( "D" ) );
6195 t2.reRoot( t2.getNode( "ABC" ) );
6196 t2.reRoot( t2.getNode( "D" ) );
6197 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6200 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6203 t2.reRoot( t2.getNode( "ABC" ) );
6204 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6207 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6210 t2.reRoot( t2.getNode( "AB" ) );
6211 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6214 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6217 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6220 t2.reRoot( t2.getNode( "AB" ) );
6221 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6224 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6227 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6230 t2.reRoot( t2.getNode( "D" ) );
6231 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6234 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6237 t2.reRoot( t2.getNode( "ABC" ) );
6238 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6241 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6244 final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
6245 new NHXParser() )[ 0 ];
6246 t3.reRoot( t3.getNode( "B" ) );
6247 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6250 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6253 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6256 t3.reRoot( t3.getNode( "B" ) );
6257 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6260 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6263 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6266 t3.reRoot( t3.getRoot() );
6267 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6270 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6273 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6277 catch ( final Exception e ) {
6278 e.printStackTrace( System.out );
6284 private static boolean testSDIse() {
6286 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6287 final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
6288 final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
6289 gene1.setRooted( true );
6290 species1.setRooted( true );
6291 final SDI sdi = new SDI( gene1, species1 );
6292 if ( !gene1.getRoot().isDuplication() ) {
6295 final Phylogeny species2 = factory
6296 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6297 new NHXParser() )[ 0 ];
6298 final Phylogeny gene2 = factory
6299 .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6300 new NHXParser() )[ 0 ];
6301 species2.setRooted( true );
6302 gene2.setRooted( true );
6303 final SDI sdi2 = new SDI( gene2, species2 );
6304 if ( sdi2.getDuplicationsSum() != 0 ) {
6307 if ( !gene2.getNode( "ab" ).isSpeciation() ) {
6310 if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
6313 if ( !gene2.getNode( "abc" ).isSpeciation() ) {
6316 if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
6319 if ( !gene2.getNode( "r" ).isSpeciation() ) {
6322 if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
6325 final Phylogeny species3 = factory
6326 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6327 new NHXParser() )[ 0 ];
6328 final Phylogeny gene3 = factory
6329 .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6330 new NHXParser() )[ 0 ];
6331 species3.setRooted( true );
6332 gene3.setRooted( true );
6333 final SDI sdi3 = new SDI( gene3, species3 );
6334 if ( sdi3.getDuplicationsSum() != 1 ) {
6337 if ( !gene3.getNode( "aa" ).isDuplication() ) {
6340 if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
6343 final Phylogeny species4 = factory
6344 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6345 new NHXParser() )[ 0 ];
6346 final Phylogeny gene4 = factory
6347 .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6348 new NHXParser() )[ 0 ];
6349 species4.setRooted( true );
6350 gene4.setRooted( true );
6351 final SDI sdi4 = new SDI( gene4, species4 );
6352 if ( sdi4.getDuplicationsSum() != 1 ) {
6355 if ( !gene4.getNode( "ac" ).isSpeciation() ) {
6358 if ( !gene4.getNode( "abc" ).isDuplication() ) {
6361 if ( gene4.getNode( "abcd" ).isDuplication() ) {
6364 if ( species4.getNumberOfExternalNodes() != 6 ) {
6367 if ( gene4.getNumberOfExternalNodes() != 6 ) {
6370 final Phylogeny species5 = factory
6371 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6372 new NHXParser() )[ 0 ];
6373 final Phylogeny gene5 = factory
6374 .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6375 new NHXParser() )[ 0 ];
6376 species5.setRooted( true );
6377 gene5.setRooted( true );
6378 final SDI sdi5 = new SDI( gene5, species5 );
6379 if ( sdi5.getDuplicationsSum() != 2 ) {
6382 if ( !gene5.getNode( "ad" ).isSpeciation() ) {
6385 if ( !gene5.getNode( "adc" ).isDuplication() ) {
6388 if ( !gene5.getNode( "abcd" ).isDuplication() ) {
6391 if ( species5.getNumberOfExternalNodes() != 6 ) {
6394 if ( gene5.getNumberOfExternalNodes() != 6 ) {
6397 // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
6398 // Conjecture for Comparing Molecular Phylogenies"
6399 // J. of Comput Bio. Vol. 4, No 2, pp.177-187
6400 final Phylogeny species6 = factory
6401 .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,"
6402 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6403 new NHXParser() )[ 0 ];
6404 final Phylogeny gene6 = factory
6405 .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,"
6406 + "((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,"
6407 + "(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;",
6408 new NHXParser() )[ 0 ];
6409 species6.setRooted( true );
6410 gene6.setRooted( true );
6411 final SDI sdi6 = new SDI( gene6, species6 );
6412 if ( sdi6.getDuplicationsSum() != 3 ) {
6415 if ( !gene6.getNode( "r" ).isDuplication() ) {
6418 if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
6421 if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
6424 if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
6427 if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
6430 if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
6433 if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
6436 if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
6439 sdi6.computeMappingCostL();
6440 if ( sdi6.computeMappingCostL() != 17 ) {
6443 if ( species6.getNumberOfExternalNodes() != 9 ) {
6446 if ( gene6.getNumberOfExternalNodes() != 9 ) {
6449 final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
6450 + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
6451 + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
6452 + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
6453 + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
6454 species7.setRooted( true );
6455 final Phylogeny gene7_1 = Test
6456 .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])" );
6457 gene7_1.setRooted( true );
6458 final SDI sdi7 = new SDI( gene7_1, species7 );
6459 if ( sdi7.getDuplicationsSum() != 0 ) {
6462 if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
6465 if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
6468 if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
6471 if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
6474 if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
6477 if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
6480 if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
6483 if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
6486 final Phylogeny gene7_2 = Test
6487 .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])" );
6488 gene7_2.setRooted( true );
6489 final SDI sdi7_2 = new SDI( gene7_2, species7 );
6490 if ( sdi7_2.getDuplicationsSum() != 1 ) {
6493 if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
6496 if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
6499 if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
6502 if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
6505 if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
6508 if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
6511 if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
6514 if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
6517 if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
6521 catch ( final Exception e ) {
6527 private static boolean testSDIunrooted() {
6529 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6530 final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
6531 final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
6532 final Iterator<PhylogenyBranch> iter = l.iterator();
6533 PhylogenyBranch br = iter.next();
6534 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
6537 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
6541 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
6544 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
6548 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
6551 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
6555 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6558 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6562 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6565 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6569 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
6572 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
6576 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6579 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6583 if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6586 if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6590 if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6593 if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6597 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6600 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6604 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
6607 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
6611 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
6614 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
6618 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
6621 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
6625 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
6628 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
6632 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
6635 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
6638 if ( iter.hasNext() ) {
6641 final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
6642 final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
6643 final Iterator<PhylogenyBranch> iter1 = l1.iterator();
6645 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
6648 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
6652 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6655 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6659 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6662 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6665 if ( iter1.hasNext() ) {
6668 final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
6669 final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
6670 final Iterator<PhylogenyBranch> iter2 = l2.iterator();
6672 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
6675 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
6679 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6682 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6686 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6689 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6692 if ( iter2.hasNext() ) {
6695 final Phylogeny species0 = factory
6696 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6697 new NHXParser() )[ 0 ];
6698 final Phylogeny gene1 = factory
6699 .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])",
6700 new NHXParser() )[ 0 ];
6701 species0.setRooted( true );
6702 gene1.setRooted( true );
6703 final SDIR sdi_unrooted = new SDIR();
6704 sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
6705 if ( sdi_unrooted.getCount() != 1 ) {
6708 if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
6711 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
6714 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
6717 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6720 final Phylogeny gene2 = factory
6721 .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])",
6722 new NHXParser() )[ 0 ];
6723 gene2.setRooted( true );
6724 sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
6725 if ( sdi_unrooted.getCount() != 1 ) {
6728 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6731 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6734 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
6737 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6740 final Phylogeny species6 = factory
6741 .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,"
6742 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6743 new NHXParser() )[ 0 ];
6744 final Phylogeny gene6 = factory
6745 .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],"
6746 + "(((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],"
6747 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6748 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6749 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6750 new NHXParser() )[ 0 ];
6751 species6.setRooted( true );
6752 gene6.setRooted( true );
6753 Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
6754 if ( sdi_unrooted.getCount() != 1 ) {
6757 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6760 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6763 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6766 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6769 if ( !p6[ 0 ].getRoot().isDuplication() ) {
6772 if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6775 if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6778 if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
6781 if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6784 if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
6787 if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
6790 if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6794 final Phylogeny species7 = factory
6795 .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,"
6796 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6797 new NHXParser() )[ 0 ];
6798 final Phylogeny gene7 = factory
6799 .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],"
6800 + "(((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],"
6801 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6802 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6803 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6804 new NHXParser() )[ 0 ];
6805 species7.setRooted( true );
6806 gene7.setRooted( true );
6807 Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
6808 if ( sdi_unrooted.getCount() != 1 ) {
6811 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6814 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6817 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6820 if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
6823 if ( !p7[ 0 ].getRoot().isDuplication() ) {
6826 if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6829 if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6832 if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
6835 if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6838 if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
6841 if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
6844 if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6848 final Phylogeny species8 = factory
6849 .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,"
6850 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6851 new NHXParser() )[ 0 ];
6852 final Phylogeny gene8 = factory
6853 .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],"
6854 + "(((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],"
6855 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6856 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6857 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6858 new NHXParser() )[ 0 ];
6859 species8.setRooted( true );
6860 gene8.setRooted( true );
6861 Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
6862 if ( sdi_unrooted.getCount() != 1 ) {
6865 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6868 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6871 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6874 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6877 if ( !p8[ 0 ].getRoot().isDuplication() ) {
6880 if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6883 if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6886 if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
6889 if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6892 if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
6895 if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
6898 if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6903 catch ( final Exception e ) {
6904 e.printStackTrace( System.out );
6910 private static boolean testSplit() {
6912 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6913 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
6914 //Archaeopteryx.createApplication( p0 );
6915 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
6916 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6917 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6918 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6919 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6920 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6921 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6922 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6923 ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
6924 ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
6925 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
6926 // System.out.println( s0.toString() );
6928 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
6929 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6930 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6931 if ( s0.match( query_nodes ) ) {
6934 query_nodes = new HashSet<PhylogenyNode>();
6935 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6936 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6937 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6938 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6939 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6940 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6941 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6942 if ( !s0.match( query_nodes ) ) {
6946 query_nodes = new HashSet<PhylogenyNode>();
6947 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6948 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6949 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6950 if ( !s0.match( query_nodes ) ) {
6954 query_nodes = new HashSet<PhylogenyNode>();
6955 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6956 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6957 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6958 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6959 if ( !s0.match( query_nodes ) ) {
6963 query_nodes = new HashSet<PhylogenyNode>();
6964 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6965 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6966 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6967 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6968 if ( !s0.match( query_nodes ) ) {
6972 query_nodes = new HashSet<PhylogenyNode>();
6973 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6974 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6975 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6976 if ( !s0.match( query_nodes ) ) {
6980 query_nodes = new HashSet<PhylogenyNode>();
6981 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6982 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6983 if ( !s0.match( query_nodes ) ) {
6987 query_nodes = new HashSet<PhylogenyNode>();
6988 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6989 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6990 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6991 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6992 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6993 if ( !s0.match( query_nodes ) ) {
6997 query_nodes = new HashSet<PhylogenyNode>();
6998 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6999 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7000 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7001 if ( !s0.match( query_nodes ) ) {
7005 query_nodes = new HashSet<PhylogenyNode>();
7006 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7007 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7008 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7009 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7010 if ( !s0.match( query_nodes ) ) {
7014 query_nodes = new HashSet<PhylogenyNode>();
7015 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7016 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7017 if ( s0.match( query_nodes ) ) {
7021 query_nodes = new HashSet<PhylogenyNode>();
7022 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7023 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7024 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7025 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7026 if ( s0.match( query_nodes ) ) {
7030 query_nodes = new HashSet<PhylogenyNode>();
7031 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7032 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7033 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7034 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7035 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7036 if ( s0.match( query_nodes ) ) {
7040 query_nodes = new HashSet<PhylogenyNode>();
7041 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7042 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7043 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7044 if ( s0.match( query_nodes ) ) {
7048 query_nodes = new HashSet<PhylogenyNode>();
7049 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7050 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7051 if ( s0.match( query_nodes ) ) {
7055 query_nodes = new HashSet<PhylogenyNode>();
7056 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7057 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7058 if ( s0.match( query_nodes ) ) {
7062 query_nodes = new HashSet<PhylogenyNode>();
7063 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7064 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7065 if ( s0.match( query_nodes ) ) {
7069 query_nodes = new HashSet<PhylogenyNode>();
7070 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7071 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7072 if ( s0.match( query_nodes ) ) {
7076 query_nodes = new HashSet<PhylogenyNode>();
7077 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7078 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7079 if ( s0.match( query_nodes ) ) {
7083 query_nodes = new HashSet<PhylogenyNode>();
7084 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7085 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7086 if ( s0.match( query_nodes ) ) {
7090 query_nodes = new HashSet<PhylogenyNode>();
7091 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7092 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7093 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7094 if ( s0.match( query_nodes ) ) {
7098 query_nodes = new HashSet<PhylogenyNode>();
7099 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7100 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7101 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7102 if ( s0.match( query_nodes ) ) {
7106 query_nodes = new HashSet<PhylogenyNode>();
7107 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7108 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7109 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7110 if ( s0.match( query_nodes ) ) {
7114 query_nodes = new HashSet<PhylogenyNode>();
7115 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7116 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7117 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7118 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7119 if ( s0.match( query_nodes ) ) {
7123 // query_nodes = new HashSet<PhylogenyNode>();
7124 // query_nodes.add( new PhylogenyNode( "X" ) );
7125 // query_nodes.add( new PhylogenyNode( "Y" ) );
7126 // query_nodes.add( new PhylogenyNode( "A" ) );
7127 // query_nodes.add( new PhylogenyNode( "B" ) );
7128 // query_nodes.add( new PhylogenyNode( "C" ) );
7129 // query_nodes.add( new PhylogenyNode( "D" ) );
7130 // query_nodes.add( new PhylogenyNode( "E" ) );
7131 // query_nodes.add( new PhylogenyNode( "F" ) );
7132 // query_nodes.add( new PhylogenyNode( "G" ) );
7133 // if ( !s0.match( query_nodes ) ) {
7136 // query_nodes = new HashSet<PhylogenyNode>();
7137 // query_nodes.add( new PhylogenyNode( "X" ) );
7138 // query_nodes.add( new PhylogenyNode( "Y" ) );
7139 // query_nodes.add( new PhylogenyNode( "A" ) );
7140 // query_nodes.add( new PhylogenyNode( "B" ) );
7141 // query_nodes.add( new PhylogenyNode( "C" ) );
7142 // if ( !s0.match( query_nodes ) ) {
7146 // query_nodes = new HashSet<PhylogenyNode>();
7147 // query_nodes.add( new PhylogenyNode( "X" ) );
7148 // query_nodes.add( new PhylogenyNode( "Y" ) );
7149 // query_nodes.add( new PhylogenyNode( "D" ) );
7150 // query_nodes.add( new PhylogenyNode( "E" ) );
7151 // query_nodes.add( new PhylogenyNode( "F" ) );
7152 // query_nodes.add( new PhylogenyNode( "G" ) );
7153 // if ( !s0.match( query_nodes ) ) {
7157 // query_nodes = new HashSet<PhylogenyNode>();
7158 // query_nodes.add( new PhylogenyNode( "X" ) );
7159 // query_nodes.add( new PhylogenyNode( "Y" ) );
7160 // query_nodes.add( new PhylogenyNode( "A" ) );
7161 // query_nodes.add( new PhylogenyNode( "B" ) );
7162 // query_nodes.add( new PhylogenyNode( "C" ) );
7163 // query_nodes.add( new PhylogenyNode( "D" ) );
7164 // if ( !s0.match( query_nodes ) ) {
7168 // query_nodes = new HashSet<PhylogenyNode>();
7169 // query_nodes.add( new PhylogenyNode( "X" ) );
7170 // query_nodes.add( new PhylogenyNode( "Y" ) );
7171 // query_nodes.add( new PhylogenyNode( "E" ) );
7172 // query_nodes.add( new PhylogenyNode( "F" ) );
7173 // query_nodes.add( new PhylogenyNode( "G" ) );
7174 // if ( !s0.match( query_nodes ) ) {
7178 // query_nodes = new HashSet<PhylogenyNode>();
7179 // query_nodes.add( new PhylogenyNode( "X" ) );
7180 // query_nodes.add( new PhylogenyNode( "Y" ) );
7181 // query_nodes.add( new PhylogenyNode( "F" ) );
7182 // query_nodes.add( new PhylogenyNode( "G" ) );
7183 // if ( !s0.match( query_nodes ) ) {
7187 query_nodes = new HashSet<PhylogenyNode>();
7188 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7189 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7190 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7191 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7192 if ( s0.match( query_nodes ) ) {
7196 query_nodes = new HashSet<PhylogenyNode>();
7197 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7198 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7199 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7200 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7201 if ( s0.match( query_nodes ) ) {
7204 ///////////////////////////
7206 query_nodes = new HashSet<PhylogenyNode>();
7207 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7208 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7209 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7210 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7211 if ( s0.match( query_nodes ) ) {
7215 query_nodes = new HashSet<PhylogenyNode>();
7216 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7217 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7218 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7219 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7220 if ( s0.match( query_nodes ) ) {
7224 query_nodes = new HashSet<PhylogenyNode>();
7225 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7226 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7227 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7228 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7229 if ( s0.match( query_nodes ) ) {
7233 query_nodes = new HashSet<PhylogenyNode>();
7234 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7235 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7236 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7237 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7238 if ( s0.match( query_nodes ) ) {
7242 query_nodes = new HashSet<PhylogenyNode>();
7243 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7244 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7245 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7246 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7247 if ( s0.match( query_nodes ) ) {
7251 query_nodes = new HashSet<PhylogenyNode>();
7252 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7253 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7254 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7255 if ( s0.match( query_nodes ) ) {
7259 query_nodes = new HashSet<PhylogenyNode>();
7260 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7261 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7262 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7263 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7264 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7265 if ( s0.match( query_nodes ) ) {
7269 query_nodes = new HashSet<PhylogenyNode>();
7270 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7271 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7272 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7273 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7274 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7275 if ( s0.match( query_nodes ) ) {
7279 query_nodes = new HashSet<PhylogenyNode>();
7280 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7281 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7282 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7283 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7284 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7285 if ( s0.match( query_nodes ) ) {
7289 query_nodes = new HashSet<PhylogenyNode>();
7290 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7291 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7292 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7293 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7294 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7295 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7296 if ( s0.match( query_nodes ) ) {
7300 catch ( final Exception e ) {
7301 e.printStackTrace();
7307 private static boolean testSplitStrict() {
7309 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7310 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
7311 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
7312 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7313 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7314 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7315 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7316 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7317 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7318 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7319 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
7320 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
7321 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7322 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7323 if ( s0.match( query_nodes ) ) {
7326 query_nodes = new HashSet<PhylogenyNode>();
7327 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7328 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7329 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7330 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7331 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7332 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
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( "A" ) );
7340 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7341 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7342 if ( !s0.match( query_nodes ) ) {
7346 query_nodes = new HashSet<PhylogenyNode>();
7347 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7348 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7349 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7350 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7351 if ( !s0.match( query_nodes ) ) {
7355 query_nodes = new HashSet<PhylogenyNode>();
7356 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7357 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7358 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7359 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7360 if ( !s0.match( query_nodes ) ) {
7364 query_nodes = new HashSet<PhylogenyNode>();
7365 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7366 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7367 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7368 if ( !s0.match( query_nodes ) ) {
7372 query_nodes = new HashSet<PhylogenyNode>();
7373 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7374 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7375 if ( !s0.match( query_nodes ) ) {
7379 query_nodes = new HashSet<PhylogenyNode>();
7380 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7381 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7382 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7383 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7384 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7385 if ( !s0.match( query_nodes ) ) {
7389 query_nodes = new HashSet<PhylogenyNode>();
7390 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7391 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7392 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7393 if ( !s0.match( query_nodes ) ) {
7397 query_nodes = new HashSet<PhylogenyNode>();
7398 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7399 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7400 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7401 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7402 if ( !s0.match( query_nodes ) ) {
7406 query_nodes = new HashSet<PhylogenyNode>();
7407 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7408 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7409 if ( s0.match( query_nodes ) ) {
7413 query_nodes = new HashSet<PhylogenyNode>();
7414 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7415 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7416 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7417 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7418 if ( s0.match( query_nodes ) ) {
7422 query_nodes = new HashSet<PhylogenyNode>();
7423 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7424 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7425 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7426 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7427 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7428 if ( s0.match( query_nodes ) ) {
7432 query_nodes = new HashSet<PhylogenyNode>();
7433 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7434 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7435 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7436 if ( s0.match( query_nodes ) ) {
7440 query_nodes = new HashSet<PhylogenyNode>();
7441 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7442 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7443 if ( s0.match( query_nodes ) ) {
7447 query_nodes = new HashSet<PhylogenyNode>();
7448 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7449 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7450 if ( s0.match( query_nodes ) ) {
7454 query_nodes = new HashSet<PhylogenyNode>();
7455 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7456 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7457 if ( s0.match( query_nodes ) ) {
7461 query_nodes = new HashSet<PhylogenyNode>();
7462 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7463 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7464 if ( s0.match( query_nodes ) ) {
7468 query_nodes = new HashSet<PhylogenyNode>();
7469 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7470 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7471 if ( s0.match( query_nodes ) ) {
7475 query_nodes = new HashSet<PhylogenyNode>();
7476 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7477 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7478 if ( s0.match( query_nodes ) ) {
7482 query_nodes = new HashSet<PhylogenyNode>();
7483 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7484 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7485 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7486 if ( s0.match( query_nodes ) ) {
7490 query_nodes = new HashSet<PhylogenyNode>();
7491 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7492 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7493 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7494 if ( s0.match( query_nodes ) ) {
7498 query_nodes = new HashSet<PhylogenyNode>();
7499 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7500 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7501 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7502 if ( s0.match( query_nodes ) ) {
7506 query_nodes = new HashSet<PhylogenyNode>();
7507 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7508 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7509 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7510 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7511 if ( s0.match( query_nodes ) ) {
7515 catch ( final Exception e ) {
7516 e.printStackTrace();
7522 private static boolean testSubtreeDeletion() {
7524 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7525 final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
7526 t1.deleteSubtree( t1.getNode( "A" ), false );
7527 if ( t1.getNumberOfExternalNodes() != 5 ) {
7530 t1.toNewHampshireX();
7531 t1.deleteSubtree( t1.getNode( "E" ), false );
7532 if ( t1.getNumberOfExternalNodes() != 4 ) {
7535 t1.toNewHampshireX();
7536 t1.deleteSubtree( t1.getNode( "F" ), false );
7537 if ( t1.getNumberOfExternalNodes() != 3 ) {
7540 t1.toNewHampshireX();
7541 t1.deleteSubtree( t1.getNode( "D" ), false );
7542 t1.toNewHampshireX();
7543 if ( t1.getNumberOfExternalNodes() != 3 ) {
7546 t1.deleteSubtree( t1.getNode( "def" ), false );
7547 t1.toNewHampshireX();
7548 if ( t1.getNumberOfExternalNodes() != 2 ) {
7551 t1.deleteSubtree( t1.getNode( "B" ), false );
7552 t1.toNewHampshireX();
7553 if ( t1.getNumberOfExternalNodes() != 1 ) {
7556 t1.deleteSubtree( t1.getNode( "C" ), false );
7557 t1.toNewHampshireX();
7558 if ( t1.getNumberOfExternalNodes() != 1 ) {
7561 t1.deleteSubtree( t1.getNode( "abc" ), false );
7562 t1.toNewHampshireX();
7563 if ( t1.getNumberOfExternalNodes() != 1 ) {
7566 t1.deleteSubtree( t1.getNode( "r" ), false );
7567 if ( t1.getNumberOfExternalNodes() != 0 ) {
7570 if ( !t1.isEmpty() ) {
7573 final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
7574 t2.deleteSubtree( t2.getNode( "A" ), false );
7575 t2.toNewHampshireX();
7576 if ( t2.getNumberOfExternalNodes() != 5 ) {
7579 t2.deleteSubtree( t2.getNode( "abc" ), false );
7580 t2.toNewHampshireX();
7581 if ( t2.getNumberOfExternalNodes() != 3 ) {
7584 t2.deleteSubtree( t2.getNode( "def" ), false );
7585 t2.toNewHampshireX();
7586 if ( t2.getNumberOfExternalNodes() != 1 ) {
7590 catch ( final Exception e ) {
7591 e.printStackTrace( System.out );
7597 private static boolean testSupportCount() {
7599 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7600 final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
7601 final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
7602 + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
7603 + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
7604 + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
7605 + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
7607 SupportCount.count( t0_1, phylogenies_1, true, false );
7608 final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
7609 final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
7610 + "(((((A,B),C),D),E),((F,G),X))"
7611 + "(((((A,Y),B),C),D),((F,G),E))"
7612 + "(((((A,B),C),D),E),(F,G))"
7613 + "(((((A,B),C),D),E),(F,G))"
7614 + "(((((A,B),C),D),E),(F,G))"
7615 + "(((((A,B),C),D),E),(F,G),Z)"
7616 + "(((((A,B),C),D),E),(F,G))"
7617 + "((((((A,B),C),D),E),F),G)"
7618 + "(((((X,Y),F,G),E),((A,B),C)),D)",
7620 SupportCount.count( t0_2, phylogenies_2, true, false );
7621 final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
7622 while ( it.hasNext() ) {
7623 final PhylogenyNode n = it.next();
7624 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
7628 final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
7629 final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
7630 + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
7631 SupportCount.count( t0_3, phylogenies_3, true, false );
7632 t0_3.reRoot( t0_3.getNode( "def" ).getId() );
7633 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
7636 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
7639 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
7642 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
7645 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
7648 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
7651 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
7654 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
7657 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
7660 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
7663 final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7664 final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
7665 + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
7666 SupportCount.count( t0_4, phylogenies_4, true, false );
7667 t0_4.reRoot( t0_4.getNode( "F" ).getId() );
7668 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
7671 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
7674 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
7677 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
7680 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
7683 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
7686 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
7689 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
7692 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
7695 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
7698 Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7699 final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7700 double d = SupportCount.compare( b1, a, true, true, true );
7701 if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
7704 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7705 final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7706 d = SupportCount.compare( b2, a, true, true, true );
7707 if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
7710 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7711 final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
7712 d = SupportCount.compare( b3, a, true, true, true );
7713 if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
7716 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
7717 final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
7718 d = SupportCount.compare( b4, a, true, true, false );
7719 if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
7723 catch ( final Exception e ) {
7724 e.printStackTrace( System.out );
7730 private static boolean testSupportTransfer() {
7732 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7733 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)",
7734 new NHXParser() )[ 0 ];
7735 final Phylogeny p2 = factory
7736 .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 ];
7737 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
7740 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
7743 support_transfer.moveBranchLengthsToBootstrap( p1 );
7744 support_transfer.transferSupportValues( p1, p2 );
7745 if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
7748 if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
7751 if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
7754 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
7757 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
7760 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
7763 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
7766 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
7770 catch ( final Exception e ) {
7771 e.printStackTrace( System.out );
7777 private static boolean testUniprotTaxonomySearch() {
7779 List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
7781 if ( results.size() != 1 ) {
7784 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7787 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7790 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7793 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7796 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7800 results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
7801 if ( results.size() != 1 ) {
7804 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7807 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7810 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7813 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7816 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7820 results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
7821 if ( results.size() != 1 ) {
7824 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7827 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7830 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7833 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7836 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7840 results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
7841 if ( results.size() != 1 ) {
7844 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7847 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7850 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7853 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7856 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7859 if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
7862 if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
7865 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
7866 .equals( "Nematostella vectensis" ) ) {
7867 System.out.println( results.get( 0 ).getLineage() );
7871 catch ( final IOException e ) {
7872 System.out.println();
7873 System.out.println( "the following might be due to absence internet connection:" );
7874 e.printStackTrace( System.out );
7877 catch ( final Exception e ) {
7883 private static boolean testEmblEntryRetrieval() {
7884 //The format for GenBank Accession numbers are:
7885 //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
7886 //Protein: 3 letters + 5 numerals
7887 //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
7888 if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
7891 if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) {
7894 if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
7897 if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
7900 if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
7903 if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
7906 if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
7909 if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
7912 if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
7915 if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
7918 if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
7921 if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
7924 if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
7930 private static boolean testUniprotEntryRetrieval() {
7931 if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) {
7934 if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) {
7937 if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) {
7940 if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) {
7943 if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) {
7946 if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) {
7949 if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) {
7952 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) {
7955 if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) {
7958 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) {
7961 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) {
7964 if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) {
7967 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) {
7971 final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
7972 if ( !entry.getAccession().equals( "P12345" ) ) {
7975 if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
7978 if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
7981 if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) {
7984 if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
7988 catch ( final IOException e ) {
7989 System.out.println();
7990 System.out.println( "the following might be due to absence internet connection:" );
7991 e.printStackTrace( System.out );
7994 catch ( final Exception e ) {
8000 private static boolean testWabiTxSearch() {
8003 result = TxSearch.searchSimple( "nematostella" );
8004 result = TxSearch.getTxId( "nematostella" );
8005 if ( !result.equals( "45350" ) ) {
8008 result = TxSearch.getTxName( "45350" );
8009 if ( !result.equals( "Nematostella" ) ) {
8012 result = TxSearch.getTxId( "nematostella vectensis" );
8013 if ( !result.equals( "45351" ) ) {
8016 result = TxSearch.getTxName( "45351" );
8017 if ( !result.equals( "Nematostella vectensis" ) ) {
8020 result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
8021 if ( !result.equals( "536089" ) ) {
8024 result = TxSearch.getTxName( "536089" );
8025 if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
8028 final List<String> queries = new ArrayList<String>();
8029 queries.add( "Campylobacter coli" );
8030 queries.add( "Escherichia coli" );
8031 queries.add( "Arabidopsis" );
8032 queries.add( "Trichoplax" );
8033 queries.add( "Samanea saman" );
8034 queries.add( "Kluyveromyces marxianus" );
8035 queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
8036 queries.add( "Bornavirus parrot/PDD/2008" );
8037 final List<RANKS> ranks = new ArrayList<RANKS>();
8038 ranks.add( RANKS.SUPERKINGDOM );
8039 ranks.add( RANKS.KINGDOM );
8040 ranks.add( RANKS.FAMILY );
8041 ranks.add( RANKS.GENUS );
8042 ranks.add( RANKS.TRIBE );
8043 result = TxSearch.searchLineage( queries, ranks );
8044 result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
8045 result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
8047 catch ( final Exception e ) {
8048 System.out.println();
8049 System.out.println( "the following might be due to absence internet connection:" );
8050 e.printStackTrace( System.out );
8056 private static boolean testAminoAcidSequence() {
8058 final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
8059 if ( aa1.getLength() != 13 ) {
8062 if ( aa1.getResidueAt( 0 ) != 'A' ) {
8065 if ( aa1.getResidueAt( 2 ) != 'K' ) {
8068 if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
8071 final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
8072 if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
8075 final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
8076 if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
8079 final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
8080 if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
8084 catch ( final Exception e ) {
8085 e.printStackTrace();
8091 private static boolean testCreateBalancedPhylogeny() {
8093 final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
8094 if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
8097 if ( p0.getNumberOfExternalNodes() != 15625 ) {
8100 final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
8101 if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
8104 if ( p1.getNumberOfExternalNodes() != 100 ) {
8108 catch ( final Exception e ) {
8109 e.printStackTrace();
8115 private static boolean testFastaParser() {
8117 if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
8120 if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
8123 final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
8124 if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
8127 if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
8130 if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
8133 if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
8136 if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
8139 if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
8143 catch ( final Exception e ) {
8144 e.printStackTrace();
8150 private static boolean testGeneralMsaParser() {
8152 final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
8153 final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
8154 final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
8155 final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
8156 final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
8157 final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
8158 final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
8159 final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
8160 if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8163 if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8166 if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8169 if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8172 if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8175 if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8178 if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8181 if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8184 if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8187 if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8190 if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8193 if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8196 final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
8197 if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
8200 if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
8203 if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
8206 final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
8207 if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
8210 if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
8213 if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
8216 final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
8217 if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
8220 if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
8223 if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
8227 catch ( final Exception e ) {
8228 e.printStackTrace();
8234 private static boolean testMafft( final String path ) {
8236 final List<String> opts = new ArrayList<String>();
8237 opts.add( "--maxiterate" );
8239 opts.add( "--localpair" );
8240 opts.add( "--quiet" );
8242 final MsaInferrer mafft = Mafft.createInstance( path );
8243 msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
8244 if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
8247 if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
8251 catch ( final Exception e ) {
8252 e.printStackTrace( System.out );
8258 private static boolean testNextNodeWithCollapsing() {
8260 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8262 List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
8263 final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8264 final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
8265 t0.getNode( "cd" ).setCollapse( true );
8266 t0.getNode( "cde" ).setCollapse( true );
8267 n = t0.getFirstExternalNode();
8268 while ( n != null ) {
8270 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8272 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8275 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8278 if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
8281 if ( !ext.get( 3 ).getName().equals( "f" ) ) {
8284 if ( !ext.get( 4 ).getName().equals( "g" ) ) {
8287 if ( !ext.get( 5 ).getName().equals( "h" ) ) {
8291 final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8292 final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
8293 t1.getNode( "ab" ).setCollapse( true );
8294 t1.getNode( "cd" ).setCollapse( true );
8295 t1.getNode( "cde" ).setCollapse( true );
8296 n = t1.getNode( "ab" );
8297 ext = new ArrayList<PhylogenyNode>();
8298 while ( n != null ) {
8300 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8302 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8305 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8308 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
8311 if ( !ext.get( 3 ).getName().equals( "g" ) ) {
8314 if ( !ext.get( 4 ).getName().equals( "h" ) ) {
8320 final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8321 final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
8322 t2.getNode( "ab" ).setCollapse( true );
8323 t2.getNode( "cd" ).setCollapse( true );
8324 t2.getNode( "cde" ).setCollapse( true );
8325 t2.getNode( "c" ).setCollapse( true );
8326 t2.getNode( "d" ).setCollapse( true );
8327 t2.getNode( "e" ).setCollapse( true );
8328 t2.getNode( "gh" ).setCollapse( true );
8329 n = t2.getNode( "ab" );
8330 ext = new ArrayList<PhylogenyNode>();
8331 while ( n != null ) {
8333 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8335 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8338 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8341 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
8344 if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
8350 final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8351 final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
8352 t3.getNode( "ab" ).setCollapse( true );
8353 t3.getNode( "cd" ).setCollapse( true );
8354 t3.getNode( "cde" ).setCollapse( true );
8355 t3.getNode( "c" ).setCollapse( true );
8356 t3.getNode( "d" ).setCollapse( true );
8357 t3.getNode( "e" ).setCollapse( true );
8358 t3.getNode( "gh" ).setCollapse( true );
8359 t3.getNode( "fgh" ).setCollapse( true );
8360 n = t3.getNode( "ab" );
8361 ext = new ArrayList<PhylogenyNode>();
8362 while ( n != null ) {
8364 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8366 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8369 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8372 if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
8378 final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8379 final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
8380 t4.getNode( "ab" ).setCollapse( true );
8381 t4.getNode( "cd" ).setCollapse( true );
8382 t4.getNode( "cde" ).setCollapse( true );
8383 t4.getNode( "c" ).setCollapse( true );
8384 t4.getNode( "d" ).setCollapse( true );
8385 t4.getNode( "e" ).setCollapse( true );
8386 t4.getNode( "gh" ).setCollapse( true );
8387 t4.getNode( "fgh" ).setCollapse( true );
8388 t4.getNode( "abcdefgh" ).setCollapse( true );
8389 n = t4.getNode( "abcdefgh" );
8390 if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
8395 final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8396 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
8398 n = t5.getFirstExternalNode();
8399 while ( n != null ) {
8401 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8403 if ( ext.size() != 8 ) {
8406 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8409 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8412 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8415 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8418 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8421 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8424 if ( !ext.get( 6 ).getName().equals( "g" ) ) {
8427 if ( !ext.get( 7 ).getName().equals( "h" ) ) {
8432 final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8433 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
8435 t6.getNode( "ab" ).setCollapse( true );
8436 n = t6.getNode( "ab" );
8437 while ( n != null ) {
8439 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8441 if ( ext.size() != 7 ) {
8444 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8447 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8450 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8453 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8456 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8459 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8462 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8467 final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8468 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
8470 t7.getNode( "cd" ).setCollapse( true );
8471 n = t7.getNode( "a" );
8472 while ( n != null ) {
8474 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8476 if ( ext.size() != 7 ) {
8479 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8482 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8485 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
8488 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8491 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8494 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8497 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8502 final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8503 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
8505 t8.getNode( "cd" ).setCollapse( true );
8506 t8.getNode( "c" ).setCollapse( true );
8507 t8.getNode( "d" ).setCollapse( true );
8508 n = t8.getNode( "a" );
8509 while ( n != null ) {
8511 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8513 if ( ext.size() != 7 ) {
8516 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8519 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8522 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
8523 System.out.println( "2 fail" );
8526 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8529 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8532 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8535 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8540 final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8541 final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
8543 t9.getNode( "gh" ).setCollapse( true );
8544 n = t9.getNode( "a" );
8545 while ( n != null ) {
8547 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8549 if ( ext.size() != 7 ) {
8552 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8555 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8558 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8561 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8564 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8567 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8570 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
8575 final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8576 final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
8578 t10.getNode( "gh" ).setCollapse( true );
8579 t10.getNode( "g" ).setCollapse( true );
8580 t10.getNode( "h" ).setCollapse( true );
8581 n = t10.getNode( "a" );
8582 while ( n != null ) {
8584 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8586 if ( ext.size() != 7 ) {
8589 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8592 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8595 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8598 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8601 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8604 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8607 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
8612 final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8613 final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
8615 t11.getNode( "gh" ).setCollapse( true );
8616 t11.getNode( "fgh" ).setCollapse( true );
8617 n = t11.getNode( "a" );
8618 while ( n != null ) {
8620 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8622 if ( ext.size() != 6 ) {
8625 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8628 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8631 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8634 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8637 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8640 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8645 final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8646 final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
8648 t12.getNode( "gh" ).setCollapse( true );
8649 t12.getNode( "fgh" ).setCollapse( true );
8650 t12.getNode( "g" ).setCollapse( true );
8651 t12.getNode( "h" ).setCollapse( true );
8652 t12.getNode( "f" ).setCollapse( true );
8653 n = t12.getNode( "a" );
8654 while ( n != null ) {
8656 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8658 if ( ext.size() != 6 ) {
8661 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8664 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8667 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8670 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8673 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8676 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8681 final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8682 final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
8684 t13.getNode( "ab" ).setCollapse( true );
8685 t13.getNode( "b" ).setCollapse( true );
8686 t13.getNode( "fgh" ).setCollapse( true );
8687 t13.getNode( "gh" ).setCollapse( true );
8688 n = t13.getNode( "ab" );
8689 while ( n != null ) {
8691 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8693 if ( ext.size() != 5 ) {
8696 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8699 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8702 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8705 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8708 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
8713 final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
8714 final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
8716 t14.getNode( "ab" ).setCollapse( true );
8717 t14.getNode( "a" ).setCollapse( true );
8718 t14.getNode( "fgh" ).setCollapse( true );
8719 t14.getNode( "gh" ).setCollapse( true );
8720 n = t14.getNode( "ab" );
8721 while ( n != null ) {
8723 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8725 if ( ext.size() != 5 ) {
8728 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8731 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8734 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8737 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8740 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
8745 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" );
8746 final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
8748 t15.getNode( "ab" ).setCollapse( true );
8749 t15.getNode( "a" ).setCollapse( true );
8750 t15.getNode( "fgh" ).setCollapse( true );
8751 t15.getNode( "gh" ).setCollapse( true );
8752 n = t15.getNode( "ab" );
8753 while ( n != null ) {
8755 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8757 if ( ext.size() != 6 ) {
8760 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8763 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8766 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8769 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8772 if ( !ext.get( 4 ).getName().equals( "x" ) ) {
8775 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8780 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" );
8781 final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
8783 t16.getNode( "ab" ).setCollapse( true );
8784 t16.getNode( "a" ).setCollapse( true );
8785 t16.getNode( "fgh" ).setCollapse( true );
8786 t16.getNode( "gh" ).setCollapse( true );
8787 t16.getNode( "cd" ).setCollapse( true );
8788 t16.getNode( "cde" ).setCollapse( true );
8789 t16.getNode( "d" ).setCollapse( true );
8790 t16.getNode( "x" ).setCollapse( true );
8791 n = t16.getNode( "ab" );
8792 while ( n != null ) {
8794 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8796 if ( ext.size() != 4 ) {
8799 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8802 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8805 if ( !ext.get( 2 ).getName().equals( "x" ) ) {
8808 if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
8812 catch ( final Exception e ) {
8813 e.printStackTrace( System.out );
8819 private static boolean testMsaQualityMethod() {
8821 final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
8822 final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
8823 final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
8824 final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
8825 final List<Sequence> l = new ArrayList<Sequence>();
8830 final Msa msa = BasicMsa.createInstance( l );
8831 if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
8834 if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
8837 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
8840 if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
8844 catch ( final Exception e ) {
8845 e.printStackTrace( System.out );
8851 private static boolean testSequenceIdParsing() {
8853 Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
8854 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8855 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8857 System.out.println( "value =" + id.getValue() );
8858 System.out.println( "provider=" + id.getProvider() );
8863 id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
8864 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8865 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8867 System.out.println( "value =" + id.getValue() );
8868 System.out.println( "provider=" + id.getProvider() );
8873 id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
8874 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8875 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8877 System.out.println( "value =" + id.getValue() );
8878 System.out.println( "provider=" + id.getProvider() );
8883 id = SequenceIdParser.parse( "gb_AAA96518_1" );
8884 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8885 || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
8887 System.out.println( "value =" + id.getValue() );
8888 System.out.println( "provider=" + id.getProvider() );
8893 id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
8894 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8895 || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
8897 System.out.println( "value =" + id.getValue() );
8898 System.out.println( "provider=" + id.getProvider() );
8903 id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
8904 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8905 || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
8907 System.out.println( "value =" + id.getValue() );
8908 System.out.println( "provider=" + id.getProvider() );
8913 id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
8914 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8915 || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
8917 System.out.println( "value =" + id.getValue() );
8918 System.out.println( "provider=" + id.getProvider() );
8923 id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
8924 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8925 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
8927 System.out.println( "value =" + id.getValue() );
8928 System.out.println( "provider=" + id.getProvider() );
8933 id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
8934 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8935 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
8937 System.out.println( "value =" + id.getValue() );
8938 System.out.println( "provider=" + id.getProvider() );
8943 id = SequenceIdParser.parse( "P4A123" );
8944 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8945 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
8947 System.out.println( "value =" + id.getValue() );
8948 System.out.println( "provider=" + id.getProvider() );
8953 id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
8954 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8955 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
8957 System.out.println( "value =" + id.getValue() );
8958 System.out.println( "provider=" + id.getProvider() );
8963 id = SequenceIdParser.parse( "XP_12345" );
8965 System.out.println( "value =" + id.getValue() );
8966 System.out.println( "provider=" + id.getProvider() );
8969 // lcl_91970_unknown_
8971 catch ( final Exception e ) {
8972 e.printStackTrace( System.out );