598ad3a1e09f07e39af60d55f5bf9e03d41fe62d
[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: https://sites.google.com/site/cmzmasek/home/software/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.archaeopteryx.AptxUtil;
42 import org.forester.development.DevelopmentTools;
43 import org.forester.evoinference.TestPhylogenyReconstruction;
44 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
46 import org.forester.go.TestGo;
47 import org.forester.io.parsers.FastaParser;
48 import org.forester.io.parsers.GeneralMsaParser;
49 import org.forester.io.parsers.HmmscanPerDomainTableParser;
50 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
51 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
52 import org.forester.io.parsers.nexus.NexusCharactersParser;
53 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
54 import org.forester.io.parsers.nhx.NHXParser;
55 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
56 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
57 import org.forester.io.parsers.tol.TolParser;
58 import org.forester.io.parsers.util.ParserUtils;
59 import org.forester.io.writers.PhylogenyWriter;
60 import org.forester.io.writers.SequenceWriter;
61 import org.forester.msa.BasicMsa;
62 import org.forester.msa.Mafft;
63 import org.forester.msa.Msa;
64 import org.forester.msa.MsaInferrer;
65 import org.forester.msa.MsaMethods;
66 import org.forester.pccx.TestPccx;
67 import org.forester.phylogeny.Phylogeny;
68 import org.forester.phylogeny.PhylogenyBranch;
69 import org.forester.phylogeny.PhylogenyMethods;
70 import org.forester.phylogeny.PhylogenyNode;
71 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
72 import org.forester.phylogeny.data.Accession;
73 import org.forester.phylogeny.data.BinaryCharacters;
74 import org.forester.phylogeny.data.BranchWidth;
75 import org.forester.phylogeny.data.Confidence;
76 import org.forester.phylogeny.data.Distribution;
77 import org.forester.phylogeny.data.DomainArchitecture;
78 import org.forester.phylogeny.data.Event;
79 import org.forester.phylogeny.data.Identifier;
80 import org.forester.phylogeny.data.PhylogenyData;
81 import org.forester.phylogeny.data.PhylogenyDataUtil;
82 import org.forester.phylogeny.data.Polygon;
83 import org.forester.phylogeny.data.PropertiesMap;
84 import org.forester.phylogeny.data.Property;
85 import org.forester.phylogeny.data.Property.AppliesTo;
86 import org.forester.phylogeny.data.ProteinDomain;
87 import org.forester.phylogeny.data.Taxonomy;
88 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
89 import org.forester.phylogeny.factories.PhylogenyFactory;
90 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
91 import org.forester.protein.Protein;
92 import org.forester.rio.TestRIO;
93 import org.forester.sdi.SDI;
94 import org.forester.sdi.SDIR;
95 import org.forester.sdi.TestGSDI;
96 import org.forester.sequence.BasicSequence;
97 import org.forester.sequence.Sequence;
98 import org.forester.surfacing.TestSurfacing;
99 import org.forester.tools.ConfidenceAssessor;
100 import org.forester.tools.SupportCount;
101 import org.forester.tools.TreeSplitMatrix;
102 import org.forester.util.AsciiHistogram;
103 import org.forester.util.BasicDescriptiveStatistics;
104 import org.forester.util.BasicTable;
105 import org.forester.util.BasicTableParser;
106 import org.forester.util.DescriptiveStatistics;
107 import org.forester.util.ForesterConstants;
108 import org.forester.util.ForesterUtil;
109 import org.forester.util.GeneralTable;
110 import org.forester.util.SequenceIdParser;
111 import org.forester.ws.seqdb.SequenceDatabaseEntry;
112 import org.forester.ws.seqdb.SequenceDbWsTools;
113 import org.forester.ws.seqdb.UniProtTaxonomy;
114 import org.forester.ws.wabi.TxSearch;
115 import org.forester.ws.wabi.TxSearch.RANKS;
116 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
117 import org.forester.ws.wabi.TxSearch.TAX_RANK;
118
119 @SuppressWarnings( "unused")
120 public final class Test {
121
122     private final static double  ZERO_DIFF                 = 1.0E-9;
123     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
124                                                                    + ForesterUtil.getFileSeparator() + "test_data"
125                                                                    + ForesterUtil.getFileSeparator();
126     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
127                                                                    + ForesterUtil.getFileSeparator() + "resources"
128                                                                    + ForesterUtil.getFileSeparator();
129     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
130     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
131                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
132                                                                    + ForesterConstants.PHYLO_XML_XSD;
133     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
134                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
135                                                                    + ForesterConstants.PHYLO_XML_XSD;
136
137     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
138         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
139         return p;
140     }
141
142     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
143         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
144     }
145
146     public static boolean isEqual( final double a, final double b ) {
147         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
148     }
149
150     public static void main( final String[] args ) {
151         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
152         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
153                 + "]" );
154         Locale.setDefault( Locale.US );
155         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
156         int failed = 0;
157         int succeeded = 0;
158         System.out.print( "[Test if directory with files for testing exists/is readable: " );
159         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
160             System.out.println( "OK.]" );
161         }
162         else {
163             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
164             System.out.println( "Testing aborted." );
165             System.exit( -1 );
166         }
167         System.out.print( "[Test if resources directory exists/is readable: " );
168         if ( testDir( PATH_TO_RESOURCES ) ) {
169             System.out.println( "OK.]" );
170         }
171         else {
172             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
173             System.out.println( "Testing aborted." );
174             System.exit( -1 );
175         }
176         final long start_time = new Date().getTime();
177         System.out.print( "Sequence writer: " );
178         if ( testSequenceWriter() ) {
179             System.out.println( "OK." );
180             succeeded++;
181         }
182         else {
183             System.out.println( "failed." );
184             failed++;
185         }
186         System.out.print( "Sequence id parsing: " );
187         if ( testSequenceIdParsing() ) {
188             System.out.println( "OK." );
189             succeeded++;
190         }
191         else {
192             System.out.println( "failed." );
193             failed++;
194         }
195         System.out.print( "Hmmscan output parser: " );
196         if ( testHmmscanOutputParser() ) {
197             System.out.println( "OK." );
198             succeeded++;
199         }
200         else {
201             System.out.println( "failed." );
202             failed++;
203         }
204         System.out.print( "Basic node methods: " );
205         if ( Test.testBasicNodeMethods() ) {
206             System.out.println( "OK." );
207             succeeded++;
208         }
209         else {
210             System.out.println( "failed." );
211             failed++;
212         }
213         System.out.print( "Taxonomy code extraction: " );
214         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
215             System.out.println( "OK." );
216             succeeded++;
217         }
218         else {
219             System.out.println( "failed." );
220             failed++;
221         }
222         System.out.print( "SN extraction: " );
223         if ( Test.testExtractSNFromNodeName() ) {
224             System.out.println( "OK." );
225             succeeded++;
226         }
227         else {
228             System.out.println( "failed." );
229             failed++;
230         }
231         System.out.print( "Taxonomy extraction (general): " );
232         if ( Test.testTaxonomyExtraction() ) {
233             System.out.println( "OK." );
234             succeeded++;
235         }
236         else {
237             System.out.println( "failed." );
238             failed++;
239         }
240         System.out.print( "UniProtKB id extraction: " );
241         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
242             System.out.println( "OK." );
243             succeeded++;
244         }
245         else {
246             System.out.println( "failed." );
247             failed++;
248         }
249         System.out.print( "Uri for Aptx web sequence accession: " );
250         if ( Test.testCreateUriForSeqWeb() ) {
251             System.out.println( "OK." );
252             succeeded++;
253         }
254         else {
255             System.out.println( "failed." );
256             failed++;
257         }
258         System.out.print( "Basic node construction and parsing of NHX (node level): " );
259         if ( Test.testNHXNodeParsing() ) {
260             System.out.println( "OK." );
261             succeeded++;
262         }
263         else {
264             System.out.println( "failed." );
265             failed++;
266         }
267         System.out.print( "NHX parsing iterating: " );
268         if ( Test.testNHParsingIter() ) {
269             System.out.println( "OK." );
270             succeeded++;
271         }
272         else {
273             System.out.println( "failed." );
274             failed++;
275         }
276         System.out.print( "NH parsing: " );
277         if ( Test.testNHParsing() ) {
278             System.out.println( "OK." );
279             succeeded++;
280         }
281         else {
282             System.out.println( "failed." );
283             failed++;
284         }
285         System.out.print( "Conversion to NHX (node level): " );
286         if ( Test.testNHXconversion() ) {
287             System.out.println( "OK." );
288             succeeded++;
289         }
290         else {
291             System.out.println( "failed." );
292             failed++;
293         }
294         System.out.print( "NHX parsing: " );
295         if ( Test.testNHXParsing() ) {
296             System.out.println( "OK." );
297             succeeded++;
298         }
299         else {
300             System.out.println( "failed." );
301             failed++;
302         }
303         System.out.print( "NHX parsing with quotes: " );
304         if ( Test.testNHXParsingQuotes() ) {
305             System.out.println( "OK." );
306             succeeded++;
307         }
308         else {
309             System.out.println( "failed." );
310             failed++;
311         }
312         System.out.print( "NHX parsing (MrBayes): " );
313         if ( Test.testNHXParsingMB() ) {
314             System.out.println( "OK." );
315             succeeded++;
316         }
317         else {
318             System.out.println( "failed." );
319             failed++;
320         }
321         System.out.print( "Nexus characters parsing: " );
322         if ( Test.testNexusCharactersParsing() ) {
323             System.out.println( "OK." );
324             succeeded++;
325         }
326         else {
327             System.out.println( "failed." );
328             failed++;
329         }
330         System.out.print( "Nexus tree parsing iterating: " );
331         if ( Test.testNexusTreeParsingIterating() ) {
332             System.out.println( "OK." );
333             succeeded++;
334         }
335         else {
336             System.out.println( "failed." );
337             failed++;
338         }
339         System.out.print( "Nexus tree parsing: " );
340         if ( Test.testNexusTreeParsing() ) {
341             System.out.println( "OK." );
342             succeeded++;
343         }
344         else {
345             System.out.println( "failed." );
346             failed++;
347         }
348         System.out.print( "Nexus tree parsing (translating): " );
349         if ( Test.testNexusTreeParsingTranslating() ) {
350             System.out.println( "OK." );
351             succeeded++;
352         }
353         else {
354             System.out.println( "failed." );
355             failed++;
356         }
357         System.out.print( "Nexus matrix parsing: " );
358         if ( Test.testNexusMatrixParsing() ) {
359             System.out.println( "OK." );
360             succeeded++;
361         }
362         else {
363             System.out.println( "failed." );
364             failed++;
365         }
366         System.out.print( "Basic phyloXML parsing: " );
367         if ( Test.testBasicPhyloXMLparsing() ) {
368             System.out.println( "OK." );
369             succeeded++;
370         }
371         else {
372             System.out.println( "failed." );
373             failed++;
374         }
375         System.out.print( "Basic phyloXML parsing (validating against schema): " );
376         if ( testBasicPhyloXMLparsingValidating() ) {
377             System.out.println( "OK." );
378             succeeded++;
379         }
380         else {
381             System.out.println( "failed." );
382             failed++;
383         }
384         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
385         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
386             System.out.println( "OK." );
387             succeeded++;
388         }
389         else {
390             System.out.println( "failed." );
391             failed++;
392         }
393         System.out.print( "phyloXML Distribution Element: " );
394         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
395             System.out.println( "OK." );
396             succeeded++;
397         }
398         else {
399             System.out.println( "failed." );
400             failed++;
401         }
402         System.out.print( "Tol XML parsing: " );
403         if ( Test.testBasicTolXMLparsing() ) {
404             System.out.println( "OK." );
405             succeeded++;
406         }
407         else {
408             System.out.println( "failed." );
409             failed++;
410         }
411         System.out.print( "Copying of node data: " );
412         if ( Test.testCopyOfNodeData() ) {
413             System.out.println( "OK." );
414             succeeded++;
415         }
416         else {
417             System.out.println( "failed." );
418             failed++;
419         }
420         System.out.print( "Basic tree methods: " );
421         if ( Test.testBasicTreeMethods() ) {
422             System.out.println( "OK." );
423             succeeded++;
424         }
425         else {
426             System.out.println( "failed." );
427             failed++;
428         }
429         System.out.print( "Tree methods: " );
430         if ( Test.testTreeMethods() ) {
431             System.out.println( "OK." );
432             succeeded++;
433         }
434         else {
435             System.out.println( "failed." );
436             failed++;
437         }
438         System.out.print( "Postorder Iterator: " );
439         if ( Test.testPostOrderIterator() ) {
440             System.out.println( "OK." );
441             succeeded++;
442         }
443         else {
444             System.out.println( "failed." );
445             failed++;
446         }
447         System.out.print( "Preorder Iterator: " );
448         if ( Test.testPreOrderIterator() ) {
449             System.out.println( "OK." );
450             succeeded++;
451         }
452         else {
453             System.out.println( "failed." );
454             failed++;
455         }
456         System.out.print( "Levelorder Iterator: " );
457         if ( Test.testLevelOrderIterator() ) {
458             System.out.println( "OK." );
459             succeeded++;
460         }
461         else {
462             System.out.println( "failed." );
463             failed++;
464         }
465         System.out.print( "Re-id methods: " );
466         if ( Test.testReIdMethods() ) {
467             System.out.println( "OK." );
468             succeeded++;
469         }
470         else {
471             System.out.println( "failed." );
472             failed++;
473         }
474         System.out.print( "Methods on last external nodes: " );
475         if ( Test.testLastExternalNodeMethods() ) {
476             System.out.println( "OK." );
477             succeeded++;
478         }
479         else {
480             System.out.println( "failed." );
481             failed++;
482         }
483         System.out.print( "Methods on external nodes: " );
484         if ( Test.testExternalNodeRelatedMethods() ) {
485             System.out.println( "OK." );
486             succeeded++;
487         }
488         else {
489             System.out.println( "failed." );
490             failed++;
491         }
492         System.out.print( "Deletion of external nodes: " );
493         if ( Test.testDeletionOfExternalNodes() ) {
494             System.out.println( "OK." );
495             succeeded++;
496         }
497         else {
498             System.out.println( "failed." );
499             failed++;
500         }
501         System.out.print( "Subtree deletion: " );
502         if ( Test.testSubtreeDeletion() ) {
503             System.out.println( "OK." );
504             succeeded++;
505         }
506         else {
507             System.out.println( "failed." );
508             failed++;
509         }
510         System.out.print( "Phylogeny branch: " );
511         if ( Test.testPhylogenyBranch() ) {
512             System.out.println( "OK." );
513             succeeded++;
514         }
515         else {
516             System.out.println( "failed." );
517             failed++;
518         }
519         System.out.print( "Rerooting: " );
520         if ( Test.testRerooting() ) {
521             System.out.println( "OK." );
522             succeeded++;
523         }
524         else {
525             System.out.println( "failed." );
526             failed++;
527         }
528         System.out.print( "Mipoint rooting: " );
529         if ( Test.testMidpointrooting() ) {
530             System.out.println( "OK." );
531             succeeded++;
532         }
533         else {
534             System.out.println( "failed." );
535             failed++;
536         }
537         System.out.print( "Node removal: " );
538         if ( Test.testNodeRemoval() ) {
539             System.out.println( "OK." );
540             succeeded++;
541         }
542         else {
543             System.out.println( "failed." );
544             failed++;
545         }
546         System.out.print( "Support count: " );
547         if ( Test.testSupportCount() ) {
548             System.out.println( "OK." );
549             succeeded++;
550         }
551         else {
552             System.out.println( "failed." );
553             failed++;
554         }
555         System.out.print( "Support transfer: " );
556         if ( Test.testSupportTransfer() ) {
557             System.out.println( "OK." );
558             succeeded++;
559         }
560         else {
561             System.out.println( "failed." );
562             failed++;
563         }
564         System.out.print( "Finding of LCA: " );
565         if ( Test.testGetLCA() ) {
566             System.out.println( "OK." );
567             succeeded++;
568         }
569         else {
570             System.out.println( "failed." );
571             failed++;
572         }
573         System.out.print( "Finding of LCA 2: " );
574         if ( Test.testGetLCA2() ) {
575             System.out.println( "OK." );
576             succeeded++;
577         }
578         else {
579             System.out.println( "failed." );
580             failed++;
581         }
582         System.out.print( "Calculation of distance between nodes: " );
583         if ( Test.testGetDistance() ) {
584             System.out.println( "OK." );
585             succeeded++;
586         }
587         else {
588             System.out.println( "failed." );
589             failed++;
590         }
591         System.out.print( "Descriptive statistics: " );
592         if ( Test.testDescriptiveStatistics() ) {
593             System.out.println( "OK." );
594             succeeded++;
595         }
596         else {
597             System.out.println( "failed." );
598             failed++;
599         }
600         System.out.print( "Data objects and methods: " );
601         if ( Test.testDataObjects() ) {
602             System.out.println( "OK." );
603             succeeded++;
604         }
605         else {
606             System.out.println( "failed." );
607             failed++;
608         }
609         System.out.print( "Properties map: " );
610         if ( Test.testPropertiesMap() ) {
611             System.out.println( "OK." );
612             succeeded++;
613         }
614         else {
615             System.out.println( "failed." );
616             failed++;
617         }
618         System.out.print( "SDIse: " );
619         if ( Test.testSDIse() ) {
620             System.out.println( "OK." );
621             succeeded++;
622         }
623         else {
624             System.out.println( "failed." );
625             failed++;
626         }
627         System.out.print( "SDIunrooted: " );
628         if ( Test.testSDIunrooted() ) {
629             System.out.println( "OK." );
630             succeeded++;
631         }
632         else {
633             System.out.println( "failed." );
634             failed++;
635         }
636         System.out.print( "GSDI: " );
637         if ( TestGSDI.test() ) {
638             System.out.println( "OK." );
639             succeeded++;
640         }
641         else {
642             System.out.println( "failed." );
643             failed++;
644         }
645         System.out.print( "RIO: " );
646         if ( TestRIO.test() ) {
647             System.out.println( "OK." );
648             succeeded++;
649         }
650         else {
651             System.out.println( "failed." );
652             failed++;
653         }
654         System.out.print( "Phylogeny reconstruction:" );
655         System.out.println();
656         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
657             System.out.println( "OK." );
658             succeeded++;
659         }
660         else {
661             System.out.println( "failed." );
662             failed++;
663         }
664         System.out.print( "Analysis of domain architectures: " );
665         System.out.println();
666         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
667             System.out.println( "OK." );
668             succeeded++;
669         }
670         else {
671             System.out.println( "failed." );
672             failed++;
673         }
674         System.out.print( "GO: " );
675         System.out.println();
676         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
677             System.out.println( "OK." );
678             succeeded++;
679         }
680         else {
681             System.out.println( "failed." );
682             failed++;
683         }
684         System.out.print( "Modeling tools: " );
685         if ( TestPccx.test() ) {
686             System.out.println( "OK." );
687             succeeded++;
688         }
689         else {
690             System.out.println( "failed." );
691             failed++;
692         }
693         System.out.print( "Split Matrix strict: " );
694         if ( Test.testSplitStrict() ) {
695             System.out.println( "OK." );
696             succeeded++;
697         }
698         else {
699             System.out.println( "failed." );
700             failed++;
701         }
702         System.out.print( "Split Matrix: " );
703         if ( Test.testSplit() ) {
704             System.out.println( "OK." );
705             succeeded++;
706         }
707         else {
708             System.out.println( "failed." );
709             failed++;
710         }
711         System.out.print( "Confidence Assessor: " );
712         if ( Test.testConfidenceAssessor() ) {
713             System.out.println( "OK." );
714             succeeded++;
715         }
716         else {
717             System.out.println( "failed." );
718             failed++;
719         }
720         System.out.print( "Basic table: " );
721         if ( Test.testBasicTable() ) {
722             System.out.println( "OK." );
723             succeeded++;
724         }
725         else {
726             System.out.println( "failed." );
727             failed++;
728         }
729         System.out.print( "General table: " );
730         if ( Test.testGeneralTable() ) {
731             System.out.println( "OK." );
732             succeeded++;
733         }
734         else {
735             System.out.println( "failed." );
736             failed++;
737         }
738         System.out.print( "Amino acid sequence: " );
739         if ( Test.testAminoAcidSequence() ) {
740             System.out.println( "OK." );
741             succeeded++;
742         }
743         else {
744             System.out.println( "failed." );
745             failed++;
746         }
747         System.out.print( "General MSA parser: " );
748         if ( Test.testGeneralMsaParser() ) {
749             System.out.println( "OK." );
750             succeeded++;
751         }
752         else {
753             System.out.println( "failed." );
754             failed++;
755         }
756         System.out.print( "Fasta parser for msa: " );
757         if ( Test.testFastaParser() ) {
758             System.out.println( "OK." );
759             succeeded++;
760         }
761         else {
762             System.out.println( "failed." );
763             failed++;
764         }
765         System.out.print( "Creation of balanced phylogeny: " );
766         if ( Test.testCreateBalancedPhylogeny() ) {
767             System.out.println( "OK." );
768             succeeded++;
769         }
770         else {
771             System.out.println( "failed." );
772             failed++;
773         }
774         System.out.print( "EMBL Entry Retrieval: " );
775         if ( Test.testEmblEntryRetrieval() ) {
776             System.out.println( "OK." );
777             succeeded++;
778         }
779         else {
780             System.out.println( "failed." );
781             failed++;
782         }
783         System.out.print( "Uniprot Entry Retrieval: " );
784         if ( Test.testUniprotEntryRetrieval() ) {
785             System.out.println( "OK." );
786             succeeded++;
787         }
788         else {
789             System.out.println( "failed." );
790             failed++;
791         }
792         System.out.print( "Uniprot Taxonomy Search: " );
793         if ( Test.testUniprotTaxonomySearch() ) {
794             System.out.println( "OK." );
795             succeeded++;
796         }
797         else {
798             System.out.println( "failed." );
799             failed++;
800         }
801         //----
802         String path = "";
803         final String os = ForesterUtil.OS_NAME.toLowerCase();
804         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
805             path = "/usr/local/bin/mafft";
806         }
807         else if ( os.indexOf( "win" ) >= 0 ) {
808             path = "C:\\Program Files\\mafft-win\\mafft.bat";
809         }
810         else {
811             path = "/home/czmasek/bin/mafft";
812         }
813         if ( !MsaInferrer.isInstalled( path ) ) {
814             path = "mafft";
815         }
816         if ( !MsaInferrer.isInstalled( path ) ) {
817             path = "/usr/local/bin/mafft";
818         }
819         if ( MsaInferrer.isInstalled( path ) ) {
820             System.out.print( "MAFFT (external program): " );
821             if ( Test.testMafft( path ) ) {
822                 System.out.println( "OK." );
823                 succeeded++;
824             }
825             else {
826                 System.out.println( "failed [will not count towards failed tests]" );
827             }
828         }
829         //----
830         System.out.print( "Next nodes with collapsed: " );
831         if ( Test.testNextNodeWithCollapsing() ) {
832             System.out.println( "OK." );
833             succeeded++;
834         }
835         else {
836             System.out.println( "failed." );
837             failed++;
838         }
839         System.out.print( "Simple MSA quality: " );
840         if ( Test.testMsaQualityMethod() ) {
841             System.out.println( "OK." );
842             succeeded++;
843         }
844         else {
845             System.out.println( "failed." );
846             failed++;
847         }
848         System.out.println();
849         final Runtime rt = java.lang.Runtime.getRuntime();
850         final long free_memory = rt.freeMemory() / 1000000;
851         final long total_memory = rt.totalMemory() / 1000000;
852         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
853                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
854         System.out.println();
855         System.out.println( "Successful tests: " + succeeded );
856         System.out.println( "Failed     tests: " + failed );
857         System.out.println();
858         if ( failed < 1 ) {
859             System.out.println( "OK." );
860         }
861         else {
862             System.out.println( "Not OK." );
863         }
864     }
865
866     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
867         try {
868             PhylogenyNode n = new PhylogenyNode();
869             n.setName( "tr|B3RJ64" );
870             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
871                 return false;
872             }
873             n.setName( "tr.B3RJ64" );
874             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
875                 return false;
876             }
877             n.setName( "tr=B3RJ64" );
878             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
879                 return false;
880             }
881             n.setName( "tr-B3RJ64" );
882             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
883                 return false;
884             }
885             n.setName( "tr/B3RJ64" );
886             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
887                 return false;
888             }
889             n.setName( "tr\\B3RJ64" );
890             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
891                 return false;
892             }
893             n.setName( "tr_B3RJ64" );
894             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
895                 return false;
896             }
897             n.setName( " tr|B3RJ64 " );
898             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
899                 return false;
900             }
901             n.setName( "-tr|B3RJ64-" );
902             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
903                 return false;
904             }
905             n.setName( "-tr=B3RJ64-" );
906             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
907                 return false;
908             }
909             n.setName( "_tr=B3RJ64_" );
910             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
911                 return false;
912             }
913             n.setName( " tr_tr|B3RJ64_sp|123 " );
914             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
915                 return false;
916             }
917             n.setName( "sp|B3RJ64" );
918             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
919                 return false;
920             }
921             n.setName( "ssp|B3RJ64" );
922             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
923                 return false;
924             }
925             n.setName( "sp|B3RJ64C" );
926             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
927                 return false;
928             }
929             n.setName( "sp B3RJ64" );
930             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
931                 return false;
932             }
933             n.setName( "sp|B3RJ6X" );
934             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
935                 return false;
936             }
937             n.setName( "sp|B3RJ6" );
938             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
939                 return false;
940             }
941             n.setName( "K1PYK7_CRAGI" );
942             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
943                 return false;
944             }
945             n.setName( "K1PYK7_PEA" );
946             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) {
947                 return false;
948             }
949             n.setName( "K1PYK7_RAT" );
950             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) {
951                 return false;
952             }
953             n.setName( "K1PYK7_PIG" );
954             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
955                 return false;
956             }
957             n.setName( "~K1PYK7_PIG~" );
958             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
959                 return false;
960             }
961             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
962             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
963                 return false;
964             }
965             n.setName( "K1PYKX_CRAGI" );
966             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
967                 return false;
968             }
969             n.setName( "XXXXX_CRAGI" );
970             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) {
971                 return false;
972             }
973             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
974             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) {
975                 return false;
976             }
977             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
978             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
979                 return false;
980             }
981             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
982             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) {
983                 return false;
984             }
985             n = new PhylogenyNode();
986             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
987             seq.setSymbol( "K1PYK7_CRAGI" );
988             n.getNodeData().addSequence( seq );
989             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
990                 return false;
991             }
992             seq.setSymbol( "tr|B3RJ64" );
993             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
994                 return false;
995             }
996             n = new PhylogenyNode();
997             seq = new org.forester.phylogeny.data.Sequence();
998             seq.setName( "K1PYK7_CRAGI" );
999             n.getNodeData().addSequence( seq );
1000             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
1001                 return false;
1002             }
1003             seq.setName( "tr|B3RJ64" );
1004             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
1005                 return false;
1006             }
1007             n = new PhylogenyNode();
1008             seq = new org.forester.phylogeny.data.Sequence();
1009             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
1010             n.getNodeData().addSequence( seq );
1011             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) {
1012                 return false;
1013             }
1014             n = new PhylogenyNode();
1015             seq = new org.forester.phylogeny.data.Sequence();
1016             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
1017             n.getNodeData().addSequence( seq );
1018             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
1019                 return false;
1020             }
1021             //
1022             n = new PhylogenyNode();
1023             n.setName( "ACP19736" );
1024             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1025                 return false;
1026             }
1027             n = new PhylogenyNode();
1028             n.setName( "_ACP19736_" );
1029             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1030                 return false;
1031             }
1032         }
1033         catch ( final Exception e ) {
1034             e.printStackTrace( System.out );
1035             return false;
1036         }
1037         return true;
1038     }
1039
1040     private static boolean testCreateUriForSeqWeb() {
1041         try {
1042             final PhylogenyNode n = new PhylogenyNode();
1043             n.setName( "tr|B3RJ64" );
1044             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
1045                 return false;
1046             }
1047             n.setName( "B0LM41_HUMAN" );
1048             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
1049                 return false;
1050             }
1051             n.setName( "NP_001025424" );
1052             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
1053                 return false;
1054             }
1055             n.setName( "_NM_001030253-" );
1056             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
1057                 return false;
1058             }
1059             n.setName( "XM_002122186" );
1060             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
1061                 return false;
1062             }
1063             n.setName( "dgh_AAA34956_gdg" );
1064             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
1065                 return false;
1066             }
1067             n.setName( "j40f4_Q06891.1_fndn2 fnr3" );
1068             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891.1" ) ) {
1069                 return false;
1070             }
1071             n.setName( "GI:394892" );
1072             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1073                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1074                 return false;
1075             }
1076             n.setName( "gi_394892" );
1077             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1078                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1079                 return false;
1080             }
1081             n.setName( "gi6335_gi_394892_56635_Gi_43" );
1082             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1083                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1084                 return false;
1085             }
1086         }
1087         catch ( final Exception e ) {
1088             e.printStackTrace( System.out );
1089             return false;
1090         }
1091         return true;
1092     }
1093
1094     private static boolean testExtractSNFromNodeName() {
1095         try {
1096             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
1097                 return false;
1098             }
1099             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
1100                     .equals( "Mus musculus musculus" ) ) {
1101                 return false;
1102             }
1103             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
1104                     .equals( "Mus musculus musculus" ) ) {
1105                 return false;
1106             }
1107             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
1108                 return false;
1109             }
1110             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
1111                     .equals( "Mus musculus" ) ) {
1112                 return false;
1113             }
1114         }
1115         catch ( final Exception e ) {
1116             e.printStackTrace( System.out );
1117             return false;
1118         }
1119         return true;
1120     }
1121
1122     private static boolean testExtractTaxonomyCodeFromNodeName() {
1123         try {
1124             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1125                 return false;
1126             }
1127             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1128                     .equals( "SOYBN" ) ) {
1129                 return false;
1130             }
1131             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
1132                     .equals( "ARATH" ) ) {
1133                 return false;
1134             }
1135             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
1136                     .equals( "ARATH" ) ) {
1137                 return false;
1138             }
1139             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
1140                 return false;
1141             }
1142             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
1143                 return false;
1144             }
1145             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1146                 return false;
1147             }
1148             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1149                     .equals( "SOYBN" ) ) {
1150                 return false;
1151             }
1152             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1153                     .equals( "SOYBN" ) ) {
1154                 return false;
1155             }
1156             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1157                     .equals( "SOYBN" ) ) {
1158                 return false;
1159             }
1160             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1161                     .equals( "SOYBN" ) ) {
1162                 return false;
1163             }
1164             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1165                     .equals( "SOYBN" ) ) {
1166                 return false;
1167             }
1168             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1169                     .equals( "SOYBN" ) ) {
1170                 return false;
1171             }
1172             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
1173                     .equals( "SOYBN" ) ) {
1174                 return false;
1175             }
1176             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
1177                     .equals( "SOYBN" ) ) {
1178                 return false;
1179             }
1180             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
1181                 return false;
1182             }
1183             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
1184                     .equals( "SOYBN" ) ) {
1185                 return false;
1186             }
1187             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
1188                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
1189                 return false;
1190             }
1191             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
1192                     .equals( "9YX45" ) ) {
1193                 return false;
1194             }
1195             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
1196                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1197                     .equals( "MOUSE" ) ) {
1198                 return false;
1199             }
1200             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
1201                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1202                     .equals( "MOUSE" ) ) {
1203                 return false;
1204             }
1205             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
1206                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1207                     .equals( "MOUSE" ) ) {
1208                 return false;
1209             }
1210             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
1211                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1212                 return false;
1213             }
1214             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
1215                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1216                 return false;
1217             }
1218             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1219                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1220                 return false;
1221             }
1222             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1223                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1224                 return false;
1225             }
1226             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
1227                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1228                 return false;
1229             }
1230             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
1231                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1232                 return false;
1233             }
1234             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
1235                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1236                 return false;
1237             }
1238             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1239                     .equals( "RAT" ) ) {
1240                 return false;
1241             }
1242             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1243                     .equals( "PIG" ) ) {
1244                 return false;
1245             }
1246             if ( !ParserUtils
1247                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1248                     .equals( "MOUSE" ) ) {
1249                 return false;
1250             }
1251             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1252                     .equals( "MOUSE" ) ) {
1253                 return false;
1254             }
1255             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1256                 return false;
1257             }
1258         }
1259         catch ( final Exception e ) {
1260             e.printStackTrace( System.out );
1261             return false;
1262         }
1263         return true;
1264     }
1265
1266     private static boolean testBasicNodeMethods() {
1267         try {
1268             if ( PhylogenyNode.getNodeCount() != 0 ) {
1269                 return false;
1270             }
1271             final PhylogenyNode n1 = new PhylogenyNode();
1272             final PhylogenyNode n2 = PhylogenyNode
1273                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1274             final PhylogenyNode n3 = PhylogenyNode
1275                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1276             final PhylogenyNode n4 = PhylogenyNode
1277                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1278             if ( n1.isHasAssignedEvent() ) {
1279                 return false;
1280             }
1281             if ( PhylogenyNode.getNodeCount() != 4 ) {
1282                 return false;
1283             }
1284             if ( n3.getIndicator() != 0 ) {
1285                 return false;
1286             }
1287             if ( n3.getNumberOfExternalNodes() != 1 ) {
1288                 return false;
1289             }
1290             if ( !n3.isExternal() ) {
1291                 return false;
1292             }
1293             if ( !n3.isRoot() ) {
1294                 return false;
1295             }
1296             if ( !n4.getName().equals( "n4" ) ) {
1297                 return false;
1298             }
1299         }
1300         catch ( final Exception e ) {
1301             e.printStackTrace( System.out );
1302             return false;
1303         }
1304         return true;
1305     }
1306
1307     private static boolean testBasicPhyloXMLparsing() {
1308         try {
1309             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1310             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1311             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1312                                                               xml_parser );
1313             if ( xml_parser.getErrorCount() > 0 ) {
1314                 System.out.println( xml_parser.getErrorMessages().toString() );
1315                 return false;
1316             }
1317             if ( phylogenies_0.length != 4 ) {
1318                 return false;
1319             }
1320             final Phylogeny t1 = phylogenies_0[ 0 ];
1321             final Phylogeny t2 = phylogenies_0[ 1 ];
1322             final Phylogeny t3 = phylogenies_0[ 2 ];
1323             final Phylogeny t4 = phylogenies_0[ 3 ];
1324             if ( t1.getNumberOfExternalNodes() != 1 ) {
1325                 return false;
1326             }
1327             if ( !t1.isRooted() ) {
1328                 return false;
1329             }
1330             if ( t1.isRerootable() ) {
1331                 return false;
1332             }
1333             if ( !t1.getType().equals( "gene_tree" ) ) {
1334                 return false;
1335             }
1336             if ( t2.getNumberOfExternalNodes() != 2 ) {
1337                 return false;
1338             }
1339             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1340                 return false;
1341             }
1342             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1343                 return false;
1344             }
1345             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1346                 return false;
1347             }
1348             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1349                 return false;
1350             }
1351             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1352                 return false;
1353             }
1354             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1355                 return false;
1356             }
1357             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1358                     .startsWith( "actgtgggggt" ) ) {
1359                 return false;
1360             }
1361             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1362                     .startsWith( "ctgtgatgcat" ) ) {
1363                 return false;
1364             }
1365             if ( t3.getNumberOfExternalNodes() != 4 ) {
1366                 return false;
1367             }
1368             if ( !t1.getName().equals( "t1" ) ) {
1369                 return false;
1370             }
1371             if ( !t2.getName().equals( "t2" ) ) {
1372                 return false;
1373             }
1374             if ( !t3.getName().equals( "t3" ) ) {
1375                 return false;
1376             }
1377             if ( !t4.getName().equals( "t4" ) ) {
1378                 return false;
1379             }
1380             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1381                 return false;
1382             }
1383             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1384                 return false;
1385             }
1386             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1387                 return false;
1388             }
1389             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1390                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1391                 return false;
1392             }
1393             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1394                 return false;
1395             }
1396             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1397                 return false;
1398             }
1399             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1400                 return false;
1401             }
1402             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1403                     .equals( "apoptosis" ) ) {
1404                 return false;
1405             }
1406             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1407                     .equals( "GO:0006915" ) ) {
1408                 return false;
1409             }
1410             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1411                     .equals( "UniProtKB" ) ) {
1412                 return false;
1413             }
1414             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1415                     .equals( "experimental" ) ) {
1416                 return false;
1417             }
1418             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1419                     .equals( "function" ) ) {
1420                 return false;
1421             }
1422             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1423                     .getValue() != 1 ) {
1424                 return false;
1425             }
1426             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1427                     .getType().equals( "ml" ) ) {
1428                 return false;
1429             }
1430             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1431                     .equals( "apoptosis" ) ) {
1432                 return false;
1433             }
1434             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1435                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1436                 return false;
1437             }
1438             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1439                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1440                 return false;
1441             }
1442             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1443                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1444                 return false;
1445             }
1446             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1447                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1448                 return false;
1449             }
1450             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1451                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1452                 return false;
1453             }
1454             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1455                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1456                 return false;
1457             }
1458             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1459                     .equals( "GO:0005829" ) ) {
1460                 return false;
1461             }
1462             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1463                     .equals( "intracellular organelle" ) ) {
1464                 return false;
1465             }
1466             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1467                 return false;
1468             }
1469             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1470                     .equals( "UniProt link" ) ) ) {
1471                 return false;
1472             }
1473             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1474                 return false;
1475             }
1476         }
1477         catch ( final Exception e ) {
1478             e.printStackTrace( System.out );
1479             return false;
1480         }
1481         return true;
1482     }
1483
1484     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1485         try {
1486             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1487             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1488             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1489                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1490             }
1491             else {
1492                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1493             }
1494             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1495                                                               xml_parser );
1496             if ( xml_parser.getErrorCount() > 0 ) {
1497                 System.out.println( xml_parser.getErrorMessages().toString() );
1498                 return false;
1499             }
1500             if ( phylogenies_0.length != 4 ) {
1501                 return false;
1502             }
1503             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1504             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1505             if ( phylogenies_t1.length != 1 ) {
1506                 return false;
1507             }
1508             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1509             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1510                 return false;
1511             }
1512             if ( !t1_rt.isRooted() ) {
1513                 return false;
1514             }
1515             if ( t1_rt.isRerootable() ) {
1516                 return false;
1517             }
1518             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1519                 return false;
1520             }
1521             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1522             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1523             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1524             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1525                 return false;
1526             }
1527             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1528                 return false;
1529             }
1530             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1531                 return false;
1532             }
1533             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1534                 return false;
1535             }
1536             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1537                     .startsWith( "actgtgggggt" ) ) {
1538                 return false;
1539             }
1540             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1541                     .startsWith( "ctgtgatgcat" ) ) {
1542                 return false;
1543             }
1544             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1545             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1546             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1547             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1548             if ( phylogenies_1.length != 1 ) {
1549                 return false;
1550             }
1551             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1552             if ( !t3_rt.getName().equals( "t3" ) ) {
1553                 return false;
1554             }
1555             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1556                 return false;
1557             }
1558             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1559                 return false;
1560             }
1561             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1562                 return false;
1563             }
1564             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1565                 return false;
1566             }
1567             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1568                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1569                 return false;
1570             }
1571             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1572                 return false;
1573             }
1574             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1575                 return false;
1576             }
1577             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1578                     .equals( "UniProtKB" ) ) {
1579                 return false;
1580             }
1581             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1582                     .equals( "apoptosis" ) ) {
1583                 return false;
1584             }
1585             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1586                     .equals( "GO:0006915" ) ) {
1587                 return false;
1588             }
1589             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1590                     .equals( "UniProtKB" ) ) {
1591                 return false;
1592             }
1593             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1594                     .equals( "experimental" ) ) {
1595                 return false;
1596             }
1597             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1598                     .equals( "function" ) ) {
1599                 return false;
1600             }
1601             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1602                     .getValue() != 1 ) {
1603                 return false;
1604             }
1605             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1606                     .getType().equals( "ml" ) ) {
1607                 return false;
1608             }
1609             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1610                     .equals( "apoptosis" ) ) {
1611                 return false;
1612             }
1613             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1614                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1615                 return false;
1616             }
1617             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1618                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1619                 return false;
1620             }
1621             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1622                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1623                 return false;
1624             }
1625             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1626                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1627                 return false;
1628             }
1629             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1630                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1631                 return false;
1632             }
1633             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1634                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1635                 return false;
1636             }
1637             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1638                     .equals( "GO:0005829" ) ) {
1639                 return false;
1640             }
1641             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1642                     .equals( "intracellular organelle" ) ) {
1643                 return false;
1644             }
1645             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1646                 return false;
1647             }
1648             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1649                     .equals( "UniProt link" ) ) ) {
1650                 return false;
1651             }
1652             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1653                 return false;
1654             }
1655             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1656                 return false;
1657             }
1658             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1659                     .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." ) ) ) {
1660                 return false;
1661             }
1662             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1663                 return false;
1664             }
1665             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1666                 return false;
1667             }
1668             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1669                 return false;
1670             }
1671             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1672                 return false;
1673             }
1674             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1675                     .equals( "ncbi" ) ) {
1676                 return false;
1677             }
1678             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1679                 return false;
1680             }
1681             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1682                     .getName().equals( "B" ) ) {
1683                 return false;
1684             }
1685             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1686                     .getFrom() != 21 ) {
1687                 return false;
1688             }
1689             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1690                 return false;
1691             }
1692             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1693                     .getLength() != 24 ) {
1694                 return false;
1695             }
1696             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1697                     .getConfidence() != 2144 ) {
1698                 return false;
1699             }
1700             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1701                     .equals( "pfam" ) ) {
1702                 return false;
1703             }
1704             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1705                 return false;
1706             }
1707             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1708                 return false;
1709             }
1710             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1711                 return false;
1712             }
1713             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1714                 return false;
1715             }
1716             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1717             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1718                 return false;
1719             }
1720             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1721                 return false;
1722             }
1723             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1724                 return false;
1725             }
1726             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1727                 return false;
1728             }
1729             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1730                 return false;
1731             }
1732             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1733                 return false;
1734             }
1735             if ( taxbb.getSynonyms().size() != 2 ) {
1736                 return false;
1737             }
1738             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1739                 return false;
1740             }
1741             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1742                 return false;
1743             }
1744             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1745                 return false;
1746             }
1747             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1748                 return false;
1749             }
1750             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1751                 return false;
1752             }
1753             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1754                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1755                 ;
1756                 return false;
1757             }
1758             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1759                 return false;
1760             }
1761             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1762                 return false;
1763             }
1764             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1765                 return false;
1766             }
1767             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1768                 return false;
1769             }
1770             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1771                 return false;
1772             }
1773             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1774                 return false;
1775             }
1776             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1777                 return false;
1778             }
1779             //
1780             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1781                 return false;
1782             }
1783             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1784                     .equalsIgnoreCase( "435" ) ) {
1785                 return false;
1786             }
1787             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1788                 return false;
1789             }
1790             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1791                     .equalsIgnoreCase( "443.7" ) ) {
1792                 return false;
1793             }
1794             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1795                 return false;
1796             }
1797             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1798                 return false;
1799             }
1800             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1801                     .equalsIgnoreCase( "433" ) ) {
1802                 return false;
1803             }
1804         }
1805         catch ( final Exception e ) {
1806             e.printStackTrace( System.out );
1807             return false;
1808         }
1809         return true;
1810     }
1811
1812     private static boolean testBasicPhyloXMLparsingValidating() {
1813         try {
1814             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1815             PhyloXmlParser xml_parser = null;
1816             try {
1817                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1818             }
1819             catch ( final Exception e ) {
1820                 // Do nothing -- means were not running from jar.
1821             }
1822             if ( xml_parser == null ) {
1823                 xml_parser = new PhyloXmlParser();
1824                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1825                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1826                 }
1827                 else {
1828                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1829                 }
1830             }
1831             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1832                                                               xml_parser );
1833             if ( xml_parser.getErrorCount() > 0 ) {
1834                 System.out.println( xml_parser.getErrorMessages().toString() );
1835                 return false;
1836             }
1837             if ( phylogenies_0.length != 4 ) {
1838                 return false;
1839             }
1840             final Phylogeny t1 = phylogenies_0[ 0 ];
1841             final Phylogeny t2 = phylogenies_0[ 1 ];
1842             final Phylogeny t3 = phylogenies_0[ 2 ];
1843             final Phylogeny t4 = phylogenies_0[ 3 ];
1844             if ( !t1.getName().equals( "t1" ) ) {
1845                 return false;
1846             }
1847             if ( !t2.getName().equals( "t2" ) ) {
1848                 return false;
1849             }
1850             if ( !t3.getName().equals( "t3" ) ) {
1851                 return false;
1852             }
1853             if ( !t4.getName().equals( "t4" ) ) {
1854                 return false;
1855             }
1856             if ( t1.getNumberOfExternalNodes() != 1 ) {
1857                 return false;
1858             }
1859             if ( t2.getNumberOfExternalNodes() != 2 ) {
1860                 return false;
1861             }
1862             if ( t3.getNumberOfExternalNodes() != 4 ) {
1863                 return false;
1864             }
1865             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1866             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1867             if ( xml_parser.getErrorCount() > 0 ) {
1868                 System.out.println( "errors:" );
1869                 System.out.println( xml_parser.getErrorMessages().toString() );
1870                 return false;
1871             }
1872             if ( phylogenies_1.length != 4 ) {
1873                 return false;
1874             }
1875             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1876                                                               xml_parser );
1877             if ( xml_parser.getErrorCount() > 0 ) {
1878                 System.out.println( "errors:" );
1879                 System.out.println( xml_parser.getErrorMessages().toString() );
1880                 return false;
1881             }
1882             if ( phylogenies_2.length != 1 ) {
1883                 return false;
1884             }
1885             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1886                 return false;
1887             }
1888             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1889                                                               xml_parser );
1890             if ( xml_parser.getErrorCount() > 0 ) {
1891                 System.out.println( xml_parser.getErrorMessages().toString() );
1892                 return false;
1893             }
1894             if ( phylogenies_3.length != 2 ) {
1895                 return false;
1896             }
1897             final Phylogeny a = phylogenies_3[ 0 ];
1898             if ( !a.getName().equals( "tree 4" ) ) {
1899                 return false;
1900             }
1901             if ( a.getNumberOfExternalNodes() != 3 ) {
1902                 return false;
1903             }
1904             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1905                 return false;
1906             }
1907             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1908                 return false;
1909             }
1910             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1911                                                               xml_parser );
1912             if ( xml_parser.getErrorCount() > 0 ) {
1913                 System.out.println( xml_parser.getErrorMessages().toString() );
1914                 return false;
1915             }
1916             if ( phylogenies_4.length != 1 ) {
1917                 return false;
1918             }
1919             final Phylogeny s = phylogenies_4[ 0 ];
1920             if ( s.getNumberOfExternalNodes() != 6 ) {
1921                 return false;
1922             }
1923             s.getNode( "first" );
1924             s.getNode( "<>" );
1925             s.getNode( "\"<a'b&c'd\">\"" );
1926             s.getNode( "'''\"" );
1927             s.getNode( "\"\"\"" );
1928             s.getNode( "dick & doof" );
1929         }
1930         catch ( final Exception e ) {
1931             e.printStackTrace( System.out );
1932             return false;
1933         }
1934         return true;
1935     }
1936
1937     private static boolean testBasicTable() {
1938         try {
1939             final BasicTable<String> t0 = new BasicTable<String>();
1940             if ( t0.getNumberOfColumns() != 0 ) {
1941                 return false;
1942             }
1943             if ( t0.getNumberOfRows() != 0 ) {
1944                 return false;
1945             }
1946             t0.setValue( 3, 2, "23" );
1947             t0.setValue( 10, 1, "error" );
1948             t0.setValue( 10, 1, "110" );
1949             t0.setValue( 9, 1, "19" );
1950             t0.setValue( 1, 10, "101" );
1951             t0.setValue( 10, 10, "1010" );
1952             t0.setValue( 100, 10, "10100" );
1953             t0.setValue( 0, 0, "00" );
1954             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1955                 return false;
1956             }
1957             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1958                 return false;
1959             }
1960             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1961                 return false;
1962             }
1963             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1964                 return false;
1965             }
1966             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1967                 return false;
1968             }
1969             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1970                 return false;
1971             }
1972             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1973                 return false;
1974             }
1975             if ( t0.getNumberOfColumns() != 101 ) {
1976                 return false;
1977             }
1978             if ( t0.getNumberOfRows() != 11 ) {
1979                 return false;
1980             }
1981             if ( t0.getValueAsString( 49, 4 ) != null ) {
1982                 return false;
1983             }
1984             final String l = ForesterUtil.getLineSeparator();
1985             final StringBuffer source = new StringBuffer();
1986             source.append( "" + l );
1987             source.append( "# 1 1 1 1 1 1 1 1" + l );
1988             source.append( " 00 01 02 03" + l );
1989             source.append( "   10 11 12 13  " + l );
1990             source.append( "20 21 22 23 " + l );
1991             source.append( "    30  31    32 33" + l );
1992             source.append( "40 41 42 43" + l );
1993             source.append( "  # 1 1 1 1 1 " + l );
1994             source.append( "50 51 52 53 54" + l );
1995             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
1996             if ( t1.getNumberOfColumns() != 5 ) {
1997                 return false;
1998             }
1999             if ( t1.getNumberOfRows() != 6 ) {
2000                 return false;
2001             }
2002             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2003                 return false;
2004             }
2005             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2006                 return false;
2007             }
2008             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2009                 return false;
2010             }
2011             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2012                 return false;
2013             }
2014             final StringBuffer source1 = new StringBuffer();
2015             source1.append( "" + l );
2016             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2017             source1.append( " 00; 01 ;02;03" + l );
2018             source1.append( "   10; 11; 12; 13  " + l );
2019             source1.append( "20; 21; 22; 23 " + l );
2020             source1.append( "    30;  31;    32; 33" + l );
2021             source1.append( "40;41;42;43" + l );
2022             source1.append( "  # 1 1 1 1 1 " + l );
2023             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2024             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2025             if ( t2.getNumberOfColumns() != 5 ) {
2026                 return false;
2027             }
2028             if ( t2.getNumberOfRows() != 6 ) {
2029                 return false;
2030             }
2031             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2032                 return false;
2033             }
2034             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2035                 return false;
2036             }
2037             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2038                 return false;
2039             }
2040             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2041                 return false;
2042             }
2043             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2044                 return false;
2045             }
2046             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2047                 return false;
2048             }
2049             final StringBuffer source2 = new StringBuffer();
2050             source2.append( "" + l );
2051             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2052             source2.append( " 00; 01 ;02;03" + l );
2053             source2.append( "   10; 11; 12; 13  " + l );
2054             source2.append( "20; 21; 22; 23 " + l );
2055             source2.append( "                     " + l );
2056             source2.append( "    30;  31;    32; 33" + l );
2057             source2.append( "40;41;42;43" + l );
2058             source2.append( "  comment: 1 1 1 1 1 " + l );
2059             source2.append( ";;;50  ;   52; 53;;54   " + l );
2060             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2061                                                                         ';',
2062                                                                         false,
2063                                                                         false,
2064                                                                         "comment:",
2065                                                                         false );
2066             if ( tl.size() != 2 ) {
2067                 return false;
2068             }
2069             final BasicTable<String> t3 = tl.get( 0 );
2070             final BasicTable<String> t4 = tl.get( 1 );
2071             if ( t3.getNumberOfColumns() != 4 ) {
2072                 return false;
2073             }
2074             if ( t3.getNumberOfRows() != 3 ) {
2075                 return false;
2076             }
2077             if ( t4.getNumberOfColumns() != 4 ) {
2078                 return false;
2079             }
2080             if ( t4.getNumberOfRows() != 3 ) {
2081                 return false;
2082             }
2083             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2084                 return false;
2085             }
2086             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2087                 return false;
2088             }
2089         }
2090         catch ( final Exception e ) {
2091             e.printStackTrace( System.out );
2092             return false;
2093         }
2094         return true;
2095     }
2096
2097     private static boolean testBasicTolXMLparsing() {
2098         try {
2099             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2100             final TolParser parser = new TolParser();
2101             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2102             if ( parser.getErrorCount() > 0 ) {
2103                 System.out.println( parser.getErrorMessages().toString() );
2104                 return false;
2105             }
2106             if ( phylogenies_0.length != 1 ) {
2107                 return false;
2108             }
2109             final Phylogeny t1 = phylogenies_0[ 0 ];
2110             if ( t1.getNumberOfExternalNodes() != 5 ) {
2111                 return false;
2112             }
2113             if ( !t1.isRooted() ) {
2114                 return false;
2115             }
2116             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2117                 return false;
2118             }
2119             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2120                 return false;
2121             }
2122             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2123                 return false;
2124             }
2125             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2126                 return false;
2127             }
2128             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2129             if ( parser.getErrorCount() > 0 ) {
2130                 System.out.println( parser.getErrorMessages().toString() );
2131                 return false;
2132             }
2133             if ( phylogenies_1.length != 1 ) {
2134                 return false;
2135             }
2136             final Phylogeny t2 = phylogenies_1[ 0 ];
2137             if ( t2.getNumberOfExternalNodes() != 664 ) {
2138                 return false;
2139             }
2140             if ( !t2.isRooted() ) {
2141                 return false;
2142             }
2143             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2144                 return false;
2145             }
2146             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2147                 return false;
2148             }
2149             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2150                 return false;
2151             }
2152             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2153                 return false;
2154             }
2155             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2156                 return false;
2157             }
2158             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2159                     .equals( "Aquifex" ) ) {
2160                 return false;
2161             }
2162             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2163             if ( parser.getErrorCount() > 0 ) {
2164                 System.out.println( parser.getErrorMessages().toString() );
2165                 return false;
2166             }
2167             if ( phylogenies_2.length != 1 ) {
2168                 return false;
2169             }
2170             final Phylogeny t3 = phylogenies_2[ 0 ];
2171             if ( t3.getNumberOfExternalNodes() != 184 ) {
2172                 return false;
2173             }
2174             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2175                 return false;
2176             }
2177             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2178                 return false;
2179             }
2180             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2181                 return false;
2182             }
2183             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2184             if ( parser.getErrorCount() > 0 ) {
2185                 System.out.println( parser.getErrorMessages().toString() );
2186                 return false;
2187             }
2188             if ( phylogenies_3.length != 1 ) {
2189                 return false;
2190             }
2191             final Phylogeny t4 = phylogenies_3[ 0 ];
2192             if ( t4.getNumberOfExternalNodes() != 1 ) {
2193                 return false;
2194             }
2195             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2196                 return false;
2197             }
2198             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2199                 return false;
2200             }
2201             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2202                 return false;
2203             }
2204             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2205             if ( parser.getErrorCount() > 0 ) {
2206                 System.out.println( parser.getErrorMessages().toString() );
2207                 return false;
2208             }
2209             if ( phylogenies_4.length != 1 ) {
2210                 return false;
2211             }
2212             final Phylogeny t5 = phylogenies_4[ 0 ];
2213             if ( t5.getNumberOfExternalNodes() != 13 ) {
2214                 return false;
2215             }
2216             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2217                 return false;
2218             }
2219             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2220                 return false;
2221             }
2222             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2223                 return false;
2224             }
2225         }
2226         catch ( final Exception e ) {
2227             e.printStackTrace( System.out );
2228             return false;
2229         }
2230         return true;
2231     }
2232
2233     private static boolean testBasicTreeMethods() {
2234         try {
2235             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2236             final Phylogeny t1 = factory.create();
2237             if ( !t1.isEmpty() ) {
2238                 return false;
2239             }
2240             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2241             if ( t2.getNumberOfExternalNodes() != 4 ) {
2242                 return false;
2243             }
2244             if ( t2.getHeight() != 8.5 ) {
2245                 return false;
2246             }
2247             if ( !t2.isCompletelyBinary() ) {
2248                 return false;
2249             }
2250             if ( t2.isEmpty() ) {
2251                 return false;
2252             }
2253             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2254             if ( t3.getNumberOfExternalNodes() != 5 ) {
2255                 return false;
2256             }
2257             if ( t3.getHeight() != 11 ) {
2258                 return false;
2259             }
2260             if ( t3.isCompletelyBinary() ) {
2261                 return false;
2262             }
2263             final PhylogenyNode n = t3.getNode( "ABC" );
2264             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 ];
2265             if ( t4.getNumberOfExternalNodes() != 9 ) {
2266                 return false;
2267             }
2268             if ( t4.getHeight() != 11 ) {
2269                 return false;
2270             }
2271             if ( t4.isCompletelyBinary() ) {
2272                 return false;
2273             }
2274             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)" );
2275             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2276             if ( t5.getNumberOfExternalNodes() != 8 ) {
2277                 return false;
2278             }
2279             if ( t5.getHeight() != 15 ) {
2280                 return false;
2281             }
2282             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)" );
2283             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2284             if ( t6.getHeight() != 15 ) {
2285                 return false;
2286             }
2287             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)" );
2288             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2289             if ( t7.getHeight() != 15 ) {
2290                 return false;
2291             }
2292             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)" );
2293             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2294             if ( t8.getNumberOfExternalNodes() != 10 ) {
2295                 return false;
2296             }
2297             if ( t8.getHeight() != 15 ) {
2298                 return false;
2299             }
2300             final char[] a9 = new char[] { 'a' };
2301             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2302             if ( t9.getHeight() != 0 ) {
2303                 return false;
2304             }
2305             final char[] a10 = new char[] { 'a', ':', '6' };
2306             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2307             if ( t10.getHeight() != 6 ) {
2308                 return false;
2309             }
2310         }
2311         catch ( final Exception e ) {
2312             e.printStackTrace( System.out );
2313             return false;
2314         }
2315         return true;
2316     }
2317
2318     private static boolean testTreeMethods() {
2319         try {
2320             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2321             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
2322             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
2323             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
2324                 System.out.println( t0.toNewHampshireX() );
2325                 return false;
2326             }
2327             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
2328             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
2329             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
2330                 return false;
2331             }
2332             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
2333                 return false;
2334             }
2335             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
2336                 return false;
2337             }
2338         }
2339         catch ( final Exception e ) {
2340             e.printStackTrace( System.out );
2341             return false;
2342         }
2343         return true;
2344     }
2345
2346     private static boolean testConfidenceAssessor() {
2347         try {
2348             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2349             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2350             final Phylogeny[] ev0 = factory
2351                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2352                              new NHXParser() );
2353             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2354             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2355                 return false;
2356             }
2357             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2358                 return false;
2359             }
2360             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2361             final Phylogeny[] ev1 = factory
2362                     .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)));",
2363                              new NHXParser() );
2364             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2365             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2366                 return false;
2367             }
2368             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2369                 return false;
2370             }
2371             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2372             final Phylogeny[] ev_b = factory
2373                     .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",
2374                              new NHXParser() );
2375             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2376             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2377                 return false;
2378             }
2379             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2380                 return false;
2381             }
2382             //
2383             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2384             final Phylogeny[] ev1x = factory
2385                     .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)));",
2386                              new NHXParser() );
2387             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2388             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2389                 return false;
2390             }
2391             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2392                 return false;
2393             }
2394             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2395             final Phylogeny[] ev_bx = factory
2396                     .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",
2397                              new NHXParser() );
2398             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2399             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2400                 return false;
2401             }
2402             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2403                 return false;
2404             }
2405             //
2406             final Phylogeny[] t2 = factory
2407                     .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);",
2408                              new NHXParser() );
2409             final Phylogeny[] ev2 = factory
2410                     .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);",
2411                              new NHXParser() );
2412             for( final Phylogeny target : t2 ) {
2413                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2414             }
2415             //
2416             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2417                                                  new NHXParser() )[ 0 ];
2418             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2419             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2420             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2421                 return false;
2422             }
2423             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2424                 return false;
2425             }
2426             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2427                 return false;
2428             }
2429         }
2430         catch ( final Exception e ) {
2431             e.printStackTrace();
2432             return false;
2433         }
2434         return true;
2435     }
2436
2437     private static boolean testCopyOfNodeData() {
2438         try {
2439             final PhylogenyNode n1 = PhylogenyNode
2440                     .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]" );
2441             final PhylogenyNode n2 = n1.copyNodeData();
2442             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2443                 return false;
2444             }
2445         }
2446         catch ( final Exception e ) {
2447             e.printStackTrace();
2448             return false;
2449         }
2450         return true;
2451     }
2452
2453     private static boolean testDataObjects() {
2454         try {
2455             final Confidence s0 = new Confidence();
2456             final Confidence s1 = new Confidence();
2457             if ( !s0.isEqual( s1 ) ) {
2458                 return false;
2459             }
2460             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2461             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2462             if ( s2.isEqual( s1 ) ) {
2463                 return false;
2464             }
2465             if ( !s2.isEqual( s3 ) ) {
2466                 return false;
2467             }
2468             final Confidence s4 = ( Confidence ) s3.copy();
2469             if ( !s4.isEqual( s3 ) ) {
2470                 return false;
2471             }
2472             s3.asSimpleText();
2473             s3.asText();
2474             // Taxonomy
2475             // ----------
2476             final Taxonomy t1 = new Taxonomy();
2477             final Taxonomy t2 = new Taxonomy();
2478             final Taxonomy t3 = new Taxonomy();
2479             final Taxonomy t4 = new Taxonomy();
2480             final Taxonomy t5 = new Taxonomy();
2481             t1.setIdentifier( new Identifier( "ecoli" ) );
2482             t1.setTaxonomyCode( "ECOLI" );
2483             t1.setScientificName( "E. coli" );
2484             t1.setCommonName( "coli" );
2485             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2486             if ( !t1.isEqual( t0 ) ) {
2487                 return false;
2488             }
2489             t2.setIdentifier( new Identifier( "ecoli" ) );
2490             t2.setTaxonomyCode( "OTHER" );
2491             t2.setScientificName( "what" );
2492             t2.setCommonName( "something" );
2493             if ( !t1.isEqual( t2 ) ) {
2494                 return false;
2495             }
2496             t2.setIdentifier( new Identifier( "nemve" ) );
2497             if ( t1.isEqual( t2 ) ) {
2498                 return false;
2499             }
2500             t1.setIdentifier( null );
2501             t3.setTaxonomyCode( "ECOLI" );
2502             t3.setScientificName( "what" );
2503             t3.setCommonName( "something" );
2504             if ( !t1.isEqual( t3 ) ) {
2505                 return false;
2506             }
2507             t1.setIdentifier( null );
2508             t1.setTaxonomyCode( "" );
2509             t4.setScientificName( "E. ColI" );
2510             t4.setCommonName( "something" );
2511             if ( !t1.isEqual( t4 ) ) {
2512                 return false;
2513             }
2514             t4.setScientificName( "B. subtilis" );
2515             t4.setCommonName( "something" );
2516             if ( t1.isEqual( t4 ) ) {
2517                 return false;
2518             }
2519             t1.setIdentifier( null );
2520             t1.setTaxonomyCode( "" );
2521             t1.setScientificName( "" );
2522             t5.setCommonName( "COLI" );
2523             if ( !t1.isEqual( t5 ) ) {
2524                 return false;
2525             }
2526             t5.setCommonName( "vibrio" );
2527             if ( t1.isEqual( t5 ) ) {
2528                 return false;
2529             }
2530             // Identifier
2531             // ----------
2532             final Identifier id0 = new Identifier( "123", "pfam" );
2533             final Identifier id1 = ( Identifier ) id0.copy();
2534             if ( !id1.isEqual( id1 ) ) {
2535                 return false;
2536             }
2537             if ( !id1.isEqual( id0 ) ) {
2538                 return false;
2539             }
2540             if ( !id0.isEqual( id1 ) ) {
2541                 return false;
2542             }
2543             id1.asSimpleText();
2544             id1.asText();
2545             // ProteinDomain
2546             // ---------------
2547             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2548             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2549             if ( !pd1.isEqual( pd1 ) ) {
2550                 return false;
2551             }
2552             if ( !pd1.isEqual( pd0 ) ) {
2553                 return false;
2554             }
2555             pd1.asSimpleText();
2556             pd1.asText();
2557             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2558             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2559             if ( !pd3.isEqual( pd3 ) ) {
2560                 return false;
2561             }
2562             if ( !pd2.isEqual( pd3 ) ) {
2563                 return false;
2564             }
2565             if ( !pd0.isEqual( pd3 ) ) {
2566                 return false;
2567             }
2568             pd3.asSimpleText();
2569             pd3.asText();
2570             // DomainArchitecture
2571             // ------------------
2572             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2573             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2574             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2575             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2576             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2577             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2578             domains0.add( d2 );
2579             domains0.add( d0 );
2580             domains0.add( d3 );
2581             domains0.add( d1 );
2582             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2583             if ( ds0.getNumberOfDomains() != 4 ) {
2584                 return false;
2585             }
2586             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2587             if ( !ds0.isEqual( ds0 ) ) {
2588                 return false;
2589             }
2590             if ( !ds0.isEqual( ds1 ) ) {
2591                 return false;
2592             }
2593             if ( ds1.getNumberOfDomains() != 4 ) {
2594                 return false;
2595             }
2596             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2597             domains1.add( d1 );
2598             domains1.add( d2 );
2599             domains1.add( d4 );
2600             domains1.add( d0 );
2601             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2602             if ( ds0.isEqual( ds2 ) ) {
2603                 return false;
2604             }
2605             ds1.asSimpleText();
2606             ds1.asText();
2607             ds1.toNHX();
2608             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2609             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2610                 System.out.println( ds3.toNHX() );
2611                 return false;
2612             }
2613             if ( ds3.getNumberOfDomains() != 3 ) {
2614                 return false;
2615             }
2616             // Event
2617             // -----
2618             final Event e1 = new Event( Event.EventType.fusion );
2619             if ( e1.isDuplication() ) {
2620                 return false;
2621             }
2622             if ( !e1.isFusion() ) {
2623                 return false;
2624             }
2625             if ( !e1.asText().toString().equals( "fusion" ) ) {
2626                 return false;
2627             }
2628             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2629                 return false;
2630             }
2631             final Event e11 = new Event( Event.EventType.fusion );
2632             if ( !e11.isEqual( e1 ) ) {
2633                 return false;
2634             }
2635             if ( !e11.toNHX().toString().equals( "" ) ) {
2636                 return false;
2637             }
2638             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2639             if ( e2.isDuplication() ) {
2640                 return false;
2641             }
2642             if ( !e2.isSpeciationOrDuplication() ) {
2643                 return false;
2644             }
2645             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2646                 return false;
2647             }
2648             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2649                 return false;
2650             }
2651             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2652                 return false;
2653             }
2654             if ( e11.isEqual( e2 ) ) {
2655                 return false;
2656             }
2657             final Event e2c = ( Event ) e2.copy();
2658             if ( !e2c.isEqual( e2 ) ) {
2659                 return false;
2660             }
2661             Event e3 = new Event( 1, 2, 3 );
2662             if ( e3.isDuplication() ) {
2663                 return false;
2664             }
2665             if ( e3.isSpeciation() ) {
2666                 return false;
2667             }
2668             if ( e3.isGeneLoss() ) {
2669                 return false;
2670             }
2671             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2672                 return false;
2673             }
2674             final Event e3c = ( Event ) e3.copy();
2675             final Event e3cc = ( Event ) e3c.copy();
2676             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2677                 return false;
2678             }
2679             e3 = null;
2680             if ( !e3c.isEqual( e3cc ) ) {
2681                 return false;
2682             }
2683             Event e4 = new Event( 1, 2, 3 );
2684             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2685                 return false;
2686             }
2687             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2688                 return false;
2689             }
2690             final Event e4c = ( Event ) e4.copy();
2691             e4 = null;
2692             final Event e4cc = ( Event ) e4c.copy();
2693             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2694                 return false;
2695             }
2696             if ( !e4c.isEqual( e4cc ) ) {
2697                 return false;
2698             }
2699             final Event e5 = new Event();
2700             if ( !e5.isUnassigned() ) {
2701                 return false;
2702             }
2703             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2704                 return false;
2705             }
2706             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2707                 return false;
2708             }
2709             final Event e6 = new Event( 1, 0, 0 );
2710             if ( !e6.asText().toString().equals( "duplication" ) ) {
2711                 return false;
2712             }
2713             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2714                 return false;
2715             }
2716             final Event e7 = new Event( 0, 1, 0 );
2717             if ( !e7.asText().toString().equals( "speciation" ) ) {
2718                 return false;
2719             }
2720             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2721                 return false;
2722             }
2723             final Event e8 = new Event( 0, 0, 1 );
2724             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2725                 return false;
2726             }
2727             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2728                 return false;
2729             }
2730         }
2731         catch ( final Exception e ) {
2732             e.printStackTrace( System.out );
2733             return false;
2734         }
2735         return true;
2736     }
2737
2738     private static boolean testDeletionOfExternalNodes() {
2739         try {
2740             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2741             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2742             final PhylogenyWriter w = new PhylogenyWriter();
2743             if ( t0.isEmpty() ) {
2744                 return false;
2745             }
2746             if ( t0.getNumberOfExternalNodes() != 1 ) {
2747                 return false;
2748             }
2749             t0.deleteSubtree( t0.getNode( "A" ), false );
2750             if ( t0.getNumberOfExternalNodes() != 0 ) {
2751                 return false;
2752             }
2753             if ( !t0.isEmpty() ) {
2754                 return false;
2755             }
2756             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2757             if ( t1.getNumberOfExternalNodes() != 2 ) {
2758                 return false;
2759             }
2760             t1.deleteSubtree( t1.getNode( "A" ), false );
2761             if ( t1.getNumberOfExternalNodes() != 1 ) {
2762                 return false;
2763             }
2764             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2765                 return false;
2766             }
2767             t1.deleteSubtree( t1.getNode( "B" ), false );
2768             if ( t1.getNumberOfExternalNodes() != 1 ) {
2769                 return false;
2770             }
2771             t1.deleteSubtree( t1.getNode( "r" ), false );
2772             if ( !t1.isEmpty() ) {
2773                 return false;
2774             }
2775             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2776             if ( t2.getNumberOfExternalNodes() != 3 ) {
2777                 return false;
2778             }
2779             t2.deleteSubtree( t2.getNode( "B" ), false );
2780             if ( t2.getNumberOfExternalNodes() != 2 ) {
2781                 return false;
2782             }
2783             t2.toNewHampshireX();
2784             PhylogenyNode n = t2.getNode( "A" );
2785             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2786                 return false;
2787             }
2788             t2.deleteSubtree( t2.getNode( "A" ), false );
2789             if ( t2.getNumberOfExternalNodes() != 2 ) {
2790                 return false;
2791             }
2792             t2.deleteSubtree( t2.getNode( "C" ), true );
2793             if ( t2.getNumberOfExternalNodes() != 1 ) {
2794                 return false;
2795             }
2796             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2797             if ( t3.getNumberOfExternalNodes() != 4 ) {
2798                 return false;
2799             }
2800             t3.deleteSubtree( t3.getNode( "B" ), true );
2801             if ( t3.getNumberOfExternalNodes() != 3 ) {
2802                 return false;
2803             }
2804             n = t3.getNode( "A" );
2805             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2806                 return false;
2807             }
2808             n = n.getNextExternalNode();
2809             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2810                 return false;
2811             }
2812             t3.deleteSubtree( t3.getNode( "A" ), true );
2813             if ( t3.getNumberOfExternalNodes() != 2 ) {
2814                 return false;
2815             }
2816             n = t3.getNode( "C" );
2817             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2818                 return false;
2819             }
2820             t3.deleteSubtree( t3.getNode( "C" ), true );
2821             if ( t3.getNumberOfExternalNodes() != 1 ) {
2822                 return false;
2823             }
2824             t3.deleteSubtree( t3.getNode( "D" ), true );
2825             if ( t3.getNumberOfExternalNodes() != 0 ) {
2826                 return false;
2827             }
2828             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2829             if ( t4.getNumberOfExternalNodes() != 6 ) {
2830                 return false;
2831             }
2832             t4.deleteSubtree( t4.getNode( "B2" ), true );
2833             if ( t4.getNumberOfExternalNodes() != 5 ) {
2834                 return false;
2835             }
2836             String s = w.toNewHampshire( t4, false, true ).toString();
2837             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2838                 return false;
2839             }
2840             t4.deleteSubtree( t4.getNode( "B11" ), true );
2841             if ( t4.getNumberOfExternalNodes() != 4 ) {
2842                 return false;
2843             }
2844             t4.deleteSubtree( t4.getNode( "C" ), true );
2845             if ( t4.getNumberOfExternalNodes() != 3 ) {
2846                 return false;
2847             }
2848             n = t4.getNode( "A" );
2849             n = n.getNextExternalNode();
2850             if ( !n.getName().equals( "B12" ) ) {
2851                 return false;
2852             }
2853             n = n.getNextExternalNode();
2854             if ( !n.getName().equals( "D" ) ) {
2855                 return false;
2856             }
2857             s = w.toNewHampshire( t4, false, true ).toString();
2858             if ( !s.equals( "((A,B12),D);" ) ) {
2859                 return false;
2860             }
2861             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2862             t5.deleteSubtree( t5.getNode( "A" ), true );
2863             if ( t5.getNumberOfExternalNodes() != 5 ) {
2864                 return false;
2865             }
2866             s = w.toNewHampshire( t5, false, true ).toString();
2867             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2868                 return false;
2869             }
2870             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2871             t6.deleteSubtree( t6.getNode( "B11" ), true );
2872             if ( t6.getNumberOfExternalNodes() != 5 ) {
2873                 return false;
2874             }
2875             s = w.toNewHampshire( t6, false, false ).toString();
2876             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2877                 return false;
2878             }
2879             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2880             t7.deleteSubtree( t7.getNode( "B12" ), true );
2881             if ( t7.getNumberOfExternalNodes() != 5 ) {
2882                 return false;
2883             }
2884             s = w.toNewHampshire( t7, false, true ).toString();
2885             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2886                 return false;
2887             }
2888             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2889             t8.deleteSubtree( t8.getNode( "B2" ), true );
2890             if ( t8.getNumberOfExternalNodes() != 5 ) {
2891                 return false;
2892             }
2893             s = w.toNewHampshire( t8, false, false ).toString();
2894             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2895                 return false;
2896             }
2897             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2898             t9.deleteSubtree( t9.getNode( "C" ), true );
2899             if ( t9.getNumberOfExternalNodes() != 5 ) {
2900                 return false;
2901             }
2902             s = w.toNewHampshire( t9, false, true ).toString();
2903             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2904                 return false;
2905             }
2906             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2907             t10.deleteSubtree( t10.getNode( "D" ), true );
2908             if ( t10.getNumberOfExternalNodes() != 5 ) {
2909                 return false;
2910             }
2911             s = w.toNewHampshire( t10, false, true ).toString();
2912             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2913                 return false;
2914             }
2915             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2916             t11.deleteSubtree( t11.getNode( "A" ), true );
2917             if ( t11.getNumberOfExternalNodes() != 2 ) {
2918                 return false;
2919             }
2920             s = w.toNewHampshire( t11, false, true ).toString();
2921             if ( !s.equals( "(B,C);" ) ) {
2922                 return false;
2923             }
2924             t11.deleteSubtree( t11.getNode( "C" ), true );
2925             if ( t11.getNumberOfExternalNodes() != 1 ) {
2926                 return false;
2927             }
2928             s = w.toNewHampshire( t11, false, false ).toString();
2929             if ( !s.equals( "B;" ) ) {
2930                 return false;
2931             }
2932             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2933             t12.deleteSubtree( t12.getNode( "B2" ), true );
2934             if ( t12.getNumberOfExternalNodes() != 8 ) {
2935                 return false;
2936             }
2937             s = w.toNewHampshire( t12, false, true ).toString();
2938             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2939                 return false;
2940             }
2941             t12.deleteSubtree( t12.getNode( "B3" ), true );
2942             if ( t12.getNumberOfExternalNodes() != 7 ) {
2943                 return false;
2944             }
2945             s = w.toNewHampshire( t12, false, true ).toString();
2946             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2947                 return false;
2948             }
2949             t12.deleteSubtree( t12.getNode( "C3" ), true );
2950             if ( t12.getNumberOfExternalNodes() != 6 ) {
2951                 return false;
2952             }
2953             s = w.toNewHampshire( t12, false, true ).toString();
2954             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2955                 return false;
2956             }
2957             t12.deleteSubtree( t12.getNode( "A1" ), true );
2958             if ( t12.getNumberOfExternalNodes() != 5 ) {
2959                 return false;
2960             }
2961             s = w.toNewHampshire( t12, false, true ).toString();
2962             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2963                 return false;
2964             }
2965             t12.deleteSubtree( t12.getNode( "B1" ), true );
2966             if ( t12.getNumberOfExternalNodes() != 4 ) {
2967                 return false;
2968             }
2969             s = w.toNewHampshire( t12, false, true ).toString();
2970             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2971                 return false;
2972             }
2973             t12.deleteSubtree( t12.getNode( "A3" ), true );
2974             if ( t12.getNumberOfExternalNodes() != 3 ) {
2975                 return false;
2976             }
2977             s = w.toNewHampshire( t12, false, true ).toString();
2978             if ( !s.equals( "(A2,(C1,C2));" ) ) {
2979                 return false;
2980             }
2981             t12.deleteSubtree( t12.getNode( "A2" ), true );
2982             if ( t12.getNumberOfExternalNodes() != 2 ) {
2983                 return false;
2984             }
2985             s = w.toNewHampshire( t12, false, true ).toString();
2986             if ( !s.equals( "(C1,C2);" ) ) {
2987                 return false;
2988             }
2989             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2990             t13.deleteSubtree( t13.getNode( "D" ), true );
2991             if ( t13.getNumberOfExternalNodes() != 4 ) {
2992                 return false;
2993             }
2994             s = w.toNewHampshire( t13, false, true ).toString();
2995             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2996                 return false;
2997             }
2998             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2999             t14.deleteSubtree( t14.getNode( "E" ), true );
3000             if ( t14.getNumberOfExternalNodes() != 5 ) {
3001                 return false;
3002             }
3003             s = w.toNewHampshire( t14, false, true ).toString();
3004             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3005                 return false;
3006             }
3007             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3008             t15.deleteSubtree( t15.getNode( "B2" ), true );
3009             if ( t15.getNumberOfExternalNodes() != 11 ) {
3010                 return false;
3011             }
3012             t15.deleteSubtree( t15.getNode( "B1" ), true );
3013             if ( t15.getNumberOfExternalNodes() != 10 ) {
3014                 return false;
3015             }
3016             t15.deleteSubtree( t15.getNode( "B3" ), true );
3017             if ( t15.getNumberOfExternalNodes() != 9 ) {
3018                 return false;
3019             }
3020             t15.deleteSubtree( t15.getNode( "B4" ), true );
3021             if ( t15.getNumberOfExternalNodes() != 8 ) {
3022                 return false;
3023             }
3024             t15.deleteSubtree( t15.getNode( "A1" ), true );
3025             if ( t15.getNumberOfExternalNodes() != 7 ) {
3026                 return false;
3027             }
3028             t15.deleteSubtree( t15.getNode( "C4" ), true );
3029             if ( t15.getNumberOfExternalNodes() != 6 ) {
3030                 return false;
3031             }
3032         }
3033         catch ( final Exception e ) {
3034             e.printStackTrace( System.out );
3035             return false;
3036         }
3037         return true;
3038     }
3039
3040     private static boolean testDescriptiveStatistics() {
3041         try {
3042             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3043             dss1.addValue( 82 );
3044             dss1.addValue( 78 );
3045             dss1.addValue( 70 );
3046             dss1.addValue( 58 );
3047             dss1.addValue( 42 );
3048             if ( dss1.getN() != 5 ) {
3049                 return false;
3050             }
3051             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3052                 return false;
3053             }
3054             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3055                 return false;
3056             }
3057             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3058                 return false;
3059             }
3060             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3061                 return false;
3062             }
3063             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3064                 return false;
3065             }
3066             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3067                 return false;
3068             }
3069             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3070                 return false;
3071             }
3072             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3073                 return false;
3074             }
3075             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3076                 return false;
3077             }
3078             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3079                 return false;
3080             }
3081             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3082                 return false;
3083             }
3084             dss1.addValue( 123 );
3085             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3086                 return false;
3087             }
3088             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3089                 return false;
3090             }
3091             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3092                 return false;
3093             }
3094             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3095             dss2.addValue( -1.85 );
3096             dss2.addValue( 57.5 );
3097             dss2.addValue( 92.78 );
3098             dss2.addValue( 57.78 );
3099             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3100                 return false;
3101             }
3102             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3103                 return false;
3104             }
3105             final double[] a = dss2.getDataAsDoubleArray();
3106             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3107                 return false;
3108             }
3109             dss2.addValue( -100 );
3110             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3111                 return false;
3112             }
3113             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3114                 return false;
3115             }
3116             final double[] ds = new double[ 14 ];
3117             ds[ 0 ] = 34;
3118             ds[ 1 ] = 23;
3119             ds[ 2 ] = 1;
3120             ds[ 3 ] = 32;
3121             ds[ 4 ] = 11;
3122             ds[ 5 ] = 2;
3123             ds[ 6 ] = 12;
3124             ds[ 7 ] = 33;
3125             ds[ 8 ] = 13;
3126             ds[ 9 ] = 22;
3127             ds[ 10 ] = 21;
3128             ds[ 11 ] = 35;
3129             ds[ 12 ] = 24;
3130             ds[ 13 ] = 31;
3131             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3132             if ( bins.length != 4 ) {
3133                 return false;
3134             }
3135             if ( bins[ 0 ] != 2 ) {
3136                 return false;
3137             }
3138             if ( bins[ 1 ] != 3 ) {
3139                 return false;
3140             }
3141             if ( bins[ 2 ] != 4 ) {
3142                 return false;
3143             }
3144             if ( bins[ 3 ] != 5 ) {
3145                 return false;
3146             }
3147             final double[] ds1 = new double[ 9 ];
3148             ds1[ 0 ] = 10.0;
3149             ds1[ 1 ] = 19.0;
3150             ds1[ 2 ] = 9.999;
3151             ds1[ 3 ] = 0.0;
3152             ds1[ 4 ] = 39.9;
3153             ds1[ 5 ] = 39.999;
3154             ds1[ 6 ] = 30.0;
3155             ds1[ 7 ] = 19.999;
3156             ds1[ 8 ] = 30.1;
3157             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3158             if ( bins1.length != 4 ) {
3159                 return false;
3160             }
3161             if ( bins1[ 0 ] != 2 ) {
3162                 return false;
3163             }
3164             if ( bins1[ 1 ] != 3 ) {
3165                 return false;
3166             }
3167             if ( bins1[ 2 ] != 0 ) {
3168                 return false;
3169             }
3170             if ( bins1[ 3 ] != 4 ) {
3171                 return false;
3172             }
3173             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3174             if ( bins1_1.length != 3 ) {
3175                 return false;
3176             }
3177             if ( bins1_1[ 0 ] != 3 ) {
3178                 return false;
3179             }
3180             if ( bins1_1[ 1 ] != 2 ) {
3181                 return false;
3182             }
3183             if ( bins1_1[ 2 ] != 4 ) {
3184                 return false;
3185             }
3186             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3187             if ( bins1_2.length != 3 ) {
3188                 return false;
3189             }
3190             if ( bins1_2[ 0 ] != 2 ) {
3191                 return false;
3192             }
3193             if ( bins1_2[ 1 ] != 2 ) {
3194                 return false;
3195             }
3196             if ( bins1_2[ 2 ] != 2 ) {
3197                 return false;
3198             }
3199             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3200             dss3.addValue( 1 );
3201             dss3.addValue( 1 );
3202             dss3.addValue( 1 );
3203             dss3.addValue( 2 );
3204             dss3.addValue( 3 );
3205             dss3.addValue( 4 );
3206             dss3.addValue( 5 );
3207             dss3.addValue( 5 );
3208             dss3.addValue( 5 );
3209             dss3.addValue( 6 );
3210             dss3.addValue( 7 );
3211             dss3.addValue( 8 );
3212             dss3.addValue( 9 );
3213             dss3.addValue( 10 );
3214             dss3.addValue( 10 );
3215             dss3.addValue( 10 );
3216             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3217             histo.toStringBuffer( 10, '=', 40, 5 );
3218             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3219         }
3220         catch ( final Exception e ) {
3221             e.printStackTrace( System.out );
3222             return false;
3223         }
3224         return true;
3225     }
3226
3227     private static boolean testDir( final String file ) {
3228         try {
3229             final File f = new File( file );
3230             if ( !f.exists() ) {
3231                 return false;
3232             }
3233             if ( !f.isDirectory() ) {
3234                 return false;
3235             }
3236             if ( !f.canRead() ) {
3237                 return false;
3238             }
3239         }
3240         catch ( final Exception e ) {
3241             return false;
3242         }
3243         return true;
3244     }
3245
3246     private static boolean testExternalNodeRelatedMethods() {
3247         try {
3248             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3249             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3250             PhylogenyNode n = t1.getNode( "A" );
3251             n = n.getNextExternalNode();
3252             if ( !n.getName().equals( "B" ) ) {
3253                 return false;
3254             }
3255             n = n.getNextExternalNode();
3256             if ( !n.getName().equals( "C" ) ) {
3257                 return false;
3258             }
3259             n = n.getNextExternalNode();
3260             if ( !n.getName().equals( "D" ) ) {
3261                 return false;
3262             }
3263             n = t1.getNode( "B" );
3264             while ( !n.isLastExternalNode() ) {
3265                 n = n.getNextExternalNode();
3266             }
3267             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3268             n = t2.getNode( "A" );
3269             n = n.getNextExternalNode();
3270             if ( !n.getName().equals( "B" ) ) {
3271                 return false;
3272             }
3273             n = n.getNextExternalNode();
3274             if ( !n.getName().equals( "C" ) ) {
3275                 return false;
3276             }
3277             n = n.getNextExternalNode();
3278             if ( !n.getName().equals( "D" ) ) {
3279                 return false;
3280             }
3281             n = t2.getNode( "B" );
3282             while ( !n.isLastExternalNode() ) {
3283                 n = n.getNextExternalNode();
3284             }
3285             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3286             n = t3.getNode( "A" );
3287             n = n.getNextExternalNode();
3288             if ( !n.getName().equals( "B" ) ) {
3289                 return false;
3290             }
3291             n = n.getNextExternalNode();
3292             if ( !n.getName().equals( "C" ) ) {
3293                 return false;
3294             }
3295             n = n.getNextExternalNode();
3296             if ( !n.getName().equals( "D" ) ) {
3297                 return false;
3298             }
3299             n = n.getNextExternalNode();
3300             if ( !n.getName().equals( "E" ) ) {
3301                 return false;
3302             }
3303             n = n.getNextExternalNode();
3304             if ( !n.getName().equals( "F" ) ) {
3305                 return false;
3306             }
3307             n = n.getNextExternalNode();
3308             if ( !n.getName().equals( "G" ) ) {
3309                 return false;
3310             }
3311             n = n.getNextExternalNode();
3312             if ( !n.getName().equals( "H" ) ) {
3313                 return false;
3314             }
3315             n = t3.getNode( "B" );
3316             while ( !n.isLastExternalNode() ) {
3317                 n = n.getNextExternalNode();
3318             }
3319             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3320             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3321                 final PhylogenyNode node = iter.next();
3322             }
3323             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3324             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3325                 final PhylogenyNode node = iter.next();
3326             }
3327             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3328             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3329             if ( !iter.next().getName().equals( "A" ) ) {
3330                 return false;
3331             }
3332             if ( !iter.next().getName().equals( "B" ) ) {
3333                 return false;
3334             }
3335             if ( !iter.next().getName().equals( "C" ) ) {
3336                 return false;
3337             }
3338             if ( !iter.next().getName().equals( "D" ) ) {
3339                 return false;
3340             }
3341             if ( !iter.next().getName().equals( "E" ) ) {
3342                 return false;
3343             }
3344             if ( !iter.next().getName().equals( "F" ) ) {
3345                 return false;
3346             }
3347             if ( iter.hasNext() ) {
3348                 return false;
3349             }
3350         }
3351         catch ( final Exception e ) {
3352             e.printStackTrace( System.out );
3353             return false;
3354         }
3355         return true;
3356     }
3357
3358     private static boolean testGeneralTable() {
3359         try {
3360             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3361             t0.setValue( 3, 2, "23" );
3362             t0.setValue( 10, 1, "error" );
3363             t0.setValue( 10, 1, "110" );
3364             t0.setValue( 9, 1, "19" );
3365             t0.setValue( 1, 10, "101" );
3366             t0.setValue( 10, 10, "1010" );
3367             t0.setValue( 100, 10, "10100" );
3368             t0.setValue( 0, 0, "00" );
3369             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3370                 return false;
3371             }
3372             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3373                 return false;
3374             }
3375             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3376                 return false;
3377             }
3378             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3379                 return false;
3380             }
3381             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3382                 return false;
3383             }
3384             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3385                 return false;
3386             }
3387             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3388                 return false;
3389             }
3390             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3391                 return false;
3392             }
3393             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3394                 return false;
3395             }
3396             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3397             t1.setValue( "3", "2", "23" );
3398             t1.setValue( "10", "1", "error" );
3399             t1.setValue( "10", "1", "110" );
3400             t1.setValue( "9", "1", "19" );
3401             t1.setValue( "1", "10", "101" );
3402             t1.setValue( "10", "10", "1010" );
3403             t1.setValue( "100", "10", "10100" );
3404             t1.setValue( "0", "0", "00" );
3405             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3406             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3407                 return false;
3408             }
3409             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3410                 return false;
3411             }
3412             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3413                 return false;
3414             }
3415             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3416                 return false;
3417             }
3418             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3419                 return false;
3420             }
3421             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3422                 return false;
3423             }
3424             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3425                 return false;
3426             }
3427             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3428                 return false;
3429             }
3430             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3431                 return false;
3432             }
3433             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3434                 return false;
3435             }
3436         }
3437         catch ( final Exception e ) {
3438             e.printStackTrace( System.out );
3439             return false;
3440         }
3441         return true;
3442     }
3443
3444     private static boolean testGetDistance() {
3445         try {
3446             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3447             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",
3448                                                  new NHXParser() )[ 0 ];
3449             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3450                 return false;
3451             }
3452             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3453                 return false;
3454             }
3455             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3456                 return false;
3457             }
3458             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3459                 return false;
3460             }
3461             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3462                 return false;
3463             }
3464             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3465                 return false;
3466             }
3467             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3468                 return false;
3469             }
3470             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3471                 return false;
3472             }
3473             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3474                 return false;
3475             }
3476             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3477                 return false;
3478             }
3479             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3480                 return false;
3481             }
3482             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3483                 return false;
3484             }
3485             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3486                 return false;
3487             }
3488             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3489                 return false;
3490             }
3491             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3492                 return false;
3493             }
3494             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3495                 return false;
3496             }
3497             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3498                 return false;
3499             }
3500             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3501                 return false;
3502             }
3503             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3504                 return false;
3505             }
3506             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3507                 return false;
3508             }
3509             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3510                 return false;
3511             }
3512             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3513                 return false;
3514             }
3515             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3516                 return false;
3517             }
3518             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3519                 return false;
3520             }
3521             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3522                 return false;
3523             }
3524             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3525                 return false;
3526             }
3527             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3528                 return false;
3529             }
3530             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3531                 return false;
3532             }
3533             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3534                 return false;
3535             }
3536             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3537                 return false;
3538             }
3539             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3540                 return false;
3541             }
3542             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",
3543                                                  new NHXParser() )[ 0 ];
3544             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3545                 return false;
3546             }
3547             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3548                 return false;
3549             }
3550             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3551                 return false;
3552             }
3553             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3554                 return false;
3555             }
3556             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3557                 return false;
3558             }
3559             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3560                 return false;
3561             }
3562             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3563                 return false;
3564             }
3565             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3566                 return false;
3567             }
3568             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3569                 return false;
3570             }
3571             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3572                 return false;
3573             }
3574             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3575                 return false;
3576             }
3577         }
3578         catch ( final Exception e ) {
3579             e.printStackTrace( System.out );
3580             return false;
3581         }
3582         return true;
3583     }
3584
3585     private static boolean testGetLCA() {
3586         try {
3587             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3588             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3589                                                  new NHXParser() )[ 0 ];
3590             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3591             if ( !A.getName().equals( "A" ) ) {
3592                 return false;
3593             }
3594             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3595             if ( !gh.getName().equals( "gh" ) ) {
3596                 return false;
3597             }
3598             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3599             if ( !ab.getName().equals( "ab" ) ) {
3600                 return false;
3601             }
3602             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3603             if ( !ab2.getName().equals( "ab" ) ) {
3604                 return false;
3605             }
3606             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3607             if ( !gh2.getName().equals( "gh" ) ) {
3608                 return false;
3609             }
3610             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3611             if ( !gh3.getName().equals( "gh" ) ) {
3612                 return false;
3613             }
3614             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3615             if ( !abc.getName().equals( "abc" ) ) {
3616                 return false;
3617             }
3618             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3619             if ( !abc2.getName().equals( "abc" ) ) {
3620                 return false;
3621             }
3622             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3623             if ( !abcd.getName().equals( "abcd" ) ) {
3624                 return false;
3625             }
3626             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3627             if ( !abcd2.getName().equals( "abcd" ) ) {
3628                 return false;
3629             }
3630             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3631             if ( !abcdef.getName().equals( "abcdef" ) ) {
3632                 return false;
3633             }
3634             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3635             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3636                 return false;
3637             }
3638             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3639             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3640                 return false;
3641             }
3642             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3643             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3644                 return false;
3645             }
3646             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3647             if ( !abcde.getName().equals( "abcde" ) ) {
3648                 return false;
3649             }
3650             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3651             if ( !abcde2.getName().equals( "abcde" ) ) {
3652                 return false;
3653             }
3654             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3655             if ( !r.getName().equals( "abcdefgh" ) ) {
3656                 return false;
3657             }
3658             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3659             if ( !r2.getName().equals( "abcdefgh" ) ) {
3660                 return false;
3661             }
3662             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3663             if ( !r3.getName().equals( "abcdefgh" ) ) {
3664                 return false;
3665             }
3666             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3667             if ( !abcde3.getName().equals( "abcde" ) ) {
3668                 return false;
3669             }
3670             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3671             if ( !abcde4.getName().equals( "abcde" ) ) {
3672                 return false;
3673             }
3674             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3675             if ( !ab3.getName().equals( "ab" ) ) {
3676                 return false;
3677             }
3678             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3679             if ( !ab4.getName().equals( "ab" ) ) {
3680                 return false;
3681             }
3682             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3683             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3684             if ( !cd.getName().equals( "cd" ) ) {
3685                 return false;
3686             }
3687             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3688             if ( !cd2.getName().equals( "cd" ) ) {
3689                 return false;
3690             }
3691             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3692             if ( !cde.getName().equals( "cde" ) ) {
3693                 return false;
3694             }
3695             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3696             if ( !cde2.getName().equals( "cde" ) ) {
3697                 return false;
3698             }
3699             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3700             if ( !cdef.getName().equals( "cdef" ) ) {
3701                 return false;
3702             }
3703             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3704             if ( !cdef2.getName().equals( "cdef" ) ) {
3705                 return false;
3706             }
3707             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3708             if ( !cdef3.getName().equals( "cdef" ) ) {
3709                 return false;
3710             }
3711             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3712             if ( !rt.getName().equals( "r" ) ) {
3713                 return false;
3714             }
3715             final Phylogeny p3 = factory
3716                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3717                              new NHXParser() )[ 0 ];
3718             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3719             if ( !bc_3.getName().equals( "bc" ) ) {
3720                 return false;
3721             }
3722             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3723             if ( !ac_3.getName().equals( "abc" ) ) {
3724                 return false;
3725             }
3726             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3727             if ( !ad_3.getName().equals( "abcde" ) ) {
3728                 return false;
3729             }
3730             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3731             if ( !af_3.getName().equals( "abcdef" ) ) {
3732                 return false;
3733             }
3734             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3735             if ( !ag_3.getName().equals( "" ) ) {
3736                 return false;
3737             }
3738             if ( !ag_3.isRoot() ) {
3739                 return false;
3740             }
3741             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3742             if ( !al_3.getName().equals( "" ) ) {
3743                 return false;
3744             }
3745             if ( !al_3.isRoot() ) {
3746                 return false;
3747             }
3748             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3749             if ( !kl_3.getName().equals( "" ) ) {
3750                 return false;
3751             }
3752             if ( !kl_3.isRoot() ) {
3753                 return false;
3754             }
3755             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3756             if ( !fl_3.getName().equals( "" ) ) {
3757                 return false;
3758             }
3759             if ( !fl_3.isRoot() ) {
3760                 return false;
3761             }
3762             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3763             if ( !gk_3.getName().equals( "ghijk" ) ) {
3764                 return false;
3765             }
3766             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3767             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3768             if ( !r_4.getName().equals( "r" ) ) {
3769                 return false;
3770             }
3771             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3772             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3773             if ( !r_5.getName().equals( "root" ) ) {
3774                 return false;
3775             }
3776             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3777             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3778             if ( !r_6.getName().equals( "rot" ) ) {
3779                 return false;
3780             }
3781             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3782             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3783             if ( !r_7.getName().equals( "rott" ) ) {
3784                 return false;
3785             }
3786         }
3787         catch ( final Exception e ) {
3788             e.printStackTrace( System.out );
3789             return false;
3790         }
3791         return true;
3792     }
3793
3794     private static boolean testGetLCA2() {
3795         try {
3796             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3797             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3798             PhylogenyMethods.preOrderReId( p_a );
3799             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3800                                                                                               p_a.getNode( "a" ) );
3801             if ( !p_a_1.getName().equals( "a" ) ) {
3802                 return false;
3803             }
3804             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3805             PhylogenyMethods.preOrderReId( p_b );
3806             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3807                                                                                               p_b.getNode( "a" ) );
3808             if ( !p_b_1.getName().equals( "b" ) ) {
3809                 return false;
3810             }
3811             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3812                                                                                               p_b.getNode( "b" ) );
3813             if ( !p_b_2.getName().equals( "b" ) ) {
3814                 return false;
3815             }
3816             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3817             PhylogenyMethods.preOrderReId( p_c );
3818             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3819                                                                                               p_c.getNode( "a" ) );
3820             if ( !p_c_1.getName().equals( "b" ) ) {
3821                 return false;
3822             }
3823             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3824                                                                                               p_c.getNode( "c" ) );
3825             if ( !p_c_2.getName().equals( "c" ) ) {
3826                 System.out.println( p_c_2.getName() );
3827                 System.exit( -1 );
3828                 return false;
3829             }
3830             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3831                                                                                               p_c.getNode( "b" ) );
3832             if ( !p_c_3.getName().equals( "b" ) ) {
3833                 return false;
3834             }
3835             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3836                                                                                               p_c.getNode( "a" ) );
3837             if ( !p_c_4.getName().equals( "c" ) ) {
3838                 return false;
3839             }
3840             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3841                                                  new NHXParser() )[ 0 ];
3842             PhylogenyMethods.preOrderReId( p1 );
3843             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3844                                                                                           p1.getNode( "A" ) );
3845             if ( !A.getName().equals( "A" ) ) {
3846                 return false;
3847             }
3848             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3849                                                                                            p1.getNode( "gh" ) );
3850             if ( !gh.getName().equals( "gh" ) ) {
3851                 return false;
3852             }
3853             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3854                                                                                            p1.getNode( "B" ) );
3855             if ( !ab.getName().equals( "ab" ) ) {
3856                 return false;
3857             }
3858             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3859                                                                                             p1.getNode( "A" ) );
3860             if ( !ab2.getName().equals( "ab" ) ) {
3861                 return false;
3862             }
3863             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3864                                                                                             p1.getNode( "G" ) );
3865             if ( !gh2.getName().equals( "gh" ) ) {
3866                 return false;
3867             }
3868             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3869                                                                                             p1.getNode( "H" ) );
3870             if ( !gh3.getName().equals( "gh" ) ) {
3871                 return false;
3872             }
3873             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3874                                                                                             p1.getNode( "A" ) );
3875             if ( !abc.getName().equals( "abc" ) ) {
3876                 return false;
3877             }
3878             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3879                                                                                              p1.getNode( "C" ) );
3880             if ( !abc2.getName().equals( "abc" ) ) {
3881                 return false;
3882             }
3883             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3884                                                                                              p1.getNode( "D" ) );
3885             if ( !abcd.getName().equals( "abcd" ) ) {
3886                 return false;
3887             }
3888             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3889                                                                                               p1.getNode( "A" ) );
3890             if ( !abcd2.getName().equals( "abcd" ) ) {
3891                 return false;
3892             }
3893             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3894                                                                                                p1.getNode( "F" ) );
3895             if ( !abcdef.getName().equals( "abcdef" ) ) {
3896                 return false;
3897             }
3898             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3899                                                                                                 p1.getNode( "A" ) );
3900             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3901                 return false;
3902             }
3903             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3904                                                                                                 p1.getNode( "F" ) );
3905             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3906                 return false;
3907             }
3908             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3909                                                                                                 p1.getNode( "ab" ) );
3910             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3911                 return false;
3912             }
3913             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3914                                                                                               p1.getNode( "E" ) );
3915             if ( !abcde.getName().equals( "abcde" ) ) {
3916                 return false;
3917             }
3918             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3919                                                                                                p1.getNode( "A" ) );
3920             if ( !abcde2.getName().equals( "abcde" ) ) {
3921                 return false;
3922             }
3923             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3924                                                                                           p1.getNode( "abcdefgh" ) );
3925             if ( !r.getName().equals( "abcdefgh" ) ) {
3926                 return false;
3927             }
3928             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3929                                                                                            p1.getNode( "H" ) );
3930             if ( !r2.getName().equals( "abcdefgh" ) ) {
3931                 return false;
3932             }
3933             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3934                                                                                            p1.getNode( "A" ) );
3935             if ( !r3.getName().equals( "abcdefgh" ) ) {
3936                 return false;
3937             }
3938             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3939                                                                                                p1.getNode( "abcde" ) );
3940             if ( !abcde3.getName().equals( "abcde" ) ) {
3941                 return false;
3942             }
3943             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3944                                                                                                p1.getNode( "E" ) );
3945             if ( !abcde4.getName().equals( "abcde" ) ) {
3946                 return false;
3947             }
3948             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3949                                                                                             p1.getNode( "B" ) );
3950             if ( !ab3.getName().equals( "ab" ) ) {
3951                 return false;
3952             }
3953             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3954                                                                                             p1.getNode( "ab" ) );
3955             if ( !ab4.getName().equals( "ab" ) ) {
3956                 return false;
3957             }
3958             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3959             PhylogenyMethods.preOrderReId( p2 );
3960             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3961                                                                                            p2.getNode( "d" ) );
3962             if ( !cd.getName().equals( "cd" ) ) {
3963                 return false;
3964             }
3965             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3966                                                                                             p2.getNode( "c" ) );
3967             if ( !cd2.getName().equals( "cd" ) ) {
3968                 return false;
3969             }
3970             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3971                                                                                             p2.getNode( "e" ) );
3972             if ( !cde.getName().equals( "cde" ) ) {
3973                 return false;
3974             }
3975             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3976                                                                                              p2.getNode( "c" ) );
3977             if ( !cde2.getName().equals( "cde" ) ) {
3978                 return false;
3979             }
3980             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3981                                                                                              p2.getNode( "f" ) );
3982             if ( !cdef.getName().equals( "cdef" ) ) {
3983                 return false;
3984             }
3985             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3986                                                                                               p2.getNode( "f" ) );
3987             if ( !cdef2.getName().equals( "cdef" ) ) {
3988                 return false;
3989             }
3990             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3991                                                                                               p2.getNode( "d" ) );
3992             if ( !cdef3.getName().equals( "cdef" ) ) {
3993                 return false;
3994             }
3995             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3996                                                                                            p2.getNode( "a" ) );
3997             if ( !rt.getName().equals( "r" ) ) {
3998                 return false;
3999             }
4000             final Phylogeny p3 = factory
4001                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4002                              new NHXParser() )[ 0 ];
4003             PhylogenyMethods.preOrderReId( p3 );
4004             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
4005                                                                                              p3.getNode( "c" ) );
4006             if ( !bc_3.getName().equals( "bc" ) ) {
4007                 return false;
4008             }
4009             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4010                                                                                              p3.getNode( "c" ) );
4011             if ( !ac_3.getName().equals( "abc" ) ) {
4012                 return false;
4013             }
4014             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4015                                                                                              p3.getNode( "d" ) );
4016             if ( !ad_3.getName().equals( "abcde" ) ) {
4017                 return false;
4018             }
4019             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4020                                                                                              p3.getNode( "f" ) );
4021             if ( !af_3.getName().equals( "abcdef" ) ) {
4022                 return false;
4023             }
4024             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4025                                                                                              p3.getNode( "g" ) );
4026             if ( !ag_3.getName().equals( "" ) ) {
4027                 return false;
4028             }
4029             if ( !ag_3.isRoot() ) {
4030                 return false;
4031             }
4032             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4033                                                                                              p3.getNode( "l" ) );
4034             if ( !al_3.getName().equals( "" ) ) {
4035                 return false;
4036             }
4037             if ( !al_3.isRoot() ) {
4038                 return false;
4039             }
4040             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
4041                                                                                              p3.getNode( "l" ) );
4042             if ( !kl_3.getName().equals( "" ) ) {
4043                 return false;
4044             }
4045             if ( !kl_3.isRoot() ) {
4046                 return false;
4047             }
4048             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
4049                                                                                              p3.getNode( "l" ) );
4050             if ( !fl_3.getName().equals( "" ) ) {
4051                 return false;
4052             }
4053             if ( !fl_3.isRoot() ) {
4054                 return false;
4055             }
4056             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
4057                                                                                              p3.getNode( "k" ) );
4058             if ( !gk_3.getName().equals( "ghijk" ) ) {
4059                 return false;
4060             }
4061             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4062             PhylogenyMethods.preOrderReId( p4 );
4063             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
4064                                                                                             p4.getNode( "c" ) );
4065             if ( !r_4.getName().equals( "r" ) ) {
4066                 return false;
4067             }
4068             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4069             PhylogenyMethods.preOrderReId( p5 );
4070             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
4071                                                                                             p5.getNode( "c" ) );
4072             if ( !r_5.getName().equals( "root" ) ) {
4073                 return false;
4074             }
4075             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4076             PhylogenyMethods.preOrderReId( p6 );
4077             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
4078                                                                                             p6.getNode( "a" ) );
4079             if ( !r_6.getName().equals( "rot" ) ) {
4080                 return false;
4081             }
4082             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4083             PhylogenyMethods.preOrderReId( p7 );
4084             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4085                                                                                             p7.getNode( "e" ) );
4086             if ( !r_7.getName().equals( "rott" ) ) {
4087                 return false;
4088             }
4089             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4090                                                                                              p7.getNode( "a" ) );
4091             if ( !r_71.getName().equals( "rott" ) ) {
4092                 return false;
4093             }
4094             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4095                                                                                              p7.getNode( "rott" ) );
4096             if ( !r_72.getName().equals( "rott" ) ) {
4097                 return false;
4098             }
4099             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4100                                                                                              p7.getNode( "a" ) );
4101             if ( !r_73.getName().equals( "rott" ) ) {
4102                 return false;
4103             }
4104             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4105                                                                                              p7.getNode( "rott" ) );
4106             if ( !r_74.getName().equals( "rott" ) ) {
4107                 return false;
4108             }
4109             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4110                                                                                              p7.getNode( "e" ) );
4111             if ( !r_75.getName().equals( "e" ) ) {
4112                 return false;
4113             }
4114         }
4115         catch ( final Exception e ) {
4116             e.printStackTrace( System.out );
4117             return false;
4118         }
4119         return true;
4120     }
4121
4122     private static boolean testHmmscanOutputParser() {
4123         final String test_dir = Test.PATH_TO_TEST_DATA;
4124         try {
4125             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4126                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4127             parser1.parse();
4128             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4129                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4130             final List<Protein> proteins = parser2.parse();
4131             if ( parser2.getProteinsEncountered() != 4 ) {
4132                 return false;
4133             }
4134             if ( proteins.size() != 4 ) {
4135                 return false;
4136             }
4137             if ( parser2.getDomainsEncountered() != 69 ) {
4138                 return false;
4139             }
4140             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4141                 return false;
4142             }
4143             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4144                 return false;
4145             }
4146             final Protein p1 = proteins.get( 0 );
4147             if ( p1.getNumberOfProteinDomains() != 15 ) {
4148                 return false;
4149             }
4150             if ( p1.getLength() != 850 ) {
4151                 return false;
4152             }
4153             final Protein p2 = proteins.get( 1 );
4154             if ( p2.getNumberOfProteinDomains() != 51 ) {
4155                 return false;
4156             }
4157             if ( p2.getLength() != 1291 ) {
4158                 return false;
4159             }
4160             final Protein p3 = proteins.get( 2 );
4161             if ( p3.getNumberOfProteinDomains() != 2 ) {
4162                 return false;
4163             }
4164             final Protein p4 = proteins.get( 3 );
4165             if ( p4.getNumberOfProteinDomains() != 1 ) {
4166                 return false;
4167             }
4168             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4169                 return false;
4170             }
4171             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4172                 return false;
4173             }
4174             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4175                 return false;
4176             }
4177             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4178                 return false;
4179             }
4180             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4181                 return false;
4182             }
4183             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4184                 return false;
4185             }
4186             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4187                 return false;
4188             }
4189             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4190                 return false;
4191             }
4192             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4193                 return false;
4194             }
4195         }
4196         catch ( final Exception e ) {
4197             e.printStackTrace( System.out );
4198             return false;
4199         }
4200         return true;
4201     }
4202
4203     private static boolean testLastExternalNodeMethods() {
4204         try {
4205             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4206             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4207             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4208             final PhylogenyNode n1 = t0.getNode( "A" );
4209             if ( n1.isLastExternalNode() ) {
4210                 return false;
4211             }
4212             final PhylogenyNode n2 = t0.getNode( "B" );
4213             if ( n2.isLastExternalNode() ) {
4214                 return false;
4215             }
4216             final PhylogenyNode n3 = t0.getNode( "C" );
4217             if ( n3.isLastExternalNode() ) {
4218                 return false;
4219             }
4220             final PhylogenyNode n4 = t0.getNode( "D" );
4221             if ( !n4.isLastExternalNode() ) {
4222                 return false;
4223             }
4224         }
4225         catch ( final Exception e ) {
4226             e.printStackTrace( System.out );
4227             return false;
4228         }
4229         return true;
4230     }
4231
4232     private static boolean testLevelOrderIterator() {
4233         try {
4234             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4235             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4236             PhylogenyNodeIterator it0;
4237             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4238                 it0.next();
4239             }
4240             for( it0.reset(); it0.hasNext(); ) {
4241                 it0.next();
4242             }
4243             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4244             if ( !it.next().getName().equals( "r" ) ) {
4245                 return false;
4246             }
4247             if ( !it.next().getName().equals( "ab" ) ) {
4248                 return false;
4249             }
4250             if ( !it.next().getName().equals( "cd" ) ) {
4251                 return false;
4252             }
4253             if ( !it.next().getName().equals( "A" ) ) {
4254                 return false;
4255             }
4256             if ( !it.next().getName().equals( "B" ) ) {
4257                 return false;
4258             }
4259             if ( !it.next().getName().equals( "C" ) ) {
4260                 return false;
4261             }
4262             if ( !it.next().getName().equals( "D" ) ) {
4263                 return false;
4264             }
4265             if ( it.hasNext() ) {
4266                 return false;
4267             }
4268             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",
4269                                                  new NHXParser() )[ 0 ];
4270             PhylogenyNodeIterator it2;
4271             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4272                 it2.next();
4273             }
4274             for( it2.reset(); it2.hasNext(); ) {
4275                 it2.next();
4276             }
4277             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4278             if ( !it3.next().getName().equals( "r" ) ) {
4279                 return false;
4280             }
4281             if ( !it3.next().getName().equals( "abc" ) ) {
4282                 return false;
4283             }
4284             if ( !it3.next().getName().equals( "defg" ) ) {
4285                 return false;
4286             }
4287             if ( !it3.next().getName().equals( "A" ) ) {
4288                 return false;
4289             }
4290             if ( !it3.next().getName().equals( "B" ) ) {
4291                 return false;
4292             }
4293             if ( !it3.next().getName().equals( "C" ) ) {
4294                 return false;
4295             }
4296             if ( !it3.next().getName().equals( "D" ) ) {
4297                 return false;
4298             }
4299             if ( !it3.next().getName().equals( "E" ) ) {
4300                 return false;
4301             }
4302             if ( !it3.next().getName().equals( "F" ) ) {
4303                 return false;
4304             }
4305             if ( !it3.next().getName().equals( "G" ) ) {
4306                 return false;
4307             }
4308             if ( !it3.next().getName().equals( "1" ) ) {
4309                 return false;
4310             }
4311             if ( !it3.next().getName().equals( "2" ) ) {
4312                 return false;
4313             }
4314             if ( !it3.next().getName().equals( "3" ) ) {
4315                 return false;
4316             }
4317             if ( !it3.next().getName().equals( "4" ) ) {
4318                 return false;
4319             }
4320             if ( !it3.next().getName().equals( "5" ) ) {
4321                 return false;
4322             }
4323             if ( !it3.next().getName().equals( "6" ) ) {
4324                 return false;
4325             }
4326             if ( !it3.next().getName().equals( "f1" ) ) {
4327                 return false;
4328             }
4329             if ( !it3.next().getName().equals( "f2" ) ) {
4330                 return false;
4331             }
4332             if ( !it3.next().getName().equals( "f3" ) ) {
4333                 return false;
4334             }
4335             if ( !it3.next().getName().equals( "a" ) ) {
4336                 return false;
4337             }
4338             if ( !it3.next().getName().equals( "b" ) ) {
4339                 return false;
4340             }
4341             if ( !it3.next().getName().equals( "f21" ) ) {
4342                 return false;
4343             }
4344             if ( !it3.next().getName().equals( "X" ) ) {
4345                 return false;
4346             }
4347             if ( !it3.next().getName().equals( "Y" ) ) {
4348                 return false;
4349             }
4350             if ( !it3.next().getName().equals( "Z" ) ) {
4351                 return false;
4352             }
4353             if ( it3.hasNext() ) {
4354                 return false;
4355             }
4356             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4357             PhylogenyNodeIterator it4;
4358             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4359                 it4.next();
4360             }
4361             for( it4.reset(); it4.hasNext(); ) {
4362                 it4.next();
4363             }
4364             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4365             if ( !it5.next().getName().equals( "r" ) ) {
4366                 return false;
4367             }
4368             if ( !it5.next().getName().equals( "A" ) ) {
4369                 return false;
4370             }
4371             if ( !it5.next().getName().equals( "B" ) ) {
4372                 return false;
4373             }
4374             if ( !it5.next().getName().equals( "C" ) ) {
4375                 return false;
4376             }
4377             if ( !it5.next().getName().equals( "D" ) ) {
4378                 return false;
4379             }
4380             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4381             PhylogenyNodeIterator it6;
4382             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4383                 it6.next();
4384             }
4385             for( it6.reset(); it6.hasNext(); ) {
4386                 it6.next();
4387             }
4388             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4389             if ( !it7.next().getName().equals( "A" ) ) {
4390                 return false;
4391             }
4392             if ( it.hasNext() ) {
4393                 return false;
4394             }
4395         }
4396         catch ( final Exception e ) {
4397             e.printStackTrace( System.out );
4398             return false;
4399         }
4400         return true;
4401     }
4402
4403     private static boolean testNodeRemoval() {
4404         try {
4405             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4406             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4407             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
4408             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
4409                 return false;
4410             }
4411             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
4412             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
4413             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
4414                 return false;
4415             }
4416             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
4417             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
4418             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
4419                 return false;
4420             }
4421         }
4422         catch ( final Exception e ) {
4423             e.printStackTrace( System.out );
4424             return false;
4425         }
4426         return true;
4427     }
4428
4429     private static boolean testMidpointrooting() {
4430         try {
4431             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4432             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4433             PhylogenyMethods.midpointRoot( t0 );
4434             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4435                 return false;
4436             }
4437             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4438                 return false;
4439             }
4440             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4441                            1 ) ) {
4442                 return false;
4443             }
4444             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",
4445                                                  new NHXParser() )[ 0 ];
4446             if ( !t1.isRooted() ) {
4447                 return false;
4448             }
4449             PhylogenyMethods.midpointRoot( t1 );
4450             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4451                 return false;
4452             }
4453             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4454                 return false;
4455             }
4456             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4457                 return false;
4458             }
4459             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4460                 return false;
4461             }
4462             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4463                 return false;
4464             }
4465             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4466                 return false;
4467             }
4468             t1.reRoot( t1.getNode( "A" ) );
4469             PhylogenyMethods.midpointRoot( t1 );
4470             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4471                 return false;
4472             }
4473             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4474                 return false;
4475             }
4476             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4477                 return false;
4478             }
4479             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4480                 return false;
4481             }
4482             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4483                 System.exit( -1 );
4484                 return false;
4485             }
4486             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4487                 return false;
4488             }
4489         }
4490         catch ( final Exception e ) {
4491             e.printStackTrace( System.out );
4492             return false;
4493         }
4494         return true;
4495     }
4496
4497     private static boolean testNexusCharactersParsing() {
4498         try {
4499             final NexusCharactersParser parser = new NexusCharactersParser();
4500             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4501             parser.parse();
4502             String[] labels = parser.getCharStateLabels();
4503             if ( labels.length != 7 ) {
4504                 return false;
4505             }
4506             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4507                 return false;
4508             }
4509             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4510                 return false;
4511             }
4512             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4513                 return false;
4514             }
4515             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4516                 return false;
4517             }
4518             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4519                 return false;
4520             }
4521             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4522                 return false;
4523             }
4524             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4525                 return false;
4526             }
4527             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4528             parser.parse();
4529             labels = parser.getCharStateLabels();
4530             if ( labels.length != 7 ) {
4531                 return false;
4532             }
4533             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4534                 return false;
4535             }
4536             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4537                 return false;
4538             }
4539             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4540                 return false;
4541             }
4542             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4543                 return false;
4544             }
4545             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4546                 return false;
4547             }
4548             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4549                 return false;
4550             }
4551             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4552                 return false;
4553             }
4554         }
4555         catch ( final Exception e ) {
4556             e.printStackTrace( System.out );
4557             return false;
4558         }
4559         return true;
4560     }
4561
4562     private static boolean testNexusMatrixParsing() {
4563         try {
4564             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4565             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4566             parser.parse();
4567             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4568             if ( m.getNumberOfCharacters() != 9 ) {
4569                 return false;
4570             }
4571             if ( m.getNumberOfIdentifiers() != 5 ) {
4572                 return false;
4573             }
4574             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4575                 return false;
4576             }
4577             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4578                 return false;
4579             }
4580             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4581                 return false;
4582             }
4583             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4584                 return false;
4585             }
4586             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4587                 return false;
4588             }
4589             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4590                 return false;
4591             }
4592             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4593                 return false;
4594             }
4595             //            if ( labels.length != 7 ) {
4596             //                return false;
4597             //            }
4598             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4599             //                return false;
4600             //            }
4601             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4602             //                return false;
4603             //            }
4604             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4605             //                return false;
4606             //            }
4607             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4608             //                return false;
4609             //            }
4610             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4611             //                return false;
4612             //            }
4613             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4614             //                return false;
4615             //            }
4616             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4617             //                return false;
4618             //            }
4619             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4620             //            parser.parse();
4621             //            labels = parser.getCharStateLabels();
4622             //            if ( labels.length != 7 ) {
4623             //                return false;
4624             //            }
4625             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4626             //                return false;
4627             //            }
4628             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4629             //                return false;
4630             //            }
4631             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4632             //                return false;
4633             //            }
4634             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4635             //                return false;
4636             //            }
4637             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4638             //                return false;
4639             //            }
4640             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4641             //                return false;
4642             //            }
4643             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4644             //                return false;
4645             //            }
4646         }
4647         catch ( final Exception e ) {
4648             e.printStackTrace( System.out );
4649             return false;
4650         }
4651         return true;
4652     }
4653
4654     private static boolean testNexusTreeParsing() {
4655         try {
4656             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4657             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4658             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4659             if ( phylogenies.length != 1 ) {
4660                 return false;
4661             }
4662             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4663                 return false;
4664             }
4665             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4666                 return false;
4667             }
4668             phylogenies = null;
4669             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4670             if ( phylogenies.length != 1 ) {
4671                 return false;
4672             }
4673             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4674                 return false;
4675             }
4676             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4677                 return false;
4678             }
4679             phylogenies = null;
4680             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4681             if ( phylogenies.length != 1 ) {
4682                 return false;
4683             }
4684             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4685                 return false;
4686             }
4687             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4688                 return false;
4689             }
4690             if ( phylogenies[ 0 ].isRooted() ) {
4691                 return false;
4692             }
4693             phylogenies = null;
4694             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4695             if ( phylogenies.length != 18 ) {
4696                 return false;
4697             }
4698             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4699                 return false;
4700             }
4701             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4702                 return false;
4703             }
4704             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4705                 return false;
4706             }
4707             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4708                 return false;
4709             }
4710             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4711                 return false;
4712             }
4713             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4714                 return false;
4715             }
4716             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4717                 return false;
4718             }
4719             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4720                 return false;
4721             }
4722             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4723                 return false;
4724             }
4725             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4726                 return false;
4727             }
4728             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4729                 return false;
4730             }
4731             if ( phylogenies[ 8 ].isRooted() ) {
4732                 return false;
4733             }
4734             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4735                 return false;
4736             }
4737             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4738                 return false;
4739             }
4740             if ( !phylogenies[ 9 ].isRooted() ) {
4741                 return false;
4742             }
4743             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4744                 return false;
4745             }
4746             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4747                 return false;
4748             }
4749             if ( !phylogenies[ 10 ].isRooted() ) {
4750                 return false;
4751             }
4752             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4753                 return false;
4754             }
4755             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4756                 return false;
4757             }
4758             if ( phylogenies[ 11 ].isRooted() ) {
4759                 return false;
4760             }
4761             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4762                 return false;
4763             }
4764             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4765                 return false;
4766             }
4767             if ( !phylogenies[ 12 ].isRooted() ) {
4768                 return false;
4769             }
4770             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4771                 return false;
4772             }
4773             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4774                 return false;
4775             }
4776             if ( !phylogenies[ 13 ].isRooted() ) {
4777                 return false;
4778             }
4779             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4780                 return false;
4781             }
4782             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4783                 return false;
4784             }
4785             if ( !phylogenies[ 14 ].isRooted() ) {
4786                 return false;
4787             }
4788             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4789                 return false;
4790             }
4791             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4792                 return false;
4793             }
4794             if ( phylogenies[ 15 ].isRooted() ) {
4795                 return false;
4796             }
4797             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4798                 return false;
4799             }
4800             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4801                 return false;
4802             }
4803             if ( !phylogenies[ 16 ].isRooted() ) {
4804                 return false;
4805             }
4806             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4807                 return false;
4808             }
4809             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4810                 return false;
4811             }
4812             if ( phylogenies[ 17 ].isRooted() ) {
4813                 return false;
4814             }
4815             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4816                 return false;
4817             }
4818         }
4819         catch ( final Exception e ) {
4820             e.printStackTrace( System.out );
4821             return false;
4822         }
4823         return true;
4824     }
4825
4826     private static boolean testNexusTreeParsingIterating() {
4827         try {
4828             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
4829             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
4830             if ( !p.hasNext() ) {
4831                 return false;
4832             }
4833             Phylogeny phy = p.next();
4834             if ( phy == null ) {
4835                 return false;
4836             }
4837             if ( phy.getNumberOfExternalNodes() != 25 ) {
4838                 return false;
4839             }
4840             if ( !phy.getName().equals( "" ) ) {
4841                 return false;
4842             }
4843             if ( p.hasNext() ) {
4844                 return false;
4845             }
4846             phy = p.next();
4847             if ( phy != null ) {
4848                 return false;
4849             }
4850             //
4851             p.reset();
4852             if ( !p.hasNext() ) {
4853                 return false;
4854             }
4855             phy = p.next();
4856             if ( phy == null ) {
4857                 return false;
4858             }
4859             if ( phy.getNumberOfExternalNodes() != 25 ) {
4860                 return false;
4861             }
4862             if ( !phy.getName().equals( "" ) ) {
4863                 return false;
4864             }
4865             if ( p.hasNext() ) {
4866                 return false;
4867             }
4868             phy = p.next();
4869             if ( phy != null ) {
4870                 return false;
4871             }
4872             ////
4873             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
4874             if ( !p.hasNext() ) {
4875                 return false;
4876             }
4877             phy = p.next();
4878             if ( phy == null ) {
4879                 return false;
4880             }
4881             if ( phy.getNumberOfExternalNodes() != 10 ) {
4882                 return false;
4883             }
4884             if ( !phy.getName().equals( "name" ) ) {
4885                 return false;
4886             }
4887             if ( p.hasNext() ) {
4888                 return false;
4889             }
4890             phy = p.next();
4891             if ( phy != null ) {
4892                 return false;
4893             }
4894             //
4895             p.reset();
4896             if ( !p.hasNext() ) {
4897                 return false;
4898             }
4899             phy = p.next();
4900             if ( phy == null ) {
4901                 return false;
4902             }
4903             if ( phy.getNumberOfExternalNodes() != 10 ) {
4904                 return false;
4905             }
4906             if ( !phy.getName().equals( "name" ) ) {
4907                 return false;
4908             }
4909             if ( p.hasNext() ) {
4910                 return false;
4911             }
4912             phy = p.next();
4913             if ( phy != null ) {
4914                 return false;
4915             }
4916             ////
4917             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
4918             if ( !p.hasNext() ) {
4919                 return false;
4920             }
4921             phy = p.next();
4922             if ( phy == null ) {
4923                 return false;
4924             }
4925             if ( phy.getNumberOfExternalNodes() != 3 ) {
4926                 return false;
4927             }
4928             if ( !phy.getName().equals( "" ) ) {
4929                 return false;
4930             }
4931             if ( phy.isRooted() ) {
4932                 return false;
4933             }
4934             if ( p.hasNext() ) {
4935                 return false;
4936             }
4937             phy = p.next();
4938             if ( phy != null ) {
4939                 return false;
4940             }
4941             //
4942             p.reset();
4943             if ( !p.hasNext() ) {
4944                 return false;
4945             }
4946             phy = p.next();
4947             if ( phy == null ) {
4948                 return false;
4949             }
4950             if ( phy.getNumberOfExternalNodes() != 3 ) {
4951                 return false;
4952             }
4953             if ( !phy.getName().equals( "" ) ) {
4954                 return false;
4955             }
4956             if ( p.hasNext() ) {
4957                 return false;
4958             }
4959             phy = p.next();
4960             if ( phy != null ) {
4961                 return false;
4962             }
4963             ////
4964             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
4965             //            if ( phylogenies.length != 18 ) {
4966             //                return false;
4967             //            }
4968             //0
4969             if ( !p.hasNext() ) {
4970                 return false;
4971             }
4972             phy = p.next();
4973             if ( phy == null ) {
4974                 return false;
4975             }
4976             if ( phy.getNumberOfExternalNodes() != 10 ) {
4977                 return false;
4978             }
4979             if ( !phy.getName().equals( "tree 0" ) ) {
4980                 return false;
4981             }
4982             //1
4983             if ( !p.hasNext() ) {
4984                 return false;
4985             }
4986             phy = p.next();
4987             if ( phy == null ) {
4988                 return false;
4989             }
4990             if ( phy.getNumberOfExternalNodes() != 10 ) {
4991                 return false;
4992             }
4993             if ( !phy.getName().equals( "tree 1" ) ) {
4994                 return false;
4995             }
4996             //2
4997             if ( !p.hasNext() ) {
4998                 return false;
4999             }
5000             phy = p.next();
5001             if ( phy == null ) {
5002                 return false;
5003             }
5004             if ( phy.getNumberOfExternalNodes() != 3 ) {
5005                 return false;
5006             }
5007             if ( !phy.getName().equals( "" ) ) {
5008                 return false;
5009             }
5010             if ( phy.isRooted() ) {
5011                 return false;
5012             }
5013             //3
5014             if ( !p.hasNext() ) {
5015                 return false;
5016             }
5017             phy = p.next();
5018             if ( phy == null ) {
5019                 return false;
5020             }
5021             if ( phy.getNumberOfExternalNodes() != 4 ) {
5022                 return false;
5023             }
5024             if ( !phy.getName().equals( "" ) ) {
5025                 return false;
5026             }
5027             if ( !phy.isRooted() ) {
5028                 return false;
5029             }
5030             //4
5031             if ( !p.hasNext() ) {
5032                 return false;
5033             }
5034             phy = p.next();
5035             if ( phy == null ) {
5036                 return false;
5037             }
5038             if ( phy.getNumberOfExternalNodes() != 5 ) {
5039                 System.out.println( phy.getNumberOfExternalNodes() );
5040                 return false;
5041             }
5042             if ( !phy.getName().equals( "" ) ) {
5043                 return false;
5044             }
5045             if ( !phy.isRooted() ) {
5046                 return false;
5047             }
5048             //5
5049             if ( !p.hasNext() ) {
5050                 return false;
5051             }
5052             phy = p.next();
5053             if ( phy == null ) {
5054                 return false;
5055             }
5056             if ( phy.getNumberOfExternalNodes() != 3 ) {
5057                 return false;
5058             }
5059             if ( !phy.getName().equals( "" ) ) {
5060                 return false;
5061             }
5062             if ( phy.isRooted() ) {
5063                 return false;
5064             }
5065             //6
5066             if ( !p.hasNext() ) {
5067                 return false;
5068             }
5069             phy = p.next();
5070             if ( phy == null ) {
5071                 return false;
5072             }
5073             if ( phy.getNumberOfExternalNodes() != 2 ) {
5074                 return false;
5075             }
5076             if ( !phy.getName().equals( "" ) ) {
5077                 return false;
5078             }
5079             if ( !phy.isRooted() ) {
5080                 return false;
5081             }
5082             //7
5083             if ( !p.hasNext() ) {
5084                 return false;
5085             }
5086             phy = p.next();
5087             if ( phy.getNumberOfExternalNodes() != 3 ) {
5088                 return false;
5089             }
5090             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5091                 return false;
5092             }
5093             if ( !phy.isRooted() ) {
5094                 return false;
5095             }
5096             //8
5097             if ( !p.hasNext() ) {
5098                 return false;
5099             }
5100             phy = p.next();
5101             if ( phy.getNumberOfExternalNodes() != 3 ) {
5102                 return false;
5103             }
5104             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
5105                 return false;
5106             }
5107             if ( !phy.getName().equals( "tree 8" ) ) {
5108                 return false;
5109             }
5110             //9
5111             if ( !p.hasNext() ) {
5112                 return false;
5113             }
5114             phy = p.next();
5115             if ( phy.getNumberOfExternalNodes() != 3 ) {
5116                 return false;
5117             }
5118             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
5119                 return false;
5120             }
5121             if ( !phy.getName().equals( "tree 9" ) ) {
5122                 return false;
5123             }
5124             //10
5125             if ( !p.hasNext() ) {
5126                 return false;
5127             }
5128             phy = p.next();
5129             if ( phy.getNumberOfExternalNodes() != 3 ) {
5130                 return false;
5131             }
5132             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5133                 return false;
5134             }
5135             if ( !phy.getName().equals( "tree 10" ) ) {
5136                 return false;
5137             }
5138             if ( !phy.isRooted() ) {
5139                 return false;
5140             }
5141             //11
5142             if ( !p.hasNext() ) {
5143                 return false;
5144             }
5145             phy = p.next();
5146             if ( phy.getNumberOfExternalNodes() != 3 ) {
5147                 return false;
5148             }
5149             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
5150                 return false;
5151             }
5152             if ( !phy.getName().equals( "tree 11" ) ) {
5153                 return false;
5154             }
5155             if ( phy.isRooted() ) {
5156                 return false;
5157             }
5158             //12
5159             if ( !p.hasNext() ) {
5160                 return false;
5161             }
5162             phy = p.next();
5163             if ( phy.getNumberOfExternalNodes() != 3 ) {
5164                 return false;
5165             }
5166             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
5167                 return false;
5168             }
5169             if ( !phy.getName().equals( "tree 12" ) ) {
5170                 return false;
5171             }
5172             if ( !phy.isRooted() ) {
5173                 return false;
5174             }
5175             //13
5176             if ( !p.hasNext() ) {
5177                 return false;
5178             }
5179             phy = p.next();
5180             if ( phy.getNumberOfExternalNodes() != 3 ) {
5181                 return false;
5182             }
5183             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5184                 return false;
5185             }
5186             if ( !phy.getName().equals( "tree 13" ) ) {
5187                 return false;
5188             }
5189             if ( !phy.isRooted() ) {
5190                 return false;
5191             }
5192             //14
5193             if ( !p.hasNext() ) {
5194                 return false;
5195             }
5196             phy = p.next();
5197             if ( phy.getNumberOfExternalNodes() != 10 ) {
5198                 System.out.println( phy.getNumberOfExternalNodes() );
5199                 return false;
5200             }
5201             if ( !phy
5202                     .toNewHampshire()
5203                     .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
5204                 System.out.println( phy.toNewHampshire() );
5205                 return false;
5206             }
5207             if ( !phy.getName().equals( "tree 14" ) ) {
5208                 return false;
5209             }
5210             if ( !phy.isRooted() ) {
5211                 return false;
5212             }
5213             //15
5214             if ( !p.hasNext() ) {
5215                 return false;
5216             }
5217             phy = p.next();
5218             if ( phy.getNumberOfExternalNodes() != 10 ) {
5219                 System.out.println( phy.getNumberOfExternalNodes() );
5220                 return false;
5221             }
5222             if ( !phy
5223                     .toNewHampshire()
5224                     .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
5225                 System.out.println( phy.toNewHampshire() );
5226                 return false;
5227             }
5228             if ( !phy.getName().equals( "tree 15" ) ) {
5229                 return false;
5230             }
5231             if ( phy.isRooted() ) {
5232                 return false;
5233             }
5234             //16
5235             if ( !p.hasNext() ) {
5236                 return false;
5237             }
5238             phy = p.next();
5239             if ( phy.getNumberOfExternalNodes() != 10 ) {
5240                 System.out.println( phy.getNumberOfExternalNodes() );
5241                 return false;
5242             }
5243             if ( !phy
5244                     .toNewHampshire()
5245                     .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
5246                 System.out.println( phy.toNewHampshire() );
5247                 return false;
5248             }
5249             if ( !phy.getName().equals( "tree 16" ) ) {
5250                 return false;
5251             }
5252             if ( !phy.isRooted() ) {
5253                 return false;
5254             }
5255             //17
5256             if ( !p.hasNext() ) {
5257                 return false;
5258             }
5259             phy = p.next();
5260             if ( phy.getNumberOfExternalNodes() != 10 ) {
5261                 System.out.println( phy.getNumberOfExternalNodes() );
5262                 return false;
5263             }
5264             if ( !phy
5265                     .toNewHampshire()
5266                     .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
5267                 System.out.println( phy.toNewHampshire() );
5268                 return false;
5269             }
5270             if ( !phy.getName().equals( "tree 17" ) ) {
5271                 return false;
5272             }
5273             if ( phy.isRooted() ) {
5274                 return false;
5275             }
5276             //
5277             if ( p.hasNext() ) {
5278                 return false;
5279             }
5280             phy = p.next();
5281             if ( phy != null ) {
5282                 return false;
5283             }
5284             p.reset();
5285             //0
5286             if ( !p.hasNext() ) {
5287                 return false;
5288             }
5289             phy = p.next();
5290             if ( phy == null ) {
5291                 return false;
5292             }
5293             if ( phy.getNumberOfExternalNodes() != 10 ) {
5294                 return false;
5295             }
5296             if ( !phy.getName().equals( "tree 0" ) ) {
5297                 return false;
5298             }
5299             //1
5300             if ( !p.hasNext() ) {
5301                 return false;
5302             }
5303             phy = p.next();
5304             if ( phy == null ) {
5305                 return false;
5306             }
5307             if ( phy.getNumberOfExternalNodes() != 10 ) {
5308                 return false;
5309             }
5310             if ( !phy.getName().equals( "tree 1" ) ) {
5311                 return false;
5312             }
5313             //2
5314             if ( !p.hasNext() ) {
5315                 return false;
5316             }
5317             phy = p.next();
5318             if ( phy == null ) {
5319                 return false;
5320             }
5321             if ( phy.getNumberOfExternalNodes() != 3 ) {
5322                 return false;
5323             }
5324             if ( !phy.getName().equals( "" ) ) {
5325                 return false;
5326             }
5327             if ( phy.isRooted() ) {
5328                 return false;
5329             }
5330             //3
5331             if ( !p.hasNext() ) {
5332                 return false;
5333             }
5334             phy = p.next();
5335             if ( phy == null ) {
5336                 return false;
5337             }
5338             if ( phy.getNumberOfExternalNodes() != 4 ) {
5339                 return false;
5340             }
5341             if ( !phy.getName().equals( "" ) ) {
5342                 return false;
5343             }
5344             if ( !phy.isRooted() ) {
5345                 return false;
5346             }
5347             //4
5348             if ( !p.hasNext() ) {
5349                 return false;
5350             }
5351             phy = p.next();
5352             if ( phy == null ) {
5353                 return false;
5354             }
5355             if ( phy.getNumberOfExternalNodes() != 5 ) {
5356                 System.out.println( phy.getNumberOfExternalNodes() );
5357                 return false;
5358             }
5359             if ( !phy.getName().equals( "" ) ) {
5360                 return false;
5361             }
5362             if ( !phy.isRooted() ) {
5363                 return false;
5364             }
5365             //5
5366             if ( !p.hasNext() ) {
5367                 return false;
5368             }
5369             phy = p.next();
5370             if ( phy == null ) {
5371                 return false;
5372             }
5373             if ( phy.getNumberOfExternalNodes() != 3 ) {
5374                 return false;
5375             }
5376             if ( !phy.getName().equals( "" ) ) {
5377                 return false;
5378             }
5379             if ( phy.isRooted() ) {
5380                 return false;
5381             }
5382         }
5383         catch ( final Exception e ) {
5384             e.printStackTrace( System.out );
5385             return false;
5386         }
5387         return true;
5388     }
5389
5390     private static boolean testNexusTreeParsingTranslating() {
5391         try {
5392             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5393             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5394             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
5395             if ( phylogenies.length != 1 ) {
5396                 return false;
5397             }
5398             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5399                 return false;
5400             }
5401             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5402                 return false;
5403             }
5404             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5405                 return false;
5406             }
5407             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5408                 return false;
5409             }
5410             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5411                     .equals( "Aranaeus" ) ) {
5412                 return false;
5413             }
5414             phylogenies = null;
5415             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
5416             if ( phylogenies.length != 3 ) {
5417                 return false;
5418             }
5419             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5420                 return false;
5421             }
5422             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5423                 return false;
5424             }
5425             if ( phylogenies[ 0 ].isRooted() ) {
5426                 return false;
5427             }
5428             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5429                 return false;
5430             }
5431             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5432                 return false;
5433             }
5434             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5435                     .equals( "Aranaeus" ) ) {
5436                 return false;
5437             }
5438             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5439                 return false;
5440             }
5441             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5442                 return false;
5443             }
5444             if ( phylogenies[ 1 ].isRooted() ) {
5445                 return false;
5446             }
5447             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5448                 return false;
5449             }
5450             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5451                 return false;
5452             }
5453             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5454                     .equals( "Aranaeus" ) ) {
5455                 return false;
5456             }
5457             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5458                 return false;
5459             }
5460             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5461                 return false;
5462             }
5463             if ( !phylogenies[ 2 ].isRooted() ) {
5464                 return false;
5465             }
5466             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5467                 return false;
5468             }
5469             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5470                 return false;
5471             }
5472             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5473                     .equals( "Aranaeus" ) ) {
5474                 return false;
5475             }
5476             phylogenies = null;
5477             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
5478             if ( phylogenies.length != 3 ) {
5479                 return false;
5480             }
5481             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5482                 return false;
5483             }
5484             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5485                 return false;
5486             }
5487             if ( phylogenies[ 0 ].isRooted() ) {
5488                 return false;
5489             }
5490             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5491                 return false;
5492             }
5493             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5494                 return false;
5495             }
5496             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5497                     .equals( "Aranaeus" ) ) {
5498                 return false;
5499             }
5500             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5501                 return false;
5502             }
5503             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5504                 return false;
5505             }
5506             if ( phylogenies[ 1 ].isRooted() ) {
5507                 return false;
5508             }
5509             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5510                 return false;
5511             }
5512             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5513                 return false;
5514             }
5515             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5516                     .equals( "Aranaeus" ) ) {
5517                 return false;
5518             }
5519             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5520                 return false;
5521             }
5522             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5523                 return false;
5524             }
5525             if ( !phylogenies[ 2 ].isRooted() ) {
5526                 return false;
5527             }
5528             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5529                 return false;
5530             }
5531             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5532                 return false;
5533             }
5534             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5535                     .equals( "Aranaeus" ) ) {
5536                 return false;
5537             }
5538         }
5539         catch ( final Exception e ) {
5540             e.printStackTrace( System.out );
5541             return false;
5542         }
5543         return true;
5544     }
5545
5546     private static boolean testNHParsing() {
5547         try {
5548             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5549             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
5550             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
5551                 return false;
5552             }
5553             final NHXParser nhxp = new NHXParser();
5554             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
5555             nhxp.setReplaceUnderscores( true );
5556             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
5557             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
5558                 return false;
5559             }
5560             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
5561                 return false;
5562             }
5563             final Phylogeny p1b = factory
5564                     .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 ",
5565                              new NHXParser() )[ 0 ];
5566             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
5567                 return false;
5568             }
5569             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
5570                 return false;
5571             }
5572             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
5573             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
5574             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
5575             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
5576             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
5577             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
5578             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
5579             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
5580             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
5581             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
5582             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
5583                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
5584                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
5585                                                     new NHXParser() );
5586             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
5587                 return false;
5588             }
5589             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
5590                 return false;
5591             }
5592             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
5593                 return false;
5594             }
5595             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
5596                 return false;
5597             }
5598             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
5599             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
5600             final String p16_S = "((A,B),C)";
5601             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
5602             if ( p16.length != 1 ) {
5603                 return false;
5604             }
5605             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
5606                 return false;
5607             }
5608             final String p17_S = "(C,(A,B))";
5609             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
5610             if ( p17.length != 1 ) {
5611                 return false;
5612             }
5613             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
5614                 return false;
5615             }
5616             final String p18_S = "((A,B),(C,D))";
5617             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
5618             if ( p18.length != 1 ) {
5619                 return false;
5620             }
5621             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
5622                 return false;
5623             }
5624             final String p19_S = "(((A,B),C),D)";
5625             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
5626             if ( p19.length != 1 ) {
5627                 return false;
5628             }
5629             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
5630                 return false;
5631             }
5632             final String p20_S = "(A,(B,(C,D)))";
5633             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
5634             if ( p20.length != 1 ) {
5635                 return false;
5636             }
5637             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
5638                 return false;
5639             }
5640             final String p21_S = "(A,(B,(C,(D,E))))";
5641             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
5642             if ( p21.length != 1 ) {
5643                 return false;
5644             }
5645             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
5646                 return false;
5647             }
5648             final String p22_S = "((((A,B),C),D),E)";
5649             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
5650             if ( p22.length != 1 ) {
5651                 return false;
5652             }
5653             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
5654                 return false;
5655             }
5656             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5657             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
5658             if ( p23.length != 1 ) {
5659                 System.out.println( "xl=" + p23.length );
5660                 System.exit( -1 );
5661                 return false;
5662             }
5663             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
5664                 return false;
5665             }
5666             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5667             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
5668             if ( p24.length != 1 ) {
5669                 return false;
5670             }
5671             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
5672                 return false;
5673             }
5674             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5675             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5676             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
5677             if ( p241.length != 2 ) {
5678                 return false;
5679             }
5680             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
5681                 return false;
5682             }
5683             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
5684                 return false;
5685             }
5686             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
5687                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
5688                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
5689                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
5690                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
5691                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
5692                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
5693                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
5694             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
5695             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
5696                 return false;
5697             }
5698             final String p26_S = "(A,B)ab";
5699             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
5700             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
5701                 return false;
5702             }
5703             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5704             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
5705             if ( p27s.length != 1 ) {
5706                 System.out.println( "xxl=" + p27s.length );
5707                 System.exit( -1 );
5708                 return false;
5709             }
5710             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5711                 System.out.println( p27s[ 0 ].toNewHampshireX() );
5712                 System.exit( -1 );
5713                 return false;
5714             }
5715             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
5716                                                     new NHXParser() );
5717             if ( p27.length != 1 ) {
5718                 System.out.println( "yl=" + p27.length );
5719                 System.exit( -1 );
5720                 return false;
5721             }
5722             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5723                 System.out.println( p27[ 0 ].toNewHampshireX() );
5724                 System.exit( -1 );
5725                 return false;
5726             }
5727             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5728             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5729             final String p28_S3 = "(A,B)ab";
5730             final String p28_S4 = "((((A,B),C),D),;E;)";
5731             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
5732                                                     new NHXParser() );
5733             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
5734                 return false;
5735             }
5736             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
5737                 return false;
5738             }
5739             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
5740                 return false;
5741             }
5742             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
5743                 return false;
5744             }
5745             if ( p28.length != 4 ) {
5746                 return false;
5747             }
5748             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";
5749             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
5750             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
5751                 return false;
5752             }
5753             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";
5754             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
5755             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
5756                 return false;
5757             }
5758             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
5759             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
5760             if ( ( p32.length != 0 ) ) {
5761                 return false;
5762             }
5763             final String p33_S = "A";
5764             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
5765             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
5766                 return false;
5767             }
5768             final String p34_S = "B;";
5769             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
5770             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
5771                 return false;
5772             }
5773             final String p35_S = "B:0.2";
5774             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
5775             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
5776                 return false;
5777             }
5778             final String p36_S = "(A)";
5779             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
5780             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
5781                 return false;
5782             }
5783             final String p37_S = "((A))";
5784             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
5785             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
5786                 return false;
5787             }
5788             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5789             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
5790             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
5791                 return false;
5792             }
5793             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5794             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
5795             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
5796                 return false;
5797             }
5798             final String p40_S = "(A,B,C)";
5799             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
5800             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
5801                 return false;
5802             }
5803             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
5804             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
5805             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
5806                 return false;
5807             }
5808             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
5809             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
5810             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
5811                 return false;
5812             }
5813             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)";
5814             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
5815             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
5816                 return false;
5817             }
5818             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)))";
5819             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
5820             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
5821                 return false;
5822             }
5823             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
5824             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
5825             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
5826                 return false;
5827             }
5828             final String p46_S = "";
5829             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
5830             if ( p46.length != 0 ) {
5831                 return false;
5832             }
5833             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
5834             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5835                 return false;
5836             }
5837             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5838             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5839                 return false;
5840             }
5841             final Phylogeny p49 = factory
5842                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
5843                              new NHXParser() )[ 0 ];
5844             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5845                 return false;
5846             }
5847             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5848             if ( p50.getNode( "A" ) == null ) {
5849                 return false;
5850             }
5851             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5852                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
5853                 return false;
5854             }
5855             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
5856                 return false;
5857             }
5858             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
5859                     .equals( "((A,B)88:2.0,C);" ) ) {
5860                 return false;
5861             }
5862             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5863             if ( p51.getNode( "A(A" ) == null ) {
5864                 return false;
5865             }
5866             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5867             if ( p52.getNode( "A(A" ) == null ) {
5868                 return false;
5869             }
5870             final Phylogeny p53 = factory
5871                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
5872                              new NHXParser() )[ 0 ];
5873             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
5874                 return false;
5875             }
5876             // 
5877             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
5878             if ( p54.getNode( "A" ) == null ) {
5879                 return false;
5880             }
5881             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5882                     .equals( "((A,B)[88],C);" ) ) {
5883                 return false;
5884             }
5885         }
5886         catch ( final Exception e ) {
5887             e.printStackTrace( System.out );
5888             return false;
5889         }
5890         return true;
5891     }
5892
5893     private static boolean testNHParsingIter() {
5894         try {
5895             final String p0_str = "(A,B);";
5896             final NHXParser p = new NHXParser();
5897             p.setSource( p0_str );
5898             if ( !p.hasNext() ) {
5899                 return false;
5900             }
5901             final Phylogeny p0 = p.next();
5902             if ( !p0.toNewHampshire().equals( p0_str ) ) {
5903                 System.out.println( p0.toNewHampshire() );
5904                 return false;
5905             }
5906             if ( p.hasNext() ) {
5907                 return false;
5908             }
5909             if ( p.next() != null ) {
5910                 return false;
5911             }
5912             //
5913             final String p00_str = "(A,B)root;";
5914             p.setSource( p00_str );
5915             final Phylogeny p00 = p.next();
5916             if ( !p00.toNewHampshire().equals( p00_str ) ) {
5917                 System.out.println( p00.toNewHampshire() );
5918                 return false;
5919             }
5920             //
5921             final String p000_str = "A;";
5922             p.setSource( p000_str );
5923             final Phylogeny p000 = p.next();
5924             if ( !p000.toNewHampshire().equals( p000_str ) ) {
5925                 System.out.println( p000.toNewHampshire() );
5926                 return false;
5927             }
5928             //
5929             final String p0000_str = "A";
5930             p.setSource( p0000_str );
5931             final Phylogeny p0000 = p.next();
5932             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
5933                 System.out.println( p0000.toNewHampshire() );
5934                 return false;
5935             }
5936             //
5937             p.setSource( "(A)" );
5938             final Phylogeny p00000 = p.next();
5939             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
5940                 System.out.println( p00000.toNewHampshire() );
5941                 return false;
5942             }
5943             //
5944             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
5945             p.setSource( p1_str );
5946             if ( !p.hasNext() ) {
5947                 return false;
5948             }
5949             final Phylogeny p1_0 = p.next();
5950             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
5951                 System.out.println( p1_0.toNewHampshire() );
5952                 return false;
5953             }
5954             if ( !p.hasNext() ) {
5955                 return false;
5956             }
5957             final Phylogeny p1_1 = p.next();
5958             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
5959                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
5960                 return false;
5961             }
5962             if ( !p.hasNext() ) {
5963                 return false;
5964             }
5965             final Phylogeny p1_2 = p.next();
5966             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
5967                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
5968                 return false;
5969             }
5970             if ( !p.hasNext() ) {
5971                 return false;
5972             }
5973             final Phylogeny p1_3 = p.next();
5974             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
5975                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
5976                 return false;
5977             }
5978             if ( p.hasNext() ) {
5979                 return false;
5980             }
5981             if ( p.next() != null ) {
5982                 return false;
5983             }
5984             //
5985             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
5986             p.setSource( p2_str );
5987             if ( !p.hasNext() ) {
5988                 return false;
5989             }
5990             Phylogeny p2_0 = p.next();
5991             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5992                 System.out.println( p2_0.toNewHampshire() );
5993                 return false;
5994             }
5995             if ( !p.hasNext() ) {
5996                 return false;
5997             }
5998             Phylogeny p2_1 = p.next();
5999             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
6000                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
6001                 return false;
6002             }
6003             if ( !p.hasNext() ) {
6004                 return false;
6005             }
6006             Phylogeny p2_2 = p.next();
6007             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
6008                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
6009                 return false;
6010             }
6011             if ( !p.hasNext() ) {
6012                 return false;
6013             }
6014             Phylogeny p2_3 = p.next();
6015             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
6016                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
6017                 return false;
6018             }
6019             if ( !p.hasNext() ) {
6020                 return false;
6021             }
6022             Phylogeny p2_4 = p.next();
6023             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
6024                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
6025                 return false;
6026             }
6027             if ( p.hasNext() ) {
6028                 return false;
6029             }
6030             if ( p.next() != null ) {
6031                 return false;
6032             }
6033             ////
6034             p.reset();
6035             if ( !p.hasNext() ) {
6036                 return false;
6037             }
6038             p2_0 = p.next();
6039             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
6040                 System.out.println( p2_0.toNewHampshire() );
6041                 return false;
6042             }
6043             if ( !p.hasNext() ) {
6044                 return false;
6045             }
6046             p2_1 = p.next();
6047             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
6048                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
6049                 return false;
6050             }
6051             if ( !p.hasNext() ) {
6052                 return false;
6053             }
6054             p2_2 = p.next();
6055             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
6056                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
6057                 return false;
6058             }
6059             if ( !p.hasNext() ) {
6060                 return false;
6061             }
6062             p2_3 = p.next();
6063             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
6064                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
6065                 return false;
6066             }
6067             if ( !p.hasNext() ) {
6068                 return false;
6069             }
6070             p2_4 = p.next();
6071             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
6072                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
6073                 return false;
6074             }
6075             if ( p.hasNext() ) {
6076                 return false;
6077             }
6078             if ( p.next() != null ) {
6079                 return false;
6080             }
6081             //
6082             final String p3_str = "((A,B),C)abc";
6083             p.setSource( p3_str );
6084             if ( !p.hasNext() ) {
6085                 return false;
6086             }
6087             final Phylogeny p3_0 = p.next();
6088             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
6089                 return false;
6090             }
6091             if ( p.hasNext() ) {
6092                 return false;
6093             }
6094             if ( p.next() != null ) {
6095                 return false;
6096             }
6097             //
6098             final String p4_str = "((A,B)ab,C)abc";
6099             p.setSource( p4_str );
6100             if ( !p.hasNext() ) {
6101                 return false;
6102             }
6103             final Phylogeny p4_0 = p.next();
6104             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
6105                 return false;
6106             }
6107             if ( p.hasNext() ) {
6108                 return false;
6109             }
6110             if ( p.next() != null ) {
6111                 return false;
6112             }
6113             //
6114             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
6115             p.setSource( p5_str );
6116             if ( !p.hasNext() ) {
6117                 return false;
6118             }
6119             final Phylogeny p5_0 = p.next();
6120             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
6121                 return false;
6122             }
6123             if ( p.hasNext() ) {
6124                 return false;
6125             }
6126             if ( p.next() != null ) {
6127                 return false;
6128             }
6129             //
6130             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6131             p.setSource( p6_str );
6132             if ( !p.hasNext() ) {
6133                 return false;
6134             }
6135             Phylogeny p6_0 = p.next();
6136             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6137                 return false;
6138             }
6139             if ( p.hasNext() ) {
6140                 return false;
6141             }
6142             if ( p.next() != null ) {
6143                 return false;
6144             }
6145             p.reset();
6146             if ( !p.hasNext() ) {
6147                 return false;
6148             }
6149             p6_0 = p.next();
6150             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6151                 return false;
6152             }
6153             if ( p.hasNext() ) {
6154                 return false;
6155             }
6156             if ( p.next() != null ) {
6157                 return false;
6158             }
6159             //
6160             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6161             p.setSource( p7_str );
6162             if ( !p.hasNext() ) {
6163                 return false;
6164             }
6165             Phylogeny p7_0 = p.next();
6166             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6167                 return false;
6168             }
6169             if ( p.hasNext() ) {
6170                 return false;
6171             }
6172             if ( p.next() != null ) {
6173                 return false;
6174             }
6175             p.reset();
6176             if ( !p.hasNext() ) {
6177                 return false;
6178             }
6179             p7_0 = p.next();
6180             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6181                 return false;
6182             }
6183             if ( p.hasNext() ) {
6184                 return false;
6185             }
6186             if ( p.next() != null ) {
6187                 return false;
6188             }
6189             //
6190             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
6191             p.setSource( p8_str );
6192             if ( !p.hasNext() ) {
6193                 return false;
6194             }
6195             Phylogeny p8_0 = p.next();
6196             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6197                 return false;
6198             }
6199             if ( !p.hasNext() ) {
6200                 return false;
6201             }
6202             if ( !p.hasNext() ) {
6203                 return false;
6204             }
6205             Phylogeny p8_1 = p.next();
6206             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6207                 return false;
6208             }
6209             if ( p.hasNext() ) {
6210                 return false;
6211             }
6212             if ( p.next() != null ) {
6213                 return false;
6214             }
6215             p.reset();
6216             if ( !p.hasNext() ) {
6217                 return false;
6218             }
6219             p8_0 = p.next();
6220             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6221                 return false;
6222             }
6223             if ( !p.hasNext() ) {
6224                 return false;
6225             }
6226             p8_1 = p.next();
6227             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6228                 return false;
6229             }
6230             if ( p.hasNext() ) {
6231                 return false;
6232             }
6233             if ( p.next() != null ) {
6234                 return false;
6235             }
6236             p.reset();
6237             //
6238             p.setSource( "" );
6239             if ( p.hasNext() ) {
6240                 return false;
6241             }
6242             //
6243             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
6244             if ( !p.hasNext() ) {
6245                 return false;
6246             }
6247             Phylogeny p_27 = p.next();
6248             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6249                 System.out.println( p_27.toNewHampshireX() );
6250                 System.exit( -1 );
6251                 return false;
6252             }
6253             if ( p.hasNext() ) {
6254                 return false;
6255             }
6256             if ( p.next() != null ) {
6257                 return false;
6258             }
6259             p.reset();
6260             if ( !p.hasNext() ) {
6261                 return false;
6262             }
6263             p_27 = p.next();
6264             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6265                 System.out.println( p_27.toNewHampshireX() );
6266                 System.exit( -1 );
6267                 return false;
6268             }
6269             if ( p.hasNext() ) {
6270                 return false;
6271             }
6272             if ( p.next() != null ) {
6273                 return false;
6274             }
6275         }
6276         catch ( final Exception e ) {
6277             e.printStackTrace( System.out );
6278             return false;
6279         }
6280         return true;
6281     }
6282
6283     private static boolean testNHXconversion() {
6284         try {
6285             final PhylogenyNode n1 = new PhylogenyNode();
6286             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6287             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6288             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6289             final PhylogenyNode n5 = PhylogenyNode
6290                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
6291             final PhylogenyNode n6 = PhylogenyNode
6292                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
6293             if ( !n1.toNewHampshireX().equals( "" ) ) {
6294                 return false;
6295             }
6296             if ( !n2.toNewHampshireX().equals( "" ) ) {
6297                 return false;
6298             }
6299             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
6300                 return false;
6301             }
6302             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
6303                 return false;
6304             }
6305             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
6306                 return false;
6307             }
6308             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
6309                 System.out.println( n6.toNewHampshireX() );
6310                 return false;
6311             }
6312         }
6313         catch ( final Exception e ) {
6314             e.printStackTrace( System.out );
6315             return false;
6316         }
6317         return true;
6318     }
6319
6320     private static boolean testTaxonomyExtraction() {
6321         try {
6322             final PhylogenyNode n0 = PhylogenyNode
6323                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6324             if ( n0.getNodeData().isHasTaxonomy() ) {
6325                 return false;
6326             }
6327             final PhylogenyNode n1 = PhylogenyNode
6328                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6329             if ( n1.getNodeData().isHasTaxonomy() ) {
6330                 System.out.println( n1.toString() );
6331                 return false;
6332             }
6333             final PhylogenyNode n2x = PhylogenyNode
6334                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6335             if ( n2x.getNodeData().isHasTaxonomy() ) {
6336                 return false;
6337             }
6338             final PhylogenyNode n3 = PhylogenyNode
6339                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6340             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6341                 System.out.println( n3.toString() );
6342                 return false;
6343             }
6344             final PhylogenyNode n4 = PhylogenyNode
6345                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6346             if ( n4.getNodeData().isHasTaxonomy() ) {
6347                 System.out.println( n4.toString() );
6348                 return false;
6349             }
6350             final PhylogenyNode n5 = PhylogenyNode
6351                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6352             if ( n5.getNodeData().isHasTaxonomy() ) {
6353                 System.out.println( n5.toString() );
6354                 return false;
6355             }
6356             final PhylogenyNode n6 = PhylogenyNode
6357                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6358             if ( n6.getNodeData().isHasTaxonomy() ) {
6359                 System.out.println( n6.toString() );
6360                 return false;
6361             }
6362             final PhylogenyNode n7 = PhylogenyNode
6363                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6364             if ( n7.getNodeData().isHasTaxonomy() ) {
6365                 System.out.println( n7.toString() );
6366                 return false;
6367             }
6368             final PhylogenyNode n8 = PhylogenyNode
6369                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6370             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6371                 System.out.println( n8.toString() );
6372                 return false;
6373             }
6374             final PhylogenyNode n9 = PhylogenyNode
6375                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6376             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6377                 System.out.println( n9.toString() );
6378                 return false;
6379             }
6380             final PhylogenyNode n10x = PhylogenyNode
6381                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6382             if ( n10x.getNodeData().isHasTaxonomy() ) {
6383                 System.out.println( n10x.toString() );
6384                 return false;
6385             }
6386             final PhylogenyNode n10xx = PhylogenyNode
6387                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6388             if ( n10xx.getNodeData().isHasTaxonomy() ) {
6389                 System.out.println( n10xx.toString() );
6390                 return false;
6391             }
6392             final PhylogenyNode n10 = PhylogenyNode
6393                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6394             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
6395                 System.out.println( n10.toString() );
6396                 return false;
6397             }
6398             final PhylogenyNode n11 = PhylogenyNode
6399                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
6400             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
6401                 System.out.println( n11.toString() );
6402                 return false;
6403             }
6404             final PhylogenyNode n12 = PhylogenyNode
6405                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
6406                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
6407             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
6408                 System.out.println( n12.toString() );
6409                 return false;
6410             }
6411             final PhylogenyNode n13 = PhylogenyNode
6412                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
6413             if ( n13.getNodeData().isHasTaxonomy() ) {
6414                 System.out.println( n13.toString() );
6415                 return false;
6416             }
6417         }
6418         catch ( final Exception e ) {
6419             e.printStackTrace( System.out );
6420             return false;
6421         }
6422         return true;
6423     }
6424
6425     private static boolean testNHXNodeParsing() {
6426         try {
6427             final PhylogenyNode n1 = new PhylogenyNode();
6428             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6429             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6430             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6431             final PhylogenyNode n5 = PhylogenyNode
6432                     .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]" );
6433             if ( !n3.getName().equals( "n3" ) ) {
6434                 return false;
6435             }
6436             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6437                 return false;
6438             }
6439             if ( n3.isDuplication() ) {
6440                 return false;
6441             }
6442             if ( n3.isHasAssignedEvent() ) {
6443                 return false;
6444             }
6445             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
6446                 return false;
6447             }
6448             if ( !n4.getName().equals( "n4" ) ) {
6449                 return false;
6450             }
6451             if ( n4.getDistanceToParent() != 0.01 ) {
6452                 return false;
6453             }
6454             if ( !n5.getName().equals( "n5" ) ) {
6455                 return false;
6456             }
6457             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
6458                 return false;
6459             }
6460             if ( n5.getDistanceToParent() != 0.1 ) {
6461                 return false;
6462             }
6463             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
6464                 return false;
6465             }
6466             if ( !n5.isDuplication() ) {
6467                 return false;
6468             }
6469             if ( !n5.isHasAssignedEvent() ) {
6470                 return false;
6471             }
6472             final PhylogenyNode n8 = PhylogenyNode
6473                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
6474                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6475             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
6476                 return false;
6477             }
6478             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
6479                 return false;
6480             }
6481             final PhylogenyNode n9 = PhylogenyNode
6482                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
6483                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6484             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
6485                 return false;
6486             }
6487             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
6488                 return false;
6489             }
6490             final PhylogenyNode n10 = PhylogenyNode
6491                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6492             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
6493                 return false;
6494             }
6495             final PhylogenyNode n20 = PhylogenyNode
6496                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6497             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
6498                 return false;
6499             }
6500             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
6501                 return false;
6502             }
6503             final PhylogenyNode n20x = PhylogenyNode
6504                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6505             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
6506                 return false;
6507             }
6508             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
6509                 return false;
6510             }
6511             final PhylogenyNode n20xx = PhylogenyNode
6512                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6513             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
6514                 return false;
6515             }
6516             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
6517                 return false;
6518             }
6519             final PhylogenyNode n20xxx = PhylogenyNode
6520                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6521             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
6522                 return false;
6523             }
6524             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
6525                 return false;
6526             }
6527             final PhylogenyNode n20xxxx = PhylogenyNode
6528                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6529             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
6530                 return false;
6531             }
6532             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
6533                 return false;
6534             }
6535             final PhylogenyNode n21 = PhylogenyNode
6536                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6537             if ( !n21.getName().equals( "N21_PIG" ) ) {
6538                 return false;
6539             }
6540             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
6541                 return false;
6542             }
6543             final PhylogenyNode n21x = PhylogenyNode
6544                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6545             if ( !n21x.getName().equals( "n21_PIG" ) ) {
6546                 return false;
6547             }
6548             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
6549                 return false;
6550             }
6551             final PhylogenyNode n22 = PhylogenyNode
6552                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6553             if ( !n22.getName().equals( "n22/PIG" ) ) {
6554                 return false;
6555             }
6556             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
6557                 return false;
6558             }
6559             final PhylogenyNode n23 = PhylogenyNode
6560                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6561             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
6562                 return false;
6563             }
6564             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
6565                 return false;
6566             }
6567             final PhylogenyNode a = PhylogenyNode
6568                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6569             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
6570                 return false;
6571             }
6572             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
6573                 return false;
6574             }
6575             final PhylogenyNode c1 = PhylogenyNode
6576                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
6577                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6578             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
6579                 return false;
6580             }
6581             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
6582                 return false;
6583             }
6584             final PhylogenyNode c2 = PhylogenyNode
6585                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
6586                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6587             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
6588                 return false;
6589             }
6590             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
6591                 return false;
6592             }
6593             final PhylogenyNode e3 = PhylogenyNode
6594                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6595             if ( !e3.getName().equals( "n10_RAT~" ) ) {
6596                 return false;
6597             }
6598             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
6599                 return false;
6600             }
6601             final PhylogenyNode n11 = PhylogenyNode
6602                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
6603                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6604             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
6605                 return false;
6606             }
6607             if ( n11.getDistanceToParent() != 0.4 ) {
6608                 return false;
6609             }
6610             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
6611                 return false;
6612             }
6613             final PhylogenyNode n12 = PhylogenyNode
6614                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
6615                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6616             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
6617                 return false;
6618             }
6619             if ( n12.getDistanceToParent() != 0.4 ) {
6620                 return false;
6621             }
6622             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
6623                 return false;
6624             }
6625             final PhylogenyNode o = PhylogenyNode
6626                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6627             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
6628                 return false;
6629             }
6630             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
6631                 return false;
6632             }
6633             if ( n1.getName().compareTo( "" ) != 0 ) {
6634                 return false;
6635             }
6636             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6637                 return false;
6638             }
6639             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6640                 return false;
6641             }
6642             if ( n2.getName().compareTo( "" ) != 0 ) {
6643                 return false;
6644             }
6645             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6646                 return false;
6647             }
6648             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6649                 return false;
6650             }
6651             final PhylogenyNode n00 = PhylogenyNode
6652                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
6653             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
6654                 return false;
6655             }
6656             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
6657                 return false;
6658             }
6659             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
6660             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
6661                 return false;
6662             }
6663             final PhylogenyNode n13 = PhylogenyNode
6664                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6665             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
6666                 return false;
6667             }
6668             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
6669                 return false;
6670             }
6671             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6672                 return false;
6673             }
6674             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6675                 return false;
6676             }
6677             final PhylogenyNode n14 = PhylogenyNode
6678                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6679             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
6680                 return false;
6681             }
6682             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
6683                 return false;
6684             }
6685             final PhylogenyNode n15 = PhylogenyNode
6686                     .createInstanceFromNhxString( "something_wicked[123]",
6687                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6688             if ( !n15.getName().equals( "something_wicked" ) ) {
6689                 return false;
6690             }
6691             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
6692                 return false;
6693             }
6694             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
6695                 return false;
6696             }
6697             final PhylogenyNode n16 = PhylogenyNode
6698                     .createInstanceFromNhxString( "something_wicked2[9]",
6699                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6700             if ( !n16.getName().equals( "something_wicked2" ) ) {
6701                 return false;
6702             }
6703             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
6704                 return false;
6705             }
6706             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
6707                 return false;
6708             }
6709             final PhylogenyNode n17 = PhylogenyNode
6710                     .createInstanceFromNhxString( "something_wicked3[a]",
6711                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6712             if ( !n17.getName().equals( "something_wicked3" ) ) {
6713                 return false;
6714             }
6715             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
6716                 return false;
6717             }
6718             final PhylogenyNode n18 = PhylogenyNode
6719                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6720             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
6721                 return false;
6722             }
6723             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
6724                 return false;
6725             }
6726             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
6727                 return false;
6728             }
6729             final PhylogenyNode n19 = PhylogenyNode
6730                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6731             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
6732                 return false;
6733             }
6734             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6735                 return false;
6736             }
6737             final PhylogenyNode n30 = PhylogenyNode
6738                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
6739                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6740             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
6741                 return false;
6742             }
6743             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6744                 return false;
6745             }
6746             final PhylogenyNode n31 = PhylogenyNode
6747                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
6748                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6749             if ( n31.getNodeData().isHasTaxonomy() ) {
6750                 return false;
6751             }
6752             final PhylogenyNode n32 = PhylogenyNode
6753                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6754             if ( n32.getNodeData().isHasTaxonomy() ) {
6755                 return false;
6756             }
6757             final PhylogenyNode n40 = PhylogenyNode
6758                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6759             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6760                 return false;
6761             }
6762             final PhylogenyNode n41 = PhylogenyNode
6763                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6764             if ( n41.getNodeData().isHasTaxonomy() ) {
6765                 return false;
6766             }
6767             final PhylogenyNode n42 = PhylogenyNode
6768                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6769             if ( n42.getNodeData().isHasTaxonomy() ) {
6770                 return false;
6771             }
6772             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
6773                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
6774             if ( n43.getNodeData().isHasTaxonomy() ) {
6775                 return false;
6776             }
6777             final PhylogenyNode n44 = PhylogenyNode
6778                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6779             if ( n44.getNodeData().isHasTaxonomy() ) {
6780                 return false;
6781             }
6782         }
6783         catch ( final Exception e ) {
6784             e.printStackTrace( System.out );
6785             return false;
6786         }
6787         return true;
6788     }
6789
6790     private static boolean testNHXParsing() {
6791         try {
6792             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6793             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
6794             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
6795                 return false;
6796             }
6797             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]";
6798             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
6799             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6800                 return false;
6801             }
6802             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]";
6803             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
6804             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
6805                 return false;
6806             }
6807             final Phylogeny[] p3 = factory
6808                     .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]",
6809                              new NHXParser() );
6810             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6811                 return false;
6812             }
6813             final Phylogeny[] p4 = factory
6814                     .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(]",
6815                              new NHXParser() );
6816             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6817                 return false;
6818             }
6819             final Phylogeny[] p5 = factory
6820                     .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(((]",
6821                              new NHXParser() );
6822             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6823                 return false;
6824             }
6825             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)";
6826             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)";
6827             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
6828             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
6829                 return false;
6830             }
6831             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)))";
6832             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)))";
6833             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
6834             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
6835                 return false;
6836             }
6837             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])   ))[,,, ])))))))";
6838             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
6839             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
6840             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
6841                 return false;
6842             }
6843             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
6844             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6845                 return false;
6846             }
6847             final Phylogeny p10 = factory
6848                     .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]",
6849                              new NHXParser() )[ 0 ];
6850             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6851                 return false;
6852             }
6853         }
6854         catch ( final Exception e ) {
6855             e.printStackTrace( System.out );
6856             return false;
6857         }
6858         return true;
6859     }
6860
6861     private static boolean testNHXParsingQuotes() {
6862         try {
6863             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6864             final NHXParser p = new NHXParser();
6865             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
6866             if ( phylogenies_0.length != 5 ) {
6867                 return false;
6868             }
6869             final Phylogeny phy = phylogenies_0[ 4 ];
6870             if ( phy.getNumberOfExternalNodes() != 7 ) {
6871                 return false;
6872             }
6873             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
6874                 return false;
6875             }
6876             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
6877                 return false;
6878             }
6879             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
6880                     .getScientificName().equals( "hsapiens" ) ) {
6881                 return false;
6882             }
6883             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
6884                 return false;
6885             }
6886             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
6887                 return false;
6888             }
6889             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
6890                 return false;
6891             }
6892             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
6893                 return false;
6894             }
6895             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
6896                 return false;
6897             }
6898             final NHXParser p1p = new NHXParser();
6899             p1p.setIgnoreQuotes( true );
6900             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
6901             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
6902                 return false;
6903             }
6904             final NHXParser p2p = new NHXParser();
6905             p1p.setIgnoreQuotes( false );
6906             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
6907             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
6908                 return false;
6909             }
6910             final NHXParser p3p = new NHXParser();
6911             p3p.setIgnoreQuotes( false );
6912             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
6913             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
6914                 return false;
6915             }
6916             final NHXParser p4p = new NHXParser();
6917             p4p.setIgnoreQuotes( false );
6918             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
6919             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
6920                 return false;
6921             }
6922             final Phylogeny p10 = factory
6923                     .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]",
6924                              new NHXParser() )[ 0 ];
6925             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]";
6926             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
6927                 return false;
6928             }
6929             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
6930             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
6931                 return false;
6932             }
6933             //
6934             final Phylogeny p12 = factory
6935                     .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]",
6936                              new NHXParser() )[ 0 ];
6937             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]";
6938             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
6939                 return false;
6940             }
6941             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
6942             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
6943                 return false;
6944             }
6945             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;";
6946             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
6947                 return false;
6948             }
6949             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
6950             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
6951                 return false;
6952             }
6953         }
6954         catch ( final Exception e ) {
6955             e.printStackTrace( System.out );
6956             return false;
6957         }
6958         return true;
6959     }
6960
6961     private static boolean testNHXParsingMB() {
6962         try {
6963             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6964             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
6965                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6966                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6967                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6968                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6969                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6970                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6971                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6972                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
6973             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
6974                 return false;
6975             }
6976             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
6977                 return false;
6978             }
6979             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
6980                            0.1100000000000000e+00 ) ) {
6981                 return false;
6982             }
6983             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
6984                 return false;
6985             }
6986             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
6987                 return false;
6988             }
6989             final Phylogeny p2 = factory
6990                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
6991                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6992                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6993                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6994                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6995                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6996                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6997                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6998                                      + "7.369400000000000e-02}])",
6999                              new NHXParser() )[ 0 ];
7000             if ( p2.getNode( "1" ) == null ) {
7001                 return false;
7002             }
7003             if ( p2.getNode( "2" ) == null ) {
7004                 return false;
7005             }
7006         }
7007         catch ( final Exception e ) {
7008             e.printStackTrace( System.out );
7009             System.exit( -1 );
7010             return false;
7011         }
7012         return true;
7013     }
7014
7015     private static boolean testPhylogenyBranch() {
7016         try {
7017             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
7018             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
7019             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
7020             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
7021             if ( !a1b1.equals( a1b1 ) ) {
7022                 return false;
7023             }
7024             if ( !a1b1.equals( b1a1 ) ) {
7025                 return false;
7026             }
7027             if ( !b1a1.equals( a1b1 ) ) {
7028                 return false;
7029             }
7030             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
7031             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
7032             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
7033             if ( a1_b1.equals( b1_a1 ) ) {
7034                 return false;
7035             }
7036             if ( a1_b1.equals( a1_b1_ ) ) {
7037                 return false;
7038             }
7039             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
7040             if ( !a1_b1.equals( b1_a1_ ) ) {
7041                 return false;
7042             }
7043             if ( a1_b1_.equals( b1_a1_ ) ) {
7044                 return false;
7045             }
7046             if ( !a1_b1_.equals( b1_a1 ) ) {
7047                 return false;
7048             }
7049         }
7050         catch ( final Exception e ) {
7051             e.printStackTrace( System.out );
7052             return false;
7053         }
7054         return true;
7055     }
7056
7057     private static boolean testPhyloXMLparsingOfDistributionElement() {
7058         try {
7059             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7060             PhyloXmlParser xml_parser = null;
7061             try {
7062                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
7063             }
7064             catch ( final Exception e ) {
7065                 // Do nothing -- means were not running from jar.
7066             }
7067             if ( xml_parser == null ) {
7068                 xml_parser = new PhyloXmlParser();
7069                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
7070                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
7071                 }
7072                 else {
7073                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
7074                 }
7075             }
7076             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
7077                                                               xml_parser );
7078             if ( xml_parser.getErrorCount() > 0 ) {
7079                 System.out.println( xml_parser.getErrorMessages().toString() );
7080                 return false;
7081             }
7082             if ( phylogenies_0.length != 1 ) {
7083                 return false;
7084             }
7085             final Phylogeny t1 = phylogenies_0[ 0 ];
7086             PhylogenyNode n = null;
7087             Distribution d = null;
7088             n = t1.getNode( "root node" );
7089             if ( !n.getNodeData().isHasDistribution() ) {
7090                 return false;
7091             }
7092             if ( n.getNodeData().getDistributions().size() != 1 ) {
7093                 return false;
7094             }
7095             d = n.getNodeData().getDistribution();
7096             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7097                 return false;
7098             }
7099             if ( d.getPoints().size() != 1 ) {
7100                 return false;
7101             }
7102             if ( d.getPolygons() != null ) {
7103                 return false;
7104             }
7105             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7106                 return false;
7107             }
7108             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7109                 return false;
7110             }
7111             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7112                 return false;
7113             }
7114             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7115                 return false;
7116             }
7117             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7118                 return false;
7119             }
7120             n = t1.getNode( "node a" );
7121             if ( !n.getNodeData().isHasDistribution() ) {
7122                 return false;
7123             }
7124             if ( n.getNodeData().getDistributions().size() != 2 ) {
7125                 return false;
7126             }
7127             d = n.getNodeData().getDistribution( 1 );
7128             if ( !d.getDesc().equals( "San Diego" ) ) {
7129                 return false;
7130             }
7131             if ( d.getPoints().size() != 1 ) {
7132                 return false;
7133             }
7134             if ( d.getPolygons() != null ) {
7135                 return false;
7136             }
7137             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7138                 return false;
7139             }
7140             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7141                 return false;
7142             }
7143             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7144                 return false;
7145             }
7146             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7147                 return false;
7148             }
7149             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7150                 return false;
7151             }
7152             n = t1.getNode( "node bb" );
7153             if ( !n.getNodeData().isHasDistribution() ) {
7154                 return false;
7155             }
7156             if ( n.getNodeData().getDistributions().size() != 1 ) {
7157                 return false;
7158             }
7159             d = n.getNodeData().getDistribution( 0 );
7160             if ( d.getPoints().size() != 3 ) {
7161                 return false;
7162             }
7163             if ( d.getPolygons().size() != 2 ) {
7164                 return false;
7165             }
7166             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7167                 return false;
7168             }
7169             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7170                 return false;
7171             }
7172             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7173                 return false;
7174             }
7175             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7176                 return false;
7177             }
7178             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7179                 return false;
7180             }
7181             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7182                 return false;
7183             }
7184             Polygon p = d.getPolygons().get( 0 );
7185             if ( p.getPoints().size() != 3 ) {
7186                 return false;
7187             }
7188             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7189                 return false;
7190             }
7191             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7192                 return false;
7193             }
7194             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7195                 return false;
7196             }
7197             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7198                 return false;
7199             }
7200             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7201                 return false;
7202             }
7203             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7204                 return false;
7205             }
7206             p = d.getPolygons().get( 1 );
7207             if ( p.getPoints().size() != 3 ) {
7208                 return false;
7209             }
7210             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7211                 return false;
7212             }
7213             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7214                 return false;
7215             }
7216             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7217                 return false;
7218             }
7219             // Roundtrip:
7220             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
7221             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
7222             if ( rt.length != 1 ) {
7223                 return false;
7224             }
7225             final Phylogeny t1_rt = rt[ 0 ];
7226             n = t1_rt.getNode( "root node" );
7227             if ( !n.getNodeData().isHasDistribution() ) {
7228                 return false;
7229             }
7230             if ( n.getNodeData().getDistributions().size() != 1 ) {
7231                 return false;
7232             }
7233             d = n.getNodeData().getDistribution();
7234             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7235                 return false;
7236             }
7237             if ( d.getPoints().size() != 1 ) {
7238                 return false;
7239             }
7240             if ( d.getPolygons() != null ) {
7241                 return false;
7242             }
7243             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7244                 return false;
7245             }
7246             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7247                 return false;
7248             }
7249             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7250                 return false;
7251             }
7252             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7253                 return false;
7254             }
7255             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7256                 return false;
7257             }
7258             n = t1_rt.getNode( "node a" );
7259             if ( !n.getNodeData().isHasDistribution() ) {
7260                 return false;
7261             }
7262             if ( n.getNodeData().getDistributions().size() != 2 ) {
7263                 return false;
7264             }
7265             d = n.getNodeData().getDistribution( 1 );
7266             if ( !d.getDesc().equals( "San Diego" ) ) {
7267                 return false;
7268             }
7269             if ( d.getPoints().size() != 1 ) {
7270                 return false;
7271             }
7272             if ( d.getPolygons() != null ) {
7273                 return false;
7274             }
7275             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7276                 return false;
7277             }
7278             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7279                 return false;
7280             }
7281             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7282                 return false;
7283             }
7284             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7285                 return false;
7286             }
7287             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7288                 return false;
7289             }
7290             n = t1_rt.getNode( "node bb" );
7291             if ( !n.getNodeData().isHasDistribution() ) {
7292                 return false;
7293             }
7294             if ( n.getNodeData().getDistributions().size() != 1 ) {
7295                 return false;
7296             }
7297             d = n.getNodeData().getDistribution( 0 );
7298             if ( d.getPoints().size() != 3 ) {
7299                 return false;
7300             }
7301             if ( d.getPolygons().size() != 2 ) {
7302                 return false;
7303             }
7304             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7305                 return false;
7306             }
7307             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7308                 return false;
7309             }
7310             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7311                 return false;
7312             }
7313             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7314                 return false;
7315             }
7316             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7317                 return false;
7318             }
7319             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7320                 return false;
7321             }
7322             p = d.getPolygons().get( 0 );
7323             if ( p.getPoints().size() != 3 ) {
7324                 return false;
7325             }
7326             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7327                 return false;
7328             }
7329             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7330                 return false;
7331             }
7332             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7333                 return false;
7334             }
7335             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7336                 return false;
7337             }
7338             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7339                 return false;
7340             }
7341             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7342                 return false;
7343             }
7344             p = d.getPolygons().get( 1 );
7345             if ( p.getPoints().size() != 3 ) {
7346                 return false;
7347             }
7348             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7349                 return false;
7350             }
7351             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7352                 return false;
7353             }
7354             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7355                 return false;
7356             }
7357         }
7358         catch ( final Exception e ) {
7359             e.printStackTrace( System.out );
7360             return false;
7361         }
7362         return true;
7363     }
7364
7365     private static boolean testPostOrderIterator() {
7366         try {
7367             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7368             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7369             PhylogenyNodeIterator it0;
7370             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
7371                 it0.next();
7372             }
7373             for( it0.reset(); it0.hasNext(); ) {
7374                 it0.next();
7375             }
7376             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7377             final PhylogenyNodeIterator it = t1.iteratorPostorder();
7378             if ( !it.next().getName().equals( "A" ) ) {
7379                 return false;
7380             }
7381             if ( !it.next().getName().equals( "B" ) ) {
7382                 return false;
7383             }
7384             if ( !it.next().getName().equals( "ab" ) ) {
7385                 return false;
7386             }
7387             if ( !it.next().getName().equals( "C" ) ) {
7388                 return false;
7389             }
7390             if ( !it.next().getName().equals( "D" ) ) {
7391                 return false;
7392             }
7393             if ( !it.next().getName().equals( "cd" ) ) {
7394                 return false;
7395             }
7396             if ( !it.next().getName().equals( "abcd" ) ) {
7397                 return false;
7398             }
7399             if ( !it.next().getName().equals( "E" ) ) {
7400                 return false;
7401             }
7402             if ( !it.next().getName().equals( "F" ) ) {
7403                 return false;
7404             }
7405             if ( !it.next().getName().equals( "ef" ) ) {
7406                 return false;
7407             }
7408             if ( !it.next().getName().equals( "G" ) ) {
7409                 return false;
7410             }
7411             if ( !it.next().getName().equals( "H" ) ) {
7412                 return false;
7413             }
7414             if ( !it.next().getName().equals( "gh" ) ) {
7415                 return false;
7416             }
7417             if ( !it.next().getName().equals( "efgh" ) ) {
7418                 return false;
7419             }
7420             if ( !it.next().getName().equals( "r" ) ) {
7421                 return false;
7422             }
7423             if ( it.hasNext() ) {
7424                 return false;
7425             }
7426         }
7427         catch ( final Exception e ) {
7428             e.printStackTrace( System.out );
7429             return false;
7430         }
7431         return true;
7432     }
7433
7434     private static boolean testPreOrderIterator() {
7435         try {
7436             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7437             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7438             PhylogenyNodeIterator it0;
7439             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
7440                 it0.next();
7441             }
7442             for( it0.reset(); it0.hasNext(); ) {
7443                 it0.next();
7444             }
7445             PhylogenyNodeIterator it = t0.iteratorPreorder();
7446             if ( !it.next().getName().equals( "r" ) ) {
7447                 return false;
7448             }
7449             if ( !it.next().getName().equals( "ab" ) ) {
7450                 return false;
7451             }
7452             if ( !it.next().getName().equals( "A" ) ) {
7453                 return false;
7454             }
7455             if ( !it.next().getName().equals( "B" ) ) {
7456                 return false;
7457             }
7458             if ( !it.next().getName().equals( "cd" ) ) {
7459                 return false;
7460             }
7461             if ( !it.next().getName().equals( "C" ) ) {
7462                 return false;
7463             }
7464             if ( !it.next().getName().equals( "D" ) ) {
7465                 return false;
7466             }
7467             if ( it.hasNext() ) {
7468                 return false;
7469             }
7470             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7471             it = t1.iteratorPreorder();
7472             if ( !it.next().getName().equals( "r" ) ) {
7473                 return false;
7474             }
7475             if ( !it.next().getName().equals( "abcd" ) ) {
7476                 return false;
7477             }
7478             if ( !it.next().getName().equals( "ab" ) ) {
7479                 return false;
7480             }
7481             if ( !it.next().getName().equals( "A" ) ) {
7482                 return false;
7483             }
7484             if ( !it.next().getName().equals( "B" ) ) {
7485                 return false;
7486             }
7487             if ( !it.next().getName().equals( "cd" ) ) {
7488                 return false;
7489             }
7490             if ( !it.next().getName().equals( "C" ) ) {
7491                 return false;
7492             }
7493             if ( !it.next().getName().equals( "D" ) ) {
7494                 return false;
7495             }
7496             if ( !it.next().getName().equals( "efgh" ) ) {
7497                 return false;
7498             }
7499             if ( !it.next().getName().equals( "ef" ) ) {
7500                 return false;
7501             }
7502             if ( !it.next().getName().equals( "E" ) ) {
7503                 return false;
7504             }
7505             if ( !it.next().getName().equals( "F" ) ) {
7506                 return false;
7507             }
7508             if ( !it.next().getName().equals( "gh" ) ) {
7509                 return false;
7510             }
7511             if ( !it.next().getName().equals( "G" ) ) {
7512                 return false;
7513             }
7514             if ( !it.next().getName().equals( "H" ) ) {
7515                 return false;
7516             }
7517             if ( it.hasNext() ) {
7518                 return false;
7519             }
7520         }
7521         catch ( final Exception e ) {
7522             e.printStackTrace( System.out );
7523             return false;
7524         }
7525         return true;
7526     }
7527
7528     private static boolean testPropertiesMap() {
7529         try {
7530             final PropertiesMap pm = new PropertiesMap();
7531             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7532             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7533             final Property p2 = new Property( "something:else",
7534                                               "?",
7535                                               "improbable:research",
7536                                               "xsd:decimal",
7537                                               AppliesTo.NODE );
7538             pm.addProperty( p0 );
7539             pm.addProperty( p1 );
7540             pm.addProperty( p2 );
7541             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
7542                 return false;
7543             }
7544             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
7545                 return false;
7546             }
7547             if ( pm.getProperties().size() != 3 ) {
7548                 return false;
7549             }
7550             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
7551                 return false;
7552             }
7553             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7554                 return false;
7555             }
7556             if ( pm.getProperties().size() != 3 ) {
7557                 return false;
7558             }
7559             pm.removeProperty( "dimensions:diameter" );
7560             if ( pm.getProperties().size() != 2 ) {
7561                 return false;
7562             }
7563             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
7564                 return false;
7565             }
7566             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7567                 return false;
7568             }
7569         }
7570         catch ( final Exception e ) {
7571             e.printStackTrace( System.out );
7572             return false;
7573         }
7574         return true;
7575     }
7576
7577     private static boolean testReIdMethods() {
7578         try {
7579             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7580             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
7581             final long count = PhylogenyNode.getNodeCount();
7582             p.levelOrderReID();
7583             if ( p.getNode( "r" ).getId() != count ) {
7584                 return false;
7585             }
7586             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
7587                 return false;
7588             }
7589             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
7590                 return false;
7591             }
7592             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
7593                 return false;
7594             }
7595             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
7596                 return false;
7597             }
7598             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
7599                 return false;
7600             }
7601             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
7602                 return false;
7603             }
7604             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
7605                 return false;
7606             }
7607             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
7608                 return false;
7609             }
7610             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
7611                 return false;
7612             }
7613             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
7614                 return false;
7615             }
7616             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
7617                 return false;
7618             }
7619             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
7620                 return false;
7621             }
7622             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
7623                 return false;
7624             }
7625             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
7626                 return false;
7627             }
7628         }
7629         catch ( final Exception e ) {
7630             e.printStackTrace( System.out );
7631             return false;
7632         }
7633         return true;
7634     }
7635
7636     private static boolean testRerooting() {
7637         try {
7638             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7639             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",
7640                                                  new NHXParser() )[ 0 ];
7641             if ( !t1.isRooted() ) {
7642                 return false;
7643             }
7644             t1.reRoot( t1.getNode( "D" ) );
7645             t1.reRoot( t1.getNode( "CD" ) );
7646             t1.reRoot( t1.getNode( "A" ) );
7647             t1.reRoot( t1.getNode( "B" ) );
7648             t1.reRoot( t1.getNode( "AB" ) );
7649             t1.reRoot( t1.getNode( "D" ) );
7650             t1.reRoot( t1.getNode( "C" ) );
7651             t1.reRoot( t1.getNode( "CD" ) );
7652             t1.reRoot( t1.getNode( "A" ) );
7653             t1.reRoot( t1.getNode( "B" ) );
7654             t1.reRoot( t1.getNode( "AB" ) );
7655             t1.reRoot( t1.getNode( "D" ) );
7656             t1.reRoot( t1.getNode( "D" ) );
7657             t1.reRoot( t1.getNode( "C" ) );
7658             t1.reRoot( t1.getNode( "A" ) );
7659             t1.reRoot( t1.getNode( "B" ) );
7660             t1.reRoot( t1.getNode( "AB" ) );
7661             t1.reRoot( t1.getNode( "C" ) );
7662             t1.reRoot( t1.getNode( "D" ) );
7663             t1.reRoot( t1.getNode( "CD" ) );
7664             t1.reRoot( t1.getNode( "D" ) );
7665             t1.reRoot( t1.getNode( "A" ) );
7666             t1.reRoot( t1.getNode( "B" ) );
7667             t1.reRoot( t1.getNode( "AB" ) );
7668             t1.reRoot( t1.getNode( "C" ) );
7669             t1.reRoot( t1.getNode( "D" ) );
7670             t1.reRoot( t1.getNode( "CD" ) );
7671             t1.reRoot( t1.getNode( "D" ) );
7672             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
7673                 return false;
7674             }
7675             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
7676                 return false;
7677             }
7678             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
7679                 return false;
7680             }
7681             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
7682                 return false;
7683             }
7684             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
7685                 return false;
7686             }
7687             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
7688                 return false;
7689             }
7690             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",
7691                                                  new NHXParser() )[ 0 ];
7692             t2.reRoot( t2.getNode( "A" ) );
7693             t2.reRoot( t2.getNode( "D" ) );
7694             t2.reRoot( t2.getNode( "ABC" ) );
7695             t2.reRoot( t2.getNode( "A" ) );
7696             t2.reRoot( t2.getNode( "B" ) );
7697             t2.reRoot( t2.getNode( "D" ) );
7698             t2.reRoot( t2.getNode( "C" ) );
7699             t2.reRoot( t2.getNode( "ABC" ) );
7700             t2.reRoot( t2.getNode( "A" ) );
7701             t2.reRoot( t2.getNode( "B" ) );
7702             t2.reRoot( t2.getNode( "AB" ) );
7703             t2.reRoot( t2.getNode( "AB" ) );
7704             t2.reRoot( t2.getNode( "D" ) );
7705             t2.reRoot( t2.getNode( "C" ) );
7706             t2.reRoot( t2.getNode( "B" ) );
7707             t2.reRoot( t2.getNode( "AB" ) );
7708             t2.reRoot( t2.getNode( "D" ) );
7709             t2.reRoot( t2.getNode( "D" ) );
7710             t2.reRoot( t2.getNode( "ABC" ) );
7711             t2.reRoot( t2.getNode( "A" ) );
7712             t2.reRoot( t2.getNode( "B" ) );
7713             t2.reRoot( t2.getNode( "AB" ) );
7714             t2.reRoot( t2.getNode( "D" ) );
7715             t2.reRoot( t2.getNode( "C" ) );
7716             t2.reRoot( t2.getNode( "ABC" ) );
7717             t2.reRoot( t2.getNode( "A" ) );
7718             t2.reRoot( t2.getNode( "B" ) );
7719             t2.reRoot( t2.getNode( "AB" ) );
7720             t2.reRoot( t2.getNode( "D" ) );
7721             t2.reRoot( t2.getNode( "D" ) );
7722             t2.reRoot( t2.getNode( "C" ) );
7723             t2.reRoot( t2.getNode( "A" ) );
7724             t2.reRoot( t2.getNode( "B" ) );
7725             t2.reRoot( t2.getNode( "AB" ) );
7726             t2.reRoot( t2.getNode( "C" ) );
7727             t2.reRoot( t2.getNode( "D" ) );
7728             t2.reRoot( t2.getNode( "ABC" ) );
7729             t2.reRoot( t2.getNode( "D" ) );
7730             t2.reRoot( t2.getNode( "A" ) );
7731             t2.reRoot( t2.getNode( "B" ) );
7732             t2.reRoot( t2.getNode( "AB" ) );
7733             t2.reRoot( t2.getNode( "C" ) );
7734             t2.reRoot( t2.getNode( "D" ) );
7735             t2.reRoot( t2.getNode( "ABC" ) );
7736             t2.reRoot( t2.getNode( "D" ) );
7737             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7738                 return false;
7739             }
7740             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7741                 return false;
7742             }
7743             t2.reRoot( t2.getNode( "ABC" ) );
7744             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7745                 return false;
7746             }
7747             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7748                 return false;
7749             }
7750             t2.reRoot( t2.getNode( "AB" ) );
7751             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7752                 return false;
7753             }
7754             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7755                 return false;
7756             }
7757             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7758                 return false;
7759             }
7760             t2.reRoot( t2.getNode( "AB" ) );
7761             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7762                 return false;
7763             }
7764             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7765                 return false;
7766             }
7767             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7768                 return false;
7769             }
7770             t2.reRoot( t2.getNode( "D" ) );
7771             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7772                 return false;
7773             }
7774             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7775                 return false;
7776             }
7777             t2.reRoot( t2.getNode( "ABC" ) );
7778             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7779                 return false;
7780             }
7781             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7782                 return false;
7783             }
7784             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
7785                                                  new NHXParser() )[ 0 ];
7786             t3.reRoot( t3.getNode( "B" ) );
7787             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7788                 return false;
7789             }
7790             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7791                 return false;
7792             }
7793             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7794                 return false;
7795             }
7796             t3.reRoot( t3.getNode( "B" ) );
7797             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7798                 return false;
7799             }
7800             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7801                 return false;
7802             }
7803             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7804                 return false;
7805             }
7806             t3.reRoot( t3.getRoot() );
7807             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7808                 return false;
7809             }
7810             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7811                 return false;
7812             }
7813             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7814                 return false;
7815             }
7816         }
7817         catch ( final Exception e ) {
7818             e.printStackTrace( System.out );
7819             return false;
7820         }
7821         return true;
7822     }
7823
7824     private static boolean testSDIse() {
7825         try {
7826             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7827             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
7828             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
7829             gene1.setRooted( true );
7830             species1.setRooted( true );
7831             final SDI sdi = new SDI( gene1, species1 );
7832             if ( !gene1.getRoot().isDuplication() ) {
7833                 return false;
7834             }
7835             final Phylogeny species2 = factory
7836                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7837                              new NHXParser() )[ 0 ];
7838             final Phylogeny gene2 = factory
7839                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7840                              new NHXParser() )[ 0 ];
7841             species2.setRooted( true );
7842             gene2.setRooted( true );
7843             final SDI sdi2 = new SDI( gene2, species2 );
7844             if ( sdi2.getDuplicationsSum() != 0 ) {
7845                 return false;
7846             }
7847             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
7848                 return false;
7849             }
7850             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
7851                 return false;
7852             }
7853             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
7854                 return false;
7855             }
7856             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
7857                 return false;
7858             }
7859             if ( !gene2.getNode( "r" ).isSpeciation() ) {
7860                 return false;
7861             }
7862             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
7863                 return false;
7864             }
7865             final Phylogeny species3 = factory
7866                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7867                              new NHXParser() )[ 0 ];
7868             final Phylogeny gene3 = factory
7869                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7870                              new NHXParser() )[ 0 ];
7871             species3.setRooted( true );
7872             gene3.setRooted( true );
7873             final SDI sdi3 = new SDI( gene3, species3 );
7874             if ( sdi3.getDuplicationsSum() != 1 ) {
7875                 return false;
7876             }
7877             if ( !gene3.getNode( "aa" ).isDuplication() ) {
7878                 return false;
7879             }
7880             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
7881                 return false;
7882             }
7883             final Phylogeny species4 = factory
7884                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7885                              new NHXParser() )[ 0 ];
7886             final Phylogeny gene4 = factory
7887                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7888                              new NHXParser() )[ 0 ];
7889             species4.setRooted( true );
7890             gene4.setRooted( true );
7891             final SDI sdi4 = new SDI( gene4, species4 );
7892             if ( sdi4.getDuplicationsSum() != 1 ) {
7893                 return false;
7894             }
7895             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
7896                 return false;
7897             }
7898             if ( !gene4.getNode( "abc" ).isDuplication() ) {
7899                 return false;
7900             }
7901             if ( gene4.getNode( "abcd" ).isDuplication() ) {
7902                 return false;
7903             }
7904             if ( species4.getNumberOfExternalNodes() != 6 ) {
7905                 return false;
7906             }
7907             if ( gene4.getNumberOfExternalNodes() != 6 ) {
7908                 return false;
7909             }
7910             final Phylogeny species5 = factory
7911                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7912                              new NHXParser() )[ 0 ];
7913             final Phylogeny gene5 = factory
7914                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7915                              new NHXParser() )[ 0 ];
7916             species5.setRooted( true );
7917             gene5.setRooted( true );
7918             final SDI sdi5 = new SDI( gene5, species5 );
7919             if ( sdi5.getDuplicationsSum() != 2 ) {
7920                 return false;
7921             }
7922             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
7923                 return false;
7924             }
7925             if ( !gene5.getNode( "adc" ).isDuplication() ) {
7926                 return false;
7927             }
7928             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
7929                 return false;
7930             }
7931             if ( species5.getNumberOfExternalNodes() != 6 ) {
7932                 return false;
7933             }
7934             if ( gene5.getNumberOfExternalNodes() != 6 ) {
7935                 return false;
7936             }
7937             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
7938             // Conjecture for Comparing Molecular Phylogenies"
7939             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
7940             final Phylogeny species6 = factory
7941                     .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,"
7942                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
7943                              new NHXParser() )[ 0 ];
7944             final Phylogeny gene6 = factory
7945                     .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,"
7946                                      + "((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,"
7947                                      + "(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;",
7948                              new NHXParser() )[ 0 ];
7949             species6.setRooted( true );
7950             gene6.setRooted( true );
7951             final SDI sdi6 = new SDI( gene6, species6 );
7952             if ( sdi6.getDuplicationsSum() != 3 ) {
7953                 return false;
7954             }
7955             if ( !gene6.getNode( "r" ).isDuplication() ) {
7956                 return false;
7957             }
7958             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
7959                 return false;
7960             }
7961             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
7962                 return false;
7963             }
7964             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
7965                 return false;
7966             }
7967             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
7968                 return false;
7969             }
7970             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
7971                 return false;
7972             }
7973             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
7974                 return false;
7975             }
7976             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
7977                 return false;
7978             }
7979             sdi6.computeMappingCostL();
7980             if ( sdi6.computeMappingCostL() != 17 ) {
7981                 return false;
7982             }
7983             if ( species6.getNumberOfExternalNodes() != 9 ) {
7984                 return false;
7985             }
7986             if ( gene6.getNumberOfExternalNodes() != 9 ) {
7987                 return false;
7988             }
7989             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
7990                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
7991                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
7992                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
7993                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
7994             species7.setRooted( true );
7995             final Phylogeny gene7_1 = Test
7996                     .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])" );
7997             gene7_1.setRooted( true );
7998             final SDI sdi7 = new SDI( gene7_1, species7 );
7999             if ( sdi7.getDuplicationsSum() != 0 ) {
8000                 return false;
8001             }
8002             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
8003                 return false;
8004             }
8005             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
8006                 return false;
8007             }
8008             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
8009                 return false;
8010             }
8011             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
8012                 return false;
8013             }
8014             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
8015                 return false;
8016             }
8017             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
8018                 return false;
8019             }
8020             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
8021                 return false;
8022             }
8023             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
8024                 return false;
8025             }
8026             final Phylogeny gene7_2 = Test
8027                     .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])" );
8028             gene7_2.setRooted( true );
8029             final SDI sdi7_2 = new SDI( gene7_2, species7 );
8030             if ( sdi7_2.getDuplicationsSum() != 1 ) {
8031                 return false;
8032             }
8033             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
8034                 return false;
8035             }
8036             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
8037                 return false;
8038             }
8039             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
8040                 return false;
8041             }
8042             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
8043                 return false;
8044             }
8045             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
8046                 return false;
8047             }
8048             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
8049                 return false;
8050             }
8051             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
8052                 return false;
8053             }
8054             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
8055                 return false;
8056             }
8057             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
8058                 return false;
8059             }
8060         }
8061         catch ( final Exception e ) {
8062             return false;
8063         }
8064         return true;
8065     }
8066
8067     private static boolean testSDIunrooted() {
8068         try {
8069             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8070             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
8071             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
8072             final Iterator<PhylogenyBranch> iter = l.iterator();
8073             PhylogenyBranch br = iter.next();
8074             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
8075                 return false;
8076             }
8077             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
8078                 return false;
8079             }
8080             br = iter.next();
8081             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8082                 return false;
8083             }
8084             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8085                 return false;
8086             }
8087             br = iter.next();
8088             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
8089                 return false;
8090             }
8091             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
8092                 return false;
8093             }
8094             br = iter.next();
8095             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8096                 return false;
8097             }
8098             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8099                 return false;
8100             }
8101             br = iter.next();
8102             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8103                 return false;
8104             }
8105             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8106                 return false;
8107             }
8108             br = iter.next();
8109             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8110                 return false;
8111             }
8112             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8113                 return false;
8114             }
8115             br = iter.next();
8116             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8117                 return false;
8118             }
8119             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8120                 return false;
8121             }
8122             br = iter.next();
8123             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8124                 return false;
8125             }
8126             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8127                 return false;
8128             }
8129             br = iter.next();
8130             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8131                 return false;
8132             }
8133             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8134                 return false;
8135             }
8136             br = iter.next();
8137             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8138                 return false;
8139             }
8140             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8141                 return false;
8142             }
8143             br = iter.next();
8144             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8145                 return false;
8146             }
8147             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8148                 return false;
8149             }
8150             br = iter.next();
8151             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
8152                 return false;
8153             }
8154             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
8155                 return false;
8156             }
8157             br = iter.next();
8158             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8159                 return false;
8160             }
8161             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8162                 return false;
8163             }
8164             br = iter.next();
8165             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
8166                 return false;
8167             }
8168             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
8169                 return false;
8170             }
8171             br = iter.next();
8172             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
8173                 return false;
8174             }
8175             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
8176                 return false;
8177             }
8178             if ( iter.hasNext() ) {
8179                 return false;
8180             }
8181             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
8182             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
8183             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
8184             br = iter1.next();
8185             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8186                 return false;
8187             }
8188             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8189                 return false;
8190             }
8191             br = iter1.next();
8192             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8193                 return false;
8194             }
8195             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8196                 return false;
8197             }
8198             br = iter1.next();
8199             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8200                 return false;
8201             }
8202             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8203                 return false;
8204             }
8205             if ( iter1.hasNext() ) {
8206                 return false;
8207             }
8208             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
8209             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
8210             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
8211             br = iter2.next();
8212             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8213                 return false;
8214             }
8215             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8216                 return false;
8217             }
8218             br = iter2.next();
8219             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8220                 return false;
8221             }
8222             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8223                 return false;
8224             }
8225             br = iter2.next();
8226             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8227                 return false;
8228             }
8229             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8230                 return false;
8231             }
8232             if ( iter2.hasNext() ) {
8233                 return false;
8234             }
8235             final Phylogeny species0 = factory
8236                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
8237                              new NHXParser() )[ 0 ];
8238             final Phylogeny gene1 = factory
8239                     .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])",
8240                              new NHXParser() )[ 0 ];
8241             species0.setRooted( true );
8242             gene1.setRooted( true );
8243             final SDIR sdi_unrooted = new SDIR();
8244             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
8245             if ( sdi_unrooted.getCount() != 1 ) {
8246                 return false;
8247             }
8248             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
8249                 return false;
8250             }
8251             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
8252                 return false;
8253             }
8254             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
8255                 return false;
8256             }
8257             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8258                 return false;
8259             }
8260             final Phylogeny gene2 = factory
8261                     .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])",
8262                              new NHXParser() )[ 0 ];
8263             gene2.setRooted( true );
8264             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
8265             if ( sdi_unrooted.getCount() != 1 ) {
8266                 return false;
8267             }
8268             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8269                 return false;
8270             }
8271             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8272                 return false;
8273             }
8274             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
8275                 return false;
8276             }
8277             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8278                 return false;
8279             }
8280             final Phylogeny species6 = factory
8281                     .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,"
8282                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8283                              new NHXParser() )[ 0 ];
8284             final Phylogeny gene6 = factory
8285                     .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],"
8286                                      + "(((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],"
8287                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8288                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8289                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8290                              new NHXParser() )[ 0 ];
8291             species6.setRooted( true );
8292             gene6.setRooted( true );
8293             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
8294             if ( sdi_unrooted.getCount() != 1 ) {
8295                 return false;
8296             }
8297             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8298                 return false;
8299             }
8300             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8301                 return false;
8302             }
8303             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8304                 return false;
8305             }
8306             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8307                 return false;
8308             }
8309             if ( !p6[ 0 ].getRoot().isDuplication() ) {
8310                 return false;
8311             }
8312             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8313                 return false;
8314             }
8315             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8316                 return false;
8317             }
8318             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
8319                 return false;
8320             }
8321             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8322                 return false;
8323             }
8324             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
8325                 return false;
8326             }
8327             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
8328                 return false;
8329             }
8330             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8331                 return false;
8332             }
8333             p6 = null;
8334             final Phylogeny species7 = factory
8335                     .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,"
8336                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8337                              new NHXParser() )[ 0 ];
8338             final Phylogeny gene7 = factory
8339                     .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],"
8340                                      + "(((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],"
8341                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8342                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8343                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8344                              new NHXParser() )[ 0 ];
8345             species7.setRooted( true );
8346             gene7.setRooted( true );
8347             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
8348             if ( sdi_unrooted.getCount() != 1 ) {
8349                 return false;
8350             }
8351             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8352                 return false;
8353             }
8354             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8355                 return false;
8356             }
8357             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8358                 return false;
8359             }
8360             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
8361                 return false;
8362             }
8363             if ( !p7[ 0 ].getRoot().isDuplication() ) {
8364                 return false;
8365             }
8366             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8367                 return false;
8368             }
8369             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8370                 return false;
8371             }
8372             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
8373                 return false;
8374             }
8375             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8376                 return false;
8377             }
8378             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
8379                 return false;
8380             }
8381             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
8382                 return false;
8383             }
8384             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8385                 return false;
8386             }
8387             p7 = null;
8388             final Phylogeny species8 = factory
8389                     .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,"
8390                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8391                              new NHXParser() )[ 0 ];
8392             final Phylogeny gene8 = factory
8393                     .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],"
8394                                      + "(((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],"
8395                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8396                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8397                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8398                              new NHXParser() )[ 0 ];
8399             species8.setRooted( true );
8400             gene8.setRooted( true );
8401             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
8402             if ( sdi_unrooted.getCount() != 1 ) {
8403                 return false;
8404             }
8405             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8406                 return false;
8407             }
8408             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8409                 return false;
8410             }
8411             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8412                 return false;
8413             }
8414             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8415                 return false;
8416             }
8417             if ( !p8[ 0 ].getRoot().isDuplication() ) {
8418                 return false;
8419             }
8420             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8421                 return false;
8422             }
8423             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8424                 return false;
8425             }
8426             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
8427                 return false;
8428             }
8429             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8430                 return false;
8431             }
8432             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
8433                 return false;
8434             }
8435             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
8436                 return false;
8437             }
8438             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8439                 return false;
8440             }
8441             p8 = null;
8442         }
8443         catch ( final Exception e ) {
8444             e.printStackTrace( System.out );
8445             return false;
8446         }
8447         return true;
8448     }
8449
8450     private static boolean testSplit() {
8451         try {
8452             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8453             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8454             //Archaeopteryx.createApplication( p0 );
8455             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8456             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8457             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8458             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8459             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8460             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8461             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8462             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8463             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8464             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8465             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
8466             // System.out.println( s0.toString() );
8467             //
8468             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8469             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8471             if ( s0.match( query_nodes ) ) {
8472                 return false;
8473             }
8474             query_nodes = new HashSet<PhylogenyNode>();
8475             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8476             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8477             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8478             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8482             if ( !s0.match( query_nodes ) ) {
8483                 return false;
8484             }
8485             //
8486             query_nodes = new HashSet<PhylogenyNode>();
8487             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8490             if ( !s0.match( query_nodes ) ) {
8491                 return false;
8492             }
8493             //
8494             query_nodes = new HashSet<PhylogenyNode>();
8495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8498             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8499             if ( !s0.match( query_nodes ) ) {
8500                 return false;
8501             }
8502             //
8503             query_nodes = new HashSet<PhylogenyNode>();
8504             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8505             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8506             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8507             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8508             if ( !s0.match( query_nodes ) ) {
8509                 return false;
8510             }
8511             //
8512             query_nodes = new HashSet<PhylogenyNode>();
8513             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8514             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8515             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8516             if ( !s0.match( query_nodes ) ) {
8517                 return false;
8518             }
8519             //
8520             query_nodes = new HashSet<PhylogenyNode>();
8521             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8522             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8523             if ( !s0.match( query_nodes ) ) {
8524                 return false;
8525             }
8526             //
8527             query_nodes = new HashSet<PhylogenyNode>();
8528             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8529             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8533             if ( !s0.match( query_nodes ) ) {
8534                 return false;
8535             }
8536             //
8537             query_nodes = new HashSet<PhylogenyNode>();
8538             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8541             if ( !s0.match( query_nodes ) ) {
8542                 return false;
8543             }
8544             //
8545             query_nodes = new HashSet<PhylogenyNode>();
8546             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8550             if ( !s0.match( query_nodes ) ) {
8551                 return false;
8552             }
8553             //
8554             query_nodes = new HashSet<PhylogenyNode>();
8555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8557             if ( s0.match( query_nodes ) ) {
8558                 return false;
8559             }
8560             //
8561             query_nodes = new HashSet<PhylogenyNode>();
8562             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8563             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8564             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8565             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8566             if ( s0.match( query_nodes ) ) {
8567                 return false;
8568             }
8569             //
8570             query_nodes = new HashSet<PhylogenyNode>();
8571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8572             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8573             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8574             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8575             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8576             if ( s0.match( query_nodes ) ) {
8577                 return false;
8578             }
8579             //
8580             query_nodes = new HashSet<PhylogenyNode>();
8581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8582             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8583             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8584             if ( s0.match( query_nodes ) ) {
8585                 return false;
8586             }
8587             //
8588             query_nodes = new HashSet<PhylogenyNode>();
8589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8590             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8591             if ( s0.match( query_nodes ) ) {
8592                 return false;
8593             }
8594             //
8595             query_nodes = new HashSet<PhylogenyNode>();
8596             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8597             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8598             if ( s0.match( query_nodes ) ) {
8599                 return false;
8600             }
8601             //
8602             query_nodes = new HashSet<PhylogenyNode>();
8603             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8604             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8605             if ( s0.match( query_nodes ) ) {
8606                 return false;
8607             }
8608             //
8609             query_nodes = new HashSet<PhylogenyNode>();
8610             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8611             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8612             if ( s0.match( query_nodes ) ) {
8613                 return false;
8614             }
8615             //
8616             query_nodes = new HashSet<PhylogenyNode>();
8617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8618             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8619             if ( s0.match( query_nodes ) ) {
8620                 return false;
8621             }
8622             //
8623             query_nodes = new HashSet<PhylogenyNode>();
8624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8626             if ( s0.match( query_nodes ) ) {
8627                 return false;
8628             }
8629             //
8630             query_nodes = new HashSet<PhylogenyNode>();
8631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8634             if ( s0.match( query_nodes ) ) {
8635                 return false;
8636             }
8637             //
8638             query_nodes = new HashSet<PhylogenyNode>();
8639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8641             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8642             if ( s0.match( query_nodes ) ) {
8643                 return false;
8644             }
8645             //
8646             query_nodes = new HashSet<PhylogenyNode>();
8647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8649             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8650             if ( s0.match( query_nodes ) ) {
8651                 return false;
8652             }
8653             //
8654             query_nodes = new HashSet<PhylogenyNode>();
8655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8657             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8658             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8659             if ( s0.match( query_nodes ) ) {
8660                 return false;
8661             }
8662             /////////
8663             //            query_nodes = new HashSet<PhylogenyNode>();
8664             //            query_nodes.add( new PhylogenyNode( "X" ) );
8665             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8666             //            query_nodes.add( new PhylogenyNode( "A" ) );
8667             //            query_nodes.add( new PhylogenyNode( "B" ) );
8668             //            query_nodes.add( new PhylogenyNode( "C" ) );
8669             //            query_nodes.add( new PhylogenyNode( "D" ) );
8670             //            query_nodes.add( new PhylogenyNode( "E" ) );
8671             //            query_nodes.add( new PhylogenyNode( "F" ) );
8672             //            query_nodes.add( new PhylogenyNode( "G" ) );
8673             //            if ( !s0.match( query_nodes ) ) {
8674             //                return false;
8675             //            }
8676             //            query_nodes = new HashSet<PhylogenyNode>();
8677             //            query_nodes.add( new PhylogenyNode( "X" ) );
8678             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8679             //            query_nodes.add( new PhylogenyNode( "A" ) );
8680             //            query_nodes.add( new PhylogenyNode( "B" ) );
8681             //            query_nodes.add( new PhylogenyNode( "C" ) );
8682             //            if ( !s0.match( query_nodes ) ) {
8683             //                return false;
8684             //            }
8685             //            //
8686             //            query_nodes = new HashSet<PhylogenyNode>();
8687             //            query_nodes.add( new PhylogenyNode( "X" ) );
8688             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8689             //            query_nodes.add( new PhylogenyNode( "D" ) );
8690             //            query_nodes.add( new PhylogenyNode( "E" ) );
8691             //            query_nodes.add( new PhylogenyNode( "F" ) );
8692             //            query_nodes.add( new PhylogenyNode( "G" ) );
8693             //            if ( !s0.match( query_nodes ) ) {
8694             //                return false;
8695             //            }
8696             //            //
8697             //            query_nodes = new HashSet<PhylogenyNode>();
8698             //            query_nodes.add( new PhylogenyNode( "X" ) );
8699             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8700             //            query_nodes.add( new PhylogenyNode( "A" ) );
8701             //            query_nodes.add( new PhylogenyNode( "B" ) );
8702             //            query_nodes.add( new PhylogenyNode( "C" ) );
8703             //            query_nodes.add( new PhylogenyNode( "D" ) );
8704             //            if ( !s0.match( query_nodes ) ) {
8705             //                return false;
8706             //            }
8707             //            //
8708             //            query_nodes = new HashSet<PhylogenyNode>();
8709             //            query_nodes.add( new PhylogenyNode( "X" ) );
8710             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8711             //            query_nodes.add( new PhylogenyNode( "E" ) );
8712             //            query_nodes.add( new PhylogenyNode( "F" ) );
8713             //            query_nodes.add( new PhylogenyNode( "G" ) );
8714             //            if ( !s0.match( query_nodes ) ) {
8715             //                return false;
8716             //            }
8717             //            //
8718             //            query_nodes = new HashSet<PhylogenyNode>();
8719             //            query_nodes.add( new PhylogenyNode( "X" ) );
8720             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8721             //            query_nodes.add( new PhylogenyNode( "F" ) );
8722             //            query_nodes.add( new PhylogenyNode( "G" ) );
8723             //            if ( !s0.match( query_nodes ) ) {
8724             //                return false;
8725             //            }
8726             //
8727             query_nodes = new HashSet<PhylogenyNode>();
8728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8732             if ( s0.match( query_nodes ) ) {
8733                 return false;
8734             }
8735             //
8736             query_nodes = new HashSet<PhylogenyNode>();
8737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8741             if ( s0.match( query_nodes ) ) {
8742                 return false;
8743             }
8744             ///////////////////////////
8745             //
8746             query_nodes = new HashSet<PhylogenyNode>();
8747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8751             if ( s0.match( query_nodes ) ) {
8752                 return false;
8753             }
8754             //
8755             query_nodes = new HashSet<PhylogenyNode>();
8756             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8759             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8760             if ( s0.match( query_nodes ) ) {
8761                 return false;
8762             }
8763             //
8764             query_nodes = new HashSet<PhylogenyNode>();
8765             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8766             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8767             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8768             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8769             if ( s0.match( query_nodes ) ) {
8770                 return false;
8771             }
8772             //
8773             query_nodes = new HashSet<PhylogenyNode>();
8774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8775             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8776             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8777             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8778             if ( s0.match( query_nodes ) ) {
8779                 return false;
8780             }
8781             //
8782             query_nodes = new HashSet<PhylogenyNode>();
8783             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8785             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8786             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8787             if ( s0.match( query_nodes ) ) {
8788                 return false;
8789             }
8790             //
8791             query_nodes = new HashSet<PhylogenyNode>();
8792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8793             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8794             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8795             if ( s0.match( query_nodes ) ) {
8796                 return false;
8797             }
8798             //
8799             query_nodes = new HashSet<PhylogenyNode>();
8800             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8801             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8802             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8803             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8805             if ( s0.match( query_nodes ) ) {
8806                 return false;
8807             }
8808             //
8809             query_nodes = new HashSet<PhylogenyNode>();
8810             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8811             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8815             if ( s0.match( query_nodes ) ) {
8816                 return false;
8817             }
8818             //
8819             query_nodes = new HashSet<PhylogenyNode>();
8820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8824             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8825             if ( s0.match( query_nodes ) ) {
8826                 return false;
8827             }
8828             //
8829             query_nodes = new HashSet<PhylogenyNode>();
8830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8833             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8834             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8835             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8836             if ( s0.match( query_nodes ) ) {
8837                 return false;
8838             }
8839         }
8840         catch ( final Exception e ) {
8841             e.printStackTrace();
8842             return false;
8843         }
8844         return true;
8845     }
8846
8847     private static boolean testSplitStrict() {
8848         try {
8849             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8850             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8851             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8852             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8853             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8854             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8855             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8856             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8857             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8858             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8859             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
8860             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8861             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8863             if ( s0.match( query_nodes ) ) {
8864                 return false;
8865             }
8866             query_nodes = new HashSet<PhylogenyNode>();
8867             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8874             if ( !s0.match( query_nodes ) ) {
8875                 return false;
8876             }
8877             //
8878             query_nodes = new HashSet<PhylogenyNode>();
8879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8882             if ( !s0.match( query_nodes ) ) {
8883                 return false;
8884             }
8885             //
8886             query_nodes = new HashSet<PhylogenyNode>();
8887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8891             if ( !s0.match( query_nodes ) ) {
8892                 return false;
8893             }
8894             //
8895             query_nodes = new HashSet<PhylogenyNode>();
8896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8900             if ( !s0.match( query_nodes ) ) {
8901                 return false;
8902             }
8903             //
8904             query_nodes = new HashSet<PhylogenyNode>();
8905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8908             if ( !s0.match( query_nodes ) ) {
8909                 return false;
8910             }
8911             //
8912             query_nodes = new HashSet<PhylogenyNode>();
8913             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8915             if ( !s0.match( query_nodes ) ) {
8916                 return false;
8917             }
8918             //
8919             query_nodes = new HashSet<PhylogenyNode>();
8920             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8921             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8925             if ( !s0.match( query_nodes ) ) {
8926                 return false;
8927             }
8928             //
8929             query_nodes = new HashSet<PhylogenyNode>();
8930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8931             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8932             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8933             if ( !s0.match( query_nodes ) ) {
8934                 return false;
8935             }
8936             //
8937             query_nodes = new HashSet<PhylogenyNode>();
8938             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8940             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8941             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8942             if ( !s0.match( query_nodes ) ) {
8943                 return false;
8944             }
8945             //
8946             query_nodes = new HashSet<PhylogenyNode>();
8947             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8949             if ( s0.match( query_nodes ) ) {
8950                 return false;
8951             }
8952             //
8953             query_nodes = new HashSet<PhylogenyNode>();
8954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8958             if ( s0.match( query_nodes ) ) {
8959                 return false;
8960             }
8961             //
8962             query_nodes = new HashSet<PhylogenyNode>();
8963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8968             if ( s0.match( query_nodes ) ) {
8969                 return false;
8970             }
8971             //
8972             query_nodes = new HashSet<PhylogenyNode>();
8973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8974             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8976             if ( s0.match( query_nodes ) ) {
8977                 return false;
8978             }
8979             //
8980             query_nodes = new HashSet<PhylogenyNode>();
8981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8983             if ( s0.match( query_nodes ) ) {
8984                 return false;
8985             }
8986             //
8987             query_nodes = new HashSet<PhylogenyNode>();
8988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8990             if ( s0.match( query_nodes ) ) {
8991                 return false;
8992             }
8993             //
8994             query_nodes = new HashSet<PhylogenyNode>();
8995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8997             if ( s0.match( query_nodes ) ) {
8998                 return false;
8999             }
9000             //
9001             query_nodes = new HashSet<PhylogenyNode>();
9002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9004             if ( s0.match( query_nodes ) ) {
9005                 return false;
9006             }
9007             //
9008             query_nodes = new HashSet<PhylogenyNode>();
9009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9011             if ( s0.match( query_nodes ) ) {
9012                 return false;
9013             }
9014             //
9015             query_nodes = new HashSet<PhylogenyNode>();
9016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9018             if ( s0.match( query_nodes ) ) {
9019                 return false;
9020             }
9021             //
9022             query_nodes = new HashSet<PhylogenyNode>();
9023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9024             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9025             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9026             if ( s0.match( query_nodes ) ) {
9027                 return false;
9028             }
9029             //
9030             query_nodes = new HashSet<PhylogenyNode>();
9031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9033             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9034             if ( s0.match( query_nodes ) ) {
9035                 return false;
9036             }
9037             //
9038             query_nodes = new HashSet<PhylogenyNode>();
9039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9041             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9042             if ( s0.match( query_nodes ) ) {
9043                 return false;
9044             }
9045             //
9046             query_nodes = new HashSet<PhylogenyNode>();
9047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9050             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9051             if ( s0.match( query_nodes ) ) {
9052                 return false;
9053             }
9054         }
9055         catch ( final Exception e ) {
9056             e.printStackTrace();
9057             return false;
9058         }
9059         return true;
9060     }
9061
9062     private static boolean testSubtreeDeletion() {
9063         try {
9064             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9065             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9066             t1.deleteSubtree( t1.getNode( "A" ), false );
9067             if ( t1.getNumberOfExternalNodes() != 5 ) {
9068                 return false;
9069             }
9070             t1.toNewHampshireX();
9071             t1.deleteSubtree( t1.getNode( "E" ), false );
9072             if ( t1.getNumberOfExternalNodes() != 4 ) {
9073                 return false;
9074             }
9075             t1.toNewHampshireX();
9076             t1.deleteSubtree( t1.getNode( "F" ), false );
9077             if ( t1.getNumberOfExternalNodes() != 3 ) {
9078                 return false;
9079             }
9080             t1.toNewHampshireX();
9081             t1.deleteSubtree( t1.getNode( "D" ), false );
9082             t1.toNewHampshireX();
9083             if ( t1.getNumberOfExternalNodes() != 3 ) {
9084                 return false;
9085             }
9086             t1.deleteSubtree( t1.getNode( "def" ), false );
9087             t1.toNewHampshireX();
9088             if ( t1.getNumberOfExternalNodes() != 2 ) {
9089                 return false;
9090             }
9091             t1.deleteSubtree( t1.getNode( "B" ), false );
9092             t1.toNewHampshireX();
9093             if ( t1.getNumberOfExternalNodes() != 1 ) {
9094                 return false;
9095             }
9096             t1.deleteSubtree( t1.getNode( "C" ), false );
9097             t1.toNewHampshireX();
9098             if ( t1.getNumberOfExternalNodes() != 1 ) {
9099                 return false;
9100             }
9101             t1.deleteSubtree( t1.getNode( "abc" ), false );
9102             t1.toNewHampshireX();
9103             if ( t1.getNumberOfExternalNodes() != 1 ) {
9104                 return false;
9105             }
9106             t1.deleteSubtree( t1.getNode( "r" ), false );
9107             if ( t1.getNumberOfExternalNodes() != 0 ) {
9108                 return false;
9109             }
9110             if ( !t1.isEmpty() ) {
9111                 return false;
9112             }
9113             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9114             t2.deleteSubtree( t2.getNode( "A" ), false );
9115             t2.toNewHampshireX();
9116             if ( t2.getNumberOfExternalNodes() != 5 ) {
9117                 return false;
9118             }
9119             t2.deleteSubtree( t2.getNode( "abc" ), false );
9120             t2.toNewHampshireX();
9121             if ( t2.getNumberOfExternalNodes() != 3 ) {
9122                 return false;
9123             }
9124             t2.deleteSubtree( t2.getNode( "def" ), false );
9125             t2.toNewHampshireX();
9126             if ( t2.getNumberOfExternalNodes() != 1 ) {
9127                 return false;
9128             }
9129         }
9130         catch ( final Exception e ) {
9131             e.printStackTrace( System.out );
9132             return false;
9133         }
9134         return true;
9135     }
9136
9137     private static boolean testSupportCount() {
9138         try {
9139             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9140             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
9141             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
9142                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
9143                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
9144                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
9145                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
9146                                                               new NHXParser() );
9147             SupportCount.count( t0_1, phylogenies_1, true, false );
9148             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
9149             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
9150                                                                       + "(((((A,B),C),D),E),((F,G),X))"
9151                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
9152                                                                       + "(((((A,B),C),D),E),(F,G))"
9153                                                                       + "(((((A,B),C),D),E),(F,G))"
9154                                                                       + "(((((A,B),C),D),E),(F,G))"
9155                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
9156                                                                       + "(((((A,B),C),D),E),(F,G))"
9157                                                                       + "((((((A,B),C),D),E),F),G)"
9158                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
9159                                                               new NHXParser() );
9160             SupportCount.count( t0_2, phylogenies_2, true, false );
9161             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
9162             while ( it.hasNext() ) {
9163                 final PhylogenyNode n = it.next();
9164                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
9165                     return false;
9166                 }
9167             }
9168             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
9169             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
9170                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
9171             SupportCount.count( t0_3, phylogenies_3, true, false );
9172             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
9173             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
9174                 return false;
9175             }
9176             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
9177                 return false;
9178             }
9179             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
9180                 return false;
9181             }
9182             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
9183                 return false;
9184             }
9185             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
9186                 return false;
9187             }
9188             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
9189                 return false;
9190             }
9191             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
9192                 return false;
9193             }
9194             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
9195                 return false;
9196             }
9197             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
9198                 return false;
9199             }
9200             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
9201                 return false;
9202             }
9203             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9204             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
9205                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
9206             SupportCount.count( t0_4, phylogenies_4, true, false );
9207             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
9208             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
9209                 return false;
9210             }
9211             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
9212                 return false;
9213             }
9214             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
9215                 return false;
9216             }
9217             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
9218                 return false;
9219             }
9220             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
9221                 return false;
9222             }
9223             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
9224                 return false;
9225             }
9226             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
9227                 return false;
9228             }
9229             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
9230                 return false;
9231             }
9232             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
9233                 return false;
9234             }
9235             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
9236                 return false;
9237             }
9238             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9239             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9240             double d = SupportCount.compare( b1, a, true, true, true );
9241             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
9242                 return false;
9243             }
9244             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9245             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9246             d = SupportCount.compare( b2, a, true, true, true );
9247             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
9248                 return false;
9249             }
9250             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9251             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
9252             d = SupportCount.compare( b3, a, true, true, true );
9253             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
9254                 return false;
9255             }
9256             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
9257             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
9258             d = SupportCount.compare( b4, a, true, true, false );
9259             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
9260                 return false;
9261             }
9262         }
9263         catch ( final Exception e ) {
9264             e.printStackTrace( System.out );
9265             return false;
9266         }
9267         return true;
9268     }
9269
9270     private static boolean testSupportTransfer() {
9271         try {
9272             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9273             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)",
9274                                                  new NHXParser() )[ 0 ];
9275             final Phylogeny p2 = factory
9276                     .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 ];
9277             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
9278                 return false;
9279             }
9280             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
9281                 return false;
9282             }
9283             support_transfer.moveBranchLengthsToBootstrap( p1 );
9284             support_transfer.transferSupportValues( p1, p2 );
9285             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
9286                 return false;
9287             }
9288             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
9289                 return false;
9290             }
9291             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
9292                 return false;
9293             }
9294             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
9295                 return false;
9296             }
9297             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
9298                 return false;
9299             }
9300             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
9301                 return false;
9302             }
9303             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
9304                 return false;
9305             }
9306             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
9307                 return false;
9308             }
9309         }
9310         catch ( final Exception e ) {
9311             e.printStackTrace( System.out );
9312             return false;
9313         }
9314         return true;
9315     }
9316
9317     private static boolean testUniprotTaxonomySearch() {
9318         try {
9319             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
9320                                                                                                  10 );
9321             if ( results.size() != 1 ) {
9322                 return false;
9323             }
9324             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9325                 return false;
9326             }
9327             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9328                 return false;
9329             }
9330             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9331                 return false;
9332             }
9333             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9334                 return false;
9335             }
9336             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9337                 return false;
9338             }
9339             results = null;
9340             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
9341             if ( results.size() != 1 ) {
9342                 return false;
9343             }
9344             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9345                 return false;
9346             }
9347             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9348                 return false;
9349             }
9350             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9351                 return false;
9352             }
9353             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9354                 return false;
9355             }
9356             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9357                 return false;
9358             }
9359             results = null;
9360             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
9361             if ( results.size() != 1 ) {
9362                 return false;
9363             }
9364             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9365                 return false;
9366             }
9367             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9368                 return false;
9369             }
9370             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9371                 return false;
9372             }
9373             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9374                 return false;
9375             }
9376             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9377                 return false;
9378             }
9379             results = null;
9380             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
9381             if ( results.size() != 1 ) {
9382                 return false;
9383             }
9384             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9385                 return false;
9386             }
9387             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9388                 return false;
9389             }
9390             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9391                 return false;
9392             }
9393             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9394                 return false;
9395             }
9396             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9397                 return false;
9398             }
9399             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
9400                 return false;
9401             }
9402             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
9403                 return false;
9404             }
9405             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
9406                     .equals( "Nematostella vectensis" ) ) {
9407                 System.out.println( results.get( 0 ).getLineage() );
9408                 return false;
9409             }
9410         }
9411         catch ( final IOException e ) {
9412             System.out.println();
9413             System.out.println( "the following might be due to absence internet connection:" );
9414             e.printStackTrace( System.out );
9415             return true;
9416         }
9417         catch ( final Exception e ) {
9418             return false;
9419         }
9420         return true;
9421     }
9422
9423     private static boolean testEmblEntryRetrieval() {
9424         //The format for GenBank Accession numbers are:
9425         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
9426         //Protein:    3 letters + 5 numerals
9427         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
9428         if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
9429             return false;
9430         }
9431         if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861.2" ).equals( "AY423861.2" ) ) {
9432             return false;
9433         }
9434         if ( !SequenceIdParser.parseGenbankAccessor( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
9435             return false;
9436         }
9437         if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
9438             return false;
9439         }
9440         if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
9441             return false;
9442         }
9443         if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
9444             return false;
9445         }
9446         if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
9447             return false;
9448         }
9449         if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
9450             return false;
9451         }
9452         if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
9453             return false;
9454         }
9455         if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
9456             return false;
9457         }
9458         if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
9459             return false;
9460         }
9461         if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
9462             return false;
9463         }
9464         if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
9465             return false;
9466         }
9467         if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
9468             return false;
9469         }
9470         return true;
9471     }
9472
9473     private static boolean testUniprotEntryRetrieval() {
9474         try {
9475             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
9476             if ( !entry.getAccession().equals( "P12345" ) ) {
9477                 return false;
9478             }
9479             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
9480                 return false;
9481             }
9482             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
9483                 return false;
9484             }
9485             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
9486                 return false;
9487             }
9488         }
9489         catch ( final IOException e ) {
9490             System.out.println();
9491             System.out.println( "the following might be due to absence internet connection:" );
9492             e.printStackTrace( System.out );
9493             return true;
9494         }
9495         catch ( final Exception e ) {
9496             return false;
9497         }
9498         return true;
9499     }
9500
9501     private static boolean testWabiTxSearch() {
9502         try {
9503             String result = "";
9504             result = TxSearch.searchSimple( "nematostella" );
9505             result = TxSearch.getTxId( "nematostella" );
9506             if ( !result.equals( "45350" ) ) {
9507                 return false;
9508             }
9509             result = TxSearch.getTxName( "45350" );
9510             if ( !result.equals( "Nematostella" ) ) {
9511                 return false;
9512             }
9513             result = TxSearch.getTxId( "nematostella vectensis" );
9514             if ( !result.equals( "45351" ) ) {
9515                 return false;
9516             }
9517             result = TxSearch.getTxName( "45351" );
9518             if ( !result.equals( "Nematostella vectensis" ) ) {
9519                 return false;
9520             }
9521             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
9522             if ( !result.equals( "536089" ) ) {
9523                 return false;
9524             }
9525             result = TxSearch.getTxName( "536089" );
9526             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
9527                 return false;
9528             }
9529             final List<String> queries = new ArrayList<String>();
9530             queries.add( "Campylobacter coli" );
9531             queries.add( "Escherichia coli" );
9532             queries.add( "Arabidopsis" );
9533             queries.add( "Trichoplax" );
9534             queries.add( "Samanea saman" );
9535             queries.add( "Kluyveromyces marxianus" );
9536             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
9537             queries.add( "Bornavirus parrot/PDD/2008" );
9538             final List<RANKS> ranks = new ArrayList<RANKS>();
9539             ranks.add( RANKS.SUPERKINGDOM );
9540             ranks.add( RANKS.KINGDOM );
9541             ranks.add( RANKS.FAMILY );
9542             ranks.add( RANKS.GENUS );
9543             ranks.add( RANKS.TRIBE );
9544             result = TxSearch.searchLineage( queries, ranks );
9545             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
9546             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
9547         }
9548         catch ( final Exception e ) {
9549             System.out.println();
9550             System.out.println( "the following might be due to absence internet connection:" );
9551             e.printStackTrace( System.out );
9552             return false;
9553         }
9554         return true;
9555     }
9556
9557     private static boolean testAminoAcidSequence() {
9558         try {
9559             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
9560             if ( aa1.getLength() != 13 ) {
9561                 return false;
9562             }
9563             if ( aa1.getResidueAt( 0 ) != 'A' ) {
9564                 return false;
9565             }
9566             if ( aa1.getResidueAt( 2 ) != 'K' ) {
9567                 return false;
9568             }
9569             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
9570                 return false;
9571             }
9572             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
9573             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
9574                 return false;
9575             }
9576             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
9577             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
9578                 return false;
9579             }
9580             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
9581             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
9582                 return false;
9583             }
9584         }
9585         catch ( final Exception e ) {
9586             e.printStackTrace();
9587             return false;
9588         }
9589         return true;
9590     }
9591
9592     private static boolean testSequenceWriter() {
9593         try {
9594             final String n = ForesterUtil.LINE_SEPARATOR;
9595             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9596                 return false;
9597             }
9598             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9599                 return false;
9600             }
9601             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9602                 return false;
9603             }
9604             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9605                 return false;
9606             }
9607             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9608                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9609                 return false;
9610             }
9611             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9612                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9613                 return false;
9614             }
9615         }
9616         catch ( final Exception e ) {
9617             e.printStackTrace();
9618             return false;
9619         }
9620         return true;
9621     }
9622
9623     private static boolean testCreateBalancedPhylogeny() {
9624         try {
9625             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
9626             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
9627                 return false;
9628             }
9629             if ( p0.getNumberOfExternalNodes() != 15625 ) {
9630                 return false;
9631             }
9632             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
9633             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
9634                 return false;
9635             }
9636             if ( p1.getNumberOfExternalNodes() != 100 ) {
9637                 return false;
9638             }
9639         }
9640         catch ( final Exception e ) {
9641             e.printStackTrace();
9642             return false;
9643         }
9644         return true;
9645     }
9646
9647     private static boolean testFastaParser() {
9648         try {
9649             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
9650                 return false;
9651             }
9652             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
9653                 return false;
9654             }
9655             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
9656             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
9657                 return false;
9658             }
9659             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
9660                 return false;
9661             }
9662             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
9663                 return false;
9664             }
9665             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
9666                 return false;
9667             }
9668             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
9669                 return false;
9670             }
9671             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
9672                 return false;
9673             }
9674         }
9675         catch ( final Exception e ) {
9676             e.printStackTrace();
9677             return false;
9678         }
9679         return true;
9680     }
9681
9682     private static boolean testGeneralMsaParser() {
9683         try {
9684             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
9685             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
9686             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
9687             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
9688             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
9689             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
9690             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
9691             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
9692             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9693                 return false;
9694             }
9695             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9696                 return false;
9697             }
9698             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9699                 return false;
9700             }
9701             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9702                 return false;
9703             }
9704             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9705                 return false;
9706             }
9707             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9708                 return false;
9709             }
9710             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9711                 return false;
9712             }
9713             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9714                 return false;
9715             }
9716             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9717                 return false;
9718             }
9719             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9720                 return false;
9721             }
9722             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9723                 return false;
9724             }
9725             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9726                 return false;
9727             }
9728             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
9729             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9730                 return false;
9731             }
9732             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9733                 return false;
9734             }
9735             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9736                 return false;
9737             }
9738             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
9739             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
9740                 return false;
9741             }
9742             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
9743                 return false;
9744             }
9745             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
9746                 return false;
9747             }
9748             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
9749             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9750                 return false;
9751             }
9752             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9753                 return false;
9754             }
9755             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9756                 return false;
9757             }
9758         }
9759         catch ( final Exception e ) {
9760             e.printStackTrace();
9761             return false;
9762         }
9763         return true;
9764     }
9765
9766     private static boolean testMafft( final String path ) {
9767         try {
9768             final List<String> opts = new ArrayList<String>();
9769             opts.add( "--maxiterate" );
9770             opts.add( "1000" );
9771             opts.add( "--localpair" );
9772             opts.add( "--quiet" );
9773             Msa msa = null;
9774             final MsaInferrer mafft = Mafft.createInstance( path );
9775             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
9776             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
9777                 return false;
9778             }
9779             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
9780                 return false;
9781             }
9782         }
9783         catch ( final Exception e ) {
9784             e.printStackTrace( System.out );
9785             return false;
9786         }
9787         return true;
9788     }
9789
9790     private static boolean testNextNodeWithCollapsing() {
9791         try {
9792             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9793             PhylogenyNode n;
9794             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
9795             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9796             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
9797             t0.getNode( "cd" ).setCollapse( true );
9798             t0.getNode( "cde" ).setCollapse( true );
9799             n = t0.getFirstExternalNode();
9800             while ( n != null ) {
9801                 ext.add( n );
9802                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9803             }
9804             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9805                 return false;
9806             }
9807             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9808                 return false;
9809             }
9810             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
9811                 return false;
9812             }
9813             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
9814                 return false;
9815             }
9816             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
9817                 return false;
9818             }
9819             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
9820                 return false;
9821             }
9822             ext.clear();
9823             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9824             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
9825             t1.getNode( "ab" ).setCollapse( true );
9826             t1.getNode( "cd" ).setCollapse( true );
9827             t1.getNode( "cde" ).setCollapse( true );
9828             n = t1.getNode( "ab" );
9829             ext = new ArrayList<PhylogenyNode>();
9830             while ( n != null ) {
9831                 ext.add( n );
9832                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9833             }
9834             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9835                 return false;
9836             }
9837             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9838                 return false;
9839             }
9840             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9841                 return false;
9842             }
9843             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
9844                 return false;
9845             }
9846             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
9847                 return false;
9848             }
9849             //
9850             //
9851             ext.clear();
9852             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9853             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
9854             t2.getNode( "ab" ).setCollapse( true );
9855             t2.getNode( "cd" ).setCollapse( true );
9856             t2.getNode( "cde" ).setCollapse( true );
9857             t2.getNode( "c" ).setCollapse( true );
9858             t2.getNode( "d" ).setCollapse( true );
9859             t2.getNode( "e" ).setCollapse( true );
9860             t2.getNode( "gh" ).setCollapse( true );
9861             n = t2.getNode( "ab" );
9862             ext = new ArrayList<PhylogenyNode>();
9863             while ( n != null ) {
9864                 ext.add( n );
9865                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9866             }
9867             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9868                 return false;
9869             }
9870             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9871                 return false;
9872             }
9873             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9874                 return false;
9875             }
9876             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
9877                 return false;
9878             }
9879             //
9880             //
9881             ext.clear();
9882             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9883             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
9884             t3.getNode( "ab" ).setCollapse( true );
9885             t3.getNode( "cd" ).setCollapse( true );
9886             t3.getNode( "cde" ).setCollapse( true );
9887             t3.getNode( "c" ).setCollapse( true );
9888             t3.getNode( "d" ).setCollapse( true );
9889             t3.getNode( "e" ).setCollapse( true );
9890             t3.getNode( "gh" ).setCollapse( true );
9891             t3.getNode( "fgh" ).setCollapse( true );
9892             n = t3.getNode( "ab" );
9893             ext = new ArrayList<PhylogenyNode>();
9894             while ( n != null ) {
9895                 ext.add( n );
9896                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9897             }
9898             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9899                 return false;
9900             }
9901             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9902                 return false;
9903             }
9904             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
9905                 return false;
9906             }
9907             //
9908             //
9909             ext.clear();
9910             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9911             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
9912             t4.getNode( "ab" ).setCollapse( true );
9913             t4.getNode( "cd" ).setCollapse( true );
9914             t4.getNode( "cde" ).setCollapse( true );
9915             t4.getNode( "c" ).setCollapse( true );
9916             t4.getNode( "d" ).setCollapse( true );
9917             t4.getNode( "e" ).setCollapse( true );
9918             t4.getNode( "gh" ).setCollapse( true );
9919             t4.getNode( "fgh" ).setCollapse( true );
9920             t4.getNode( "abcdefgh" ).setCollapse( true );
9921             n = t4.getNode( "abcdefgh" );
9922             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
9923                 return false;
9924             }
9925             //
9926             //
9927             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9928             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
9929             ext.clear();
9930             n = t5.getFirstExternalNode();
9931             while ( n != null ) {
9932                 ext.add( n );
9933                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9934             }
9935             if ( ext.size() != 8 ) {
9936                 return false;
9937             }
9938             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9939                 return false;
9940             }
9941             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9942                 return false;
9943             }
9944             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
9945                 return false;
9946             }
9947             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
9948                 return false;
9949             }
9950             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
9951                 return false;
9952             }
9953             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
9954                 return false;
9955             }
9956             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
9957                 return false;
9958             }
9959             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
9960                 return false;
9961             }
9962             //
9963             //
9964             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9965             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
9966             ext.clear();
9967             t6.getNode( "ab" ).setCollapse( true );
9968             n = t6.getNode( "ab" );
9969             while ( n != null ) {
9970                 ext.add( n );
9971                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9972             }
9973             if ( ext.size() != 7 ) {
9974                 return false;
9975             }
9976             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9977                 return false;
9978             }
9979             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
9980                 return false;
9981             }
9982             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
9983                 return false;
9984             }
9985             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9986                 return false;
9987             }
9988             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9989                 return false;
9990             }
9991             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9992                 return false;
9993             }
9994             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9995                 return false;
9996             }
9997             //
9998             //
9999             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
10000             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
10001             ext.clear();
10002             t7.getNode( "cd" ).setCollapse( true );
10003             n = t7.getNode( "a" );
10004             while ( n != null ) {
10005                 ext.add( n );
10006                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10007             }
10008             if ( ext.size() != 7 ) {
10009                 return false;
10010             }
10011             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10012                 return false;
10013             }
10014             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10015                 return false;
10016             }
10017             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10018                 return false;
10019             }
10020             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10021                 return false;
10022             }
10023             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10024                 return false;
10025             }
10026             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10027                 return false;
10028             }
10029             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10030                 return false;
10031             }
10032             //
10033             //
10034             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
10035             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
10036             ext.clear();
10037             t8.getNode( "cd" ).setCollapse( true );
10038             t8.getNode( "c" ).setCollapse( true );
10039             t8.getNode( "d" ).setCollapse( true );
10040             n = t8.getNode( "a" );
10041             while ( n != null ) {
10042                 ext.add( n );
10043                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10044             }
10045             if ( ext.size() != 7 ) {
10046                 return false;
10047             }
10048             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10049                 return false;
10050             }
10051             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10052                 return false;
10053             }
10054             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10055                 System.out.println( "2 fail" );
10056                 return false;
10057             }
10058             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10059                 return false;
10060             }
10061             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10062                 return false;
10063             }
10064             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10065                 return false;
10066             }
10067             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10068                 return false;
10069             }
10070             //
10071             //
10072             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10073             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
10074             ext.clear();
10075             t9.getNode( "gh" ).setCollapse( true );
10076             n = t9.getNode( "a" );
10077             while ( n != null ) {
10078                 ext.add( n );
10079                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10080             }
10081             if ( ext.size() != 7 ) {
10082                 return false;
10083             }
10084             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10085                 return false;
10086             }
10087             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10088                 return false;
10089             }
10090             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10091                 return false;
10092             }
10093             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10094                 return false;
10095             }
10096             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10097                 return false;
10098             }
10099             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10100                 return false;
10101             }
10102             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10103                 return false;
10104             }
10105             //
10106             //
10107             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10108             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
10109             ext.clear();
10110             t10.getNode( "gh" ).setCollapse( true );
10111             t10.getNode( "g" ).setCollapse( true );
10112             t10.getNode( "h" ).setCollapse( true );
10113             n = t10.getNode( "a" );
10114             while ( n != null ) {
10115                 ext.add( n );
10116                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10117             }
10118             if ( ext.size() != 7 ) {
10119                 return false;
10120             }
10121             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10122                 return false;
10123             }
10124             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10125                 return false;
10126             }
10127             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10128                 return false;
10129             }
10130             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10131                 return false;
10132             }
10133             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10134                 return false;
10135             }
10136             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10137                 return false;
10138             }
10139             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10140                 return false;
10141             }
10142             //
10143             //
10144             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10145             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
10146             ext.clear();
10147             t11.getNode( "gh" ).setCollapse( true );
10148             t11.getNode( "fgh" ).setCollapse( true );
10149             n = t11.getNode( "a" );
10150             while ( n != null ) {
10151                 ext.add( n );
10152                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10153             }
10154             if ( ext.size() != 6 ) {
10155                 return false;
10156             }
10157             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10158                 return false;
10159             }
10160             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10161                 return false;
10162             }
10163             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10164                 return false;
10165             }
10166             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10167                 return false;
10168             }
10169             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10170                 return false;
10171             }
10172             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10173                 return false;
10174             }
10175             //
10176             //
10177             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10178             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
10179             ext.clear();
10180             t12.getNode( "gh" ).setCollapse( true );
10181             t12.getNode( "fgh" ).setCollapse( true );
10182             t12.getNode( "g" ).setCollapse( true );
10183             t12.getNode( "h" ).setCollapse( true );
10184             t12.getNode( "f" ).setCollapse( true );
10185             n = t12.getNode( "a" );
10186             while ( n != null ) {
10187                 ext.add( n );
10188                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10189             }
10190             if ( ext.size() != 6 ) {
10191                 return false;
10192             }
10193             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10194                 return false;
10195             }
10196             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10197                 return false;
10198             }
10199             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10200                 return false;
10201             }
10202             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10203                 return false;
10204             }
10205             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10206                 return false;
10207             }
10208             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10209                 return false;
10210             }
10211             //
10212             //
10213             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10214             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
10215             ext.clear();
10216             t13.getNode( "ab" ).setCollapse( true );
10217             t13.getNode( "b" ).setCollapse( true );
10218             t13.getNode( "fgh" ).setCollapse( true );
10219             t13.getNode( "gh" ).setCollapse( true );
10220             n = t13.getNode( "ab" );
10221             while ( n != null ) {
10222                 ext.add( n );
10223                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10224             }
10225             if ( ext.size() != 5 ) {
10226                 return false;
10227             }
10228             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10229                 return false;
10230             }
10231             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10232                 return false;
10233             }
10234             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10235                 return false;
10236             }
10237             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10238                 return false;
10239             }
10240             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10241                 return false;
10242             }
10243             //
10244             //
10245             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
10246             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
10247             ext.clear();
10248             t14.getNode( "ab" ).setCollapse( true );
10249             t14.getNode( "a" ).setCollapse( true );
10250             t14.getNode( "fgh" ).setCollapse( true );
10251             t14.getNode( "gh" ).setCollapse( true );
10252             n = t14.getNode( "ab" );
10253             while ( n != null ) {
10254                 ext.add( n );
10255                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10256             }
10257             if ( ext.size() != 5 ) {
10258                 return false;
10259             }
10260             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10261                 return false;
10262             }
10263             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10264                 return false;
10265             }
10266             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10267                 return false;
10268             }
10269             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10270                 return false;
10271             }
10272             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10273                 return false;
10274             }
10275             //
10276             //
10277             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" );
10278             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
10279             ext.clear();
10280             t15.getNode( "ab" ).setCollapse( true );
10281             t15.getNode( "a" ).setCollapse( true );
10282             t15.getNode( "fgh" ).setCollapse( true );
10283             t15.getNode( "gh" ).setCollapse( true );
10284             n = t15.getNode( "ab" );
10285             while ( n != null ) {
10286                 ext.add( n );
10287                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10288             }
10289             if ( ext.size() != 6 ) {
10290                 return false;
10291             }
10292             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10293                 return false;
10294             }
10295             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10296                 return false;
10297             }
10298             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10299                 return false;
10300             }
10301             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10302                 return false;
10303             }
10304             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
10305                 return false;
10306             }
10307             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10308                 return false;
10309             }
10310             //
10311             //
10312             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" );
10313             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
10314             ext.clear();
10315             t16.getNode( "ab" ).setCollapse( true );
10316             t16.getNode( "a" ).setCollapse( true );
10317             t16.getNode( "fgh" ).setCollapse( true );
10318             t16.getNode( "gh" ).setCollapse( true );
10319             t16.getNode( "cd" ).setCollapse( true );
10320             t16.getNode( "cde" ).setCollapse( true );
10321             t16.getNode( "d" ).setCollapse( true );
10322             t16.getNode( "x" ).setCollapse( true );
10323             n = t16.getNode( "ab" );
10324             while ( n != null ) {
10325                 ext.add( n );
10326                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10327             }
10328             if ( ext.size() != 4 ) {
10329                 return false;
10330             }
10331             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10332                 return false;
10333             }
10334             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
10335                 return false;
10336             }
10337             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
10338                 return false;
10339             }
10340             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
10341                 return false;
10342             }
10343         }
10344         catch ( final Exception e ) {
10345             e.printStackTrace( System.out );
10346             return false;
10347         }
10348         return true;
10349     }
10350
10351     private static boolean testMsaQualityMethod() {
10352         try {
10353             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
10354             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
10355             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
10356             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
10357             final List<Sequence> l = new ArrayList<Sequence>();
10358             l.add( s0 );
10359             l.add( s1 );
10360             l.add( s2 );
10361             l.add( s3 );
10362             final Msa msa = BasicMsa.createInstance( l );
10363             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
10364                 return false;
10365             }
10366             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
10367                 return false;
10368             }
10369             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
10370                 return false;
10371             }
10372             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
10373                 return false;
10374             }
10375         }
10376         catch ( final Exception e ) {
10377             e.printStackTrace( System.out );
10378             return false;
10379         }
10380         return true;
10381     }
10382
10383     private static boolean testSequenceIdParsing() {
10384         try {
10385             Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
10386             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10387                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10388                 if ( id != null ) {
10389                     System.out.println( "value   =" + id.getValue() );
10390                     System.out.println( "provider=" + id.getProvider() );
10391                 }
10392                 return false;
10393             }
10394             //
10395             id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
10396             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10397                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10398                 if ( id != null ) {
10399                     System.out.println( "value   =" + id.getValue() );
10400                     System.out.println( "provider=" + id.getProvider() );
10401                 }
10402                 return false;
10403             }
10404             //
10405             id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
10406             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10407                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10408                 if ( id != null ) {
10409                     System.out.println( "value   =" + id.getValue() );
10410                     System.out.println( "provider=" + id.getProvider() );
10411                 }
10412                 return false;
10413             }
10414             // 
10415             id = SequenceIdParser.parse( "gb_AAA96518_1" );
10416             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10417                     || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
10418                 if ( id != null ) {
10419                     System.out.println( "value   =" + id.getValue() );
10420                     System.out.println( "provider=" + id.getProvider() );
10421                 }
10422                 return false;
10423             }
10424             // 
10425             id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
10426             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10427                     || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
10428                 if ( id != null ) {
10429                     System.out.println( "value   =" + id.getValue() );
10430                     System.out.println( "provider=" + id.getProvider() );
10431                 }
10432                 return false;
10433             }
10434             // 
10435             id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
10436             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10437                     || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
10438                 if ( id != null ) {
10439                     System.out.println( "value   =" + id.getValue() );
10440                     System.out.println( "provider=" + id.getProvider() );
10441                 }
10442                 return false;
10443             }
10444             // 
10445             id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
10446             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10447                     || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
10448                 if ( id != null ) {
10449                     System.out.println( "value   =" + id.getValue() );
10450                     System.out.println( "provider=" + id.getProvider() );
10451                 }
10452                 return false;
10453             }
10454             // 
10455             id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
10456             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10457                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10458                 if ( id != null ) {
10459                     System.out.println( "value   =" + id.getValue() );
10460                     System.out.println( "provider=" + id.getProvider() );
10461                 }
10462                 return false;
10463             }
10464             // 
10465             id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
10466             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10467                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10468                 if ( id != null ) {
10469                     System.out.println( "value   =" + id.getValue() );
10470                     System.out.println( "provider=" + id.getProvider() );
10471                 }
10472                 return false;
10473             }
10474             // 
10475             id = SequenceIdParser.parse( "P4A123" );
10476             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10477                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10478                 if ( id != null ) {
10479                     System.out.println( "value   =" + id.getValue() );
10480                     System.out.println( "provider=" + id.getProvider() );
10481                 }
10482                 return false;
10483             }
10484             // 
10485             id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
10486             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10487                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10488                 if ( id != null ) {
10489                     System.out.println( "value   =" + id.getValue() );
10490                     System.out.println( "provider=" + id.getProvider() );
10491                 }
10492                 return false;
10493             }
10494             // 
10495             id = SequenceIdParser.parse( "XP_12345" );
10496             if ( id != null ) {
10497                 System.out.println( "value   =" + id.getValue() );
10498                 System.out.println( "provider=" + id.getProvider() );
10499                 return false;
10500             }
10501             // lcl_91970_unknown_
10502         }
10503         catch ( final Exception e ) {
10504             e.printStackTrace( System.out );
10505             return false;
10506         }
10507         return true;
10508     }
10509 }