04c868e9a1cc5a933d227a31329e57f0df05994f
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
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.
13 //
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.
18 //
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
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
25
26 package org.forester.test;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
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;
38 import java.util.Set;
39
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;
115
116 @SuppressWarnings( "unused")
117 public final class Test {
118
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;
133
134     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
135         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
136         return p;
137     }
138
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();
141     }
142
143     public static boolean isEqual( final double a, final double b ) {
144         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
145     }
146
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
150                 + "]" );
151         Locale.setDefault( Locale.US );
152         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
153         int failed = 0;
154         int succeeded = 0;
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.]" );
158         }
159         else {
160             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
161             System.out.println( "Testing aborted." );
162             System.exit( -1 );
163         }
164         System.out.print( "[Test if resources directory exists/is readable: " );
165         if ( testDir( PATH_TO_RESOURCES ) ) {
166             System.out.println( "OK.]" );
167         }
168         else {
169             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
170             System.out.println( "Testing aborted." );
171             System.exit( -1 );
172         }
173         final long start_time = new Date().getTime();
174         System.out.print( "Sequence id parsing: " );
175         if ( testSequenceIdParsing() ) {
176             System.out.println( "OK." );
177             succeeded++;
178         }
179         else {
180             System.out.println( "failed." );
181             failed++;
182         }
183         System.out.print( "Hmmscan output parser: " );
184         if ( testHmmscanOutputParser() ) {
185             System.out.println( "OK." );
186             succeeded++;
187         }
188         else {
189             System.out.println( "failed." );
190             failed++;
191         }
192         System.out.print( "Basic node methods: " );
193         if ( Test.testBasicNodeMethods() ) {
194             System.out.println( "OK." );
195             succeeded++;
196         }
197         else {
198             System.out.println( "failed." );
199             failed++;
200         }
201         System.out.print( "Taxonomy extraction: " );
202         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
203             System.out.println( "OK." );
204             succeeded++;
205         }
206         else {
207             System.out.println( "failed." );
208             failed++;
209         }
210         System.out.print( "Basic node construction and parsing of NHX (node level): " );
211         if ( Test.testNHXNodeParsing() ) {
212             System.out.println( "OK." );
213             succeeded++;
214         }
215         else {
216             System.out.println( "failed." );
217             failed++;
218         }
219         System.out.print( "NH parsing: " );
220         if ( Test.testNHParsing() ) {
221             System.out.println( "OK." );
222             succeeded++;
223         }
224         else {
225             System.out.println( "failed." );
226             failed++;
227         }
228         System.out.print( "Conversion to NHX (node level): " );
229         if ( Test.testNHXconversion() ) {
230             System.out.println( "OK." );
231             succeeded++;
232         }
233         else {
234             System.out.println( "failed." );
235             failed++;
236         }
237         System.out.print( "NHX parsing: " );
238         if ( Test.testNHXParsing() ) {
239             System.out.println( "OK." );
240             succeeded++;
241         }
242         else {
243             System.out.println( "failed." );
244             failed++;
245         }
246         System.out.print( "NHX parsing with quotes: " );
247         if ( Test.testNHXParsingQuotes() ) {
248             System.out.println( "OK." );
249             succeeded++;
250         }
251         else {
252             System.out.println( "failed." );
253             failed++;
254         }
255         System.out.print( "NHX parsing (MrBayes): " );
256         if ( Test.testNHXParsingMB() ) {
257             System.out.println( "OK." );
258             succeeded++;
259         }
260         else {
261             System.out.println( "failed." );
262             failed++;
263         }
264         System.out.print( "Nexus characters parsing: " );
265         if ( Test.testNexusCharactersParsing() ) {
266             System.out.println( "OK." );
267             succeeded++;
268         }
269         else {
270             System.out.println( "failed." );
271             failed++;
272         }
273         System.out.print( "Nexus tree parsing: " );
274         if ( Test.testNexusTreeParsing() ) {
275             System.out.println( "OK." );
276             succeeded++;
277         }
278         else {
279             System.out.println( "failed." );
280             failed++;
281         }
282         System.out.print( "Nexus tree parsing (translating): " );
283         if ( Test.testNexusTreeParsingTranslating() ) {
284             System.out.println( "OK." );
285             succeeded++;
286         }
287         else {
288             System.out.println( "failed." );
289             failed++;
290         }
291         System.out.print( "Nexus matrix parsing: " );
292         if ( Test.testNexusMatrixParsing() ) {
293             System.out.println( "OK." );
294             succeeded++;
295         }
296         else {
297             System.out.println( "failed." );
298             failed++;
299         }
300         System.out.print( "Basic phyloXML parsing: " );
301         if ( Test.testBasicPhyloXMLparsing() ) {
302             System.out.println( "OK." );
303             succeeded++;
304         }
305         else {
306             System.out.println( "failed." );
307             failed++;
308         }
309         System.out.print( "Basic phyloXML parsing (validating against schema): " );
310         if ( testBasicPhyloXMLparsingValidating() ) {
311             System.out.println( "OK." );
312             succeeded++;
313         }
314         else {
315             System.out.println( "failed." );
316             failed++;
317         }
318         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
319         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
320             System.out.println( "OK." );
321             succeeded++;
322         }
323         else {
324             System.out.println( "failed." );
325             failed++;
326         }
327         System.out.print( "phyloXML Distribution Element: " );
328         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
329             System.out.println( "OK." );
330             succeeded++;
331         }
332         else {
333             System.out.println( "failed." );
334             failed++;
335         }
336         System.out.print( "Tol XML parsing: " );
337         if ( Test.testBasicTolXMLparsing() ) {
338             System.out.println( "OK." );
339             succeeded++;
340         }
341         else {
342             System.out.println( "failed." );
343             failed++;
344         }
345         System.out.print( "Copying of node data: " );
346         if ( Test.testCopyOfNodeData() ) {
347             System.out.println( "OK." );
348             succeeded++;
349         }
350         else {
351             System.out.println( "failed." );
352             failed++;
353         }
354         System.out.print( "Basic tree methods: " );
355         if ( Test.testBasicTreeMethods() ) {
356             System.out.println( "OK." );
357             succeeded++;
358         }
359         else {
360             System.out.println( "failed." );
361             failed++;
362         }
363         System.out.print( "Postorder Iterator: " );
364         if ( Test.testPostOrderIterator() ) {
365             System.out.println( "OK." );
366             succeeded++;
367         }
368         else {
369             System.out.println( "failed." );
370             failed++;
371         }
372         System.out.print( "Preorder Iterator: " );
373         if ( Test.testPreOrderIterator() ) {
374             System.out.println( "OK." );
375             succeeded++;
376         }
377         else {
378             System.out.println( "failed." );
379             failed++;
380         }
381         System.out.print( "Levelorder Iterator: " );
382         if ( Test.testLevelOrderIterator() ) {
383             System.out.println( "OK." );
384             succeeded++;
385         }
386         else {
387             System.out.println( "failed." );
388             failed++;
389         }
390         System.out.print( "Re-id methods: " );
391         if ( Test.testReIdMethods() ) {
392             System.out.println( "OK." );
393             succeeded++;
394         }
395         else {
396             System.out.println( "failed." );
397             failed++;
398         }
399         System.out.print( "Methods on last external nodes: " );
400         if ( Test.testLastExternalNodeMethods() ) {
401             System.out.println( "OK." );
402             succeeded++;
403         }
404         else {
405             System.out.println( "failed." );
406             failed++;
407         }
408         System.out.print( "Methods on external nodes: " );
409         if ( Test.testExternalNodeRelatedMethods() ) {
410             System.out.println( "OK." );
411             succeeded++;
412         }
413         else {
414             System.out.println( "failed." );
415             failed++;
416         }
417         System.out.print( "Deletion of external nodes: " );
418         if ( Test.testDeletionOfExternalNodes() ) {
419             System.out.println( "OK." );
420             succeeded++;
421         }
422         else {
423             System.out.println( "failed." );
424             failed++;
425         }
426         System.out.print( "Subtree deletion: " );
427         if ( Test.testSubtreeDeletion() ) {
428             System.out.println( "OK." );
429             succeeded++;
430         }
431         else {
432             System.out.println( "failed." );
433             failed++;
434         }
435         System.out.print( "Phylogeny branch: " );
436         if ( Test.testPhylogenyBranch() ) {
437             System.out.println( "OK." );
438             succeeded++;
439         }
440         else {
441             System.out.println( "failed." );
442             failed++;
443         }
444         System.out.print( "Rerooting: " );
445         if ( Test.testRerooting() ) {
446             System.out.println( "OK." );
447             succeeded++;
448         }
449         else {
450             System.out.println( "failed." );
451             failed++;
452         }
453         System.out.print( "Mipoint rooting: " );
454         if ( Test.testMidpointrooting() ) {
455             System.out.println( "OK." );
456             succeeded++;
457         }
458         else {
459             System.out.println( "failed." );
460             failed++;
461         }
462         System.out.print( "Node removal: " );
463         if ( Test.testNodeRemoval() ) {
464             System.out.println( "OK." );
465             succeeded++;
466         }
467         else {
468             System.out.println( "failed." );
469             failed++;
470         }
471         System.out.print( "Support count: " );
472         if ( Test.testSupportCount() ) {
473             System.out.println( "OK." );
474             succeeded++;
475         }
476         else {
477             System.out.println( "failed." );
478             failed++;
479         }
480         System.out.print( "Support transfer: " );
481         if ( Test.testSupportTransfer() ) {
482             System.out.println( "OK." );
483             succeeded++;
484         }
485         else {
486             System.out.println( "failed." );
487             failed++;
488         }
489         System.out.print( "Finding of LCA: " );
490         if ( Test.testGetLCA() ) {
491             System.out.println( "OK." );
492             succeeded++;
493         }
494         else {
495             System.out.println( "failed." );
496             failed++;
497         }
498         System.out.print( "Finding of LCA 2: " );
499         if ( Test.testGetLCA2() ) {
500             System.out.println( "OK." );
501             succeeded++;
502         }
503         else {
504             System.out.println( "failed." );
505             failed++;
506         }
507         System.out.print( "Calculation of distance between nodes: " );
508         if ( Test.testGetDistance() ) {
509             System.out.println( "OK." );
510             succeeded++;
511         }
512         else {
513             System.out.println( "failed." );
514             failed++;
515         }
516         System.out.print( "Descriptive statistics: " );
517         if ( Test.testDescriptiveStatistics() ) {
518             System.out.println( "OK." );
519             succeeded++;
520         }
521         else {
522             System.out.println( "failed." );
523             failed++;
524         }
525         System.out.print( "Data objects and methods: " );
526         if ( Test.testDataObjects() ) {
527             System.out.println( "OK." );
528             succeeded++;
529         }
530         else {
531             System.out.println( "failed." );
532             failed++;
533         }
534         System.out.print( "Properties map: " );
535         if ( Test.testPropertiesMap() ) {
536             System.out.println( "OK." );
537             succeeded++;
538         }
539         else {
540             System.out.println( "failed." );
541             failed++;
542         }
543         System.out.print( "SDIse: " );
544         if ( Test.testSDIse() ) {
545             System.out.println( "OK." );
546             succeeded++;
547         }
548         else {
549             System.out.println( "failed." );
550             failed++;
551         }
552         System.out.print( "SDIunrooted: " );
553         if ( Test.testSDIunrooted() ) {
554             System.out.println( "OK." );
555             succeeded++;
556         }
557         else {
558             System.out.println( "failed." );
559             failed++;
560         }
561         System.out.print( "GSDI: " );
562         if ( TestGSDI.test() ) {
563             System.out.println( "OK." );
564             succeeded++;
565         }
566         else {
567             System.out.println( "failed." );
568             failed++;
569         }
570         System.out.print( "RIO: " );
571         if ( TestRIO.test() ) {
572             System.out.println( "OK." );
573             succeeded++;
574         }
575         else {
576             System.out.println( "failed." );
577             failed++;
578         }
579         System.out.print( "Phylogeny reconstruction:" );
580         System.out.println();
581         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
582             System.out.println( "OK." );
583             succeeded++;
584         }
585         else {
586             System.out.println( "failed." );
587             failed++;
588         }
589         System.out.print( "Analysis of domain architectures: " );
590         System.out.println();
591         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
592             System.out.println( "OK." );
593             succeeded++;
594         }
595         else {
596             System.out.println( "failed." );
597             failed++;
598         }
599         System.out.print( "GO: " );
600         System.out.println();
601         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
602             System.out.println( "OK." );
603             succeeded++;
604         }
605         else {
606             System.out.println( "failed." );
607             failed++;
608         }
609         System.out.print( "Modeling tools: " );
610         if ( TestPccx.test() ) {
611             System.out.println( "OK." );
612             succeeded++;
613         }
614         else {
615             System.out.println( "failed." );
616             failed++;
617         }
618         System.out.print( "Split Matrix strict: " );
619         if ( Test.testSplitStrict() ) {
620             System.out.println( "OK." );
621             succeeded++;
622         }
623         else {
624             System.out.println( "failed." );
625             failed++;
626         }
627         System.out.print( "Split Matrix: " );
628         if ( Test.testSplit() ) {
629             System.out.println( "OK." );
630             succeeded++;
631         }
632         else {
633             System.out.println( "failed." );
634             failed++;
635         }
636         System.out.print( "Confidence Assessor: " );
637         if ( Test.testConfidenceAssessor() ) {
638             System.out.println( "OK." );
639             succeeded++;
640         }
641         else {
642             System.out.println( "failed." );
643             failed++;
644         }
645         System.out.print( "Basic table: " );
646         if ( Test.testBasicTable() ) {
647             System.out.println( "OK." );
648             succeeded++;
649         }
650         else {
651             System.out.println( "failed." );
652             failed++;
653         }
654         System.out.print( "General table: " );
655         if ( Test.testGeneralTable() ) {
656             System.out.println( "OK." );
657             succeeded++;
658         }
659         else {
660             System.out.println( "failed." );
661             failed++;
662         }
663         System.out.print( "Amino acid sequence: " );
664         if ( Test.testAminoAcidSequence() ) {
665             System.out.println( "OK." );
666             succeeded++;
667         }
668         else {
669             System.out.println( "failed." );
670             failed++;
671         }
672         System.out.print( "General MSA parser: " );
673         if ( Test.testGeneralMsaParser() ) {
674             System.out.println( "OK." );
675             succeeded++;
676         }
677         else {
678             System.out.println( "failed." );
679             failed++;
680         }
681         System.out.print( "Fasta parser for msa: " );
682         if ( Test.testFastaParser() ) {
683             System.out.println( "OK." );
684             succeeded++;
685         }
686         else {
687             System.out.println( "failed." );
688             failed++;
689         }
690         System.out.print( "Creation of balanced phylogeny: " );
691         if ( Test.testCreateBalancedPhylogeny() ) {
692             System.out.println( "OK." );
693             succeeded++;
694         }
695         else {
696             System.out.println( "failed." );
697             failed++;
698         }
699         System.out.print( "EMBL Entry Retrieval: " );
700         if ( Test.testEmblEntryRetrieval() ) {
701             System.out.println( "OK." );
702             succeeded++;
703         }
704         else {
705             System.out.println( "failed." );
706             failed++;
707         }
708         System.out.print( "Uniprot Entry Retrieval: " );
709         if ( Test.testUniprotEntryRetrieval() ) {
710             System.out.println( "OK." );
711             succeeded++;
712         }
713         else {
714             System.out.println( "failed." );
715             failed++;
716         }
717         System.out.print( "Uniprot Taxonomy Search: " );
718         if ( Test.testUniprotTaxonomySearch() ) {
719             System.out.println( "OK." );
720             succeeded++;
721         }
722         else {
723             System.out.println( "failed." );
724             failed++;
725         }
726         //----
727         String path = "";
728         final String os = ForesterUtil.OS_NAME.toLowerCase();
729         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
730             path = "/usr/local/bin/mafft";
731         }
732         else if ( os.indexOf( "win" ) >= 0 ) {
733             path = "C:\\Program Files\\mafft-win\\mafft.bat";
734         }
735         else {
736             path = "/home/czmasek/bin/mafft";
737         }
738         if ( !MsaInferrer.isInstalled( path ) ) {
739             path = "mafft";
740         }
741         if ( !MsaInferrer.isInstalled( path ) ) {
742             path = "/usr/local/bin/mafft";
743         }
744         if ( MsaInferrer.isInstalled( path ) ) {
745             System.out.print( "MAFFT (external program): " );
746             if ( Test.testMafft( path ) ) {
747                 System.out.println( "OK." );
748                 succeeded++;
749             }
750             else {
751                 System.out.println( "failed [will not count towards failed tests]" );
752             }
753         }
754         //----
755         System.out.print( "Next nodes with collapsed: " );
756         if ( Test.testNextNodeWithCollapsing() ) {
757             System.out.println( "OK." );
758             succeeded++;
759         }
760         else {
761             System.out.println( "failed." );
762             failed++;
763         }
764         System.out.print( "Simple MSA quality: " );
765         if ( Test.testMsaQualityMethod() ) {
766             System.out.println( "OK." );
767             succeeded++;
768         }
769         else {
770             System.out.println( "failed." );
771             failed++;
772         }
773         System.out.println();
774         final Runtime rt = java.lang.Runtime.getRuntime();
775         final long free_memory = rt.freeMemory() / 1000000;
776         final long total_memory = rt.totalMemory() / 1000000;
777         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
778                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
779         System.out.println();
780         System.out.println( "Successful tests: " + succeeded );
781         System.out.println( "Failed     tests: " + failed );
782         System.out.println();
783         if ( failed < 1 ) {
784             System.out.println( "OK." );
785         }
786         else {
787             System.out.println( "Not OK." );
788         }
789     }
790
791     private static boolean testExtractTaxonomyCodeFromNodeName() {
792         try {
793             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.YES ).equals( "MOUSE" ) ) {
794                 return false;
795             }
796             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.YES ).equals( "RAT" ) ) {
797                 return false;
798             }
799             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.YES ) != null ) {
800                 return false;
801             }
802             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445", TAXONOMY_EXTRACTION.YES )
803                     .equals( "MOUSE" ) ) {
804                 return false;
805             }
806             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE_function = 23445", TAXONOMY_EXTRACTION.YES )
807                     .equals( "MOUSE" ) ) {
808                 return false;
809             }
810             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445", TAXONOMY_EXTRACTION.YES )
811                     .equals( "MOUSE" ) ) {
812                 return false;
813             }
814             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
815                 return false;
816             }
817             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
818                 return false;
819             }
820             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445", TAXONOMY_EXTRACTION.YES )
821                     .equals( "RAT" ) ) {
822                 return false;
823             }
824             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445", TAXONOMY_EXTRACTION.YES )
825                     .equals( "RAT" ) ) {
826                 return false;
827             }
828             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445", TAXONOMY_EXTRACTION.YES )
829                     .equals( "RAT" ) ) {
830                 return false;
831             }
832             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
833                 return false;
834             }
835             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445", TAXONOMY_EXTRACTION.YES ) != null ) {
836                 return false;
837             }
838             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.YES ).equals( "RAT" ) ) {
839                 return false;
840             }
841             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY )
842                     .equals( "PIG" ) ) {
843                 return false;
844             }
845             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.YES )
846                     .equals( "MOUSE" ) ) {
847                 return false;
848             }
849             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY )
850                     .equals( "MOUSE" ) ) {
851                 return false;
852             }
853         }
854         catch ( final Exception e ) {
855             e.printStackTrace( System.out );
856             return false;
857         }
858         return true;
859     }
860
861     private static boolean testBasicNodeMethods() {
862         try {
863             if ( PhylogenyNode.getNodeCount() != 0 ) {
864                 return false;
865             }
866             final PhylogenyNode n1 = new PhylogenyNode();
867             final PhylogenyNode n2 = PhylogenyNode
868                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
869             final PhylogenyNode n3 = PhylogenyNode
870                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
871             final PhylogenyNode n4 = PhylogenyNode
872                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
873             if ( n1.isHasAssignedEvent() ) {
874                 return false;
875             }
876             if ( PhylogenyNode.getNodeCount() != 4 ) {
877                 return false;
878             }
879             if ( n3.getIndicator() != 0 ) {
880                 return false;
881             }
882             if ( n3.getNumberOfExternalNodes() != 1 ) {
883                 return false;
884             }
885             if ( !n3.isExternal() ) {
886                 return false;
887             }
888             if ( !n3.isRoot() ) {
889                 return false;
890             }
891             if ( !n4.getName().equals( "n4" ) ) {
892                 return false;
893             }
894         }
895         catch ( final Exception e ) {
896             e.printStackTrace( System.out );
897             return false;
898         }
899         return true;
900     }
901
902     private static boolean testBasicPhyloXMLparsing() {
903         try {
904             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
905             final PhyloXmlParser xml_parser = new PhyloXmlParser();
906             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
907                                                               xml_parser );
908             if ( xml_parser.getErrorCount() > 0 ) {
909                 System.out.println( xml_parser.getErrorMessages().toString() );
910                 return false;
911             }
912             if ( phylogenies_0.length != 4 ) {
913                 return false;
914             }
915             final Phylogeny t1 = phylogenies_0[ 0 ];
916             final Phylogeny t2 = phylogenies_0[ 1 ];
917             final Phylogeny t3 = phylogenies_0[ 2 ];
918             final Phylogeny t4 = phylogenies_0[ 3 ];
919             if ( t1.getNumberOfExternalNodes() != 1 ) {
920                 return false;
921             }
922             if ( !t1.isRooted() ) {
923                 return false;
924             }
925             if ( t1.isRerootable() ) {
926                 return false;
927             }
928             if ( !t1.getType().equals( "gene_tree" ) ) {
929                 return false;
930             }
931             if ( t2.getNumberOfExternalNodes() != 2 ) {
932                 return false;
933             }
934             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
935                 return false;
936             }
937             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
938                 return false;
939             }
940             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
941                 return false;
942             }
943             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
944                 return false;
945             }
946             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
947                 return false;
948             }
949             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
950                 return false;
951             }
952             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
953                     .startsWith( "actgtgggggt" ) ) {
954                 return false;
955             }
956             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
957                     .startsWith( "ctgtgatgcat" ) ) {
958                 return false;
959             }
960             if ( t3.getNumberOfExternalNodes() != 4 ) {
961                 return false;
962             }
963             if ( !t1.getName().equals( "t1" ) ) {
964                 return false;
965             }
966             if ( !t2.getName().equals( "t2" ) ) {
967                 return false;
968             }
969             if ( !t3.getName().equals( "t3" ) ) {
970                 return false;
971             }
972             if ( !t4.getName().equals( "t4" ) ) {
973                 return false;
974             }
975             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
976                 return false;
977             }
978             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
979                 return false;
980             }
981             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
982                 return false;
983             }
984             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
985                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
986                 return false;
987             }
988             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
989                 return false;
990             }
991             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
992                 return false;
993             }
994             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
995                 return false;
996             }
997             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
998                     .equals( "apoptosis" ) ) {
999                 return false;
1000             }
1001             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1002                     .equals( "GO:0006915" ) ) {
1003                 return false;
1004             }
1005             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1006                     .equals( "UniProtKB" ) ) {
1007                 return false;
1008             }
1009             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1010                     .equals( "experimental" ) ) {
1011                 return false;
1012             }
1013             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1014                     .equals( "function" ) ) {
1015                 return false;
1016             }
1017             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1018                     .getValue() != 1 ) {
1019                 return false;
1020             }
1021             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1022                     .getType().equals( "ml" ) ) {
1023                 return false;
1024             }
1025             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1026                     .equals( "apoptosis" ) ) {
1027                 return false;
1028             }
1029             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1030                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1031                 return false;
1032             }
1033             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1034                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1035                 return false;
1036             }
1037             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1038                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1039                 return false;
1040             }
1041             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1042                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1043                 return false;
1044             }
1045             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1046                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1047                 return false;
1048             }
1049             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1050                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1051                 return false;
1052             }
1053             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1054                     .equals( "GO:0005829" ) ) {
1055                 return false;
1056             }
1057             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1058                     .equals( "intracellular organelle" ) ) {
1059                 return false;
1060             }
1061             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1062                 return false;
1063             }
1064             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1065                     .equals( "UniProt link" ) ) ) {
1066                 return false;
1067             }
1068             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1069                 return false;
1070             }
1071         }
1072         catch ( final Exception e ) {
1073             e.printStackTrace( System.out );
1074             return false;
1075         }
1076         return true;
1077     }
1078
1079     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1080         try {
1081             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1082             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1083             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1084                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1085             }
1086             else {
1087                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1088             }
1089             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1090                                                               xml_parser );
1091             if ( xml_parser.getErrorCount() > 0 ) {
1092                 System.out.println( xml_parser.getErrorMessages().toString() );
1093                 return false;
1094             }
1095             if ( phylogenies_0.length != 4 ) {
1096                 return false;
1097             }
1098             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1099             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1100             if ( phylogenies_t1.length != 1 ) {
1101                 return false;
1102             }
1103             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1104             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1105                 return false;
1106             }
1107             if ( !t1_rt.isRooted() ) {
1108                 return false;
1109             }
1110             if ( t1_rt.isRerootable() ) {
1111                 return false;
1112             }
1113             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1114                 return false;
1115             }
1116             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1117             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1118             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1119             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1120                 return false;
1121             }
1122             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1123                 return false;
1124             }
1125             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1126                 return false;
1127             }
1128             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1129                 return false;
1130             }
1131             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1132                     .startsWith( "actgtgggggt" ) ) {
1133                 return false;
1134             }
1135             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1136                     .startsWith( "ctgtgatgcat" ) ) {
1137                 return false;
1138             }
1139             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1140             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1141             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1142             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1143             if ( phylogenies_1.length != 1 ) {
1144                 return false;
1145             }
1146             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1147             if ( !t3_rt.getName().equals( "t3" ) ) {
1148                 return false;
1149             }
1150             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1151                 return false;
1152             }
1153             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1154                 return false;
1155             }
1156             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1157                 return false;
1158             }
1159             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1160                 return false;
1161             }
1162             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1163                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1164                 return false;
1165             }
1166             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1167                 return false;
1168             }
1169             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1170                 return false;
1171             }
1172             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1173                     .equals( "UniProtKB" ) ) {
1174                 return false;
1175             }
1176             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1177                     .equals( "apoptosis" ) ) {
1178                 return false;
1179             }
1180             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1181                     .equals( "GO:0006915" ) ) {
1182                 return false;
1183             }
1184             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1185                     .equals( "UniProtKB" ) ) {
1186                 return false;
1187             }
1188             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1189                     .equals( "experimental" ) ) {
1190                 return false;
1191             }
1192             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1193                     .equals( "function" ) ) {
1194                 return false;
1195             }
1196             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1197                     .getValue() != 1 ) {
1198                 return false;
1199             }
1200             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1201                     .getType().equals( "ml" ) ) {
1202                 return false;
1203             }
1204             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1205                     .equals( "apoptosis" ) ) {
1206                 return false;
1207             }
1208             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1209                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1210                 return false;
1211             }
1212             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1213                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1214                 return false;
1215             }
1216             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1217                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1218                 return false;
1219             }
1220             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1221                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1222                 return false;
1223             }
1224             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1225                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1226                 return false;
1227             }
1228             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1229                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1230                 return false;
1231             }
1232             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1233                     .equals( "GO:0005829" ) ) {
1234                 return false;
1235             }
1236             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1237                     .equals( "intracellular organelle" ) ) {
1238                 return false;
1239             }
1240             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1241                 return false;
1242             }
1243             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1244                     .equals( "UniProt link" ) ) ) {
1245                 return false;
1246             }
1247             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1248                 return false;
1249             }
1250             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1251                 return false;
1252             }
1253             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1254                     .equals( "Aguinaldo, A. M. A.; J. M. Turbeville, L. S. Linford, M. C. Rivera, J. R. Garey, R. A. Raff, & J. A. Lake (1997). \"Evidence for a clade of nematodes, arthropods and other moulting animals\". Nature 387 (6632): 489–493." ) ) ) {
1255                 return false;
1256             }
1257             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1258                 return false;
1259             }
1260             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1261                 return false;
1262             }
1263             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1264                 return false;
1265             }
1266             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1267                 return false;
1268             }
1269             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1270                     .equals( "ncbi" ) ) {
1271                 return false;
1272             }
1273             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1274                 return false;
1275             }
1276             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1277                     .getName().equals( "B" ) ) {
1278                 return false;
1279             }
1280             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1281                     .getFrom() != 21 ) {
1282                 return false;
1283             }
1284             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1285                 return false;
1286             }
1287             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1288                     .getLength() != 24 ) {
1289                 return false;
1290             }
1291             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1292                     .getConfidence() != 2144 ) {
1293                 return false;
1294             }
1295             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1296                     .equals( "pfam" ) ) {
1297                 return false;
1298             }
1299             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1300                 return false;
1301             }
1302             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1303                 return false;
1304             }
1305             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1306                 return false;
1307             }
1308             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1309                 return false;
1310             }
1311             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1312             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1313                 return false;
1314             }
1315             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1316                 return false;
1317             }
1318             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1319                 return false;
1320             }
1321             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1322                 return false;
1323             }
1324             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1325                 return false;
1326             }
1327             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1328                 return false;
1329             }
1330             if ( taxbb.getSynonyms().size() != 2 ) {
1331                 return false;
1332             }
1333             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1334                 return false;
1335             }
1336             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1337                 return false;
1338             }
1339             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1340                 return false;
1341             }
1342             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1343                 return false;
1344             }
1345             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1346                 return false;
1347             }
1348             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1349                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1350                 ;
1351                 return false;
1352             }
1353             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1354                 return false;
1355             }
1356             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1357                 return false;
1358             }
1359             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1360                 return false;
1361             }
1362             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1363                 return false;
1364             }
1365             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1366                 return false;
1367             }
1368             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1369                 return false;
1370             }
1371             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1372                 return false;
1373             }
1374             //
1375             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1376                 return false;
1377             }
1378             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1379                     .equalsIgnoreCase( "435" ) ) {
1380                 return false;
1381             }
1382             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1383                 return false;
1384             }
1385             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1386                     .equalsIgnoreCase( "443.7" ) ) {
1387                 return false;
1388             }
1389             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1390                 return false;
1391             }
1392             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1393                 return false;
1394             }
1395             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1396                     .equalsIgnoreCase( "433" ) ) {
1397                 return false;
1398             }
1399         }
1400         catch ( final Exception e ) {
1401             e.printStackTrace( System.out );
1402             return false;
1403         }
1404         return true;
1405     }
1406
1407     private static boolean testBasicPhyloXMLparsingValidating() {
1408         try {
1409             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1410             PhyloXmlParser xml_parser = null;
1411             try {
1412                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1413             }
1414             catch ( final Exception e ) {
1415                 // Do nothing -- means were not running from jar.
1416             }
1417             if ( xml_parser == null ) {
1418                 xml_parser = new PhyloXmlParser();
1419                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1420                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1421                 }
1422                 else {
1423                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1424                 }
1425             }
1426             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1427                                                               xml_parser );
1428             if ( xml_parser.getErrorCount() > 0 ) {
1429                 System.out.println( xml_parser.getErrorMessages().toString() );
1430                 return false;
1431             }
1432             if ( phylogenies_0.length != 4 ) {
1433                 return false;
1434             }
1435             final Phylogeny t1 = phylogenies_0[ 0 ];
1436             final Phylogeny t2 = phylogenies_0[ 1 ];
1437             final Phylogeny t3 = phylogenies_0[ 2 ];
1438             final Phylogeny t4 = phylogenies_0[ 3 ];
1439             if ( !t1.getName().equals( "t1" ) ) {
1440                 return false;
1441             }
1442             if ( !t2.getName().equals( "t2" ) ) {
1443                 return false;
1444             }
1445             if ( !t3.getName().equals( "t3" ) ) {
1446                 return false;
1447             }
1448             if ( !t4.getName().equals( "t4" ) ) {
1449                 return false;
1450             }
1451             if ( t1.getNumberOfExternalNodes() != 1 ) {
1452                 return false;
1453             }
1454             if ( t2.getNumberOfExternalNodes() != 2 ) {
1455                 return false;
1456             }
1457             if ( t3.getNumberOfExternalNodes() != 4 ) {
1458                 return false;
1459             }
1460             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1461             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1462             if ( xml_parser.getErrorCount() > 0 ) {
1463                 System.out.println( "errors:" );
1464                 System.out.println( xml_parser.getErrorMessages().toString() );
1465                 return false;
1466             }
1467             if ( phylogenies_1.length != 4 ) {
1468                 return false;
1469             }
1470             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1471                                                               xml_parser );
1472             if ( xml_parser.getErrorCount() > 0 ) {
1473                 System.out.println( "errors:" );
1474                 System.out.println( xml_parser.getErrorMessages().toString() );
1475                 return false;
1476             }
1477             if ( phylogenies_2.length != 1 ) {
1478                 return false;
1479             }
1480             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1481                 return false;
1482             }
1483             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1484                                                               xml_parser );
1485             if ( xml_parser.getErrorCount() > 0 ) {
1486                 System.out.println( xml_parser.getErrorMessages().toString() );
1487                 return false;
1488             }
1489             if ( phylogenies_3.length != 2 ) {
1490                 return false;
1491             }
1492             final Phylogeny a = phylogenies_3[ 0 ];
1493             if ( !a.getName().equals( "tree 4" ) ) {
1494                 return false;
1495             }
1496             if ( a.getNumberOfExternalNodes() != 3 ) {
1497                 return false;
1498             }
1499             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1500                 return false;
1501             }
1502             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1503                 return false;
1504             }
1505             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1506                                                               xml_parser );
1507             if ( xml_parser.getErrorCount() > 0 ) {
1508                 System.out.println( xml_parser.getErrorMessages().toString() );
1509                 return false;
1510             }
1511             if ( phylogenies_4.length != 1 ) {
1512                 return false;
1513             }
1514             final Phylogeny s = phylogenies_4[ 0 ];
1515             if ( s.getNumberOfExternalNodes() != 6 ) {
1516                 return false;
1517             }
1518             s.getNode( "first" );
1519             s.getNode( "<>" );
1520             s.getNode( "\"<a'b&c'd\">\"" );
1521             s.getNode( "'''\"" );
1522             s.getNode( "\"\"\"" );
1523             s.getNode( "dick & doof" );
1524         }
1525         catch ( final Exception e ) {
1526             e.printStackTrace( System.out );
1527             return false;
1528         }
1529         return true;
1530     }
1531
1532     private static boolean testBasicTable() {
1533         try {
1534             final BasicTable<String> t0 = new BasicTable<String>();
1535             if ( t0.getNumberOfColumns() != 0 ) {
1536                 return false;
1537             }
1538             if ( t0.getNumberOfRows() != 0 ) {
1539                 return false;
1540             }
1541             t0.setValue( 3, 2, "23" );
1542             t0.setValue( 10, 1, "error" );
1543             t0.setValue( 10, 1, "110" );
1544             t0.setValue( 9, 1, "19" );
1545             t0.setValue( 1, 10, "101" );
1546             t0.setValue( 10, 10, "1010" );
1547             t0.setValue( 100, 10, "10100" );
1548             t0.setValue( 0, 0, "00" );
1549             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1550                 return false;
1551             }
1552             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1553                 return false;
1554             }
1555             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1556                 return false;
1557             }
1558             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1559                 return false;
1560             }
1561             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1562                 return false;
1563             }
1564             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1565                 return false;
1566             }
1567             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1568                 return false;
1569             }
1570             if ( t0.getNumberOfColumns() != 101 ) {
1571                 return false;
1572             }
1573             if ( t0.getNumberOfRows() != 11 ) {
1574                 return false;
1575             }
1576             if ( t0.getValueAsString( 49, 4 ) != null ) {
1577                 return false;
1578             }
1579             final String l = ForesterUtil.getLineSeparator();
1580             final StringBuffer source = new StringBuffer();
1581             source.append( "" + l );
1582             source.append( "# 1 1 1 1 1 1 1 1" + l );
1583             source.append( " 00 01 02 03" + l );
1584             source.append( "   10 11 12 13  " + l );
1585             source.append( "20 21 22 23 " + l );
1586             source.append( "    30  31    32 33" + l );
1587             source.append( "40 41 42 43" + l );
1588             source.append( "  # 1 1 1 1 1 " + l );
1589             source.append( "50 51 52 53 54" + l );
1590             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), " " );
1591             if ( t1.getNumberOfColumns() != 5 ) {
1592                 return false;
1593             }
1594             if ( t1.getNumberOfRows() != 6 ) {
1595                 return false;
1596             }
1597             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1598                 return false;
1599             }
1600             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1601                 return false;
1602             }
1603             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1604                 return false;
1605             }
1606             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1607                 return false;
1608             }
1609             final StringBuffer source1 = new StringBuffer();
1610             source1.append( "" + l );
1611             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1612             source1.append( " 00; 01 ;02;03" + l );
1613             source1.append( "   10; 11; 12; 13  " + l );
1614             source1.append( "20; 21; 22; 23 " + l );
1615             source1.append( "    30;  31;    32; 33" + l );
1616             source1.append( "40;41;42;43" + l );
1617             source1.append( "  # 1 1 1 1 1 " + l );
1618             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
1619             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ";" );
1620             if ( t2.getNumberOfColumns() != 5 ) {
1621                 return false;
1622             }
1623             if ( t2.getNumberOfRows() != 6 ) {
1624                 return false;
1625             }
1626             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1627                 return false;
1628             }
1629             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1630                 return false;
1631             }
1632             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1633                 return false;
1634             }
1635             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1636                 return false;
1637             }
1638             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1639                 return false;
1640             }
1641             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1642                 return false;
1643             }
1644             final StringBuffer source2 = new StringBuffer();
1645             source2.append( "" + l );
1646             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1647             source2.append( " 00; 01 ;02;03" + l );
1648             source2.append( "   10; 11; 12; 13  " + l );
1649             source2.append( "20; 21; 22; 23 " + l );
1650             source2.append( "                     " + l );
1651             source2.append( "    30;  31;    32; 33" + l );
1652             source2.append( "40;41;42;43" + l );
1653             source2.append( "  comment: 1 1 1 1 1 " + l );
1654             source2.append( ";;;50  ;   52; 53;;54   " + l );
1655             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1656                                                                         ";",
1657                                                                         false,
1658                                                                         false,
1659                                                                         "comment:",
1660                                                                         false );
1661             if ( tl.size() != 2 ) {
1662                 return false;
1663             }
1664             final BasicTable<String> t3 = tl.get( 0 );
1665             final BasicTable<String> t4 = tl.get( 1 );
1666             if ( t3.getNumberOfColumns() != 4 ) {
1667                 return false;
1668             }
1669             if ( t3.getNumberOfRows() != 3 ) {
1670                 return false;
1671             }
1672             if ( t4.getNumberOfColumns() != 4 ) {
1673                 return false;
1674             }
1675             if ( t4.getNumberOfRows() != 3 ) {
1676                 return false;
1677             }
1678             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1679                 return false;
1680             }
1681             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
1682                 return false;
1683             }
1684         }
1685         catch ( final Exception e ) {
1686             e.printStackTrace( System.out );
1687             return false;
1688         }
1689         return true;
1690     }
1691
1692     private static boolean testBasicTolXMLparsing() {
1693         try {
1694             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1695             final TolParser parser = new TolParser();
1696             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
1697             if ( parser.getErrorCount() > 0 ) {
1698                 System.out.println( parser.getErrorMessages().toString() );
1699                 return false;
1700             }
1701             if ( phylogenies_0.length != 1 ) {
1702                 return false;
1703             }
1704             final Phylogeny t1 = phylogenies_0[ 0 ];
1705             if ( t1.getNumberOfExternalNodes() != 5 ) {
1706                 return false;
1707             }
1708             if ( !t1.isRooted() ) {
1709                 return false;
1710             }
1711             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
1712                 return false;
1713             }
1714             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
1715                 return false;
1716             }
1717             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
1718                 return false;
1719             }
1720             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
1721                 return false;
1722             }
1723             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
1724             if ( parser.getErrorCount() > 0 ) {
1725                 System.out.println( parser.getErrorMessages().toString() );
1726                 return false;
1727             }
1728             if ( phylogenies_1.length != 1 ) {
1729                 return false;
1730             }
1731             final Phylogeny t2 = phylogenies_1[ 0 ];
1732             if ( t2.getNumberOfExternalNodes() != 664 ) {
1733                 return false;
1734             }
1735             if ( !t2.isRooted() ) {
1736                 return false;
1737             }
1738             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
1739                 return false;
1740             }
1741             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
1742                 return false;
1743             }
1744             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
1745                 return false;
1746             }
1747             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
1748                 return false;
1749             }
1750             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
1751                 return false;
1752             }
1753             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
1754                     .equals( "Aquifex" ) ) {
1755                 return false;
1756             }
1757             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
1758             if ( parser.getErrorCount() > 0 ) {
1759                 System.out.println( parser.getErrorMessages().toString() );
1760                 return false;
1761             }
1762             if ( phylogenies_2.length != 1 ) {
1763                 return false;
1764             }
1765             final Phylogeny t3 = phylogenies_2[ 0 ];
1766             if ( t3.getNumberOfExternalNodes() != 184 ) {
1767                 return false;
1768             }
1769             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
1770                 return false;
1771             }
1772             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
1773                 return false;
1774             }
1775             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
1776                 return false;
1777             }
1778             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
1779             if ( parser.getErrorCount() > 0 ) {
1780                 System.out.println( parser.getErrorMessages().toString() );
1781                 return false;
1782             }
1783             if ( phylogenies_3.length != 1 ) {
1784                 return false;
1785             }
1786             final Phylogeny t4 = phylogenies_3[ 0 ];
1787             if ( t4.getNumberOfExternalNodes() != 1 ) {
1788                 return false;
1789             }
1790             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
1791                 return false;
1792             }
1793             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
1794                 return false;
1795             }
1796             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
1797                 return false;
1798             }
1799             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
1800             if ( parser.getErrorCount() > 0 ) {
1801                 System.out.println( parser.getErrorMessages().toString() );
1802                 return false;
1803             }
1804             if ( phylogenies_4.length != 1 ) {
1805                 return false;
1806             }
1807             final Phylogeny t5 = phylogenies_4[ 0 ];
1808             if ( t5.getNumberOfExternalNodes() != 13 ) {
1809                 return false;
1810             }
1811             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
1812                 return false;
1813             }
1814             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
1815                 return false;
1816             }
1817             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
1818                 return false;
1819             }
1820         }
1821         catch ( final Exception e ) {
1822             e.printStackTrace( System.out );
1823             return false;
1824         }
1825         return true;
1826     }
1827
1828     private static boolean testBasicTreeMethods() {
1829         try {
1830             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1831             final Phylogeny t1 = factory.create();
1832             if ( !t1.isEmpty() ) {
1833                 return false;
1834             }
1835             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
1836             if ( t2.getNumberOfExternalNodes() != 4 ) {
1837                 return false;
1838             }
1839             if ( t2.getHeight() != 8.5 ) {
1840                 return false;
1841             }
1842             if ( !t2.isCompletelyBinary() ) {
1843                 return false;
1844             }
1845             if ( t2.isEmpty() ) {
1846                 return false;
1847             }
1848             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
1849             if ( t3.getNumberOfExternalNodes() != 5 ) {
1850                 return false;
1851             }
1852             if ( t3.getHeight() != 11 ) {
1853                 return false;
1854             }
1855             if ( t3.isCompletelyBinary() ) {
1856                 return false;
1857             }
1858             final PhylogenyNode n = t3.getNode( "ABC" );
1859             final Phylogeny t4 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3,(F,G,H,I))", new NHXParser() )[ 0 ];
1860             if ( t4.getNumberOfExternalNodes() != 9 ) {
1861                 return false;
1862             }
1863             if ( t4.getHeight() != 11 ) {
1864                 return false;
1865             }
1866             if ( t4.isCompletelyBinary() ) {
1867                 return false;
1868             }
1869             final StringBuffer sb5 = new StringBuffer( "(((A11:2)A1:2,(A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:3,D:8)" );
1870             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
1871             if ( t5.getNumberOfExternalNodes() != 8 ) {
1872                 return false;
1873             }
1874             if ( t5.getHeight() != 15 ) {
1875                 return false;
1876             }
1877             final StringBuffer sb6 = new StringBuffer( "(X,Y,Z,(((A111)A11:2)A1:2,(X,Y,Z,A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:3,D:8)" );
1878             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
1879             if ( t6.getHeight() != 15 ) {
1880                 return false;
1881             }
1882             final StringBuffer sb7 = new StringBuffer( "(((A11:2)A1:2,(A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:15,D:8)" );
1883             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
1884             if ( t7.getHeight() != 15 ) {
1885                 return false;
1886             }
1887             final StringBuffer sb8 = new StringBuffer( "(((A11:11)A1:2,(A21:2,A22:2,A23,A24,AA:)A2:11,A3:2)A:2,B:15,C:15,D:15)" );
1888             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
1889             if ( t8.getNumberOfExternalNodes() != 10 ) {
1890                 return false;
1891             }
1892             if ( t8.getHeight() != 15 ) {
1893                 return false;
1894             }
1895             final char[] a9 = new char[] {};
1896             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
1897             if ( t9.getHeight() != 0 ) {
1898                 return false;
1899             }
1900             final char[] a10 = new char[] { 'a', ':', '6' };
1901             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
1902             if ( t10.getHeight() != 6 ) {
1903                 return false;
1904             }
1905         }
1906         catch ( final Exception e ) {
1907             e.printStackTrace( System.out );
1908             return false;
1909         }
1910         return true;
1911     }
1912
1913     private static boolean testConfidenceAssessor() {
1914         try {
1915             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1916             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1917             final Phylogeny[] ev0 = factory
1918                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
1919                              new NHXParser() );
1920             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
1921             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
1922                 return false;
1923             }
1924             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
1925                 return false;
1926             }
1927             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1928             final Phylogeny[] ev1 = factory
1929                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
1930                              new NHXParser() );
1931             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
1932             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
1933                 return false;
1934             }
1935             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1936                 return false;
1937             }
1938             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
1939             final Phylogeny[] ev_b = factory
1940                     .create( "((A,C),X);((A,X),C);(A,C);((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
1941                              new NHXParser() );
1942             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
1943             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
1944                 return false;
1945             }
1946             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1947                 return false;
1948             }
1949             //
1950             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
1951             final Phylogeny[] ev1x = factory
1952                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
1953                              new NHXParser() );
1954             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
1955             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1956                 return false;
1957             }
1958             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
1959                 return false;
1960             }
1961             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
1962             final Phylogeny[] ev_bx = factory
1963                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
1964                              new NHXParser() );
1965             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
1966             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1967                 return false;
1968             }
1969             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1970                 return false;
1971             }
1972             //
1973             final Phylogeny[] t2 = factory
1974                     .create( "((((a,b),c),d),e);(((a,b),c),(d,e));(((((a,b),c),d),e),f);((((a,b),c),(d,e)),f);(((a,b),c),d,e);((a,b,c),d,e);",
1975                              new NHXParser() );
1976             final Phylogeny[] ev2 = factory
1977                     .create( "((((a,b),c),d),e);((((a,b),c),d),e);((((a,b),e),d),c);((((a,b),e),d),c);(((a,b),(c,d)),e);((a,b),x);((a,b),(x,y));(a,b);(a,e);(a,b,c);",
1978                              new NHXParser() );
1979             for( final Phylogeny target : t2 ) {
1980                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
1981             }
1982             //
1983             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
1984                                                  new NHXParser() )[ 0 ];
1985             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
1986             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
1987             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1988                 return false;
1989             }
1990             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
1991                 return false;
1992             }
1993             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
1994                 return false;
1995             }
1996         }
1997         catch ( final Exception e ) {
1998             e.printStackTrace();
1999             return false;
2000         }
2001         return true;
2002     }
2003
2004     private static boolean testCopyOfNodeData() {
2005         try {
2006             final PhylogenyNode n1 = PhylogenyNode
2007                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1:O=22:SO=33:SN=44:W=2:C=10.20.30:XN=S=tag1=value1=unit1]" );
2008             final PhylogenyNode n2 = n1.copyNodeData();
2009             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2010                 return false;
2011             }
2012         }
2013         catch ( final Exception e ) {
2014             e.printStackTrace();
2015             return false;
2016         }
2017         return true;
2018     }
2019
2020     private static boolean testDataObjects() {
2021         try {
2022             final Confidence s0 = new Confidence();
2023             final Confidence s1 = new Confidence();
2024             if ( !s0.isEqual( s1 ) ) {
2025                 return false;
2026             }
2027             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2028             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2029             if ( s2.isEqual( s1 ) ) {
2030                 return false;
2031             }
2032             if ( !s2.isEqual( s3 ) ) {
2033                 return false;
2034             }
2035             final Confidence s4 = ( Confidence ) s3.copy();
2036             if ( !s4.isEqual( s3 ) ) {
2037                 return false;
2038             }
2039             s3.asSimpleText();
2040             s3.asText();
2041             // Taxonomy
2042             // ----------
2043             final Taxonomy t1 = new Taxonomy();
2044             final Taxonomy t2 = new Taxonomy();
2045             final Taxonomy t3 = new Taxonomy();
2046             final Taxonomy t4 = new Taxonomy();
2047             final Taxonomy t5 = new Taxonomy();
2048             t1.setIdentifier( new Identifier( "ecoli" ) );
2049             t1.setTaxonomyCode( "ECOLI" );
2050             t1.setScientificName( "E. coli" );
2051             t1.setCommonName( "coli" );
2052             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2053             if ( !t1.isEqual( t0 ) ) {
2054                 return false;
2055             }
2056             t2.setIdentifier( new Identifier( "ecoli" ) );
2057             t2.setTaxonomyCode( "OTHER" );
2058             t2.setScientificName( "what" );
2059             t2.setCommonName( "something" );
2060             if ( !t1.isEqual( t2 ) ) {
2061                 return false;
2062             }
2063             t2.setIdentifier( new Identifier( "nemve" ) );
2064             if ( t1.isEqual( t2 ) ) {
2065                 return false;
2066             }
2067             t1.setIdentifier( null );
2068             t3.setTaxonomyCode( "ECOLI" );
2069             t3.setScientificName( "what" );
2070             t3.setCommonName( "something" );
2071             if ( !t1.isEqual( t3 ) ) {
2072                 return false;
2073             }
2074             t1.setIdentifier( null );
2075             t1.setTaxonomyCode( "" );
2076             t4.setScientificName( "E. ColI" );
2077             t4.setCommonName( "something" );
2078             if ( !t1.isEqual( t4 ) ) {
2079                 return false;
2080             }
2081             t4.setScientificName( "B. subtilis" );
2082             t4.setCommonName( "something" );
2083             if ( t1.isEqual( t4 ) ) {
2084                 return false;
2085             }
2086             t1.setIdentifier( null );
2087             t1.setTaxonomyCode( "" );
2088             t1.setScientificName( "" );
2089             t5.setCommonName( "COLI" );
2090             if ( !t1.isEqual( t5 ) ) {
2091                 return false;
2092             }
2093             t5.setCommonName( "vibrio" );
2094             if ( t1.isEqual( t5 ) ) {
2095                 return false;
2096             }
2097             // Identifier
2098             // ----------
2099             final Identifier id0 = new Identifier( "123", "pfam" );
2100             final Identifier id1 = ( Identifier ) id0.copy();
2101             if ( !id1.isEqual( id1 ) ) {
2102                 return false;
2103             }
2104             if ( !id1.isEqual( id0 ) ) {
2105                 return false;
2106             }
2107             if ( !id0.isEqual( id1 ) ) {
2108                 return false;
2109             }
2110             id1.asSimpleText();
2111             id1.asText();
2112             // ProteinDomain
2113             // ---------------
2114             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2115             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2116             if ( !pd1.isEqual( pd1 ) ) {
2117                 return false;
2118             }
2119             if ( !pd1.isEqual( pd0 ) ) {
2120                 return false;
2121             }
2122             pd1.asSimpleText();
2123             pd1.asText();
2124             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2125             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2126             if ( !pd3.isEqual( pd3 ) ) {
2127                 return false;
2128             }
2129             if ( !pd2.isEqual( pd3 ) ) {
2130                 return false;
2131             }
2132             if ( !pd0.isEqual( pd3 ) ) {
2133                 return false;
2134             }
2135             pd3.asSimpleText();
2136             pd3.asText();
2137             // DomainArchitecture
2138             // ------------------
2139             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2140             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2141             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2142             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2143             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2144             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2145             domains0.add( d2 );
2146             domains0.add( d0 );
2147             domains0.add( d3 );
2148             domains0.add( d1 );
2149             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2150             if ( ds0.getNumberOfDomains() != 4 ) {
2151                 return false;
2152             }
2153             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2154             if ( !ds0.isEqual( ds0 ) ) {
2155                 return false;
2156             }
2157             if ( !ds0.isEqual( ds1 ) ) {
2158                 return false;
2159             }
2160             if ( ds1.getNumberOfDomains() != 4 ) {
2161                 return false;
2162             }
2163             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2164             domains1.add( d1 );
2165             domains1.add( d2 );
2166             domains1.add( d4 );
2167             domains1.add( d0 );
2168             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2169             if ( ds0.isEqual( ds2 ) ) {
2170                 return false;
2171             }
2172             ds1.asSimpleText();
2173             ds1.asText();
2174             ds1.toNHX();
2175             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2176             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2177                 System.out.println( ds3.toNHX() );
2178                 return false;
2179             }
2180             if ( ds3.getNumberOfDomains() != 3 ) {
2181                 return false;
2182             }
2183             // Event
2184             // -----
2185             final Event e1 = new Event( Event.EventType.fusion );
2186             if ( e1.isDuplication() ) {
2187                 return false;
2188             }
2189             if ( !e1.isFusion() ) {
2190                 return false;
2191             }
2192             if ( !e1.asText().toString().equals( "fusion" ) ) {
2193                 return false;
2194             }
2195             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2196                 return false;
2197             }
2198             final Event e11 = new Event( Event.EventType.fusion );
2199             if ( !e11.isEqual( e1 ) ) {
2200                 return false;
2201             }
2202             if ( !e11.toNHX().toString().equals( "" ) ) {
2203                 return false;
2204             }
2205             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2206             if ( e2.isDuplication() ) {
2207                 return false;
2208             }
2209             if ( !e2.isSpeciationOrDuplication() ) {
2210                 return false;
2211             }
2212             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2213                 return false;
2214             }
2215             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2216                 return false;
2217             }
2218             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2219                 return false;
2220             }
2221             if ( e11.isEqual( e2 ) ) {
2222                 return false;
2223             }
2224             final Event e2c = ( Event ) e2.copy();
2225             if ( !e2c.isEqual( e2 ) ) {
2226                 return false;
2227             }
2228             Event e3 = new Event( 1, 2, 3 );
2229             if ( e3.isDuplication() ) {
2230                 return false;
2231             }
2232             if ( e3.isSpeciation() ) {
2233                 return false;
2234             }
2235             if ( e3.isGeneLoss() ) {
2236                 return false;
2237             }
2238             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2239                 return false;
2240             }
2241             final Event e3c = ( Event ) e3.copy();
2242             final Event e3cc = ( Event ) e3c.copy();
2243             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2244                 return false;
2245             }
2246             e3 = null;
2247             if ( !e3c.isEqual( e3cc ) ) {
2248                 return false;
2249             }
2250             Event e4 = new Event( 1, 2, 3 );
2251             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2252                 return false;
2253             }
2254             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2255                 return false;
2256             }
2257             final Event e4c = ( Event ) e4.copy();
2258             e4 = null;
2259             final Event e4cc = ( Event ) e4c.copy();
2260             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2261                 return false;
2262             }
2263             if ( !e4c.isEqual( e4cc ) ) {
2264                 return false;
2265             }
2266             final Event e5 = new Event();
2267             if ( !e5.isUnassigned() ) {
2268                 return false;
2269             }
2270             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2271                 return false;
2272             }
2273             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2274                 return false;
2275             }
2276             final Event e6 = new Event( 1, 0, 0 );
2277             if ( !e6.asText().toString().equals( "duplication" ) ) {
2278                 return false;
2279             }
2280             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2281                 return false;
2282             }
2283             final Event e7 = new Event( 0, 1, 0 );
2284             if ( !e7.asText().toString().equals( "speciation" ) ) {
2285                 return false;
2286             }
2287             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2288                 return false;
2289             }
2290             final Event e8 = new Event( 0, 0, 1 );
2291             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2292                 return false;
2293             }
2294             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2295                 return false;
2296             }
2297         }
2298         catch ( final Exception e ) {
2299             e.printStackTrace( System.out );
2300             return false;
2301         }
2302         return true;
2303     }
2304
2305     private static boolean testDeletionOfExternalNodes() {
2306         try {
2307             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2308             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2309             final PhylogenyWriter w = new PhylogenyWriter();
2310             if ( t0.isEmpty() ) {
2311                 return false;
2312             }
2313             if ( t0.getNumberOfExternalNodes() != 1 ) {
2314                 return false;
2315             }
2316             t0.deleteSubtree( t0.getNode( "A" ), false );
2317             if ( t0.getNumberOfExternalNodes() != 0 ) {
2318                 return false;
2319             }
2320             if ( !t0.isEmpty() ) {
2321                 return false;
2322             }
2323             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2324             if ( t1.getNumberOfExternalNodes() != 2 ) {
2325                 return false;
2326             }
2327             t1.deleteSubtree( t1.getNode( "A" ), false );
2328             if ( t1.getNumberOfExternalNodes() != 1 ) {
2329                 return false;
2330             }
2331             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2332                 return false;
2333             }
2334             t1.deleteSubtree( t1.getNode( "B" ), false );
2335             if ( t1.getNumberOfExternalNodes() != 1 ) {
2336                 return false;
2337             }
2338             t1.deleteSubtree( t1.getNode( "r" ), false );
2339             if ( !t1.isEmpty() ) {
2340                 return false;
2341             }
2342             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2343             if ( t2.getNumberOfExternalNodes() != 3 ) {
2344                 return false;
2345             }
2346             t2.deleteSubtree( t2.getNode( "B" ), false );
2347             if ( t2.getNumberOfExternalNodes() != 2 ) {
2348                 return false;
2349             }
2350             t2.toNewHampshireX();
2351             PhylogenyNode n = t2.getNode( "A" );
2352             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2353                 return false;
2354             }
2355             t2.deleteSubtree( t2.getNode( "A" ), false );
2356             if ( t2.getNumberOfExternalNodes() != 2 ) {
2357                 return false;
2358             }
2359             t2.deleteSubtree( t2.getNode( "C" ), true );
2360             if ( t2.getNumberOfExternalNodes() != 1 ) {
2361                 return false;
2362             }
2363             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2364             if ( t3.getNumberOfExternalNodes() != 4 ) {
2365                 return false;
2366             }
2367             t3.deleteSubtree( t3.getNode( "B" ), true );
2368             if ( t3.getNumberOfExternalNodes() != 3 ) {
2369                 return false;
2370             }
2371             n = t3.getNode( "A" );
2372             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2373                 return false;
2374             }
2375             n = n.getNextExternalNode();
2376             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2377                 return false;
2378             }
2379             t3.deleteSubtree( t3.getNode( "A" ), true );
2380             if ( t3.getNumberOfExternalNodes() != 2 ) {
2381                 return false;
2382             }
2383             n = t3.getNode( "C" );
2384             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2385                 return false;
2386             }
2387             t3.deleteSubtree( t3.getNode( "C" ), true );
2388             if ( t3.getNumberOfExternalNodes() != 1 ) {
2389                 return false;
2390             }
2391             t3.deleteSubtree( t3.getNode( "D" ), true );
2392             if ( t3.getNumberOfExternalNodes() != 0 ) {
2393                 return false;
2394             }
2395             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2396             if ( t4.getNumberOfExternalNodes() != 6 ) {
2397                 return false;
2398             }
2399             t4.deleteSubtree( t4.getNode( "B2" ), true );
2400             if ( t4.getNumberOfExternalNodes() != 5 ) {
2401                 return false;
2402             }
2403             String s = w.toNewHampshire( t4, false, true ).toString();
2404             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2405                 return false;
2406             }
2407             t4.deleteSubtree( t4.getNode( "B11" ), true );
2408             if ( t4.getNumberOfExternalNodes() != 4 ) {
2409                 return false;
2410             }
2411             t4.deleteSubtree( t4.getNode( "C" ), true );
2412             if ( t4.getNumberOfExternalNodes() != 3 ) {
2413                 return false;
2414             }
2415             n = t4.getNode( "A" );
2416             n = n.getNextExternalNode();
2417             if ( !n.getName().equals( "B12" ) ) {
2418                 return false;
2419             }
2420             n = n.getNextExternalNode();
2421             if ( !n.getName().equals( "D" ) ) {
2422                 return false;
2423             }
2424             s = w.toNewHampshire( t4, false, true ).toString();
2425             if ( !s.equals( "((A,B12),D);" ) ) {
2426                 return false;
2427             }
2428             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2429             t5.deleteSubtree( t5.getNode( "A" ), true );
2430             if ( t5.getNumberOfExternalNodes() != 5 ) {
2431                 return false;
2432             }
2433             s = w.toNewHampshire( t5, false, true ).toString();
2434             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2435                 return false;
2436             }
2437             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2438             t6.deleteSubtree( t6.getNode( "B11" ), true );
2439             if ( t6.getNumberOfExternalNodes() != 5 ) {
2440                 return false;
2441             }
2442             s = w.toNewHampshire( t6, false, false ).toString();
2443             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2444                 return false;
2445             }
2446             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2447             t7.deleteSubtree( t7.getNode( "B12" ), true );
2448             if ( t7.getNumberOfExternalNodes() != 5 ) {
2449                 return false;
2450             }
2451             s = w.toNewHampshire( t7, false, true ).toString();
2452             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2453                 return false;
2454             }
2455             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2456             t8.deleteSubtree( t8.getNode( "B2" ), true );
2457             if ( t8.getNumberOfExternalNodes() != 5 ) {
2458                 return false;
2459             }
2460             s = w.toNewHampshire( t8, false, false ).toString();
2461             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2462                 return false;
2463             }
2464             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2465             t9.deleteSubtree( t9.getNode( "C" ), true );
2466             if ( t9.getNumberOfExternalNodes() != 5 ) {
2467                 return false;
2468             }
2469             s = w.toNewHampshire( t9, false, true ).toString();
2470             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2471                 return false;
2472             }
2473             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2474             t10.deleteSubtree( t10.getNode( "D" ), true );
2475             if ( t10.getNumberOfExternalNodes() != 5 ) {
2476                 return false;
2477             }
2478             s = w.toNewHampshire( t10, false, true ).toString();
2479             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2480                 return false;
2481             }
2482             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2483             t11.deleteSubtree( t11.getNode( "A" ), true );
2484             if ( t11.getNumberOfExternalNodes() != 2 ) {
2485                 return false;
2486             }
2487             s = w.toNewHampshire( t11, false, true ).toString();
2488             if ( !s.equals( "(B,C);" ) ) {
2489                 return false;
2490             }
2491             t11.deleteSubtree( t11.getNode( "C" ), true );
2492             if ( t11.getNumberOfExternalNodes() != 1 ) {
2493                 return false;
2494             }
2495             s = w.toNewHampshire( t11, false, false ).toString();
2496             if ( !s.equals( "B;" ) ) {
2497                 return false;
2498             }
2499             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2500             t12.deleteSubtree( t12.getNode( "B2" ), true );
2501             if ( t12.getNumberOfExternalNodes() != 8 ) {
2502                 return false;
2503             }
2504             s = w.toNewHampshire( t12, false, true ).toString();
2505             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2506                 return false;
2507             }
2508             t12.deleteSubtree( t12.getNode( "B3" ), true );
2509             if ( t12.getNumberOfExternalNodes() != 7 ) {
2510                 return false;
2511             }
2512             s = w.toNewHampshire( t12, false, true ).toString();
2513             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2514                 return false;
2515             }
2516             t12.deleteSubtree( t12.getNode( "C3" ), true );
2517             if ( t12.getNumberOfExternalNodes() != 6 ) {
2518                 return false;
2519             }
2520             s = w.toNewHampshire( t12, false, true ).toString();
2521             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2522                 return false;
2523             }
2524             t12.deleteSubtree( t12.getNode( "A1" ), true );
2525             if ( t12.getNumberOfExternalNodes() != 5 ) {
2526                 return false;
2527             }
2528             s = w.toNewHampshire( t12, false, true ).toString();
2529             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2530                 return false;
2531             }
2532             t12.deleteSubtree( t12.getNode( "B1" ), true );
2533             if ( t12.getNumberOfExternalNodes() != 4 ) {
2534                 return false;
2535             }
2536             s = w.toNewHampshire( t12, false, true ).toString();
2537             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2538                 return false;
2539             }
2540             t12.deleteSubtree( t12.getNode( "A3" ), true );
2541             if ( t12.getNumberOfExternalNodes() != 3 ) {
2542                 return false;
2543             }
2544             s = w.toNewHampshire( t12, false, true ).toString();
2545             if ( !s.equals( "(A2,(C1,C2));" ) ) {
2546                 return false;
2547             }
2548             t12.deleteSubtree( t12.getNode( "A2" ), true );
2549             if ( t12.getNumberOfExternalNodes() != 2 ) {
2550                 return false;
2551             }
2552             s = w.toNewHampshire( t12, false, true ).toString();
2553             if ( !s.equals( "(C1,C2);" ) ) {
2554                 return false;
2555             }
2556             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2557             t13.deleteSubtree( t13.getNode( "D" ), true );
2558             if ( t13.getNumberOfExternalNodes() != 4 ) {
2559                 return false;
2560             }
2561             s = w.toNewHampshire( t13, false, true ).toString();
2562             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2563                 return false;
2564             }
2565             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2566             t14.deleteSubtree( t14.getNode( "E" ), true );
2567             if ( t14.getNumberOfExternalNodes() != 5 ) {
2568                 return false;
2569             }
2570             s = w.toNewHampshire( t14, false, true ).toString();
2571             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2572                 return false;
2573             }
2574             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2575             t15.deleteSubtree( t15.getNode( "B2" ), true );
2576             if ( t15.getNumberOfExternalNodes() != 11 ) {
2577                 return false;
2578             }
2579             t15.deleteSubtree( t15.getNode( "B1" ), true );
2580             if ( t15.getNumberOfExternalNodes() != 10 ) {
2581                 return false;
2582             }
2583             t15.deleteSubtree( t15.getNode( "B3" ), true );
2584             if ( t15.getNumberOfExternalNodes() != 9 ) {
2585                 return false;
2586             }
2587             t15.deleteSubtree( t15.getNode( "B4" ), true );
2588             if ( t15.getNumberOfExternalNodes() != 8 ) {
2589                 return false;
2590             }
2591             t15.deleteSubtree( t15.getNode( "A1" ), true );
2592             if ( t15.getNumberOfExternalNodes() != 7 ) {
2593                 return false;
2594             }
2595             t15.deleteSubtree( t15.getNode( "C4" ), true );
2596             if ( t15.getNumberOfExternalNodes() != 6 ) {
2597                 return false;
2598             }
2599         }
2600         catch ( final Exception e ) {
2601             e.printStackTrace( System.out );
2602             return false;
2603         }
2604         return true;
2605     }
2606
2607     private static boolean testDescriptiveStatistics() {
2608         try {
2609             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2610             dss1.addValue( 82 );
2611             dss1.addValue( 78 );
2612             dss1.addValue( 70 );
2613             dss1.addValue( 58 );
2614             dss1.addValue( 42 );
2615             if ( dss1.getN() != 5 ) {
2616                 return false;
2617             }
2618             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2619                 return false;
2620             }
2621             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2622                 return false;
2623             }
2624             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2625                 return false;
2626             }
2627             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2628                 return false;
2629             }
2630             if ( !Test.isEqual( dss1.median(), 70 ) ) {
2631                 return false;
2632             }
2633             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2634                 return false;
2635             }
2636             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2637                 return false;
2638             }
2639             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2640                 return false;
2641             }
2642             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2643                 return false;
2644             }
2645             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2646                 return false;
2647             }
2648             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2649                 return false;
2650             }
2651             dss1.addValue( 123 );
2652             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
2653                 return false;
2654             }
2655             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
2656                 return false;
2657             }
2658             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
2659                 return false;
2660             }
2661             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
2662             dss2.addValue( -1.85 );
2663             dss2.addValue( 57.5 );
2664             dss2.addValue( 92.78 );
2665             dss2.addValue( 57.78 );
2666             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
2667                 return false;
2668             }
2669             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
2670                 return false;
2671             }
2672             final double[] a = dss2.getDataAsDoubleArray();
2673             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
2674                 return false;
2675             }
2676             dss2.addValue( -100 );
2677             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
2678                 return false;
2679             }
2680             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
2681                 return false;
2682             }
2683             final double[] ds = new double[ 14 ];
2684             ds[ 0 ] = 34;
2685             ds[ 1 ] = 23;
2686             ds[ 2 ] = 1;
2687             ds[ 3 ] = 32;
2688             ds[ 4 ] = 11;
2689             ds[ 5 ] = 2;
2690             ds[ 6 ] = 12;
2691             ds[ 7 ] = 33;
2692             ds[ 8 ] = 13;
2693             ds[ 9 ] = 22;
2694             ds[ 10 ] = 21;
2695             ds[ 11 ] = 35;
2696             ds[ 12 ] = 24;
2697             ds[ 13 ] = 31;
2698             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
2699             if ( bins.length != 4 ) {
2700                 return false;
2701             }
2702             if ( bins[ 0 ] != 2 ) {
2703                 return false;
2704             }
2705             if ( bins[ 1 ] != 3 ) {
2706                 return false;
2707             }
2708             if ( bins[ 2 ] != 4 ) {
2709                 return false;
2710             }
2711             if ( bins[ 3 ] != 5 ) {
2712                 return false;
2713             }
2714             final double[] ds1 = new double[ 9 ];
2715             ds1[ 0 ] = 10.0;
2716             ds1[ 1 ] = 19.0;
2717             ds1[ 2 ] = 9.999;
2718             ds1[ 3 ] = 0.0;
2719             ds1[ 4 ] = 39.9;
2720             ds1[ 5 ] = 39.999;
2721             ds1[ 6 ] = 30.0;
2722             ds1[ 7 ] = 19.999;
2723             ds1[ 8 ] = 30.1;
2724             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
2725             if ( bins1.length != 4 ) {
2726                 return false;
2727             }
2728             if ( bins1[ 0 ] != 2 ) {
2729                 return false;
2730             }
2731             if ( bins1[ 1 ] != 3 ) {
2732                 return false;
2733             }
2734             if ( bins1[ 2 ] != 0 ) {
2735                 return false;
2736             }
2737             if ( bins1[ 3 ] != 4 ) {
2738                 return false;
2739             }
2740             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
2741             if ( bins1_1.length != 3 ) {
2742                 return false;
2743             }
2744             if ( bins1_1[ 0 ] != 3 ) {
2745                 return false;
2746             }
2747             if ( bins1_1[ 1 ] != 2 ) {
2748                 return false;
2749             }
2750             if ( bins1_1[ 2 ] != 4 ) {
2751                 return false;
2752             }
2753             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
2754             if ( bins1_2.length != 3 ) {
2755                 return false;
2756             }
2757             if ( bins1_2[ 0 ] != 2 ) {
2758                 return false;
2759             }
2760             if ( bins1_2[ 1 ] != 2 ) {
2761                 return false;
2762             }
2763             if ( bins1_2[ 2 ] != 2 ) {
2764                 return false;
2765             }
2766             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
2767             dss3.addValue( 1 );
2768             dss3.addValue( 1 );
2769             dss3.addValue( 1 );
2770             dss3.addValue( 2 );
2771             dss3.addValue( 3 );
2772             dss3.addValue( 4 );
2773             dss3.addValue( 5 );
2774             dss3.addValue( 5 );
2775             dss3.addValue( 5 );
2776             dss3.addValue( 6 );
2777             dss3.addValue( 7 );
2778             dss3.addValue( 8 );
2779             dss3.addValue( 9 );
2780             dss3.addValue( 10 );
2781             dss3.addValue( 10 );
2782             dss3.addValue( 10 );
2783             final AsciiHistogram histo = new AsciiHistogram( dss3 );
2784             histo.toStringBuffer( 10, '=', 40, 5 );
2785             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
2786         }
2787         catch ( final Exception e ) {
2788             e.printStackTrace( System.out );
2789             return false;
2790         }
2791         return true;
2792     }
2793
2794     private static boolean testDir( final String file ) {
2795         try {
2796             final File f = new File( file );
2797             if ( !f.exists() ) {
2798                 return false;
2799             }
2800             if ( !f.isDirectory() ) {
2801                 return false;
2802             }
2803             if ( !f.canRead() ) {
2804                 return false;
2805             }
2806         }
2807         catch ( final Exception e ) {
2808             return false;
2809         }
2810         return true;
2811     }
2812
2813     private static boolean testExternalNodeRelatedMethods() {
2814         try {
2815             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2816             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2817             PhylogenyNode n = t1.getNode( "A" );
2818             n = n.getNextExternalNode();
2819             if ( !n.getName().equals( "B" ) ) {
2820                 return false;
2821             }
2822             n = n.getNextExternalNode();
2823             if ( !n.getName().equals( "C" ) ) {
2824                 return false;
2825             }
2826             n = n.getNextExternalNode();
2827             if ( !n.getName().equals( "D" ) ) {
2828                 return false;
2829             }
2830             n = t1.getNode( "B" );
2831             while ( !n.isLastExternalNode() ) {
2832                 n = n.getNextExternalNode();
2833             }
2834             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
2835             n = t2.getNode( "A" );
2836             n = n.getNextExternalNode();
2837             if ( !n.getName().equals( "B" ) ) {
2838                 return false;
2839             }
2840             n = n.getNextExternalNode();
2841             if ( !n.getName().equals( "C" ) ) {
2842                 return false;
2843             }
2844             n = n.getNextExternalNode();
2845             if ( !n.getName().equals( "D" ) ) {
2846                 return false;
2847             }
2848             n = t2.getNode( "B" );
2849             while ( !n.isLastExternalNode() ) {
2850                 n = n.getNextExternalNode();
2851             }
2852             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
2853             n = t3.getNode( "A" );
2854             n = n.getNextExternalNode();
2855             if ( !n.getName().equals( "B" ) ) {
2856                 return false;
2857             }
2858             n = n.getNextExternalNode();
2859             if ( !n.getName().equals( "C" ) ) {
2860                 return false;
2861             }
2862             n = n.getNextExternalNode();
2863             if ( !n.getName().equals( "D" ) ) {
2864                 return false;
2865             }
2866             n = n.getNextExternalNode();
2867             if ( !n.getName().equals( "E" ) ) {
2868                 return false;
2869             }
2870             n = n.getNextExternalNode();
2871             if ( !n.getName().equals( "F" ) ) {
2872                 return false;
2873             }
2874             n = n.getNextExternalNode();
2875             if ( !n.getName().equals( "G" ) ) {
2876                 return false;
2877             }
2878             n = n.getNextExternalNode();
2879             if ( !n.getName().equals( "H" ) ) {
2880                 return false;
2881             }
2882             n = t3.getNode( "B" );
2883             while ( !n.isLastExternalNode() ) {
2884                 n = n.getNextExternalNode();
2885             }
2886             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2887             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
2888                 final PhylogenyNode node = iter.next();
2889             }
2890             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
2891             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
2892                 final PhylogenyNode node = iter.next();
2893             }
2894             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
2895             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
2896             if ( !iter.next().getName().equals( "A" ) ) {
2897                 return false;
2898             }
2899             if ( !iter.next().getName().equals( "B" ) ) {
2900                 return false;
2901             }
2902             if ( !iter.next().getName().equals( "C" ) ) {
2903                 return false;
2904             }
2905             if ( !iter.next().getName().equals( "D" ) ) {
2906                 return false;
2907             }
2908             if ( !iter.next().getName().equals( "E" ) ) {
2909                 return false;
2910             }
2911             if ( !iter.next().getName().equals( "F" ) ) {
2912                 return false;
2913             }
2914             if ( iter.hasNext() ) {
2915                 return false;
2916             }
2917         }
2918         catch ( final Exception e ) {
2919             e.printStackTrace( System.out );
2920             return false;
2921         }
2922         return true;
2923     }
2924
2925     private static boolean testGeneralTable() {
2926         try {
2927             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
2928             t0.setValue( 3, 2, "23" );
2929             t0.setValue( 10, 1, "error" );
2930             t0.setValue( 10, 1, "110" );
2931             t0.setValue( 9, 1, "19" );
2932             t0.setValue( 1, 10, "101" );
2933             t0.setValue( 10, 10, "1010" );
2934             t0.setValue( 100, 10, "10100" );
2935             t0.setValue( 0, 0, "00" );
2936             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2937                 return false;
2938             }
2939             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2940                 return false;
2941             }
2942             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2943                 return false;
2944             }
2945             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2946                 return false;
2947             }
2948             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2949                 return false;
2950             }
2951             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2952                 return false;
2953             }
2954             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2955                 return false;
2956             }
2957             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
2958                 return false;
2959             }
2960             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
2961                 return false;
2962             }
2963             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
2964             t1.setValue( "3", "2", "23" );
2965             t1.setValue( "10", "1", "error" );
2966             t1.setValue( "10", "1", "110" );
2967             t1.setValue( "9", "1", "19" );
2968             t1.setValue( "1", "10", "101" );
2969             t1.setValue( "10", "10", "1010" );
2970             t1.setValue( "100", "10", "10100" );
2971             t1.setValue( "0", "0", "00" );
2972             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
2973             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
2974                 return false;
2975             }
2976             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
2977                 return false;
2978             }
2979             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
2980                 return false;
2981             }
2982             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
2983                 return false;
2984             }
2985             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
2986                 return false;
2987             }
2988             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
2989                 return false;
2990             }
2991             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
2992                 return false;
2993             }
2994             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
2995                 return false;
2996             }
2997             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
2998                 return false;
2999             }
3000             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3001                 return false;
3002             }
3003         }
3004         catch ( final Exception e ) {
3005             e.printStackTrace( System.out );
3006             return false;
3007         }
3008         return true;
3009     }
3010
3011     private static boolean testGetDistance() {
3012         try {
3013             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3014             final Phylogeny p1 = factory.create( "(((A:1,B:2,X:100)ab:3,C:4)abc:5,(D:7,(E:9,F:10)ef:8)def:6)r",
3015                                                  new NHXParser() )[ 0 ];
3016             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3017                 return false;
3018             }
3019             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3020                 return false;
3021             }
3022             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3023                 return false;
3024             }
3025             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3026                 return false;
3027             }
3028             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3029                 return false;
3030             }
3031             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3032                 return false;
3033             }
3034             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3035                 return false;
3036             }
3037             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3038                 return false;
3039             }
3040             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3041                 return false;
3042             }
3043             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3044                 return false;
3045             }
3046             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3047                 return false;
3048             }
3049             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3050                 return false;
3051             }
3052             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3053                 return false;
3054             }
3055             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3056                 return false;
3057             }
3058             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3059                 return false;
3060             }
3061             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3062                 return false;
3063             }
3064             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3065                 return false;
3066             }
3067             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3068                 return false;
3069             }
3070             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3071                 return false;
3072             }
3073             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3074                 return false;
3075             }
3076             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3077                 return false;
3078             }
3079             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3080                 return false;
3081             }
3082             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3083                 return false;
3084             }
3085             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3086                 return false;
3087             }
3088             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3089                 return false;
3090             }
3091             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3092                 return false;
3093             }
3094             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3095                 return false;
3096             }
3097             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3098                 return false;
3099             }
3100             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3101                 return false;
3102             }
3103             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3104                 return false;
3105             }
3106             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3107                 return false;
3108             }
3109             final Phylogeny p2 = factory.create( "((A:4,B:5,C:6)abc:1,(D:7,E:8,F:9)def:2,(G:10,H:11,I:12)ghi:3)r",
3110                                                  new NHXParser() )[ 0 ];
3111             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3112                 return false;
3113             }
3114             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3115                 return false;
3116             }
3117             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3118                 return false;
3119             }
3120             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3121                 return false;
3122             }
3123             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3124                 return false;
3125             }
3126             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3127                 return false;
3128             }
3129             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3130                 return false;
3131             }
3132             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3133                 return false;
3134             }
3135             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3136                 return false;
3137             }
3138             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3139                 return false;
3140             }
3141             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3142                 return false;
3143             }
3144         }
3145         catch ( final Exception e ) {
3146             e.printStackTrace( System.out );
3147             return false;
3148         }
3149         return true;
3150     }
3151
3152     private static boolean testGetLCA() {
3153         try {
3154             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3155             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3156                                                  new NHXParser() )[ 0 ];
3157             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3158             if ( !A.getName().equals( "A" ) ) {
3159                 return false;
3160             }
3161             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3162             if ( !gh.getName().equals( "gh" ) ) {
3163                 return false;
3164             }
3165             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3166             if ( !ab.getName().equals( "ab" ) ) {
3167                 return false;
3168             }
3169             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3170             if ( !ab2.getName().equals( "ab" ) ) {
3171                 return false;
3172             }
3173             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3174             if ( !gh2.getName().equals( "gh" ) ) {
3175                 return false;
3176             }
3177             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3178             if ( !gh3.getName().equals( "gh" ) ) {
3179                 return false;
3180             }
3181             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3182             if ( !abc.getName().equals( "abc" ) ) {
3183                 return false;
3184             }
3185             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3186             if ( !abc2.getName().equals( "abc" ) ) {
3187                 return false;
3188             }
3189             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3190             if ( !abcd.getName().equals( "abcd" ) ) {
3191                 return false;
3192             }
3193             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3194             if ( !abcd2.getName().equals( "abcd" ) ) {
3195                 return false;
3196             }
3197             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3198             if ( !abcdef.getName().equals( "abcdef" ) ) {
3199                 return false;
3200             }
3201             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3202             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3203                 return false;
3204             }
3205             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3206             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3207                 return false;
3208             }
3209             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3210             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3211                 return false;
3212             }
3213             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3214             if ( !abcde.getName().equals( "abcde" ) ) {
3215                 return false;
3216             }
3217             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3218             if ( !abcde2.getName().equals( "abcde" ) ) {
3219                 return false;
3220             }
3221             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3222             if ( !r.getName().equals( "abcdefgh" ) ) {
3223                 return false;
3224             }
3225             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3226             if ( !r2.getName().equals( "abcdefgh" ) ) {
3227                 return false;
3228             }
3229             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3230             if ( !r3.getName().equals( "abcdefgh" ) ) {
3231                 return false;
3232             }
3233             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3234             if ( !abcde3.getName().equals( "abcde" ) ) {
3235                 return false;
3236             }
3237             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3238             if ( !abcde4.getName().equals( "abcde" ) ) {
3239                 return false;
3240             }
3241             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3242             if ( !ab3.getName().equals( "ab" ) ) {
3243                 return false;
3244             }
3245             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3246             if ( !ab4.getName().equals( "ab" ) ) {
3247                 return false;
3248             }
3249             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3250             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3251             if ( !cd.getName().equals( "cd" ) ) {
3252                 return false;
3253             }
3254             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3255             if ( !cd2.getName().equals( "cd" ) ) {
3256                 return false;
3257             }
3258             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3259             if ( !cde.getName().equals( "cde" ) ) {
3260                 return false;
3261             }
3262             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3263             if ( !cde2.getName().equals( "cde" ) ) {
3264                 return false;
3265             }
3266             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3267             if ( !cdef.getName().equals( "cdef" ) ) {
3268                 return false;
3269             }
3270             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3271             if ( !cdef2.getName().equals( "cdef" ) ) {
3272                 return false;
3273             }
3274             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3275             if ( !cdef3.getName().equals( "cdef" ) ) {
3276                 return false;
3277             }
3278             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3279             if ( !rt.getName().equals( "r" ) ) {
3280                 return false;
3281             }
3282             final Phylogeny p3 = factory
3283                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3284                              new NHXParser() )[ 0 ];
3285             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3286             if ( !bc_3.getName().equals( "bc" ) ) {
3287                 return false;
3288             }
3289             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3290             if ( !ac_3.getName().equals( "abc" ) ) {
3291                 return false;
3292             }
3293             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3294             if ( !ad_3.getName().equals( "abcde" ) ) {
3295                 return false;
3296             }
3297             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3298             if ( !af_3.getName().equals( "abcdef" ) ) {
3299                 return false;
3300             }
3301             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3302             if ( !ag_3.getName().equals( "" ) ) {
3303                 return false;
3304             }
3305             if ( !ag_3.isRoot() ) {
3306                 return false;
3307             }
3308             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3309             if ( !al_3.getName().equals( "" ) ) {
3310                 return false;
3311             }
3312             if ( !al_3.isRoot() ) {
3313                 return false;
3314             }
3315             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3316             if ( !kl_3.getName().equals( "" ) ) {
3317                 return false;
3318             }
3319             if ( !kl_3.isRoot() ) {
3320                 return false;
3321             }
3322             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3323             if ( !fl_3.getName().equals( "" ) ) {
3324                 return false;
3325             }
3326             if ( !fl_3.isRoot() ) {
3327                 return false;
3328             }
3329             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3330             if ( !gk_3.getName().equals( "ghijk" ) ) {
3331                 return false;
3332             }
3333             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3334             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3335             if ( !r_4.getName().equals( "r" ) ) {
3336                 return false;
3337             }
3338             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3339             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3340             if ( !r_5.getName().equals( "root" ) ) {
3341                 return false;
3342             }
3343             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3344             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3345             if ( !r_6.getName().equals( "rot" ) ) {
3346                 return false;
3347             }
3348             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3349             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3350             if ( !r_7.getName().equals( "rott" ) ) {
3351                 return false;
3352             }
3353         }
3354         catch ( final Exception e ) {
3355             e.printStackTrace( System.out );
3356             return false;
3357         }
3358         return true;
3359     }
3360
3361     private static boolean testGetLCA2() {
3362         try {
3363             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3364             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3365             PhylogenyMethods.preOrderReId( p_a );
3366             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3367                                                                                               p_a.getNode( "a" ) );
3368             if ( !p_a_1.getName().equals( "a" ) ) {
3369                 return false;
3370             }
3371             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3372             PhylogenyMethods.preOrderReId( p_b );
3373             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3374                                                                                               p_b.getNode( "a" ) );
3375             if ( !p_b_1.getName().equals( "b" ) ) {
3376                 return false;
3377             }
3378             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3379                                                                                               p_b.getNode( "b" ) );
3380             if ( !p_b_2.getName().equals( "b" ) ) {
3381                 return false;
3382             }
3383             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3384             PhylogenyMethods.preOrderReId( p_c );
3385             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3386                                                                                               p_c.getNode( "a" ) );
3387             if ( !p_c_1.getName().equals( "b" ) ) {
3388                 return false;
3389             }
3390             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3391                                                                                               p_c.getNode( "c" ) );
3392             if ( !p_c_2.getName().equals( "c" ) ) {
3393                 System.out.println( p_c_2.getName() );
3394                 System.exit( -1 );
3395                 return false;
3396             }
3397             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3398                                                                                               p_c.getNode( "b" ) );
3399             if ( !p_c_3.getName().equals( "b" ) ) {
3400                 return false;
3401             }
3402             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3403                                                                                               p_c.getNode( "a" ) );
3404             if ( !p_c_4.getName().equals( "c" ) ) {
3405                 return false;
3406             }
3407             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3408                                                  new NHXParser() )[ 0 ];
3409             PhylogenyMethods.preOrderReId( p1 );
3410             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3411                                                                                           p1.getNode( "A" ) );
3412             if ( !A.getName().equals( "A" ) ) {
3413                 return false;
3414             }
3415             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3416                                                                                            p1.getNode( "gh" ) );
3417             if ( !gh.getName().equals( "gh" ) ) {
3418                 return false;
3419             }
3420             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3421                                                                                            p1.getNode( "B" ) );
3422             if ( !ab.getName().equals( "ab" ) ) {
3423                 return false;
3424             }
3425             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3426                                                                                             p1.getNode( "A" ) );
3427             if ( !ab2.getName().equals( "ab" ) ) {
3428                 return false;
3429             }
3430             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3431                                                                                             p1.getNode( "G" ) );
3432             if ( !gh2.getName().equals( "gh" ) ) {
3433                 return false;
3434             }
3435             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3436                                                                                             p1.getNode( "H" ) );
3437             if ( !gh3.getName().equals( "gh" ) ) {
3438                 return false;
3439             }
3440             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3441                                                                                             p1.getNode( "A" ) );
3442             if ( !abc.getName().equals( "abc" ) ) {
3443                 return false;
3444             }
3445             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3446                                                                                              p1.getNode( "C" ) );
3447             if ( !abc2.getName().equals( "abc" ) ) {
3448                 return false;
3449             }
3450             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3451                                                                                              p1.getNode( "D" ) );
3452             if ( !abcd.getName().equals( "abcd" ) ) {
3453                 return false;
3454             }
3455             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3456                                                                                               p1.getNode( "A" ) );
3457             if ( !abcd2.getName().equals( "abcd" ) ) {
3458                 return false;
3459             }
3460             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3461                                                                                                p1.getNode( "F" ) );
3462             if ( !abcdef.getName().equals( "abcdef" ) ) {
3463                 return false;
3464             }
3465             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3466                                                                                                 p1.getNode( "A" ) );
3467             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3468                 return false;
3469             }
3470             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3471                                                                                                 p1.getNode( "F" ) );
3472             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3473                 return false;
3474             }
3475             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3476                                                                                                 p1.getNode( "ab" ) );
3477             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3478                 return false;
3479             }
3480             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3481                                                                                               p1.getNode( "E" ) );
3482             if ( !abcde.getName().equals( "abcde" ) ) {
3483                 return false;
3484             }
3485             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3486                                                                                                p1.getNode( "A" ) );
3487             if ( !abcde2.getName().equals( "abcde" ) ) {
3488                 return false;
3489             }
3490             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3491                                                                                           p1.getNode( "abcdefgh" ) );
3492             if ( !r.getName().equals( "abcdefgh" ) ) {
3493                 return false;
3494             }
3495             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3496                                                                                            p1.getNode( "H" ) );
3497             if ( !r2.getName().equals( "abcdefgh" ) ) {
3498                 return false;
3499             }
3500             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3501                                                                                            p1.getNode( "A" ) );
3502             if ( !r3.getName().equals( "abcdefgh" ) ) {
3503                 return false;
3504             }
3505             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3506                                                                                                p1.getNode( "abcde" ) );
3507             if ( !abcde3.getName().equals( "abcde" ) ) {
3508                 return false;
3509             }
3510             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3511                                                                                                p1.getNode( "E" ) );
3512             if ( !abcde4.getName().equals( "abcde" ) ) {
3513                 return false;
3514             }
3515             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3516                                                                                             p1.getNode( "B" ) );
3517             if ( !ab3.getName().equals( "ab" ) ) {
3518                 return false;
3519             }
3520             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3521                                                                                             p1.getNode( "ab" ) );
3522             if ( !ab4.getName().equals( "ab" ) ) {
3523                 return false;
3524             }
3525             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3526             PhylogenyMethods.preOrderReId( p2 );
3527             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3528                                                                                            p2.getNode( "d" ) );
3529             if ( !cd.getName().equals( "cd" ) ) {
3530                 return false;
3531             }
3532             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3533                                                                                             p2.getNode( "c" ) );
3534             if ( !cd2.getName().equals( "cd" ) ) {
3535                 return false;
3536             }
3537             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3538                                                                                             p2.getNode( "e" ) );
3539             if ( !cde.getName().equals( "cde" ) ) {
3540                 return false;
3541             }
3542             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3543                                                                                              p2.getNode( "c" ) );
3544             if ( !cde2.getName().equals( "cde" ) ) {
3545                 return false;
3546             }
3547             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3548                                                                                              p2.getNode( "f" ) );
3549             if ( !cdef.getName().equals( "cdef" ) ) {
3550                 return false;
3551             }
3552             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3553                                                                                               p2.getNode( "f" ) );
3554             if ( !cdef2.getName().equals( "cdef" ) ) {
3555                 return false;
3556             }
3557             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3558                                                                                               p2.getNode( "d" ) );
3559             if ( !cdef3.getName().equals( "cdef" ) ) {
3560                 return false;
3561             }
3562             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3563                                                                                            p2.getNode( "a" ) );
3564             if ( !rt.getName().equals( "r" ) ) {
3565                 return false;
3566             }
3567             final Phylogeny p3 = factory
3568                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3569                              new NHXParser() )[ 0 ];
3570             PhylogenyMethods.preOrderReId( p3 );
3571             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3572                                                                                              p3.getNode( "c" ) );
3573             if ( !bc_3.getName().equals( "bc" ) ) {
3574                 return false;
3575             }
3576             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3577                                                                                              p3.getNode( "c" ) );
3578             if ( !ac_3.getName().equals( "abc" ) ) {
3579                 return false;
3580             }
3581             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3582                                                                                              p3.getNode( "d" ) );
3583             if ( !ad_3.getName().equals( "abcde" ) ) {
3584                 return false;
3585             }
3586             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3587                                                                                              p3.getNode( "f" ) );
3588             if ( !af_3.getName().equals( "abcdef" ) ) {
3589                 return false;
3590             }
3591             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3592                                                                                              p3.getNode( "g" ) );
3593             if ( !ag_3.getName().equals( "" ) ) {
3594                 return false;
3595             }
3596             if ( !ag_3.isRoot() ) {
3597                 return false;
3598             }
3599             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3600                                                                                              p3.getNode( "l" ) );
3601             if ( !al_3.getName().equals( "" ) ) {
3602                 return false;
3603             }
3604             if ( !al_3.isRoot() ) {
3605                 return false;
3606             }
3607             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3608                                                                                              p3.getNode( "l" ) );
3609             if ( !kl_3.getName().equals( "" ) ) {
3610                 return false;
3611             }
3612             if ( !kl_3.isRoot() ) {
3613                 return false;
3614             }
3615             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3616                                                                                              p3.getNode( "l" ) );
3617             if ( !fl_3.getName().equals( "" ) ) {
3618                 return false;
3619             }
3620             if ( !fl_3.isRoot() ) {
3621                 return false;
3622             }
3623             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3624                                                                                              p3.getNode( "k" ) );
3625             if ( !gk_3.getName().equals( "ghijk" ) ) {
3626                 return false;
3627             }
3628             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3629             PhylogenyMethods.preOrderReId( p4 );
3630             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3631                                                                                             p4.getNode( "c" ) );
3632             if ( !r_4.getName().equals( "r" ) ) {
3633                 return false;
3634             }
3635             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3636             PhylogenyMethods.preOrderReId( p5 );
3637             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3638                                                                                             p5.getNode( "c" ) );
3639             if ( !r_5.getName().equals( "root" ) ) {
3640                 return false;
3641             }
3642             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3643             PhylogenyMethods.preOrderReId( p6 );
3644             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3645                                                                                             p6.getNode( "a" ) );
3646             if ( !r_6.getName().equals( "rot" ) ) {
3647                 return false;
3648             }
3649             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3650             PhylogenyMethods.preOrderReId( p7 );
3651             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
3652                                                                                             p7.getNode( "e" ) );
3653             if ( !r_7.getName().equals( "rott" ) ) {
3654                 return false;
3655             }
3656             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3657                                                                                              p7.getNode( "a" ) );
3658             if ( !r_71.getName().equals( "rott" ) ) {
3659                 return false;
3660             }
3661             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3662                                                                                              p7.getNode( "rott" ) );
3663             if ( !r_72.getName().equals( "rott" ) ) {
3664                 return false;
3665             }
3666             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3667                                                                                              p7.getNode( "a" ) );
3668             if ( !r_73.getName().equals( "rott" ) ) {
3669                 return false;
3670             }
3671             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3672                                                                                              p7.getNode( "rott" ) );
3673             if ( !r_74.getName().equals( "rott" ) ) {
3674                 return false;
3675             }
3676             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3677                                                                                              p7.getNode( "e" ) );
3678             if ( !r_75.getName().equals( "e" ) ) {
3679                 return false;
3680             }
3681         }
3682         catch ( final Exception e ) {
3683             e.printStackTrace( System.out );
3684             return false;
3685         }
3686         return true;
3687     }
3688
3689     private static boolean testHmmscanOutputParser() {
3690         final String test_dir = Test.PATH_TO_TEST_DATA;
3691         try {
3692             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
3693                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
3694             parser1.parse();
3695             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
3696                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
3697             final List<Protein> proteins = parser2.parse();
3698             if ( parser2.getProteinsEncountered() != 4 ) {
3699                 return false;
3700             }
3701             if ( proteins.size() != 4 ) {
3702                 return false;
3703             }
3704             if ( parser2.getDomainsEncountered() != 69 ) {
3705                 return false;
3706             }
3707             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
3708                 return false;
3709             }
3710             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
3711                 return false;
3712             }
3713             final Protein p1 = proteins.get( 0 );
3714             if ( p1.getNumberOfProteinDomains() != 15 ) {
3715                 return false;
3716             }
3717             if ( p1.getLength() != 850 ) {
3718                 return false;
3719             }
3720             final Protein p2 = proteins.get( 1 );
3721             if ( p2.getNumberOfProteinDomains() != 51 ) {
3722                 return false;
3723             }
3724             if ( p2.getLength() != 1291 ) {
3725                 return false;
3726             }
3727             final Protein p3 = proteins.get( 2 );
3728             if ( p3.getNumberOfProteinDomains() != 2 ) {
3729                 return false;
3730             }
3731             final Protein p4 = proteins.get( 3 );
3732             if ( p4.getNumberOfProteinDomains() != 1 ) {
3733                 return false;
3734             }
3735             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
3736                 return false;
3737             }
3738             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
3739                 return false;
3740             }
3741             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
3742                 return false;
3743             }
3744             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
3745                 return false;
3746             }
3747             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
3748                 return false;
3749             }
3750             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
3751                 return false;
3752             }
3753             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
3754                 return false;
3755             }
3756             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
3757                 return false;
3758             }
3759             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
3760                 return false;
3761             }
3762         }
3763         catch ( final Exception e ) {
3764             e.printStackTrace( System.out );
3765             return false;
3766         }
3767         return true;
3768     }
3769
3770     private static boolean testLastExternalNodeMethods() {
3771         try {
3772             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3773             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
3774             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
3775             final PhylogenyNode n1 = t0.getNode( "A" );
3776             if ( n1.isLastExternalNode() ) {
3777                 return false;
3778             }
3779             final PhylogenyNode n2 = t0.getNode( "B" );
3780             if ( n2.isLastExternalNode() ) {
3781                 return false;
3782             }
3783             final PhylogenyNode n3 = t0.getNode( "C" );
3784             if ( n3.isLastExternalNode() ) {
3785                 return false;
3786             }
3787             final PhylogenyNode n4 = t0.getNode( "D" );
3788             if ( !n4.isLastExternalNode() ) {
3789                 return false;
3790             }
3791         }
3792         catch ( final Exception e ) {
3793             e.printStackTrace( System.out );
3794             return false;
3795         }
3796         return true;
3797     }
3798
3799     private static boolean testLevelOrderIterator() {
3800         try {
3801             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3802             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
3803             PhylogenyNodeIterator it0;
3804             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
3805                 it0.next();
3806             }
3807             for( it0.reset(); it0.hasNext(); ) {
3808                 it0.next();
3809             }
3810             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
3811             if ( !it.next().getName().equals( "r" ) ) {
3812                 return false;
3813             }
3814             if ( !it.next().getName().equals( "ab" ) ) {
3815                 return false;
3816             }
3817             if ( !it.next().getName().equals( "cd" ) ) {
3818                 return false;
3819             }
3820             if ( !it.next().getName().equals( "A" ) ) {
3821                 return false;
3822             }
3823             if ( !it.next().getName().equals( "B" ) ) {
3824                 return false;
3825             }
3826             if ( !it.next().getName().equals( "C" ) ) {
3827                 return false;
3828             }
3829             if ( !it.next().getName().equals( "D" ) ) {
3830                 return false;
3831             }
3832             if ( it.hasNext() ) {
3833                 return false;
3834             }
3835             final Phylogeny t2 = factory.create( "(((1,2,(a,(X,Y,Z)b)3,4,5,6)A,B,C)abc,(D,E,(f1,(f21)f2,f3)F,G)defg)r",
3836                                                  new NHXParser() )[ 0 ];
3837             PhylogenyNodeIterator it2;
3838             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
3839                 it2.next();
3840             }
3841             for( it2.reset(); it2.hasNext(); ) {
3842                 it2.next();
3843             }
3844             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
3845             if ( !it3.next().getName().equals( "r" ) ) {
3846                 return false;
3847             }
3848             if ( !it3.next().getName().equals( "abc" ) ) {
3849                 return false;
3850             }
3851             if ( !it3.next().getName().equals( "defg" ) ) {
3852                 return false;
3853             }
3854             if ( !it3.next().getName().equals( "A" ) ) {
3855                 return false;
3856             }
3857             if ( !it3.next().getName().equals( "B" ) ) {
3858                 return false;
3859             }
3860             if ( !it3.next().getName().equals( "C" ) ) {
3861                 return false;
3862             }
3863             if ( !it3.next().getName().equals( "D" ) ) {
3864                 return false;
3865             }
3866             if ( !it3.next().getName().equals( "E" ) ) {
3867                 return false;
3868             }
3869             if ( !it3.next().getName().equals( "F" ) ) {
3870                 return false;
3871             }
3872             if ( !it3.next().getName().equals( "G" ) ) {
3873                 return false;
3874             }
3875             if ( !it3.next().getName().equals( "1" ) ) {
3876                 return false;
3877             }
3878             if ( !it3.next().getName().equals( "2" ) ) {
3879                 return false;
3880             }
3881             if ( !it3.next().getName().equals( "3" ) ) {
3882                 return false;
3883             }
3884             if ( !it3.next().getName().equals( "4" ) ) {
3885                 return false;
3886             }
3887             if ( !it3.next().getName().equals( "5" ) ) {
3888                 return false;
3889             }
3890             if ( !it3.next().getName().equals( "6" ) ) {
3891                 return false;
3892             }
3893             if ( !it3.next().getName().equals( "f1" ) ) {
3894                 return false;
3895             }
3896             if ( !it3.next().getName().equals( "f2" ) ) {
3897                 return false;
3898             }
3899             if ( !it3.next().getName().equals( "f3" ) ) {
3900                 return false;
3901             }
3902             if ( !it3.next().getName().equals( "a" ) ) {
3903                 return false;
3904             }
3905             if ( !it3.next().getName().equals( "b" ) ) {
3906                 return false;
3907             }
3908             if ( !it3.next().getName().equals( "f21" ) ) {
3909                 return false;
3910             }
3911             if ( !it3.next().getName().equals( "X" ) ) {
3912                 return false;
3913             }
3914             if ( !it3.next().getName().equals( "Y" ) ) {
3915                 return false;
3916             }
3917             if ( !it3.next().getName().equals( "Z" ) ) {
3918                 return false;
3919             }
3920             if ( it3.hasNext() ) {
3921                 return false;
3922             }
3923             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
3924             PhylogenyNodeIterator it4;
3925             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
3926                 it4.next();
3927             }
3928             for( it4.reset(); it4.hasNext(); ) {
3929                 it4.next();
3930             }
3931             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
3932             if ( !it5.next().getName().equals( "r" ) ) {
3933                 return false;
3934             }
3935             if ( !it5.next().getName().equals( "A" ) ) {
3936                 return false;
3937             }
3938             if ( !it5.next().getName().equals( "B" ) ) {
3939                 return false;
3940             }
3941             if ( !it5.next().getName().equals( "C" ) ) {
3942                 return false;
3943             }
3944             if ( !it5.next().getName().equals( "D" ) ) {
3945                 return false;
3946             }
3947             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
3948             PhylogenyNodeIterator it6;
3949             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
3950                 it6.next();
3951             }
3952             for( it6.reset(); it6.hasNext(); ) {
3953                 it6.next();
3954             }
3955             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
3956             if ( !it7.next().getName().equals( "A" ) ) {
3957                 return false;
3958             }
3959             if ( it.hasNext() ) {
3960                 return false;
3961             }
3962         }
3963         catch ( final Exception e ) {
3964             e.printStackTrace( System.out );
3965             return false;
3966         }
3967         return true;
3968     }
3969
3970     
3971     private static boolean testNodeRemoval() {
3972         try {
3973             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3974             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3975             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
3976             
3977             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
3978                 return false;
3979             }
3980             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
3981             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
3982             
3983             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
3984                 return false;
3985             }
3986             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
3987             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
3988             
3989             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
3990                 return false;
3991             }
3992             
3993         }
3994         catch ( final Exception e ) {
3995             e.printStackTrace( System.out );
3996             return false;
3997         }
3998         return true;
3999     }
4000     
4001     private static boolean testMidpointrooting() {
4002         try {
4003             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4004             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4005             PhylogenyMethods.midpointRoot( t0 );
4006             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4007                 return false;
4008             }
4009             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4010                 return false;
4011             }
4012             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4013                            1 ) ) {
4014                 return false;
4015             }
4016             final Phylogeny t1 = factory.create( "((A:1,B:2)AB:1[&&NHX:B=55],(C:3,D:4)CD:3[&&NHX:B=10])ABCD:0.5",
4017                                                  new NHXParser() )[ 0 ];
4018             if ( !t1.isRooted() ) {
4019                 return false;
4020             }
4021             PhylogenyMethods.midpointRoot( t1 );
4022             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4023                 return false;
4024             }
4025             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4026                 return false;
4027             }
4028             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4029                 return false;
4030             }
4031             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4032                 return false;
4033             }
4034             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4035                 return false;
4036             }
4037             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4038                 return false;
4039             }
4040             t1.reRoot( t1.getNode( "A" ) );
4041             PhylogenyMethods.midpointRoot( t1 );
4042             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4043                 return false;
4044             }
4045             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4046                 return false;
4047             }
4048             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4049                 return false;
4050             }
4051             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4052                 return false;
4053             }
4054             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4055                 System.exit( -1 );
4056                 return false;
4057             }
4058             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4059                 return false;
4060             }
4061         }
4062         catch ( final Exception e ) {
4063             e.printStackTrace( System.out );
4064             return false;
4065         }
4066         return true;
4067     }
4068
4069     private static boolean testNexusCharactersParsing() {
4070         try {
4071             final NexusCharactersParser parser = new NexusCharactersParser();
4072             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4073             parser.parse();
4074             String[] labels = parser.getCharStateLabels();
4075             if ( labels.length != 7 ) {
4076                 return false;
4077             }
4078             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4079                 return false;
4080             }
4081             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4082                 return false;
4083             }
4084             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4085                 return false;
4086             }
4087             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4088                 return false;
4089             }
4090             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4091                 return false;
4092             }
4093             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4094                 return false;
4095             }
4096             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4097                 return false;
4098             }
4099             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4100             parser.parse();
4101             labels = parser.getCharStateLabels();
4102             if ( labels.length != 7 ) {
4103                 return false;
4104             }
4105             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4106                 return false;
4107             }
4108             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4109                 return false;
4110             }
4111             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4112                 return false;
4113             }
4114             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4115                 return false;
4116             }
4117             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4118                 return false;
4119             }
4120             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4121                 return false;
4122             }
4123             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4124                 return false;
4125             }
4126         }
4127         catch ( final Exception e ) {
4128             e.printStackTrace( System.out );
4129             return false;
4130         }
4131         return true;
4132     }
4133
4134     private static boolean testNexusMatrixParsing() {
4135         try {
4136             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4137             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4138             parser.parse();
4139             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4140             if ( m.getNumberOfCharacters() != 9 ) {
4141                 return false;
4142             }
4143             if ( m.getNumberOfIdentifiers() != 5 ) {
4144                 return false;
4145             }
4146             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4147                 return false;
4148             }
4149             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4150                 return false;
4151             }
4152             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4153                 return false;
4154             }
4155             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4156                 return false;
4157             }
4158             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4159                 return false;
4160             }
4161             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4162                 return false;
4163             }
4164             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4165                 return false;
4166             }
4167             //            if ( labels.length != 7 ) {
4168             //                return false;
4169             //            }
4170             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4171             //                return false;
4172             //            }
4173             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4174             //                return false;
4175             //            }
4176             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4177             //                return false;
4178             //            }
4179             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4180             //                return false;
4181             //            }
4182             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4183             //                return false;
4184             //            }
4185             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4186             //                return false;
4187             //            }
4188             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4189             //                return false;
4190             //            }
4191             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4192             //            parser.parse();
4193             //            labels = parser.getCharStateLabels();
4194             //            if ( labels.length != 7 ) {
4195             //                return false;
4196             //            }
4197             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4198             //                return false;
4199             //            }
4200             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4201             //                return false;
4202             //            }
4203             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4204             //                return false;
4205             //            }
4206             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4207             //                return false;
4208             //            }
4209             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4210             //                return false;
4211             //            }
4212             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4213             //                return false;
4214             //            }
4215             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4216             //                return false;
4217             //            }
4218         }
4219         catch ( final Exception e ) {
4220             e.printStackTrace( System.out );
4221             return false;
4222         }
4223         return true;
4224     }
4225
4226     private static boolean testNexusTreeParsing() {
4227         try {
4228             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4229             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4230             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4231             if ( phylogenies.length != 1 ) {
4232                 return false;
4233             }
4234             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4235                 return false;
4236             }
4237             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4238                 return false;
4239             }
4240             phylogenies = null;
4241             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4242             if ( phylogenies.length != 1 ) {
4243                 return false;
4244             }
4245             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4246                 return false;
4247             }
4248             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4249                 return false;
4250             }
4251             phylogenies = null;
4252             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4253             if ( phylogenies.length != 1 ) {
4254                 return false;
4255             }
4256             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4257                 return false;
4258             }
4259             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4260                 return false;
4261             }
4262             if ( phylogenies[ 0 ].isRooted() ) {
4263                 return false;
4264             }
4265             phylogenies = null;
4266             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4267             if ( phylogenies.length != 18 ) {
4268                 return false;
4269             }
4270             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4271                 return false;
4272             }
4273             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4274                 return false;
4275             }
4276             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4277                 return false;
4278             }
4279             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4280                 return false;
4281             }
4282             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4283                 return false;
4284             }
4285             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4286                 return false;
4287             }
4288             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4289                 return false;
4290             }
4291             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4292                 return false;
4293             }
4294             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4295                 return false;
4296             }
4297             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4298                 return false;
4299             }
4300             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4301                 return false;
4302             }
4303             if ( phylogenies[ 8 ].isRooted() ) {
4304                 return false;
4305             }
4306             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4307                 return false;
4308             }
4309             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4310                 return false;
4311             }
4312             if ( !phylogenies[ 9 ].isRooted() ) {
4313                 return false;
4314             }
4315             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4316                 return false;
4317             }
4318             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4319                 return false;
4320             }
4321             if ( !phylogenies[ 10 ].isRooted() ) {
4322                 return false;
4323             }
4324             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4325                 return false;
4326             }
4327             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4328                 return false;
4329             }
4330             if ( phylogenies[ 11 ].isRooted() ) {
4331                 return false;
4332             }
4333             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4334                 return false;
4335             }
4336             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4337                 return false;
4338             }
4339             if ( !phylogenies[ 12 ].isRooted() ) {
4340                 return false;
4341             }
4342             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4343                 return false;
4344             }
4345             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4346                 return false;
4347             }
4348             if ( !phylogenies[ 13 ].isRooted() ) {
4349                 return false;
4350             }
4351             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4352                 return false;
4353             }
4354             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4355                 return false;
4356             }
4357             if ( !phylogenies[ 14 ].isRooted() ) {
4358                 return false;
4359             }
4360             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4361                 return false;
4362             }
4363             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4364                 return false;
4365             }
4366             if ( phylogenies[ 15 ].isRooted() ) {
4367                 return false;
4368             }
4369             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4370                 return false;
4371             }
4372             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4373                 return false;
4374             }
4375             if ( !phylogenies[ 16 ].isRooted() ) {
4376                 return false;
4377             }
4378             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4379                 return false;
4380             }
4381             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4382                 return false;
4383             }
4384             if ( phylogenies[ 17 ].isRooted() ) {
4385                 return false;
4386             }
4387             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4388                 return false;
4389             }
4390         }
4391         catch ( final Exception e ) {
4392             e.printStackTrace( System.out );
4393             return false;
4394         }
4395         return true;
4396     }
4397
4398     private static boolean testNexusTreeParsingTranslating() {
4399         try {
4400             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4401             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4402             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
4403             if ( phylogenies.length != 1 ) {
4404                 return false;
4405             }
4406             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4407                 return false;
4408             }
4409             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4410                 return false;
4411             }
4412             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4413                 return false;
4414             }
4415             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4416                 return false;
4417             }
4418             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4419                     .equals( "Aranaeus" ) ) {
4420                 return false;
4421             }
4422             phylogenies = null;
4423             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
4424             if ( phylogenies.length != 3 ) {
4425                 return false;
4426             }
4427             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4428                 return false;
4429             }
4430             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4431                 return false;
4432             }
4433             if ( phylogenies[ 0 ].isRooted() ) {
4434                 return false;
4435             }
4436             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4437                 return false;
4438             }
4439             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4440                 return false;
4441             }
4442             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4443                     .equals( "Aranaeus" ) ) {
4444                 return false;
4445             }
4446             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
4447                 return false;
4448             }
4449             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
4450                 return false;
4451             }
4452             if ( phylogenies[ 1 ].isRooted() ) {
4453                 return false;
4454             }
4455             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4456                 return false;
4457             }
4458             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4459                 return false;
4460             }
4461             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4462                     .equals( "Aranaeus" ) ) {
4463                 return false;
4464             }
4465             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4466                 return false;
4467             }
4468             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
4469                 return false;
4470             }
4471             if ( !phylogenies[ 2 ].isRooted() ) {
4472                 return false;
4473             }
4474             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4475                 return false;
4476             }
4477             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4478                 return false;
4479             }
4480             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4481                     .equals( "Aranaeus" ) ) {
4482                 return false;
4483             }
4484             phylogenies = null;
4485             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
4486             if ( phylogenies.length != 3 ) {
4487                 return false;
4488             }
4489             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4490                 return false;
4491             }
4492             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4493                 return false;
4494             }
4495             if ( phylogenies[ 0 ].isRooted() ) {
4496                 return false;
4497             }
4498             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4499                 return false;
4500             }
4501             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4502                 return false;
4503             }
4504             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4505                     .equals( "Aranaeus" ) ) {
4506                 return false;
4507             }
4508             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
4509                 return false;
4510             }
4511             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
4512                 return false;
4513             }
4514             if ( phylogenies[ 1 ].isRooted() ) {
4515                 return false;
4516             }
4517             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4518                 return false;
4519             }
4520             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4521                 return false;
4522             }
4523             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4524                     .equals( "Aranaeus" ) ) {
4525                 return false;
4526             }
4527             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4528                 return false;
4529             }
4530             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
4531                 return false;
4532             }
4533             if ( !phylogenies[ 2 ].isRooted() ) {
4534                 return false;
4535             }
4536             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4537                 return false;
4538             }
4539             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4540                 return false;
4541             }
4542             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4543                     .equals( "Aranaeus" ) ) {
4544                 return false;
4545             }
4546         }
4547         catch ( final Exception e ) {
4548             e.printStackTrace( System.out );
4549             return false;
4550         }
4551         return true;
4552     }
4553
4554     private static boolean testNHParsing() {
4555         try {
4556             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4557             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
4558             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
4559                 return false;
4560             }
4561             final NHXParser nhxp = new NHXParser();
4562             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
4563             nhxp.setReplaceUnderscores( true );
4564             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
4565             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
4566                 return false;
4567             }
4568             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
4569                 return false;
4570             }
4571             final Phylogeny p1b = factory
4572                     .create( "   \n  \t  \b   \r \f   ; (  \n  \t  \b   \r \f; A ;  \n  \t  \b   \r \f,  \n  \t  \b   \r \f; B ;   \n  \t  \b   \r \f 1  \n  \t  \b   \r \f ;  \n  \t  \b   \r \f );;;;; \n  \t  \b   \r \f;;;  \n  \t  \b   \r \f ",
4573                              new NHXParser() )[ 0 ];
4574             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
4575                 return false;
4576             }
4577             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
4578                 return false;
4579             }
4580             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
4581             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
4582             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
4583             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
4584             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
4585             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
4586             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
4587             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
4588             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
4589             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
4590             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
4591                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
4592                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
4593                                                     new NHXParser() );
4594             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
4595                 return false;
4596             }
4597             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
4598                 return false;
4599             }
4600             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
4601                 return false;
4602             }
4603             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
4604                 return false;
4605             }
4606             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
4607             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
4608             final String p16_S = "((A,B),C)";
4609             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
4610             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
4611                 return false;
4612             }
4613             final String p17_S = "(C,(A,B))";
4614             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
4615             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
4616                 return false;
4617             }
4618             final String p18_S = "((A,B),(C,D))";
4619             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
4620             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
4621                 return false;
4622             }
4623             final String p19_S = "(((A,B),C),D)";
4624             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
4625             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
4626                 return false;
4627             }
4628             final String p20_S = "(A,(B,(C,D)))";
4629             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
4630             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
4631                 return false;
4632             }
4633             final String p21_S = "(A,(B,(C,(D,E))))";
4634             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
4635             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
4636                 return false;
4637             }
4638             final String p22_S = "((((A,B),C),D),E)";
4639             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
4640             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
4641                 return false;
4642             }
4643             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4644             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
4645             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
4646                 return false;
4647             }
4648             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4649             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
4650             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
4651                 return false;
4652             }
4653             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4654             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4655             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
4656             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
4657                 return false;
4658             }
4659             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
4660                 return false;
4661             }
4662             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
4663                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
4664                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
4665                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
4666                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
4667                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
4668                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
4669                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
4670             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
4671             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
4672                 return false;
4673             }
4674             final String p26_S = "(A,B)ab";
4675             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
4676             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
4677                 return false;
4678             }
4679             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4680             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
4681                                                     new NHXParser() );
4682             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
4683                 return false;
4684             }
4685             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4686             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4687             final String p28_S3 = "(A,B)ab";
4688             final String p28_S4 = "((((A,B),C),D),;E;)";
4689             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
4690                                                     new NHXParser() );
4691             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
4692                 return false;
4693             }
4694             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
4695                 return false;
4696             }
4697             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
4698                 return false;
4699             }
4700             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
4701                 return false;
4702             }
4703             final String p29_S = "((((A:0.01,B:0.684)ab:0.345,C:0.3451)abc:0.3451,D:1.5)abcd:0.134,E:0.32)abcde:0.1345";
4704             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
4705             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
4706                 return false;
4707             }
4708             final String p30_S = "((((A:0.01,B:0.02):0.93,C:0.04):0.05,D:1.4):0.06,E):0.72";
4709             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
4710             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
4711                 return false;
4712             }
4713             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
4714             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
4715             if ( ( p32.length != 1 ) || !p32[ 0 ].isEmpty() ) {
4716                 return false;
4717             }
4718             final String p33_S = "A";
4719             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
4720             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
4721                 return false;
4722             }
4723             final String p34_S = "B;";
4724             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
4725             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
4726                 return false;
4727             }
4728             final String p35_S = "B:0.2";
4729             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
4730             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
4731                 return false;
4732             }
4733             final String p36_S = "(A)";
4734             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
4735             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
4736                 return false;
4737             }
4738             final String p37_S = "((A))";
4739             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
4740             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
4741                 return false;
4742             }
4743             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
4744             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
4745             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
4746                 return false;
4747             }
4748             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
4749             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
4750             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
4751                 return false;
4752             }
4753             final String p40_S = "(A,B,C)";
4754             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
4755             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
4756                 return false;
4757             }
4758             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
4759             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
4760             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
4761                 return false;
4762             }
4763             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
4764             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
4765             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
4766                 return false;
4767             }
4768             final String p43_S = "(A,B,C,(AA,BB,CC,(CCC,DDD,EEE,(FFFF,GGGG)x)y,DD,EE,FF,GG,HH),D,E,(EE,FF),F,G,H,(((((5)4)3)2)1),I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,(XX,(YY)),Y,Z)";
4769             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
4770             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
4771                 return false;
4772             }
4773             final String p44_S = "(((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)),((A,B,C,D),(A,B,C,D),(A,B,C,D),(A,B,C,D)))";
4774             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
4775             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
4776                 return false;
4777             }
4778             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
4779             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
4780             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
4781                 return false;
4782             }
4783             final String p46_S = "";
4784             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
4785             if ( ( p46.length != 1 ) || !p46[ 0 ].isEmpty() ) {
4786                 return false;
4787             }
4788             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
4789             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4790                 return false;
4791             }
4792             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4793             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4794                 return false;
4795             }
4796             final Phylogeny p49 = factory
4797                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
4798                              new NHXParser() )[ 0 ];
4799             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4800                 return false;
4801             }
4802             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4803             if ( p50.getNode( "A" ) == null ) {
4804                 return false;
4805             }
4806             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
4807                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
4808                 return false;
4809             }
4810             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
4811                 return false;
4812             }
4813             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
4814                     .equals( "((A,B)88:2.0,C);" ) ) {
4815                 return false;
4816             }
4817             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4818             if ( p51.getNode( "A(A" ) == null ) {
4819                 return false;
4820             }
4821             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4822             if ( p52.getNode( "A(A" ) == null ) {
4823                 return false;
4824             }
4825             final Phylogeny p53 = factory
4826                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
4827                              new NHXParser() )[ 0 ];
4828             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
4829                 return false;
4830             }
4831             // 
4832             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
4833             if ( p54.getNode( "A" ) == null ) {
4834                 return false;
4835             }
4836             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
4837                     .equals( "((A,B)[88],C);" ) ) {
4838                 return false;
4839             }
4840         }
4841         catch ( final Exception e ) {
4842             e.printStackTrace( System.out );
4843             return false;
4844         }
4845         return true;
4846     }
4847
4848     private static boolean testNHXconversion() {
4849         try {
4850             final PhylogenyNode n1 = new PhylogenyNode();
4851             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
4852             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
4853             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
4854             final PhylogenyNode n5 = PhylogenyNode
4855                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1:W=2:C=10.20.30:XN=S=tag1=value1=unit1]" );
4856             final PhylogenyNode n6 = PhylogenyNode
4857                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1:W=2:C=0.0.0:XN=B=bool_tag=T]" );
4858             if ( !n1.toNewHampshireX().equals( "" ) ) {
4859                 return false;
4860             }
4861             if ( !n2.toNewHampshireX().equals( "" ) ) {
4862                 return false;
4863             }
4864             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
4865                 return false;
4866             }
4867             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
4868                 return false;
4869             }
4870             if ( !n5.toNewHampshireX()
4871                     .equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:XN=S=tag1=value1=unit1:B=56:W=2.0:C=10.20.30]" ) ) {
4872                 return false;
4873             }
4874             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:XN=B=bool_tag=T:B=100:W=2.0:C=0.0.0]" ) ) {
4875                 return false;
4876             }
4877         }
4878         catch ( final Exception e ) {
4879             e.printStackTrace( System.out );
4880             return false;
4881         }
4882         return true;
4883     }
4884
4885     private static boolean testNHXNodeParsing() {
4886         try {
4887             final PhylogenyNode n1 = new PhylogenyNode();
4888             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
4889             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
4890             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
4891             final PhylogenyNode n5 = PhylogenyNode
4892                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:B=56:T=1:On=22:SOn=33:SNn=44:W=2:C=10.20.30:XN=S=tag1=value1=unit1:XN=S=tag3=value3=unit3]" );
4893             if ( !n3.getName().equals( "n3" ) ) {
4894                 return false;
4895             }
4896             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
4897                 return false;
4898             }
4899             if ( n3.isDuplication() ) {
4900                 return false;
4901             }
4902             if ( n3.isHasAssignedEvent() ) {
4903                 return false;
4904             }
4905             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
4906                 return false;
4907             }
4908             if ( !n4.getName().equals( "n4" ) ) {
4909                 return false;
4910             }
4911             if ( n4.getDistanceToParent() != 0.01 ) {
4912                 return false;
4913             }
4914             if ( !n5.getName().equals( "n5" ) ) {
4915                 return false;
4916             }
4917             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
4918                 return false;
4919             }
4920             if ( n5.getDistanceToParent() != 0.1 ) {
4921                 return false;
4922             }
4923             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
4924                 return false;
4925             }
4926             if ( !n5.isDuplication() ) {
4927                 return false;
4928             }
4929             if ( !n5.isHasAssignedEvent() ) {
4930                 return false;
4931             }
4932             if ( PhylogenyMethods.getBranchWidthValue( n5 ) != 2 ) {
4933                 return false;
4934             }
4935             if ( n5.getNodeData().getProperties().getPropertyRefs().length != 2 ) {
4936                 return false;
4937             }
4938             final PhylogenyNode n8 = PhylogenyNode
4939                     .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4940             if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
4941                 return false;
4942             }
4943             if ( PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
4944                 return false;
4945             }
4946             final PhylogenyNode n9 = PhylogenyNode
4947                     .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4948             if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
4949                 return false;
4950             }
4951             if ( PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
4952                 return false;
4953             }
4954             final PhylogenyNode n10 = PhylogenyNode
4955                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4956             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
4957                 return false;
4958             }
4959             final PhylogenyNode n20 = PhylogenyNode
4960                     .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4961             if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
4962                 return false;
4963             }
4964             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
4965                 return false;
4966             }
4967             final PhylogenyNode n20x = PhylogenyNode.createInstanceFromNhxString( "n20_ECOL1/1-2",
4968                                                                                   NHXParser.TAXONOMY_EXTRACTION.YES );
4969             if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
4970                 return false;
4971             }
4972             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
4973                 return false;
4974             }
4975             final PhylogenyNode n20xx = PhylogenyNode
4976                     .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4977             if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
4978                 return false;
4979             }
4980             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
4981                 return false;
4982             }
4983             final PhylogenyNode n20xxx = PhylogenyNode
4984                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4985             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
4986                 return false;
4987             }
4988             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
4989                 return false;
4990             }
4991             final PhylogenyNode n20xxxx = PhylogenyNode
4992                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4993             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
4994                 return false;
4995             }
4996             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
4997                 return false;
4998             }
4999             final PhylogenyNode n21 = PhylogenyNode.createInstanceFromNhxString( "n21_PIG",
5000                                                                                  NHXParser.TAXONOMY_EXTRACTION.YES );
5001             if ( !n21.getName().equals( "n21_PIG" ) ) {
5002                 return false;
5003             }
5004             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
5005                 return false;
5006             }
5007             final PhylogenyNode n21x = PhylogenyNode
5008                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5009             if ( !n21x.getName().equals( "n21_PIG" ) ) {
5010                 return false;
5011             }
5012             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
5013                 return false;
5014             }
5015             final PhylogenyNode n22 = PhylogenyNode
5016                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5017             if ( !n22.getName().equals( "n22/PIG" ) ) {
5018                 return false;
5019             }
5020             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
5021                 return false;
5022             }
5023             final PhylogenyNode n23 = PhylogenyNode
5024                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5025             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
5026                 return false;
5027             }
5028             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
5029                 return false;
5030             }
5031             final PhylogenyNode a = PhylogenyNode
5032                     .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5033             if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
5034                 return false;
5035             }
5036             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
5037                 return false;
5038             }
5039             final PhylogenyNode b = PhylogenyNode
5040                     .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5041             if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
5042                 return false;
5043             }
5044             if ( PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
5045                 return false;
5046             }
5047             final PhylogenyNode c = PhylogenyNode
5048                     .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
5049                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5050             if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
5051                 return false;
5052             }
5053             if ( PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
5054                 return false;
5055             }
5056             final PhylogenyNode c1 = PhylogenyNode
5057                     .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
5058                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5059             if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
5060                 return false;
5061             }
5062             if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
5063                 return false;
5064             }
5065             final PhylogenyNode c2 = PhylogenyNode
5066                     .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
5067                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5068             if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
5069                 return false;
5070             }
5071             if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
5072                 return false;
5073             }
5074             final PhylogenyNode d = PhylogenyNode
5075                     .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5076             if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
5077                 return false;
5078             }
5079             if ( PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
5080                 return false;
5081             }
5082             final PhylogenyNode e = PhylogenyNode
5083                     .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5084             if ( !e.getName().equals( "n10_RAT1" ) ) {
5085                 return false;
5086             }
5087             if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
5088                 return false;
5089             }
5090             final PhylogenyNode e2 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT1",
5091                                                                                 NHXParser.TAXONOMY_EXTRACTION.YES );
5092             if ( !e2.getName().equals( "n10_RAT1" ) ) {
5093                 return false;
5094             }
5095             if ( !PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
5096                 return false;
5097             }
5098             final PhylogenyNode e3 = PhylogenyNode.createInstanceFromNhxString( "n10_RAT~",
5099                                                                                 NHXParser.TAXONOMY_EXTRACTION.YES );
5100             if ( !e3.getName().equals( "n10_RAT~" ) ) {
5101                 return false;
5102             }
5103             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
5104                 return false;
5105             }
5106             final PhylogenyNode n11 = PhylogenyNode
5107                     .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
5108                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5109             if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
5110                 return false;
5111             }
5112             if ( n11.getDistanceToParent() != 0.4 ) {
5113                 return false;
5114             }
5115             if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
5116                 return false;
5117             }
5118             final PhylogenyNode n12 = PhylogenyNode
5119                     .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
5120                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5121             if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
5122                 return false;
5123             }
5124             if ( n12.getDistanceToParent() != 0.4 ) {
5125                 return false;
5126             }
5127             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
5128                 return false;
5129             }
5130             final PhylogenyNode m = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSEa",
5131                                                                                NHXParser.TAXONOMY_EXTRACTION.YES );
5132             if ( !m.getName().equals( "n10_MOUSEa" ) ) {
5133                 return false;
5134             }
5135             if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
5136                 return false;
5137             }
5138             final PhylogenyNode o = PhylogenyNode.createInstanceFromNhxString( "n10_MOUSE_",
5139                                                                                NHXParser.TAXONOMY_EXTRACTION.YES );
5140             if ( !o.getName().equals( "n10_MOUSE_" ) ) {
5141                 return false;
5142             }
5143             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
5144                 return false;
5145             }
5146             final Property tvu1 = n5.getNodeData().getProperties().getProperty( "tag1" );
5147             final Property tvu3 = n5.getNodeData().getProperties().getProperty( "tag3" );
5148             if ( !tvu1.getRef().equals( "tag1" ) ) {
5149                 return false;
5150             }
5151             if ( !tvu1.getDataType().equals( "xsd:string" ) ) {
5152                 return false;
5153             }
5154             if ( !tvu1.getUnit().equals( "unit1" ) ) {
5155                 return false;
5156             }
5157             if ( !tvu1.getValue().equals( "value1" ) ) {
5158                 return false;
5159             }
5160             if ( !tvu3.getRef().equals( "tag3" ) ) {
5161                 return false;
5162             }
5163             if ( !tvu3.getDataType().equals( "xsd:string" ) ) {
5164                 return false;
5165             }
5166             if ( !tvu3.getUnit().equals( "unit3" ) ) {
5167                 return false;
5168             }
5169             if ( !tvu3.getValue().equals( "value3" ) ) {
5170                 return false;
5171             }
5172             if ( n1.getName().compareTo( "" ) != 0 ) {
5173                 return false;
5174             }
5175             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5176                 return false;
5177             }
5178             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
5179                 return false;
5180             }
5181             if ( n2.getName().compareTo( "" ) != 0 ) {
5182                 return false;
5183             }
5184             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5185                 return false;
5186             }
5187             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
5188                 return false;
5189             }
5190             final PhylogenyNode n00 = PhylogenyNode
5191                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:ID=node_identifier:S=Ecoli:D=N:Co=N:B=100:T=1:On=100:SOn=100:SNn=100:W=2:C=0.0.0:XN=U=url_tag=www.yahoo.com]" );
5192             if ( !n00.getNodeData().getNodeIdentifier().getValue().equals( "node_identifier" ) ) {
5193                 return false;
5194             }
5195             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
5196                 return false;
5197             }
5198             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
5199                 return false;
5200             }
5201             if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getRef().equals( "url_tag" ) ) {
5202                 return false;
5203             }
5204             if ( n00.getNodeData().getProperties().getProperty( "url_tag" ).getAppliesTo() != Property.AppliesTo.NODE ) {
5205                 return false;
5206             }
5207             if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getDataType().equals( "xsd:anyURI" ) ) {
5208                 return false;
5209             }
5210             if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getValue().equals( "www.yahoo.com" ) ) {
5211                 return false;
5212             }
5213             if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getUnit().equals( "" ) ) {
5214                 return false;
5215             }
5216             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
5217             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
5218                 return false;
5219             }
5220             final PhylogenyNode nx2 = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:G=gene_2]" );
5221             if ( !nx2.getNodeData().getSequence().getName().equals( "gene_2" ) ) {
5222                 return false;
5223             }
5224             final PhylogenyNode n13 = PhylogenyNode
5225                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5226             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
5227                 return false;
5228             }
5229             if ( !PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
5230                 return false;
5231             }
5232             final PhylogenyNode n14 = PhylogenyNode
5233                     .createInstanceFromNhxString( "blah_12X45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5234             if ( !n14.getName().equals( "blah_12X45/1-2" ) ) {
5235                 return false;
5236             }
5237             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "12X45" ) ) {
5238                 return false;
5239             }
5240             final PhylogenyNode n15 = PhylogenyNode
5241                     .createInstanceFromNhxString( "something_wicked[123]",
5242                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5243             if ( !n15.getName().equals( "something_wicked" ) ) {
5244                 return false;
5245             }
5246             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
5247                 return false;
5248             }
5249             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
5250                 return false;
5251             }
5252             final PhylogenyNode n16 = PhylogenyNode
5253                     .createInstanceFromNhxString( "something_wicked2[9]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5254             if ( !n16.getName().equals( "something_wicked2" ) ) {
5255                 return false;
5256             }
5257             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
5258                 return false;
5259             }
5260             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
5261                 return false;
5262             }
5263             final PhylogenyNode n17 = PhylogenyNode
5264                     .createInstanceFromNhxString( "something_wicked3[a]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5265             if ( !n17.getName().equals( "something_wicked3" ) ) {
5266                 return false;
5267             }
5268             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
5269                 return false;
5270             }
5271             final PhylogenyNode n18 = PhylogenyNode
5272                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5273             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
5274                 return false;
5275             }
5276             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
5277                 return false;
5278             }
5279             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
5280                 return false;
5281             }
5282         }
5283         catch ( final Exception e ) {
5284             e.printStackTrace( System.out );
5285             return false;
5286         }
5287         return true;
5288     }
5289
5290     private static boolean testNHXParsing() {
5291         try {
5292             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5293             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
5294             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
5295                 return false;
5296             }
5297             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]";
5298             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
5299             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5300                 return false;
5301             }
5302             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]";
5303             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
5304             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
5305                 return false;
5306             }
5307             final Phylogeny[] p3 = factory
5308                     .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]",
5309                              new NHXParser() );
5310             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5311                 return false;
5312             }
5313             final Phylogeny[] p4 = factory
5314                     .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(]",
5315                              new NHXParser() );
5316             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5317                 return false;
5318             }
5319             final Phylogeny[] p5 = factory
5320                     .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(((]",
5321                              new NHXParser() );
5322             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5323                 return false;
5324             }
5325             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)";
5326             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)";
5327             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
5328             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
5329                 return false;
5330             }
5331             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)))";
5332             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)))";
5333             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
5334             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
5335                 return false;
5336             }
5337             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])   ))[,,, ])))))))";
5338             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
5339             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
5340             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
5341                 return false;
5342             }
5343             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
5344             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
5345                 return false;
5346             }
5347             final Phylogeny p10 = factory
5348                     .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]",
5349                              new NHXParser() )[ 0 ];
5350             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
5351                 return false;
5352             }
5353         }
5354         catch ( final Exception e ) {
5355             e.printStackTrace( System.out );
5356             return false;
5357         }
5358         return true;
5359     }
5360
5361     private static boolean testNHXParsingQuotes() {
5362         try {
5363             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5364             final NHXParser p = new NHXParser();
5365             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
5366             if ( phylogenies_0.length != 5 ) {
5367                 return false;
5368             }
5369             final Phylogeny phy = phylogenies_0[ 4 ];
5370             if ( phy.getNumberOfExternalNodes() != 7 ) {
5371                 return false;
5372             }
5373             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
5374                 return false;
5375             }
5376             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
5377                 return false;
5378             }
5379             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
5380                     .getScientificName().equals( "hsapiens" ) ) {
5381                 return false;
5382             }
5383             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
5384                 return false;
5385             }
5386             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
5387                 return false;
5388             }
5389             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
5390                 return false;
5391             }
5392             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
5393                 return false;
5394             }
5395             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
5396                 return false;
5397             }
5398             final NHXParser p1p = new NHXParser();
5399             p1p.setIgnoreQuotes( true );
5400             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
5401             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
5402                 return false;
5403             }
5404             final NHXParser p2p = new NHXParser();
5405             p1p.setIgnoreQuotes( false );
5406             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
5407             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
5408                 return false;
5409             }
5410             final NHXParser p3p = new NHXParser();
5411             p3p.setIgnoreQuotes( false );
5412             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
5413             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
5414                 return false;
5415             }
5416             final NHXParser p4p = new NHXParser();
5417             p4p.setIgnoreQuotes( false );
5418             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
5419             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
5420                 return false;
5421             }
5422             final Phylogeny p10 = factory
5423                     .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]",
5424                              new NHXParser() )[ 0 ];
5425             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]";
5426             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
5427                 return false;
5428             }
5429             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
5430             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
5431                 return false;
5432             }
5433             //
5434             final Phylogeny p12 = factory
5435                     .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]",
5436                              new NHXParser() )[ 0 ];
5437             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]";
5438             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
5439                 return false;
5440             }
5441             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
5442             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
5443                 return false;
5444             }
5445             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;";
5446             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
5447                 return false;
5448             }
5449             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
5450             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
5451                 return false;
5452             }
5453         }
5454         catch ( final Exception e ) {
5455             e.printStackTrace( System.out );
5456             return false;
5457         }
5458         return true;
5459     }
5460
5461     private static boolean testNHXParsingMB() {
5462         try {
5463             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5464             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
5465                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5466                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
5467                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
5468                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
5469                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5470                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
5471                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
5472                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
5473             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
5474                 return false;
5475             }
5476             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
5477                 return false;
5478             }
5479             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
5480                            0.1100000000000000e+00 ) ) {
5481                 return false;
5482             }
5483             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
5484                 return false;
5485             }
5486             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
5487                 return false;
5488             }
5489             final Phylogeny p2 = factory
5490                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
5491                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5492                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
5493                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
5494                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
5495                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5496                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
5497                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
5498                                      + "7.369400000000000e-02}])",
5499                              new NHXParser() )[ 0 ];
5500             if ( p2.getNode( "1" ) == null ) {
5501                 return false;
5502             }
5503             if ( p2.getNode( "2" ) == null ) {
5504                 return false;
5505             }
5506         }
5507         catch ( final Exception e ) {
5508             e.printStackTrace( System.out );
5509             System.exit( -1 );
5510             return false;
5511         }
5512         return true;
5513     }
5514
5515     private static boolean testPhylogenyBranch() {
5516         try {
5517             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
5518             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
5519             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
5520             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
5521             if ( !a1b1.equals( a1b1 ) ) {
5522                 return false;
5523             }
5524             if ( !a1b1.equals( b1a1 ) ) {
5525                 return false;
5526             }
5527             if ( !b1a1.equals( a1b1 ) ) {
5528                 return false;
5529             }
5530             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
5531             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
5532             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
5533             if ( a1_b1.equals( b1_a1 ) ) {
5534                 return false;
5535             }
5536             if ( a1_b1.equals( a1_b1_ ) ) {
5537                 return false;
5538             }
5539             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
5540             if ( !a1_b1.equals( b1_a1_ ) ) {
5541                 return false;
5542             }
5543             if ( a1_b1_.equals( b1_a1_ ) ) {
5544                 return false;
5545             }
5546             if ( !a1_b1_.equals( b1_a1 ) ) {
5547                 return false;
5548             }
5549         }
5550         catch ( final Exception e ) {
5551             e.printStackTrace( System.out );
5552             return false;
5553         }
5554         return true;
5555     }
5556
5557     private static boolean testPhyloXMLparsingOfDistributionElement() {
5558         try {
5559             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5560             PhyloXmlParser xml_parser = null;
5561             try {
5562                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
5563             }
5564             catch ( final Exception e ) {
5565                 // Do nothing -- means were not running from jar.
5566             }
5567             if ( xml_parser == null ) {
5568                 xml_parser = new PhyloXmlParser();
5569                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
5570                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
5571                 }
5572                 else {
5573                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
5574                 }
5575             }
5576             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
5577                                                               xml_parser );
5578             if ( xml_parser.getErrorCount() > 0 ) {
5579                 System.out.println( xml_parser.getErrorMessages().toString() );
5580                 return false;
5581             }
5582             if ( phylogenies_0.length != 1 ) {
5583                 return false;
5584             }
5585             final Phylogeny t1 = phylogenies_0[ 0 ];
5586             PhylogenyNode n = null;
5587             Distribution d = null;
5588             n = t1.getNode( "root node" );
5589             if ( !n.getNodeData().isHasDistribution() ) {
5590                 return false;
5591             }
5592             if ( n.getNodeData().getDistributions().size() != 1 ) {
5593                 return false;
5594             }
5595             d = n.getNodeData().getDistribution();
5596             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
5597                 return false;
5598             }
5599             if ( d.getPoints().size() != 1 ) {
5600                 return false;
5601             }
5602             if ( d.getPolygons() != null ) {
5603                 return false;
5604             }
5605             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
5606                 return false;
5607             }
5608             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5609                 return false;
5610             }
5611             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5612                 return false;
5613             }
5614             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
5615                 return false;
5616             }
5617             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
5618                 return false;
5619             }
5620             n = t1.getNode( "node a" );
5621             if ( !n.getNodeData().isHasDistribution() ) {
5622                 return false;
5623             }
5624             if ( n.getNodeData().getDistributions().size() != 2 ) {
5625                 return false;
5626             }
5627             d = n.getNodeData().getDistribution( 1 );
5628             if ( !d.getDesc().equals( "San Diego" ) ) {
5629                 return false;
5630             }
5631             if ( d.getPoints().size() != 1 ) {
5632                 return false;
5633             }
5634             if ( d.getPolygons() != null ) {
5635                 return false;
5636             }
5637             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
5638                 return false;
5639             }
5640             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5641                 return false;
5642             }
5643             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5644                 return false;
5645             }
5646             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
5647                 return false;
5648             }
5649             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
5650                 return false;
5651             }
5652             n = t1.getNode( "node bb" );
5653             if ( !n.getNodeData().isHasDistribution() ) {
5654                 return false;
5655             }
5656             if ( n.getNodeData().getDistributions().size() != 1 ) {
5657                 return false;
5658             }
5659             d = n.getNodeData().getDistribution( 0 );
5660             if ( d.getPoints().size() != 3 ) {
5661                 return false;
5662             }
5663             if ( d.getPolygons().size() != 2 ) {
5664                 return false;
5665             }
5666             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
5667                 return false;
5668             }
5669             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
5670                 return false;
5671             }
5672             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
5673                 return false;
5674             }
5675             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
5676                 return false;
5677             }
5678             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
5679                 return false;
5680             }
5681             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
5682                 return false;
5683             }
5684             Polygon p = d.getPolygons().get( 0 );
5685             if ( p.getPoints().size() != 3 ) {
5686                 return false;
5687             }
5688             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
5689                 return false;
5690             }
5691             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
5692                 return false;
5693             }
5694             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5695                 return false;
5696             }
5697             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
5698                 return false;
5699             }
5700             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
5701                 return false;
5702             }
5703             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
5704                 return false;
5705             }
5706             p = d.getPolygons().get( 1 );
5707             if ( p.getPoints().size() != 3 ) {
5708                 return false;
5709             }
5710             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
5711                 return false;
5712             }
5713             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
5714                 return false;
5715             }
5716             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5717                 return false;
5718             }
5719             // Roundtrip:
5720             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
5721             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
5722             if ( rt.length != 1 ) {
5723                 return false;
5724             }
5725             final Phylogeny t1_rt = rt[ 0 ];
5726             n = t1_rt.getNode( "root node" );
5727             if ( !n.getNodeData().isHasDistribution() ) {
5728                 return false;
5729             }
5730             if ( n.getNodeData().getDistributions().size() != 1 ) {
5731                 return false;
5732             }
5733             d = n.getNodeData().getDistribution();
5734             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
5735                 return false;
5736             }
5737             if ( d.getPoints().size() != 1 ) {
5738                 return false;
5739             }
5740             if ( d.getPolygons() != null ) {
5741                 return false;
5742             }
5743             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
5744                 return false;
5745             }
5746             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5747                 return false;
5748             }
5749             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5750                 return false;
5751             }
5752             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
5753                 return false;
5754             }
5755             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
5756                 return false;
5757             }
5758             n = t1_rt.getNode( "node a" );
5759             if ( !n.getNodeData().isHasDistribution() ) {
5760                 return false;
5761             }
5762             if ( n.getNodeData().getDistributions().size() != 2 ) {
5763                 return false;
5764             }
5765             d = n.getNodeData().getDistribution( 1 );
5766             if ( !d.getDesc().equals( "San Diego" ) ) {
5767                 return false;
5768             }
5769             if ( d.getPoints().size() != 1 ) {
5770                 return false;
5771             }
5772             if ( d.getPolygons() != null ) {
5773                 return false;
5774             }
5775             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
5776                 return false;
5777             }
5778             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5779                 return false;
5780             }
5781             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5782                 return false;
5783             }
5784             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
5785                 return false;
5786             }
5787             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
5788                 return false;
5789             }
5790             n = t1_rt.getNode( "node bb" );
5791             if ( !n.getNodeData().isHasDistribution() ) {
5792                 return false;
5793             }
5794             if ( n.getNodeData().getDistributions().size() != 1 ) {
5795                 return false;
5796             }
5797             d = n.getNodeData().getDistribution( 0 );
5798             if ( d.getPoints().size() != 3 ) {
5799                 return false;
5800             }
5801             if ( d.getPolygons().size() != 2 ) {
5802                 return false;
5803             }
5804             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
5805                 return false;
5806             }
5807             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
5808                 return false;
5809             }
5810             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
5811                 return false;
5812             }
5813             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
5814                 return false;
5815             }
5816             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
5817                 return false;
5818             }
5819             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
5820                 return false;
5821             }
5822             p = d.getPolygons().get( 0 );
5823             if ( p.getPoints().size() != 3 ) {
5824                 return false;
5825             }
5826             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
5827                 return false;
5828             }
5829             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
5830                 return false;
5831             }
5832             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5833                 return false;
5834             }
5835             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
5836                 return false;
5837             }
5838             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
5839                 return false;
5840             }
5841             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
5842                 return false;
5843             }
5844             p = d.getPolygons().get( 1 );
5845             if ( p.getPoints().size() != 3 ) {
5846                 return false;
5847             }
5848             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
5849                 return false;
5850             }
5851             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
5852                 return false;
5853             }
5854             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5855                 return false;
5856             }
5857         }
5858         catch ( final Exception e ) {
5859             e.printStackTrace( System.out );
5860             return false;
5861         }
5862         return true;
5863     }
5864
5865     private static boolean testPostOrderIterator() {
5866         try {
5867             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5868             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5869             PhylogenyNodeIterator it0;
5870             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
5871                 it0.next();
5872             }
5873             for( it0.reset(); it0.hasNext(); ) {
5874                 it0.next();
5875             }
5876             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
5877             final PhylogenyNodeIterator it = t1.iteratorPostorder();
5878             if ( !it.next().getName().equals( "A" ) ) {
5879                 return false;
5880             }
5881             if ( !it.next().getName().equals( "B" ) ) {
5882                 return false;
5883             }
5884             if ( !it.next().getName().equals( "ab" ) ) {
5885                 return false;
5886             }
5887             if ( !it.next().getName().equals( "C" ) ) {
5888                 return false;
5889             }
5890             if ( !it.next().getName().equals( "D" ) ) {
5891                 return false;
5892             }
5893             if ( !it.next().getName().equals( "cd" ) ) {
5894                 return false;
5895             }
5896             if ( !it.next().getName().equals( "abcd" ) ) {
5897                 return false;
5898             }
5899             if ( !it.next().getName().equals( "E" ) ) {
5900                 return false;
5901             }
5902             if ( !it.next().getName().equals( "F" ) ) {
5903                 return false;
5904             }
5905             if ( !it.next().getName().equals( "ef" ) ) {
5906                 return false;
5907             }
5908             if ( !it.next().getName().equals( "G" ) ) {
5909                 return false;
5910             }
5911             if ( !it.next().getName().equals( "H" ) ) {
5912                 return false;
5913             }
5914             if ( !it.next().getName().equals( "gh" ) ) {
5915                 return false;
5916             }
5917             if ( !it.next().getName().equals( "efgh" ) ) {
5918                 return false;
5919             }
5920             if ( !it.next().getName().equals( "r" ) ) {
5921                 return false;
5922             }
5923             if ( it.hasNext() ) {
5924                 return false;
5925             }
5926         }
5927         catch ( final Exception e ) {
5928             e.printStackTrace( System.out );
5929             return false;
5930         }
5931         return true;
5932     }
5933
5934     private static boolean testPreOrderIterator() {
5935         try {
5936             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5937             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5938             PhylogenyNodeIterator it0;
5939             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
5940                 it0.next();
5941             }
5942             for( it0.reset(); it0.hasNext(); ) {
5943                 it0.next();
5944             }
5945             PhylogenyNodeIterator it = t0.iteratorPreorder();
5946             if ( !it.next().getName().equals( "r" ) ) {
5947                 return false;
5948             }
5949             if ( !it.next().getName().equals( "ab" ) ) {
5950                 return false;
5951             }
5952             if ( !it.next().getName().equals( "A" ) ) {
5953                 return false;
5954             }
5955             if ( !it.next().getName().equals( "B" ) ) {
5956                 return false;
5957             }
5958             if ( !it.next().getName().equals( "cd" ) ) {
5959                 return false;
5960             }
5961             if ( !it.next().getName().equals( "C" ) ) {
5962                 return false;
5963             }
5964             if ( !it.next().getName().equals( "D" ) ) {
5965                 return false;
5966             }
5967             if ( it.hasNext() ) {
5968                 return false;
5969             }
5970             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
5971             it = t1.iteratorPreorder();
5972             if ( !it.next().getName().equals( "r" ) ) {
5973                 return false;
5974             }
5975             if ( !it.next().getName().equals( "abcd" ) ) {
5976                 return false;
5977             }
5978             if ( !it.next().getName().equals( "ab" ) ) {
5979                 return false;
5980             }
5981             if ( !it.next().getName().equals( "A" ) ) {
5982                 return false;
5983             }
5984             if ( !it.next().getName().equals( "B" ) ) {
5985                 return false;
5986             }
5987             if ( !it.next().getName().equals( "cd" ) ) {
5988                 return false;
5989             }
5990             if ( !it.next().getName().equals( "C" ) ) {
5991                 return false;
5992             }
5993             if ( !it.next().getName().equals( "D" ) ) {
5994                 return false;
5995             }
5996             if ( !it.next().getName().equals( "efgh" ) ) {
5997                 return false;
5998             }
5999             if ( !it.next().getName().equals( "ef" ) ) {
6000                 return false;
6001             }
6002             if ( !it.next().getName().equals( "E" ) ) {
6003                 return false;
6004             }
6005             if ( !it.next().getName().equals( "F" ) ) {
6006                 return false;
6007             }
6008             if ( !it.next().getName().equals( "gh" ) ) {
6009                 return false;
6010             }
6011             if ( !it.next().getName().equals( "G" ) ) {
6012                 return false;
6013             }
6014             if ( !it.next().getName().equals( "H" ) ) {
6015                 return false;
6016             }
6017             if ( it.hasNext() ) {
6018                 return false;
6019             }
6020         }
6021         catch ( final Exception e ) {
6022             e.printStackTrace( System.out );
6023             return false;
6024         }
6025         return true;
6026     }
6027
6028     private static boolean testPropertiesMap() {
6029         try {
6030             final PropertiesMap pm = new PropertiesMap();
6031             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
6032             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
6033             final Property p2 = new Property( "something:else",
6034                                               "?",
6035                                               "improbable:research",
6036                                               "xsd:decimal",
6037                                               AppliesTo.NODE );
6038             pm.addProperty( p0 );
6039             pm.addProperty( p1 );
6040             pm.addProperty( p2 );
6041             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
6042                 return false;
6043             }
6044             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
6045                 return false;
6046             }
6047             if ( pm.getProperties().size() != 3 ) {
6048                 return false;
6049             }
6050             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
6051                 return false;
6052             }
6053             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
6054                 return false;
6055             }
6056             if ( pm.getProperties().size() != 3 ) {
6057                 return false;
6058             }
6059             pm.removeProperty( "dimensions:diameter" );
6060             if ( pm.getProperties().size() != 2 ) {
6061                 return false;
6062             }
6063             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
6064                 return false;
6065             }
6066             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
6067                 return false;
6068             }
6069         }
6070         catch ( final Exception e ) {
6071             e.printStackTrace( System.out );
6072             return false;
6073         }
6074         return true;
6075     }
6076
6077     private static boolean testReIdMethods() {
6078         try {
6079             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6080             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
6081             final int count = PhylogenyNode.getNodeCount();
6082             p.levelOrderReID();
6083             if ( p.getNode( "r" ).getId() != count ) {
6084                 return false;
6085             }
6086             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
6087                 return false;
6088             }
6089             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
6090                 return false;
6091             }
6092             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
6093                 return false;
6094             }
6095             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
6096                 return false;
6097             }
6098             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
6099                 return false;
6100             }
6101             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
6102                 return false;
6103             }
6104             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
6105                 return false;
6106             }
6107             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
6108                 return false;
6109             }
6110             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
6111                 return false;
6112             }
6113             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
6114                 return false;
6115             }
6116             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
6117                 return false;
6118             }
6119             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
6120                 return false;
6121             }
6122             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
6123                 return false;
6124             }
6125             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
6126                 return false;
6127             }
6128         }
6129         catch ( final Exception e ) {
6130             e.printStackTrace( System.out );
6131             return false;
6132         }
6133         return true;
6134     }
6135
6136     private static boolean testRerooting() {
6137         try {
6138             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6139             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",
6140                                                  new NHXParser() )[ 0 ];
6141             if ( !t1.isRooted() ) {
6142                 return false;
6143             }
6144             t1.reRoot( t1.getNode( "D" ) );
6145             t1.reRoot( t1.getNode( "CD" ) );
6146             t1.reRoot( t1.getNode( "A" ) );
6147             t1.reRoot( t1.getNode( "B" ) );
6148             t1.reRoot( t1.getNode( "AB" ) );
6149             t1.reRoot( t1.getNode( "D" ) );
6150             t1.reRoot( t1.getNode( "C" ) );
6151             t1.reRoot( t1.getNode( "CD" ) );
6152             t1.reRoot( t1.getNode( "A" ) );
6153             t1.reRoot( t1.getNode( "B" ) );
6154             t1.reRoot( t1.getNode( "AB" ) );
6155             t1.reRoot( t1.getNode( "D" ) );
6156             t1.reRoot( t1.getNode( "D" ) );
6157             t1.reRoot( t1.getNode( "C" ) );
6158             t1.reRoot( t1.getNode( "A" ) );
6159             t1.reRoot( t1.getNode( "B" ) );
6160             t1.reRoot( t1.getNode( "AB" ) );
6161             t1.reRoot( t1.getNode( "C" ) );
6162             t1.reRoot( t1.getNode( "D" ) );
6163             t1.reRoot( t1.getNode( "CD" ) );
6164             t1.reRoot( t1.getNode( "D" ) );
6165             t1.reRoot( t1.getNode( "A" ) );
6166             t1.reRoot( t1.getNode( "B" ) );
6167             t1.reRoot( t1.getNode( "AB" ) );
6168             t1.reRoot( t1.getNode( "C" ) );
6169             t1.reRoot( t1.getNode( "D" ) );
6170             t1.reRoot( t1.getNode( "CD" ) );
6171             t1.reRoot( t1.getNode( "D" ) );
6172             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6173                 return false;
6174             }
6175             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6176                 return false;
6177             }
6178             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6179                 return false;
6180             }
6181             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
6182                 return false;
6183             }
6184             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
6185                 return false;
6186             }
6187             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
6188                 return false;
6189             }
6190             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",
6191                                                  new NHXParser() )[ 0 ];
6192             t2.reRoot( t2.getNode( "A" ) );
6193             t2.reRoot( t2.getNode( "D" ) );
6194             t2.reRoot( t2.getNode( "ABC" ) );
6195             t2.reRoot( t2.getNode( "A" ) );
6196             t2.reRoot( t2.getNode( "B" ) );
6197             t2.reRoot( t2.getNode( "D" ) );
6198             t2.reRoot( t2.getNode( "C" ) );
6199             t2.reRoot( t2.getNode( "ABC" ) );
6200             t2.reRoot( t2.getNode( "A" ) );
6201             t2.reRoot( t2.getNode( "B" ) );
6202             t2.reRoot( t2.getNode( "AB" ) );
6203             t2.reRoot( t2.getNode( "AB" ) );
6204             t2.reRoot( t2.getNode( "D" ) );
6205             t2.reRoot( t2.getNode( "C" ) );
6206             t2.reRoot( t2.getNode( "B" ) );
6207             t2.reRoot( t2.getNode( "AB" ) );
6208             t2.reRoot( t2.getNode( "D" ) );
6209             t2.reRoot( t2.getNode( "D" ) );
6210             t2.reRoot( t2.getNode( "ABC" ) );
6211             t2.reRoot( t2.getNode( "A" ) );
6212             t2.reRoot( t2.getNode( "B" ) );
6213             t2.reRoot( t2.getNode( "AB" ) );
6214             t2.reRoot( t2.getNode( "D" ) );
6215             t2.reRoot( t2.getNode( "C" ) );
6216             t2.reRoot( t2.getNode( "ABC" ) );
6217             t2.reRoot( t2.getNode( "A" ) );
6218             t2.reRoot( t2.getNode( "B" ) );
6219             t2.reRoot( t2.getNode( "AB" ) );
6220             t2.reRoot( t2.getNode( "D" ) );
6221             t2.reRoot( t2.getNode( "D" ) );
6222             t2.reRoot( t2.getNode( "C" ) );
6223             t2.reRoot( t2.getNode( "A" ) );
6224             t2.reRoot( t2.getNode( "B" ) );
6225             t2.reRoot( t2.getNode( "AB" ) );
6226             t2.reRoot( t2.getNode( "C" ) );
6227             t2.reRoot( t2.getNode( "D" ) );
6228             t2.reRoot( t2.getNode( "ABC" ) );
6229             t2.reRoot( t2.getNode( "D" ) );
6230             t2.reRoot( t2.getNode( "A" ) );
6231             t2.reRoot( t2.getNode( "B" ) );
6232             t2.reRoot( t2.getNode( "AB" ) );
6233             t2.reRoot( t2.getNode( "C" ) );
6234             t2.reRoot( t2.getNode( "D" ) );
6235             t2.reRoot( t2.getNode( "ABC" ) );
6236             t2.reRoot( t2.getNode( "D" ) );
6237             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6238                 return false;
6239             }
6240             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6241                 return false;
6242             }
6243             t2.reRoot( t2.getNode( "ABC" ) );
6244             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6245                 return false;
6246             }
6247             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6248                 return false;
6249             }
6250             t2.reRoot( t2.getNode( "AB" ) );
6251             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6252                 return false;
6253             }
6254             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6255                 return false;
6256             }
6257             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6258                 return false;
6259             }
6260             t2.reRoot( t2.getNode( "AB" ) );
6261             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6262                 return false;
6263             }
6264             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6265                 return false;
6266             }
6267             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6268                 return false;
6269             }
6270             t2.reRoot( t2.getNode( "D" ) );
6271             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6272                 return false;
6273             }
6274             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6275                 return false;
6276             }
6277             t2.reRoot( t2.getNode( "ABC" ) );
6278             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6279                 return false;
6280             }
6281             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6282                 return false;
6283             }
6284             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
6285                                                  new NHXParser() )[ 0 ];
6286             t3.reRoot( t3.getNode( "B" ) );
6287             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6288                 return false;
6289             }
6290             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6291                 return false;
6292             }
6293             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6294                 return false;
6295             }
6296             t3.reRoot( t3.getNode( "B" ) );
6297             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6298                 return false;
6299             }
6300             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6301                 return false;
6302             }
6303             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6304                 return false;
6305             }
6306             t3.reRoot( t3.getRoot() );
6307             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6308                 return false;
6309             }
6310             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6311                 return false;
6312             }
6313             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6314                 return false;
6315             }
6316         }
6317         catch ( final Exception e ) {
6318             e.printStackTrace( System.out );
6319             return false;
6320         }
6321         return true;
6322     }
6323
6324     private static boolean testSDIse() {
6325         try {
6326             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6327             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
6328             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
6329             gene1.setRooted( true );
6330             species1.setRooted( true );
6331             final SDI sdi = new SDI( gene1, species1 );
6332             if ( !gene1.getRoot().isDuplication() ) {
6333                 return false;
6334             }
6335             final Phylogeny species2 = factory
6336                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6337                              new NHXParser() )[ 0 ];
6338             final Phylogeny gene2 = factory
6339                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6340                              new NHXParser() )[ 0 ];
6341             species2.setRooted( true );
6342             gene2.setRooted( true );
6343             final SDI sdi2 = new SDI( gene2, species2 );
6344             if ( sdi2.getDuplicationsSum() != 0 ) {
6345                 return false;
6346             }
6347             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
6348                 return false;
6349             }
6350             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
6351                 return false;
6352             }
6353             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
6354                 return false;
6355             }
6356             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
6357                 return false;
6358             }
6359             if ( !gene2.getNode( "r" ).isSpeciation() ) {
6360                 return false;
6361             }
6362             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
6363                 return false;
6364             }
6365             final Phylogeny species3 = factory
6366                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6367                              new NHXParser() )[ 0 ];
6368             final Phylogeny gene3 = factory
6369                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6370                              new NHXParser() )[ 0 ];
6371             species3.setRooted( true );
6372             gene3.setRooted( true );
6373             final SDI sdi3 = new SDI( gene3, species3 );
6374             if ( sdi3.getDuplicationsSum() != 1 ) {
6375                 return false;
6376             }
6377             if ( !gene3.getNode( "aa" ).isDuplication() ) {
6378                 return false;
6379             }
6380             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
6381                 return false;
6382             }
6383             final Phylogeny species4 = factory
6384                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6385                              new NHXParser() )[ 0 ];
6386             final Phylogeny gene4 = factory
6387                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6388                              new NHXParser() )[ 0 ];
6389             species4.setRooted( true );
6390             gene4.setRooted( true );
6391             final SDI sdi4 = new SDI( gene4, species4 );
6392             if ( sdi4.getDuplicationsSum() != 1 ) {
6393                 return false;
6394             }
6395             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
6396                 return false;
6397             }
6398             if ( !gene4.getNode( "abc" ).isDuplication() ) {
6399                 return false;
6400             }
6401             if ( gene4.getNode( "abcd" ).isDuplication() ) {
6402                 return false;
6403             }
6404             if ( species4.getNumberOfExternalNodes() != 6 ) {
6405                 return false;
6406             }
6407             if ( gene4.getNumberOfExternalNodes() != 6 ) {
6408                 return false;
6409             }
6410             final Phylogeny species5 = factory
6411                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6412                              new NHXParser() )[ 0 ];
6413             final Phylogeny gene5 = factory
6414                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6415                              new NHXParser() )[ 0 ];
6416             species5.setRooted( true );
6417             gene5.setRooted( true );
6418             final SDI sdi5 = new SDI( gene5, species5 );
6419             if ( sdi5.getDuplicationsSum() != 2 ) {
6420                 return false;
6421             }
6422             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
6423                 return false;
6424             }
6425             if ( !gene5.getNode( "adc" ).isDuplication() ) {
6426                 return false;
6427             }
6428             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
6429                 return false;
6430             }
6431             if ( species5.getNumberOfExternalNodes() != 6 ) {
6432                 return false;
6433             }
6434             if ( gene5.getNumberOfExternalNodes() != 6 ) {
6435                 return false;
6436             }
6437             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
6438             // Conjecture for Comparing Molecular Phylogenies"
6439             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
6440             final Phylogeny species6 = factory
6441                     .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,"
6442                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6443                              new NHXParser() )[ 0 ];
6444             final Phylogeny gene6 = factory
6445                     .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,"
6446                                      + "((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,"
6447                                      + "(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;",
6448                              new NHXParser() )[ 0 ];
6449             species6.setRooted( true );
6450             gene6.setRooted( true );
6451             final SDI sdi6 = new SDI( gene6, species6 );
6452             if ( sdi6.getDuplicationsSum() != 3 ) {
6453                 return false;
6454             }
6455             if ( !gene6.getNode( "r" ).isDuplication() ) {
6456                 return false;
6457             }
6458             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
6459                 return false;
6460             }
6461             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
6462                 return false;
6463             }
6464             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
6465                 return false;
6466             }
6467             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
6468                 return false;
6469             }
6470             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
6471                 return false;
6472             }
6473             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
6474                 return false;
6475             }
6476             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
6477                 return false;
6478             }
6479             sdi6.computeMappingCostL();
6480             if ( sdi6.computeMappingCostL() != 17 ) {
6481                 return false;
6482             }
6483             if ( species6.getNumberOfExternalNodes() != 9 ) {
6484                 return false;
6485             }
6486             if ( gene6.getNumberOfExternalNodes() != 9 ) {
6487                 return false;
6488             }
6489             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
6490                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
6491                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
6492                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
6493                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
6494             species7.setRooted( true );
6495             final Phylogeny gene7_1 = Test
6496                     .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])" );
6497             gene7_1.setRooted( true );
6498             final SDI sdi7 = new SDI( gene7_1, species7 );
6499             if ( sdi7.getDuplicationsSum() != 0 ) {
6500                 return false;
6501             }
6502             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
6503                 return false;
6504             }
6505             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
6506                 return false;
6507             }
6508             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
6509                 return false;
6510             }
6511             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
6512                 return false;
6513             }
6514             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
6515                 return false;
6516             }
6517             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
6518                 return false;
6519             }
6520             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
6521                 return false;
6522             }
6523             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
6524                 return false;
6525             }
6526             final Phylogeny gene7_2 = Test
6527                     .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])" );
6528             gene7_2.setRooted( true );
6529             final SDI sdi7_2 = new SDI( gene7_2, species7 );
6530             if ( sdi7_2.getDuplicationsSum() != 1 ) {
6531                 return false;
6532             }
6533             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
6534                 return false;
6535             }
6536             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
6537                 return false;
6538             }
6539             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
6540                 return false;
6541             }
6542             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
6543                 return false;
6544             }
6545             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
6546                 return false;
6547             }
6548             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
6549                 return false;
6550             }
6551             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
6552                 return false;
6553             }
6554             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
6555                 return false;
6556             }
6557             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
6558                 return false;
6559             }
6560         }
6561         catch ( final Exception e ) {
6562             return false;
6563         }
6564         return true;
6565     }
6566
6567     private static boolean testSDIunrooted() {
6568         try {
6569             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6570             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
6571             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
6572             final Iterator<PhylogenyBranch> iter = l.iterator();
6573             PhylogenyBranch br = iter.next();
6574             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
6575                 return false;
6576             }
6577             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
6578                 return false;
6579             }
6580             br = iter.next();
6581             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
6582                 return false;
6583             }
6584             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
6585                 return false;
6586             }
6587             br = iter.next();
6588             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
6589                 return false;
6590             }
6591             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
6592                 return false;
6593             }
6594             br = iter.next();
6595             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6596                 return false;
6597             }
6598             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6599                 return false;
6600             }
6601             br = iter.next();
6602             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6603                 return false;
6604             }
6605             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6606                 return false;
6607             }
6608             br = iter.next();
6609             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
6610                 return false;
6611             }
6612             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
6613                 return false;
6614             }
6615             br = iter.next();
6616             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6617                 return false;
6618             }
6619             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6620                 return false;
6621             }
6622             br = iter.next();
6623             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6624                 return false;
6625             }
6626             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6627                 return false;
6628             }
6629             br = iter.next();
6630             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6631                 return false;
6632             }
6633             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6634                 return false;
6635             }
6636             br = iter.next();
6637             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6638                 return false;
6639             }
6640             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6641                 return false;
6642             }
6643             br = iter.next();
6644             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
6645                 return false;
6646             }
6647             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
6648                 return false;
6649             }
6650             br = iter.next();
6651             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
6652                 return false;
6653             }
6654             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
6655                 return false;
6656             }
6657             br = iter.next();
6658             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
6659                 return false;
6660             }
6661             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
6662                 return false;
6663             }
6664             br = iter.next();
6665             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
6666                 return false;
6667             }
6668             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
6669                 return false;
6670             }
6671             br = iter.next();
6672             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
6673                 return false;
6674             }
6675             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
6676                 return false;
6677             }
6678             if ( iter.hasNext() ) {
6679                 return false;
6680             }
6681             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
6682             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
6683             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
6684             br = iter1.next();
6685             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
6686                 return false;
6687             }
6688             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
6689                 return false;
6690             }
6691             br = iter1.next();
6692             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6693                 return false;
6694             }
6695             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6696                 return false;
6697             }
6698             br = iter1.next();
6699             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6700                 return false;
6701             }
6702             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6703                 return false;
6704             }
6705             if ( iter1.hasNext() ) {
6706                 return false;
6707             }
6708             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
6709             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
6710             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
6711             br = iter2.next();
6712             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
6713                 return false;
6714             }
6715             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
6716                 return false;
6717             }
6718             br = iter2.next();
6719             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6720                 return false;
6721             }
6722             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6723                 return false;
6724             }
6725             br = iter2.next();
6726             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6727                 return false;
6728             }
6729             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6730                 return false;
6731             }
6732             if ( iter2.hasNext() ) {
6733                 return false;
6734             }
6735             final Phylogeny species0 = factory
6736                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6737                              new NHXParser() )[ 0 ];
6738             final Phylogeny gene1 = factory
6739                     .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])",
6740                              new NHXParser() )[ 0 ];
6741             species0.setRooted( true );
6742             gene1.setRooted( true );
6743             final SDIR sdi_unrooted = new SDIR();
6744             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
6745             if ( sdi_unrooted.getCount() != 1 ) {
6746                 return false;
6747             }
6748             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
6749                 return false;
6750             }
6751             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
6752                 return false;
6753             }
6754             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
6755                 return false;
6756             }
6757             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6758                 return false;
6759             }
6760             final Phylogeny gene2 = factory
6761                     .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])",
6762                              new NHXParser() )[ 0 ];
6763             gene2.setRooted( true );
6764             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
6765             if ( sdi_unrooted.getCount() != 1 ) {
6766                 return false;
6767             }
6768             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6769                 return false;
6770             }
6771             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6772                 return false;
6773             }
6774             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
6775                 return false;
6776             }
6777             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6778                 return false;
6779             }
6780             final Phylogeny species6 = factory
6781                     .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,"
6782                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6783                              new NHXParser() )[ 0 ];
6784             final Phylogeny gene6 = factory
6785                     .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],"
6786                                      + "(((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],"
6787                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6788                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6789                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6790                              new NHXParser() )[ 0 ];
6791             species6.setRooted( true );
6792             gene6.setRooted( true );
6793             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
6794             if ( sdi_unrooted.getCount() != 1 ) {
6795                 return false;
6796             }
6797             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6798                 return false;
6799             }
6800             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6801                 return false;
6802             }
6803             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6804                 return false;
6805             }
6806             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6807                 return false;
6808             }
6809             if ( !p6[ 0 ].getRoot().isDuplication() ) {
6810                 return false;
6811             }
6812             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6813                 return false;
6814             }
6815             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6816                 return false;
6817             }
6818             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
6819                 return false;
6820             }
6821             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6822                 return false;
6823             }
6824             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
6825                 return false;
6826             }
6827             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
6828                 return false;
6829             }
6830             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6831                 return false;
6832             }
6833             p6 = null;
6834             final Phylogeny species7 = factory
6835                     .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,"
6836                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6837                              new NHXParser() )[ 0 ];
6838             final Phylogeny gene7 = factory
6839                     .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],"
6840                                      + "(((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],"
6841                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6842                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6843                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6844                              new NHXParser() )[ 0 ];
6845             species7.setRooted( true );
6846             gene7.setRooted( true );
6847             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
6848             if ( sdi_unrooted.getCount() != 1 ) {
6849                 return false;
6850             }
6851             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6852                 return false;
6853             }
6854             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6855                 return false;
6856             }
6857             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6858                 return false;
6859             }
6860             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
6861                 return false;
6862             }
6863             if ( !p7[ 0 ].getRoot().isDuplication() ) {
6864                 return false;
6865             }
6866             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6867                 return false;
6868             }
6869             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6870                 return false;
6871             }
6872             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
6873                 return false;
6874             }
6875             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6876                 return false;
6877             }
6878             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
6879                 return false;
6880             }
6881             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
6882                 return false;
6883             }
6884             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6885                 return false;
6886             }
6887             p7 = null;
6888             final Phylogeny species8 = factory
6889                     .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,"
6890                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6891                              new NHXParser() )[ 0 ];
6892             final Phylogeny gene8 = factory
6893                     .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],"
6894                                      + "(((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],"
6895                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6896                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6897                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6898                              new NHXParser() )[ 0 ];
6899             species8.setRooted( true );
6900             gene8.setRooted( true );
6901             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
6902             if ( sdi_unrooted.getCount() != 1 ) {
6903                 return false;
6904             }
6905             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6906                 return false;
6907             }
6908             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6909                 return false;
6910             }
6911             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6912                 return false;
6913             }
6914             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6915                 return false;
6916             }
6917             if ( !p8[ 0 ].getRoot().isDuplication() ) {
6918                 return false;
6919             }
6920             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6921                 return false;
6922             }
6923             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6924                 return false;
6925             }
6926             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
6927                 return false;
6928             }
6929             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6930                 return false;
6931             }
6932             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
6933                 return false;
6934             }
6935             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
6936                 return false;
6937             }
6938             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6939                 return false;
6940             }
6941             p8 = null;
6942         }
6943         catch ( final Exception e ) {
6944             e.printStackTrace( System.out );
6945             return false;
6946         }
6947         return true;
6948     }
6949
6950     private static boolean testSplit() {
6951         try {
6952             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6953             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
6954             //Archaeopteryx.createApplication( p0 );
6955             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
6956             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6957             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6958             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6959             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6960             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6961             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6962             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6963             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
6964             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
6965             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
6966             // System.out.println( s0.toString() );
6967             //
6968             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
6969             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6970             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6971             if ( s0.match( query_nodes ) ) {
6972                 return false;
6973             }
6974             query_nodes = new HashSet<PhylogenyNode>();
6975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6977             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6978             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6982             if ( !s0.match( query_nodes ) ) {
6983                 return false;
6984             }
6985             //
6986             query_nodes = new HashSet<PhylogenyNode>();
6987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6990             if ( !s0.match( query_nodes ) ) {
6991                 return false;
6992             }
6993             //
6994             query_nodes = new HashSet<PhylogenyNode>();
6995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6998             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6999             if ( !s0.match( query_nodes ) ) {
7000                 return false;
7001             }
7002             //
7003             query_nodes = new HashSet<PhylogenyNode>();
7004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7005             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7006             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7007             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7008             if ( !s0.match( query_nodes ) ) {
7009                 return false;
7010             }
7011             //
7012             query_nodes = new HashSet<PhylogenyNode>();
7013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7016             if ( !s0.match( query_nodes ) ) {
7017                 return false;
7018             }
7019             //
7020             query_nodes = new HashSet<PhylogenyNode>();
7021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7023             if ( !s0.match( query_nodes ) ) {
7024                 return false;
7025             }
7026             //
7027             query_nodes = new HashSet<PhylogenyNode>();
7028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7033             if ( !s0.match( query_nodes ) ) {
7034                 return false;
7035             }
7036             //
7037             query_nodes = new HashSet<PhylogenyNode>();
7038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7041             if ( !s0.match( query_nodes ) ) {
7042                 return false;
7043             }
7044             //
7045             query_nodes = new HashSet<PhylogenyNode>();
7046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7050             if ( !s0.match( query_nodes ) ) {
7051                 return false;
7052             }
7053             //
7054             query_nodes = new HashSet<PhylogenyNode>();
7055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7057             if ( s0.match( query_nodes ) ) {
7058                 return false;
7059             }
7060             //
7061             query_nodes = new HashSet<PhylogenyNode>();
7062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7063             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7064             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7066             if ( s0.match( query_nodes ) ) {
7067                 return false;
7068             }
7069             //
7070             query_nodes = new HashSet<PhylogenyNode>();
7071             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7072             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7074             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7075             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7076             if ( s0.match( query_nodes ) ) {
7077                 return false;
7078             }
7079             //
7080             query_nodes = new HashSet<PhylogenyNode>();
7081             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7082             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7083             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7084             if ( s0.match( query_nodes ) ) {
7085                 return false;
7086             }
7087             //
7088             query_nodes = new HashSet<PhylogenyNode>();
7089             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7090             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7091             if ( s0.match( query_nodes ) ) {
7092                 return false;
7093             }
7094             //
7095             query_nodes = new HashSet<PhylogenyNode>();
7096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7098             if ( s0.match( query_nodes ) ) {
7099                 return false;
7100             }
7101             //
7102             query_nodes = new HashSet<PhylogenyNode>();
7103             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7104             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7105             if ( s0.match( query_nodes ) ) {
7106                 return false;
7107             }
7108             //
7109             query_nodes = new HashSet<PhylogenyNode>();
7110             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7111             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7112             if ( s0.match( query_nodes ) ) {
7113                 return false;
7114             }
7115             //
7116             query_nodes = new HashSet<PhylogenyNode>();
7117             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7118             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7119             if ( s0.match( query_nodes ) ) {
7120                 return false;
7121             }
7122             //
7123             query_nodes = new HashSet<PhylogenyNode>();
7124             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7125             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7126             if ( s0.match( query_nodes ) ) {
7127                 return false;
7128             }
7129             //
7130             query_nodes = new HashSet<PhylogenyNode>();
7131             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7133             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7134             if ( s0.match( query_nodes ) ) {
7135                 return false;
7136             }
7137             //
7138             query_nodes = new HashSet<PhylogenyNode>();
7139             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7142             if ( s0.match( query_nodes ) ) {
7143                 return false;
7144             }
7145             //
7146             query_nodes = new HashSet<PhylogenyNode>();
7147             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7148             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7149             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7150             if ( s0.match( query_nodes ) ) {
7151                 return false;
7152             }
7153             //
7154             query_nodes = new HashSet<PhylogenyNode>();
7155             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7156             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7159             if ( s0.match( query_nodes ) ) {
7160                 return false;
7161             }
7162             /////////
7163             //            query_nodes = new HashSet<PhylogenyNode>();
7164             //            query_nodes.add( new PhylogenyNode( "X" ) );
7165             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7166             //            query_nodes.add( new PhylogenyNode( "A" ) );
7167             //            query_nodes.add( new PhylogenyNode( "B" ) );
7168             //            query_nodes.add( new PhylogenyNode( "C" ) );
7169             //            query_nodes.add( new PhylogenyNode( "D" ) );
7170             //            query_nodes.add( new PhylogenyNode( "E" ) );
7171             //            query_nodes.add( new PhylogenyNode( "F" ) );
7172             //            query_nodes.add( new PhylogenyNode( "G" ) );
7173             //            if ( !s0.match( query_nodes ) ) {
7174             //                return false;
7175             //            }
7176             //            query_nodes = new HashSet<PhylogenyNode>();
7177             //            query_nodes.add( new PhylogenyNode( "X" ) );
7178             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7179             //            query_nodes.add( new PhylogenyNode( "A" ) );
7180             //            query_nodes.add( new PhylogenyNode( "B" ) );
7181             //            query_nodes.add( new PhylogenyNode( "C" ) );
7182             //            if ( !s0.match( query_nodes ) ) {
7183             //                return false;
7184             //            }
7185             //            //
7186             //            query_nodes = new HashSet<PhylogenyNode>();
7187             //            query_nodes.add( new PhylogenyNode( "X" ) );
7188             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7189             //            query_nodes.add( new PhylogenyNode( "D" ) );
7190             //            query_nodes.add( new PhylogenyNode( "E" ) );
7191             //            query_nodes.add( new PhylogenyNode( "F" ) );
7192             //            query_nodes.add( new PhylogenyNode( "G" ) );
7193             //            if ( !s0.match( query_nodes ) ) {
7194             //                return false;
7195             //            }
7196             //            //
7197             //            query_nodes = new HashSet<PhylogenyNode>();
7198             //            query_nodes.add( new PhylogenyNode( "X" ) );
7199             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7200             //            query_nodes.add( new PhylogenyNode( "A" ) );
7201             //            query_nodes.add( new PhylogenyNode( "B" ) );
7202             //            query_nodes.add( new PhylogenyNode( "C" ) );
7203             //            query_nodes.add( new PhylogenyNode( "D" ) );
7204             //            if ( !s0.match( query_nodes ) ) {
7205             //                return false;
7206             //            }
7207             //            //
7208             //            query_nodes = new HashSet<PhylogenyNode>();
7209             //            query_nodes.add( new PhylogenyNode( "X" ) );
7210             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7211             //            query_nodes.add( new PhylogenyNode( "E" ) );
7212             //            query_nodes.add( new PhylogenyNode( "F" ) );
7213             //            query_nodes.add( new PhylogenyNode( "G" ) );
7214             //            if ( !s0.match( query_nodes ) ) {
7215             //                return false;
7216             //            }
7217             //            //
7218             //            query_nodes = new HashSet<PhylogenyNode>();
7219             //            query_nodes.add( new PhylogenyNode( "X" ) );
7220             //            query_nodes.add( new PhylogenyNode( "Y" ) );
7221             //            query_nodes.add( new PhylogenyNode( "F" ) );
7222             //            query_nodes.add( new PhylogenyNode( "G" ) );
7223             //            if ( !s0.match( query_nodes ) ) {
7224             //                return false;
7225             //            }
7226             //
7227             query_nodes = new HashSet<PhylogenyNode>();
7228             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7229             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7230             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7232             if ( s0.match( query_nodes ) ) {
7233                 return false;
7234             }
7235             //
7236             query_nodes = new HashSet<PhylogenyNode>();
7237             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7238             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7239             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7240             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7241             if ( s0.match( query_nodes ) ) {
7242                 return false;
7243             }
7244             ///////////////////////////
7245             //
7246             query_nodes = new HashSet<PhylogenyNode>();
7247             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7248             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7249             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7250             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7251             if ( s0.match( query_nodes ) ) {
7252                 return false;
7253             }
7254             //
7255             query_nodes = new HashSet<PhylogenyNode>();
7256             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7257             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7258             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7259             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7260             if ( s0.match( query_nodes ) ) {
7261                 return false;
7262             }
7263             //
7264             query_nodes = new HashSet<PhylogenyNode>();
7265             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7266             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7267             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7268             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7269             if ( s0.match( query_nodes ) ) {
7270                 return false;
7271             }
7272             //
7273             query_nodes = new HashSet<PhylogenyNode>();
7274             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7275             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7276             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7277             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7278             if ( s0.match( query_nodes ) ) {
7279                 return false;
7280             }
7281             //
7282             query_nodes = new HashSet<PhylogenyNode>();
7283             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7284             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7285             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7286             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7287             if ( s0.match( query_nodes ) ) {
7288                 return false;
7289             }
7290             //
7291             query_nodes = new HashSet<PhylogenyNode>();
7292             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7293             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7294             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7295             if ( s0.match( query_nodes ) ) {
7296                 return false;
7297             }
7298             //
7299             query_nodes = new HashSet<PhylogenyNode>();
7300             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7301             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7302             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7303             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7304             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7305             if ( s0.match( query_nodes ) ) {
7306                 return false;
7307             }
7308             //
7309             query_nodes = new HashSet<PhylogenyNode>();
7310             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7311             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7312             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7313             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7314             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7315             if ( s0.match( query_nodes ) ) {
7316                 return false;
7317             }
7318             //
7319             query_nodes = new HashSet<PhylogenyNode>();
7320             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7321             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7322             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7323             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7324             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7325             if ( s0.match( query_nodes ) ) {
7326                 return false;
7327             }
7328             //
7329             query_nodes = new HashSet<PhylogenyNode>();
7330             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7331             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7332             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7333             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7334             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7335             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7336             if ( s0.match( query_nodes ) ) {
7337                 return false;
7338             }
7339         }
7340         catch ( final Exception e ) {
7341             e.printStackTrace();
7342             return false;
7343         }
7344         return true;
7345     }
7346
7347     private static boolean testSplitStrict() {
7348         try {
7349             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7350             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
7351             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
7352             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7353             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7354             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7355             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7356             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7357             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7358             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7359             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
7360             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
7361             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7362             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7363             if ( s0.match( query_nodes ) ) {
7364                 return false;
7365             }
7366             query_nodes = new HashSet<PhylogenyNode>();
7367             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7368             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7370             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7371             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7372             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7373             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7374             if ( !s0.match( query_nodes ) ) {
7375                 return false;
7376             }
7377             //
7378             query_nodes = new HashSet<PhylogenyNode>();
7379             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7380             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7381             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7382             if ( !s0.match( query_nodes ) ) {
7383                 return false;
7384             }
7385             //
7386             query_nodes = new HashSet<PhylogenyNode>();
7387             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7388             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7389             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7390             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7391             if ( !s0.match( query_nodes ) ) {
7392                 return false;
7393             }
7394             //
7395             query_nodes = new HashSet<PhylogenyNode>();
7396             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7397             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7398             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7399             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7400             if ( !s0.match( query_nodes ) ) {
7401                 return false;
7402             }
7403             //
7404             query_nodes = new HashSet<PhylogenyNode>();
7405             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7406             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7407             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7408             if ( !s0.match( query_nodes ) ) {
7409                 return false;
7410             }
7411             //
7412             query_nodes = new HashSet<PhylogenyNode>();
7413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7415             if ( !s0.match( query_nodes ) ) {
7416                 return false;
7417             }
7418             //
7419             query_nodes = new HashSet<PhylogenyNode>();
7420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7422             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7423             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7424             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7425             if ( !s0.match( query_nodes ) ) {
7426                 return false;
7427             }
7428             //
7429             query_nodes = new HashSet<PhylogenyNode>();
7430             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7431             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7432             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7433             if ( !s0.match( query_nodes ) ) {
7434                 return false;
7435             }
7436             //
7437             query_nodes = new HashSet<PhylogenyNode>();
7438             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7439             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7440             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7441             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7442             if ( !s0.match( query_nodes ) ) {
7443                 return false;
7444             }
7445             //
7446             query_nodes = new HashSet<PhylogenyNode>();
7447             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7448             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7449             if ( s0.match( query_nodes ) ) {
7450                 return false;
7451             }
7452             //
7453             query_nodes = new HashSet<PhylogenyNode>();
7454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7456             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7457             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7458             if ( s0.match( query_nodes ) ) {
7459                 return false;
7460             }
7461             //
7462             query_nodes = new HashSet<PhylogenyNode>();
7463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7465             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7466             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7467             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7468             if ( s0.match( query_nodes ) ) {
7469                 return false;
7470             }
7471             //
7472             query_nodes = new HashSet<PhylogenyNode>();
7473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7474             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7475             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7476             if ( s0.match( query_nodes ) ) {
7477                 return false;
7478             }
7479             //
7480             query_nodes = new HashSet<PhylogenyNode>();
7481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7482             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7483             if ( s0.match( query_nodes ) ) {
7484                 return false;
7485             }
7486             //
7487             query_nodes = new HashSet<PhylogenyNode>();
7488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7490             if ( s0.match( query_nodes ) ) {
7491                 return false;
7492             }
7493             //
7494             query_nodes = new HashSet<PhylogenyNode>();
7495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7497             if ( s0.match( query_nodes ) ) {
7498                 return false;
7499             }
7500             //
7501             query_nodes = new HashSet<PhylogenyNode>();
7502             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7504             if ( s0.match( query_nodes ) ) {
7505                 return false;
7506             }
7507             //
7508             query_nodes = new HashSet<PhylogenyNode>();
7509             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7510             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7511             if ( s0.match( query_nodes ) ) {
7512                 return false;
7513             }
7514             //
7515             query_nodes = new HashSet<PhylogenyNode>();
7516             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7517             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7518             if ( s0.match( query_nodes ) ) {
7519                 return false;
7520             }
7521             //
7522             query_nodes = new HashSet<PhylogenyNode>();
7523             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7524             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7525             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7526             if ( s0.match( query_nodes ) ) {
7527                 return false;
7528             }
7529             //
7530             query_nodes = new HashSet<PhylogenyNode>();
7531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7533             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7534             if ( s0.match( query_nodes ) ) {
7535                 return false;
7536             }
7537             //
7538             query_nodes = new HashSet<PhylogenyNode>();
7539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7541             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7542             if ( s0.match( query_nodes ) ) {
7543                 return false;
7544             }
7545             //
7546             query_nodes = new HashSet<PhylogenyNode>();
7547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7550             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7551             if ( s0.match( query_nodes ) ) {
7552                 return false;
7553             }
7554         }
7555         catch ( final Exception e ) {
7556             e.printStackTrace();
7557             return false;
7558         }
7559         return true;
7560     }
7561
7562     private static boolean testSubtreeDeletion() {
7563         try {
7564             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7565             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
7566             t1.deleteSubtree( t1.getNode( "A" ), false );
7567             if ( t1.getNumberOfExternalNodes() != 5 ) {
7568                 return false;
7569             }
7570             t1.toNewHampshireX();
7571             t1.deleteSubtree( t1.getNode( "E" ), false );
7572             if ( t1.getNumberOfExternalNodes() != 4 ) {
7573                 return false;
7574             }
7575             t1.toNewHampshireX();
7576             t1.deleteSubtree( t1.getNode( "F" ), false );
7577             if ( t1.getNumberOfExternalNodes() != 3 ) {
7578                 return false;
7579             }
7580             t1.toNewHampshireX();
7581             t1.deleteSubtree( t1.getNode( "D" ), false );
7582             t1.toNewHampshireX();
7583             if ( t1.getNumberOfExternalNodes() != 3 ) {
7584                 return false;
7585             }
7586             t1.deleteSubtree( t1.getNode( "def" ), false );
7587             t1.toNewHampshireX();
7588             if ( t1.getNumberOfExternalNodes() != 2 ) {
7589                 return false;
7590             }
7591             t1.deleteSubtree( t1.getNode( "B" ), false );
7592             t1.toNewHampshireX();
7593             if ( t1.getNumberOfExternalNodes() != 1 ) {
7594                 return false;
7595             }
7596             t1.deleteSubtree( t1.getNode( "C" ), false );
7597             t1.toNewHampshireX();
7598             if ( t1.getNumberOfExternalNodes() != 1 ) {
7599                 return false;
7600             }
7601             t1.deleteSubtree( t1.getNode( "abc" ), false );
7602             t1.toNewHampshireX();
7603             if ( t1.getNumberOfExternalNodes() != 1 ) {
7604                 return false;
7605             }
7606             t1.deleteSubtree( t1.getNode( "r" ), false );
7607             if ( t1.getNumberOfExternalNodes() != 0 ) {
7608                 return false;
7609             }
7610             if ( !t1.isEmpty() ) {
7611                 return false;
7612             }
7613             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
7614             t2.deleteSubtree( t2.getNode( "A" ), false );
7615             t2.toNewHampshireX();
7616             if ( t2.getNumberOfExternalNodes() != 5 ) {
7617                 return false;
7618             }
7619             t2.deleteSubtree( t2.getNode( "abc" ), false );
7620             t2.toNewHampshireX();
7621             if ( t2.getNumberOfExternalNodes() != 3 ) {
7622                 return false;
7623             }
7624             t2.deleteSubtree( t2.getNode( "def" ), false );
7625             t2.toNewHampshireX();
7626             if ( t2.getNumberOfExternalNodes() != 1 ) {
7627                 return false;
7628             }
7629         }
7630         catch ( final Exception e ) {
7631             e.printStackTrace( System.out );
7632             return false;
7633         }
7634         return true;
7635     }
7636
7637     private static boolean testSupportCount() {
7638         try {
7639             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7640             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
7641             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
7642                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
7643                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
7644                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
7645                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
7646                                                               new NHXParser() );
7647             SupportCount.count( t0_1, phylogenies_1, true, false );
7648             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
7649             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
7650                                                                       + "(((((A,B),C),D),E),((F,G),X))"
7651                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
7652                                                                       + "(((((A,B),C),D),E),(F,G))"
7653                                                                       + "(((((A,B),C),D),E),(F,G))"
7654                                                                       + "(((((A,B),C),D),E),(F,G))"
7655                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
7656                                                                       + "(((((A,B),C),D),E),(F,G))"
7657                                                                       + "((((((A,B),C),D),E),F),G)"
7658                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
7659                                                               new NHXParser() );
7660             SupportCount.count( t0_2, phylogenies_2, true, false );
7661             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
7662             while ( it.hasNext() ) {
7663                 final PhylogenyNode n = it.next();
7664                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
7665                     return false;
7666                 }
7667             }
7668             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
7669             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
7670                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
7671             SupportCount.count( t0_3, phylogenies_3, true, false );
7672             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
7673             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
7674                 return false;
7675             }
7676             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
7677                 return false;
7678             }
7679             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
7680                 return false;
7681             }
7682             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
7683                 return false;
7684             }
7685             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
7686                 return false;
7687             }
7688             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
7689                 return false;
7690             }
7691             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
7692                 return false;
7693             }
7694             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
7695                 return false;
7696             }
7697             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
7698                 return false;
7699             }
7700             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
7701                 return false;
7702             }
7703             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7704             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
7705                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
7706             SupportCount.count( t0_4, phylogenies_4, true, false );
7707             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
7708             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
7709                 return false;
7710             }
7711             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
7712                 return false;
7713             }
7714             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
7715                 return false;
7716             }
7717             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
7718                 return false;
7719             }
7720             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
7721                 return false;
7722             }
7723             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
7724                 return false;
7725             }
7726             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
7727                 return false;
7728             }
7729             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
7730                 return false;
7731             }
7732             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
7733                 return false;
7734             }
7735             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
7736                 return false;
7737             }
7738             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7739             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7740             double d = SupportCount.compare( b1, a, true, true, true );
7741             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
7742                 return false;
7743             }
7744             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7745             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7746             d = SupportCount.compare( b2, a, true, true, true );
7747             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
7748                 return false;
7749             }
7750             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7751             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
7752             d = SupportCount.compare( b3, a, true, true, true );
7753             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
7754                 return false;
7755             }
7756             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
7757             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
7758             d = SupportCount.compare( b4, a, true, true, false );
7759             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
7760                 return false;
7761             }
7762         }
7763         catch ( final Exception e ) {
7764             e.printStackTrace( System.out );
7765             return false;
7766         }
7767         return true;
7768     }
7769
7770     private static boolean testSupportTransfer() {
7771         try {
7772             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7773             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)",
7774                                                  new NHXParser() )[ 0 ];
7775             final Phylogeny p2 = factory
7776                     .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 ];
7777             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
7778                 return false;
7779             }
7780             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
7781                 return false;
7782             }
7783             support_transfer.moveBranchLengthsToBootstrap( p1 );
7784             support_transfer.transferSupportValues( p1, p2 );
7785             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
7786                 return false;
7787             }
7788             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
7789                 return false;
7790             }
7791             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
7792                 return false;
7793             }
7794             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
7795                 return false;
7796             }
7797             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
7798                 return false;
7799             }
7800             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
7801                 return false;
7802             }
7803             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
7804                 return false;
7805             }
7806             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
7807                 return false;
7808             }
7809         }
7810         catch ( final Exception e ) {
7811             e.printStackTrace( System.out );
7812             return false;
7813         }
7814         return true;
7815     }
7816
7817     private static boolean testUniprotTaxonomySearch() {
7818         try {
7819             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
7820                                                                                                  10 );
7821             if ( results.size() != 1 ) {
7822                 return false;
7823             }
7824             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7825                 return false;
7826             }
7827             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7828                 return false;
7829             }
7830             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7831                 return false;
7832             }
7833             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7834                 return false;
7835             }
7836             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7837                 return false;
7838             }
7839             results = null;
7840             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
7841             if ( results.size() != 1 ) {
7842                 return false;
7843             }
7844             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7845                 return false;
7846             }
7847             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7848                 return false;
7849             }
7850             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7851                 return false;
7852             }
7853             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7854                 return false;
7855             }
7856             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7857                 return false;
7858             }
7859             results = null;
7860             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
7861             if ( results.size() != 1 ) {
7862                 return false;
7863             }
7864             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7865                 return false;
7866             }
7867             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7868                 return false;
7869             }
7870             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7871                 return false;
7872             }
7873             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7874                 return false;
7875             }
7876             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7877                 return false;
7878             }
7879             results = null;
7880             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
7881             if ( results.size() != 1 ) {
7882                 return false;
7883             }
7884             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7885                 return false;
7886             }
7887             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7888                 return false;
7889             }
7890             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7891                 return false;
7892             }
7893             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7894                 return false;
7895             }
7896             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7897                 return false;
7898             }
7899             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
7900                 return false;
7901             }
7902             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
7903                 return false;
7904             }
7905             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
7906                     .equals( "Nematostella vectensis" ) ) {
7907                 System.out.println( results.get( 0 ).getLineage() );
7908                 return false;
7909             }
7910         }
7911         catch ( final IOException e ) {
7912             System.out.println();
7913             System.out.println( "the following might be due to absence internet connection:" );
7914             e.printStackTrace( System.out );
7915             return true;
7916         }
7917         catch ( final Exception e ) {
7918             return false;
7919         }
7920         return true;
7921     }
7922
7923     private static boolean testEmblEntryRetrieval() {
7924         //The format for GenBank Accession numbers are:
7925         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
7926         //Protein:    3 letters + 5 numerals
7927         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
7928         if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
7929             return false;
7930         }
7931         if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) {
7932             return false;
7933         }
7934         if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
7935             return false;
7936         }
7937         if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
7938             return false;
7939         }
7940         if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
7941             return false;
7942         }
7943         if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
7944             return false;
7945         }
7946         if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
7947             return false;
7948         }
7949         if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
7950             return false;
7951         }
7952         if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
7953             return false;
7954         }
7955         if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
7956             return false;
7957         }
7958         if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
7959             return false;
7960         }
7961         if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
7962             return false;
7963         }
7964         if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
7965             return false;
7966         }
7967         return true;
7968     }
7969
7970     private static boolean testUniprotEntryRetrieval() {
7971         if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) {
7972             return false;
7973         }
7974         if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) {
7975             return false;
7976         }
7977         if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) {
7978             return false;
7979         }
7980         if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) {
7981             return false;
7982         }
7983         if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) {
7984             return false;
7985         }
7986         if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) {
7987             return false;
7988         }
7989         if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) {
7990             return false;
7991         }
7992         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) {
7993             return false;
7994         }
7995         if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) {
7996             return false;
7997         }
7998         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) {
7999             return false;
8000         }
8001         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) {
8002             return false;
8003         }
8004         if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) {
8005             return false;
8006         }
8007         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) {
8008             return false;
8009         }
8010         try {
8011             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
8012             if ( !entry.getAccession().equals( "P12345" ) ) {
8013                 return false;
8014             }
8015             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
8016                 return false;
8017             }
8018             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
8019                 return false;
8020             }
8021             if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) {
8022                 return false;
8023             }
8024             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
8025                 return false;
8026             }
8027         }
8028         catch ( final IOException e ) {
8029             System.out.println();
8030             System.out.println( "the following might be due to absence internet connection:" );
8031             e.printStackTrace( System.out );
8032             return true;
8033         }
8034         catch ( final Exception e ) {
8035             return false;
8036         }
8037         return true;
8038     }
8039
8040     private static boolean testWabiTxSearch() {
8041         try {
8042             String result = "";
8043             result = TxSearch.searchSimple( "nematostella" );
8044             result = TxSearch.getTxId( "nematostella" );
8045             if ( !result.equals( "45350" ) ) {
8046                 return false;
8047             }
8048             result = TxSearch.getTxName( "45350" );
8049             if ( !result.equals( "Nematostella" ) ) {
8050                 return false;
8051             }
8052             result = TxSearch.getTxId( "nematostella vectensis" );
8053             if ( !result.equals( "45351" ) ) {
8054                 return false;
8055             }
8056             result = TxSearch.getTxName( "45351" );
8057             if ( !result.equals( "Nematostella vectensis" ) ) {
8058                 return false;
8059             }
8060             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
8061             if ( !result.equals( "536089" ) ) {
8062                 return false;
8063             }
8064             result = TxSearch.getTxName( "536089" );
8065             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
8066                 return false;
8067             }
8068             final List<String> queries = new ArrayList<String>();
8069             queries.add( "Campylobacter coli" );
8070             queries.add( "Escherichia coli" );
8071             queries.add( "Arabidopsis" );
8072             queries.add( "Trichoplax" );
8073             queries.add( "Samanea saman" );
8074             queries.add( "Kluyveromyces marxianus" );
8075             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
8076             queries.add( "Bornavirus parrot/PDD/2008" );
8077             final List<RANKS> ranks = new ArrayList<RANKS>();
8078             ranks.add( RANKS.SUPERKINGDOM );
8079             ranks.add( RANKS.KINGDOM );
8080             ranks.add( RANKS.FAMILY );
8081             ranks.add( RANKS.GENUS );
8082             ranks.add( RANKS.TRIBE );
8083             result = TxSearch.searchLineage( queries, ranks );
8084             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
8085             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
8086         }
8087         catch ( final Exception e ) {
8088             System.out.println();
8089             System.out.println( "the following might be due to absence internet connection:" );
8090             e.printStackTrace( System.out );
8091             return false;
8092         }
8093         return true;
8094     }
8095
8096     private static boolean testAminoAcidSequence() {
8097         try {
8098             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
8099             if ( aa1.getLength() != 13 ) {
8100                 return false;
8101             }
8102             if ( aa1.getResidueAt( 0 ) != 'A' ) {
8103                 return false;
8104             }
8105             if ( aa1.getResidueAt( 2 ) != 'K' ) {
8106                 return false;
8107             }
8108             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
8109                 return false;
8110             }
8111             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
8112             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
8113                 return false;
8114             }
8115             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
8116             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
8117                 return false;
8118             }
8119             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
8120             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
8121                 return false;
8122             }
8123         }
8124         catch ( final Exception e ) {
8125             e.printStackTrace();
8126             return false;
8127         }
8128         return true;
8129     }
8130
8131     private static boolean testCreateBalancedPhylogeny() {
8132         try {
8133             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
8134             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
8135                 return false;
8136             }
8137             if ( p0.getNumberOfExternalNodes() != 15625 ) {
8138                 return false;
8139             }
8140             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
8141             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
8142                 return false;
8143             }
8144             if ( p1.getNumberOfExternalNodes() != 100 ) {
8145                 return false;
8146             }
8147         }
8148         catch ( final Exception e ) {
8149             e.printStackTrace();
8150             return false;
8151         }
8152         return true;
8153     }
8154
8155     private static boolean testFastaParser() {
8156         try {
8157             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
8158                 return false;
8159             }
8160             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
8161                 return false;
8162             }
8163             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
8164             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
8165                 return false;
8166             }
8167             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
8168                 return false;
8169             }
8170             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
8171                 return false;
8172             }
8173             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
8174                 return false;
8175             }
8176             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
8177                 return false;
8178             }
8179             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
8180                 return false;
8181             }
8182         }
8183         catch ( final Exception e ) {
8184             e.printStackTrace();
8185             return false;
8186         }
8187         return true;
8188     }
8189
8190     private static boolean testGeneralMsaParser() {
8191         try {
8192             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
8193             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
8194             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
8195             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
8196             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
8197             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
8198             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
8199             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
8200             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8201                 return false;
8202             }
8203             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8204                 return false;
8205             }
8206             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8207                 return false;
8208             }
8209             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8210                 return false;
8211             }
8212             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8213                 return false;
8214             }
8215             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8216                 return false;
8217             }
8218             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8219                 return false;
8220             }
8221             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8222                 return false;
8223             }
8224             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8225                 return false;
8226             }
8227             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8228                 return false;
8229             }
8230             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8231                 return false;
8232             }
8233             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8234                 return false;
8235             }
8236             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
8237             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
8238                 return false;
8239             }
8240             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
8241                 return false;
8242             }
8243             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
8244                 return false;
8245             }
8246             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
8247             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
8248                 return false;
8249             }
8250             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
8251                 return false;
8252             }
8253             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
8254                 return false;
8255             }
8256             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
8257             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
8258                 return false;
8259             }
8260             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
8261                 return false;
8262             }
8263             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
8264                 return false;
8265             }
8266         }
8267         catch ( final Exception e ) {
8268             e.printStackTrace();
8269             return false;
8270         }
8271         return true;
8272     }
8273
8274     private static boolean testMafft( final String path ) {
8275         try {
8276             final List<String> opts = new ArrayList<String>();
8277             opts.add( "--maxiterate" );
8278             opts.add( "1000" );
8279             opts.add( "--localpair" );
8280             opts.add( "--quiet" );
8281             Msa msa = null;
8282             final MsaInferrer mafft = Mafft.createInstance( path );
8283             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
8284             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
8285                 return false;
8286             }
8287             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
8288                 return false;
8289             }
8290         }
8291         catch ( final Exception e ) {
8292             e.printStackTrace( System.out );
8293             return false;
8294         }
8295         return true;
8296     }
8297
8298     private static boolean testNextNodeWithCollapsing() {
8299         try {
8300             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8301             PhylogenyNode n;
8302             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
8303             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8304             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
8305             t0.getNode( "cd" ).setCollapse( true );
8306             t0.getNode( "cde" ).setCollapse( true );
8307             n = t0.getFirstExternalNode();
8308             while ( n != null ) {
8309                 ext.add( n );
8310                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8311             }
8312             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8313                 return false;
8314             }
8315             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8316                 return false;
8317             }
8318             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
8319                 return false;
8320             }
8321             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
8322                 return false;
8323             }
8324             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
8325                 return false;
8326             }
8327             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
8328                 return false;
8329             }
8330             ext.clear();
8331             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8332             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
8333             t1.getNode( "ab" ).setCollapse( true );
8334             t1.getNode( "cd" ).setCollapse( true );
8335             t1.getNode( "cde" ).setCollapse( true );
8336             n = t1.getNode( "ab" );
8337             ext = new ArrayList<PhylogenyNode>();
8338             while ( n != null ) {
8339                 ext.add( n );
8340                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8341             }
8342             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8343                 return false;
8344             }
8345             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8346                 return false;
8347             }
8348             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
8349                 return false;
8350             }
8351             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
8352                 return false;
8353             }
8354             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
8355                 return false;
8356             }
8357             //
8358             //
8359             ext.clear();
8360             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8361             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
8362             t2.getNode( "ab" ).setCollapse( true );
8363             t2.getNode( "cd" ).setCollapse( true );
8364             t2.getNode( "cde" ).setCollapse( true );
8365             t2.getNode( "c" ).setCollapse( true );
8366             t2.getNode( "d" ).setCollapse( true );
8367             t2.getNode( "e" ).setCollapse( true );
8368             t2.getNode( "gh" ).setCollapse( true );
8369             n = t2.getNode( "ab" );
8370             ext = new ArrayList<PhylogenyNode>();
8371             while ( n != null ) {
8372                 ext.add( n );
8373                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8374             }
8375             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8376                 return false;
8377             }
8378             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8379                 return false;
8380             }
8381             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
8382                 return false;
8383             }
8384             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
8385                 return false;
8386             }
8387             //
8388             //
8389             ext.clear();
8390             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8391             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
8392             t3.getNode( "ab" ).setCollapse( true );
8393             t3.getNode( "cd" ).setCollapse( true );
8394             t3.getNode( "cde" ).setCollapse( true );
8395             t3.getNode( "c" ).setCollapse( true );
8396             t3.getNode( "d" ).setCollapse( true );
8397             t3.getNode( "e" ).setCollapse( true );
8398             t3.getNode( "gh" ).setCollapse( true );
8399             t3.getNode( "fgh" ).setCollapse( true );
8400             n = t3.getNode( "ab" );
8401             ext = new ArrayList<PhylogenyNode>();
8402             while ( n != null ) {
8403                 ext.add( n );
8404                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8405             }
8406             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8407                 return false;
8408             }
8409             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8410                 return false;
8411             }
8412             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
8413                 return false;
8414             }
8415             //
8416             //
8417             ext.clear();
8418             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8419             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
8420             t4.getNode( "ab" ).setCollapse( true );
8421             t4.getNode( "cd" ).setCollapse( true );
8422             t4.getNode( "cde" ).setCollapse( true );
8423             t4.getNode( "c" ).setCollapse( true );
8424             t4.getNode( "d" ).setCollapse( true );
8425             t4.getNode( "e" ).setCollapse( true );
8426             t4.getNode( "gh" ).setCollapse( true );
8427             t4.getNode( "fgh" ).setCollapse( true );
8428             t4.getNode( "abcdefgh" ).setCollapse( true );
8429             n = t4.getNode( "abcdefgh" );
8430             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
8431                 return false;
8432             }
8433             //
8434             //
8435             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8436             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
8437             ext.clear();
8438             n = t5.getFirstExternalNode();
8439             while ( n != null ) {
8440                 ext.add( n );
8441                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8442             }
8443             if ( ext.size() != 8 ) {
8444                 return false;
8445             }
8446             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8447                 return false;
8448             }
8449             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8450                 return false;
8451             }
8452             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8453                 return false;
8454             }
8455             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8456                 return false;
8457             }
8458             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8459                 return false;
8460             }
8461             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8462                 return false;
8463             }
8464             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
8465                 return false;
8466             }
8467             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
8468                 return false;
8469             }
8470             //
8471             //
8472             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8473             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
8474             ext.clear();
8475             t6.getNode( "ab" ).setCollapse( true );
8476             n = t6.getNode( "ab" );
8477             while ( n != null ) {
8478                 ext.add( n );
8479                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8480             }
8481             if ( ext.size() != 7 ) {
8482                 return false;
8483             }
8484             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8485                 return false;
8486             }
8487             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8488                 return false;
8489             }
8490             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8491                 return false;
8492             }
8493             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8494                 return false;
8495             }
8496             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8497                 return false;
8498             }
8499             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8500                 return false;
8501             }
8502             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8503                 return false;
8504             }
8505             //
8506             //
8507             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8508             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
8509             ext.clear();
8510             t7.getNode( "cd" ).setCollapse( true );
8511             n = t7.getNode( "a" );
8512             while ( n != null ) {
8513                 ext.add( n );
8514                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8515             }
8516             if ( ext.size() != 7 ) {
8517                 return false;
8518             }
8519             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8520                 return false;
8521             }
8522             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8523                 return false;
8524             }
8525             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
8526                 return false;
8527             }
8528             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8529                 return false;
8530             }
8531             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8532                 return false;
8533             }
8534             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8535                 return false;
8536             }
8537             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8538                 return false;
8539             }
8540             //
8541             //
8542             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8543             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
8544             ext.clear();
8545             t8.getNode( "cd" ).setCollapse( true );
8546             t8.getNode( "c" ).setCollapse( true );
8547             t8.getNode( "d" ).setCollapse( true );
8548             n = t8.getNode( "a" );
8549             while ( n != null ) {
8550                 ext.add( n );
8551                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8552             }
8553             if ( ext.size() != 7 ) {
8554                 return false;
8555             }
8556             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8557                 return false;
8558             }
8559             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8560                 return false;
8561             }
8562             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
8563                 System.out.println( "2 fail" );
8564                 return false;
8565             }
8566             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8567                 return false;
8568             }
8569             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8570                 return false;
8571             }
8572             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8573                 return false;
8574             }
8575             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8576                 return false;
8577             }
8578             //
8579             //
8580             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8581             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
8582             ext.clear();
8583             t9.getNode( "gh" ).setCollapse( true );
8584             n = t9.getNode( "a" );
8585             while ( n != null ) {
8586                 ext.add( n );
8587                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8588             }
8589             if ( ext.size() != 7 ) {
8590                 return false;
8591             }
8592             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8593                 return false;
8594             }
8595             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8596                 return false;
8597             }
8598             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8599                 return false;
8600             }
8601             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8602                 return false;
8603             }
8604             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8605                 return false;
8606             }
8607             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8608                 return false;
8609             }
8610             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
8611                 return false;
8612             }
8613             //
8614             //
8615             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8616             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
8617             ext.clear();
8618             t10.getNode( "gh" ).setCollapse( true );
8619             t10.getNode( "g" ).setCollapse( true );
8620             t10.getNode( "h" ).setCollapse( true );
8621             n = t10.getNode( "a" );
8622             while ( n != null ) {
8623                 ext.add( n );
8624                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8625             }
8626             if ( ext.size() != 7 ) {
8627                 return false;
8628             }
8629             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8630                 return false;
8631             }
8632             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8633                 return false;
8634             }
8635             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8636                 return false;
8637             }
8638             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8639                 return false;
8640             }
8641             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8642                 return false;
8643             }
8644             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8645                 return false;
8646             }
8647             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
8648                 return false;
8649             }
8650             //
8651             //
8652             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8653             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
8654             ext.clear();
8655             t11.getNode( "gh" ).setCollapse( true );
8656             t11.getNode( "fgh" ).setCollapse( true );
8657             n = t11.getNode( "a" );
8658             while ( n != null ) {
8659                 ext.add( n );
8660                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8661             }
8662             if ( ext.size() != 6 ) {
8663                 return false;
8664             }
8665             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8666                 return false;
8667             }
8668             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8669                 return false;
8670             }
8671             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8672                 return false;
8673             }
8674             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8675                 return false;
8676             }
8677             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8678                 return false;
8679             }
8680             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8681                 return false;
8682             }
8683             //
8684             //
8685             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8686             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
8687             ext.clear();
8688             t12.getNode( "gh" ).setCollapse( true );
8689             t12.getNode( "fgh" ).setCollapse( true );
8690             t12.getNode( "g" ).setCollapse( true );
8691             t12.getNode( "h" ).setCollapse( true );
8692             t12.getNode( "f" ).setCollapse( true );
8693             n = t12.getNode( "a" );
8694             while ( n != null ) {
8695                 ext.add( n );
8696                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8697             }
8698             if ( ext.size() != 6 ) {
8699                 return false;
8700             }
8701             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8702                 return false;
8703             }
8704             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8705                 return false;
8706             }
8707             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8708                 return false;
8709             }
8710             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8711                 return false;
8712             }
8713             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8714                 return false;
8715             }
8716             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8717                 return false;
8718             }
8719             //
8720             //
8721             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8722             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
8723             ext.clear();
8724             t13.getNode( "ab" ).setCollapse( true );
8725             t13.getNode( "b" ).setCollapse( true );
8726             t13.getNode( "fgh" ).setCollapse( true );
8727             t13.getNode( "gh" ).setCollapse( true );
8728             n = t13.getNode( "ab" );
8729             while ( n != null ) {
8730                 ext.add( n );
8731                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8732             }
8733             if ( ext.size() != 5 ) {
8734                 return false;
8735             }
8736             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8737                 return false;
8738             }
8739             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8740                 return false;
8741             }
8742             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8743                 return false;
8744             }
8745             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8746                 return false;
8747             }
8748             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
8749                 return false;
8750             }
8751             //
8752             //
8753             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
8754             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
8755             ext.clear();
8756             t14.getNode( "ab" ).setCollapse( true );
8757             t14.getNode( "a" ).setCollapse( true );
8758             t14.getNode( "fgh" ).setCollapse( true );
8759             t14.getNode( "gh" ).setCollapse( true );
8760             n = t14.getNode( "ab" );
8761             while ( n != null ) {
8762                 ext.add( n );
8763                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8764             }
8765             if ( ext.size() != 5 ) {
8766                 return false;
8767             }
8768             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8769                 return false;
8770             }
8771             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8772                 return false;
8773             }
8774             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8775                 return false;
8776             }
8777             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8778                 return false;
8779             }
8780             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
8781                 return false;
8782             }
8783             //
8784             //
8785             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" );
8786             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
8787             ext.clear();
8788             t15.getNode( "ab" ).setCollapse( true );
8789             t15.getNode( "a" ).setCollapse( true );
8790             t15.getNode( "fgh" ).setCollapse( true );
8791             t15.getNode( "gh" ).setCollapse( true );
8792             n = t15.getNode( "ab" );
8793             while ( n != null ) {
8794                 ext.add( n );
8795                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8796             }
8797             if ( ext.size() != 6 ) {
8798                 return false;
8799             }
8800             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8801                 return false;
8802             }
8803             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8804                 return false;
8805             }
8806             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8807                 return false;
8808             }
8809             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8810                 return false;
8811             }
8812             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
8813                 return false;
8814             }
8815             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8816                 return false;
8817             }
8818             //
8819             //
8820             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" );
8821             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
8822             ext.clear();
8823             t16.getNode( "ab" ).setCollapse( true );
8824             t16.getNode( "a" ).setCollapse( true );
8825             t16.getNode( "fgh" ).setCollapse( true );
8826             t16.getNode( "gh" ).setCollapse( true );
8827             t16.getNode( "cd" ).setCollapse( true );
8828             t16.getNode( "cde" ).setCollapse( true );
8829             t16.getNode( "d" ).setCollapse( true );
8830             t16.getNode( "x" ).setCollapse( true );
8831             n = t16.getNode( "ab" );
8832             while ( n != null ) {
8833                 ext.add( n );
8834                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8835             }
8836             if ( ext.size() != 4 ) {
8837                 return false;
8838             }
8839             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8840                 return false;
8841             }
8842             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8843                 return false;
8844             }
8845             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
8846                 return false;
8847             }
8848             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
8849                 return false;
8850             }
8851         }
8852         catch ( final Exception e ) {
8853             e.printStackTrace( System.out );
8854             return false;
8855         }
8856         return true;
8857     }
8858
8859     private static boolean testMsaQualityMethod() {
8860         try {
8861             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
8862             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
8863             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
8864             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
8865             final List<Sequence> l = new ArrayList<Sequence>();
8866             l.add( s0 );
8867             l.add( s1 );
8868             l.add( s2 );
8869             l.add( s3 );
8870             final Msa msa = BasicMsa.createInstance( l );
8871             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
8872                 return false;
8873             }
8874             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
8875                 return false;
8876             }
8877             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
8878                 return false;
8879             }
8880             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
8881                 return false;
8882             }
8883         }
8884         catch ( final Exception e ) {
8885             e.printStackTrace( System.out );
8886             return false;
8887         }
8888         return true;
8889     }
8890
8891     private static boolean testSequenceIdParsing() {
8892         try {
8893             Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
8894             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8895                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8896                 if ( id != null ) {
8897                     System.out.println( "value   =" + id.getValue() );
8898                     System.out.println( "provider=" + id.getProvider() );
8899                 }
8900                 return false;
8901             }
8902             //
8903             id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
8904             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8905                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8906                 if ( id != null ) {
8907                     System.out.println( "value   =" + id.getValue() );
8908                     System.out.println( "provider=" + id.getProvider() );
8909                 }
8910                 return false;
8911             }
8912             //
8913             id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
8914             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8915                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8916                 if ( id != null ) {
8917                     System.out.println( "value   =" + id.getValue() );
8918                     System.out.println( "provider=" + id.getProvider() );
8919                 }
8920                 return false;
8921             }
8922             // 
8923             id = SequenceIdParser.parse( "gb_AAA96518_1" );
8924             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8925                     || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
8926                 if ( id != null ) {
8927                     System.out.println( "value   =" + id.getValue() );
8928                     System.out.println( "provider=" + id.getProvider() );
8929                 }
8930                 return false;
8931             }
8932             // 
8933             id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
8934             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8935                     || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
8936                 if ( id != null ) {
8937                     System.out.println( "value   =" + id.getValue() );
8938                     System.out.println( "provider=" + id.getProvider() );
8939                 }
8940                 return false;
8941             }
8942             // 
8943             id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
8944             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8945                     || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
8946                 if ( id != null ) {
8947                     System.out.println( "value   =" + id.getValue() );
8948                     System.out.println( "provider=" + id.getProvider() );
8949                 }
8950                 return false;
8951             }
8952             // 
8953             id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
8954             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8955                     || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
8956                 if ( id != null ) {
8957                     System.out.println( "value   =" + id.getValue() );
8958                     System.out.println( "provider=" + id.getProvider() );
8959                 }
8960                 return false;
8961             }
8962             // 
8963             id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
8964             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8965                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
8966                 if ( id != null ) {
8967                     System.out.println( "value   =" + id.getValue() );
8968                     System.out.println( "provider=" + id.getProvider() );
8969                 }
8970                 return false;
8971             }
8972             // 
8973             id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
8974             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8975                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
8976                 if ( id != null ) {
8977                     System.out.println( "value   =" + id.getValue() );
8978                     System.out.println( "provider=" + id.getProvider() );
8979                 }
8980                 return false;
8981             }
8982             // 
8983             id = SequenceIdParser.parse( "P4A123" );
8984             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8985                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
8986                 if ( id != null ) {
8987                     System.out.println( "value   =" + id.getValue() );
8988                     System.out.println( "provider=" + id.getProvider() );
8989                 }
8990                 return false;
8991             }
8992             // 
8993             id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
8994             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8995                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
8996                 if ( id != null ) {
8997                     System.out.println( "value   =" + id.getValue() );
8998                     System.out.println( "provider=" + id.getProvider() );
8999                 }
9000                 return false;
9001             }
9002             // 
9003             id = SequenceIdParser.parse( "XP_12345" );
9004             if ( id != null ) {
9005                 System.out.println( "value   =" + id.getValue() );
9006                 System.out.println( "provider=" + id.getProvider() );
9007                 return false;
9008             }
9009             // lcl_91970_unknown_
9010         }
9011         catch ( final Exception e ) {
9012             e.printStackTrace( System.out );
9013             return false;
9014         }
9015         return true;
9016     }
9017 }