c13523c39aa3c85341c76dce9d6907623051d51f
[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.msa.BasicMsa;
61 import org.forester.msa.Mafft;
62 import org.forester.msa.Msa;
63 import org.forester.msa.MsaInferrer;
64 import org.forester.msa.MsaMethods;
65 import org.forester.pccx.TestPccx;
66 import org.forester.phylogeny.Phylogeny;
67 import org.forester.phylogeny.PhylogenyBranch;
68 import org.forester.phylogeny.PhylogenyMethods;
69 import org.forester.phylogeny.PhylogenyNode;
70 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
71 import org.forester.phylogeny.data.Accession;
72 import org.forester.phylogeny.data.BinaryCharacters;
73 import org.forester.phylogeny.data.BranchWidth;
74 import org.forester.phylogeny.data.Confidence;
75 import org.forester.phylogeny.data.Distribution;
76 import org.forester.phylogeny.data.DomainArchitecture;
77 import org.forester.phylogeny.data.Event;
78 import org.forester.phylogeny.data.Identifier;
79 import org.forester.phylogeny.data.PhylogenyData;
80 import org.forester.phylogeny.data.PhylogenyDataUtil;
81 import org.forester.phylogeny.data.Polygon;
82 import org.forester.phylogeny.data.PropertiesMap;
83 import org.forester.phylogeny.data.Property;
84 import org.forester.phylogeny.data.Property.AppliesTo;
85 import org.forester.phylogeny.data.ProteinDomain;
86 import org.forester.phylogeny.data.Taxonomy;
87 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
88 import org.forester.phylogeny.factories.PhylogenyFactory;
89 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
90 import org.forester.protein.Protein;
91 import org.forester.rio.TestRIO;
92 import org.forester.sdi.SDI;
93 import org.forester.sdi.SDIR;
94 import org.forester.sdi.TestGSDI;
95 import org.forester.sequence.BasicSequence;
96 import org.forester.sequence.Sequence;
97 import org.forester.surfacing.TestSurfacing;
98 import org.forester.tools.ConfidenceAssessor;
99 import org.forester.tools.SupportCount;
100 import org.forester.tools.TreeSplitMatrix;
101 import org.forester.util.AsciiHistogram;
102 import org.forester.util.BasicDescriptiveStatistics;
103 import org.forester.util.BasicTable;
104 import org.forester.util.BasicTableParser;
105 import org.forester.util.DescriptiveStatistics;
106 import org.forester.util.ForesterConstants;
107 import org.forester.util.ForesterUtil;
108 import org.forester.util.GeneralTable;
109 import org.forester.util.SequenceIdParser;
110 import org.forester.ws.seqdb.SequenceDatabaseEntry;
111 import org.forester.ws.seqdb.SequenceDbWsTools;
112 import org.forester.ws.seqdb.UniProtTaxonomy;
113 import org.forester.ws.wabi.TxSearch;
114 import org.forester.ws.wabi.TxSearch.RANKS;
115 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
116 import org.forester.ws.wabi.TxSearch.TAX_RANK;
117
118 @SuppressWarnings( "unused")
119 public final class Test {
120
121     private final static double  ZERO_DIFF                 = 1.0E-9;
122     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
123                                                                    + ForesterUtil.getFileSeparator() + "test_data"
124                                                                    + ForesterUtil.getFileSeparator();
125     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
126                                                                    + ForesterUtil.getFileSeparator() + "resources"
127                                                                    + ForesterUtil.getFileSeparator();
128     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
129     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
130                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
131                                                                    + ForesterConstants.PHYLO_XML_XSD;
132     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
133                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
134                                                                    + ForesterConstants.PHYLO_XML_XSD;
135
136     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
137         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
138         return p;
139     }
140
141     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
142         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
143     }
144
145     public static boolean isEqual( final double a, final double b ) {
146         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
147     }
148
149     public static void main( final String[] args ) {
150         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
151         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
152                 + "]" );
153         Locale.setDefault( Locale.US );
154         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
155         int failed = 0;
156         int succeeded = 0;
157         System.out.print( "[Test if directory with files for testing exists/is readable: " );
158         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
159             System.out.println( "OK.]" );
160         }
161         else {
162             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
163             System.out.println( "Testing aborted." );
164             System.exit( -1 );
165         }
166         System.out.print( "[Test if resources directory exists/is readable: " );
167         if ( testDir( PATH_TO_RESOURCES ) ) {
168             System.out.println( "OK.]" );
169         }
170         else {
171             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
172             System.out.println( "Testing aborted." );
173             System.exit( -1 );
174         }
175         final long start_time = new Date().getTime();
176         System.out.print( "Sequence id parsing: " );
177         if ( testSequenceIdParsing() ) {
178             System.out.println( "OK." );
179             succeeded++;
180         }
181         else {
182             System.out.println( "failed." );
183             failed++;
184         }
185         System.out.print( "Hmmscan output parser: " );
186         if ( testHmmscanOutputParser() ) {
187             System.out.println( "OK." );
188             succeeded++;
189         }
190         else {
191             System.out.println( "failed." );
192             failed++;
193         }
194         System.out.print( "Basic node methods: " );
195         if ( Test.testBasicNodeMethods() ) {
196             System.out.println( "OK." );
197             succeeded++;
198         }
199         else {
200             System.out.println( "failed." );
201             failed++;
202         }
203         System.out.print( "Taxonomy code extraction: " );
204         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
205             System.out.println( "OK." );
206             succeeded++;
207         }
208         else {
209             System.out.println( "failed." );
210             failed++;
211         }
212         System.out.print( "Taxonomy extraction (general): " );
213         if ( Test.testTaxonomyExtraction() ) {
214             System.out.println( "OK." );
215             succeeded++;
216         }
217         else {
218             System.out.println( "failed." );
219             failed++;
220         }
221         System.out.print( "UniProtKB id extraction: " );
222         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
223             System.out.println( "OK." );
224             succeeded++;
225         }
226         else {
227             System.out.println( "failed." );
228             failed++;
229         }
230         System.out.print( "Uri for Aptx web sequence accession: " );
231         if ( Test.testCreateUriForSeqWeb() ) {
232             System.out.println( "OK." );
233             succeeded++;
234         }
235         else {
236             System.out.println( "failed." );
237             failed++;
238         }
239         System.out.print( "Basic node construction and parsing of NHX (node level): " );
240         if ( Test.testNHXNodeParsing() ) {
241             System.out.println( "OK." );
242             succeeded++;
243         }
244         else {
245             System.out.println( "failed." );
246             failed++;
247         }
248         System.out.print( "NHX parsing iterating: " );
249         if ( Test.testNHParsingIter() ) {
250             System.out.println( "OK." );
251             succeeded++;
252         }
253         else {
254             System.out.println( "failed." );
255             failed++;
256         }
257         System.out.print( "NH parsing: " );
258         if ( Test.testNHParsing() ) {
259             System.out.println( "OK." );
260             succeeded++;
261         }
262         else {
263             System.out.println( "failed." );
264             failed++;
265         }
266         System.out.print( "Conversion to NHX (node level): " );
267         if ( Test.testNHXconversion() ) {
268             System.out.println( "OK." );
269             succeeded++;
270         }
271         else {
272             System.out.println( "failed." );
273             failed++;
274         }
275         System.out.print( "NHX parsing: " );
276         if ( Test.testNHXParsing() ) {
277             System.out.println( "OK." );
278             succeeded++;
279         }
280         else {
281             System.out.println( "failed." );
282             failed++;
283         }
284         System.out.print( "NHX parsing with quotes: " );
285         if ( Test.testNHXParsingQuotes() ) {
286             System.out.println( "OK." );
287             succeeded++;
288         }
289         else {
290             System.out.println( "failed." );
291             failed++;
292         }
293         System.out.print( "NHX parsing (MrBayes): " );
294         if ( Test.testNHXParsingMB() ) {
295             System.out.println( "OK." );
296             succeeded++;
297         }
298         else {
299             System.out.println( "failed." );
300             failed++;
301         }
302         System.out.print( "Nexus characters parsing: " );
303         if ( Test.testNexusCharactersParsing() ) {
304             System.out.println( "OK." );
305             succeeded++;
306         }
307         else {
308             System.out.println( "failed." );
309             failed++;
310         }
311         System.out.print( "Nexus tree parsing iterating: " );
312         if ( Test.testNexusTreeParsingIterating() ) {
313             System.out.println( "OK." );
314             succeeded++;
315         }
316         else {
317             System.out.println( "failed." );
318             failed++;
319         }
320         System.out.print( "Nexus tree parsing: " );
321         if ( Test.testNexusTreeParsing() ) {
322             System.out.println( "OK." );
323             succeeded++;
324         }
325         else {
326             System.out.println( "failed." );
327             failed++;
328         }
329         System.out.print( "Nexus tree parsing (translating): " );
330         if ( Test.testNexusTreeParsingTranslating() ) {
331             System.out.println( "OK." );
332             succeeded++;
333         }
334         else {
335             System.out.println( "failed." );
336             failed++;
337         }
338         System.out.print( "Nexus matrix parsing: " );
339         if ( Test.testNexusMatrixParsing() ) {
340             System.out.println( "OK." );
341             succeeded++;
342         }
343         else {
344             System.out.println( "failed." );
345             failed++;
346         }
347         System.out.print( "Basic phyloXML parsing: " );
348         if ( Test.testBasicPhyloXMLparsing() ) {
349             System.out.println( "OK." );
350             succeeded++;
351         }
352         else {
353             System.out.println( "failed." );
354             failed++;
355         }
356         System.out.print( "Basic phyloXML parsing (validating against schema): " );
357         if ( testBasicPhyloXMLparsingValidating() ) {
358             System.out.println( "OK." );
359             succeeded++;
360         }
361         else {
362             System.out.println( "failed." );
363             failed++;
364         }
365         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
366         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
367             System.out.println( "OK." );
368             succeeded++;
369         }
370         else {
371             System.out.println( "failed." );
372             failed++;
373         }
374         System.out.print( "phyloXML Distribution Element: " );
375         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
376             System.out.println( "OK." );
377             succeeded++;
378         }
379         else {
380             System.out.println( "failed." );
381             failed++;
382         }
383         System.out.print( "Tol XML parsing: " );
384         if ( Test.testBasicTolXMLparsing() ) {
385             System.out.println( "OK." );
386             succeeded++;
387         }
388         else {
389             System.out.println( "failed." );
390             failed++;
391         }
392         System.out.print( "Copying of node data: " );
393         if ( Test.testCopyOfNodeData() ) {
394             System.out.println( "OK." );
395             succeeded++;
396         }
397         else {
398             System.out.println( "failed." );
399             failed++;
400         }
401         System.out.print( "Basic tree methods: " );
402         if ( Test.testBasicTreeMethods() ) {
403             System.out.println( "OK." );
404             succeeded++;
405         }
406         else {
407             System.out.println( "failed." );
408             failed++;
409         }
410         System.out.print( "Tree methods: " );
411         if ( Test.testTreeMethods() ) {
412             System.out.println( "OK." );
413             succeeded++;
414         }
415         else {
416             System.out.println( "failed." );
417             failed++;
418         }
419         System.out.print( "Postorder Iterator: " );
420         if ( Test.testPostOrderIterator() ) {
421             System.out.println( "OK." );
422             succeeded++;
423         }
424         else {
425             System.out.println( "failed." );
426             failed++;
427         }
428         System.out.print( "Preorder Iterator: " );
429         if ( Test.testPreOrderIterator() ) {
430             System.out.println( "OK." );
431             succeeded++;
432         }
433         else {
434             System.out.println( "failed." );
435             failed++;
436         }
437         System.out.print( "Levelorder Iterator: " );
438         if ( Test.testLevelOrderIterator() ) {
439             System.out.println( "OK." );
440             succeeded++;
441         }
442         else {
443             System.out.println( "failed." );
444             failed++;
445         }
446         System.out.print( "Re-id methods: " );
447         if ( Test.testReIdMethods() ) {
448             System.out.println( "OK." );
449             succeeded++;
450         }
451         else {
452             System.out.println( "failed." );
453             failed++;
454         }
455         System.out.print( "Methods on last external nodes: " );
456         if ( Test.testLastExternalNodeMethods() ) {
457             System.out.println( "OK." );
458             succeeded++;
459         }
460         else {
461             System.out.println( "failed." );
462             failed++;
463         }
464         System.out.print( "Methods on external nodes: " );
465         if ( Test.testExternalNodeRelatedMethods() ) {
466             System.out.println( "OK." );
467             succeeded++;
468         }
469         else {
470             System.out.println( "failed." );
471             failed++;
472         }
473         System.out.print( "Deletion of external nodes: " );
474         if ( Test.testDeletionOfExternalNodes() ) {
475             System.out.println( "OK." );
476             succeeded++;
477         }
478         else {
479             System.out.println( "failed." );
480             failed++;
481         }
482         System.out.print( "Subtree deletion: " );
483         if ( Test.testSubtreeDeletion() ) {
484             System.out.println( "OK." );
485             succeeded++;
486         }
487         else {
488             System.out.println( "failed." );
489             failed++;
490         }
491         System.out.print( "Phylogeny branch: " );
492         if ( Test.testPhylogenyBranch() ) {
493             System.out.println( "OK." );
494             succeeded++;
495         }
496         else {
497             System.out.println( "failed." );
498             failed++;
499         }
500         System.out.print( "Rerooting: " );
501         if ( Test.testRerooting() ) {
502             System.out.println( "OK." );
503             succeeded++;
504         }
505         else {
506             System.out.println( "failed." );
507             failed++;
508         }
509         System.out.print( "Mipoint rooting: " );
510         if ( Test.testMidpointrooting() ) {
511             System.out.println( "OK." );
512             succeeded++;
513         }
514         else {
515             System.out.println( "failed." );
516             failed++;
517         }
518         System.out.print( "Node removal: " );
519         if ( Test.testNodeRemoval() ) {
520             System.out.println( "OK." );
521             succeeded++;
522         }
523         else {
524             System.out.println( "failed." );
525             failed++;
526         }
527         System.out.print( "Support count: " );
528         if ( Test.testSupportCount() ) {
529             System.out.println( "OK." );
530             succeeded++;
531         }
532         else {
533             System.out.println( "failed." );
534             failed++;
535         }
536         System.out.print( "Support transfer: " );
537         if ( Test.testSupportTransfer() ) {
538             System.out.println( "OK." );
539             succeeded++;
540         }
541         else {
542             System.out.println( "failed." );
543             failed++;
544         }
545         System.out.print( "Finding of LCA: " );
546         if ( Test.testGetLCA() ) {
547             System.out.println( "OK." );
548             succeeded++;
549         }
550         else {
551             System.out.println( "failed." );
552             failed++;
553         }
554         System.out.print( "Finding of LCA 2: " );
555         if ( Test.testGetLCA2() ) {
556             System.out.println( "OK." );
557             succeeded++;
558         }
559         else {
560             System.out.println( "failed." );
561             failed++;
562         }
563         System.out.print( "Calculation of distance between nodes: " );
564         if ( Test.testGetDistance() ) {
565             System.out.println( "OK." );
566             succeeded++;
567         }
568         else {
569             System.out.println( "failed." );
570             failed++;
571         }
572         System.out.print( "Descriptive statistics: " );
573         if ( Test.testDescriptiveStatistics() ) {
574             System.out.println( "OK." );
575             succeeded++;
576         }
577         else {
578             System.out.println( "failed." );
579             failed++;
580         }
581         System.out.print( "Data objects and methods: " );
582         if ( Test.testDataObjects() ) {
583             System.out.println( "OK." );
584             succeeded++;
585         }
586         else {
587             System.out.println( "failed." );
588             failed++;
589         }
590         System.out.print( "Properties map: " );
591         if ( Test.testPropertiesMap() ) {
592             System.out.println( "OK." );
593             succeeded++;
594         }
595         else {
596             System.out.println( "failed." );
597             failed++;
598         }
599         System.out.print( "SDIse: " );
600         if ( Test.testSDIse() ) {
601             System.out.println( "OK." );
602             succeeded++;
603         }
604         else {
605             System.out.println( "failed." );
606             failed++;
607         }
608         System.out.print( "SDIunrooted: " );
609         if ( Test.testSDIunrooted() ) {
610             System.out.println( "OK." );
611             succeeded++;
612         }
613         else {
614             System.out.println( "failed." );
615             failed++;
616         }
617         System.out.print( "GSDI: " );
618         if ( TestGSDI.test() ) {
619             System.out.println( "OK." );
620             succeeded++;
621         }
622         else {
623             System.out.println( "failed." );
624             failed++;
625         }
626         System.out.print( "RIO: " );
627         if ( TestRIO.test() ) {
628             System.out.println( "OK." );
629             succeeded++;
630         }
631         else {
632             System.out.println( "failed." );
633             failed++;
634         }
635         System.out.print( "Phylogeny reconstruction:" );
636         System.out.println();
637         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
638             System.out.println( "OK." );
639             succeeded++;
640         }
641         else {
642             System.out.println( "failed." );
643             failed++;
644         }
645         System.out.print( "Analysis of domain architectures: " );
646         System.out.println();
647         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
648             System.out.println( "OK." );
649             succeeded++;
650         }
651         else {
652             System.out.println( "failed." );
653             failed++;
654         }
655         System.out.print( "GO: " );
656         System.out.println();
657         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
658             System.out.println( "OK." );
659             succeeded++;
660         }
661         else {
662             System.out.println( "failed." );
663             failed++;
664         }
665         System.out.print( "Modeling tools: " );
666         if ( TestPccx.test() ) {
667             System.out.println( "OK." );
668             succeeded++;
669         }
670         else {
671             System.out.println( "failed." );
672             failed++;
673         }
674         System.out.print( "Split Matrix strict: " );
675         if ( Test.testSplitStrict() ) {
676             System.out.println( "OK." );
677             succeeded++;
678         }
679         else {
680             System.out.println( "failed." );
681             failed++;
682         }
683         System.out.print( "Split Matrix: " );
684         if ( Test.testSplit() ) {
685             System.out.println( "OK." );
686             succeeded++;
687         }
688         else {
689             System.out.println( "failed." );
690             failed++;
691         }
692         System.out.print( "Confidence Assessor: " );
693         if ( Test.testConfidenceAssessor() ) {
694             System.out.println( "OK." );
695             succeeded++;
696         }
697         else {
698             System.out.println( "failed." );
699             failed++;
700         }
701         System.out.print( "Basic table: " );
702         if ( Test.testBasicTable() ) {
703             System.out.println( "OK." );
704             succeeded++;
705         }
706         else {
707             System.out.println( "failed." );
708             failed++;
709         }
710         System.out.print( "General table: " );
711         if ( Test.testGeneralTable() ) {
712             System.out.println( "OK." );
713             succeeded++;
714         }
715         else {
716             System.out.println( "failed." );
717             failed++;
718         }
719         System.out.print( "Amino acid sequence: " );
720         if ( Test.testAminoAcidSequence() ) {
721             System.out.println( "OK." );
722             succeeded++;
723         }
724         else {
725             System.out.println( "failed." );
726             failed++;
727         }
728         System.out.print( "General MSA parser: " );
729         if ( Test.testGeneralMsaParser() ) {
730             System.out.println( "OK." );
731             succeeded++;
732         }
733         else {
734             System.out.println( "failed." );
735             failed++;
736         }
737         System.out.print( "Fasta parser for msa: " );
738         if ( Test.testFastaParser() ) {
739             System.out.println( "OK." );
740             succeeded++;
741         }
742         else {
743             System.out.println( "failed." );
744             failed++;
745         }
746         System.out.print( "Creation of balanced phylogeny: " );
747         if ( Test.testCreateBalancedPhylogeny() ) {
748             System.out.println( "OK." );
749             succeeded++;
750         }
751         else {
752             System.out.println( "failed." );
753             failed++;
754         }
755         System.out.print( "EMBL Entry Retrieval: " );
756         if ( Test.testEmblEntryRetrieval() ) {
757             System.out.println( "OK." );
758             succeeded++;
759         }
760         else {
761             System.out.println( "failed." );
762             failed++;
763         }
764         System.out.print( "Uniprot Entry Retrieval: " );
765         if ( Test.testUniprotEntryRetrieval() ) {
766             System.out.println( "OK." );
767             succeeded++;
768         }
769         else {
770             System.out.println( "failed." );
771             failed++;
772         }
773         System.out.print( "Uniprot Taxonomy Search: " );
774         if ( Test.testUniprotTaxonomySearch() ) {
775             System.out.println( "OK." );
776             succeeded++;
777         }
778         else {
779             System.out.println( "failed." );
780             failed++;
781         }
782         //----
783         String path = "";
784         final String os = ForesterUtil.OS_NAME.toLowerCase();
785         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
786             path = "/usr/local/bin/mafft";
787         }
788         else if ( os.indexOf( "win" ) >= 0 ) {
789             path = "C:\\Program Files\\mafft-win\\mafft.bat";
790         }
791         else {
792             path = "/home/czmasek/bin/mafft";
793         }
794         if ( !MsaInferrer.isInstalled( path ) ) {
795             path = "mafft";
796         }
797         if ( !MsaInferrer.isInstalled( path ) ) {
798             path = "/usr/local/bin/mafft";
799         }
800         if ( MsaInferrer.isInstalled( path ) ) {
801             System.out.print( "MAFFT (external program): " );
802             if ( Test.testMafft( path ) ) {
803                 System.out.println( "OK." );
804                 succeeded++;
805             }
806             else {
807                 System.out.println( "failed [will not count towards failed tests]" );
808             }
809         }
810         //----
811         System.out.print( "Next nodes with collapsed: " );
812         if ( Test.testNextNodeWithCollapsing() ) {
813             System.out.println( "OK." );
814             succeeded++;
815         }
816         else {
817             System.out.println( "failed." );
818             failed++;
819         }
820         System.out.print( "Simple MSA quality: " );
821         if ( Test.testMsaQualityMethod() ) {
822             System.out.println( "OK." );
823             succeeded++;
824         }
825         else {
826             System.out.println( "failed." );
827             failed++;
828         }
829         System.out.println();
830         final Runtime rt = java.lang.Runtime.getRuntime();
831         final long free_memory = rt.freeMemory() / 1000000;
832         final long total_memory = rt.totalMemory() / 1000000;
833         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
834                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
835         System.out.println();
836         System.out.println( "Successful tests: " + succeeded );
837         System.out.println( "Failed     tests: " + failed );
838         System.out.println();
839         if ( failed < 1 ) {
840             System.out.println( "OK." );
841         }
842         else {
843             System.out.println( "Not OK." );
844         }
845     }
846
847     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
848         try {
849             PhylogenyNode n = new PhylogenyNode();
850             n.setName( "tr|B3RJ64" );
851             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
852                 return false;
853             }
854             n.setName( "tr.B3RJ64" );
855             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
856                 return false;
857             }
858             n.setName( "tr=B3RJ64" );
859             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
860                 return false;
861             }
862             n.setName( "tr-B3RJ64" );
863             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
864                 return false;
865             }
866             n.setName( "tr/B3RJ64" );
867             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
868                 return false;
869             }
870             n.setName( "tr\\B3RJ64" );
871             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
872                 return false;
873             }
874             n.setName( "tr_B3RJ64" );
875             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
876                 return false;
877             }
878             n.setName( " tr|B3RJ64 " );
879             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
880                 return false;
881             }
882             n.setName( "-tr|B3RJ64-" );
883             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
884                 return false;
885             }
886             n.setName( "-tr=B3RJ64-" );
887             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
888                 return false;
889             }
890             n.setName( "_tr=B3RJ64_" );
891             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
892                 return false;
893             }
894             n.setName( " tr_tr|B3RJ64_sp|123 " );
895             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
896                 return false;
897             }
898             n.setName( "sp|B3RJ64" );
899             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
900                 return false;
901             }
902             n.setName( "ssp|B3RJ64" );
903             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
904                 return false;
905             }
906             n.setName( "sp|B3RJ64C" );
907             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
908                 return false;
909             }
910             n.setName( "sp B3RJ64" );
911             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
912                 return false;
913             }
914             n.setName( "sp|B3RJ6X" );
915             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
916                 return false;
917             }
918             n.setName( "sp|B3RJ6" );
919             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
920                 return false;
921             }
922             n.setName( "K1PYK7_CRAGI" );
923             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
924                 return false;
925             }
926             n.setName( "K1PYK7_PEA" );
927             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) {
928                 return false;
929             }
930             n.setName( "K1PYK7_RAT" );
931             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) {
932                 return false;
933             }
934             n.setName( "K1PYK7_PIG" );
935             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
936                 return false;
937             }
938             n.setName( "~K1PYK7_PIG~" );
939             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
940                 return false;
941             }
942             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
943             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
944                 return false;
945             }
946             n.setName( "K1PYKX_CRAGI" );
947             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
948                 return false;
949             }
950             n.setName( "XXXXX_CRAGI" );
951             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) {
952                 return false;
953             }
954             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
955             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) {
956                 return false;
957             }
958             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
959             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
960                 return false;
961             }
962             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
963             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) {
964                 return false;
965             }
966             n = new PhylogenyNode();
967             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
968             seq.setSymbol( "K1PYK7_CRAGI" );
969             n.getNodeData().addSequence( seq );
970             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
971                 return false;
972             }
973             seq.setSymbol( "tr|B3RJ64" );
974             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
975                 return false;
976             }
977             n = new PhylogenyNode();
978             seq = new org.forester.phylogeny.data.Sequence();
979             seq.setName( "K1PYK7_CRAGI" );
980             n.getNodeData().addSequence( seq );
981             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
982                 return false;
983             }
984             seq.setName( "tr|B3RJ64" );
985             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
986                 return false;
987             }
988             n = new PhylogenyNode();
989             seq = new org.forester.phylogeny.data.Sequence();
990             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
991             n.getNodeData().addSequence( seq );
992             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) {
993                 return false;
994             }
995             n = new PhylogenyNode();
996             seq = new org.forester.phylogeny.data.Sequence();
997             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
998             n.getNodeData().addSequence( seq );
999             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
1000                 return false;
1001             }
1002             //
1003             n = new PhylogenyNode();
1004             n.setName( "ACP19736" );
1005             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1006                 return false;
1007             }
1008             n = new PhylogenyNode();
1009             n.setName( "_ACP19736_" );
1010             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1011                 return false;
1012             }
1013         }
1014         catch ( final Exception e ) {
1015             e.printStackTrace( System.out );
1016             return false;
1017         }
1018         return true;
1019     }
1020
1021     private static boolean testCreateUriForSeqWeb() {
1022         try {
1023             final PhylogenyNode n = new PhylogenyNode();
1024             n.setName( "tr|B3RJ64" );
1025             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
1026                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1027                 System.exit( -1 );
1028                 return false;
1029             }
1030             n.setName( "B0LM41_HUMAN" );
1031             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
1032                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1033                 System.exit( -1 );
1034                 return false;
1035             }
1036             n.setName( "NP_001025424" );
1037             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
1038                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1039                 System.exit( -1 );
1040                 return false;
1041             }
1042             n.setName( "_NM_001030253-" );
1043             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
1044                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1045                 System.exit( -1 );
1046                 return false;
1047             }
1048             n.setName( "NP_001025424" );
1049             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
1050                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1051                 System.exit( -1 );
1052                 return false;
1053             }
1054         }
1055         catch ( final Exception e ) {
1056             e.printStackTrace( System.out );
1057             return false;
1058         }
1059         return true;
1060     }
1061
1062     private static boolean testExtractTaxonomyCodeFromNodeName() {
1063         try {
1064             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1065                     .equals( "MOUSE" ) ) {
1066                 return false;
1067             }
1068             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1069                     .equals( "RAT" ) ) {
1070                 return false;
1071             }
1072             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1073                 return false;
1074             }
1075             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
1076                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1077                     .equals( "MOUSE" ) ) {
1078                 return false;
1079             }
1080             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE_function = 23445",
1081                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1082                     .equals( "MOUSE" ) ) {
1083                 return false;
1084             }
1085             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
1086                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1087                     .equals( "MOUSE" ) ) {
1088                 return false;
1089             }
1090             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
1091                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1092                 return false;
1093             }
1094             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
1095                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1096                 return false;
1097             }
1098             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1099                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1100                 return false;
1101             }
1102             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445",
1103                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1104                 return false;
1105             }
1106             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
1107                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1108                 return false;
1109             }
1110             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
1111                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1112                 return false;
1113             }
1114             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
1115                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1116                 return false;
1117             }
1118             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1119                     .equals( "RAT" ) ) {
1120                 return false;
1121             }
1122             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1123                     .equals( "PIG" ) ) {
1124                 return false;
1125             }
1126             if ( !ParserUtils
1127                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1128                     .equals( "MOUSE" ) ) {
1129                 return false;
1130             }
1131             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1132                     .equals( "MOUSE" ) ) {
1133                 return false;
1134             }
1135             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.AGRESSIVE )
1136                     .equals( "MOUSE" ) ) {
1137                 return false;
1138             }
1139             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1140                     .equals( "MOUSE" ) ) {
1141                 return false;
1142             }
1143             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ) != null ) {
1144                 return false;
1145             }
1146             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "x_MOUSE_x", TAXONOMY_EXTRACTION.AGRESSIVE )
1147                     .equals( "MOUSE" ) ) {
1148                 return false;
1149             }
1150         }
1151         catch ( final Exception e ) {
1152             e.printStackTrace( System.out );
1153             return false;
1154         }
1155         return true;
1156     }
1157
1158     private static boolean testBasicNodeMethods() {
1159         try {
1160             if ( PhylogenyNode.getNodeCount() != 0 ) {
1161                 return false;
1162             }
1163             final PhylogenyNode n1 = new PhylogenyNode();
1164             final PhylogenyNode n2 = PhylogenyNode
1165                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1166             final PhylogenyNode n3 = PhylogenyNode
1167                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1168             final PhylogenyNode n4 = PhylogenyNode
1169                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1170             if ( n1.isHasAssignedEvent() ) {
1171                 return false;
1172             }
1173             if ( PhylogenyNode.getNodeCount() != 4 ) {
1174                 return false;
1175             }
1176             if ( n3.getIndicator() != 0 ) {
1177                 return false;
1178             }
1179             if ( n3.getNumberOfExternalNodes() != 1 ) {
1180                 return false;
1181             }
1182             if ( !n3.isExternal() ) {
1183                 return false;
1184             }
1185             if ( !n3.isRoot() ) {
1186                 return false;
1187             }
1188             if ( !n4.getName().equals( "n4" ) ) {
1189                 return false;
1190             }
1191         }
1192         catch ( final Exception e ) {
1193             e.printStackTrace( System.out );
1194             return false;
1195         }
1196         return true;
1197     }
1198
1199     private static boolean testBasicPhyloXMLparsing() {
1200         try {
1201             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1202             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1203             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1204                                                               xml_parser );
1205             if ( xml_parser.getErrorCount() > 0 ) {
1206                 System.out.println( xml_parser.getErrorMessages().toString() );
1207                 return false;
1208             }
1209             if ( phylogenies_0.length != 4 ) {
1210                 return false;
1211             }
1212             final Phylogeny t1 = phylogenies_0[ 0 ];
1213             final Phylogeny t2 = phylogenies_0[ 1 ];
1214             final Phylogeny t3 = phylogenies_0[ 2 ];
1215             final Phylogeny t4 = phylogenies_0[ 3 ];
1216             if ( t1.getNumberOfExternalNodes() != 1 ) {
1217                 return false;
1218             }
1219             if ( !t1.isRooted() ) {
1220                 return false;
1221             }
1222             if ( t1.isRerootable() ) {
1223                 return false;
1224             }
1225             if ( !t1.getType().equals( "gene_tree" ) ) {
1226                 return false;
1227             }
1228             if ( t2.getNumberOfExternalNodes() != 2 ) {
1229                 return false;
1230             }
1231             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1232                 return false;
1233             }
1234             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1235                 return false;
1236             }
1237             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1238                 return false;
1239             }
1240             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1241                 return false;
1242             }
1243             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1244                 return false;
1245             }
1246             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1247                 return false;
1248             }
1249             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1250                     .startsWith( "actgtgggggt" ) ) {
1251                 return false;
1252             }
1253             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1254                     .startsWith( "ctgtgatgcat" ) ) {
1255                 return false;
1256             }
1257             if ( t3.getNumberOfExternalNodes() != 4 ) {
1258                 return false;
1259             }
1260             if ( !t1.getName().equals( "t1" ) ) {
1261                 return false;
1262             }
1263             if ( !t2.getName().equals( "t2" ) ) {
1264                 return false;
1265             }
1266             if ( !t3.getName().equals( "t3" ) ) {
1267                 return false;
1268             }
1269             if ( !t4.getName().equals( "t4" ) ) {
1270                 return false;
1271             }
1272             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1273                 return false;
1274             }
1275             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1276                 return false;
1277             }
1278             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1279                 return false;
1280             }
1281             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1282                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1283                 return false;
1284             }
1285             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1286                 return false;
1287             }
1288             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1289                 return false;
1290             }
1291             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1292                 return false;
1293             }
1294             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1295                     .equals( "apoptosis" ) ) {
1296                 return false;
1297             }
1298             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1299                     .equals( "GO:0006915" ) ) {
1300                 return false;
1301             }
1302             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1303                     .equals( "UniProtKB" ) ) {
1304                 return false;
1305             }
1306             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1307                     .equals( "experimental" ) ) {
1308                 return false;
1309             }
1310             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1311                     .equals( "function" ) ) {
1312                 return false;
1313             }
1314             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1315                     .getValue() != 1 ) {
1316                 return false;
1317             }
1318             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1319                     .getType().equals( "ml" ) ) {
1320                 return false;
1321             }
1322             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1323                     .equals( "apoptosis" ) ) {
1324                 return false;
1325             }
1326             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1327                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1328                 return false;
1329             }
1330             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1331                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1332                 return false;
1333             }
1334             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1335                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1336                 return false;
1337             }
1338             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1339                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1340                 return false;
1341             }
1342             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1343                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1344                 return false;
1345             }
1346             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1347                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1348                 return false;
1349             }
1350             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1351                     .equals( "GO:0005829" ) ) {
1352                 return false;
1353             }
1354             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1355                     .equals( "intracellular organelle" ) ) {
1356                 return false;
1357             }
1358             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1359                 return false;
1360             }
1361             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1362                     .equals( "UniProt link" ) ) ) {
1363                 return false;
1364             }
1365             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1366                 return false;
1367             }
1368         }
1369         catch ( final Exception e ) {
1370             e.printStackTrace( System.out );
1371             return false;
1372         }
1373         return true;
1374     }
1375
1376     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1377         try {
1378             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1379             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1380             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1381                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1382             }
1383             else {
1384                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1385             }
1386             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1387                                                               xml_parser );
1388             if ( xml_parser.getErrorCount() > 0 ) {
1389                 System.out.println( xml_parser.getErrorMessages().toString() );
1390                 return false;
1391             }
1392             if ( phylogenies_0.length != 4 ) {
1393                 return false;
1394             }
1395             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1396             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1397             if ( phylogenies_t1.length != 1 ) {
1398                 return false;
1399             }
1400             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1401             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1402                 return false;
1403             }
1404             if ( !t1_rt.isRooted() ) {
1405                 return false;
1406             }
1407             if ( t1_rt.isRerootable() ) {
1408                 return false;
1409             }
1410             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1411                 return false;
1412             }
1413             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1414             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1415             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1416             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1417                 return false;
1418             }
1419             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1420                 return false;
1421             }
1422             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1423                 return false;
1424             }
1425             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1426                 return false;
1427             }
1428             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1429                     .startsWith( "actgtgggggt" ) ) {
1430                 return false;
1431             }
1432             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1433                     .startsWith( "ctgtgatgcat" ) ) {
1434                 return false;
1435             }
1436             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1437             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1438             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1439             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1440             if ( phylogenies_1.length != 1 ) {
1441                 return false;
1442             }
1443             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1444             if ( !t3_rt.getName().equals( "t3" ) ) {
1445                 return false;
1446             }
1447             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1448                 return false;
1449             }
1450             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1451                 return false;
1452             }
1453             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1454                 return false;
1455             }
1456             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1457                 return false;
1458             }
1459             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1460                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1461                 return false;
1462             }
1463             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1464                 return false;
1465             }
1466             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1467                 return false;
1468             }
1469             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1470                     .equals( "UniProtKB" ) ) {
1471                 return false;
1472             }
1473             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1474                     .equals( "apoptosis" ) ) {
1475                 return false;
1476             }
1477             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1478                     .equals( "GO:0006915" ) ) {
1479                 return false;
1480             }
1481             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1482                     .equals( "UniProtKB" ) ) {
1483                 return false;
1484             }
1485             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1486                     .equals( "experimental" ) ) {
1487                 return false;
1488             }
1489             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1490                     .equals( "function" ) ) {
1491                 return false;
1492             }
1493             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1494                     .getValue() != 1 ) {
1495                 return false;
1496             }
1497             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1498                     .getType().equals( "ml" ) ) {
1499                 return false;
1500             }
1501             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1502                     .equals( "apoptosis" ) ) {
1503                 return false;
1504             }
1505             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1506                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1507                 return false;
1508             }
1509             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1510                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1511                 return false;
1512             }
1513             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1514                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1515                 return false;
1516             }
1517             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1518                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1519                 return false;
1520             }
1521             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1522                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1523                 return false;
1524             }
1525             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1526                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1527                 return false;
1528             }
1529             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1530                     .equals( "GO:0005829" ) ) {
1531                 return false;
1532             }
1533             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1534                     .equals( "intracellular organelle" ) ) {
1535                 return false;
1536             }
1537             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1538                 return false;
1539             }
1540             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1541                     .equals( "UniProt link" ) ) ) {
1542                 return false;
1543             }
1544             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1545                 return false;
1546             }
1547             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1548                 return false;
1549             }
1550             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1551                     .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." ) ) ) {
1552                 return false;
1553             }
1554             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1555                 return false;
1556             }
1557             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1558                 return false;
1559             }
1560             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1561                 return false;
1562             }
1563             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1564                 return false;
1565             }
1566             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1567                     .equals( "ncbi" ) ) {
1568                 return false;
1569             }
1570             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1571                 return false;
1572             }
1573             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1574                     .getName().equals( "B" ) ) {
1575                 return false;
1576             }
1577             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1578                     .getFrom() != 21 ) {
1579                 return false;
1580             }
1581             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1582                 return false;
1583             }
1584             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1585                     .getLength() != 24 ) {
1586                 return false;
1587             }
1588             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1589                     .getConfidence() != 2144 ) {
1590                 return false;
1591             }
1592             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1593                     .equals( "pfam" ) ) {
1594                 return false;
1595             }
1596             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1597                 return false;
1598             }
1599             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1600                 return false;
1601             }
1602             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1603                 return false;
1604             }
1605             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1606                 return false;
1607             }
1608             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1609             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1610                 return false;
1611             }
1612             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1613                 return false;
1614             }
1615             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1616                 return false;
1617             }
1618             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1619                 return false;
1620             }
1621             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1622                 return false;
1623             }
1624             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1625                 return false;
1626             }
1627             if ( taxbb.getSynonyms().size() != 2 ) {
1628                 return false;
1629             }
1630             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1631                 return false;
1632             }
1633             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1634                 return false;
1635             }
1636             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1637                 return false;
1638             }
1639             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1640                 return false;
1641             }
1642             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1643                 return false;
1644             }
1645             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1646                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1647                 ;
1648                 return false;
1649             }
1650             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1651                 return false;
1652             }
1653             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1654                 return false;
1655             }
1656             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1657                 return false;
1658             }
1659             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1660                 return false;
1661             }
1662             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1663                 return false;
1664             }
1665             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1666                 return false;
1667             }
1668             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1669                 return false;
1670             }
1671             //
1672             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1673                 return false;
1674             }
1675             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1676                     .equalsIgnoreCase( "435" ) ) {
1677                 return false;
1678             }
1679             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1680                 return false;
1681             }
1682             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1683                     .equalsIgnoreCase( "443.7" ) ) {
1684                 return false;
1685             }
1686             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1687                 return false;
1688             }
1689             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1690                 return false;
1691             }
1692             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1693                     .equalsIgnoreCase( "433" ) ) {
1694                 return false;
1695             }
1696         }
1697         catch ( final Exception e ) {
1698             e.printStackTrace( System.out );
1699             return false;
1700         }
1701         return true;
1702     }
1703
1704     private static boolean testBasicPhyloXMLparsingValidating() {
1705         try {
1706             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1707             PhyloXmlParser xml_parser = null;
1708             try {
1709                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1710             }
1711             catch ( final Exception e ) {
1712                 // Do nothing -- means were not running from jar.
1713             }
1714             if ( xml_parser == null ) {
1715                 xml_parser = new PhyloXmlParser();
1716                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1717                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1718                 }
1719                 else {
1720                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1721                 }
1722             }
1723             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1724                                                               xml_parser );
1725             if ( xml_parser.getErrorCount() > 0 ) {
1726                 System.out.println( xml_parser.getErrorMessages().toString() );
1727                 return false;
1728             }
1729             if ( phylogenies_0.length != 4 ) {
1730                 return false;
1731             }
1732             final Phylogeny t1 = phylogenies_0[ 0 ];
1733             final Phylogeny t2 = phylogenies_0[ 1 ];
1734             final Phylogeny t3 = phylogenies_0[ 2 ];
1735             final Phylogeny t4 = phylogenies_0[ 3 ];
1736             if ( !t1.getName().equals( "t1" ) ) {
1737                 return false;
1738             }
1739             if ( !t2.getName().equals( "t2" ) ) {
1740                 return false;
1741             }
1742             if ( !t3.getName().equals( "t3" ) ) {
1743                 return false;
1744             }
1745             if ( !t4.getName().equals( "t4" ) ) {
1746                 return false;
1747             }
1748             if ( t1.getNumberOfExternalNodes() != 1 ) {
1749                 return false;
1750             }
1751             if ( t2.getNumberOfExternalNodes() != 2 ) {
1752                 return false;
1753             }
1754             if ( t3.getNumberOfExternalNodes() != 4 ) {
1755                 return false;
1756             }
1757             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1758             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1759             if ( xml_parser.getErrorCount() > 0 ) {
1760                 System.out.println( "errors:" );
1761                 System.out.println( xml_parser.getErrorMessages().toString() );
1762                 return false;
1763             }
1764             if ( phylogenies_1.length != 4 ) {
1765                 return false;
1766             }
1767             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1768                                                               xml_parser );
1769             if ( xml_parser.getErrorCount() > 0 ) {
1770                 System.out.println( "errors:" );
1771                 System.out.println( xml_parser.getErrorMessages().toString() );
1772                 return false;
1773             }
1774             if ( phylogenies_2.length != 1 ) {
1775                 return false;
1776             }
1777             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1778                 return false;
1779             }
1780             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1781                                                               xml_parser );
1782             if ( xml_parser.getErrorCount() > 0 ) {
1783                 System.out.println( xml_parser.getErrorMessages().toString() );
1784                 return false;
1785             }
1786             if ( phylogenies_3.length != 2 ) {
1787                 return false;
1788             }
1789             final Phylogeny a = phylogenies_3[ 0 ];
1790             if ( !a.getName().equals( "tree 4" ) ) {
1791                 return false;
1792             }
1793             if ( a.getNumberOfExternalNodes() != 3 ) {
1794                 return false;
1795             }
1796             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1797                 return false;
1798             }
1799             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1800                 return false;
1801             }
1802             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1803                                                               xml_parser );
1804             if ( xml_parser.getErrorCount() > 0 ) {
1805                 System.out.println( xml_parser.getErrorMessages().toString() );
1806                 return false;
1807             }
1808             if ( phylogenies_4.length != 1 ) {
1809                 return false;
1810             }
1811             final Phylogeny s = phylogenies_4[ 0 ];
1812             if ( s.getNumberOfExternalNodes() != 6 ) {
1813                 return false;
1814             }
1815             s.getNode( "first" );
1816             s.getNode( "<>" );
1817             s.getNode( "\"<a'b&c'd\">\"" );
1818             s.getNode( "'''\"" );
1819             s.getNode( "\"\"\"" );
1820             s.getNode( "dick & doof" );
1821         }
1822         catch ( final Exception e ) {
1823             e.printStackTrace( System.out );
1824             return false;
1825         }
1826         return true;
1827     }
1828
1829     private static boolean testBasicTable() {
1830         try {
1831             final BasicTable<String> t0 = new BasicTable<String>();
1832             if ( t0.getNumberOfColumns() != 0 ) {
1833                 return false;
1834             }
1835             if ( t0.getNumberOfRows() != 0 ) {
1836                 return false;
1837             }
1838             t0.setValue( 3, 2, "23" );
1839             t0.setValue( 10, 1, "error" );
1840             t0.setValue( 10, 1, "110" );
1841             t0.setValue( 9, 1, "19" );
1842             t0.setValue( 1, 10, "101" );
1843             t0.setValue( 10, 10, "1010" );
1844             t0.setValue( 100, 10, "10100" );
1845             t0.setValue( 0, 0, "00" );
1846             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1847                 return false;
1848             }
1849             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1850                 return false;
1851             }
1852             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1853                 return false;
1854             }
1855             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1856                 return false;
1857             }
1858             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1859                 return false;
1860             }
1861             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1862                 return false;
1863             }
1864             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1865                 return false;
1866             }
1867             if ( t0.getNumberOfColumns() != 101 ) {
1868                 return false;
1869             }
1870             if ( t0.getNumberOfRows() != 11 ) {
1871                 return false;
1872             }
1873             if ( t0.getValueAsString( 49, 4 ) != null ) {
1874                 return false;
1875             }
1876             final String l = ForesterUtil.getLineSeparator();
1877             final StringBuffer source = new StringBuffer();
1878             source.append( "" + l );
1879             source.append( "# 1 1 1 1 1 1 1 1" + l );
1880             source.append( " 00 01 02 03" + l );
1881             source.append( "   10 11 12 13  " + l );
1882             source.append( "20 21 22 23 " + l );
1883             source.append( "    30  31    32 33" + l );
1884             source.append( "40 41 42 43" + l );
1885             source.append( "  # 1 1 1 1 1 " + l );
1886             source.append( "50 51 52 53 54" + l );
1887             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), " " );
1888             if ( t1.getNumberOfColumns() != 5 ) {
1889                 return false;
1890             }
1891             if ( t1.getNumberOfRows() != 6 ) {
1892                 return false;
1893             }
1894             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1895                 return false;
1896             }
1897             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1898                 return false;
1899             }
1900             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1901                 return false;
1902             }
1903             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1904                 return false;
1905             }
1906             final StringBuffer source1 = new StringBuffer();
1907             source1.append( "" + l );
1908             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1909             source1.append( " 00; 01 ;02;03" + l );
1910             source1.append( "   10; 11; 12; 13  " + l );
1911             source1.append( "20; 21; 22; 23 " + l );
1912             source1.append( "    30;  31;    32; 33" + l );
1913             source1.append( "40;41;42;43" + l );
1914             source1.append( "  # 1 1 1 1 1 " + l );
1915             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
1916             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ";" );
1917             if ( t2.getNumberOfColumns() != 5 ) {
1918                 return false;
1919             }
1920             if ( t2.getNumberOfRows() != 6 ) {
1921                 return false;
1922             }
1923             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1924                 return false;
1925             }
1926             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1927                 return false;
1928             }
1929             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1930                 return false;
1931             }
1932             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1933                 return false;
1934             }
1935             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1936                 return false;
1937             }
1938             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1939                 return false;
1940             }
1941             final StringBuffer source2 = new StringBuffer();
1942             source2.append( "" + l );
1943             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1944             source2.append( " 00; 01 ;02;03" + l );
1945             source2.append( "   10; 11; 12; 13  " + l );
1946             source2.append( "20; 21; 22; 23 " + l );
1947             source2.append( "                     " + l );
1948             source2.append( "    30;  31;    32; 33" + l );
1949             source2.append( "40;41;42;43" + l );
1950             source2.append( "  comment: 1 1 1 1 1 " + l );
1951             source2.append( ";;;50  ;   52; 53;;54   " + l );
1952             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1953                                                                         ";",
1954                                                                         false,
1955                                                                         false,
1956                                                                         "comment:",
1957                                                                         false );
1958             if ( tl.size() != 2 ) {
1959                 return false;
1960             }
1961             final BasicTable<String> t3 = tl.get( 0 );
1962             final BasicTable<String> t4 = tl.get( 1 );
1963             if ( t3.getNumberOfColumns() != 4 ) {
1964                 return false;
1965             }
1966             if ( t3.getNumberOfRows() != 3 ) {
1967                 return false;
1968             }
1969             if ( t4.getNumberOfColumns() != 4 ) {
1970                 return false;
1971             }
1972             if ( t4.getNumberOfRows() != 3 ) {
1973                 return false;
1974             }
1975             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1976                 return false;
1977             }
1978             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
1979                 return false;
1980             }
1981         }
1982         catch ( final Exception e ) {
1983             e.printStackTrace( System.out );
1984             return false;
1985         }
1986         return true;
1987     }
1988
1989     private static boolean testBasicTolXMLparsing() {
1990         try {
1991             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1992             final TolParser parser = new TolParser();
1993             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
1994             if ( parser.getErrorCount() > 0 ) {
1995                 System.out.println( parser.getErrorMessages().toString() );
1996                 return false;
1997             }
1998             if ( phylogenies_0.length != 1 ) {
1999                 return false;
2000             }
2001             final Phylogeny t1 = phylogenies_0[ 0 ];
2002             if ( t1.getNumberOfExternalNodes() != 5 ) {
2003                 return false;
2004             }
2005             if ( !t1.isRooted() ) {
2006                 return false;
2007             }
2008             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2009                 return false;
2010             }
2011             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2012                 return false;
2013             }
2014             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2015                 return false;
2016             }
2017             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2018                 return false;
2019             }
2020             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2021             if ( parser.getErrorCount() > 0 ) {
2022                 System.out.println( parser.getErrorMessages().toString() );
2023                 return false;
2024             }
2025             if ( phylogenies_1.length != 1 ) {
2026                 return false;
2027             }
2028             final Phylogeny t2 = phylogenies_1[ 0 ];
2029             if ( t2.getNumberOfExternalNodes() != 664 ) {
2030                 return false;
2031             }
2032             if ( !t2.isRooted() ) {
2033                 return false;
2034             }
2035             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2036                 return false;
2037             }
2038             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2039                 return false;
2040             }
2041             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2042                 return false;
2043             }
2044             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2045                 return false;
2046             }
2047             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2048                 return false;
2049             }
2050             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2051                     .equals( "Aquifex" ) ) {
2052                 return false;
2053             }
2054             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2055             if ( parser.getErrorCount() > 0 ) {
2056                 System.out.println( parser.getErrorMessages().toString() );
2057                 return false;
2058             }
2059             if ( phylogenies_2.length != 1 ) {
2060                 return false;
2061             }
2062             final Phylogeny t3 = phylogenies_2[ 0 ];
2063             if ( t3.getNumberOfExternalNodes() != 184 ) {
2064                 return false;
2065             }
2066             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2067                 return false;
2068             }
2069             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2070                 return false;
2071             }
2072             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2073                 return false;
2074             }
2075             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2076             if ( parser.getErrorCount() > 0 ) {
2077                 System.out.println( parser.getErrorMessages().toString() );
2078                 return false;
2079             }
2080             if ( phylogenies_3.length != 1 ) {
2081                 return false;
2082             }
2083             final Phylogeny t4 = phylogenies_3[ 0 ];
2084             if ( t4.getNumberOfExternalNodes() != 1 ) {
2085                 return false;
2086             }
2087             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2088                 return false;
2089             }
2090             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2091                 return false;
2092             }
2093             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2094                 return false;
2095             }
2096             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2097             if ( parser.getErrorCount() > 0 ) {
2098                 System.out.println( parser.getErrorMessages().toString() );
2099                 return false;
2100             }
2101             if ( phylogenies_4.length != 1 ) {
2102                 return false;
2103             }
2104             final Phylogeny t5 = phylogenies_4[ 0 ];
2105             if ( t5.getNumberOfExternalNodes() != 13 ) {
2106                 return false;
2107             }
2108             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2109                 return false;
2110             }
2111             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2112                 return false;
2113             }
2114             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2115                 return false;
2116             }
2117         }
2118         catch ( final Exception e ) {
2119             e.printStackTrace( System.out );
2120             return false;
2121         }
2122         return true;
2123     }
2124
2125     private static boolean testBasicTreeMethods() {
2126         try {
2127             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2128             final Phylogeny t1 = factory.create();
2129             if ( !t1.isEmpty() ) {
2130                 return false;
2131             }
2132             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2133             if ( t2.getNumberOfExternalNodes() != 4 ) {
2134                 return false;
2135             }
2136             if ( t2.getHeight() != 8.5 ) {
2137                 return false;
2138             }
2139             if ( !t2.isCompletelyBinary() ) {
2140                 return false;
2141             }
2142             if ( t2.isEmpty() ) {
2143                 return false;
2144             }
2145             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2146             if ( t3.getNumberOfExternalNodes() != 5 ) {
2147                 return false;
2148             }
2149             if ( t3.getHeight() != 11 ) {
2150                 return false;
2151             }
2152             if ( t3.isCompletelyBinary() ) {
2153                 return false;
2154             }
2155             final PhylogenyNode n = t3.getNode( "ABC" );
2156             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 ];
2157             if ( t4.getNumberOfExternalNodes() != 9 ) {
2158                 return false;
2159             }
2160             if ( t4.getHeight() != 11 ) {
2161                 return false;
2162             }
2163             if ( t4.isCompletelyBinary() ) {
2164                 return false;
2165             }
2166             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)" );
2167             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2168             if ( t5.getNumberOfExternalNodes() != 8 ) {
2169                 return false;
2170             }
2171             if ( t5.getHeight() != 15 ) {
2172                 return false;
2173             }
2174             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)" );
2175             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2176             if ( t6.getHeight() != 15 ) {
2177                 return false;
2178             }
2179             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)" );
2180             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2181             if ( t7.getHeight() != 15 ) {
2182                 return false;
2183             }
2184             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)" );
2185             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2186             if ( t8.getNumberOfExternalNodes() != 10 ) {
2187                 return false;
2188             }
2189             if ( t8.getHeight() != 15 ) {
2190                 return false;
2191             }
2192             final char[] a9 = new char[] { 'a' };
2193             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2194             if ( t9.getHeight() != 0 ) {
2195                 return false;
2196             }
2197             final char[] a10 = new char[] { 'a', ':', '6' };
2198             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2199             if ( t10.getHeight() != 6 ) {
2200                 return false;
2201             }
2202         }
2203         catch ( final Exception e ) {
2204             e.printStackTrace( System.out );
2205             return false;
2206         }
2207         return true;
2208     }
2209
2210     private static boolean testTreeMethods() {
2211         try {
2212             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2213             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
2214             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
2215             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
2216                 System.out.println( t0.toNewHampshireX() );
2217                 return false;
2218             }
2219             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
2220             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
2221             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
2222                 return false;
2223             }
2224             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
2225                 return false;
2226             }
2227             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
2228                 return false;
2229             }
2230         }
2231         catch ( final Exception e ) {
2232             e.printStackTrace( System.out );
2233             return false;
2234         }
2235         return true;
2236     }
2237
2238     private static boolean testConfidenceAssessor() {
2239         try {
2240             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2241             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2242             final Phylogeny[] ev0 = factory
2243                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2244                              new NHXParser() );
2245             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2246             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2247                 return false;
2248             }
2249             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2250                 return false;
2251             }
2252             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2253             final Phylogeny[] ev1 = factory
2254                     .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)));",
2255                              new NHXParser() );
2256             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2257             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2258                 return false;
2259             }
2260             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2261                 return false;
2262             }
2263             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2264             final Phylogeny[] ev_b = factory
2265                     .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",
2266                              new NHXParser() );
2267             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2268             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2269                 return false;
2270             }
2271             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2272                 return false;
2273             }
2274             //
2275             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2276             final Phylogeny[] ev1x = factory
2277                     .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)));",
2278                              new NHXParser() );
2279             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2280             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2281                 return false;
2282             }
2283             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2284                 return false;
2285             }
2286             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2287             final Phylogeny[] ev_bx = factory
2288                     .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",
2289                              new NHXParser() );
2290             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2291             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2292                 return false;
2293             }
2294             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2295                 return false;
2296             }
2297             //
2298             final Phylogeny[] t2 = factory
2299                     .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);",
2300                              new NHXParser() );
2301             final Phylogeny[] ev2 = factory
2302                     .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);",
2303                              new NHXParser() );
2304             for( final Phylogeny target : t2 ) {
2305                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2306             }
2307             //
2308             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2309                                                  new NHXParser() )[ 0 ];
2310             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2311             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2312             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2313                 return false;
2314             }
2315             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2316                 return false;
2317             }
2318             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2319                 return false;
2320             }
2321         }
2322         catch ( final Exception e ) {
2323             e.printStackTrace();
2324             return false;
2325         }
2326         return true;
2327     }
2328
2329     private static boolean testCopyOfNodeData() {
2330         try {
2331             final PhylogenyNode n1 = PhylogenyNode
2332                     .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]" );
2333             final PhylogenyNode n2 = n1.copyNodeData();
2334             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2335                 return false;
2336             }
2337         }
2338         catch ( final Exception e ) {
2339             e.printStackTrace();
2340             return false;
2341         }
2342         return true;
2343     }
2344
2345     private static boolean testDataObjects() {
2346         try {
2347             final Confidence s0 = new Confidence();
2348             final Confidence s1 = new Confidence();
2349             if ( !s0.isEqual( s1 ) ) {
2350                 return false;
2351             }
2352             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2353             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2354             if ( s2.isEqual( s1 ) ) {
2355                 return false;
2356             }
2357             if ( !s2.isEqual( s3 ) ) {
2358                 return false;
2359             }
2360             final Confidence s4 = ( Confidence ) s3.copy();
2361             if ( !s4.isEqual( s3 ) ) {
2362                 return false;
2363             }
2364             s3.asSimpleText();
2365             s3.asText();
2366             // Taxonomy
2367             // ----------
2368             final Taxonomy t1 = new Taxonomy();
2369             final Taxonomy t2 = new Taxonomy();
2370             final Taxonomy t3 = new Taxonomy();
2371             final Taxonomy t4 = new Taxonomy();
2372             final Taxonomy t5 = new Taxonomy();
2373             t1.setIdentifier( new Identifier( "ecoli" ) );
2374             t1.setTaxonomyCode( "ECOLI" );
2375             t1.setScientificName( "E. coli" );
2376             t1.setCommonName( "coli" );
2377             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2378             if ( !t1.isEqual( t0 ) ) {
2379                 return false;
2380             }
2381             t2.setIdentifier( new Identifier( "ecoli" ) );
2382             t2.setTaxonomyCode( "OTHER" );
2383             t2.setScientificName( "what" );
2384             t2.setCommonName( "something" );
2385             if ( !t1.isEqual( t2 ) ) {
2386                 return false;
2387             }
2388             t2.setIdentifier( new Identifier( "nemve" ) );
2389             if ( t1.isEqual( t2 ) ) {
2390                 return false;
2391             }
2392             t1.setIdentifier( null );
2393             t3.setTaxonomyCode( "ECOLI" );
2394             t3.setScientificName( "what" );
2395             t3.setCommonName( "something" );
2396             if ( !t1.isEqual( t3 ) ) {
2397                 return false;
2398             }
2399             t1.setIdentifier( null );
2400             t1.setTaxonomyCode( "" );
2401             t4.setScientificName( "E. ColI" );
2402             t4.setCommonName( "something" );
2403             if ( !t1.isEqual( t4 ) ) {
2404                 return false;
2405             }
2406             t4.setScientificName( "B. subtilis" );
2407             t4.setCommonName( "something" );
2408             if ( t1.isEqual( t4 ) ) {
2409                 return false;
2410             }
2411             t1.setIdentifier( null );
2412             t1.setTaxonomyCode( "" );
2413             t1.setScientificName( "" );
2414             t5.setCommonName( "COLI" );
2415             if ( !t1.isEqual( t5 ) ) {
2416                 return false;
2417             }
2418             t5.setCommonName( "vibrio" );
2419             if ( t1.isEqual( t5 ) ) {
2420                 return false;
2421             }
2422             // Identifier
2423             // ----------
2424             final Identifier id0 = new Identifier( "123", "pfam" );
2425             final Identifier id1 = ( Identifier ) id0.copy();
2426             if ( !id1.isEqual( id1 ) ) {
2427                 return false;
2428             }
2429             if ( !id1.isEqual( id0 ) ) {
2430                 return false;
2431             }
2432             if ( !id0.isEqual( id1 ) ) {
2433                 return false;
2434             }
2435             id1.asSimpleText();
2436             id1.asText();
2437             // ProteinDomain
2438             // ---------------
2439             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2440             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2441             if ( !pd1.isEqual( pd1 ) ) {
2442                 return false;
2443             }
2444             if ( !pd1.isEqual( pd0 ) ) {
2445                 return false;
2446             }
2447             pd1.asSimpleText();
2448             pd1.asText();
2449             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2450             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2451             if ( !pd3.isEqual( pd3 ) ) {
2452                 return false;
2453             }
2454             if ( !pd2.isEqual( pd3 ) ) {
2455                 return false;
2456             }
2457             if ( !pd0.isEqual( pd3 ) ) {
2458                 return false;
2459             }
2460             pd3.asSimpleText();
2461             pd3.asText();
2462             // DomainArchitecture
2463             // ------------------
2464             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2465             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2466             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2467             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2468             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2469             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2470             domains0.add( d2 );
2471             domains0.add( d0 );
2472             domains0.add( d3 );
2473             domains0.add( d1 );
2474             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2475             if ( ds0.getNumberOfDomains() != 4 ) {
2476                 return false;
2477             }
2478             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2479             if ( !ds0.isEqual( ds0 ) ) {
2480                 return false;
2481             }
2482             if ( !ds0.isEqual( ds1 ) ) {
2483                 return false;
2484             }
2485             if ( ds1.getNumberOfDomains() != 4 ) {
2486                 return false;
2487             }
2488             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2489             domains1.add( d1 );
2490             domains1.add( d2 );
2491             domains1.add( d4 );
2492             domains1.add( d0 );
2493             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2494             if ( ds0.isEqual( ds2 ) ) {
2495                 return false;
2496             }
2497             ds1.asSimpleText();
2498             ds1.asText();
2499             ds1.toNHX();
2500             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2501             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2502                 System.out.println( ds3.toNHX() );
2503                 return false;
2504             }
2505             if ( ds3.getNumberOfDomains() != 3 ) {
2506                 return false;
2507             }
2508             // Event
2509             // -----
2510             final Event e1 = new Event( Event.EventType.fusion );
2511             if ( e1.isDuplication() ) {
2512                 return false;
2513             }
2514             if ( !e1.isFusion() ) {
2515                 return false;
2516             }
2517             if ( !e1.asText().toString().equals( "fusion" ) ) {
2518                 return false;
2519             }
2520             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2521                 return false;
2522             }
2523             final Event e11 = new Event( Event.EventType.fusion );
2524             if ( !e11.isEqual( e1 ) ) {
2525                 return false;
2526             }
2527             if ( !e11.toNHX().toString().equals( "" ) ) {
2528                 return false;
2529             }
2530             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2531             if ( e2.isDuplication() ) {
2532                 return false;
2533             }
2534             if ( !e2.isSpeciationOrDuplication() ) {
2535                 return false;
2536             }
2537             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2538                 return false;
2539             }
2540             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2541                 return false;
2542             }
2543             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2544                 return false;
2545             }
2546             if ( e11.isEqual( e2 ) ) {
2547                 return false;
2548             }
2549             final Event e2c = ( Event ) e2.copy();
2550             if ( !e2c.isEqual( e2 ) ) {
2551                 return false;
2552             }
2553             Event e3 = new Event( 1, 2, 3 );
2554             if ( e3.isDuplication() ) {
2555                 return false;
2556             }
2557             if ( e3.isSpeciation() ) {
2558                 return false;
2559             }
2560             if ( e3.isGeneLoss() ) {
2561                 return false;
2562             }
2563             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2564                 return false;
2565             }
2566             final Event e3c = ( Event ) e3.copy();
2567             final Event e3cc = ( Event ) e3c.copy();
2568             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2569                 return false;
2570             }
2571             e3 = null;
2572             if ( !e3c.isEqual( e3cc ) ) {
2573                 return false;
2574             }
2575             Event e4 = new Event( 1, 2, 3 );
2576             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2577                 return false;
2578             }
2579             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2580                 return false;
2581             }
2582             final Event e4c = ( Event ) e4.copy();
2583             e4 = null;
2584             final Event e4cc = ( Event ) e4c.copy();
2585             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2586                 return false;
2587             }
2588             if ( !e4c.isEqual( e4cc ) ) {
2589                 return false;
2590             }
2591             final Event e5 = new Event();
2592             if ( !e5.isUnassigned() ) {
2593                 return false;
2594             }
2595             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2596                 return false;
2597             }
2598             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2599                 return false;
2600             }
2601             final Event e6 = new Event( 1, 0, 0 );
2602             if ( !e6.asText().toString().equals( "duplication" ) ) {
2603                 return false;
2604             }
2605             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2606                 return false;
2607             }
2608             final Event e7 = new Event( 0, 1, 0 );
2609             if ( !e7.asText().toString().equals( "speciation" ) ) {
2610                 return false;
2611             }
2612             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2613                 return false;
2614             }
2615             final Event e8 = new Event( 0, 0, 1 );
2616             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2617                 return false;
2618             }
2619             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2620                 return false;
2621             }
2622         }
2623         catch ( final Exception e ) {
2624             e.printStackTrace( System.out );
2625             return false;
2626         }
2627         return true;
2628     }
2629
2630     private static boolean testDeletionOfExternalNodes() {
2631         try {
2632             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2633             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2634             final PhylogenyWriter w = new PhylogenyWriter();
2635             if ( t0.isEmpty() ) {
2636                 return false;
2637             }
2638             if ( t0.getNumberOfExternalNodes() != 1 ) {
2639                 return false;
2640             }
2641             t0.deleteSubtree( t0.getNode( "A" ), false );
2642             if ( t0.getNumberOfExternalNodes() != 0 ) {
2643                 return false;
2644             }
2645             if ( !t0.isEmpty() ) {
2646                 return false;
2647             }
2648             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2649             if ( t1.getNumberOfExternalNodes() != 2 ) {
2650                 return false;
2651             }
2652             t1.deleteSubtree( t1.getNode( "A" ), false );
2653             if ( t1.getNumberOfExternalNodes() != 1 ) {
2654                 return false;
2655             }
2656             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2657                 return false;
2658             }
2659             t1.deleteSubtree( t1.getNode( "B" ), false );
2660             if ( t1.getNumberOfExternalNodes() != 1 ) {
2661                 return false;
2662             }
2663             t1.deleteSubtree( t1.getNode( "r" ), false );
2664             if ( !t1.isEmpty() ) {
2665                 return false;
2666             }
2667             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2668             if ( t2.getNumberOfExternalNodes() != 3 ) {
2669                 return false;
2670             }
2671             t2.deleteSubtree( t2.getNode( "B" ), false );
2672             if ( t2.getNumberOfExternalNodes() != 2 ) {
2673                 return false;
2674             }
2675             t2.toNewHampshireX();
2676             PhylogenyNode n = t2.getNode( "A" );
2677             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2678                 return false;
2679             }
2680             t2.deleteSubtree( t2.getNode( "A" ), false );
2681             if ( t2.getNumberOfExternalNodes() != 2 ) {
2682                 return false;
2683             }
2684             t2.deleteSubtree( t2.getNode( "C" ), true );
2685             if ( t2.getNumberOfExternalNodes() != 1 ) {
2686                 return false;
2687             }
2688             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2689             if ( t3.getNumberOfExternalNodes() != 4 ) {
2690                 return false;
2691             }
2692             t3.deleteSubtree( t3.getNode( "B" ), true );
2693             if ( t3.getNumberOfExternalNodes() != 3 ) {
2694                 return false;
2695             }
2696             n = t3.getNode( "A" );
2697             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2698                 return false;
2699             }
2700             n = n.getNextExternalNode();
2701             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2702                 return false;
2703             }
2704             t3.deleteSubtree( t3.getNode( "A" ), true );
2705             if ( t3.getNumberOfExternalNodes() != 2 ) {
2706                 return false;
2707             }
2708             n = t3.getNode( "C" );
2709             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2710                 return false;
2711             }
2712             t3.deleteSubtree( t3.getNode( "C" ), true );
2713             if ( t3.getNumberOfExternalNodes() != 1 ) {
2714                 return false;
2715             }
2716             t3.deleteSubtree( t3.getNode( "D" ), true );
2717             if ( t3.getNumberOfExternalNodes() != 0 ) {
2718                 return false;
2719             }
2720             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2721             if ( t4.getNumberOfExternalNodes() != 6 ) {
2722                 return false;
2723             }
2724             t4.deleteSubtree( t4.getNode( "B2" ), true );
2725             if ( t4.getNumberOfExternalNodes() != 5 ) {
2726                 return false;
2727             }
2728             String s = w.toNewHampshire( t4, false, true ).toString();
2729             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2730                 return false;
2731             }
2732             t4.deleteSubtree( t4.getNode( "B11" ), true );
2733             if ( t4.getNumberOfExternalNodes() != 4 ) {
2734                 return false;
2735             }
2736             t4.deleteSubtree( t4.getNode( "C" ), true );
2737             if ( t4.getNumberOfExternalNodes() != 3 ) {
2738                 return false;
2739             }
2740             n = t4.getNode( "A" );
2741             n = n.getNextExternalNode();
2742             if ( !n.getName().equals( "B12" ) ) {
2743                 return false;
2744             }
2745             n = n.getNextExternalNode();
2746             if ( !n.getName().equals( "D" ) ) {
2747                 return false;
2748             }
2749             s = w.toNewHampshire( t4, false, true ).toString();
2750             if ( !s.equals( "((A,B12),D);" ) ) {
2751                 return false;
2752             }
2753             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2754             t5.deleteSubtree( t5.getNode( "A" ), true );
2755             if ( t5.getNumberOfExternalNodes() != 5 ) {
2756                 return false;
2757             }
2758             s = w.toNewHampshire( t5, false, true ).toString();
2759             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2760                 return false;
2761             }
2762             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2763             t6.deleteSubtree( t6.getNode( "B11" ), true );
2764             if ( t6.getNumberOfExternalNodes() != 5 ) {
2765                 return false;
2766             }
2767             s = w.toNewHampshire( t6, false, false ).toString();
2768             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2769                 return false;
2770             }
2771             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2772             t7.deleteSubtree( t7.getNode( "B12" ), true );
2773             if ( t7.getNumberOfExternalNodes() != 5 ) {
2774                 return false;
2775             }
2776             s = w.toNewHampshire( t7, false, true ).toString();
2777             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2778                 return false;
2779             }
2780             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2781             t8.deleteSubtree( t8.getNode( "B2" ), true );
2782             if ( t8.getNumberOfExternalNodes() != 5 ) {
2783                 return false;
2784             }
2785             s = w.toNewHampshire( t8, false, false ).toString();
2786             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2787                 return false;
2788             }
2789             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2790             t9.deleteSubtree( t9.getNode( "C" ), true );
2791             if ( t9.getNumberOfExternalNodes() != 5 ) {
2792                 return false;
2793             }
2794             s = w.toNewHampshire( t9, false, true ).toString();
2795             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2796                 return false;
2797             }
2798             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2799             t10.deleteSubtree( t10.getNode( "D" ), true );
2800             if ( t10.getNumberOfExternalNodes() != 5 ) {
2801                 return false;
2802             }
2803             s = w.toNewHampshire( t10, false, true ).toString();
2804             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2805                 return false;
2806             }
2807             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2808             t11.deleteSubtree( t11.getNode( "A" ), true );
2809             if ( t11.getNumberOfExternalNodes() != 2 ) {
2810                 return false;
2811             }
2812             s = w.toNewHampshire( t11, false, true ).toString();
2813             if ( !s.equals( "(B,C);" ) ) {
2814                 return false;
2815             }
2816             t11.deleteSubtree( t11.getNode( "C" ), true );
2817             if ( t11.getNumberOfExternalNodes() != 1 ) {
2818                 return false;
2819             }
2820             s = w.toNewHampshire( t11, false, false ).toString();
2821             if ( !s.equals( "B;" ) ) {
2822                 return false;
2823             }
2824             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2825             t12.deleteSubtree( t12.getNode( "B2" ), true );
2826             if ( t12.getNumberOfExternalNodes() != 8 ) {
2827                 return false;
2828             }
2829             s = w.toNewHampshire( t12, false, true ).toString();
2830             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2831                 return false;
2832             }
2833             t12.deleteSubtree( t12.getNode( "B3" ), true );
2834             if ( t12.getNumberOfExternalNodes() != 7 ) {
2835                 return false;
2836             }
2837             s = w.toNewHampshire( t12, false, true ).toString();
2838             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2839                 return false;
2840             }
2841             t12.deleteSubtree( t12.getNode( "C3" ), true );
2842             if ( t12.getNumberOfExternalNodes() != 6 ) {
2843                 return false;
2844             }
2845             s = w.toNewHampshire( t12, false, true ).toString();
2846             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2847                 return false;
2848             }
2849             t12.deleteSubtree( t12.getNode( "A1" ), true );
2850             if ( t12.getNumberOfExternalNodes() != 5 ) {
2851                 return false;
2852             }
2853             s = w.toNewHampshire( t12, false, true ).toString();
2854             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2855                 return false;
2856             }
2857             t12.deleteSubtree( t12.getNode( "B1" ), true );
2858             if ( t12.getNumberOfExternalNodes() != 4 ) {
2859                 return false;
2860             }
2861             s = w.toNewHampshire( t12, false, true ).toString();
2862             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2863                 return false;
2864             }
2865             t12.deleteSubtree( t12.getNode( "A3" ), true );
2866             if ( t12.getNumberOfExternalNodes() != 3 ) {
2867                 return false;
2868             }
2869             s = w.toNewHampshire( t12, false, true ).toString();
2870             if ( !s.equals( "(A2,(C1,C2));" ) ) {
2871                 return false;
2872             }
2873             t12.deleteSubtree( t12.getNode( "A2" ), true );
2874             if ( t12.getNumberOfExternalNodes() != 2 ) {
2875                 return false;
2876             }
2877             s = w.toNewHampshire( t12, false, true ).toString();
2878             if ( !s.equals( "(C1,C2);" ) ) {
2879                 return false;
2880             }
2881             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2882             t13.deleteSubtree( t13.getNode( "D" ), true );
2883             if ( t13.getNumberOfExternalNodes() != 4 ) {
2884                 return false;
2885             }
2886             s = w.toNewHampshire( t13, false, true ).toString();
2887             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2888                 return false;
2889             }
2890             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2891             t14.deleteSubtree( t14.getNode( "E" ), true );
2892             if ( t14.getNumberOfExternalNodes() != 5 ) {
2893                 return false;
2894             }
2895             s = w.toNewHampshire( t14, false, true ).toString();
2896             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2897                 return false;
2898             }
2899             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2900             t15.deleteSubtree( t15.getNode( "B2" ), true );
2901             if ( t15.getNumberOfExternalNodes() != 11 ) {
2902                 return false;
2903             }
2904             t15.deleteSubtree( t15.getNode( "B1" ), true );
2905             if ( t15.getNumberOfExternalNodes() != 10 ) {
2906                 return false;
2907             }
2908             t15.deleteSubtree( t15.getNode( "B3" ), true );
2909             if ( t15.getNumberOfExternalNodes() != 9 ) {
2910                 return false;
2911             }
2912             t15.deleteSubtree( t15.getNode( "B4" ), true );
2913             if ( t15.getNumberOfExternalNodes() != 8 ) {
2914                 return false;
2915             }
2916             t15.deleteSubtree( t15.getNode( "A1" ), true );
2917             if ( t15.getNumberOfExternalNodes() != 7 ) {
2918                 return false;
2919             }
2920             t15.deleteSubtree( t15.getNode( "C4" ), true );
2921             if ( t15.getNumberOfExternalNodes() != 6 ) {
2922                 return false;
2923             }
2924         }
2925         catch ( final Exception e ) {
2926             e.printStackTrace( System.out );
2927             return false;
2928         }
2929         return true;
2930     }
2931
2932     private static boolean testDescriptiveStatistics() {
2933         try {
2934             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2935             dss1.addValue( 82 );
2936             dss1.addValue( 78 );
2937             dss1.addValue( 70 );
2938             dss1.addValue( 58 );
2939             dss1.addValue( 42 );
2940             if ( dss1.getN() != 5 ) {
2941                 return false;
2942             }
2943             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2944                 return false;
2945             }
2946             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2947                 return false;
2948             }
2949             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2950                 return false;
2951             }
2952             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2953                 return false;
2954             }
2955             if ( !Test.isEqual( dss1.median(), 70 ) ) {
2956                 return false;
2957             }
2958             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2959                 return false;
2960             }
2961             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2962                 return false;
2963             }
2964             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2965                 return false;
2966             }
2967             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2968                 return false;
2969             }
2970             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2971                 return false;
2972             }
2973             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2974                 return false;
2975             }
2976             dss1.addValue( 123 );
2977             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
2978                 return false;
2979             }
2980             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
2981                 return false;
2982             }
2983             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
2984                 return false;
2985             }
2986             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
2987             dss2.addValue( -1.85 );
2988             dss2.addValue( 57.5 );
2989             dss2.addValue( 92.78 );
2990             dss2.addValue( 57.78 );
2991             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
2992                 return false;
2993             }
2994             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
2995                 return false;
2996             }
2997             final double[] a = dss2.getDataAsDoubleArray();
2998             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
2999                 return false;
3000             }
3001             dss2.addValue( -100 );
3002             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3003                 return false;
3004             }
3005             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3006                 return false;
3007             }
3008             final double[] ds = new double[ 14 ];
3009             ds[ 0 ] = 34;
3010             ds[ 1 ] = 23;
3011             ds[ 2 ] = 1;
3012             ds[ 3 ] = 32;
3013             ds[ 4 ] = 11;
3014             ds[ 5 ] = 2;
3015             ds[ 6 ] = 12;
3016             ds[ 7 ] = 33;
3017             ds[ 8 ] = 13;
3018             ds[ 9 ] = 22;
3019             ds[ 10 ] = 21;
3020             ds[ 11 ] = 35;
3021             ds[ 12 ] = 24;
3022             ds[ 13 ] = 31;
3023             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3024             if ( bins.length != 4 ) {
3025                 return false;
3026             }
3027             if ( bins[ 0 ] != 2 ) {
3028                 return false;
3029             }
3030             if ( bins[ 1 ] != 3 ) {
3031                 return false;
3032             }
3033             if ( bins[ 2 ] != 4 ) {
3034                 return false;
3035             }
3036             if ( bins[ 3 ] != 5 ) {
3037                 return false;
3038             }
3039             final double[] ds1 = new double[ 9 ];
3040             ds1[ 0 ] = 10.0;
3041             ds1[ 1 ] = 19.0;
3042             ds1[ 2 ] = 9.999;
3043             ds1[ 3 ] = 0.0;
3044             ds1[ 4 ] = 39.9;
3045             ds1[ 5 ] = 39.999;
3046             ds1[ 6 ] = 30.0;
3047             ds1[ 7 ] = 19.999;
3048             ds1[ 8 ] = 30.1;
3049             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3050             if ( bins1.length != 4 ) {
3051                 return false;
3052             }
3053             if ( bins1[ 0 ] != 2 ) {
3054                 return false;
3055             }
3056             if ( bins1[ 1 ] != 3 ) {
3057                 return false;
3058             }
3059             if ( bins1[ 2 ] != 0 ) {
3060                 return false;
3061             }
3062             if ( bins1[ 3 ] != 4 ) {
3063                 return false;
3064             }
3065             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3066             if ( bins1_1.length != 3 ) {
3067                 return false;
3068             }
3069             if ( bins1_1[ 0 ] != 3 ) {
3070                 return false;
3071             }
3072             if ( bins1_1[ 1 ] != 2 ) {
3073                 return false;
3074             }
3075             if ( bins1_1[ 2 ] != 4 ) {
3076                 return false;
3077             }
3078             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3079             if ( bins1_2.length != 3 ) {
3080                 return false;
3081             }
3082             if ( bins1_2[ 0 ] != 2 ) {
3083                 return false;
3084             }
3085             if ( bins1_2[ 1 ] != 2 ) {
3086                 return false;
3087             }
3088             if ( bins1_2[ 2 ] != 2 ) {
3089                 return false;
3090             }
3091             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3092             dss3.addValue( 1 );
3093             dss3.addValue( 1 );
3094             dss3.addValue( 1 );
3095             dss3.addValue( 2 );
3096             dss3.addValue( 3 );
3097             dss3.addValue( 4 );
3098             dss3.addValue( 5 );
3099             dss3.addValue( 5 );
3100             dss3.addValue( 5 );
3101             dss3.addValue( 6 );
3102             dss3.addValue( 7 );
3103             dss3.addValue( 8 );
3104             dss3.addValue( 9 );
3105             dss3.addValue( 10 );
3106             dss3.addValue( 10 );
3107             dss3.addValue( 10 );
3108             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3109             histo.toStringBuffer( 10, '=', 40, 5 );
3110             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3111         }
3112         catch ( final Exception e ) {
3113             e.printStackTrace( System.out );
3114             return false;
3115         }
3116         return true;
3117     }
3118
3119     private static boolean testDir( final String file ) {
3120         try {
3121             final File f = new File( file );
3122             if ( !f.exists() ) {
3123                 return false;
3124             }
3125             if ( !f.isDirectory() ) {
3126                 return false;
3127             }
3128             if ( !f.canRead() ) {
3129                 return false;
3130             }
3131         }
3132         catch ( final Exception e ) {
3133             return false;
3134         }
3135         return true;
3136     }
3137
3138     private static boolean testExternalNodeRelatedMethods() {
3139         try {
3140             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3141             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3142             PhylogenyNode n = t1.getNode( "A" );
3143             n = n.getNextExternalNode();
3144             if ( !n.getName().equals( "B" ) ) {
3145                 return false;
3146             }
3147             n = n.getNextExternalNode();
3148             if ( !n.getName().equals( "C" ) ) {
3149                 return false;
3150             }
3151             n = n.getNextExternalNode();
3152             if ( !n.getName().equals( "D" ) ) {
3153                 return false;
3154             }
3155             n = t1.getNode( "B" );
3156             while ( !n.isLastExternalNode() ) {
3157                 n = n.getNextExternalNode();
3158             }
3159             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3160             n = t2.getNode( "A" );
3161             n = n.getNextExternalNode();
3162             if ( !n.getName().equals( "B" ) ) {
3163                 return false;
3164             }
3165             n = n.getNextExternalNode();
3166             if ( !n.getName().equals( "C" ) ) {
3167                 return false;
3168             }
3169             n = n.getNextExternalNode();
3170             if ( !n.getName().equals( "D" ) ) {
3171                 return false;
3172             }
3173             n = t2.getNode( "B" );
3174             while ( !n.isLastExternalNode() ) {
3175                 n = n.getNextExternalNode();
3176             }
3177             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3178             n = t3.getNode( "A" );
3179             n = n.getNextExternalNode();
3180             if ( !n.getName().equals( "B" ) ) {
3181                 return false;
3182             }
3183             n = n.getNextExternalNode();
3184             if ( !n.getName().equals( "C" ) ) {
3185                 return false;
3186             }
3187             n = n.getNextExternalNode();
3188             if ( !n.getName().equals( "D" ) ) {
3189                 return false;
3190             }
3191             n = n.getNextExternalNode();
3192             if ( !n.getName().equals( "E" ) ) {
3193                 return false;
3194             }
3195             n = n.getNextExternalNode();
3196             if ( !n.getName().equals( "F" ) ) {
3197                 return false;
3198             }
3199             n = n.getNextExternalNode();
3200             if ( !n.getName().equals( "G" ) ) {
3201                 return false;
3202             }
3203             n = n.getNextExternalNode();
3204             if ( !n.getName().equals( "H" ) ) {
3205                 return false;
3206             }
3207             n = t3.getNode( "B" );
3208             while ( !n.isLastExternalNode() ) {
3209                 n = n.getNextExternalNode();
3210             }
3211             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3212             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3213                 final PhylogenyNode node = iter.next();
3214             }
3215             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3216             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3217                 final PhylogenyNode node = iter.next();
3218             }
3219             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3220             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3221             if ( !iter.next().getName().equals( "A" ) ) {
3222                 return false;
3223             }
3224             if ( !iter.next().getName().equals( "B" ) ) {
3225                 return false;
3226             }
3227             if ( !iter.next().getName().equals( "C" ) ) {
3228                 return false;
3229             }
3230             if ( !iter.next().getName().equals( "D" ) ) {
3231                 return false;
3232             }
3233             if ( !iter.next().getName().equals( "E" ) ) {
3234                 return false;
3235             }
3236             if ( !iter.next().getName().equals( "F" ) ) {
3237                 return false;
3238             }
3239             if ( iter.hasNext() ) {
3240                 return false;
3241             }
3242         }
3243         catch ( final Exception e ) {
3244             e.printStackTrace( System.out );
3245             return false;
3246         }
3247         return true;
3248     }
3249
3250     private static boolean testGeneralTable() {
3251         try {
3252             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3253             t0.setValue( 3, 2, "23" );
3254             t0.setValue( 10, 1, "error" );
3255             t0.setValue( 10, 1, "110" );
3256             t0.setValue( 9, 1, "19" );
3257             t0.setValue( 1, 10, "101" );
3258             t0.setValue( 10, 10, "1010" );
3259             t0.setValue( 100, 10, "10100" );
3260             t0.setValue( 0, 0, "00" );
3261             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3262                 return false;
3263             }
3264             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3265                 return false;
3266             }
3267             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3268                 return false;
3269             }
3270             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3271                 return false;
3272             }
3273             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3274                 return false;
3275             }
3276             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3277                 return false;
3278             }
3279             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3280                 return false;
3281             }
3282             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3283                 return false;
3284             }
3285             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3286                 return false;
3287             }
3288             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3289             t1.setValue( "3", "2", "23" );
3290             t1.setValue( "10", "1", "error" );
3291             t1.setValue( "10", "1", "110" );
3292             t1.setValue( "9", "1", "19" );
3293             t1.setValue( "1", "10", "101" );
3294             t1.setValue( "10", "10", "1010" );
3295             t1.setValue( "100", "10", "10100" );
3296             t1.setValue( "0", "0", "00" );
3297             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3298             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3299                 return false;
3300             }
3301             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3302                 return false;
3303             }
3304             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3305                 return false;
3306             }
3307             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3308                 return false;
3309             }
3310             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3311                 return false;
3312             }
3313             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3314                 return false;
3315             }
3316             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3317                 return false;
3318             }
3319             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3320                 return false;
3321             }
3322             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3323                 return false;
3324             }
3325             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3326                 return false;
3327             }
3328         }
3329         catch ( final Exception e ) {
3330             e.printStackTrace( System.out );
3331             return false;
3332         }
3333         return true;
3334     }
3335
3336     private static boolean testGetDistance() {
3337         try {
3338             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3339             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",
3340                                                  new NHXParser() )[ 0 ];
3341             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3342                 return false;
3343             }
3344             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3345                 return false;
3346             }
3347             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3348                 return false;
3349             }
3350             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3351                 return false;
3352             }
3353             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3354                 return false;
3355             }
3356             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3357                 return false;
3358             }
3359             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3360                 return false;
3361             }
3362             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3363                 return false;
3364             }
3365             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3366                 return false;
3367             }
3368             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3369                 return false;
3370             }
3371             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3372                 return false;
3373             }
3374             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3375                 return false;
3376             }
3377             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3378                 return false;
3379             }
3380             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3381                 return false;
3382             }
3383             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3384                 return false;
3385             }
3386             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3387                 return false;
3388             }
3389             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3390                 return false;
3391             }
3392             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3393                 return false;
3394             }
3395             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3396                 return false;
3397             }
3398             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3399                 return false;
3400             }
3401             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3402                 return false;
3403             }
3404             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3405                 return false;
3406             }
3407             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3408                 return false;
3409             }
3410             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3411                 return false;
3412             }
3413             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3414                 return false;
3415             }
3416             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3417                 return false;
3418             }
3419             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3420                 return false;
3421             }
3422             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3423                 return false;
3424             }
3425             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3426                 return false;
3427             }
3428             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3429                 return false;
3430             }
3431             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3432                 return false;
3433             }
3434             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",
3435                                                  new NHXParser() )[ 0 ];
3436             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3437                 return false;
3438             }
3439             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3440                 return false;
3441             }
3442             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3443                 return false;
3444             }
3445             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3446                 return false;
3447             }
3448             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3449                 return false;
3450             }
3451             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3452                 return false;
3453             }
3454             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3455                 return false;
3456             }
3457             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3458                 return false;
3459             }
3460             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3461                 return false;
3462             }
3463             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3464                 return false;
3465             }
3466             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3467                 return false;
3468             }
3469         }
3470         catch ( final Exception e ) {
3471             e.printStackTrace( System.out );
3472             return false;
3473         }
3474         return true;
3475     }
3476
3477     private static boolean testGetLCA() {
3478         try {
3479             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3480             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3481                                                  new NHXParser() )[ 0 ];
3482             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3483             if ( !A.getName().equals( "A" ) ) {
3484                 return false;
3485             }
3486             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3487             if ( !gh.getName().equals( "gh" ) ) {
3488                 return false;
3489             }
3490             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3491             if ( !ab.getName().equals( "ab" ) ) {
3492                 return false;
3493             }
3494             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3495             if ( !ab2.getName().equals( "ab" ) ) {
3496                 return false;
3497             }
3498             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3499             if ( !gh2.getName().equals( "gh" ) ) {
3500                 return false;
3501             }
3502             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3503             if ( !gh3.getName().equals( "gh" ) ) {
3504                 return false;
3505             }
3506             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3507             if ( !abc.getName().equals( "abc" ) ) {
3508                 return false;
3509             }
3510             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3511             if ( !abc2.getName().equals( "abc" ) ) {
3512                 return false;
3513             }
3514             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3515             if ( !abcd.getName().equals( "abcd" ) ) {
3516                 return false;
3517             }
3518             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3519             if ( !abcd2.getName().equals( "abcd" ) ) {
3520                 return false;
3521             }
3522             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3523             if ( !abcdef.getName().equals( "abcdef" ) ) {
3524                 return false;
3525             }
3526             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3527             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3528                 return false;
3529             }
3530             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3531             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3532                 return false;
3533             }
3534             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3535             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3536                 return false;
3537             }
3538             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3539             if ( !abcde.getName().equals( "abcde" ) ) {
3540                 return false;
3541             }
3542             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3543             if ( !abcde2.getName().equals( "abcde" ) ) {
3544                 return false;
3545             }
3546             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3547             if ( !r.getName().equals( "abcdefgh" ) ) {
3548                 return false;
3549             }
3550             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3551             if ( !r2.getName().equals( "abcdefgh" ) ) {
3552                 return false;
3553             }
3554             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3555             if ( !r3.getName().equals( "abcdefgh" ) ) {
3556                 return false;
3557             }
3558             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3559             if ( !abcde3.getName().equals( "abcde" ) ) {
3560                 return false;
3561             }
3562             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3563             if ( !abcde4.getName().equals( "abcde" ) ) {
3564                 return false;
3565             }
3566             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3567             if ( !ab3.getName().equals( "ab" ) ) {
3568                 return false;
3569             }
3570             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3571             if ( !ab4.getName().equals( "ab" ) ) {
3572                 return false;
3573             }
3574             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3575             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3576             if ( !cd.getName().equals( "cd" ) ) {
3577                 return false;
3578             }
3579             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3580             if ( !cd2.getName().equals( "cd" ) ) {
3581                 return false;
3582             }
3583             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3584             if ( !cde.getName().equals( "cde" ) ) {
3585                 return false;
3586             }
3587             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3588             if ( !cde2.getName().equals( "cde" ) ) {
3589                 return false;
3590             }
3591             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3592             if ( !cdef.getName().equals( "cdef" ) ) {
3593                 return false;
3594             }
3595             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3596             if ( !cdef2.getName().equals( "cdef" ) ) {
3597                 return false;
3598             }
3599             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3600             if ( !cdef3.getName().equals( "cdef" ) ) {
3601                 return false;
3602             }
3603             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3604             if ( !rt.getName().equals( "r" ) ) {
3605                 return false;
3606             }
3607             final Phylogeny p3 = factory
3608                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3609                              new NHXParser() )[ 0 ];
3610             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3611             if ( !bc_3.getName().equals( "bc" ) ) {
3612                 return false;
3613             }
3614             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3615             if ( !ac_3.getName().equals( "abc" ) ) {
3616                 return false;
3617             }
3618             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3619             if ( !ad_3.getName().equals( "abcde" ) ) {
3620                 return false;
3621             }
3622             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3623             if ( !af_3.getName().equals( "abcdef" ) ) {
3624                 return false;
3625             }
3626             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3627             if ( !ag_3.getName().equals( "" ) ) {
3628                 return false;
3629             }
3630             if ( !ag_3.isRoot() ) {
3631                 return false;
3632             }
3633             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3634             if ( !al_3.getName().equals( "" ) ) {
3635                 return false;
3636             }
3637             if ( !al_3.isRoot() ) {
3638                 return false;
3639             }
3640             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3641             if ( !kl_3.getName().equals( "" ) ) {
3642                 return false;
3643             }
3644             if ( !kl_3.isRoot() ) {
3645                 return false;
3646             }
3647             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3648             if ( !fl_3.getName().equals( "" ) ) {
3649                 return false;
3650             }
3651             if ( !fl_3.isRoot() ) {
3652                 return false;
3653             }
3654             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3655             if ( !gk_3.getName().equals( "ghijk" ) ) {
3656                 return false;
3657             }
3658             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3659             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3660             if ( !r_4.getName().equals( "r" ) ) {
3661                 return false;
3662             }
3663             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3664             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3665             if ( !r_5.getName().equals( "root" ) ) {
3666                 return false;
3667             }
3668             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3669             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3670             if ( !r_6.getName().equals( "rot" ) ) {
3671                 return false;
3672             }
3673             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3674             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3675             if ( !r_7.getName().equals( "rott" ) ) {
3676                 return false;
3677             }
3678         }
3679         catch ( final Exception e ) {
3680             e.printStackTrace( System.out );
3681             return false;
3682         }
3683         return true;
3684     }
3685
3686     private static boolean testGetLCA2() {
3687         try {
3688             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3689             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3690             PhylogenyMethods.preOrderReId( p_a );
3691             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3692                                                                                               p_a.getNode( "a" ) );
3693             if ( !p_a_1.getName().equals( "a" ) ) {
3694                 return false;
3695             }
3696             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3697             PhylogenyMethods.preOrderReId( p_b );
3698             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3699                                                                                               p_b.getNode( "a" ) );
3700             if ( !p_b_1.getName().equals( "b" ) ) {
3701                 return false;
3702             }
3703             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3704                                                                                               p_b.getNode( "b" ) );
3705             if ( !p_b_2.getName().equals( "b" ) ) {
3706                 return false;
3707             }
3708             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3709             PhylogenyMethods.preOrderReId( p_c );
3710             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3711                                                                                               p_c.getNode( "a" ) );
3712             if ( !p_c_1.getName().equals( "b" ) ) {
3713                 return false;
3714             }
3715             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3716                                                                                               p_c.getNode( "c" ) );
3717             if ( !p_c_2.getName().equals( "c" ) ) {
3718                 System.out.println( p_c_2.getName() );
3719                 System.exit( -1 );
3720                 return false;
3721             }
3722             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3723                                                                                               p_c.getNode( "b" ) );
3724             if ( !p_c_3.getName().equals( "b" ) ) {
3725                 return false;
3726             }
3727             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3728                                                                                               p_c.getNode( "a" ) );
3729             if ( !p_c_4.getName().equals( "c" ) ) {
3730                 return false;
3731             }
3732             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3733                                                  new NHXParser() )[ 0 ];
3734             PhylogenyMethods.preOrderReId( p1 );
3735             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3736                                                                                           p1.getNode( "A" ) );
3737             if ( !A.getName().equals( "A" ) ) {
3738                 return false;
3739             }
3740             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3741                                                                                            p1.getNode( "gh" ) );
3742             if ( !gh.getName().equals( "gh" ) ) {
3743                 return false;
3744             }
3745             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3746                                                                                            p1.getNode( "B" ) );
3747             if ( !ab.getName().equals( "ab" ) ) {
3748                 return false;
3749             }
3750             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3751                                                                                             p1.getNode( "A" ) );
3752             if ( !ab2.getName().equals( "ab" ) ) {
3753                 return false;
3754             }
3755             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3756                                                                                             p1.getNode( "G" ) );
3757             if ( !gh2.getName().equals( "gh" ) ) {
3758                 return false;
3759             }
3760             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3761                                                                                             p1.getNode( "H" ) );
3762             if ( !gh3.getName().equals( "gh" ) ) {
3763                 return false;
3764             }
3765             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3766                                                                                             p1.getNode( "A" ) );
3767             if ( !abc.getName().equals( "abc" ) ) {
3768                 return false;
3769             }
3770             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3771                                                                                              p1.getNode( "C" ) );
3772             if ( !abc2.getName().equals( "abc" ) ) {
3773                 return false;
3774             }
3775             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3776                                                                                              p1.getNode( "D" ) );
3777             if ( !abcd.getName().equals( "abcd" ) ) {
3778                 return false;
3779             }
3780             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3781                                                                                               p1.getNode( "A" ) );
3782             if ( !abcd2.getName().equals( "abcd" ) ) {
3783                 return false;
3784             }
3785             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3786                                                                                                p1.getNode( "F" ) );
3787             if ( !abcdef.getName().equals( "abcdef" ) ) {
3788                 return false;
3789             }
3790             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3791                                                                                                 p1.getNode( "A" ) );
3792             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3793                 return false;
3794             }
3795             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3796                                                                                                 p1.getNode( "F" ) );
3797             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3798                 return false;
3799             }
3800             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3801                                                                                                 p1.getNode( "ab" ) );
3802             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3803                 return false;
3804             }
3805             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3806                                                                                               p1.getNode( "E" ) );
3807             if ( !abcde.getName().equals( "abcde" ) ) {
3808                 return false;
3809             }
3810             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3811                                                                                                p1.getNode( "A" ) );
3812             if ( !abcde2.getName().equals( "abcde" ) ) {
3813                 return false;
3814             }
3815             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3816                                                                                           p1.getNode( "abcdefgh" ) );
3817             if ( !r.getName().equals( "abcdefgh" ) ) {
3818                 return false;
3819             }
3820             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3821                                                                                            p1.getNode( "H" ) );
3822             if ( !r2.getName().equals( "abcdefgh" ) ) {
3823                 return false;
3824             }
3825             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3826                                                                                            p1.getNode( "A" ) );
3827             if ( !r3.getName().equals( "abcdefgh" ) ) {
3828                 return false;
3829             }
3830             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3831                                                                                                p1.getNode( "abcde" ) );
3832             if ( !abcde3.getName().equals( "abcde" ) ) {
3833                 return false;
3834             }
3835             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3836                                                                                                p1.getNode( "E" ) );
3837             if ( !abcde4.getName().equals( "abcde" ) ) {
3838                 return false;
3839             }
3840             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3841                                                                                             p1.getNode( "B" ) );
3842             if ( !ab3.getName().equals( "ab" ) ) {
3843                 return false;
3844             }
3845             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3846                                                                                             p1.getNode( "ab" ) );
3847             if ( !ab4.getName().equals( "ab" ) ) {
3848                 return false;
3849             }
3850             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3851             PhylogenyMethods.preOrderReId( p2 );
3852             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3853                                                                                            p2.getNode( "d" ) );
3854             if ( !cd.getName().equals( "cd" ) ) {
3855                 return false;
3856             }
3857             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3858                                                                                             p2.getNode( "c" ) );
3859             if ( !cd2.getName().equals( "cd" ) ) {
3860                 return false;
3861             }
3862             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3863                                                                                             p2.getNode( "e" ) );
3864             if ( !cde.getName().equals( "cde" ) ) {
3865                 return false;
3866             }
3867             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3868                                                                                              p2.getNode( "c" ) );
3869             if ( !cde2.getName().equals( "cde" ) ) {
3870                 return false;
3871             }
3872             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3873                                                                                              p2.getNode( "f" ) );
3874             if ( !cdef.getName().equals( "cdef" ) ) {
3875                 return false;
3876             }
3877             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3878                                                                                               p2.getNode( "f" ) );
3879             if ( !cdef2.getName().equals( "cdef" ) ) {
3880                 return false;
3881             }
3882             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3883                                                                                               p2.getNode( "d" ) );
3884             if ( !cdef3.getName().equals( "cdef" ) ) {
3885                 return false;
3886             }
3887             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3888                                                                                            p2.getNode( "a" ) );
3889             if ( !rt.getName().equals( "r" ) ) {
3890                 return false;
3891             }
3892             final Phylogeny p3 = factory
3893                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3894                              new NHXParser() )[ 0 ];
3895             PhylogenyMethods.preOrderReId( p3 );
3896             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3897                                                                                              p3.getNode( "c" ) );
3898             if ( !bc_3.getName().equals( "bc" ) ) {
3899                 return false;
3900             }
3901             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3902                                                                                              p3.getNode( "c" ) );
3903             if ( !ac_3.getName().equals( "abc" ) ) {
3904                 return false;
3905             }
3906             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3907                                                                                              p3.getNode( "d" ) );
3908             if ( !ad_3.getName().equals( "abcde" ) ) {
3909                 return false;
3910             }
3911             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3912                                                                                              p3.getNode( "f" ) );
3913             if ( !af_3.getName().equals( "abcdef" ) ) {
3914                 return false;
3915             }
3916             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3917                                                                                              p3.getNode( "g" ) );
3918             if ( !ag_3.getName().equals( "" ) ) {
3919                 return false;
3920             }
3921             if ( !ag_3.isRoot() ) {
3922                 return false;
3923             }
3924             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3925                                                                                              p3.getNode( "l" ) );
3926             if ( !al_3.getName().equals( "" ) ) {
3927                 return false;
3928             }
3929             if ( !al_3.isRoot() ) {
3930                 return false;
3931             }
3932             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3933                                                                                              p3.getNode( "l" ) );
3934             if ( !kl_3.getName().equals( "" ) ) {
3935                 return false;
3936             }
3937             if ( !kl_3.isRoot() ) {
3938                 return false;
3939             }
3940             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3941                                                                                              p3.getNode( "l" ) );
3942             if ( !fl_3.getName().equals( "" ) ) {
3943                 return false;
3944             }
3945             if ( !fl_3.isRoot() ) {
3946                 return false;
3947             }
3948             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3949                                                                                              p3.getNode( "k" ) );
3950             if ( !gk_3.getName().equals( "ghijk" ) ) {
3951                 return false;
3952             }
3953             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3954             PhylogenyMethods.preOrderReId( p4 );
3955             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3956                                                                                             p4.getNode( "c" ) );
3957             if ( !r_4.getName().equals( "r" ) ) {
3958                 return false;
3959             }
3960             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3961             PhylogenyMethods.preOrderReId( p5 );
3962             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3963                                                                                             p5.getNode( "c" ) );
3964             if ( !r_5.getName().equals( "root" ) ) {
3965                 return false;
3966             }
3967             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3968             PhylogenyMethods.preOrderReId( p6 );
3969             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3970                                                                                             p6.getNode( "a" ) );
3971             if ( !r_6.getName().equals( "rot" ) ) {
3972                 return false;
3973             }
3974             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3975             PhylogenyMethods.preOrderReId( p7 );
3976             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
3977                                                                                             p7.getNode( "e" ) );
3978             if ( !r_7.getName().equals( "rott" ) ) {
3979                 return false;
3980             }
3981             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3982                                                                                              p7.getNode( "a" ) );
3983             if ( !r_71.getName().equals( "rott" ) ) {
3984                 return false;
3985             }
3986             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3987                                                                                              p7.getNode( "rott" ) );
3988             if ( !r_72.getName().equals( "rott" ) ) {
3989                 return false;
3990             }
3991             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3992                                                                                              p7.getNode( "a" ) );
3993             if ( !r_73.getName().equals( "rott" ) ) {
3994                 return false;
3995             }
3996             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3997                                                                                              p7.getNode( "rott" ) );
3998             if ( !r_74.getName().equals( "rott" ) ) {
3999                 return false;
4000             }
4001             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4002                                                                                              p7.getNode( "e" ) );
4003             if ( !r_75.getName().equals( "e" ) ) {
4004                 return false;
4005             }
4006         }
4007         catch ( final Exception e ) {
4008             e.printStackTrace( System.out );
4009             return false;
4010         }
4011         return true;
4012     }
4013
4014     private static boolean testHmmscanOutputParser() {
4015         final String test_dir = Test.PATH_TO_TEST_DATA;
4016         try {
4017             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4018                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4019             parser1.parse();
4020             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4021                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4022             final List<Protein> proteins = parser2.parse();
4023             if ( parser2.getProteinsEncountered() != 4 ) {
4024                 return false;
4025             }
4026             if ( proteins.size() != 4 ) {
4027                 return false;
4028             }
4029             if ( parser2.getDomainsEncountered() != 69 ) {
4030                 return false;
4031             }
4032             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4033                 return false;
4034             }
4035             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4036                 return false;
4037             }
4038             final Protein p1 = proteins.get( 0 );
4039             if ( p1.getNumberOfProteinDomains() != 15 ) {
4040                 return false;
4041             }
4042             if ( p1.getLength() != 850 ) {
4043                 return false;
4044             }
4045             final Protein p2 = proteins.get( 1 );
4046             if ( p2.getNumberOfProteinDomains() != 51 ) {
4047                 return false;
4048             }
4049             if ( p2.getLength() != 1291 ) {
4050                 return false;
4051             }
4052             final Protein p3 = proteins.get( 2 );
4053             if ( p3.getNumberOfProteinDomains() != 2 ) {
4054                 return false;
4055             }
4056             final Protein p4 = proteins.get( 3 );
4057             if ( p4.getNumberOfProteinDomains() != 1 ) {
4058                 return false;
4059             }
4060             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4061                 return false;
4062             }
4063             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4064                 return false;
4065             }
4066             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4067                 return false;
4068             }
4069             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4070                 return false;
4071             }
4072             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4073                 return false;
4074             }
4075             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4076                 return false;
4077             }
4078             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4079                 return false;
4080             }
4081             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4082                 return false;
4083             }
4084             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4085                 return false;
4086             }
4087         }
4088         catch ( final Exception e ) {
4089             e.printStackTrace( System.out );
4090             return false;
4091         }
4092         return true;
4093     }
4094
4095     private static boolean testLastExternalNodeMethods() {
4096         try {
4097             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4098             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4099             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4100             final PhylogenyNode n1 = t0.getNode( "A" );
4101             if ( n1.isLastExternalNode() ) {
4102                 return false;
4103             }
4104             final PhylogenyNode n2 = t0.getNode( "B" );
4105             if ( n2.isLastExternalNode() ) {
4106                 return false;
4107             }
4108             final PhylogenyNode n3 = t0.getNode( "C" );
4109             if ( n3.isLastExternalNode() ) {
4110                 return false;
4111             }
4112             final PhylogenyNode n4 = t0.getNode( "D" );
4113             if ( !n4.isLastExternalNode() ) {
4114                 return false;
4115             }
4116         }
4117         catch ( final Exception e ) {
4118             e.printStackTrace( System.out );
4119             return false;
4120         }
4121         return true;
4122     }
4123
4124     private static boolean testLevelOrderIterator() {
4125         try {
4126             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4127             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4128             PhylogenyNodeIterator it0;
4129             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4130                 it0.next();
4131             }
4132             for( it0.reset(); it0.hasNext(); ) {
4133                 it0.next();
4134             }
4135             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4136             if ( !it.next().getName().equals( "r" ) ) {
4137                 return false;
4138             }
4139             if ( !it.next().getName().equals( "ab" ) ) {
4140                 return false;
4141             }
4142             if ( !it.next().getName().equals( "cd" ) ) {
4143                 return false;
4144             }
4145             if ( !it.next().getName().equals( "A" ) ) {
4146                 return false;
4147             }
4148             if ( !it.next().getName().equals( "B" ) ) {
4149                 return false;
4150             }
4151             if ( !it.next().getName().equals( "C" ) ) {
4152                 return false;
4153             }
4154             if ( !it.next().getName().equals( "D" ) ) {
4155                 return false;
4156             }
4157             if ( it.hasNext() ) {
4158                 return false;
4159             }
4160             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",
4161                                                  new NHXParser() )[ 0 ];
4162             PhylogenyNodeIterator it2;
4163             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4164                 it2.next();
4165             }
4166             for( it2.reset(); it2.hasNext(); ) {
4167                 it2.next();
4168             }
4169             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4170             if ( !it3.next().getName().equals( "r" ) ) {
4171                 return false;
4172             }
4173             if ( !it3.next().getName().equals( "abc" ) ) {
4174                 return false;
4175             }
4176             if ( !it3.next().getName().equals( "defg" ) ) {
4177                 return false;
4178             }
4179             if ( !it3.next().getName().equals( "A" ) ) {
4180                 return false;
4181             }
4182             if ( !it3.next().getName().equals( "B" ) ) {
4183                 return false;
4184             }
4185             if ( !it3.next().getName().equals( "C" ) ) {
4186                 return false;
4187             }
4188             if ( !it3.next().getName().equals( "D" ) ) {
4189                 return false;
4190             }
4191             if ( !it3.next().getName().equals( "E" ) ) {
4192                 return false;
4193             }
4194             if ( !it3.next().getName().equals( "F" ) ) {
4195                 return false;
4196             }
4197             if ( !it3.next().getName().equals( "G" ) ) {
4198                 return false;
4199             }
4200             if ( !it3.next().getName().equals( "1" ) ) {
4201                 return false;
4202             }
4203             if ( !it3.next().getName().equals( "2" ) ) {
4204                 return false;
4205             }
4206             if ( !it3.next().getName().equals( "3" ) ) {
4207                 return false;
4208             }
4209             if ( !it3.next().getName().equals( "4" ) ) {
4210                 return false;
4211             }
4212             if ( !it3.next().getName().equals( "5" ) ) {
4213                 return false;
4214             }
4215             if ( !it3.next().getName().equals( "6" ) ) {
4216                 return false;
4217             }
4218             if ( !it3.next().getName().equals( "f1" ) ) {
4219                 return false;
4220             }
4221             if ( !it3.next().getName().equals( "f2" ) ) {
4222                 return false;
4223             }
4224             if ( !it3.next().getName().equals( "f3" ) ) {
4225                 return false;
4226             }
4227             if ( !it3.next().getName().equals( "a" ) ) {
4228                 return false;
4229             }
4230             if ( !it3.next().getName().equals( "b" ) ) {
4231                 return false;
4232             }
4233             if ( !it3.next().getName().equals( "f21" ) ) {
4234                 return false;
4235             }
4236             if ( !it3.next().getName().equals( "X" ) ) {
4237                 return false;
4238             }
4239             if ( !it3.next().getName().equals( "Y" ) ) {
4240                 return false;
4241             }
4242             if ( !it3.next().getName().equals( "Z" ) ) {
4243                 return false;
4244             }
4245             if ( it3.hasNext() ) {
4246                 return false;
4247             }
4248             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4249             PhylogenyNodeIterator it4;
4250             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4251                 it4.next();
4252             }
4253             for( it4.reset(); it4.hasNext(); ) {
4254                 it4.next();
4255             }
4256             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4257             if ( !it5.next().getName().equals( "r" ) ) {
4258                 return false;
4259             }
4260             if ( !it5.next().getName().equals( "A" ) ) {
4261                 return false;
4262             }
4263             if ( !it5.next().getName().equals( "B" ) ) {
4264                 return false;
4265             }
4266             if ( !it5.next().getName().equals( "C" ) ) {
4267                 return false;
4268             }
4269             if ( !it5.next().getName().equals( "D" ) ) {
4270                 return false;
4271             }
4272             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4273             PhylogenyNodeIterator it6;
4274             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4275                 it6.next();
4276             }
4277             for( it6.reset(); it6.hasNext(); ) {
4278                 it6.next();
4279             }
4280             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4281             if ( !it7.next().getName().equals( "A" ) ) {
4282                 return false;
4283             }
4284             if ( it.hasNext() ) {
4285                 return false;
4286             }
4287         }
4288         catch ( final Exception e ) {
4289             e.printStackTrace( System.out );
4290             return false;
4291         }
4292         return true;
4293     }
4294
4295     private static boolean testNodeRemoval() {
4296         try {
4297             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4298             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4299             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
4300             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
4301                 return false;
4302             }
4303             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
4304             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
4305             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
4306                 return false;
4307             }
4308             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
4309             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
4310             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
4311                 return false;
4312             }
4313         }
4314         catch ( final Exception e ) {
4315             e.printStackTrace( System.out );
4316             return false;
4317         }
4318         return true;
4319     }
4320
4321     private static boolean testMidpointrooting() {
4322         try {
4323             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4324             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4325             PhylogenyMethods.midpointRoot( t0 );
4326             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4327                 return false;
4328             }
4329             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4330                 return false;
4331             }
4332             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4333                            1 ) ) {
4334                 return false;
4335             }
4336             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",
4337                                                  new NHXParser() )[ 0 ];
4338             if ( !t1.isRooted() ) {
4339                 return false;
4340             }
4341             PhylogenyMethods.midpointRoot( t1 );
4342             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4343                 return false;
4344             }
4345             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4346                 return false;
4347             }
4348             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4349                 return false;
4350             }
4351             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4352                 return false;
4353             }
4354             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4355                 return false;
4356             }
4357             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4358                 return false;
4359             }
4360             t1.reRoot( t1.getNode( "A" ) );
4361             PhylogenyMethods.midpointRoot( t1 );
4362             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4363                 return false;
4364             }
4365             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4366                 return false;
4367             }
4368             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4369                 return false;
4370             }
4371             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4372                 return false;
4373             }
4374             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4375                 System.exit( -1 );
4376                 return false;
4377             }
4378             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4379                 return false;
4380             }
4381         }
4382         catch ( final Exception e ) {
4383             e.printStackTrace( System.out );
4384             return false;
4385         }
4386         return true;
4387     }
4388
4389     private static boolean testNexusCharactersParsing() {
4390         try {
4391             final NexusCharactersParser parser = new NexusCharactersParser();
4392             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4393             parser.parse();
4394             String[] labels = parser.getCharStateLabels();
4395             if ( labels.length != 7 ) {
4396                 return false;
4397             }
4398             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4399                 return false;
4400             }
4401             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4402                 return false;
4403             }
4404             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4405                 return false;
4406             }
4407             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4408                 return false;
4409             }
4410             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4411                 return false;
4412             }
4413             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4414                 return false;
4415             }
4416             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4417                 return false;
4418             }
4419             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4420             parser.parse();
4421             labels = parser.getCharStateLabels();
4422             if ( labels.length != 7 ) {
4423                 return false;
4424             }
4425             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4426                 return false;
4427             }
4428             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4429                 return false;
4430             }
4431             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4432                 return false;
4433             }
4434             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4435                 return false;
4436             }
4437             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4438                 return false;
4439             }
4440             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4441                 return false;
4442             }
4443             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4444                 return false;
4445             }
4446         }
4447         catch ( final Exception e ) {
4448             e.printStackTrace( System.out );
4449             return false;
4450         }
4451         return true;
4452     }
4453
4454     private static boolean testNexusMatrixParsing() {
4455         try {
4456             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4457             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4458             parser.parse();
4459             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4460             if ( m.getNumberOfCharacters() != 9 ) {
4461                 return false;
4462             }
4463             if ( m.getNumberOfIdentifiers() != 5 ) {
4464                 return false;
4465             }
4466             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4467                 return false;
4468             }
4469             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4470                 return false;
4471             }
4472             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4473                 return false;
4474             }
4475             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4476                 return false;
4477             }
4478             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4479                 return false;
4480             }
4481             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4482                 return false;
4483             }
4484             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4485                 return false;
4486             }
4487             //            if ( labels.length != 7 ) {
4488             //                return false;
4489             //            }
4490             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4491             //                return false;
4492             //            }
4493             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4494             //                return false;
4495             //            }
4496             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4497             //                return false;
4498             //            }
4499             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4500             //                return false;
4501             //            }
4502             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4503             //                return false;
4504             //            }
4505             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4506             //                return false;
4507             //            }
4508             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4509             //                return false;
4510             //            }
4511             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4512             //            parser.parse();
4513             //            labels = parser.getCharStateLabels();
4514             //            if ( labels.length != 7 ) {
4515             //                return false;
4516             //            }
4517             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4518             //                return false;
4519             //            }
4520             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4521             //                return false;
4522             //            }
4523             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4524             //                return false;
4525             //            }
4526             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4527             //                return false;
4528             //            }
4529             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4530             //                return false;
4531             //            }
4532             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4533             //                return false;
4534             //            }
4535             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4536             //                return false;
4537             //            }
4538         }
4539         catch ( final Exception e ) {
4540             e.printStackTrace( System.out );
4541             return false;
4542         }
4543         return true;
4544     }
4545
4546     private static boolean testNexusTreeParsing() {
4547         try {
4548             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4549             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4550             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4551             if ( phylogenies.length != 1 ) {
4552                 return false;
4553             }
4554             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4555                 return false;
4556             }
4557             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4558                 return false;
4559             }
4560             phylogenies = null;
4561             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4562             if ( phylogenies.length != 1 ) {
4563                 return false;
4564             }
4565             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4566                 return false;
4567             }
4568             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4569                 return false;
4570             }
4571             phylogenies = null;
4572             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4573             if ( phylogenies.length != 1 ) {
4574                 return false;
4575             }
4576             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4577                 return false;
4578             }
4579             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4580                 return false;
4581             }
4582             if ( phylogenies[ 0 ].isRooted() ) {
4583                 return false;
4584             }
4585             phylogenies = null;
4586             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4587             if ( phylogenies.length != 18 ) {
4588                 return false;
4589             }
4590             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4591                 return false;
4592             }
4593             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4594                 return false;
4595             }
4596             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4597                 return false;
4598             }
4599             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4600                 return false;
4601             }
4602             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4603                 return false;
4604             }
4605             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4606                 return false;
4607             }
4608             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4609                 return false;
4610             }
4611             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4612                 return false;
4613             }
4614             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4615                 return false;
4616             }
4617             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4618                 return false;
4619             }
4620             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4621                 return false;
4622             }
4623             if ( phylogenies[ 8 ].isRooted() ) {
4624                 return false;
4625             }
4626             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4627                 return false;
4628             }
4629             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4630                 return false;
4631             }
4632             if ( !phylogenies[ 9 ].isRooted() ) {
4633                 return false;
4634             }
4635             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4636                 return false;
4637             }
4638             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4639                 return false;
4640             }
4641             if ( !phylogenies[ 10 ].isRooted() ) {
4642                 return false;
4643             }
4644             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4645                 return false;
4646             }
4647             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4648                 return false;
4649             }
4650             if ( phylogenies[ 11 ].isRooted() ) {
4651                 return false;
4652             }
4653             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4654                 return false;
4655             }
4656             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4657                 return false;
4658             }
4659             if ( !phylogenies[ 12 ].isRooted() ) {
4660                 return false;
4661             }
4662             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4663                 return false;
4664             }
4665             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4666                 return false;
4667             }
4668             if ( !phylogenies[ 13 ].isRooted() ) {
4669                 return false;
4670             }
4671             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4672                 return false;
4673             }
4674             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4675                 return false;
4676             }
4677             if ( !phylogenies[ 14 ].isRooted() ) {
4678                 return false;
4679             }
4680             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4681                 return false;
4682             }
4683             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4684                 return false;
4685             }
4686             if ( phylogenies[ 15 ].isRooted() ) {
4687                 return false;
4688             }
4689             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4690                 return false;
4691             }
4692             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4693                 return false;
4694             }
4695             if ( !phylogenies[ 16 ].isRooted() ) {
4696                 return false;
4697             }
4698             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4699                 return false;
4700             }
4701             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4702                 return false;
4703             }
4704             if ( phylogenies[ 17 ].isRooted() ) {
4705                 return false;
4706             }
4707             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4708                 return false;
4709             }
4710         }
4711         catch ( final Exception e ) {
4712             e.printStackTrace( System.out );
4713             return false;
4714         }
4715         return true;
4716     }
4717
4718     private static boolean testNexusTreeParsingIterating() {
4719         try {
4720             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
4721             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
4722             if ( !p.hasNext() ) {
4723                 return false;
4724             }
4725             Phylogeny phy = p.next();
4726             if ( phy == null ) {
4727                 return false;
4728             }
4729             if ( phy.getNumberOfExternalNodes() != 25 ) {
4730                 return false;
4731             }
4732             if ( !phy.getName().equals( "" ) ) {
4733                 return false;
4734             }
4735             if ( p.hasNext() ) {
4736                 return false;
4737             }
4738             phy = p.next();
4739             if ( phy != null ) {
4740                 return false;
4741             }
4742             //
4743             p.reset();
4744             if ( !p.hasNext() ) {
4745                 return false;
4746             }
4747             phy = p.next();
4748             if ( phy == null ) {
4749                 return false;
4750             }
4751             if ( phy.getNumberOfExternalNodes() != 25 ) {
4752                 return false;
4753             }
4754             if ( !phy.getName().equals( "" ) ) {
4755                 return false;
4756             }
4757             if ( p.hasNext() ) {
4758                 return false;
4759             }
4760             phy = p.next();
4761             if ( phy != null ) {
4762                 return false;
4763             }
4764             ////
4765             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
4766             if ( !p.hasNext() ) {
4767                 return false;
4768             }
4769             phy = p.next();
4770             if ( phy == null ) {
4771                 return false;
4772             }
4773             if ( phy.getNumberOfExternalNodes() != 10 ) {
4774                 return false;
4775             }
4776             if ( !phy.getName().equals( "name" ) ) {
4777                 return false;
4778             }
4779             if ( p.hasNext() ) {
4780                 return false;
4781             }
4782             phy = p.next();
4783             if ( phy != null ) {
4784                 return false;
4785             }
4786             //
4787             p.reset();
4788             if ( !p.hasNext() ) {
4789                 return false;
4790             }
4791             phy = p.next();
4792             if ( phy == null ) {
4793                 return false;
4794             }
4795             if ( phy.getNumberOfExternalNodes() != 10 ) {
4796                 return false;
4797             }
4798             if ( !phy.getName().equals( "name" ) ) {
4799                 return false;
4800             }
4801             if ( p.hasNext() ) {
4802                 return false;
4803             }
4804             phy = p.next();
4805             if ( phy != null ) {
4806                 return false;
4807             }
4808             ////
4809             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
4810             if ( !p.hasNext() ) {
4811                 return false;
4812             }
4813             phy = p.next();
4814             if ( phy == null ) {
4815                 return false;
4816             }
4817             if ( phy.getNumberOfExternalNodes() != 3 ) {
4818                 return false;
4819             }
4820             if ( !phy.getName().equals( "" ) ) {
4821                 return false;
4822             }
4823             if ( phy.isRooted() ) {
4824                 return false;
4825             }
4826             if ( p.hasNext() ) {
4827                 return false;
4828             }
4829             phy = p.next();
4830             if ( phy != null ) {
4831                 return false;
4832             }
4833             //
4834             p.reset();
4835             if ( !p.hasNext() ) {
4836                 return false;
4837             }
4838             phy = p.next();
4839             if ( phy == null ) {
4840                 return false;
4841             }
4842             if ( phy.getNumberOfExternalNodes() != 3 ) {
4843                 return false;
4844             }
4845             if ( !phy.getName().equals( "" ) ) {
4846                 return false;
4847             }
4848             if ( p.hasNext() ) {
4849                 return false;
4850             }
4851             phy = p.next();
4852             if ( phy != null ) {
4853                 return false;
4854             }
4855             ////
4856             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
4857             //            if ( phylogenies.length != 18 ) {
4858             //                return false;
4859             //            }
4860             //0
4861             if ( !p.hasNext() ) {
4862                 return false;
4863             }
4864             phy = p.next();
4865             if ( phy == null ) {
4866                 return false;
4867             }
4868             if ( phy.getNumberOfExternalNodes() != 10 ) {
4869                 return false;
4870             }
4871             if ( !phy.getName().equals( "tree 0" ) ) {
4872                 return false;
4873             }
4874             //1
4875             if ( !p.hasNext() ) {
4876                 return false;
4877             }
4878             phy = p.next();
4879             if ( phy == null ) {
4880                 return false;
4881             }
4882             if ( phy.getNumberOfExternalNodes() != 10 ) {
4883                 return false;
4884             }
4885             if ( !phy.getName().equals( "tree 1" ) ) {
4886                 return false;
4887             }
4888             //2
4889             if ( !p.hasNext() ) {
4890                 return false;
4891             }
4892             phy = p.next();
4893             if ( phy == null ) {
4894                 return false;
4895             }
4896             if ( phy.getNumberOfExternalNodes() != 3 ) {
4897                 return false;
4898             }
4899             if ( !phy.getName().equals( "" ) ) {
4900                 return false;
4901             }
4902             if ( phy.isRooted() ) {
4903                 return false;
4904             }
4905             //3
4906             if ( !p.hasNext() ) {
4907                 return false;
4908             }
4909             phy = p.next();
4910             if ( phy == null ) {
4911                 return false;
4912             }
4913             if ( phy.getNumberOfExternalNodes() != 4 ) {
4914                 return false;
4915             }
4916             if ( !phy.getName().equals( "" ) ) {
4917                 return false;
4918             }
4919             if ( !phy.isRooted() ) {
4920                 return false;
4921             }
4922             //4
4923             if ( !p.hasNext() ) {
4924                 return false;
4925             }
4926             phy = p.next();
4927             if ( phy == null ) {
4928                 return false;
4929             }
4930             if ( phy.getNumberOfExternalNodes() != 5 ) {
4931                 System.out.println( phy.getNumberOfExternalNodes() );
4932                 return false;
4933             }
4934             if ( !phy.getName().equals( "" ) ) {
4935                 return false;
4936             }
4937             if ( !phy.isRooted() ) {
4938                 return false;
4939             }
4940             //5
4941             if ( !p.hasNext() ) {
4942                 return false;
4943             }
4944             phy = p.next();
4945             if ( phy == null ) {
4946                 return false;
4947             }
4948             if ( phy.getNumberOfExternalNodes() != 3 ) {
4949                 return false;
4950             }
4951             if ( !phy.getName().equals( "" ) ) {
4952                 return false;
4953             }
4954             if ( phy.isRooted() ) {
4955                 return false;
4956             }
4957             //6
4958             if ( !p.hasNext() ) {
4959                 return false;
4960             }
4961             phy = p.next();
4962             if ( phy == null ) {
4963                 return false;
4964             }
4965             if ( phy.getNumberOfExternalNodes() != 2 ) {
4966                 return false;
4967             }
4968             if ( !phy.getName().equals( "" ) ) {
4969                 return false;
4970             }
4971             if ( !phy.isRooted() ) {
4972                 return false;
4973             }
4974             //7
4975             if ( !p.hasNext() ) {
4976                 return false;
4977             }
4978             phy = p.next();
4979             if ( phy.getNumberOfExternalNodes() != 3 ) {
4980                 return false;
4981             }
4982             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
4983                 return false;
4984             }
4985             if ( !phy.isRooted() ) {
4986                 return false;
4987             }
4988             //8
4989             if ( !p.hasNext() ) {
4990                 return false;
4991             }
4992             phy = p.next();
4993             if ( phy.getNumberOfExternalNodes() != 3 ) {
4994                 return false;
4995             }
4996             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
4997                 return false;
4998             }
4999             if ( !phy.getName().equals( "tree 8" ) ) {
5000                 return false;
5001             }
5002             //9
5003             if ( !p.hasNext() ) {
5004                 return false;
5005             }
5006             phy = p.next();
5007             if ( phy.getNumberOfExternalNodes() != 3 ) {
5008                 return false;
5009             }
5010             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
5011                 return false;
5012             }
5013             if ( !phy.getName().equals( "tree 9" ) ) {
5014                 return false;
5015             }
5016             //10
5017             if ( !p.hasNext() ) {
5018                 return false;
5019             }
5020             phy = p.next();
5021             if ( phy.getNumberOfExternalNodes() != 3 ) {
5022                 return false;
5023             }
5024             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5025                 return false;
5026             }
5027             if ( !phy.getName().equals( "tree 10" ) ) {
5028                 return false;
5029             }
5030             if ( !phy.isRooted() ) {
5031                 return false;
5032             }
5033             //11
5034             if ( !p.hasNext() ) {
5035                 return false;
5036             }
5037             phy = p.next();
5038             if ( phy.getNumberOfExternalNodes() != 3 ) {
5039                 return false;
5040             }
5041             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
5042                 return false;
5043             }
5044             if ( !phy.getName().equals( "tree 11" ) ) {
5045                 return false;
5046             }
5047             if ( phy.isRooted() ) {
5048                 return false;
5049             }
5050             //12
5051             if ( !p.hasNext() ) {
5052                 return false;
5053             }
5054             phy = p.next();
5055             if ( phy.getNumberOfExternalNodes() != 3 ) {
5056                 return false;
5057             }
5058             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
5059                 return false;
5060             }
5061             if ( !phy.getName().equals( "tree 12" ) ) {
5062                 return false;
5063             }
5064             if ( !phy.isRooted() ) {
5065                 return false;
5066             }
5067             //13
5068             if ( !p.hasNext() ) {
5069                 return false;
5070             }
5071             phy = p.next();
5072             if ( phy.getNumberOfExternalNodes() != 3 ) {
5073                 return false;
5074             }
5075             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5076                 return false;
5077             }
5078             if ( !phy.getName().equals( "tree 13" ) ) {
5079                 return false;
5080             }
5081             if ( !phy.isRooted() ) {
5082                 return false;
5083             }
5084             //14
5085             if ( !p.hasNext() ) {
5086                 return false;
5087             }
5088             phy = p.next();
5089             if ( phy.getNumberOfExternalNodes() != 10 ) {
5090                 System.out.println( phy.getNumberOfExternalNodes() );
5091                 return false;
5092             }
5093             if ( !phy
5094                     .toNewHampshire()
5095                     .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;" ) ) {
5096                 System.out.println( phy.toNewHampshire() );
5097                 return false;
5098             }
5099             if ( !phy.getName().equals( "tree 14" ) ) {
5100                 return false;
5101             }
5102             if ( !phy.isRooted() ) {
5103                 return false;
5104             }
5105             //15
5106             if ( !p.hasNext() ) {
5107                 return false;
5108             }
5109             phy = p.next();
5110             if ( phy.getNumberOfExternalNodes() != 10 ) {
5111                 System.out.println( phy.getNumberOfExternalNodes() );
5112                 return false;
5113             }
5114             if ( !phy
5115                     .toNewHampshire()
5116                     .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;" ) ) {
5117                 System.out.println( phy.toNewHampshire() );
5118                 return false;
5119             }
5120             if ( !phy.getName().equals( "tree 15" ) ) {
5121                 return false;
5122             }
5123             if ( phy.isRooted() ) {
5124                 return false;
5125             }
5126             //16
5127             if ( !p.hasNext() ) {
5128                 return false;
5129             }
5130             phy = p.next();
5131             if ( phy.getNumberOfExternalNodes() != 10 ) {
5132                 System.out.println( phy.getNumberOfExternalNodes() );
5133                 return false;
5134             }
5135             if ( !phy
5136                     .toNewHampshire()
5137                     .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;" ) ) {
5138                 System.out.println( phy.toNewHampshire() );
5139                 return false;
5140             }
5141             if ( !phy.getName().equals( "tree 16" ) ) {
5142                 return false;
5143             }
5144             if ( !phy.isRooted() ) {
5145                 return false;
5146             }
5147             //17
5148             if ( !p.hasNext() ) {
5149                 return false;
5150             }
5151             phy = p.next();
5152             if ( phy.getNumberOfExternalNodes() != 10 ) {
5153                 System.out.println( phy.getNumberOfExternalNodes() );
5154                 return false;
5155             }
5156             if ( !phy
5157                     .toNewHampshire()
5158                     .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;" ) ) {
5159                 System.out.println( phy.toNewHampshire() );
5160                 return false;
5161             }
5162             if ( !phy.getName().equals( "tree 17" ) ) {
5163                 return false;
5164             }
5165             if ( phy.isRooted() ) {
5166                 return false;
5167             }
5168             //
5169             if ( p.hasNext() ) {
5170                 return false;
5171             }
5172             phy = p.next();
5173             if ( phy != null ) {
5174                 return false;
5175             }
5176             p.reset();
5177             //0
5178             if ( !p.hasNext() ) {
5179                 return false;
5180             }
5181             phy = p.next();
5182             if ( phy == null ) {
5183                 return false;
5184             }
5185             if ( phy.getNumberOfExternalNodes() != 10 ) {
5186                 return false;
5187             }
5188             if ( !phy.getName().equals( "tree 0" ) ) {
5189                 return false;
5190             }
5191             //1
5192             if ( !p.hasNext() ) {
5193                 return false;
5194             }
5195             phy = p.next();
5196             if ( phy == null ) {
5197                 return false;
5198             }
5199             if ( phy.getNumberOfExternalNodes() != 10 ) {
5200                 return false;
5201             }
5202             if ( !phy.getName().equals( "tree 1" ) ) {
5203                 return false;
5204             }
5205             //2
5206             if ( !p.hasNext() ) {
5207                 return false;
5208             }
5209             phy = p.next();
5210             if ( phy == null ) {
5211                 return false;
5212             }
5213             if ( phy.getNumberOfExternalNodes() != 3 ) {
5214                 return false;
5215             }
5216             if ( !phy.getName().equals( "" ) ) {
5217                 return false;
5218             }
5219             if ( phy.isRooted() ) {
5220                 return false;
5221             }
5222             //3
5223             if ( !p.hasNext() ) {
5224                 return false;
5225             }
5226             phy = p.next();
5227             if ( phy == null ) {
5228                 return false;
5229             }
5230             if ( phy.getNumberOfExternalNodes() != 4 ) {
5231                 return false;
5232             }
5233             if ( !phy.getName().equals( "" ) ) {
5234                 return false;
5235             }
5236             if ( !phy.isRooted() ) {
5237                 return false;
5238             }
5239             //4
5240             if ( !p.hasNext() ) {
5241                 return false;
5242             }
5243             phy = p.next();
5244             if ( phy == null ) {
5245                 return false;
5246             }
5247             if ( phy.getNumberOfExternalNodes() != 5 ) {
5248                 System.out.println( phy.getNumberOfExternalNodes() );
5249                 return false;
5250             }
5251             if ( !phy.getName().equals( "" ) ) {
5252                 return false;
5253             }
5254             if ( !phy.isRooted() ) {
5255                 return false;
5256             }
5257             //5
5258             if ( !p.hasNext() ) {
5259                 return false;
5260             }
5261             phy = p.next();
5262             if ( phy == null ) {
5263                 return false;
5264             }
5265             if ( phy.getNumberOfExternalNodes() != 3 ) {
5266                 return false;
5267             }
5268             if ( !phy.getName().equals( "" ) ) {
5269                 return false;
5270             }
5271             if ( phy.isRooted() ) {
5272                 return false;
5273             }
5274         }
5275         catch ( final Exception e ) {
5276             e.printStackTrace( System.out );
5277             return false;
5278         }
5279         return true;
5280     }
5281
5282     private static boolean testNexusTreeParsingTranslating() {
5283         try {
5284             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5285             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5286             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
5287             if ( phylogenies.length != 1 ) {
5288                 return false;
5289             }
5290             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5291                 return false;
5292             }
5293             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5294                 return false;
5295             }
5296             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5297                 return false;
5298             }
5299             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5300                 return false;
5301             }
5302             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5303                     .equals( "Aranaeus" ) ) {
5304                 return false;
5305             }
5306             phylogenies = null;
5307             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
5308             if ( phylogenies.length != 3 ) {
5309                 return false;
5310             }
5311             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5312                 return false;
5313             }
5314             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5315                 return false;
5316             }
5317             if ( phylogenies[ 0 ].isRooted() ) {
5318                 return false;
5319             }
5320             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5321                 return false;
5322             }
5323             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5324                 return false;
5325             }
5326             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5327                     .equals( "Aranaeus" ) ) {
5328                 return false;
5329             }
5330             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5331                 return false;
5332             }
5333             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5334                 return false;
5335             }
5336             if ( phylogenies[ 1 ].isRooted() ) {
5337                 return false;
5338             }
5339             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5340                 return false;
5341             }
5342             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5343                 return false;
5344             }
5345             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5346                     .equals( "Aranaeus" ) ) {
5347                 return false;
5348             }
5349             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5350                 return false;
5351             }
5352             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5353                 return false;
5354             }
5355             if ( !phylogenies[ 2 ].isRooted() ) {
5356                 return false;
5357             }
5358             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5359                 return false;
5360             }
5361             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5362                 return false;
5363             }
5364             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5365                     .equals( "Aranaeus" ) ) {
5366                 return false;
5367             }
5368             phylogenies = null;
5369             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
5370             if ( phylogenies.length != 3 ) {
5371                 return false;
5372             }
5373             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5374                 return false;
5375             }
5376             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5377                 return false;
5378             }
5379             if ( phylogenies[ 0 ].isRooted() ) {
5380                 return false;
5381             }
5382             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5383                 return false;
5384             }
5385             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5386                 return false;
5387             }
5388             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5389                     .equals( "Aranaeus" ) ) {
5390                 return false;
5391             }
5392             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5393                 return false;
5394             }
5395             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5396                 return false;
5397             }
5398             if ( phylogenies[ 1 ].isRooted() ) {
5399                 return false;
5400             }
5401             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5402                 return false;
5403             }
5404             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5405                 return false;
5406             }
5407             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5408                     .equals( "Aranaeus" ) ) {
5409                 return false;
5410             }
5411             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5412                 return false;
5413             }
5414             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5415                 return false;
5416             }
5417             if ( !phylogenies[ 2 ].isRooted() ) {
5418                 return false;
5419             }
5420             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5421                 return false;
5422             }
5423             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5424                 return false;
5425             }
5426             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5427                     .equals( "Aranaeus" ) ) {
5428                 return false;
5429             }
5430         }
5431         catch ( final Exception e ) {
5432             e.printStackTrace( System.out );
5433             return false;
5434         }
5435         return true;
5436     }
5437
5438     private static boolean testNHParsing() {
5439         try {
5440             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5441             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
5442             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
5443                 return false;
5444             }
5445             final NHXParser nhxp = new NHXParser();
5446             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
5447             nhxp.setReplaceUnderscores( true );
5448             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
5449             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
5450                 return false;
5451             }
5452             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
5453                 return false;
5454             }
5455             final Phylogeny p1b = factory
5456                     .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 ",
5457                              new NHXParser() )[ 0 ];
5458             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
5459                 return false;
5460             }
5461             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
5462                 return false;
5463             }
5464             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
5465             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
5466             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
5467             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
5468             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
5469             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
5470             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
5471             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
5472             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
5473             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
5474             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
5475                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
5476                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
5477                                                     new NHXParser() );
5478             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
5479                 return false;
5480             }
5481             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
5482                 return false;
5483             }
5484             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
5485                 return false;
5486             }
5487             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
5488                 return false;
5489             }
5490             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
5491             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
5492             final String p16_S = "((A,B),C)";
5493             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
5494             if ( p16.length != 1 ) {
5495                 return false;
5496             }
5497             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
5498                 return false;
5499             }
5500             final String p17_S = "(C,(A,B))";
5501             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
5502             if ( p17.length != 1 ) {
5503                 return false;
5504             }
5505             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
5506                 return false;
5507             }
5508             final String p18_S = "((A,B),(C,D))";
5509             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
5510             if ( p18.length != 1 ) {
5511                 return false;
5512             }
5513             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
5514                 return false;
5515             }
5516             final String p19_S = "(((A,B),C),D)";
5517             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
5518             if ( p19.length != 1 ) {
5519                 return false;
5520             }
5521             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
5522                 return false;
5523             }
5524             final String p20_S = "(A,(B,(C,D)))";
5525             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
5526             if ( p20.length != 1 ) {
5527                 return false;
5528             }
5529             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
5530                 return false;
5531             }
5532             final String p21_S = "(A,(B,(C,(D,E))))";
5533             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
5534             if ( p21.length != 1 ) {
5535                 return false;
5536             }
5537             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
5538                 return false;
5539             }
5540             final String p22_S = "((((A,B),C),D),E)";
5541             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
5542             if ( p22.length != 1 ) {
5543                 return false;
5544             }
5545             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
5546                 return false;
5547             }
5548             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5549             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
5550             if ( p23.length != 1 ) {
5551                 System.out.println( "xl=" + p23.length );
5552                 System.exit( -1 );
5553                 return false;
5554             }
5555             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
5556                 return false;
5557             }
5558             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5559             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
5560             if ( p24.length != 1 ) {
5561                 return false;
5562             }
5563             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
5564                 return false;
5565             }
5566             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5567             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5568             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
5569             if ( p241.length != 2 ) {
5570                 return false;
5571             }
5572             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
5573                 return false;
5574             }
5575             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
5576                 return false;
5577             }
5578             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
5579                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
5580                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
5581                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
5582                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
5583                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
5584                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
5585                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
5586             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
5587             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
5588                 return false;
5589             }
5590             final String p26_S = "(A,B)ab";
5591             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
5592             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
5593                 return false;
5594             }
5595             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5596             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
5597             if ( p27s.length != 1 ) {
5598                 System.out.println( "xxl=" + p27s.length );
5599                 System.exit( -1 );
5600                 return false;
5601             }
5602             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5603                 System.out.println( p27s[ 0 ].toNewHampshireX() );
5604                 System.exit( -1 );
5605                 return false;
5606             }
5607             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
5608                                                     new NHXParser() );
5609             if ( p27.length != 1 ) {
5610                 System.out.println( "yl=" + p27.length );
5611                 System.exit( -1 );
5612                 return false;
5613             }
5614             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5615                 System.out.println( p27[ 0 ].toNewHampshireX() );
5616                 System.exit( -1 );
5617                 return false;
5618             }
5619             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5620             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5621             final String p28_S3 = "(A,B)ab";
5622             final String p28_S4 = "((((A,B),C),D),;E;)";
5623             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
5624                                                     new NHXParser() );
5625             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
5626                 return false;
5627             }
5628             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
5629                 return false;
5630             }
5631             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
5632                 return false;
5633             }
5634             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
5635                 return false;
5636             }
5637             if ( p28.length != 4 ) {
5638                 return false;
5639             }
5640             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";
5641             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
5642             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
5643                 return false;
5644             }
5645             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";
5646             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
5647             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
5648                 return false;
5649             }
5650             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
5651             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
5652             if ( ( p32.length != 0 ) ) {
5653                 return false;
5654             }
5655             final String p33_S = "A";
5656             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
5657             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
5658                 return false;
5659             }
5660             final String p34_S = "B;";
5661             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
5662             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
5663                 return false;
5664             }
5665             final String p35_S = "B:0.2";
5666             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
5667             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
5668                 return false;
5669             }
5670             final String p36_S = "(A)";
5671             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
5672             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
5673                 return false;
5674             }
5675             final String p37_S = "((A))";
5676             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
5677             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
5678                 return false;
5679             }
5680             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5681             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
5682             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
5683                 return false;
5684             }
5685             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5686             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
5687             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
5688                 return false;
5689             }
5690             final String p40_S = "(A,B,C)";
5691             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
5692             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
5693                 return false;
5694             }
5695             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
5696             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
5697             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
5698                 return false;
5699             }
5700             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
5701             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
5702             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
5703                 return false;
5704             }
5705             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)";
5706             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
5707             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
5708                 return false;
5709             }
5710             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)))";
5711             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
5712             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
5713                 return false;
5714             }
5715             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
5716             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
5717             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
5718                 return false;
5719             }
5720             final String p46_S = "";
5721             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
5722             if ( p46.length != 0 ) {
5723                 return false;
5724             }
5725             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
5726             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5727                 return false;
5728             }
5729             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5730             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5731                 return false;
5732             }
5733             final Phylogeny p49 = factory
5734                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
5735                              new NHXParser() )[ 0 ];
5736             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5737                 return false;
5738             }
5739             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5740             if ( p50.getNode( "A" ) == null ) {
5741                 return false;
5742             }
5743             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5744                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
5745                 return false;
5746             }
5747             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
5748                 return false;
5749             }
5750             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
5751                     .equals( "((A,B)88:2.0,C);" ) ) {
5752                 return false;
5753             }
5754             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5755             if ( p51.getNode( "A(A" ) == null ) {
5756                 return false;
5757             }
5758             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5759             if ( p52.getNode( "A(A" ) == null ) {
5760                 return false;
5761             }
5762             final Phylogeny p53 = factory
5763                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
5764                              new NHXParser() )[ 0 ];
5765             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
5766                 return false;
5767             }
5768             // 
5769             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
5770             if ( p54.getNode( "A" ) == null ) {
5771                 return false;
5772             }
5773             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5774                     .equals( "((A,B)[88],C);" ) ) {
5775                 return false;
5776             }
5777         }
5778         catch ( final Exception e ) {
5779             e.printStackTrace( System.out );
5780             return false;
5781         }
5782         return true;
5783     }
5784
5785     private static boolean testNHParsingIter() {
5786         try {
5787             final String p0_str = "(A,B);";
5788             final NHXParser p = new NHXParser();
5789             p.setSource( p0_str );
5790             if ( !p.hasNext() ) {
5791                 return false;
5792             }
5793             final Phylogeny p0 = p.next();
5794             if ( !p0.toNewHampshire().equals( p0_str ) ) {
5795                 System.out.println( p0.toNewHampshire() );
5796                 return false;
5797             }
5798             if ( p.hasNext() ) {
5799                 return false;
5800             }
5801             if ( p.next() != null ) {
5802                 return false;
5803             }
5804             //
5805             final String p00_str = "(A,B)root;";
5806             p.setSource( p00_str );
5807             final Phylogeny p00 = p.next();
5808             if ( !p00.toNewHampshire().equals( p00_str ) ) {
5809                 System.out.println( p00.toNewHampshire() );
5810                 return false;
5811             }
5812             //
5813             final String p000_str = "A;";
5814             p.setSource( p000_str );
5815             final Phylogeny p000 = p.next();
5816             if ( !p000.toNewHampshire().equals( p000_str ) ) {
5817                 System.out.println( p000.toNewHampshire() );
5818                 return false;
5819             }
5820             //
5821             final String p0000_str = "A";
5822             p.setSource( p0000_str );
5823             final Phylogeny p0000 = p.next();
5824             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
5825                 System.out.println( p0000.toNewHampshire() );
5826                 return false;
5827             }
5828             //
5829             p.setSource( "(A)" );
5830             final Phylogeny p00000 = p.next();
5831             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
5832                 System.out.println( p00000.toNewHampshire() );
5833                 return false;
5834             }
5835             //
5836             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
5837             p.setSource( p1_str );
5838             if ( !p.hasNext() ) {
5839                 return false;
5840             }
5841             final Phylogeny p1_0 = p.next();
5842             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
5843                 System.out.println( p1_0.toNewHampshire() );
5844                 return false;
5845             }
5846             if ( !p.hasNext() ) {
5847                 return false;
5848             }
5849             final Phylogeny p1_1 = p.next();
5850             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
5851                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
5852                 return false;
5853             }
5854             if ( !p.hasNext() ) {
5855                 return false;
5856             }
5857             final Phylogeny p1_2 = p.next();
5858             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
5859                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
5860                 return false;
5861             }
5862             if ( !p.hasNext() ) {
5863                 return false;
5864             }
5865             final Phylogeny p1_3 = p.next();
5866             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
5867                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
5868                 return false;
5869             }
5870             if ( p.hasNext() ) {
5871                 return false;
5872             }
5873             if ( p.next() != null ) {
5874                 return false;
5875             }
5876             //
5877             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
5878             p.setSource( p2_str );
5879             if ( !p.hasNext() ) {
5880                 return false;
5881             }
5882             Phylogeny p2_0 = p.next();
5883             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5884                 System.out.println( p2_0.toNewHampshire() );
5885                 return false;
5886             }
5887             if ( !p.hasNext() ) {
5888                 return false;
5889             }
5890             Phylogeny p2_1 = p.next();
5891             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5892                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5893                 return false;
5894             }
5895             if ( !p.hasNext() ) {
5896                 return false;
5897             }
5898             Phylogeny p2_2 = p.next();
5899             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5900                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5901                 return false;
5902             }
5903             if ( !p.hasNext() ) {
5904                 return false;
5905             }
5906             Phylogeny p2_3 = p.next();
5907             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5908                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5909                 return false;
5910             }
5911             if ( !p.hasNext() ) {
5912                 return false;
5913             }
5914             Phylogeny p2_4 = p.next();
5915             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5916                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5917                 return false;
5918             }
5919             if ( p.hasNext() ) {
5920                 return false;
5921             }
5922             if ( p.next() != null ) {
5923                 return false;
5924             }
5925             ////
5926             p.reset();
5927             if ( !p.hasNext() ) {
5928                 return false;
5929             }
5930             p2_0 = p.next();
5931             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5932                 System.out.println( p2_0.toNewHampshire() );
5933                 return false;
5934             }
5935             if ( !p.hasNext() ) {
5936                 return false;
5937             }
5938             p2_1 = p.next();
5939             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5940                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5941                 return false;
5942             }
5943             if ( !p.hasNext() ) {
5944                 return false;
5945             }
5946             p2_2 = p.next();
5947             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5948                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5949                 return false;
5950             }
5951             if ( !p.hasNext() ) {
5952                 return false;
5953             }
5954             p2_3 = p.next();
5955             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5956                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5957                 return false;
5958             }
5959             if ( !p.hasNext() ) {
5960                 return false;
5961             }
5962             p2_4 = p.next();
5963             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5964                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5965                 return false;
5966             }
5967             if ( p.hasNext() ) {
5968                 return false;
5969             }
5970             if ( p.next() != null ) {
5971                 return false;
5972             }
5973             //
5974             final String p3_str = "((A,B),C)abc";
5975             p.setSource( p3_str );
5976             if ( !p.hasNext() ) {
5977                 return false;
5978             }
5979             final Phylogeny p3_0 = p.next();
5980             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
5981                 return false;
5982             }
5983             if ( p.hasNext() ) {
5984                 return false;
5985             }
5986             if ( p.next() != null ) {
5987                 return false;
5988             }
5989             //
5990             final String p4_str = "((A,B)ab,C)abc";
5991             p.setSource( p4_str );
5992             if ( !p.hasNext() ) {
5993                 return false;
5994             }
5995             final Phylogeny p4_0 = p.next();
5996             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
5997                 return false;
5998             }
5999             if ( p.hasNext() ) {
6000                 return false;
6001             }
6002             if ( p.next() != null ) {
6003                 return false;
6004             }
6005             //
6006             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
6007             p.setSource( p5_str );
6008             if ( !p.hasNext() ) {
6009                 return false;
6010             }
6011             final Phylogeny p5_0 = p.next();
6012             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
6013                 return false;
6014             }
6015             if ( p.hasNext() ) {
6016                 return false;
6017             }
6018             if ( p.next() != null ) {
6019                 return false;
6020             }
6021             //
6022             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6023             p.setSource( p6_str );
6024             if ( !p.hasNext() ) {
6025                 return false;
6026             }
6027             Phylogeny p6_0 = p.next();
6028             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6029                 return false;
6030             }
6031             if ( p.hasNext() ) {
6032                 return false;
6033             }
6034             if ( p.next() != null ) {
6035                 return false;
6036             }
6037             p.reset();
6038             if ( !p.hasNext() ) {
6039                 return false;
6040             }
6041             p6_0 = p.next();
6042             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6043                 return false;
6044             }
6045             if ( p.hasNext() ) {
6046                 return false;
6047             }
6048             if ( p.next() != null ) {
6049                 return false;
6050             }
6051             //
6052             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6053             p.setSource( p7_str );
6054             if ( !p.hasNext() ) {
6055                 return false;
6056             }
6057             Phylogeny p7_0 = p.next();
6058             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6059                 return false;
6060             }
6061             if ( p.hasNext() ) {
6062                 return false;
6063             }
6064             if ( p.next() != null ) {
6065                 return false;
6066             }
6067             p.reset();
6068             if ( !p.hasNext() ) {
6069                 return false;
6070             }
6071             p7_0 = p.next();
6072             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
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 p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
6083             p.setSource( p8_str );
6084             if ( !p.hasNext() ) {
6085                 return false;
6086             }
6087             Phylogeny p8_0 = p.next();
6088             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6089                 return false;
6090             }
6091             if ( !p.hasNext() ) {
6092                 return false;
6093             }
6094             if ( !p.hasNext() ) {
6095                 return false;
6096             }
6097             Phylogeny p8_1 = p.next();
6098             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6099                 return false;
6100             }
6101             if ( p.hasNext() ) {
6102                 return false;
6103             }
6104             if ( p.next() != null ) {
6105                 return false;
6106             }
6107             p.reset();
6108             if ( !p.hasNext() ) {
6109                 return false;
6110             }
6111             p8_0 = p.next();
6112             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6113                 return false;
6114             }
6115             if ( !p.hasNext() ) {
6116                 return false;
6117             }
6118             p8_1 = p.next();
6119             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6120                 return false;
6121             }
6122             if ( p.hasNext() ) {
6123                 return false;
6124             }
6125             if ( p.next() != null ) {
6126                 return false;
6127             }
6128             p.reset();
6129             //
6130             p.setSource( "" );
6131             if ( p.hasNext() ) {
6132                 return false;
6133             }
6134             //
6135             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
6136             if ( !p.hasNext() ) {
6137                 return false;
6138             }
6139             Phylogeny p_27 = p.next();
6140             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6141                 System.out.println( p_27.toNewHampshireX() );
6142                 System.exit( -1 );
6143                 return false;
6144             }
6145             if ( p.hasNext() ) {
6146                 return false;
6147             }
6148             if ( p.next() != null ) {
6149                 return false;
6150             }
6151             p.reset();
6152             if ( !p.hasNext() ) {
6153                 return false;
6154             }
6155             p_27 = p.next();
6156             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6157                 System.out.println( p_27.toNewHampshireX() );
6158                 System.exit( -1 );
6159                 return false;
6160             }
6161             if ( p.hasNext() ) {
6162                 return false;
6163             }
6164             if ( p.next() != null ) {
6165                 return false;
6166             }
6167         }
6168         catch ( final Exception e ) {
6169             e.printStackTrace( System.out );
6170             return false;
6171         }
6172         return true;
6173     }
6174
6175     private static boolean testNHXconversion() {
6176         try {
6177             final PhylogenyNode n1 = new PhylogenyNode();
6178             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6179             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6180             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6181             final PhylogenyNode n5 = PhylogenyNode
6182                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
6183             final PhylogenyNode n6 = PhylogenyNode
6184                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
6185             if ( !n1.toNewHampshireX().equals( "" ) ) {
6186                 return false;
6187             }
6188             if ( !n2.toNewHampshireX().equals( "" ) ) {
6189                 return false;
6190             }
6191             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
6192                 return false;
6193             }
6194             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
6195                 return false;
6196             }
6197             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
6198                 return false;
6199             }
6200             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
6201                 System.out.println( n6.toNewHampshireX() );
6202                 return false;
6203             }
6204         }
6205         catch ( final Exception e ) {
6206             e.printStackTrace( System.out );
6207             return false;
6208         }
6209         return true;
6210     }
6211
6212     private static boolean testTaxonomyExtraction() {
6213         try {
6214             final PhylogenyNode n0 = PhylogenyNode
6215                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6216             if ( n0.getNodeData().isHasTaxonomy() ) {
6217                 return false;
6218             }
6219             final PhylogenyNode n1 = PhylogenyNode
6220                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6221             if ( n1.getNodeData().isHasTaxonomy() ) {
6222                 System.out.println( n1.toString() );
6223                 return false;
6224             }
6225             final PhylogenyNode n2 = PhylogenyNode
6226                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE );
6227             if ( !n2.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6228                 System.out.println( n2.toString() );
6229                 return false;
6230             }
6231             final PhylogenyNode n2x = PhylogenyNode
6232                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6233             if ( n2x.getNodeData().isHasTaxonomy() ) {
6234                 return false;
6235             }
6236             final PhylogenyNode n3 = PhylogenyNode
6237                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6238             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6239                 System.out.println( n3.toString() );
6240                 return false;
6241             }
6242             final PhylogenyNode n4 = PhylogenyNode
6243                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6244             if ( n4.getNodeData().isHasTaxonomy() ) {
6245                 System.out.println( n4.toString() );
6246                 return false;
6247             }
6248             final PhylogenyNode n5 = PhylogenyNode
6249                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6250             if ( n5.getNodeData().isHasTaxonomy() ) {
6251                 System.out.println( n5.toString() );
6252                 return false;
6253             }
6254             final PhylogenyNode n6 = PhylogenyNode
6255                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6256             if ( n6.getNodeData().isHasTaxonomy() ) {
6257                 System.out.println( n6.toString() );
6258                 return false;
6259             }
6260             final PhylogenyNode n7 = PhylogenyNode
6261                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6262             if ( n7.getNodeData().isHasTaxonomy() ) {
6263                 System.out.println( n7.toString() );
6264                 return false;
6265             }
6266             final PhylogenyNode n8 = PhylogenyNode
6267                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6268             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6269                 System.out.println( n8.toString() );
6270                 return false;
6271             }
6272             final PhylogenyNode n9 = PhylogenyNode
6273                     .createInstanceFromNhxString( "blag_12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6274             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6275                 System.out.println( n9.toString() );
6276                 return false;
6277             }
6278             final PhylogenyNode n10x = PhylogenyNode
6279                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6280             if ( n10x.getNodeData().isHasTaxonomy() ) {
6281                 System.out.println( n10x.toString() );
6282                 return false;
6283             }
6284             final PhylogenyNode n10xx = PhylogenyNode
6285                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6286             if ( n10xx.getNodeData().isHasTaxonomy() ) {
6287                 System.out.println( n10xx.toString() );
6288                 return false;
6289             }
6290             final PhylogenyNode n10 = PhylogenyNode
6291                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6292             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
6293                 System.out.println( n10.toString() );
6294                 return false;
6295             }
6296             final PhylogenyNode n11 = PhylogenyNode
6297                     .createInstanceFromNhxString( "blag_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6298             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
6299                 System.out.println( n11.toString() );
6300                 return false;
6301             }
6302             final PhylogenyNode n12 = PhylogenyNode
6303                     .createInstanceFromNhxString( "blag_Mus_musculus_musculus",
6304                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6305             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
6306                 System.out.println( n12.toString() );
6307                 return false;
6308             }
6309             final PhylogenyNode n13 = PhylogenyNode
6310                     .createInstanceFromNhxString( "blag_Mus_musculus1",
6311                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6312             if ( n13.getNodeData().isHasTaxonomy() ) {
6313                 System.out.println( n13.toString() );
6314                 return false;
6315             }
6316             final PhylogenyNode n14 = PhylogenyNode
6317                     .createInstanceFromNhxString( "blag_Mus_musculus_11",
6318                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6319             if ( n14.getNodeData().isHasTaxonomy() ) {
6320                 System.out.println( n14.toString() );
6321                 return false;
6322             }
6323             final PhylogenyNode n15 = PhylogenyNode
6324                     .createInstanceFromNhxString( "blag_Mus_musculus_v11",
6325                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6326             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus v11" ) ) {
6327                 System.out.println( n15.toString() );
6328                 return false;
6329             }
6330             final PhylogenyNode n16 = PhylogenyNode
6331                     .createInstanceFromNhxString( "blag_Mus_musculus_/11",
6332                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6333             if ( n16.getNodeData().isHasTaxonomy() ) {
6334                 System.out.println( n16.toString() );
6335                 return false;
6336             }
6337             final PhylogenyNode n17 = PhylogenyNode
6338                     .createInstanceFromNhxString( "blag_Mus_musculus_v",
6339                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6340             if ( n17.getNodeData().isHasTaxonomy() ) {
6341                 System.out.println( n17.toString() );
6342                 return false;
6343             }
6344         }
6345         catch ( final Exception e ) {
6346             e.printStackTrace( System.out );
6347             return false;
6348         }
6349         return true;
6350     }
6351
6352     private static boolean testNHXNodeParsing() {
6353         try {
6354             final PhylogenyNode n1 = new PhylogenyNode();
6355             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6356             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6357             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6358             final PhylogenyNode n5 = PhylogenyNode
6359                     .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]" );
6360             if ( !n3.getName().equals( "n3" ) ) {
6361                 return false;
6362             }
6363             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6364                 return false;
6365             }
6366             if ( n3.isDuplication() ) {
6367                 return false;
6368             }
6369             if ( n3.isHasAssignedEvent() ) {
6370                 return false;
6371             }
6372             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
6373                 return false;
6374             }
6375             if ( !n4.getName().equals( "n4" ) ) {
6376                 return false;
6377             }
6378             if ( n4.getDistanceToParent() != 0.01 ) {
6379                 return false;
6380             }
6381             if ( !n5.getName().equals( "n5" ) ) {
6382                 return false;
6383             }
6384             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
6385                 return false;
6386             }
6387             if ( n5.getDistanceToParent() != 0.1 ) {
6388                 return false;
6389             }
6390             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
6391                 return false;
6392             }
6393             if ( !n5.isDuplication() ) {
6394                 return false;
6395             }
6396             if ( !n5.isHasAssignedEvent() ) {
6397                 return false;
6398             }
6399             final PhylogenyNode n8 = PhylogenyNode
6400                     .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6401             if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
6402                 return false;
6403             }
6404             if ( PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
6405                 return false;
6406             }
6407             final PhylogenyNode n9 = PhylogenyNode
6408                     .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01",
6409                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6410             if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
6411                 return false;
6412             }
6413             if ( PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
6414                 return false;
6415             }
6416             final PhylogenyNode n10 = PhylogenyNode
6417                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6418             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
6419                 return false;
6420             }
6421             final PhylogenyNode n20 = PhylogenyNode
6422                     .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6423             if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
6424                 return false;
6425             }
6426             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
6427                 return false;
6428             }
6429             final PhylogenyNode n20x = PhylogenyNode
6430                     .createInstanceFromNhxString( "n20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6431             if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
6432                 return false;
6433             }
6434             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
6435                 return false;
6436             }
6437             final PhylogenyNode n20xx = PhylogenyNode
6438                     .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6439             if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
6440                 return false;
6441             }
6442             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
6443                 return false;
6444             }
6445             final PhylogenyNode n20xxx = PhylogenyNode
6446                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6447             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
6448                 return false;
6449             }
6450             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
6451                 return false;
6452             }
6453             final PhylogenyNode n20xxxx = PhylogenyNode
6454                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6455             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
6456                 return false;
6457             }
6458             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
6459                 return false;
6460             }
6461             final PhylogenyNode n21 = PhylogenyNode
6462                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6463             if ( !n21.getName().equals( "n21_PIG" ) ) {
6464                 return false;
6465             }
6466             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
6467                 return false;
6468             }
6469             final PhylogenyNode n21x = PhylogenyNode
6470                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6471             if ( !n21x.getName().equals( "n21_PIG" ) ) {
6472                 return false;
6473             }
6474             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
6475                 return false;
6476             }
6477             final PhylogenyNode n22 = PhylogenyNode
6478                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6479             if ( !n22.getName().equals( "n22/PIG" ) ) {
6480                 return false;
6481             }
6482             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
6483                 return false;
6484             }
6485             final PhylogenyNode n23 = PhylogenyNode
6486                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6487             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
6488                 return false;
6489             }
6490             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
6491                 return false;
6492             }
6493             final PhylogenyNode a = PhylogenyNode
6494                     .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6495             if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
6496                 return false;
6497             }
6498             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
6499                 return false;
6500             }
6501             final PhylogenyNode b = PhylogenyNode
6502                     .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6503             if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
6504                 return false;
6505             }
6506             if ( PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
6507                 return false;
6508             }
6509             final PhylogenyNode c = PhylogenyNode
6510                     .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
6511                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6512             if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
6513                 return false;
6514             }
6515             if ( PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
6516                 return false;
6517             }
6518             final PhylogenyNode c1 = PhylogenyNode
6519                     .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
6520                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6521             if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
6522                 return false;
6523             }
6524             if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
6525                 return false;
6526             }
6527             final PhylogenyNode c2 = PhylogenyNode
6528                     .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
6529                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6530             if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
6531                 return false;
6532             }
6533             if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
6534                 return false;
6535             }
6536             final PhylogenyNode d = PhylogenyNode
6537                     .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6538             if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
6539                 return false;
6540             }
6541             if ( PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
6542                 return false;
6543             }
6544             final PhylogenyNode e = PhylogenyNode
6545                     .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6546             if ( !e.getName().equals( "n10_RAT1" ) ) {
6547                 return false;
6548             }
6549             if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
6550                 return false;
6551             }
6552             final PhylogenyNode e2 = PhylogenyNode
6553                     .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6554             if ( !e2.getName().equals( "n10_RAT1" ) ) {
6555                 return false;
6556             }
6557             if ( PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
6558                 return false;
6559             }
6560             final PhylogenyNode e3 = PhylogenyNode
6561                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6562             if ( !e3.getName().equals( "n10_RAT~" ) ) {
6563                 return false;
6564             }
6565             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
6566                 return false;
6567             }
6568             final PhylogenyNode n11 = PhylogenyNode
6569                     .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
6570                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6571             if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
6572                 return false;
6573             }
6574             if ( n11.getDistanceToParent() != 0.4 ) {
6575                 return false;
6576             }
6577             if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
6578                 return false;
6579             }
6580             final PhylogenyNode n12 = PhylogenyNode
6581                     .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
6582                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6583             if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
6584                 return false;
6585             }
6586             if ( n12.getDistanceToParent() != 0.4 ) {
6587                 return false;
6588             }
6589             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
6590                 return false;
6591             }
6592             final PhylogenyNode m = PhylogenyNode
6593                     .createInstanceFromNhxString( "n10_MOUSEa", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6594             if ( !m.getName().equals( "n10_MOUSEa" ) ) {
6595                 return false;
6596             }
6597             if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
6598                 return false;
6599             }
6600             final PhylogenyNode o = PhylogenyNode
6601                     .createInstanceFromNhxString( "n10_MOUSE_", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6602             if ( !o.getName().equals( "n10_MOUSE_" ) ) {
6603                 return false;
6604             }
6605             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
6606                 return false;
6607             }
6608             if ( n1.getName().compareTo( "" ) != 0 ) {
6609                 return false;
6610             }
6611             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6612                 return false;
6613             }
6614             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6615                 return false;
6616             }
6617             if ( n2.getName().compareTo( "" ) != 0 ) {
6618                 return false;
6619             }
6620             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6621                 return false;
6622             }
6623             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6624                 return false;
6625             }
6626             final PhylogenyNode n00 = PhylogenyNode
6627                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
6628             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
6629                 return false;
6630             }
6631             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
6632                 return false;
6633             }
6634             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
6635             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
6636                 return false;
6637             }
6638             final PhylogenyNode n13 = PhylogenyNode
6639                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE );
6640             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
6641                 return false;
6642             }
6643             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
6644                 return false;
6645             }
6646             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6647                 return false;
6648             }
6649             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6650                 return false;
6651             }
6652             final PhylogenyNode n14 = PhylogenyNode
6653                     .createInstanceFromNhxString( "blah_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6654             if ( !n14.getName().equals( "blah_9QX45/1-2" ) ) {
6655                 return false;
6656             }
6657             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
6658                 return false;
6659             }
6660             final PhylogenyNode n15 = PhylogenyNode
6661                     .createInstanceFromNhxString( "something_wicked[123]",
6662                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6663             if ( !n15.getName().equals( "something_wicked" ) ) {
6664                 return false;
6665             }
6666             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
6667                 return false;
6668             }
6669             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
6670                 return false;
6671             }
6672             final PhylogenyNode n16 = PhylogenyNode
6673                     .createInstanceFromNhxString( "something_wicked2[9]",
6674                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6675             if ( !n16.getName().equals( "something_wicked2" ) ) {
6676                 return false;
6677             }
6678             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
6679                 return false;
6680             }
6681             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
6682                 return false;
6683             }
6684             final PhylogenyNode n17 = PhylogenyNode
6685                     .createInstanceFromNhxString( "something_wicked3[a]",
6686                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6687             if ( !n17.getName().equals( "something_wicked3" ) ) {
6688                 return false;
6689             }
6690             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
6691                 return false;
6692             }
6693             final PhylogenyNode n18 = PhylogenyNode
6694                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6695             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
6696                 return false;
6697             }
6698             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
6699                 return false;
6700             }
6701             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
6702                 return false;
6703             }
6704             final PhylogenyNode n19 = PhylogenyNode
6705                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6706             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
6707                 return false;
6708             }
6709             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6710                 return false;
6711             }
6712             final PhylogenyNode n30 = PhylogenyNode
6713                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
6714                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6715             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
6716                 return false;
6717             }
6718             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6719                 return false;
6720             }
6721             final PhylogenyNode n31 = PhylogenyNode
6722                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
6723                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6724             if ( n31.getNodeData().isHasTaxonomy() ) {
6725                 return false;
6726             }
6727             final PhylogenyNode n32 = PhylogenyNode
6728                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6729             if ( n32.getNodeData().isHasTaxonomy() ) {
6730                 return false;
6731             }
6732         }
6733         catch ( final Exception e ) {
6734             e.printStackTrace( System.out );
6735             return false;
6736         }
6737         return true;
6738     }
6739
6740     private static boolean testNHXParsing() {
6741         try {
6742             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6743             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
6744             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
6745                 return false;
6746             }
6747             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]";
6748             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
6749             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6750                 return false;
6751             }
6752             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]";
6753             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
6754             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
6755                 return false;
6756             }
6757             final Phylogeny[] p3 = factory
6758                     .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]",
6759                              new NHXParser() );
6760             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6761                 return false;
6762             }
6763             final Phylogeny[] p4 = factory
6764                     .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(]",
6765                              new NHXParser() );
6766             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6767                 return false;
6768             }
6769             final Phylogeny[] p5 = factory
6770                     .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(((]",
6771                              new NHXParser() );
6772             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6773                 return false;
6774             }
6775             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)";
6776             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)";
6777             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
6778             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
6779                 return false;
6780             }
6781             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)))";
6782             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)))";
6783             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
6784             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
6785                 return false;
6786             }
6787             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])   ))[,,, ])))))))";
6788             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
6789             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
6790             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
6791                 return false;
6792             }
6793             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
6794             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6795                 return false;
6796             }
6797             final Phylogeny p10 = factory
6798                     .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]",
6799                              new NHXParser() )[ 0 ];
6800             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6801                 return false;
6802             }
6803         }
6804         catch ( final Exception e ) {
6805             e.printStackTrace( System.out );
6806             return false;
6807         }
6808         return true;
6809     }
6810
6811     private static boolean testNHXParsingQuotes() {
6812         try {
6813             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6814             final NHXParser p = new NHXParser();
6815             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
6816             if ( phylogenies_0.length != 5 ) {
6817                 return false;
6818             }
6819             final Phylogeny phy = phylogenies_0[ 4 ];
6820             if ( phy.getNumberOfExternalNodes() != 7 ) {
6821                 return false;
6822             }
6823             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
6824                 return false;
6825             }
6826             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
6827                 return false;
6828             }
6829             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
6830                     .getScientificName().equals( "hsapiens" ) ) {
6831                 return false;
6832             }
6833             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
6834                 return false;
6835             }
6836             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
6837                 return false;
6838             }
6839             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
6840                 return false;
6841             }
6842             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
6843                 return false;
6844             }
6845             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
6846                 return false;
6847             }
6848             final NHXParser p1p = new NHXParser();
6849             p1p.setIgnoreQuotes( true );
6850             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
6851             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
6852                 return false;
6853             }
6854             final NHXParser p2p = new NHXParser();
6855             p1p.setIgnoreQuotes( false );
6856             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
6857             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
6858                 return false;
6859             }
6860             final NHXParser p3p = new NHXParser();
6861             p3p.setIgnoreQuotes( false );
6862             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
6863             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
6864                 return false;
6865             }
6866             final NHXParser p4p = new NHXParser();
6867             p4p.setIgnoreQuotes( false );
6868             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
6869             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
6870                 return false;
6871             }
6872             final Phylogeny p10 = factory
6873                     .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]",
6874                              new NHXParser() )[ 0 ];
6875             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]";
6876             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
6877                 return false;
6878             }
6879             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
6880             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
6881                 return false;
6882             }
6883             //
6884             final Phylogeny p12 = factory
6885                     .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]",
6886                              new NHXParser() )[ 0 ];
6887             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]";
6888             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
6889                 return false;
6890             }
6891             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
6892             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
6893                 return false;
6894             }
6895             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;";
6896             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
6897                 return false;
6898             }
6899             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
6900             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
6901                 return false;
6902             }
6903         }
6904         catch ( final Exception e ) {
6905             e.printStackTrace( System.out );
6906             return false;
6907         }
6908         return true;
6909     }
6910
6911     private static boolean testNHXParsingMB() {
6912         try {
6913             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6914             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
6915                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6916                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6917                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6918                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6919                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6920                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6921                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6922                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
6923             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
6924                 return false;
6925             }
6926             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
6927                 return false;
6928             }
6929             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
6930                            0.1100000000000000e+00 ) ) {
6931                 return false;
6932             }
6933             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
6934                 return false;
6935             }
6936             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
6937                 return false;
6938             }
6939             final Phylogeny p2 = factory
6940                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
6941                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6942                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6943                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6944                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6945                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6946                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6947                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6948                                      + "7.369400000000000e-02}])",
6949                              new NHXParser() )[ 0 ];
6950             if ( p2.getNode( "1" ) == null ) {
6951                 return false;
6952             }
6953             if ( p2.getNode( "2" ) == null ) {
6954                 return false;
6955             }
6956         }
6957         catch ( final Exception e ) {
6958             e.printStackTrace( System.out );
6959             System.exit( -1 );
6960             return false;
6961         }
6962         return true;
6963     }
6964
6965     private static boolean testPhylogenyBranch() {
6966         try {
6967             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
6968             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
6969             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
6970             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
6971             if ( !a1b1.equals( a1b1 ) ) {
6972                 return false;
6973             }
6974             if ( !a1b1.equals( b1a1 ) ) {
6975                 return false;
6976             }
6977             if ( !b1a1.equals( a1b1 ) ) {
6978                 return false;
6979             }
6980             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
6981             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
6982             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
6983             if ( a1_b1.equals( b1_a1 ) ) {
6984                 return false;
6985             }
6986             if ( a1_b1.equals( a1_b1_ ) ) {
6987                 return false;
6988             }
6989             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
6990             if ( !a1_b1.equals( b1_a1_ ) ) {
6991                 return false;
6992             }
6993             if ( a1_b1_.equals( b1_a1_ ) ) {
6994                 return false;
6995             }
6996             if ( !a1_b1_.equals( b1_a1 ) ) {
6997                 return false;
6998             }
6999         }
7000         catch ( final Exception e ) {
7001             e.printStackTrace( System.out );
7002             return false;
7003         }
7004         return true;
7005     }
7006
7007     private static boolean testPhyloXMLparsingOfDistributionElement() {
7008         try {
7009             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7010             PhyloXmlParser xml_parser = null;
7011             try {
7012                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
7013             }
7014             catch ( final Exception e ) {
7015                 // Do nothing -- means were not running from jar.
7016             }
7017             if ( xml_parser == null ) {
7018                 xml_parser = new PhyloXmlParser();
7019                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
7020                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
7021                 }
7022                 else {
7023                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
7024                 }
7025             }
7026             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
7027                                                               xml_parser );
7028             if ( xml_parser.getErrorCount() > 0 ) {
7029                 System.out.println( xml_parser.getErrorMessages().toString() );
7030                 return false;
7031             }
7032             if ( phylogenies_0.length != 1 ) {
7033                 return false;
7034             }
7035             final Phylogeny t1 = phylogenies_0[ 0 ];
7036             PhylogenyNode n = null;
7037             Distribution d = null;
7038             n = t1.getNode( "root node" );
7039             if ( !n.getNodeData().isHasDistribution() ) {
7040                 return false;
7041             }
7042             if ( n.getNodeData().getDistributions().size() != 1 ) {
7043                 return false;
7044             }
7045             d = n.getNodeData().getDistribution();
7046             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7047                 return false;
7048             }
7049             if ( d.getPoints().size() != 1 ) {
7050                 return false;
7051             }
7052             if ( d.getPolygons() != null ) {
7053                 return false;
7054             }
7055             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7056                 return false;
7057             }
7058             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7059                 return false;
7060             }
7061             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7062                 return false;
7063             }
7064             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7065                 return false;
7066             }
7067             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7068                 return false;
7069             }
7070             n = t1.getNode( "node a" );
7071             if ( !n.getNodeData().isHasDistribution() ) {
7072                 return false;
7073             }
7074             if ( n.getNodeData().getDistributions().size() != 2 ) {
7075                 return false;
7076             }
7077             d = n.getNodeData().getDistribution( 1 );
7078             if ( !d.getDesc().equals( "San Diego" ) ) {
7079                 return false;
7080             }
7081             if ( d.getPoints().size() != 1 ) {
7082                 return false;
7083             }
7084             if ( d.getPolygons() != null ) {
7085                 return false;
7086             }
7087             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7088                 return false;
7089             }
7090             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7091                 return false;
7092             }
7093             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7094                 return false;
7095             }
7096             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7097                 return false;
7098             }
7099             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7100                 return false;
7101             }
7102             n = t1.getNode( "node bb" );
7103             if ( !n.getNodeData().isHasDistribution() ) {
7104                 return false;
7105             }
7106             if ( n.getNodeData().getDistributions().size() != 1 ) {
7107                 return false;
7108             }
7109             d = n.getNodeData().getDistribution( 0 );
7110             if ( d.getPoints().size() != 3 ) {
7111                 return false;
7112             }
7113             if ( d.getPolygons().size() != 2 ) {
7114                 return false;
7115             }
7116             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7117                 return false;
7118             }
7119             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7120                 return false;
7121             }
7122             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7123                 return false;
7124             }
7125             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7126                 return false;
7127             }
7128             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7129                 return false;
7130             }
7131             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7132                 return false;
7133             }
7134             Polygon p = d.getPolygons().get( 0 );
7135             if ( p.getPoints().size() != 3 ) {
7136                 return false;
7137             }
7138             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7139                 return false;
7140             }
7141             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7142                 return false;
7143             }
7144             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7145                 return false;
7146             }
7147             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7148                 return false;
7149             }
7150             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7151                 return false;
7152             }
7153             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7154                 return false;
7155             }
7156             p = d.getPolygons().get( 1 );
7157             if ( p.getPoints().size() != 3 ) {
7158                 return false;
7159             }
7160             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7161                 return false;
7162             }
7163             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7164                 return false;
7165             }
7166             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7167                 return false;
7168             }
7169             // Roundtrip:
7170             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
7171             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
7172             if ( rt.length != 1 ) {
7173                 return false;
7174             }
7175             final Phylogeny t1_rt = rt[ 0 ];
7176             n = t1_rt.getNode( "root node" );
7177             if ( !n.getNodeData().isHasDistribution() ) {
7178                 return false;
7179             }
7180             if ( n.getNodeData().getDistributions().size() != 1 ) {
7181                 return false;
7182             }
7183             d = n.getNodeData().getDistribution();
7184             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7185                 return false;
7186             }
7187             if ( d.getPoints().size() != 1 ) {
7188                 return false;
7189             }
7190             if ( d.getPolygons() != null ) {
7191                 return false;
7192             }
7193             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7194                 return false;
7195             }
7196             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7197                 return false;
7198             }
7199             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7200                 return false;
7201             }
7202             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7203                 return false;
7204             }
7205             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7206                 return false;
7207             }
7208             n = t1_rt.getNode( "node a" );
7209             if ( !n.getNodeData().isHasDistribution() ) {
7210                 return false;
7211             }
7212             if ( n.getNodeData().getDistributions().size() != 2 ) {
7213                 return false;
7214             }
7215             d = n.getNodeData().getDistribution( 1 );
7216             if ( !d.getDesc().equals( "San Diego" ) ) {
7217                 return false;
7218             }
7219             if ( d.getPoints().size() != 1 ) {
7220                 return false;
7221             }
7222             if ( d.getPolygons() != null ) {
7223                 return false;
7224             }
7225             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7226                 return false;
7227             }
7228             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7229                 return false;
7230             }
7231             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7232                 return false;
7233             }
7234             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7235                 return false;
7236             }
7237             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7238                 return false;
7239             }
7240             n = t1_rt.getNode( "node bb" );
7241             if ( !n.getNodeData().isHasDistribution() ) {
7242                 return false;
7243             }
7244             if ( n.getNodeData().getDistributions().size() != 1 ) {
7245                 return false;
7246             }
7247             d = n.getNodeData().getDistribution( 0 );
7248             if ( d.getPoints().size() != 3 ) {
7249                 return false;
7250             }
7251             if ( d.getPolygons().size() != 2 ) {
7252                 return false;
7253             }
7254             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7255                 return false;
7256             }
7257             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7258                 return false;
7259             }
7260             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7261                 return false;
7262             }
7263             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7264                 return false;
7265             }
7266             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7267                 return false;
7268             }
7269             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7270                 return false;
7271             }
7272             p = d.getPolygons().get( 0 );
7273             if ( p.getPoints().size() != 3 ) {
7274                 return false;
7275             }
7276             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7277                 return false;
7278             }
7279             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7280                 return false;
7281             }
7282             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7283                 return false;
7284             }
7285             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7286                 return false;
7287             }
7288             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7289                 return false;
7290             }
7291             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7292                 return false;
7293             }
7294             p = d.getPolygons().get( 1 );
7295             if ( p.getPoints().size() != 3 ) {
7296                 return false;
7297             }
7298             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7299                 return false;
7300             }
7301             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7302                 return false;
7303             }
7304             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7305                 return false;
7306             }
7307         }
7308         catch ( final Exception e ) {
7309             e.printStackTrace( System.out );
7310             return false;
7311         }
7312         return true;
7313     }
7314
7315     private static boolean testPostOrderIterator() {
7316         try {
7317             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7318             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7319             PhylogenyNodeIterator it0;
7320             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
7321                 it0.next();
7322             }
7323             for( it0.reset(); it0.hasNext(); ) {
7324                 it0.next();
7325             }
7326             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7327             final PhylogenyNodeIterator it = t1.iteratorPostorder();
7328             if ( !it.next().getName().equals( "A" ) ) {
7329                 return false;
7330             }
7331             if ( !it.next().getName().equals( "B" ) ) {
7332                 return false;
7333             }
7334             if ( !it.next().getName().equals( "ab" ) ) {
7335                 return false;
7336             }
7337             if ( !it.next().getName().equals( "C" ) ) {
7338                 return false;
7339             }
7340             if ( !it.next().getName().equals( "D" ) ) {
7341                 return false;
7342             }
7343             if ( !it.next().getName().equals( "cd" ) ) {
7344                 return false;
7345             }
7346             if ( !it.next().getName().equals( "abcd" ) ) {
7347                 return false;
7348             }
7349             if ( !it.next().getName().equals( "E" ) ) {
7350                 return false;
7351             }
7352             if ( !it.next().getName().equals( "F" ) ) {
7353                 return false;
7354             }
7355             if ( !it.next().getName().equals( "ef" ) ) {
7356                 return false;
7357             }
7358             if ( !it.next().getName().equals( "G" ) ) {
7359                 return false;
7360             }
7361             if ( !it.next().getName().equals( "H" ) ) {
7362                 return false;
7363             }
7364             if ( !it.next().getName().equals( "gh" ) ) {
7365                 return false;
7366             }
7367             if ( !it.next().getName().equals( "efgh" ) ) {
7368                 return false;
7369             }
7370             if ( !it.next().getName().equals( "r" ) ) {
7371                 return false;
7372             }
7373             if ( it.hasNext() ) {
7374                 return false;
7375             }
7376         }
7377         catch ( final Exception e ) {
7378             e.printStackTrace( System.out );
7379             return false;
7380         }
7381         return true;
7382     }
7383
7384     private static boolean testPreOrderIterator() {
7385         try {
7386             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7387             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7388             PhylogenyNodeIterator it0;
7389             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
7390                 it0.next();
7391             }
7392             for( it0.reset(); it0.hasNext(); ) {
7393                 it0.next();
7394             }
7395             PhylogenyNodeIterator it = t0.iteratorPreorder();
7396             if ( !it.next().getName().equals( "r" ) ) {
7397                 return false;
7398             }
7399             if ( !it.next().getName().equals( "ab" ) ) {
7400                 return false;
7401             }
7402             if ( !it.next().getName().equals( "A" ) ) {
7403                 return false;
7404             }
7405             if ( !it.next().getName().equals( "B" ) ) {
7406                 return false;
7407             }
7408             if ( !it.next().getName().equals( "cd" ) ) {
7409                 return false;
7410             }
7411             if ( !it.next().getName().equals( "C" ) ) {
7412                 return false;
7413             }
7414             if ( !it.next().getName().equals( "D" ) ) {
7415                 return false;
7416             }
7417             if ( it.hasNext() ) {
7418                 return false;
7419             }
7420             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7421             it = t1.iteratorPreorder();
7422             if ( !it.next().getName().equals( "r" ) ) {
7423                 return false;
7424             }
7425             if ( !it.next().getName().equals( "abcd" ) ) {
7426                 return false;
7427             }
7428             if ( !it.next().getName().equals( "ab" ) ) {
7429                 return false;
7430             }
7431             if ( !it.next().getName().equals( "A" ) ) {
7432                 return false;
7433             }
7434             if ( !it.next().getName().equals( "B" ) ) {
7435                 return false;
7436             }
7437             if ( !it.next().getName().equals( "cd" ) ) {
7438                 return false;
7439             }
7440             if ( !it.next().getName().equals( "C" ) ) {
7441                 return false;
7442             }
7443             if ( !it.next().getName().equals( "D" ) ) {
7444                 return false;
7445             }
7446             if ( !it.next().getName().equals( "efgh" ) ) {
7447                 return false;
7448             }
7449             if ( !it.next().getName().equals( "ef" ) ) {
7450                 return false;
7451             }
7452             if ( !it.next().getName().equals( "E" ) ) {
7453                 return false;
7454             }
7455             if ( !it.next().getName().equals( "F" ) ) {
7456                 return false;
7457             }
7458             if ( !it.next().getName().equals( "gh" ) ) {
7459                 return false;
7460             }
7461             if ( !it.next().getName().equals( "G" ) ) {
7462                 return false;
7463             }
7464             if ( !it.next().getName().equals( "H" ) ) {
7465                 return false;
7466             }
7467             if ( it.hasNext() ) {
7468                 return false;
7469             }
7470         }
7471         catch ( final Exception e ) {
7472             e.printStackTrace( System.out );
7473             return false;
7474         }
7475         return true;
7476     }
7477
7478     private static boolean testPropertiesMap() {
7479         try {
7480             final PropertiesMap pm = new PropertiesMap();
7481             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7482             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7483             final Property p2 = new Property( "something:else",
7484                                               "?",
7485                                               "improbable:research",
7486                                               "xsd:decimal",
7487                                               AppliesTo.NODE );
7488             pm.addProperty( p0 );
7489             pm.addProperty( p1 );
7490             pm.addProperty( p2 );
7491             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
7492                 return false;
7493             }
7494             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
7495                 return false;
7496             }
7497             if ( pm.getProperties().size() != 3 ) {
7498                 return false;
7499             }
7500             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
7501                 return false;
7502             }
7503             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7504                 return false;
7505             }
7506             if ( pm.getProperties().size() != 3 ) {
7507                 return false;
7508             }
7509             pm.removeProperty( "dimensions:diameter" );
7510             if ( pm.getProperties().size() != 2 ) {
7511                 return false;
7512             }
7513             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
7514                 return false;
7515             }
7516             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7517                 return false;
7518             }
7519         }
7520         catch ( final Exception e ) {
7521             e.printStackTrace( System.out );
7522             return false;
7523         }
7524         return true;
7525     }
7526
7527     private static boolean testReIdMethods() {
7528         try {
7529             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7530             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
7531             final long count = PhylogenyNode.getNodeCount();
7532             p.levelOrderReID();
7533             if ( p.getNode( "r" ).getId() != count ) {
7534                 return false;
7535             }
7536             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
7537                 return false;
7538             }
7539             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
7540                 return false;
7541             }
7542             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
7543                 return false;
7544             }
7545             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
7546                 return false;
7547             }
7548             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
7549                 return false;
7550             }
7551             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
7552                 return false;
7553             }
7554             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
7555                 return false;
7556             }
7557             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
7558                 return false;
7559             }
7560             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
7561                 return false;
7562             }
7563             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
7564                 return false;
7565             }
7566             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
7567                 return false;
7568             }
7569             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
7570                 return false;
7571             }
7572             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
7573                 return false;
7574             }
7575             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
7576                 return false;
7577             }
7578         }
7579         catch ( final Exception e ) {
7580             e.printStackTrace( System.out );
7581             return false;
7582         }
7583         return true;
7584     }
7585
7586     private static boolean testRerooting() {
7587         try {
7588             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7589             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",
7590                                                  new NHXParser() )[ 0 ];
7591             if ( !t1.isRooted() ) {
7592                 return false;
7593             }
7594             t1.reRoot( t1.getNode( "D" ) );
7595             t1.reRoot( t1.getNode( "CD" ) );
7596             t1.reRoot( t1.getNode( "A" ) );
7597             t1.reRoot( t1.getNode( "B" ) );
7598             t1.reRoot( t1.getNode( "AB" ) );
7599             t1.reRoot( t1.getNode( "D" ) );
7600             t1.reRoot( t1.getNode( "C" ) );
7601             t1.reRoot( t1.getNode( "CD" ) );
7602             t1.reRoot( t1.getNode( "A" ) );
7603             t1.reRoot( t1.getNode( "B" ) );
7604             t1.reRoot( t1.getNode( "AB" ) );
7605             t1.reRoot( t1.getNode( "D" ) );
7606             t1.reRoot( t1.getNode( "D" ) );
7607             t1.reRoot( t1.getNode( "C" ) );
7608             t1.reRoot( t1.getNode( "A" ) );
7609             t1.reRoot( t1.getNode( "B" ) );
7610             t1.reRoot( t1.getNode( "AB" ) );
7611             t1.reRoot( t1.getNode( "C" ) );
7612             t1.reRoot( t1.getNode( "D" ) );
7613             t1.reRoot( t1.getNode( "CD" ) );
7614             t1.reRoot( t1.getNode( "D" ) );
7615             t1.reRoot( t1.getNode( "A" ) );
7616             t1.reRoot( t1.getNode( "B" ) );
7617             t1.reRoot( t1.getNode( "AB" ) );
7618             t1.reRoot( t1.getNode( "C" ) );
7619             t1.reRoot( t1.getNode( "D" ) );
7620             t1.reRoot( t1.getNode( "CD" ) );
7621             t1.reRoot( t1.getNode( "D" ) );
7622             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
7623                 return false;
7624             }
7625             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
7626                 return false;
7627             }
7628             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
7629                 return false;
7630             }
7631             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
7632                 return false;
7633             }
7634             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
7635                 return false;
7636             }
7637             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
7638                 return false;
7639             }
7640             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",
7641                                                  new NHXParser() )[ 0 ];
7642             t2.reRoot( t2.getNode( "A" ) );
7643             t2.reRoot( t2.getNode( "D" ) );
7644             t2.reRoot( t2.getNode( "ABC" ) );
7645             t2.reRoot( t2.getNode( "A" ) );
7646             t2.reRoot( t2.getNode( "B" ) );
7647             t2.reRoot( t2.getNode( "D" ) );
7648             t2.reRoot( t2.getNode( "C" ) );
7649             t2.reRoot( t2.getNode( "ABC" ) );
7650             t2.reRoot( t2.getNode( "A" ) );
7651             t2.reRoot( t2.getNode( "B" ) );
7652             t2.reRoot( t2.getNode( "AB" ) );
7653             t2.reRoot( t2.getNode( "AB" ) );
7654             t2.reRoot( t2.getNode( "D" ) );
7655             t2.reRoot( t2.getNode( "C" ) );
7656             t2.reRoot( t2.getNode( "B" ) );
7657             t2.reRoot( t2.getNode( "AB" ) );
7658             t2.reRoot( t2.getNode( "D" ) );
7659             t2.reRoot( t2.getNode( "D" ) );
7660             t2.reRoot( t2.getNode( "ABC" ) );
7661             t2.reRoot( t2.getNode( "A" ) );
7662             t2.reRoot( t2.getNode( "B" ) );
7663             t2.reRoot( t2.getNode( "AB" ) );
7664             t2.reRoot( t2.getNode( "D" ) );
7665             t2.reRoot( t2.getNode( "C" ) );
7666             t2.reRoot( t2.getNode( "ABC" ) );
7667             t2.reRoot( t2.getNode( "A" ) );
7668             t2.reRoot( t2.getNode( "B" ) );
7669             t2.reRoot( t2.getNode( "AB" ) );
7670             t2.reRoot( t2.getNode( "D" ) );
7671             t2.reRoot( t2.getNode( "D" ) );
7672             t2.reRoot( t2.getNode( "C" ) );
7673             t2.reRoot( t2.getNode( "A" ) );
7674             t2.reRoot( t2.getNode( "B" ) );
7675             t2.reRoot( t2.getNode( "AB" ) );
7676             t2.reRoot( t2.getNode( "C" ) );
7677             t2.reRoot( t2.getNode( "D" ) );
7678             t2.reRoot( t2.getNode( "ABC" ) );
7679             t2.reRoot( t2.getNode( "D" ) );
7680             t2.reRoot( t2.getNode( "A" ) );
7681             t2.reRoot( t2.getNode( "B" ) );
7682             t2.reRoot( t2.getNode( "AB" ) );
7683             t2.reRoot( t2.getNode( "C" ) );
7684             t2.reRoot( t2.getNode( "D" ) );
7685             t2.reRoot( t2.getNode( "ABC" ) );
7686             t2.reRoot( t2.getNode( "D" ) );
7687             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7688                 return false;
7689             }
7690             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7691                 return false;
7692             }
7693             t2.reRoot( t2.getNode( "ABC" ) );
7694             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7695                 return false;
7696             }
7697             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7698                 return false;
7699             }
7700             t2.reRoot( t2.getNode( "AB" ) );
7701             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7702                 return false;
7703             }
7704             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7705                 return false;
7706             }
7707             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7708                 return false;
7709             }
7710             t2.reRoot( t2.getNode( "AB" ) );
7711             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7712                 return false;
7713             }
7714             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7715                 return false;
7716             }
7717             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7718                 return false;
7719             }
7720             t2.reRoot( t2.getNode( "D" ) );
7721             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7722                 return false;
7723             }
7724             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7725                 return false;
7726             }
7727             t2.reRoot( t2.getNode( "ABC" ) );
7728             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7729                 return false;
7730             }
7731             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7732                 return false;
7733             }
7734             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
7735                                                  new NHXParser() )[ 0 ];
7736             t3.reRoot( t3.getNode( "B" ) );
7737             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7738                 return false;
7739             }
7740             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7741                 return false;
7742             }
7743             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7744                 return false;
7745             }
7746             t3.reRoot( t3.getNode( "B" ) );
7747             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7748                 return false;
7749             }
7750             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7751                 return false;
7752             }
7753             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7754                 return false;
7755             }
7756             t3.reRoot( t3.getRoot() );
7757             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7758                 return false;
7759             }
7760             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7761                 return false;
7762             }
7763             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7764                 return false;
7765             }
7766         }
7767         catch ( final Exception e ) {
7768             e.printStackTrace( System.out );
7769             return false;
7770         }
7771         return true;
7772     }
7773
7774     private static boolean testSDIse() {
7775         try {
7776             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7777             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
7778             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
7779             gene1.setRooted( true );
7780             species1.setRooted( true );
7781             final SDI sdi = new SDI( gene1, species1 );
7782             if ( !gene1.getRoot().isDuplication() ) {
7783                 return false;
7784             }
7785             final Phylogeny species2 = factory
7786                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7787                              new NHXParser() )[ 0 ];
7788             final Phylogeny gene2 = factory
7789                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7790                              new NHXParser() )[ 0 ];
7791             species2.setRooted( true );
7792             gene2.setRooted( true );
7793             final SDI sdi2 = new SDI( gene2, species2 );
7794             if ( sdi2.getDuplicationsSum() != 0 ) {
7795                 return false;
7796             }
7797             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
7798                 return false;
7799             }
7800             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
7801                 return false;
7802             }
7803             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
7804                 return false;
7805             }
7806             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
7807                 return false;
7808             }
7809             if ( !gene2.getNode( "r" ).isSpeciation() ) {
7810                 return false;
7811             }
7812             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
7813                 return false;
7814             }
7815             final Phylogeny species3 = factory
7816                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7817                              new NHXParser() )[ 0 ];
7818             final Phylogeny gene3 = factory
7819                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7820                              new NHXParser() )[ 0 ];
7821             species3.setRooted( true );
7822             gene3.setRooted( true );
7823             final SDI sdi3 = new SDI( gene3, species3 );
7824             if ( sdi3.getDuplicationsSum() != 1 ) {
7825                 return false;
7826             }
7827             if ( !gene3.getNode( "aa" ).isDuplication() ) {
7828                 return false;
7829             }
7830             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
7831                 return false;
7832             }
7833             final Phylogeny species4 = factory
7834                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7835                              new NHXParser() )[ 0 ];
7836             final Phylogeny gene4 = factory
7837                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7838                              new NHXParser() )[ 0 ];
7839             species4.setRooted( true );
7840             gene4.setRooted( true );
7841             final SDI sdi4 = new SDI( gene4, species4 );
7842             if ( sdi4.getDuplicationsSum() != 1 ) {
7843                 return false;
7844             }
7845             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
7846                 return false;
7847             }
7848             if ( !gene4.getNode( "abc" ).isDuplication() ) {
7849                 return false;
7850             }
7851             if ( gene4.getNode( "abcd" ).isDuplication() ) {
7852                 return false;
7853             }
7854             if ( species4.getNumberOfExternalNodes() != 6 ) {
7855                 return false;
7856             }
7857             if ( gene4.getNumberOfExternalNodes() != 6 ) {
7858                 return false;
7859             }
7860             final Phylogeny species5 = factory
7861                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7862                              new NHXParser() )[ 0 ];
7863             final Phylogeny gene5 = factory
7864                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7865                              new NHXParser() )[ 0 ];
7866             species5.setRooted( true );
7867             gene5.setRooted( true );
7868             final SDI sdi5 = new SDI( gene5, species5 );
7869             if ( sdi5.getDuplicationsSum() != 2 ) {
7870                 return false;
7871             }
7872             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
7873                 return false;
7874             }
7875             if ( !gene5.getNode( "adc" ).isDuplication() ) {
7876                 return false;
7877             }
7878             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
7879                 return false;
7880             }
7881             if ( species5.getNumberOfExternalNodes() != 6 ) {
7882                 return false;
7883             }
7884             if ( gene5.getNumberOfExternalNodes() != 6 ) {
7885                 return false;
7886             }
7887             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
7888             // Conjecture for Comparing Molecular Phylogenies"
7889             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
7890             final Phylogeny species6 = factory
7891                     .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,"
7892                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
7893                              new NHXParser() )[ 0 ];
7894             final Phylogeny gene6 = factory
7895                     .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,"
7896                                      + "((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,"
7897                                      + "(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;",
7898                              new NHXParser() )[ 0 ];
7899             species6.setRooted( true );
7900             gene6.setRooted( true );
7901             final SDI sdi6 = new SDI( gene6, species6 );
7902             if ( sdi6.getDuplicationsSum() != 3 ) {
7903                 return false;
7904             }
7905             if ( !gene6.getNode( "r" ).isDuplication() ) {
7906                 return false;
7907             }
7908             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
7909                 return false;
7910             }
7911             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
7912                 return false;
7913             }
7914             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
7915                 return false;
7916             }
7917             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
7918                 return false;
7919             }
7920             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
7921                 return false;
7922             }
7923             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
7924                 return false;
7925             }
7926             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
7927                 return false;
7928             }
7929             sdi6.computeMappingCostL();
7930             if ( sdi6.computeMappingCostL() != 17 ) {
7931                 return false;
7932             }
7933             if ( species6.getNumberOfExternalNodes() != 9 ) {
7934                 return false;
7935             }
7936             if ( gene6.getNumberOfExternalNodes() != 9 ) {
7937                 return false;
7938             }
7939             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
7940                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
7941                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
7942                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
7943                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
7944             species7.setRooted( true );
7945             final Phylogeny gene7_1 = Test
7946                     .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])" );
7947             gene7_1.setRooted( true );
7948             final SDI sdi7 = new SDI( gene7_1, species7 );
7949             if ( sdi7.getDuplicationsSum() != 0 ) {
7950                 return false;
7951             }
7952             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
7953                 return false;
7954             }
7955             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
7956                 return false;
7957             }
7958             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
7959                 return false;
7960             }
7961             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
7962                 return false;
7963             }
7964             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
7965                 return false;
7966             }
7967             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
7968                 return false;
7969             }
7970             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
7971                 return false;
7972             }
7973             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
7974                 return false;
7975             }
7976             final Phylogeny gene7_2 = Test
7977                     .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])" );
7978             gene7_2.setRooted( true );
7979             final SDI sdi7_2 = new SDI( gene7_2, species7 );
7980             if ( sdi7_2.getDuplicationsSum() != 1 ) {
7981                 return false;
7982             }
7983             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
7984                 return false;
7985             }
7986             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
7987                 return false;
7988             }
7989             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
7990                 return false;
7991             }
7992             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
7993                 return false;
7994             }
7995             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
7996                 return false;
7997             }
7998             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
7999                 return false;
8000             }
8001             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
8002                 return false;
8003             }
8004             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
8005                 return false;
8006             }
8007             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
8008                 return false;
8009             }
8010         }
8011         catch ( final Exception e ) {
8012             return false;
8013         }
8014         return true;
8015     }
8016
8017     private static boolean testSDIunrooted() {
8018         try {
8019             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8020             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
8021             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
8022             final Iterator<PhylogenyBranch> iter = l.iterator();
8023             PhylogenyBranch br = iter.next();
8024             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
8025                 return false;
8026             }
8027             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
8028                 return false;
8029             }
8030             br = iter.next();
8031             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8032                 return false;
8033             }
8034             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8035                 return false;
8036             }
8037             br = iter.next();
8038             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
8039                 return false;
8040             }
8041             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
8042                 return false;
8043             }
8044             br = iter.next();
8045             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8046                 return false;
8047             }
8048             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8049                 return false;
8050             }
8051             br = iter.next();
8052             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8053                 return false;
8054             }
8055             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8056                 return false;
8057             }
8058             br = iter.next();
8059             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8060                 return false;
8061             }
8062             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8063                 return false;
8064             }
8065             br = iter.next();
8066             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8067                 return false;
8068             }
8069             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8070                 return false;
8071             }
8072             br = iter.next();
8073             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8074                 return false;
8075             }
8076             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8077                 return false;
8078             }
8079             br = iter.next();
8080             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8081                 return false;
8082             }
8083             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8084                 return false;
8085             }
8086             br = iter.next();
8087             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8088                 return false;
8089             }
8090             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8091                 return false;
8092             }
8093             br = iter.next();
8094             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8095                 return false;
8096             }
8097             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8098                 return false;
8099             }
8100             br = iter.next();
8101             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
8102                 return false;
8103             }
8104             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
8105                 return false;
8106             }
8107             br = iter.next();
8108             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8109                 return false;
8110             }
8111             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8112                 return false;
8113             }
8114             br = iter.next();
8115             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
8116                 return false;
8117             }
8118             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
8119                 return false;
8120             }
8121             br = iter.next();
8122             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
8123                 return false;
8124             }
8125             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
8126                 return false;
8127             }
8128             if ( iter.hasNext() ) {
8129                 return false;
8130             }
8131             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
8132             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
8133             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
8134             br = iter1.next();
8135             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8136                 return false;
8137             }
8138             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8139                 return false;
8140             }
8141             br = iter1.next();
8142             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8143                 return false;
8144             }
8145             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8146                 return false;
8147             }
8148             br = iter1.next();
8149             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8150                 return false;
8151             }
8152             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8153                 return false;
8154             }
8155             if ( iter1.hasNext() ) {
8156                 return false;
8157             }
8158             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
8159             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
8160             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
8161             br = iter2.next();
8162             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8163                 return false;
8164             }
8165             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8166                 return false;
8167             }
8168             br = iter2.next();
8169             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8170                 return false;
8171             }
8172             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8173                 return false;
8174             }
8175             br = iter2.next();
8176             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8177                 return false;
8178             }
8179             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8180                 return false;
8181             }
8182             if ( iter2.hasNext() ) {
8183                 return false;
8184             }
8185             final Phylogeny species0 = factory
8186                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
8187                              new NHXParser() )[ 0 ];
8188             final Phylogeny gene1 = factory
8189                     .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])",
8190                              new NHXParser() )[ 0 ];
8191             species0.setRooted( true );
8192             gene1.setRooted( true );
8193             final SDIR sdi_unrooted = new SDIR();
8194             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
8195             if ( sdi_unrooted.getCount() != 1 ) {
8196                 return false;
8197             }
8198             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
8199                 return false;
8200             }
8201             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
8202                 return false;
8203             }
8204             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
8205                 return false;
8206             }
8207             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8208                 return false;
8209             }
8210             final Phylogeny gene2 = factory
8211                     .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])",
8212                              new NHXParser() )[ 0 ];
8213             gene2.setRooted( true );
8214             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
8215             if ( sdi_unrooted.getCount() != 1 ) {
8216                 return false;
8217             }
8218             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8219                 return false;
8220             }
8221             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8222                 return false;
8223             }
8224             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
8225                 return false;
8226             }
8227             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8228                 return false;
8229             }
8230             final Phylogeny species6 = factory
8231                     .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,"
8232                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8233                              new NHXParser() )[ 0 ];
8234             final Phylogeny gene6 = factory
8235                     .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],"
8236                                      + "(((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],"
8237                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8238                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8239                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8240                              new NHXParser() )[ 0 ];
8241             species6.setRooted( true );
8242             gene6.setRooted( true );
8243             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
8244             if ( sdi_unrooted.getCount() != 1 ) {
8245                 return false;
8246             }
8247             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8248                 return false;
8249             }
8250             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8251                 return false;
8252             }
8253             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8254                 return false;
8255             }
8256             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8257                 return false;
8258             }
8259             if ( !p6[ 0 ].getRoot().isDuplication() ) {
8260                 return false;
8261             }
8262             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8263                 return false;
8264             }
8265             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8266                 return false;
8267             }
8268             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
8269                 return false;
8270             }
8271             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8272                 return false;
8273             }
8274             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
8275                 return false;
8276             }
8277             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
8278                 return false;
8279             }
8280             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8281                 return false;
8282             }
8283             p6 = null;
8284             final Phylogeny species7 = factory
8285                     .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,"
8286                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8287                              new NHXParser() )[ 0 ];
8288             final Phylogeny gene7 = factory
8289                     .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],"
8290                                      + "(((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],"
8291                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8292                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8293                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8294                              new NHXParser() )[ 0 ];
8295             species7.setRooted( true );
8296             gene7.setRooted( true );
8297             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
8298             if ( sdi_unrooted.getCount() != 1 ) {
8299                 return false;
8300             }
8301             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8302                 return false;
8303             }
8304             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8305                 return false;
8306             }
8307             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8308                 return false;
8309             }
8310             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
8311                 return false;
8312             }
8313             if ( !p7[ 0 ].getRoot().isDuplication() ) {
8314                 return false;
8315             }
8316             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8317                 return false;
8318             }
8319             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8320                 return false;
8321             }
8322             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
8323                 return false;
8324             }
8325             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8326                 return false;
8327             }
8328             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
8329                 return false;
8330             }
8331             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
8332                 return false;
8333             }
8334             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8335                 return false;
8336             }
8337             p7 = null;
8338             final Phylogeny species8 = factory
8339                     .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,"
8340                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8341                              new NHXParser() )[ 0 ];
8342             final Phylogeny gene8 = factory
8343                     .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],"
8344                                      + "(((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],"
8345                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8346                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8347                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8348                              new NHXParser() )[ 0 ];
8349             species8.setRooted( true );
8350             gene8.setRooted( true );
8351             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
8352             if ( sdi_unrooted.getCount() != 1 ) {
8353                 return false;
8354             }
8355             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8356                 return false;
8357             }
8358             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8359                 return false;
8360             }
8361             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8362                 return false;
8363             }
8364             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8365                 return false;
8366             }
8367             if ( !p8[ 0 ].getRoot().isDuplication() ) {
8368                 return false;
8369             }
8370             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8371                 return false;
8372             }
8373             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8374                 return false;
8375             }
8376             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
8377                 return false;
8378             }
8379             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8380                 return false;
8381             }
8382             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
8383                 return false;
8384             }
8385             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
8386                 return false;
8387             }
8388             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8389                 return false;
8390             }
8391             p8 = null;
8392         }
8393         catch ( final Exception e ) {
8394             e.printStackTrace( System.out );
8395             return false;
8396         }
8397         return true;
8398     }
8399
8400     private static boolean testSplit() {
8401         try {
8402             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8403             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8404             //Archaeopteryx.createApplication( p0 );
8405             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8406             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8407             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8408             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8409             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8410             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8411             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8412             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8413             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8414             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8415             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
8416             // System.out.println( s0.toString() );
8417             //
8418             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8419             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8421             if ( s0.match( query_nodes ) ) {
8422                 return false;
8423             }
8424             query_nodes = new HashSet<PhylogenyNode>();
8425             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8426             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8430             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8431             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8432             if ( !s0.match( query_nodes ) ) {
8433                 return false;
8434             }
8435             //
8436             query_nodes = new HashSet<PhylogenyNode>();
8437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8438             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8439             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8440             if ( !s0.match( query_nodes ) ) {
8441                 return false;
8442             }
8443             //
8444             query_nodes = new HashSet<PhylogenyNode>();
8445             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8447             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8448             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8449             if ( !s0.match( query_nodes ) ) {
8450                 return false;
8451             }
8452             //
8453             query_nodes = new HashSet<PhylogenyNode>();
8454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8456             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8457             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8458             if ( !s0.match( query_nodes ) ) {
8459                 return false;
8460             }
8461             //
8462             query_nodes = new HashSet<PhylogenyNode>();
8463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8465             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8466             if ( !s0.match( query_nodes ) ) {
8467                 return false;
8468             }
8469             //
8470             query_nodes = new HashSet<PhylogenyNode>();
8471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8473             if ( !s0.match( query_nodes ) ) {
8474                 return false;
8475             }
8476             //
8477             query_nodes = new HashSet<PhylogenyNode>();
8478             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8482             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8483             if ( !s0.match( query_nodes ) ) {
8484                 return false;
8485             }
8486             //
8487             query_nodes = new HashSet<PhylogenyNode>();
8488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8490             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8491             if ( !s0.match( query_nodes ) ) {
8492                 return false;
8493             }
8494             //
8495             query_nodes = new HashSet<PhylogenyNode>();
8496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8498             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8499             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8500             if ( !s0.match( query_nodes ) ) {
8501                 return false;
8502             }
8503             //
8504             query_nodes = new HashSet<PhylogenyNode>();
8505             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8506             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8507             if ( s0.match( query_nodes ) ) {
8508                 return false;
8509             }
8510             //
8511             query_nodes = new HashSet<PhylogenyNode>();
8512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8513             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8514             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8515             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
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             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8524             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8525             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8526             if ( s0.match( query_nodes ) ) {
8527                 return false;
8528             }
8529             //
8530             query_nodes = new HashSet<PhylogenyNode>();
8531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8533             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8534             if ( s0.match( query_nodes ) ) {
8535                 return false;
8536             }
8537             //
8538             query_nodes = new HashSet<PhylogenyNode>();
8539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8541             if ( s0.match( query_nodes ) ) {
8542                 return false;
8543             }
8544             //
8545             query_nodes = new HashSet<PhylogenyNode>();
8546             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8548             if ( s0.match( query_nodes ) ) {
8549                 return false;
8550             }
8551             //
8552             query_nodes = new HashSet<PhylogenyNode>();
8553             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8554             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8555             if ( s0.match( query_nodes ) ) {
8556                 return false;
8557             }
8558             //
8559             query_nodes = new HashSet<PhylogenyNode>();
8560             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8561             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8562             if ( s0.match( query_nodes ) ) {
8563                 return false;
8564             }
8565             //
8566             query_nodes = new HashSet<PhylogenyNode>();
8567             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8568             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8569             if ( s0.match( query_nodes ) ) {
8570                 return false;
8571             }
8572             //
8573             query_nodes = new HashSet<PhylogenyNode>();
8574             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8575             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "F" ) );
8583             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "B" ) );
8591             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8592             if ( s0.match( query_nodes ) ) {
8593                 return false;
8594             }
8595             //
8596             query_nodes = new HashSet<PhylogenyNode>();
8597             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8598             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8599             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8600             if ( s0.match( query_nodes ) ) {
8601                 return false;
8602             }
8603             //
8604             query_nodes = new HashSet<PhylogenyNode>();
8605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8606             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8607             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8608             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8609             if ( s0.match( query_nodes ) ) {
8610                 return false;
8611             }
8612             /////////
8613             //            query_nodes = new HashSet<PhylogenyNode>();
8614             //            query_nodes.add( new PhylogenyNode( "X" ) );
8615             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8616             //            query_nodes.add( new PhylogenyNode( "A" ) );
8617             //            query_nodes.add( new PhylogenyNode( "B" ) );
8618             //            query_nodes.add( new PhylogenyNode( "C" ) );
8619             //            query_nodes.add( new PhylogenyNode( "D" ) );
8620             //            query_nodes.add( new PhylogenyNode( "E" ) );
8621             //            query_nodes.add( new PhylogenyNode( "F" ) );
8622             //            query_nodes.add( new PhylogenyNode( "G" ) );
8623             //            if ( !s0.match( query_nodes ) ) {
8624             //                return false;
8625             //            }
8626             //            query_nodes = new HashSet<PhylogenyNode>();
8627             //            query_nodes.add( new PhylogenyNode( "X" ) );
8628             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8629             //            query_nodes.add( new PhylogenyNode( "A" ) );
8630             //            query_nodes.add( new PhylogenyNode( "B" ) );
8631             //            query_nodes.add( new PhylogenyNode( "C" ) );
8632             //            if ( !s0.match( query_nodes ) ) {
8633             //                return false;
8634             //            }
8635             //            //
8636             //            query_nodes = new HashSet<PhylogenyNode>();
8637             //            query_nodes.add( new PhylogenyNode( "X" ) );
8638             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8639             //            query_nodes.add( new PhylogenyNode( "D" ) );
8640             //            query_nodes.add( new PhylogenyNode( "E" ) );
8641             //            query_nodes.add( new PhylogenyNode( "F" ) );
8642             //            query_nodes.add( new PhylogenyNode( "G" ) );
8643             //            if ( !s0.match( query_nodes ) ) {
8644             //                return false;
8645             //            }
8646             //            //
8647             //            query_nodes = new HashSet<PhylogenyNode>();
8648             //            query_nodes.add( new PhylogenyNode( "X" ) );
8649             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8650             //            query_nodes.add( new PhylogenyNode( "A" ) );
8651             //            query_nodes.add( new PhylogenyNode( "B" ) );
8652             //            query_nodes.add( new PhylogenyNode( "C" ) );
8653             //            query_nodes.add( new PhylogenyNode( "D" ) );
8654             //            if ( !s0.match( query_nodes ) ) {
8655             //                return false;
8656             //            }
8657             //            //
8658             //            query_nodes = new HashSet<PhylogenyNode>();
8659             //            query_nodes.add( new PhylogenyNode( "X" ) );
8660             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8661             //            query_nodes.add( new PhylogenyNode( "E" ) );
8662             //            query_nodes.add( new PhylogenyNode( "F" ) );
8663             //            query_nodes.add( new PhylogenyNode( "G" ) );
8664             //            if ( !s0.match( query_nodes ) ) {
8665             //                return false;
8666             //            }
8667             //            //
8668             //            query_nodes = new HashSet<PhylogenyNode>();
8669             //            query_nodes.add( new PhylogenyNode( "X" ) );
8670             //            query_nodes.add( new PhylogenyNode( "Y" ) );
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             //
8677             query_nodes = new HashSet<PhylogenyNode>();
8678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8681             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8682             if ( s0.match( query_nodes ) ) {
8683                 return false;
8684             }
8685             //
8686             query_nodes = new HashSet<PhylogenyNode>();
8687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8689             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8691             if ( s0.match( query_nodes ) ) {
8692                 return false;
8693             }
8694             ///////////////////////////
8695             //
8696             query_nodes = new HashSet<PhylogenyNode>();
8697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8700             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8701             if ( s0.match( query_nodes ) ) {
8702                 return false;
8703             }
8704             //
8705             query_nodes = new HashSet<PhylogenyNode>();
8706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8707             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8708             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8710             if ( s0.match( query_nodes ) ) {
8711                 return false;
8712             }
8713             //
8714             query_nodes = new HashSet<PhylogenyNode>();
8715             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8716             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8718             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8719             if ( s0.match( query_nodes ) ) {
8720                 return false;
8721             }
8722             //
8723             query_nodes = new HashSet<PhylogenyNode>();
8724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8727             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8728             if ( s0.match( query_nodes ) ) {
8729                 return false;
8730             }
8731             //
8732             query_nodes = new HashSet<PhylogenyNode>();
8733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8735             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8737             if ( s0.match( query_nodes ) ) {
8738                 return false;
8739             }
8740             //
8741             query_nodes = new HashSet<PhylogenyNode>();
8742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8743             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8744             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8745             if ( s0.match( query_nodes ) ) {
8746                 return false;
8747             }
8748             //
8749             query_nodes = new HashSet<PhylogenyNode>();
8750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8753             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8754             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8755             if ( s0.match( query_nodes ) ) {
8756                 return false;
8757             }
8758             //
8759             query_nodes = new HashSet<PhylogenyNode>();
8760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8761             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8762             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8763             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8764             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8765             if ( s0.match( query_nodes ) ) {
8766                 return false;
8767             }
8768             //
8769             query_nodes = new HashSet<PhylogenyNode>();
8770             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8771             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8775             if ( s0.match( query_nodes ) ) {
8776                 return false;
8777             }
8778             //
8779             query_nodes = new HashSet<PhylogenyNode>();
8780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8781             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8782             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8783             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8785             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8786             if ( s0.match( query_nodes ) ) {
8787                 return false;
8788             }
8789         }
8790         catch ( final Exception e ) {
8791             e.printStackTrace();
8792             return false;
8793         }
8794         return true;
8795     }
8796
8797     private static boolean testSplitStrict() {
8798         try {
8799             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8800             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8801             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8802             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8803             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8804             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8805             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8806             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8807             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8808             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8809             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
8810             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8811             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8813             if ( s0.match( query_nodes ) ) {
8814                 return false;
8815             }
8816             query_nodes = new HashSet<PhylogenyNode>();
8817             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8818             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8819             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8824             if ( !s0.match( query_nodes ) ) {
8825                 return false;
8826             }
8827             //
8828             query_nodes = new HashSet<PhylogenyNode>();
8829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8832             if ( !s0.match( query_nodes ) ) {
8833                 return false;
8834             }
8835             //
8836             query_nodes = new HashSet<PhylogenyNode>();
8837             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8838             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8841             if ( !s0.match( query_nodes ) ) {
8842                 return false;
8843             }
8844             //
8845             query_nodes = new HashSet<PhylogenyNode>();
8846             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8847             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8850             if ( !s0.match( query_nodes ) ) {
8851                 return false;
8852             }
8853             //
8854             query_nodes = new HashSet<PhylogenyNode>();
8855             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8858             if ( !s0.match( query_nodes ) ) {
8859                 return false;
8860             }
8861             //
8862             query_nodes = new HashSet<PhylogenyNode>();
8863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8865             if ( !s0.match( query_nodes ) ) {
8866                 return false;
8867             }
8868             //
8869             query_nodes = new HashSet<PhylogenyNode>();
8870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8874             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8875             if ( !s0.match( query_nodes ) ) {
8876                 return false;
8877             }
8878             //
8879             query_nodes = new HashSet<PhylogenyNode>();
8880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8882             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8883             if ( !s0.match( query_nodes ) ) {
8884                 return false;
8885             }
8886             //
8887             query_nodes = new HashSet<PhylogenyNode>();
8888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8892             if ( !s0.match( query_nodes ) ) {
8893                 return false;
8894             }
8895             //
8896             query_nodes = new HashSet<PhylogenyNode>();
8897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8899             if ( s0.match( query_nodes ) ) {
8900                 return false;
8901             }
8902             //
8903             query_nodes = new HashSet<PhylogenyNode>();
8904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
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             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8918             if ( s0.match( query_nodes ) ) {
8919                 return false;
8920             }
8921             //
8922             query_nodes = new HashSet<PhylogenyNode>();
8923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8926             if ( s0.match( query_nodes ) ) {
8927                 return false;
8928             }
8929             //
8930             query_nodes = new HashSet<PhylogenyNode>();
8931             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8932             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8933             if ( s0.match( query_nodes ) ) {
8934                 return false;
8935             }
8936             //
8937             query_nodes = new HashSet<PhylogenyNode>();
8938             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8940             if ( s0.match( query_nodes ) ) {
8941                 return false;
8942             }
8943             //
8944             query_nodes = new HashSet<PhylogenyNode>();
8945             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8947             if ( s0.match( query_nodes ) ) {
8948                 return false;
8949             }
8950             //
8951             query_nodes = new HashSet<PhylogenyNode>();
8952             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8953             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8954             if ( s0.match( query_nodes ) ) {
8955                 return false;
8956             }
8957             //
8958             query_nodes = new HashSet<PhylogenyNode>();
8959             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8960             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8961             if ( s0.match( query_nodes ) ) {
8962                 return false;
8963             }
8964             //
8965             query_nodes = new HashSet<PhylogenyNode>();
8966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "F" ) );
8975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "B" ) );
8983             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8984             if ( s0.match( query_nodes ) ) {
8985                 return false;
8986             }
8987             //
8988             query_nodes = new HashSet<PhylogenyNode>();
8989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8992             if ( s0.match( query_nodes ) ) {
8993                 return false;
8994             }
8995             //
8996             query_nodes = new HashSet<PhylogenyNode>();
8997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8998             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8999             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9001             if ( s0.match( query_nodes ) ) {
9002                 return false;
9003             }
9004         }
9005         catch ( final Exception e ) {
9006             e.printStackTrace();
9007             return false;
9008         }
9009         return true;
9010     }
9011
9012     private static boolean testSubtreeDeletion() {
9013         try {
9014             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9015             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9016             t1.deleteSubtree( t1.getNode( "A" ), false );
9017             if ( t1.getNumberOfExternalNodes() != 5 ) {
9018                 return false;
9019             }
9020             t1.toNewHampshireX();
9021             t1.deleteSubtree( t1.getNode( "E" ), false );
9022             if ( t1.getNumberOfExternalNodes() != 4 ) {
9023                 return false;
9024             }
9025             t1.toNewHampshireX();
9026             t1.deleteSubtree( t1.getNode( "F" ), false );
9027             if ( t1.getNumberOfExternalNodes() != 3 ) {
9028                 return false;
9029             }
9030             t1.toNewHampshireX();
9031             t1.deleteSubtree( t1.getNode( "D" ), false );
9032             t1.toNewHampshireX();
9033             if ( t1.getNumberOfExternalNodes() != 3 ) {
9034                 return false;
9035             }
9036             t1.deleteSubtree( t1.getNode( "def" ), false );
9037             t1.toNewHampshireX();
9038             if ( t1.getNumberOfExternalNodes() != 2 ) {
9039                 return false;
9040             }
9041             t1.deleteSubtree( t1.getNode( "B" ), false );
9042             t1.toNewHampshireX();
9043             if ( t1.getNumberOfExternalNodes() != 1 ) {
9044                 return false;
9045             }
9046             t1.deleteSubtree( t1.getNode( "C" ), false );
9047             t1.toNewHampshireX();
9048             if ( t1.getNumberOfExternalNodes() != 1 ) {
9049                 return false;
9050             }
9051             t1.deleteSubtree( t1.getNode( "abc" ), false );
9052             t1.toNewHampshireX();
9053             if ( t1.getNumberOfExternalNodes() != 1 ) {
9054                 return false;
9055             }
9056             t1.deleteSubtree( t1.getNode( "r" ), false );
9057             if ( t1.getNumberOfExternalNodes() != 0 ) {
9058                 return false;
9059             }
9060             if ( !t1.isEmpty() ) {
9061                 return false;
9062             }
9063             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9064             t2.deleteSubtree( t2.getNode( "A" ), false );
9065             t2.toNewHampshireX();
9066             if ( t2.getNumberOfExternalNodes() != 5 ) {
9067                 return false;
9068             }
9069             t2.deleteSubtree( t2.getNode( "abc" ), false );
9070             t2.toNewHampshireX();
9071             if ( t2.getNumberOfExternalNodes() != 3 ) {
9072                 return false;
9073             }
9074             t2.deleteSubtree( t2.getNode( "def" ), false );
9075             t2.toNewHampshireX();
9076             if ( t2.getNumberOfExternalNodes() != 1 ) {
9077                 return false;
9078             }
9079         }
9080         catch ( final Exception e ) {
9081             e.printStackTrace( System.out );
9082             return false;
9083         }
9084         return true;
9085     }
9086
9087     private static boolean testSupportCount() {
9088         try {
9089             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9090             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
9091             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
9092                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
9093                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
9094                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
9095                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
9096                                                               new NHXParser() );
9097             SupportCount.count( t0_1, phylogenies_1, true, false );
9098             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
9099             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
9100                                                                       + "(((((A,B),C),D),E),((F,G),X))"
9101                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
9102                                                                       + "(((((A,B),C),D),E),(F,G))"
9103                                                                       + "(((((A,B),C),D),E),(F,G))"
9104                                                                       + "(((((A,B),C),D),E),(F,G))"
9105                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
9106                                                                       + "(((((A,B),C),D),E),(F,G))"
9107                                                                       + "((((((A,B),C),D),E),F),G)"
9108                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
9109                                                               new NHXParser() );
9110             SupportCount.count( t0_2, phylogenies_2, true, false );
9111             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
9112             while ( it.hasNext() ) {
9113                 final PhylogenyNode n = it.next();
9114                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
9115                     return false;
9116                 }
9117             }
9118             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
9119             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
9120                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
9121             SupportCount.count( t0_3, phylogenies_3, true, false );
9122             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
9123             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
9124                 return false;
9125             }
9126             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
9127                 return false;
9128             }
9129             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
9130                 return false;
9131             }
9132             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
9133                 return false;
9134             }
9135             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
9136                 return false;
9137             }
9138             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
9139                 return false;
9140             }
9141             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
9142                 return false;
9143             }
9144             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
9145                 return false;
9146             }
9147             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
9148                 return false;
9149             }
9150             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
9151                 return false;
9152             }
9153             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9154             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
9155                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
9156             SupportCount.count( t0_4, phylogenies_4, true, false );
9157             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
9158             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
9159                 return false;
9160             }
9161             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
9162                 return false;
9163             }
9164             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
9165                 return false;
9166             }
9167             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
9168                 return false;
9169             }
9170             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
9171                 return false;
9172             }
9173             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
9174                 return false;
9175             }
9176             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
9177                 return false;
9178             }
9179             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
9180                 return false;
9181             }
9182             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
9183                 return false;
9184             }
9185             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
9186                 return false;
9187             }
9188             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9189             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9190             double d = SupportCount.compare( b1, a, true, true, true );
9191             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
9192                 return false;
9193             }
9194             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9195             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9196             d = SupportCount.compare( b2, a, true, true, true );
9197             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
9198                 return false;
9199             }
9200             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9201             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
9202             d = SupportCount.compare( b3, a, true, true, true );
9203             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
9204                 return false;
9205             }
9206             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
9207             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
9208             d = SupportCount.compare( b4, a, true, true, false );
9209             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
9210                 return false;
9211             }
9212         }
9213         catch ( final Exception e ) {
9214             e.printStackTrace( System.out );
9215             return false;
9216         }
9217         return true;
9218     }
9219
9220     private static boolean testSupportTransfer() {
9221         try {
9222             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9223             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)",
9224                                                  new NHXParser() )[ 0 ];
9225             final Phylogeny p2 = factory
9226                     .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 ];
9227             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
9228                 return false;
9229             }
9230             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
9231                 return false;
9232             }
9233             support_transfer.moveBranchLengthsToBootstrap( p1 );
9234             support_transfer.transferSupportValues( p1, p2 );
9235             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
9236                 return false;
9237             }
9238             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
9239                 return false;
9240             }
9241             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
9242                 return false;
9243             }
9244             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
9245                 return false;
9246             }
9247             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
9248                 return false;
9249             }
9250             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
9251                 return false;
9252             }
9253             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
9254                 return false;
9255             }
9256             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
9257                 return false;
9258             }
9259         }
9260         catch ( final Exception e ) {
9261             e.printStackTrace( System.out );
9262             return false;
9263         }
9264         return true;
9265     }
9266
9267     private static boolean testUniprotTaxonomySearch() {
9268         try {
9269             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
9270                                                                                                  10 );
9271             if ( results.size() != 1 ) {
9272                 return false;
9273             }
9274             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9275                 return false;
9276             }
9277             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9278                 return false;
9279             }
9280             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9281                 return false;
9282             }
9283             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9284                 return false;
9285             }
9286             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9287                 return false;
9288             }
9289             results = null;
9290             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
9291             if ( results.size() != 1 ) {
9292                 return false;
9293             }
9294             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9295                 return false;
9296             }
9297             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9298                 return false;
9299             }
9300             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9301                 return false;
9302             }
9303             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9304                 return false;
9305             }
9306             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9307                 return false;
9308             }
9309             results = null;
9310             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
9311             if ( results.size() != 1 ) {
9312                 return false;
9313             }
9314             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9315                 return false;
9316             }
9317             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9318                 return false;
9319             }
9320             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9321                 return false;
9322             }
9323             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9324                 return false;
9325             }
9326             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9327                 return false;
9328             }
9329             results = null;
9330             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
9331             if ( results.size() != 1 ) {
9332                 return false;
9333             }
9334             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9335                 return false;
9336             }
9337             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9338                 return false;
9339             }
9340             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9341                 return false;
9342             }
9343             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9344                 return false;
9345             }
9346             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9347                 return false;
9348             }
9349             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
9350                 return false;
9351             }
9352             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
9353                 return false;
9354             }
9355             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
9356                     .equals( "Nematostella vectensis" ) ) {
9357                 System.out.println( results.get( 0 ).getLineage() );
9358                 return false;
9359             }
9360         }
9361         catch ( final IOException e ) {
9362             System.out.println();
9363             System.out.println( "the following might be due to absence internet connection:" );
9364             e.printStackTrace( System.out );
9365             return true;
9366         }
9367         catch ( final Exception e ) {
9368             return false;
9369         }
9370         return true;
9371     }
9372
9373     private static boolean testEmblEntryRetrieval() {
9374         //The format for GenBank Accession numbers are:
9375         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
9376         //Protein:    3 letters + 5 numerals
9377         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
9378         if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
9379             return false;
9380         }
9381         if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) {
9382             return false;
9383         }
9384         if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
9385             return false;
9386         }
9387         if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
9388             return false;
9389         }
9390         if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
9391             return false;
9392         }
9393         if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
9394             return false;
9395         }
9396         if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
9397             return false;
9398         }
9399         if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
9400             return false;
9401         }
9402         if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
9403             return false;
9404         }
9405         if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
9406             return false;
9407         }
9408         if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
9409             return false;
9410         }
9411         if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
9412             return false;
9413         }
9414         if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
9415             return false;
9416         }
9417         return true;
9418     }
9419
9420     private static boolean testUniprotEntryRetrieval() {
9421         if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) {
9422             return false;
9423         }
9424         if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) {
9425             return false;
9426         }
9427         if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) {
9428             return false;
9429         }
9430         if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) {
9431             return false;
9432         }
9433         if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) {
9434             return false;
9435         }
9436         if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) {
9437             return false;
9438         }
9439         if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) {
9440             return false;
9441         }
9442         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) {
9443             return false;
9444         }
9445         if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) {
9446             return false;
9447         }
9448         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) {
9449             return false;
9450         }
9451         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) {
9452             return false;
9453         }
9454         if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) {
9455             return false;
9456         }
9457         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) {
9458             return false;
9459         }
9460         try {
9461             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
9462             if ( !entry.getAccession().equals( "P12345" ) ) {
9463                 return false;
9464             }
9465             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
9466                 return false;
9467             }
9468             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
9469                 return false;
9470             }
9471             if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) {
9472                 return false;
9473             }
9474             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
9475                 return false;
9476             }
9477         }
9478         catch ( final IOException e ) {
9479             System.out.println();
9480             System.out.println( "the following might be due to absence internet connection:" );
9481             e.printStackTrace( System.out );
9482             return true;
9483         }
9484         catch ( final Exception e ) {
9485             return false;
9486         }
9487         return true;
9488     }
9489
9490     private static boolean testWabiTxSearch() {
9491         try {
9492             String result = "";
9493             result = TxSearch.searchSimple( "nematostella" );
9494             result = TxSearch.getTxId( "nematostella" );
9495             if ( !result.equals( "45350" ) ) {
9496                 return false;
9497             }
9498             result = TxSearch.getTxName( "45350" );
9499             if ( !result.equals( "Nematostella" ) ) {
9500                 return false;
9501             }
9502             result = TxSearch.getTxId( "nematostella vectensis" );
9503             if ( !result.equals( "45351" ) ) {
9504                 return false;
9505             }
9506             result = TxSearch.getTxName( "45351" );
9507             if ( !result.equals( "Nematostella vectensis" ) ) {
9508                 return false;
9509             }
9510             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
9511             if ( !result.equals( "536089" ) ) {
9512                 return false;
9513             }
9514             result = TxSearch.getTxName( "536089" );
9515             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
9516                 return false;
9517             }
9518             final List<String> queries = new ArrayList<String>();
9519             queries.add( "Campylobacter coli" );
9520             queries.add( "Escherichia coli" );
9521             queries.add( "Arabidopsis" );
9522             queries.add( "Trichoplax" );
9523             queries.add( "Samanea saman" );
9524             queries.add( "Kluyveromyces marxianus" );
9525             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
9526             queries.add( "Bornavirus parrot/PDD/2008" );
9527             final List<RANKS> ranks = new ArrayList<RANKS>();
9528             ranks.add( RANKS.SUPERKINGDOM );
9529             ranks.add( RANKS.KINGDOM );
9530             ranks.add( RANKS.FAMILY );
9531             ranks.add( RANKS.GENUS );
9532             ranks.add( RANKS.TRIBE );
9533             result = TxSearch.searchLineage( queries, ranks );
9534             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
9535             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
9536         }
9537         catch ( final Exception e ) {
9538             System.out.println();
9539             System.out.println( "the following might be due to absence internet connection:" );
9540             e.printStackTrace( System.out );
9541             return false;
9542         }
9543         return true;
9544     }
9545
9546     private static boolean testAminoAcidSequence() {
9547         try {
9548             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
9549             if ( aa1.getLength() != 13 ) {
9550                 return false;
9551             }
9552             if ( aa1.getResidueAt( 0 ) != 'A' ) {
9553                 return false;
9554             }
9555             if ( aa1.getResidueAt( 2 ) != 'K' ) {
9556                 return false;
9557             }
9558             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
9559                 return false;
9560             }
9561             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
9562             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
9563                 return false;
9564             }
9565             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
9566             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
9567                 return false;
9568             }
9569             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
9570             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
9571                 return false;
9572             }
9573         }
9574         catch ( final Exception e ) {
9575             e.printStackTrace();
9576             return false;
9577         }
9578         return true;
9579     }
9580
9581     private static boolean testCreateBalancedPhylogeny() {
9582         try {
9583             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
9584             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
9585                 return false;
9586             }
9587             if ( p0.getNumberOfExternalNodes() != 15625 ) {
9588                 return false;
9589             }
9590             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
9591             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
9592                 return false;
9593             }
9594             if ( p1.getNumberOfExternalNodes() != 100 ) {
9595                 return false;
9596             }
9597         }
9598         catch ( final Exception e ) {
9599             e.printStackTrace();
9600             return false;
9601         }
9602         return true;
9603     }
9604
9605     private static boolean testFastaParser() {
9606         try {
9607             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
9608                 return false;
9609             }
9610             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
9611                 return false;
9612             }
9613             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
9614             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
9615                 return false;
9616             }
9617             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
9618                 return false;
9619             }
9620             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
9621                 return false;
9622             }
9623             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
9624                 return false;
9625             }
9626             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
9627                 return false;
9628             }
9629             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
9630                 return false;
9631             }
9632         }
9633         catch ( final Exception e ) {
9634             e.printStackTrace();
9635             return false;
9636         }
9637         return true;
9638     }
9639
9640     private static boolean testGeneralMsaParser() {
9641         try {
9642             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
9643             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
9644             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
9645             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
9646             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
9647             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
9648             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
9649             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
9650             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9651                 return false;
9652             }
9653             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9654                 return false;
9655             }
9656             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9657                 return false;
9658             }
9659             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9660                 return false;
9661             }
9662             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9663                 return false;
9664             }
9665             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9666                 return false;
9667             }
9668             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9669                 return false;
9670             }
9671             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9672                 return false;
9673             }
9674             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9675                 return false;
9676             }
9677             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9678                 return false;
9679             }
9680             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9681                 return false;
9682             }
9683             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9684                 return false;
9685             }
9686             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
9687             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9688                 return false;
9689             }
9690             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9691                 return false;
9692             }
9693             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9694                 return false;
9695             }
9696             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
9697             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
9698                 return false;
9699             }
9700             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
9701                 return false;
9702             }
9703             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
9704                 return false;
9705             }
9706             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
9707             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9708                 return false;
9709             }
9710             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9711                 return false;
9712             }
9713             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9714                 return false;
9715             }
9716         }
9717         catch ( final Exception e ) {
9718             e.printStackTrace();
9719             return false;
9720         }
9721         return true;
9722     }
9723
9724     private static boolean testMafft( final String path ) {
9725         try {
9726             final List<String> opts = new ArrayList<String>();
9727             opts.add( "--maxiterate" );
9728             opts.add( "1000" );
9729             opts.add( "--localpair" );
9730             opts.add( "--quiet" );
9731             Msa msa = null;
9732             final MsaInferrer mafft = Mafft.createInstance( path );
9733             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
9734             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
9735                 return false;
9736             }
9737             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
9738                 return false;
9739             }
9740         }
9741         catch ( final Exception e ) {
9742             e.printStackTrace( System.out );
9743             return false;
9744         }
9745         return true;
9746     }
9747
9748     private static boolean testNextNodeWithCollapsing() {
9749         try {
9750             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9751             PhylogenyNode n;
9752             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
9753             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9754             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
9755             t0.getNode( "cd" ).setCollapse( true );
9756             t0.getNode( "cde" ).setCollapse( true );
9757             n = t0.getFirstExternalNode();
9758             while ( n != null ) {
9759                 ext.add( n );
9760                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9761             }
9762             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9763                 return false;
9764             }
9765             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9766                 return false;
9767             }
9768             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
9769                 return false;
9770             }
9771             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
9772                 return false;
9773             }
9774             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
9775                 return false;
9776             }
9777             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
9778                 return false;
9779             }
9780             ext.clear();
9781             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9782             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
9783             t1.getNode( "ab" ).setCollapse( true );
9784             t1.getNode( "cd" ).setCollapse( true );
9785             t1.getNode( "cde" ).setCollapse( true );
9786             n = t1.getNode( "ab" );
9787             ext = new ArrayList<PhylogenyNode>();
9788             while ( n != null ) {
9789                 ext.add( n );
9790                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9791             }
9792             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9793                 return false;
9794             }
9795             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9796                 return false;
9797             }
9798             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9799                 return false;
9800             }
9801             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
9802                 return false;
9803             }
9804             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
9805                 return false;
9806             }
9807             //
9808             //
9809             ext.clear();
9810             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9811             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
9812             t2.getNode( "ab" ).setCollapse( true );
9813             t2.getNode( "cd" ).setCollapse( true );
9814             t2.getNode( "cde" ).setCollapse( true );
9815             t2.getNode( "c" ).setCollapse( true );
9816             t2.getNode( "d" ).setCollapse( true );
9817             t2.getNode( "e" ).setCollapse( true );
9818             t2.getNode( "gh" ).setCollapse( true );
9819             n = t2.getNode( "ab" );
9820             ext = new ArrayList<PhylogenyNode>();
9821             while ( n != null ) {
9822                 ext.add( n );
9823                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9824             }
9825             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9826                 return false;
9827             }
9828             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9829                 return false;
9830             }
9831             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9832                 return false;
9833             }
9834             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
9835                 return false;
9836             }
9837             //
9838             //
9839             ext.clear();
9840             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9841             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
9842             t3.getNode( "ab" ).setCollapse( true );
9843             t3.getNode( "cd" ).setCollapse( true );
9844             t3.getNode( "cde" ).setCollapse( true );
9845             t3.getNode( "c" ).setCollapse( true );
9846             t3.getNode( "d" ).setCollapse( true );
9847             t3.getNode( "e" ).setCollapse( true );
9848             t3.getNode( "gh" ).setCollapse( true );
9849             t3.getNode( "fgh" ).setCollapse( true );
9850             n = t3.getNode( "ab" );
9851             ext = new ArrayList<PhylogenyNode>();
9852             while ( n != null ) {
9853                 ext.add( n );
9854                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9855             }
9856             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9857                 return false;
9858             }
9859             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9860                 return false;
9861             }
9862             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
9863                 return false;
9864             }
9865             //
9866             //
9867             ext.clear();
9868             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9869             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
9870             t4.getNode( "ab" ).setCollapse( true );
9871             t4.getNode( "cd" ).setCollapse( true );
9872             t4.getNode( "cde" ).setCollapse( true );
9873             t4.getNode( "c" ).setCollapse( true );
9874             t4.getNode( "d" ).setCollapse( true );
9875             t4.getNode( "e" ).setCollapse( true );
9876             t4.getNode( "gh" ).setCollapse( true );
9877             t4.getNode( "fgh" ).setCollapse( true );
9878             t4.getNode( "abcdefgh" ).setCollapse( true );
9879             n = t4.getNode( "abcdefgh" );
9880             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
9881                 return false;
9882             }
9883             //
9884             //
9885             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9886             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
9887             ext.clear();
9888             n = t5.getFirstExternalNode();
9889             while ( n != null ) {
9890                 ext.add( n );
9891                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9892             }
9893             if ( ext.size() != 8 ) {
9894                 return false;
9895             }
9896             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9897                 return false;
9898             }
9899             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9900                 return false;
9901             }
9902             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
9903                 return false;
9904             }
9905             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
9906                 return false;
9907             }
9908             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
9909                 return false;
9910             }
9911             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
9912                 return false;
9913             }
9914             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
9915                 return false;
9916             }
9917             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
9918                 return false;
9919             }
9920             //
9921             //
9922             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9923             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
9924             ext.clear();
9925             t6.getNode( "ab" ).setCollapse( true );
9926             n = t6.getNode( "ab" );
9927             while ( n != null ) {
9928                 ext.add( n );
9929                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9930             }
9931             if ( ext.size() != 7 ) {
9932                 return false;
9933             }
9934             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9935                 return false;
9936             }
9937             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
9938                 return false;
9939             }
9940             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
9941                 return false;
9942             }
9943             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9944                 return false;
9945             }
9946             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9947                 return false;
9948             }
9949             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9950                 return false;
9951             }
9952             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9953                 return false;
9954             }
9955             //
9956             //
9957             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9958             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
9959             ext.clear();
9960             t7.getNode( "cd" ).setCollapse( true );
9961             n = t7.getNode( "a" );
9962             while ( n != null ) {
9963                 ext.add( n );
9964                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9965             }
9966             if ( ext.size() != 7 ) {
9967                 return false;
9968             }
9969             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9970                 return false;
9971             }
9972             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9973                 return false;
9974             }
9975             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
9976                 return false;
9977             }
9978             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9979                 return false;
9980             }
9981             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9982                 return false;
9983             }
9984             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9985                 return false;
9986             }
9987             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9988                 return false;
9989             }
9990             //
9991             //
9992             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9993             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
9994             ext.clear();
9995             t8.getNode( "cd" ).setCollapse( true );
9996             t8.getNode( "c" ).setCollapse( true );
9997             t8.getNode( "d" ).setCollapse( true );
9998             n = t8.getNode( "a" );
9999             while ( n != null ) {
10000                 ext.add( n );
10001                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10002             }
10003             if ( ext.size() != 7 ) {
10004                 return false;
10005             }
10006             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10007                 return false;
10008             }
10009             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10010                 return false;
10011             }
10012             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10013                 System.out.println( "2 fail" );
10014                 return false;
10015             }
10016             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10017                 return false;
10018             }
10019             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10020                 return false;
10021             }
10022             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10023                 return false;
10024             }
10025             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10026                 return false;
10027             }
10028             //
10029             //
10030             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10031             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
10032             ext.clear();
10033             t9.getNode( "gh" ).setCollapse( true );
10034             n = t9.getNode( "a" );
10035             while ( n != null ) {
10036                 ext.add( n );
10037                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10038             }
10039             if ( ext.size() != 7 ) {
10040                 return false;
10041             }
10042             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10043                 return false;
10044             }
10045             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10046                 return false;
10047             }
10048             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10049                 return false;
10050             }
10051             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10052                 return false;
10053             }
10054             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10055                 return false;
10056             }
10057             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10058                 return false;
10059             }
10060             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10061                 return false;
10062             }
10063             //
10064             //
10065             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10066             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
10067             ext.clear();
10068             t10.getNode( "gh" ).setCollapse( true );
10069             t10.getNode( "g" ).setCollapse( true );
10070             t10.getNode( "h" ).setCollapse( true );
10071             n = t10.getNode( "a" );
10072             while ( n != null ) {
10073                 ext.add( n );
10074                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10075             }
10076             if ( ext.size() != 7 ) {
10077                 return false;
10078             }
10079             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10080                 return false;
10081             }
10082             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10083                 return false;
10084             }
10085             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10086                 return false;
10087             }
10088             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10089                 return false;
10090             }
10091             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10092                 return false;
10093             }
10094             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10095                 return false;
10096             }
10097             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10098                 return false;
10099             }
10100             //
10101             //
10102             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10103             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
10104             ext.clear();
10105             t11.getNode( "gh" ).setCollapse( true );
10106             t11.getNode( "fgh" ).setCollapse( true );
10107             n = t11.getNode( "a" );
10108             while ( n != null ) {
10109                 ext.add( n );
10110                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10111             }
10112             if ( ext.size() != 6 ) {
10113                 return false;
10114             }
10115             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10116                 return false;
10117             }
10118             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10119                 return false;
10120             }
10121             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10122                 return false;
10123             }
10124             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10125                 return false;
10126             }
10127             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10128                 return false;
10129             }
10130             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10131                 return false;
10132             }
10133             //
10134             //
10135             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10136             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
10137             ext.clear();
10138             t12.getNode( "gh" ).setCollapse( true );
10139             t12.getNode( "fgh" ).setCollapse( true );
10140             t12.getNode( "g" ).setCollapse( true );
10141             t12.getNode( "h" ).setCollapse( true );
10142             t12.getNode( "f" ).setCollapse( true );
10143             n = t12.getNode( "a" );
10144             while ( n != null ) {
10145                 ext.add( n );
10146                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10147             }
10148             if ( ext.size() != 6 ) {
10149                 return false;
10150             }
10151             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10152                 return false;
10153             }
10154             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10155                 return false;
10156             }
10157             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10158                 return false;
10159             }
10160             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10161                 return false;
10162             }
10163             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10164                 return false;
10165             }
10166             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10167                 return false;
10168             }
10169             //
10170             //
10171             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10172             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
10173             ext.clear();
10174             t13.getNode( "ab" ).setCollapse( true );
10175             t13.getNode( "b" ).setCollapse( true );
10176             t13.getNode( "fgh" ).setCollapse( true );
10177             t13.getNode( "gh" ).setCollapse( true );
10178             n = t13.getNode( "ab" );
10179             while ( n != null ) {
10180                 ext.add( n );
10181                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10182             }
10183             if ( ext.size() != 5 ) {
10184                 return false;
10185             }
10186             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10187                 return false;
10188             }
10189             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10190                 return false;
10191             }
10192             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10193                 return false;
10194             }
10195             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10196                 return false;
10197             }
10198             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10199                 return false;
10200             }
10201             //
10202             //
10203             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
10204             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
10205             ext.clear();
10206             t14.getNode( "ab" ).setCollapse( true );
10207             t14.getNode( "a" ).setCollapse( true );
10208             t14.getNode( "fgh" ).setCollapse( true );
10209             t14.getNode( "gh" ).setCollapse( true );
10210             n = t14.getNode( "ab" );
10211             while ( n != null ) {
10212                 ext.add( n );
10213                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10214             }
10215             if ( ext.size() != 5 ) {
10216                 return false;
10217             }
10218             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10219                 return false;
10220             }
10221             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10222                 return false;
10223             }
10224             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10225                 return false;
10226             }
10227             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10228                 return false;
10229             }
10230             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10231                 return false;
10232             }
10233             //
10234             //
10235             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" );
10236             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
10237             ext.clear();
10238             t15.getNode( "ab" ).setCollapse( true );
10239             t15.getNode( "a" ).setCollapse( true );
10240             t15.getNode( "fgh" ).setCollapse( true );
10241             t15.getNode( "gh" ).setCollapse( true );
10242             n = t15.getNode( "ab" );
10243             while ( n != null ) {
10244                 ext.add( n );
10245                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10246             }
10247             if ( ext.size() != 6 ) {
10248                 return false;
10249             }
10250             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10251                 return false;
10252             }
10253             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10254                 return false;
10255             }
10256             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10257                 return false;
10258             }
10259             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10260                 return false;
10261             }
10262             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
10263                 return false;
10264             }
10265             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10266                 return false;
10267             }
10268             //
10269             //
10270             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" );
10271             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
10272             ext.clear();
10273             t16.getNode( "ab" ).setCollapse( true );
10274             t16.getNode( "a" ).setCollapse( true );
10275             t16.getNode( "fgh" ).setCollapse( true );
10276             t16.getNode( "gh" ).setCollapse( true );
10277             t16.getNode( "cd" ).setCollapse( true );
10278             t16.getNode( "cde" ).setCollapse( true );
10279             t16.getNode( "d" ).setCollapse( true );
10280             t16.getNode( "x" ).setCollapse( true );
10281             n = t16.getNode( "ab" );
10282             while ( n != null ) {
10283                 ext.add( n );
10284                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10285             }
10286             if ( ext.size() != 4 ) {
10287                 return false;
10288             }
10289             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10290                 return false;
10291             }
10292             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
10293                 return false;
10294             }
10295             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
10296                 return false;
10297             }
10298             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
10299                 return false;
10300             }
10301         }
10302         catch ( final Exception e ) {
10303             e.printStackTrace( System.out );
10304             return false;
10305         }
10306         return true;
10307     }
10308
10309     private static boolean testMsaQualityMethod() {
10310         try {
10311             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
10312             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
10313             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
10314             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
10315             final List<Sequence> l = new ArrayList<Sequence>();
10316             l.add( s0 );
10317             l.add( s1 );
10318             l.add( s2 );
10319             l.add( s3 );
10320             final Msa msa = BasicMsa.createInstance( l );
10321             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
10322                 return false;
10323             }
10324             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
10325                 return false;
10326             }
10327             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
10328                 return false;
10329             }
10330             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
10331                 return false;
10332             }
10333         }
10334         catch ( final Exception e ) {
10335             e.printStackTrace( System.out );
10336             return false;
10337         }
10338         return true;
10339     }
10340
10341     private static boolean testSequenceIdParsing() {
10342         try {
10343             Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
10344             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10345                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10346                 if ( id != null ) {
10347                     System.out.println( "value   =" + id.getValue() );
10348                     System.out.println( "provider=" + id.getProvider() );
10349                 }
10350                 return false;
10351             }
10352             //
10353             id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
10354             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10355                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10356                 if ( id != null ) {
10357                     System.out.println( "value   =" + id.getValue() );
10358                     System.out.println( "provider=" + id.getProvider() );
10359                 }
10360                 return false;
10361             }
10362             //
10363             id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
10364             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10365                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10366                 if ( id != null ) {
10367                     System.out.println( "value   =" + id.getValue() );
10368                     System.out.println( "provider=" + id.getProvider() );
10369                 }
10370                 return false;
10371             }
10372             // 
10373             id = SequenceIdParser.parse( "gb_AAA96518_1" );
10374             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10375                     || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
10376                 if ( id != null ) {
10377                     System.out.println( "value   =" + id.getValue() );
10378                     System.out.println( "provider=" + id.getProvider() );
10379                 }
10380                 return false;
10381             }
10382             // 
10383             id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
10384             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10385                     || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
10386                 if ( id != null ) {
10387                     System.out.println( "value   =" + id.getValue() );
10388                     System.out.println( "provider=" + id.getProvider() );
10389                 }
10390                 return false;
10391             }
10392             // 
10393             id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
10394             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10395                     || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
10396                 if ( id != null ) {
10397                     System.out.println( "value   =" + id.getValue() );
10398                     System.out.println( "provider=" + id.getProvider() );
10399                 }
10400                 return false;
10401             }
10402             // 
10403             id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
10404             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10405                     || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
10406                 if ( id != null ) {
10407                     System.out.println( "value   =" + id.getValue() );
10408                     System.out.println( "provider=" + id.getProvider() );
10409                 }
10410                 return false;
10411             }
10412             // 
10413             id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
10414             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10415                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10416                 if ( id != null ) {
10417                     System.out.println( "value   =" + id.getValue() );
10418                     System.out.println( "provider=" + id.getProvider() );
10419                 }
10420                 return false;
10421             }
10422             // 
10423             id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
10424             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10425                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10426                 if ( id != null ) {
10427                     System.out.println( "value   =" + id.getValue() );
10428                     System.out.println( "provider=" + id.getProvider() );
10429                 }
10430                 return false;
10431             }
10432             // 
10433             id = SequenceIdParser.parse( "P4A123" );
10434             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10435                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10436                 if ( id != null ) {
10437                     System.out.println( "value   =" + id.getValue() );
10438                     System.out.println( "provider=" + id.getProvider() );
10439                 }
10440                 return false;
10441             }
10442             // 
10443             id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
10444             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10445                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10446                 if ( id != null ) {
10447                     System.out.println( "value   =" + id.getValue() );
10448                     System.out.println( "provider=" + id.getProvider() );
10449                 }
10450                 return false;
10451             }
10452             // 
10453             id = SequenceIdParser.parse( "XP_12345" );
10454             if ( id != null ) {
10455                 System.out.println( "value   =" + id.getValue() );
10456                 System.out.println( "provider=" + id.getProvider() );
10457                 return false;
10458             }
10459             // lcl_91970_unknown_
10460         }
10461         catch ( final Exception e ) {
10462             e.printStackTrace( System.out );
10463             return false;
10464         }
10465         return true;
10466     }
10467 }