inprogress
[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                 return false;
1027             }
1028             n.setName( "B0LM41_HUMAN" );
1029             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
1030                 return false;
1031             }
1032             n.setName( "NP_001025424" );
1033             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
1034                 return false;
1035             }
1036             n.setName( "_NM_001030253-" );
1037             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
1038                 return false;
1039             }
1040             n.setName( "XM_002122186" );
1041             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
1042                 return false;
1043             }
1044             n.setName( "AAA34956" );
1045             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
1046                 return false;
1047             }
1048             n.setName( "Q06891.1" );
1049             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891" ) ) {
1050                 return false;
1051             }
1052         }
1053         catch ( final Exception e ) {
1054             e.printStackTrace( System.out );
1055             return false;
1056         }
1057         return true;
1058     }
1059
1060     private static boolean testExtractTaxonomyCodeFromNodeName() {
1061         try {
1062             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1063                     .equals( "MOUSE" ) ) {
1064                 return false;
1065             }
1066             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1067                     .equals( "RAT" ) ) {
1068                 return false;
1069             }
1070             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1071                 return false;
1072             }
1073             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
1074                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1075                     .equals( "MOUSE" ) ) {
1076                 return false;
1077             }
1078             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE_function = 23445",
1079                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1080                     .equals( "MOUSE" ) ) {
1081                 return false;
1082             }
1083             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
1084                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1085                     .equals( "MOUSE" ) ) {
1086                 return false;
1087             }
1088             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
1089                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1090                 return false;
1091             }
1092             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
1093                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1094                 return false;
1095             }
1096             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1097                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1098                 return false;
1099             }
1100             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445",
1101                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1102                 return false;
1103             }
1104             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
1105                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1106                 return false;
1107             }
1108             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
1109                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1110                 return false;
1111             }
1112             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
1113                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1114                 return false;
1115             }
1116             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1117                     .equals( "RAT" ) ) {
1118                 return false;
1119             }
1120             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1121                     .equals( "PIG" ) ) {
1122                 return false;
1123             }
1124             if ( !ParserUtils
1125                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1126                     .equals( "MOUSE" ) ) {
1127                 return false;
1128             }
1129             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1130                     .equals( "MOUSE" ) ) {
1131                 return false;
1132             }
1133             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.AGRESSIVE )
1134                     .equals( "MOUSE" ) ) {
1135                 return false;
1136             }
1137             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1138                     .equals( "MOUSE" ) ) {
1139                 return false;
1140             }
1141             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ) != null ) {
1142                 return false;
1143             }
1144             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "x_MOUSE_x", TAXONOMY_EXTRACTION.AGRESSIVE )
1145                     .equals( "MOUSE" ) ) {
1146                 return false;
1147             }
1148         }
1149         catch ( final Exception e ) {
1150             e.printStackTrace( System.out );
1151             return false;
1152         }
1153         return true;
1154     }
1155
1156     private static boolean testBasicNodeMethods() {
1157         try {
1158             if ( PhylogenyNode.getNodeCount() != 0 ) {
1159                 return false;
1160             }
1161             final PhylogenyNode n1 = new PhylogenyNode();
1162             final PhylogenyNode n2 = PhylogenyNode
1163                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1164             final PhylogenyNode n3 = PhylogenyNode
1165                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1166             final PhylogenyNode n4 = PhylogenyNode
1167                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1168             if ( n1.isHasAssignedEvent() ) {
1169                 return false;
1170             }
1171             if ( PhylogenyNode.getNodeCount() != 4 ) {
1172                 return false;
1173             }
1174             if ( n3.getIndicator() != 0 ) {
1175                 return false;
1176             }
1177             if ( n3.getNumberOfExternalNodes() != 1 ) {
1178                 return false;
1179             }
1180             if ( !n3.isExternal() ) {
1181                 return false;
1182             }
1183             if ( !n3.isRoot() ) {
1184                 return false;
1185             }
1186             if ( !n4.getName().equals( "n4" ) ) {
1187                 return false;
1188             }
1189         }
1190         catch ( final Exception e ) {
1191             e.printStackTrace( System.out );
1192             return false;
1193         }
1194         return true;
1195     }
1196
1197     private static boolean testBasicPhyloXMLparsing() {
1198         try {
1199             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1200             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1201             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1202                                                               xml_parser );
1203             if ( xml_parser.getErrorCount() > 0 ) {
1204                 System.out.println( xml_parser.getErrorMessages().toString() );
1205                 return false;
1206             }
1207             if ( phylogenies_0.length != 4 ) {
1208                 return false;
1209             }
1210             final Phylogeny t1 = phylogenies_0[ 0 ];
1211             final Phylogeny t2 = phylogenies_0[ 1 ];
1212             final Phylogeny t3 = phylogenies_0[ 2 ];
1213             final Phylogeny t4 = phylogenies_0[ 3 ];
1214             if ( t1.getNumberOfExternalNodes() != 1 ) {
1215                 return false;
1216             }
1217             if ( !t1.isRooted() ) {
1218                 return false;
1219             }
1220             if ( t1.isRerootable() ) {
1221                 return false;
1222             }
1223             if ( !t1.getType().equals( "gene_tree" ) ) {
1224                 return false;
1225             }
1226             if ( t2.getNumberOfExternalNodes() != 2 ) {
1227                 return false;
1228             }
1229             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1230                 return false;
1231             }
1232             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1233                 return false;
1234             }
1235             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1236                 return false;
1237             }
1238             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1239                 return false;
1240             }
1241             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1242                 return false;
1243             }
1244             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1245                 return false;
1246             }
1247             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1248                     .startsWith( "actgtgggggt" ) ) {
1249                 return false;
1250             }
1251             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1252                     .startsWith( "ctgtgatgcat" ) ) {
1253                 return false;
1254             }
1255             if ( t3.getNumberOfExternalNodes() != 4 ) {
1256                 return false;
1257             }
1258             if ( !t1.getName().equals( "t1" ) ) {
1259                 return false;
1260             }
1261             if ( !t2.getName().equals( "t2" ) ) {
1262                 return false;
1263             }
1264             if ( !t3.getName().equals( "t3" ) ) {
1265                 return false;
1266             }
1267             if ( !t4.getName().equals( "t4" ) ) {
1268                 return false;
1269             }
1270             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1271                 return false;
1272             }
1273             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1274                 return false;
1275             }
1276             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1277                 return false;
1278             }
1279             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1280                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1281                 return false;
1282             }
1283             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1284                 return false;
1285             }
1286             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1287                 return false;
1288             }
1289             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1290                 return false;
1291             }
1292             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1293                     .equals( "apoptosis" ) ) {
1294                 return false;
1295             }
1296             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1297                     .equals( "GO:0006915" ) ) {
1298                 return false;
1299             }
1300             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1301                     .equals( "UniProtKB" ) ) {
1302                 return false;
1303             }
1304             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1305                     .equals( "experimental" ) ) {
1306                 return false;
1307             }
1308             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1309                     .equals( "function" ) ) {
1310                 return false;
1311             }
1312             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1313                     .getValue() != 1 ) {
1314                 return false;
1315             }
1316             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1317                     .getType().equals( "ml" ) ) {
1318                 return false;
1319             }
1320             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1321                     .equals( "apoptosis" ) ) {
1322                 return false;
1323             }
1324             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1325                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1326                 return false;
1327             }
1328             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1329                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1330                 return false;
1331             }
1332             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1333                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1334                 return false;
1335             }
1336             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1337                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1338                 return false;
1339             }
1340             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1341                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1342                 return false;
1343             }
1344             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1345                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1346                 return false;
1347             }
1348             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1349                     .equals( "GO:0005829" ) ) {
1350                 return false;
1351             }
1352             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1353                     .equals( "intracellular organelle" ) ) {
1354                 return false;
1355             }
1356             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1357                 return false;
1358             }
1359             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1360                     .equals( "UniProt link" ) ) ) {
1361                 return false;
1362             }
1363             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1364                 return false;
1365             }
1366         }
1367         catch ( final Exception e ) {
1368             e.printStackTrace( System.out );
1369             return false;
1370         }
1371         return true;
1372     }
1373
1374     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1375         try {
1376             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1377             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1378             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1379                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1380             }
1381             else {
1382                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1383             }
1384             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1385                                                               xml_parser );
1386             if ( xml_parser.getErrorCount() > 0 ) {
1387                 System.out.println( xml_parser.getErrorMessages().toString() );
1388                 return false;
1389             }
1390             if ( phylogenies_0.length != 4 ) {
1391                 return false;
1392             }
1393             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1394             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1395             if ( phylogenies_t1.length != 1 ) {
1396                 return false;
1397             }
1398             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1399             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1400                 return false;
1401             }
1402             if ( !t1_rt.isRooted() ) {
1403                 return false;
1404             }
1405             if ( t1_rt.isRerootable() ) {
1406                 return false;
1407             }
1408             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1409                 return false;
1410             }
1411             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1412             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1413             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1414             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1415                 return false;
1416             }
1417             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1418                 return false;
1419             }
1420             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1421                 return false;
1422             }
1423             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1424                 return false;
1425             }
1426             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1427                     .startsWith( "actgtgggggt" ) ) {
1428                 return false;
1429             }
1430             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1431                     .startsWith( "ctgtgatgcat" ) ) {
1432                 return false;
1433             }
1434             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1435             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1436             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1437             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1438             if ( phylogenies_1.length != 1 ) {
1439                 return false;
1440             }
1441             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1442             if ( !t3_rt.getName().equals( "t3" ) ) {
1443                 return false;
1444             }
1445             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1446                 return false;
1447             }
1448             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1449                 return false;
1450             }
1451             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1452                 return false;
1453             }
1454             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1455                 return false;
1456             }
1457             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1458                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1459                 return false;
1460             }
1461             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1462                 return false;
1463             }
1464             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1465                 return false;
1466             }
1467             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1468                     .equals( "UniProtKB" ) ) {
1469                 return false;
1470             }
1471             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1472                     .equals( "apoptosis" ) ) {
1473                 return false;
1474             }
1475             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1476                     .equals( "GO:0006915" ) ) {
1477                 return false;
1478             }
1479             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1480                     .equals( "UniProtKB" ) ) {
1481                 return false;
1482             }
1483             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1484                     .equals( "experimental" ) ) {
1485                 return false;
1486             }
1487             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1488                     .equals( "function" ) ) {
1489                 return false;
1490             }
1491             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1492                     .getValue() != 1 ) {
1493                 return false;
1494             }
1495             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1496                     .getType().equals( "ml" ) ) {
1497                 return false;
1498             }
1499             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1500                     .equals( "apoptosis" ) ) {
1501                 return false;
1502             }
1503             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1504                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1505                 return false;
1506             }
1507             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1508                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1509                 return false;
1510             }
1511             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1512                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1513                 return false;
1514             }
1515             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1516                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1517                 return false;
1518             }
1519             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1520                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1521                 return false;
1522             }
1523             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1524                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1525                 return false;
1526             }
1527             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1528                     .equals( "GO:0005829" ) ) {
1529                 return false;
1530             }
1531             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1532                     .equals( "intracellular organelle" ) ) {
1533                 return false;
1534             }
1535             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1536                 return false;
1537             }
1538             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1539                     .equals( "UniProt link" ) ) ) {
1540                 return false;
1541             }
1542             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1543                 return false;
1544             }
1545             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1546                 return false;
1547             }
1548             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1549                     .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." ) ) ) {
1550                 return false;
1551             }
1552             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1553                 return false;
1554             }
1555             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1556                 return false;
1557             }
1558             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1559                 return false;
1560             }
1561             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1562                 return false;
1563             }
1564             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1565                     .equals( "ncbi" ) ) {
1566                 return false;
1567             }
1568             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1569                 return false;
1570             }
1571             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1572                     .getName().equals( "B" ) ) {
1573                 return false;
1574             }
1575             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1576                     .getFrom() != 21 ) {
1577                 return false;
1578             }
1579             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1580                 return false;
1581             }
1582             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1583                     .getLength() != 24 ) {
1584                 return false;
1585             }
1586             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1587                     .getConfidence() != 2144 ) {
1588                 return false;
1589             }
1590             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1591                     .equals( "pfam" ) ) {
1592                 return false;
1593             }
1594             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1595                 return false;
1596             }
1597             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1598                 return false;
1599             }
1600             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1601                 return false;
1602             }
1603             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1604                 return false;
1605             }
1606             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1607             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1608                 return false;
1609             }
1610             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1611                 return false;
1612             }
1613             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1614                 return false;
1615             }
1616             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1617                 return false;
1618             }
1619             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1620                 return false;
1621             }
1622             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1623                 return false;
1624             }
1625             if ( taxbb.getSynonyms().size() != 2 ) {
1626                 return false;
1627             }
1628             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1629                 return false;
1630             }
1631             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1632                 return false;
1633             }
1634             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1635                 return false;
1636             }
1637             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1638                 return false;
1639             }
1640             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1641                 return false;
1642             }
1643             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1644                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1645                 ;
1646                 return false;
1647             }
1648             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1649                 return false;
1650             }
1651             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1652                 return false;
1653             }
1654             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1655                 return false;
1656             }
1657             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1658                 return false;
1659             }
1660             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1661                 return false;
1662             }
1663             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1664                 return false;
1665             }
1666             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1667                 return false;
1668             }
1669             //
1670             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1671                 return false;
1672             }
1673             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1674                     .equalsIgnoreCase( "435" ) ) {
1675                 return false;
1676             }
1677             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1678                 return false;
1679             }
1680             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1681                     .equalsIgnoreCase( "443.7" ) ) {
1682                 return false;
1683             }
1684             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1685                 return false;
1686             }
1687             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1688                 return false;
1689             }
1690             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1691                     .equalsIgnoreCase( "433" ) ) {
1692                 return false;
1693             }
1694         }
1695         catch ( final Exception e ) {
1696             e.printStackTrace( System.out );
1697             return false;
1698         }
1699         return true;
1700     }
1701
1702     private static boolean testBasicPhyloXMLparsingValidating() {
1703         try {
1704             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1705             PhyloXmlParser xml_parser = null;
1706             try {
1707                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1708             }
1709             catch ( final Exception e ) {
1710                 // Do nothing -- means were not running from jar.
1711             }
1712             if ( xml_parser == null ) {
1713                 xml_parser = new PhyloXmlParser();
1714                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1715                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1716                 }
1717                 else {
1718                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1719                 }
1720             }
1721             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1722                                                               xml_parser );
1723             if ( xml_parser.getErrorCount() > 0 ) {
1724                 System.out.println( xml_parser.getErrorMessages().toString() );
1725                 return false;
1726             }
1727             if ( phylogenies_0.length != 4 ) {
1728                 return false;
1729             }
1730             final Phylogeny t1 = phylogenies_0[ 0 ];
1731             final Phylogeny t2 = phylogenies_0[ 1 ];
1732             final Phylogeny t3 = phylogenies_0[ 2 ];
1733             final Phylogeny t4 = phylogenies_0[ 3 ];
1734             if ( !t1.getName().equals( "t1" ) ) {
1735                 return false;
1736             }
1737             if ( !t2.getName().equals( "t2" ) ) {
1738                 return false;
1739             }
1740             if ( !t3.getName().equals( "t3" ) ) {
1741                 return false;
1742             }
1743             if ( !t4.getName().equals( "t4" ) ) {
1744                 return false;
1745             }
1746             if ( t1.getNumberOfExternalNodes() != 1 ) {
1747                 return false;
1748             }
1749             if ( t2.getNumberOfExternalNodes() != 2 ) {
1750                 return false;
1751             }
1752             if ( t3.getNumberOfExternalNodes() != 4 ) {
1753                 return false;
1754             }
1755             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1756             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1757             if ( xml_parser.getErrorCount() > 0 ) {
1758                 System.out.println( "errors:" );
1759                 System.out.println( xml_parser.getErrorMessages().toString() );
1760                 return false;
1761             }
1762             if ( phylogenies_1.length != 4 ) {
1763                 return false;
1764             }
1765             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1766                                                               xml_parser );
1767             if ( xml_parser.getErrorCount() > 0 ) {
1768                 System.out.println( "errors:" );
1769                 System.out.println( xml_parser.getErrorMessages().toString() );
1770                 return false;
1771             }
1772             if ( phylogenies_2.length != 1 ) {
1773                 return false;
1774             }
1775             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1776                 return false;
1777             }
1778             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1779                                                               xml_parser );
1780             if ( xml_parser.getErrorCount() > 0 ) {
1781                 System.out.println( xml_parser.getErrorMessages().toString() );
1782                 return false;
1783             }
1784             if ( phylogenies_3.length != 2 ) {
1785                 return false;
1786             }
1787             final Phylogeny a = phylogenies_3[ 0 ];
1788             if ( !a.getName().equals( "tree 4" ) ) {
1789                 return false;
1790             }
1791             if ( a.getNumberOfExternalNodes() != 3 ) {
1792                 return false;
1793             }
1794             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1795                 return false;
1796             }
1797             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1798                 return false;
1799             }
1800             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1801                                                               xml_parser );
1802             if ( xml_parser.getErrorCount() > 0 ) {
1803                 System.out.println( xml_parser.getErrorMessages().toString() );
1804                 return false;
1805             }
1806             if ( phylogenies_4.length != 1 ) {
1807                 return false;
1808             }
1809             final Phylogeny s = phylogenies_4[ 0 ];
1810             if ( s.getNumberOfExternalNodes() != 6 ) {
1811                 return false;
1812             }
1813             s.getNode( "first" );
1814             s.getNode( "<>" );
1815             s.getNode( "\"<a'b&c'd\">\"" );
1816             s.getNode( "'''\"" );
1817             s.getNode( "\"\"\"" );
1818             s.getNode( "dick & doof" );
1819         }
1820         catch ( final Exception e ) {
1821             e.printStackTrace( System.out );
1822             return false;
1823         }
1824         return true;
1825     }
1826
1827     private static boolean testBasicTable() {
1828         try {
1829             final BasicTable<String> t0 = new BasicTable<String>();
1830             if ( t0.getNumberOfColumns() != 0 ) {
1831                 return false;
1832             }
1833             if ( t0.getNumberOfRows() != 0 ) {
1834                 return false;
1835             }
1836             t0.setValue( 3, 2, "23" );
1837             t0.setValue( 10, 1, "error" );
1838             t0.setValue( 10, 1, "110" );
1839             t0.setValue( 9, 1, "19" );
1840             t0.setValue( 1, 10, "101" );
1841             t0.setValue( 10, 10, "1010" );
1842             t0.setValue( 100, 10, "10100" );
1843             t0.setValue( 0, 0, "00" );
1844             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1845                 return false;
1846             }
1847             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1848                 return false;
1849             }
1850             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1851                 return false;
1852             }
1853             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1854                 return false;
1855             }
1856             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1857                 return false;
1858             }
1859             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1860                 return false;
1861             }
1862             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1863                 return false;
1864             }
1865             if ( t0.getNumberOfColumns() != 101 ) {
1866                 return false;
1867             }
1868             if ( t0.getNumberOfRows() != 11 ) {
1869                 return false;
1870             }
1871             if ( t0.getValueAsString( 49, 4 ) != null ) {
1872                 return false;
1873             }
1874             final String l = ForesterUtil.getLineSeparator();
1875             final StringBuffer source = new StringBuffer();
1876             source.append( "" + l );
1877             source.append( "# 1 1 1 1 1 1 1 1" + l );
1878             source.append( " 00 01 02 03" + l );
1879             source.append( "   10 11 12 13  " + l );
1880             source.append( "20 21 22 23 " + l );
1881             source.append( "    30  31    32 33" + l );
1882             source.append( "40 41 42 43" + l );
1883             source.append( "  # 1 1 1 1 1 " + l );
1884             source.append( "50 51 52 53 54" + l );
1885             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), " " );
1886             if ( t1.getNumberOfColumns() != 5 ) {
1887                 return false;
1888             }
1889             if ( t1.getNumberOfRows() != 6 ) {
1890                 return false;
1891             }
1892             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1893                 return false;
1894             }
1895             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1896                 return false;
1897             }
1898             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1899                 return false;
1900             }
1901             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1902                 return false;
1903             }
1904             final StringBuffer source1 = new StringBuffer();
1905             source1.append( "" + l );
1906             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1907             source1.append( " 00; 01 ;02;03" + l );
1908             source1.append( "   10; 11; 12; 13  " + l );
1909             source1.append( "20; 21; 22; 23 " + l );
1910             source1.append( "    30;  31;    32; 33" + l );
1911             source1.append( "40;41;42;43" + l );
1912             source1.append( "  # 1 1 1 1 1 " + l );
1913             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
1914             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ";" );
1915             if ( t2.getNumberOfColumns() != 5 ) {
1916                 return false;
1917             }
1918             if ( t2.getNumberOfRows() != 6 ) {
1919                 return false;
1920             }
1921             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1922                 return false;
1923             }
1924             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1925                 return false;
1926             }
1927             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1928                 return false;
1929             }
1930             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1931                 return false;
1932             }
1933             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1934                 return false;
1935             }
1936             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1937                 return false;
1938             }
1939             final StringBuffer source2 = new StringBuffer();
1940             source2.append( "" + l );
1941             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1942             source2.append( " 00; 01 ;02;03" + l );
1943             source2.append( "   10; 11; 12; 13  " + l );
1944             source2.append( "20; 21; 22; 23 " + l );
1945             source2.append( "                     " + l );
1946             source2.append( "    30;  31;    32; 33" + l );
1947             source2.append( "40;41;42;43" + l );
1948             source2.append( "  comment: 1 1 1 1 1 " + l );
1949             source2.append( ";;;50  ;   52; 53;;54   " + l );
1950             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1951                                                                         ";",
1952                                                                         false,
1953                                                                         false,
1954                                                                         "comment:",
1955                                                                         false );
1956             if ( tl.size() != 2 ) {
1957                 return false;
1958             }
1959             final BasicTable<String> t3 = tl.get( 0 );
1960             final BasicTable<String> t4 = tl.get( 1 );
1961             if ( t3.getNumberOfColumns() != 4 ) {
1962                 return false;
1963             }
1964             if ( t3.getNumberOfRows() != 3 ) {
1965                 return false;
1966             }
1967             if ( t4.getNumberOfColumns() != 4 ) {
1968                 return false;
1969             }
1970             if ( t4.getNumberOfRows() != 3 ) {
1971                 return false;
1972             }
1973             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1974                 return false;
1975             }
1976             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
1977                 return false;
1978             }
1979         }
1980         catch ( final Exception e ) {
1981             e.printStackTrace( System.out );
1982             return false;
1983         }
1984         return true;
1985     }
1986
1987     private static boolean testBasicTolXMLparsing() {
1988         try {
1989             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1990             final TolParser parser = new TolParser();
1991             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
1992             if ( parser.getErrorCount() > 0 ) {
1993                 System.out.println( parser.getErrorMessages().toString() );
1994                 return false;
1995             }
1996             if ( phylogenies_0.length != 1 ) {
1997                 return false;
1998             }
1999             final Phylogeny t1 = phylogenies_0[ 0 ];
2000             if ( t1.getNumberOfExternalNodes() != 5 ) {
2001                 return false;
2002             }
2003             if ( !t1.isRooted() ) {
2004                 return false;
2005             }
2006             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2007                 return false;
2008             }
2009             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2010                 return false;
2011             }
2012             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2013                 return false;
2014             }
2015             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2016                 return false;
2017             }
2018             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2019             if ( parser.getErrorCount() > 0 ) {
2020                 System.out.println( parser.getErrorMessages().toString() );
2021                 return false;
2022             }
2023             if ( phylogenies_1.length != 1 ) {
2024                 return false;
2025             }
2026             final Phylogeny t2 = phylogenies_1[ 0 ];
2027             if ( t2.getNumberOfExternalNodes() != 664 ) {
2028                 return false;
2029             }
2030             if ( !t2.isRooted() ) {
2031                 return false;
2032             }
2033             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2034                 return false;
2035             }
2036             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2037                 return false;
2038             }
2039             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2040                 return false;
2041             }
2042             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2043                 return false;
2044             }
2045             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2046                 return false;
2047             }
2048             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2049                     .equals( "Aquifex" ) ) {
2050                 return false;
2051             }
2052             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2053             if ( parser.getErrorCount() > 0 ) {
2054                 System.out.println( parser.getErrorMessages().toString() );
2055                 return false;
2056             }
2057             if ( phylogenies_2.length != 1 ) {
2058                 return false;
2059             }
2060             final Phylogeny t3 = phylogenies_2[ 0 ];
2061             if ( t3.getNumberOfExternalNodes() != 184 ) {
2062                 return false;
2063             }
2064             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2065                 return false;
2066             }
2067             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2068                 return false;
2069             }
2070             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2071                 return false;
2072             }
2073             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2074             if ( parser.getErrorCount() > 0 ) {
2075                 System.out.println( parser.getErrorMessages().toString() );
2076                 return false;
2077             }
2078             if ( phylogenies_3.length != 1 ) {
2079                 return false;
2080             }
2081             final Phylogeny t4 = phylogenies_3[ 0 ];
2082             if ( t4.getNumberOfExternalNodes() != 1 ) {
2083                 return false;
2084             }
2085             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2086                 return false;
2087             }
2088             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2089                 return false;
2090             }
2091             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2092                 return false;
2093             }
2094             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2095             if ( parser.getErrorCount() > 0 ) {
2096                 System.out.println( parser.getErrorMessages().toString() );
2097                 return false;
2098             }
2099             if ( phylogenies_4.length != 1 ) {
2100                 return false;
2101             }
2102             final Phylogeny t5 = phylogenies_4[ 0 ];
2103             if ( t5.getNumberOfExternalNodes() != 13 ) {
2104                 return false;
2105             }
2106             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2107                 return false;
2108             }
2109             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2110                 return false;
2111             }
2112             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2113                 return false;
2114             }
2115         }
2116         catch ( final Exception e ) {
2117             e.printStackTrace( System.out );
2118             return false;
2119         }
2120         return true;
2121     }
2122
2123     private static boolean testBasicTreeMethods() {
2124         try {
2125             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2126             final Phylogeny t1 = factory.create();
2127             if ( !t1.isEmpty() ) {
2128                 return false;
2129             }
2130             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2131             if ( t2.getNumberOfExternalNodes() != 4 ) {
2132                 return false;
2133             }
2134             if ( t2.getHeight() != 8.5 ) {
2135                 return false;
2136             }
2137             if ( !t2.isCompletelyBinary() ) {
2138                 return false;
2139             }
2140             if ( t2.isEmpty() ) {
2141                 return false;
2142             }
2143             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2144             if ( t3.getNumberOfExternalNodes() != 5 ) {
2145                 return false;
2146             }
2147             if ( t3.getHeight() != 11 ) {
2148                 return false;
2149             }
2150             if ( t3.isCompletelyBinary() ) {
2151                 return false;
2152             }
2153             final PhylogenyNode n = t3.getNode( "ABC" );
2154             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 ];
2155             if ( t4.getNumberOfExternalNodes() != 9 ) {
2156                 return false;
2157             }
2158             if ( t4.getHeight() != 11 ) {
2159                 return false;
2160             }
2161             if ( t4.isCompletelyBinary() ) {
2162                 return false;
2163             }
2164             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)" );
2165             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2166             if ( t5.getNumberOfExternalNodes() != 8 ) {
2167                 return false;
2168             }
2169             if ( t5.getHeight() != 15 ) {
2170                 return false;
2171             }
2172             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)" );
2173             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2174             if ( t6.getHeight() != 15 ) {
2175                 return false;
2176             }
2177             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)" );
2178             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2179             if ( t7.getHeight() != 15 ) {
2180                 return false;
2181             }
2182             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)" );
2183             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2184             if ( t8.getNumberOfExternalNodes() != 10 ) {
2185                 return false;
2186             }
2187             if ( t8.getHeight() != 15 ) {
2188                 return false;
2189             }
2190             final char[] a9 = new char[] { 'a' };
2191             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2192             if ( t9.getHeight() != 0 ) {
2193                 return false;
2194             }
2195             final char[] a10 = new char[] { 'a', ':', '6' };
2196             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2197             if ( t10.getHeight() != 6 ) {
2198                 return false;
2199             }
2200         }
2201         catch ( final Exception e ) {
2202             e.printStackTrace( System.out );
2203             return false;
2204         }
2205         return true;
2206     }
2207
2208     private static boolean testTreeMethods() {
2209         try {
2210             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2211             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
2212             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
2213             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
2214                 System.out.println( t0.toNewHampshireX() );
2215                 return false;
2216             }
2217             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
2218             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
2219             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
2220                 return false;
2221             }
2222             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
2223                 return false;
2224             }
2225             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
2226                 return false;
2227             }
2228         }
2229         catch ( final Exception e ) {
2230             e.printStackTrace( System.out );
2231             return false;
2232         }
2233         return true;
2234     }
2235
2236     private static boolean testConfidenceAssessor() {
2237         try {
2238             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2239             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2240             final Phylogeny[] ev0 = factory
2241                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2242                              new NHXParser() );
2243             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2244             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2245                 return false;
2246             }
2247             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2248                 return false;
2249             }
2250             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2251             final Phylogeny[] ev1 = factory
2252                     .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)));",
2253                              new NHXParser() );
2254             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2255             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2256                 return false;
2257             }
2258             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2259                 return false;
2260             }
2261             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2262             final Phylogeny[] ev_b = factory
2263                     .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",
2264                              new NHXParser() );
2265             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2266             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2267                 return false;
2268             }
2269             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2270                 return false;
2271             }
2272             //
2273             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2274             final Phylogeny[] ev1x = factory
2275                     .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)));",
2276                              new NHXParser() );
2277             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2278             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2279                 return false;
2280             }
2281             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2282                 return false;
2283             }
2284             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2285             final Phylogeny[] ev_bx = factory
2286                     .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",
2287                              new NHXParser() );
2288             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2289             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2290                 return false;
2291             }
2292             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2293                 return false;
2294             }
2295             //
2296             final Phylogeny[] t2 = factory
2297                     .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);",
2298                              new NHXParser() );
2299             final Phylogeny[] ev2 = factory
2300                     .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);",
2301                              new NHXParser() );
2302             for( final Phylogeny target : t2 ) {
2303                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2304             }
2305             //
2306             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2307                                                  new NHXParser() )[ 0 ];
2308             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2309             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2310             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2311                 return false;
2312             }
2313             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2314                 return false;
2315             }
2316             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2317                 return false;
2318             }
2319         }
2320         catch ( final Exception e ) {
2321             e.printStackTrace();
2322             return false;
2323         }
2324         return true;
2325     }
2326
2327     private static boolean testCopyOfNodeData() {
2328         try {
2329             final PhylogenyNode n1 = PhylogenyNode
2330                     .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]" );
2331             final PhylogenyNode n2 = n1.copyNodeData();
2332             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2333                 return false;
2334             }
2335         }
2336         catch ( final Exception e ) {
2337             e.printStackTrace();
2338             return false;
2339         }
2340         return true;
2341     }
2342
2343     private static boolean testDataObjects() {
2344         try {
2345             final Confidence s0 = new Confidence();
2346             final Confidence s1 = new Confidence();
2347             if ( !s0.isEqual( s1 ) ) {
2348                 return false;
2349             }
2350             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2351             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2352             if ( s2.isEqual( s1 ) ) {
2353                 return false;
2354             }
2355             if ( !s2.isEqual( s3 ) ) {
2356                 return false;
2357             }
2358             final Confidence s4 = ( Confidence ) s3.copy();
2359             if ( !s4.isEqual( s3 ) ) {
2360                 return false;
2361             }
2362             s3.asSimpleText();
2363             s3.asText();
2364             // Taxonomy
2365             // ----------
2366             final Taxonomy t1 = new Taxonomy();
2367             final Taxonomy t2 = new Taxonomy();
2368             final Taxonomy t3 = new Taxonomy();
2369             final Taxonomy t4 = new Taxonomy();
2370             final Taxonomy t5 = new Taxonomy();
2371             t1.setIdentifier( new Identifier( "ecoli" ) );
2372             t1.setTaxonomyCode( "ECOLI" );
2373             t1.setScientificName( "E. coli" );
2374             t1.setCommonName( "coli" );
2375             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2376             if ( !t1.isEqual( t0 ) ) {
2377                 return false;
2378             }
2379             t2.setIdentifier( new Identifier( "ecoli" ) );
2380             t2.setTaxonomyCode( "OTHER" );
2381             t2.setScientificName( "what" );
2382             t2.setCommonName( "something" );
2383             if ( !t1.isEqual( t2 ) ) {
2384                 return false;
2385             }
2386             t2.setIdentifier( new Identifier( "nemve" ) );
2387             if ( t1.isEqual( t2 ) ) {
2388                 return false;
2389             }
2390             t1.setIdentifier( null );
2391             t3.setTaxonomyCode( "ECOLI" );
2392             t3.setScientificName( "what" );
2393             t3.setCommonName( "something" );
2394             if ( !t1.isEqual( t3 ) ) {
2395                 return false;
2396             }
2397             t1.setIdentifier( null );
2398             t1.setTaxonomyCode( "" );
2399             t4.setScientificName( "E. ColI" );
2400             t4.setCommonName( "something" );
2401             if ( !t1.isEqual( t4 ) ) {
2402                 return false;
2403             }
2404             t4.setScientificName( "B. subtilis" );
2405             t4.setCommonName( "something" );
2406             if ( t1.isEqual( t4 ) ) {
2407                 return false;
2408             }
2409             t1.setIdentifier( null );
2410             t1.setTaxonomyCode( "" );
2411             t1.setScientificName( "" );
2412             t5.setCommonName( "COLI" );
2413             if ( !t1.isEqual( t5 ) ) {
2414                 return false;
2415             }
2416             t5.setCommonName( "vibrio" );
2417             if ( t1.isEqual( t5 ) ) {
2418                 return false;
2419             }
2420             // Identifier
2421             // ----------
2422             final Identifier id0 = new Identifier( "123", "pfam" );
2423             final Identifier id1 = ( Identifier ) id0.copy();
2424             if ( !id1.isEqual( id1 ) ) {
2425                 return false;
2426             }
2427             if ( !id1.isEqual( id0 ) ) {
2428                 return false;
2429             }
2430             if ( !id0.isEqual( id1 ) ) {
2431                 return false;
2432             }
2433             id1.asSimpleText();
2434             id1.asText();
2435             // ProteinDomain
2436             // ---------------
2437             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2438             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2439             if ( !pd1.isEqual( pd1 ) ) {
2440                 return false;
2441             }
2442             if ( !pd1.isEqual( pd0 ) ) {
2443                 return false;
2444             }
2445             pd1.asSimpleText();
2446             pd1.asText();
2447             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2448             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2449             if ( !pd3.isEqual( pd3 ) ) {
2450                 return false;
2451             }
2452             if ( !pd2.isEqual( pd3 ) ) {
2453                 return false;
2454             }
2455             if ( !pd0.isEqual( pd3 ) ) {
2456                 return false;
2457             }
2458             pd3.asSimpleText();
2459             pd3.asText();
2460             // DomainArchitecture
2461             // ------------------
2462             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2463             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2464             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2465             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2466             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2467             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2468             domains0.add( d2 );
2469             domains0.add( d0 );
2470             domains0.add( d3 );
2471             domains0.add( d1 );
2472             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2473             if ( ds0.getNumberOfDomains() != 4 ) {
2474                 return false;
2475             }
2476             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2477             if ( !ds0.isEqual( ds0 ) ) {
2478                 return false;
2479             }
2480             if ( !ds0.isEqual( ds1 ) ) {
2481                 return false;
2482             }
2483             if ( ds1.getNumberOfDomains() != 4 ) {
2484                 return false;
2485             }
2486             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2487             domains1.add( d1 );
2488             domains1.add( d2 );
2489             domains1.add( d4 );
2490             domains1.add( d0 );
2491             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2492             if ( ds0.isEqual( ds2 ) ) {
2493                 return false;
2494             }
2495             ds1.asSimpleText();
2496             ds1.asText();
2497             ds1.toNHX();
2498             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2499             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2500                 System.out.println( ds3.toNHX() );
2501                 return false;
2502             }
2503             if ( ds3.getNumberOfDomains() != 3 ) {
2504                 return false;
2505             }
2506             // Event
2507             // -----
2508             final Event e1 = new Event( Event.EventType.fusion );
2509             if ( e1.isDuplication() ) {
2510                 return false;
2511             }
2512             if ( !e1.isFusion() ) {
2513                 return false;
2514             }
2515             if ( !e1.asText().toString().equals( "fusion" ) ) {
2516                 return false;
2517             }
2518             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2519                 return false;
2520             }
2521             final Event e11 = new Event( Event.EventType.fusion );
2522             if ( !e11.isEqual( e1 ) ) {
2523                 return false;
2524             }
2525             if ( !e11.toNHX().toString().equals( "" ) ) {
2526                 return false;
2527             }
2528             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2529             if ( e2.isDuplication() ) {
2530                 return false;
2531             }
2532             if ( !e2.isSpeciationOrDuplication() ) {
2533                 return false;
2534             }
2535             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2536                 return false;
2537             }
2538             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2539                 return false;
2540             }
2541             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2542                 return false;
2543             }
2544             if ( e11.isEqual( e2 ) ) {
2545                 return false;
2546             }
2547             final Event e2c = ( Event ) e2.copy();
2548             if ( !e2c.isEqual( e2 ) ) {
2549                 return false;
2550             }
2551             Event e3 = new Event( 1, 2, 3 );
2552             if ( e3.isDuplication() ) {
2553                 return false;
2554             }
2555             if ( e3.isSpeciation() ) {
2556                 return false;
2557             }
2558             if ( e3.isGeneLoss() ) {
2559                 return false;
2560             }
2561             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2562                 return false;
2563             }
2564             final Event e3c = ( Event ) e3.copy();
2565             final Event e3cc = ( Event ) e3c.copy();
2566             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2567                 return false;
2568             }
2569             e3 = null;
2570             if ( !e3c.isEqual( e3cc ) ) {
2571                 return false;
2572             }
2573             Event e4 = new Event( 1, 2, 3 );
2574             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2575                 return false;
2576             }
2577             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2578                 return false;
2579             }
2580             final Event e4c = ( Event ) e4.copy();
2581             e4 = null;
2582             final Event e4cc = ( Event ) e4c.copy();
2583             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2584                 return false;
2585             }
2586             if ( !e4c.isEqual( e4cc ) ) {
2587                 return false;
2588             }
2589             final Event e5 = new Event();
2590             if ( !e5.isUnassigned() ) {
2591                 return false;
2592             }
2593             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2594                 return false;
2595             }
2596             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2597                 return false;
2598             }
2599             final Event e6 = new Event( 1, 0, 0 );
2600             if ( !e6.asText().toString().equals( "duplication" ) ) {
2601                 return false;
2602             }
2603             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2604                 return false;
2605             }
2606             final Event e7 = new Event( 0, 1, 0 );
2607             if ( !e7.asText().toString().equals( "speciation" ) ) {
2608                 return false;
2609             }
2610             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2611                 return false;
2612             }
2613             final Event e8 = new Event( 0, 0, 1 );
2614             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2615                 return false;
2616             }
2617             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2618                 return false;
2619             }
2620         }
2621         catch ( final Exception e ) {
2622             e.printStackTrace( System.out );
2623             return false;
2624         }
2625         return true;
2626     }
2627
2628     private static boolean testDeletionOfExternalNodes() {
2629         try {
2630             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2631             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2632             final PhylogenyWriter w = new PhylogenyWriter();
2633             if ( t0.isEmpty() ) {
2634                 return false;
2635             }
2636             if ( t0.getNumberOfExternalNodes() != 1 ) {
2637                 return false;
2638             }
2639             t0.deleteSubtree( t0.getNode( "A" ), false );
2640             if ( t0.getNumberOfExternalNodes() != 0 ) {
2641                 return false;
2642             }
2643             if ( !t0.isEmpty() ) {
2644                 return false;
2645             }
2646             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2647             if ( t1.getNumberOfExternalNodes() != 2 ) {
2648                 return false;
2649             }
2650             t1.deleteSubtree( t1.getNode( "A" ), false );
2651             if ( t1.getNumberOfExternalNodes() != 1 ) {
2652                 return false;
2653             }
2654             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2655                 return false;
2656             }
2657             t1.deleteSubtree( t1.getNode( "B" ), false );
2658             if ( t1.getNumberOfExternalNodes() != 1 ) {
2659                 return false;
2660             }
2661             t1.deleteSubtree( t1.getNode( "r" ), false );
2662             if ( !t1.isEmpty() ) {
2663                 return false;
2664             }
2665             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2666             if ( t2.getNumberOfExternalNodes() != 3 ) {
2667                 return false;
2668             }
2669             t2.deleteSubtree( t2.getNode( "B" ), false );
2670             if ( t2.getNumberOfExternalNodes() != 2 ) {
2671                 return false;
2672             }
2673             t2.toNewHampshireX();
2674             PhylogenyNode n = t2.getNode( "A" );
2675             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2676                 return false;
2677             }
2678             t2.deleteSubtree( t2.getNode( "A" ), false );
2679             if ( t2.getNumberOfExternalNodes() != 2 ) {
2680                 return false;
2681             }
2682             t2.deleteSubtree( t2.getNode( "C" ), true );
2683             if ( t2.getNumberOfExternalNodes() != 1 ) {
2684                 return false;
2685             }
2686             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2687             if ( t3.getNumberOfExternalNodes() != 4 ) {
2688                 return false;
2689             }
2690             t3.deleteSubtree( t3.getNode( "B" ), true );
2691             if ( t3.getNumberOfExternalNodes() != 3 ) {
2692                 return false;
2693             }
2694             n = t3.getNode( "A" );
2695             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2696                 return false;
2697             }
2698             n = n.getNextExternalNode();
2699             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2700                 return false;
2701             }
2702             t3.deleteSubtree( t3.getNode( "A" ), true );
2703             if ( t3.getNumberOfExternalNodes() != 2 ) {
2704                 return false;
2705             }
2706             n = t3.getNode( "C" );
2707             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2708                 return false;
2709             }
2710             t3.deleteSubtree( t3.getNode( "C" ), true );
2711             if ( t3.getNumberOfExternalNodes() != 1 ) {
2712                 return false;
2713             }
2714             t3.deleteSubtree( t3.getNode( "D" ), true );
2715             if ( t3.getNumberOfExternalNodes() != 0 ) {
2716                 return false;
2717             }
2718             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2719             if ( t4.getNumberOfExternalNodes() != 6 ) {
2720                 return false;
2721             }
2722             t4.deleteSubtree( t4.getNode( "B2" ), true );
2723             if ( t4.getNumberOfExternalNodes() != 5 ) {
2724                 return false;
2725             }
2726             String s = w.toNewHampshire( t4, false, true ).toString();
2727             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2728                 return false;
2729             }
2730             t4.deleteSubtree( t4.getNode( "B11" ), true );
2731             if ( t4.getNumberOfExternalNodes() != 4 ) {
2732                 return false;
2733             }
2734             t4.deleteSubtree( t4.getNode( "C" ), true );
2735             if ( t4.getNumberOfExternalNodes() != 3 ) {
2736                 return false;
2737             }
2738             n = t4.getNode( "A" );
2739             n = n.getNextExternalNode();
2740             if ( !n.getName().equals( "B12" ) ) {
2741                 return false;
2742             }
2743             n = n.getNextExternalNode();
2744             if ( !n.getName().equals( "D" ) ) {
2745                 return false;
2746             }
2747             s = w.toNewHampshire( t4, false, true ).toString();
2748             if ( !s.equals( "((A,B12),D);" ) ) {
2749                 return false;
2750             }
2751             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2752             t5.deleteSubtree( t5.getNode( "A" ), true );
2753             if ( t5.getNumberOfExternalNodes() != 5 ) {
2754                 return false;
2755             }
2756             s = w.toNewHampshire( t5, false, true ).toString();
2757             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2758                 return false;
2759             }
2760             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2761             t6.deleteSubtree( t6.getNode( "B11" ), true );
2762             if ( t6.getNumberOfExternalNodes() != 5 ) {
2763                 return false;
2764             }
2765             s = w.toNewHampshire( t6, false, false ).toString();
2766             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2767                 return false;
2768             }
2769             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2770             t7.deleteSubtree( t7.getNode( "B12" ), true );
2771             if ( t7.getNumberOfExternalNodes() != 5 ) {
2772                 return false;
2773             }
2774             s = w.toNewHampshire( t7, false, true ).toString();
2775             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2776                 return false;
2777             }
2778             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2779             t8.deleteSubtree( t8.getNode( "B2" ), true );
2780             if ( t8.getNumberOfExternalNodes() != 5 ) {
2781                 return false;
2782             }
2783             s = w.toNewHampshire( t8, false, false ).toString();
2784             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2785                 return false;
2786             }
2787             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2788             t9.deleteSubtree( t9.getNode( "C" ), true );
2789             if ( t9.getNumberOfExternalNodes() != 5 ) {
2790                 return false;
2791             }
2792             s = w.toNewHampshire( t9, false, true ).toString();
2793             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2794                 return false;
2795             }
2796             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2797             t10.deleteSubtree( t10.getNode( "D" ), true );
2798             if ( t10.getNumberOfExternalNodes() != 5 ) {
2799                 return false;
2800             }
2801             s = w.toNewHampshire( t10, false, true ).toString();
2802             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2803                 return false;
2804             }
2805             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2806             t11.deleteSubtree( t11.getNode( "A" ), true );
2807             if ( t11.getNumberOfExternalNodes() != 2 ) {
2808                 return false;
2809             }
2810             s = w.toNewHampshire( t11, false, true ).toString();
2811             if ( !s.equals( "(B,C);" ) ) {
2812                 return false;
2813             }
2814             t11.deleteSubtree( t11.getNode( "C" ), true );
2815             if ( t11.getNumberOfExternalNodes() != 1 ) {
2816                 return false;
2817             }
2818             s = w.toNewHampshire( t11, false, false ).toString();
2819             if ( !s.equals( "B;" ) ) {
2820                 return false;
2821             }
2822             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2823             t12.deleteSubtree( t12.getNode( "B2" ), true );
2824             if ( t12.getNumberOfExternalNodes() != 8 ) {
2825                 return false;
2826             }
2827             s = w.toNewHampshire( t12, false, true ).toString();
2828             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2829                 return false;
2830             }
2831             t12.deleteSubtree( t12.getNode( "B3" ), true );
2832             if ( t12.getNumberOfExternalNodes() != 7 ) {
2833                 return false;
2834             }
2835             s = w.toNewHampshire( t12, false, true ).toString();
2836             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2837                 return false;
2838             }
2839             t12.deleteSubtree( t12.getNode( "C3" ), true );
2840             if ( t12.getNumberOfExternalNodes() != 6 ) {
2841                 return false;
2842             }
2843             s = w.toNewHampshire( t12, false, true ).toString();
2844             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2845                 return false;
2846             }
2847             t12.deleteSubtree( t12.getNode( "A1" ), true );
2848             if ( t12.getNumberOfExternalNodes() != 5 ) {
2849                 return false;
2850             }
2851             s = w.toNewHampshire( t12, false, true ).toString();
2852             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2853                 return false;
2854             }
2855             t12.deleteSubtree( t12.getNode( "B1" ), true );
2856             if ( t12.getNumberOfExternalNodes() != 4 ) {
2857                 return false;
2858             }
2859             s = w.toNewHampshire( t12, false, true ).toString();
2860             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2861                 return false;
2862             }
2863             t12.deleteSubtree( t12.getNode( "A3" ), true );
2864             if ( t12.getNumberOfExternalNodes() != 3 ) {
2865                 return false;
2866             }
2867             s = w.toNewHampshire( t12, false, true ).toString();
2868             if ( !s.equals( "(A2,(C1,C2));" ) ) {
2869                 return false;
2870             }
2871             t12.deleteSubtree( t12.getNode( "A2" ), true );
2872             if ( t12.getNumberOfExternalNodes() != 2 ) {
2873                 return false;
2874             }
2875             s = w.toNewHampshire( t12, false, true ).toString();
2876             if ( !s.equals( "(C1,C2);" ) ) {
2877                 return false;
2878             }
2879             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2880             t13.deleteSubtree( t13.getNode( "D" ), true );
2881             if ( t13.getNumberOfExternalNodes() != 4 ) {
2882                 return false;
2883             }
2884             s = w.toNewHampshire( t13, false, true ).toString();
2885             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2886                 return false;
2887             }
2888             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2889             t14.deleteSubtree( t14.getNode( "E" ), true );
2890             if ( t14.getNumberOfExternalNodes() != 5 ) {
2891                 return false;
2892             }
2893             s = w.toNewHampshire( t14, false, true ).toString();
2894             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2895                 return false;
2896             }
2897             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2898             t15.deleteSubtree( t15.getNode( "B2" ), true );
2899             if ( t15.getNumberOfExternalNodes() != 11 ) {
2900                 return false;
2901             }
2902             t15.deleteSubtree( t15.getNode( "B1" ), true );
2903             if ( t15.getNumberOfExternalNodes() != 10 ) {
2904                 return false;
2905             }
2906             t15.deleteSubtree( t15.getNode( "B3" ), true );
2907             if ( t15.getNumberOfExternalNodes() != 9 ) {
2908                 return false;
2909             }
2910             t15.deleteSubtree( t15.getNode( "B4" ), true );
2911             if ( t15.getNumberOfExternalNodes() != 8 ) {
2912                 return false;
2913             }
2914             t15.deleteSubtree( t15.getNode( "A1" ), true );
2915             if ( t15.getNumberOfExternalNodes() != 7 ) {
2916                 return false;
2917             }
2918             t15.deleteSubtree( t15.getNode( "C4" ), true );
2919             if ( t15.getNumberOfExternalNodes() != 6 ) {
2920                 return false;
2921             }
2922         }
2923         catch ( final Exception e ) {
2924             e.printStackTrace( System.out );
2925             return false;
2926         }
2927         return true;
2928     }
2929
2930     private static boolean testDescriptiveStatistics() {
2931         try {
2932             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2933             dss1.addValue( 82 );
2934             dss1.addValue( 78 );
2935             dss1.addValue( 70 );
2936             dss1.addValue( 58 );
2937             dss1.addValue( 42 );
2938             if ( dss1.getN() != 5 ) {
2939                 return false;
2940             }
2941             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2942                 return false;
2943             }
2944             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2945                 return false;
2946             }
2947             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2948                 return false;
2949             }
2950             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2951                 return false;
2952             }
2953             if ( !Test.isEqual( dss1.median(), 70 ) ) {
2954                 return false;
2955             }
2956             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2957                 return false;
2958             }
2959             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2960                 return false;
2961             }
2962             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2963                 return false;
2964             }
2965             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2966                 return false;
2967             }
2968             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2969                 return false;
2970             }
2971             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2972                 return false;
2973             }
2974             dss1.addValue( 123 );
2975             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
2976                 return false;
2977             }
2978             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
2979                 return false;
2980             }
2981             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
2982                 return false;
2983             }
2984             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
2985             dss2.addValue( -1.85 );
2986             dss2.addValue( 57.5 );
2987             dss2.addValue( 92.78 );
2988             dss2.addValue( 57.78 );
2989             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
2990                 return false;
2991             }
2992             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
2993                 return false;
2994             }
2995             final double[] a = dss2.getDataAsDoubleArray();
2996             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
2997                 return false;
2998             }
2999             dss2.addValue( -100 );
3000             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3001                 return false;
3002             }
3003             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3004                 return false;
3005             }
3006             final double[] ds = new double[ 14 ];
3007             ds[ 0 ] = 34;
3008             ds[ 1 ] = 23;
3009             ds[ 2 ] = 1;
3010             ds[ 3 ] = 32;
3011             ds[ 4 ] = 11;
3012             ds[ 5 ] = 2;
3013             ds[ 6 ] = 12;
3014             ds[ 7 ] = 33;
3015             ds[ 8 ] = 13;
3016             ds[ 9 ] = 22;
3017             ds[ 10 ] = 21;
3018             ds[ 11 ] = 35;
3019             ds[ 12 ] = 24;
3020             ds[ 13 ] = 31;
3021             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3022             if ( bins.length != 4 ) {
3023                 return false;
3024             }
3025             if ( bins[ 0 ] != 2 ) {
3026                 return false;
3027             }
3028             if ( bins[ 1 ] != 3 ) {
3029                 return false;
3030             }
3031             if ( bins[ 2 ] != 4 ) {
3032                 return false;
3033             }
3034             if ( bins[ 3 ] != 5 ) {
3035                 return false;
3036             }
3037             final double[] ds1 = new double[ 9 ];
3038             ds1[ 0 ] = 10.0;
3039             ds1[ 1 ] = 19.0;
3040             ds1[ 2 ] = 9.999;
3041             ds1[ 3 ] = 0.0;
3042             ds1[ 4 ] = 39.9;
3043             ds1[ 5 ] = 39.999;
3044             ds1[ 6 ] = 30.0;
3045             ds1[ 7 ] = 19.999;
3046             ds1[ 8 ] = 30.1;
3047             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3048             if ( bins1.length != 4 ) {
3049                 return false;
3050             }
3051             if ( bins1[ 0 ] != 2 ) {
3052                 return false;
3053             }
3054             if ( bins1[ 1 ] != 3 ) {
3055                 return false;
3056             }
3057             if ( bins1[ 2 ] != 0 ) {
3058                 return false;
3059             }
3060             if ( bins1[ 3 ] != 4 ) {
3061                 return false;
3062             }
3063             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3064             if ( bins1_1.length != 3 ) {
3065                 return false;
3066             }
3067             if ( bins1_1[ 0 ] != 3 ) {
3068                 return false;
3069             }
3070             if ( bins1_1[ 1 ] != 2 ) {
3071                 return false;
3072             }
3073             if ( bins1_1[ 2 ] != 4 ) {
3074                 return false;
3075             }
3076             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3077             if ( bins1_2.length != 3 ) {
3078                 return false;
3079             }
3080             if ( bins1_2[ 0 ] != 2 ) {
3081                 return false;
3082             }
3083             if ( bins1_2[ 1 ] != 2 ) {
3084                 return false;
3085             }
3086             if ( bins1_2[ 2 ] != 2 ) {
3087                 return false;
3088             }
3089             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3090             dss3.addValue( 1 );
3091             dss3.addValue( 1 );
3092             dss3.addValue( 1 );
3093             dss3.addValue( 2 );
3094             dss3.addValue( 3 );
3095             dss3.addValue( 4 );
3096             dss3.addValue( 5 );
3097             dss3.addValue( 5 );
3098             dss3.addValue( 5 );
3099             dss3.addValue( 6 );
3100             dss3.addValue( 7 );
3101             dss3.addValue( 8 );
3102             dss3.addValue( 9 );
3103             dss3.addValue( 10 );
3104             dss3.addValue( 10 );
3105             dss3.addValue( 10 );
3106             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3107             histo.toStringBuffer( 10, '=', 40, 5 );
3108             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3109         }
3110         catch ( final Exception e ) {
3111             e.printStackTrace( System.out );
3112             return false;
3113         }
3114         return true;
3115     }
3116
3117     private static boolean testDir( final String file ) {
3118         try {
3119             final File f = new File( file );
3120             if ( !f.exists() ) {
3121                 return false;
3122             }
3123             if ( !f.isDirectory() ) {
3124                 return false;
3125             }
3126             if ( !f.canRead() ) {
3127                 return false;
3128             }
3129         }
3130         catch ( final Exception e ) {
3131             return false;
3132         }
3133         return true;
3134     }
3135
3136     private static boolean testExternalNodeRelatedMethods() {
3137         try {
3138             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3139             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3140             PhylogenyNode n = t1.getNode( "A" );
3141             n = n.getNextExternalNode();
3142             if ( !n.getName().equals( "B" ) ) {
3143                 return false;
3144             }
3145             n = n.getNextExternalNode();
3146             if ( !n.getName().equals( "C" ) ) {
3147                 return false;
3148             }
3149             n = n.getNextExternalNode();
3150             if ( !n.getName().equals( "D" ) ) {
3151                 return false;
3152             }
3153             n = t1.getNode( "B" );
3154             while ( !n.isLastExternalNode() ) {
3155                 n = n.getNextExternalNode();
3156             }
3157             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3158             n = t2.getNode( "A" );
3159             n = n.getNextExternalNode();
3160             if ( !n.getName().equals( "B" ) ) {
3161                 return false;
3162             }
3163             n = n.getNextExternalNode();
3164             if ( !n.getName().equals( "C" ) ) {
3165                 return false;
3166             }
3167             n = n.getNextExternalNode();
3168             if ( !n.getName().equals( "D" ) ) {
3169                 return false;
3170             }
3171             n = t2.getNode( "B" );
3172             while ( !n.isLastExternalNode() ) {
3173                 n = n.getNextExternalNode();
3174             }
3175             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3176             n = t3.getNode( "A" );
3177             n = n.getNextExternalNode();
3178             if ( !n.getName().equals( "B" ) ) {
3179                 return false;
3180             }
3181             n = n.getNextExternalNode();
3182             if ( !n.getName().equals( "C" ) ) {
3183                 return false;
3184             }
3185             n = n.getNextExternalNode();
3186             if ( !n.getName().equals( "D" ) ) {
3187                 return false;
3188             }
3189             n = n.getNextExternalNode();
3190             if ( !n.getName().equals( "E" ) ) {
3191                 return false;
3192             }
3193             n = n.getNextExternalNode();
3194             if ( !n.getName().equals( "F" ) ) {
3195                 return false;
3196             }
3197             n = n.getNextExternalNode();
3198             if ( !n.getName().equals( "G" ) ) {
3199                 return false;
3200             }
3201             n = n.getNextExternalNode();
3202             if ( !n.getName().equals( "H" ) ) {
3203                 return false;
3204             }
3205             n = t3.getNode( "B" );
3206             while ( !n.isLastExternalNode() ) {
3207                 n = n.getNextExternalNode();
3208             }
3209             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3210             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3211                 final PhylogenyNode node = iter.next();
3212             }
3213             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3214             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3215                 final PhylogenyNode node = iter.next();
3216             }
3217             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3218             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3219             if ( !iter.next().getName().equals( "A" ) ) {
3220                 return false;
3221             }
3222             if ( !iter.next().getName().equals( "B" ) ) {
3223                 return false;
3224             }
3225             if ( !iter.next().getName().equals( "C" ) ) {
3226                 return false;
3227             }
3228             if ( !iter.next().getName().equals( "D" ) ) {
3229                 return false;
3230             }
3231             if ( !iter.next().getName().equals( "E" ) ) {
3232                 return false;
3233             }
3234             if ( !iter.next().getName().equals( "F" ) ) {
3235                 return false;
3236             }
3237             if ( iter.hasNext() ) {
3238                 return false;
3239             }
3240         }
3241         catch ( final Exception e ) {
3242             e.printStackTrace( System.out );
3243             return false;
3244         }
3245         return true;
3246     }
3247
3248     private static boolean testGeneralTable() {
3249         try {
3250             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3251             t0.setValue( 3, 2, "23" );
3252             t0.setValue( 10, 1, "error" );
3253             t0.setValue( 10, 1, "110" );
3254             t0.setValue( 9, 1, "19" );
3255             t0.setValue( 1, 10, "101" );
3256             t0.setValue( 10, 10, "1010" );
3257             t0.setValue( 100, 10, "10100" );
3258             t0.setValue( 0, 0, "00" );
3259             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3260                 return false;
3261             }
3262             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3263                 return false;
3264             }
3265             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3266                 return false;
3267             }
3268             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3269                 return false;
3270             }
3271             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3272                 return false;
3273             }
3274             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3275                 return false;
3276             }
3277             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3278                 return false;
3279             }
3280             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3281                 return false;
3282             }
3283             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3284                 return false;
3285             }
3286             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3287             t1.setValue( "3", "2", "23" );
3288             t1.setValue( "10", "1", "error" );
3289             t1.setValue( "10", "1", "110" );
3290             t1.setValue( "9", "1", "19" );
3291             t1.setValue( "1", "10", "101" );
3292             t1.setValue( "10", "10", "1010" );
3293             t1.setValue( "100", "10", "10100" );
3294             t1.setValue( "0", "0", "00" );
3295             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3296             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3297                 return false;
3298             }
3299             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3300                 return false;
3301             }
3302             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3303                 return false;
3304             }
3305             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3306                 return false;
3307             }
3308             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3309                 return false;
3310             }
3311             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3312                 return false;
3313             }
3314             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3315                 return false;
3316             }
3317             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3318                 return false;
3319             }
3320             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3321                 return false;
3322             }
3323             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3324                 return false;
3325             }
3326         }
3327         catch ( final Exception e ) {
3328             e.printStackTrace( System.out );
3329             return false;
3330         }
3331         return true;
3332     }
3333
3334     private static boolean testGetDistance() {
3335         try {
3336             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3337             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",
3338                                                  new NHXParser() )[ 0 ];
3339             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3340                 return false;
3341             }
3342             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3343                 return false;
3344             }
3345             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3346                 return false;
3347             }
3348             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3349                 return false;
3350             }
3351             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3352                 return false;
3353             }
3354             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3355                 return false;
3356             }
3357             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3358                 return false;
3359             }
3360             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3361                 return false;
3362             }
3363             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3364                 return false;
3365             }
3366             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3367                 return false;
3368             }
3369             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3370                 return false;
3371             }
3372             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3373                 return false;
3374             }
3375             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3376                 return false;
3377             }
3378             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3379                 return false;
3380             }
3381             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3382                 return false;
3383             }
3384             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3385                 return false;
3386             }
3387             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3388                 return false;
3389             }
3390             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3391                 return false;
3392             }
3393             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3394                 return false;
3395             }
3396             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3397                 return false;
3398             }
3399             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3400                 return false;
3401             }
3402             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3403                 return false;
3404             }
3405             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3406                 return false;
3407             }
3408             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3409                 return false;
3410             }
3411             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3412                 return false;
3413             }
3414             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3415                 return false;
3416             }
3417             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3418                 return false;
3419             }
3420             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3421                 return false;
3422             }
3423             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3424                 return false;
3425             }
3426             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3427                 return false;
3428             }
3429             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3430                 return false;
3431             }
3432             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",
3433                                                  new NHXParser() )[ 0 ];
3434             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3435                 return false;
3436             }
3437             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3438                 return false;
3439             }
3440             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3441                 return false;
3442             }
3443             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3444                 return false;
3445             }
3446             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3447                 return false;
3448             }
3449             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3450                 return false;
3451             }
3452             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3453                 return false;
3454             }
3455             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3456                 return false;
3457             }
3458             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3459                 return false;
3460             }
3461             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3462                 return false;
3463             }
3464             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3465                 return false;
3466             }
3467         }
3468         catch ( final Exception e ) {
3469             e.printStackTrace( System.out );
3470             return false;
3471         }
3472         return true;
3473     }
3474
3475     private static boolean testGetLCA() {
3476         try {
3477             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3478             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3479                                                  new NHXParser() )[ 0 ];
3480             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3481             if ( !A.getName().equals( "A" ) ) {
3482                 return false;
3483             }
3484             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3485             if ( !gh.getName().equals( "gh" ) ) {
3486                 return false;
3487             }
3488             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3489             if ( !ab.getName().equals( "ab" ) ) {
3490                 return false;
3491             }
3492             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3493             if ( !ab2.getName().equals( "ab" ) ) {
3494                 return false;
3495             }
3496             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3497             if ( !gh2.getName().equals( "gh" ) ) {
3498                 return false;
3499             }
3500             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3501             if ( !gh3.getName().equals( "gh" ) ) {
3502                 return false;
3503             }
3504             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3505             if ( !abc.getName().equals( "abc" ) ) {
3506                 return false;
3507             }
3508             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3509             if ( !abc2.getName().equals( "abc" ) ) {
3510                 return false;
3511             }
3512             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3513             if ( !abcd.getName().equals( "abcd" ) ) {
3514                 return false;
3515             }
3516             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3517             if ( !abcd2.getName().equals( "abcd" ) ) {
3518                 return false;
3519             }
3520             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3521             if ( !abcdef.getName().equals( "abcdef" ) ) {
3522                 return false;
3523             }
3524             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3525             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3526                 return false;
3527             }
3528             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3529             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3530                 return false;
3531             }
3532             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3533             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3534                 return false;
3535             }
3536             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3537             if ( !abcde.getName().equals( "abcde" ) ) {
3538                 return false;
3539             }
3540             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3541             if ( !abcde2.getName().equals( "abcde" ) ) {
3542                 return false;
3543             }
3544             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3545             if ( !r.getName().equals( "abcdefgh" ) ) {
3546                 return false;
3547             }
3548             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3549             if ( !r2.getName().equals( "abcdefgh" ) ) {
3550                 return false;
3551             }
3552             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3553             if ( !r3.getName().equals( "abcdefgh" ) ) {
3554                 return false;
3555             }
3556             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3557             if ( !abcde3.getName().equals( "abcde" ) ) {
3558                 return false;
3559             }
3560             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3561             if ( !abcde4.getName().equals( "abcde" ) ) {
3562                 return false;
3563             }
3564             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3565             if ( !ab3.getName().equals( "ab" ) ) {
3566                 return false;
3567             }
3568             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3569             if ( !ab4.getName().equals( "ab" ) ) {
3570                 return false;
3571             }
3572             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3573             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3574             if ( !cd.getName().equals( "cd" ) ) {
3575                 return false;
3576             }
3577             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3578             if ( !cd2.getName().equals( "cd" ) ) {
3579                 return false;
3580             }
3581             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3582             if ( !cde.getName().equals( "cde" ) ) {
3583                 return false;
3584             }
3585             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3586             if ( !cde2.getName().equals( "cde" ) ) {
3587                 return false;
3588             }
3589             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3590             if ( !cdef.getName().equals( "cdef" ) ) {
3591                 return false;
3592             }
3593             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3594             if ( !cdef2.getName().equals( "cdef" ) ) {
3595                 return false;
3596             }
3597             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3598             if ( !cdef3.getName().equals( "cdef" ) ) {
3599                 return false;
3600             }
3601             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3602             if ( !rt.getName().equals( "r" ) ) {
3603                 return false;
3604             }
3605             final Phylogeny p3 = factory
3606                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3607                              new NHXParser() )[ 0 ];
3608             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3609             if ( !bc_3.getName().equals( "bc" ) ) {
3610                 return false;
3611             }
3612             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3613             if ( !ac_3.getName().equals( "abc" ) ) {
3614                 return false;
3615             }
3616             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3617             if ( !ad_3.getName().equals( "abcde" ) ) {
3618                 return false;
3619             }
3620             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3621             if ( !af_3.getName().equals( "abcdef" ) ) {
3622                 return false;
3623             }
3624             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3625             if ( !ag_3.getName().equals( "" ) ) {
3626                 return false;
3627             }
3628             if ( !ag_3.isRoot() ) {
3629                 return false;
3630             }
3631             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3632             if ( !al_3.getName().equals( "" ) ) {
3633                 return false;
3634             }
3635             if ( !al_3.isRoot() ) {
3636                 return false;
3637             }
3638             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3639             if ( !kl_3.getName().equals( "" ) ) {
3640                 return false;
3641             }
3642             if ( !kl_3.isRoot() ) {
3643                 return false;
3644             }
3645             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3646             if ( !fl_3.getName().equals( "" ) ) {
3647                 return false;
3648             }
3649             if ( !fl_3.isRoot() ) {
3650                 return false;
3651             }
3652             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3653             if ( !gk_3.getName().equals( "ghijk" ) ) {
3654                 return false;
3655             }
3656             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3657             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3658             if ( !r_4.getName().equals( "r" ) ) {
3659                 return false;
3660             }
3661             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3662             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3663             if ( !r_5.getName().equals( "root" ) ) {
3664                 return false;
3665             }
3666             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3667             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3668             if ( !r_6.getName().equals( "rot" ) ) {
3669                 return false;
3670             }
3671             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3672             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3673             if ( !r_7.getName().equals( "rott" ) ) {
3674                 return false;
3675             }
3676         }
3677         catch ( final Exception e ) {
3678             e.printStackTrace( System.out );
3679             return false;
3680         }
3681         return true;
3682     }
3683
3684     private static boolean testGetLCA2() {
3685         try {
3686             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3687             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3688             PhylogenyMethods.preOrderReId( p_a );
3689             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3690                                                                                               p_a.getNode( "a" ) );
3691             if ( !p_a_1.getName().equals( "a" ) ) {
3692                 return false;
3693             }
3694             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3695             PhylogenyMethods.preOrderReId( p_b );
3696             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3697                                                                                               p_b.getNode( "a" ) );
3698             if ( !p_b_1.getName().equals( "b" ) ) {
3699                 return false;
3700             }
3701             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3702                                                                                               p_b.getNode( "b" ) );
3703             if ( !p_b_2.getName().equals( "b" ) ) {
3704                 return false;
3705             }
3706             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3707             PhylogenyMethods.preOrderReId( p_c );
3708             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3709                                                                                               p_c.getNode( "a" ) );
3710             if ( !p_c_1.getName().equals( "b" ) ) {
3711                 return false;
3712             }
3713             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3714                                                                                               p_c.getNode( "c" ) );
3715             if ( !p_c_2.getName().equals( "c" ) ) {
3716                 System.out.println( p_c_2.getName() );
3717                 System.exit( -1 );
3718                 return false;
3719             }
3720             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3721                                                                                               p_c.getNode( "b" ) );
3722             if ( !p_c_3.getName().equals( "b" ) ) {
3723                 return false;
3724             }
3725             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3726                                                                                               p_c.getNode( "a" ) );
3727             if ( !p_c_4.getName().equals( "c" ) ) {
3728                 return false;
3729             }
3730             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3731                                                  new NHXParser() )[ 0 ];
3732             PhylogenyMethods.preOrderReId( p1 );
3733             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3734                                                                                           p1.getNode( "A" ) );
3735             if ( !A.getName().equals( "A" ) ) {
3736                 return false;
3737             }
3738             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3739                                                                                            p1.getNode( "gh" ) );
3740             if ( !gh.getName().equals( "gh" ) ) {
3741                 return false;
3742             }
3743             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3744                                                                                            p1.getNode( "B" ) );
3745             if ( !ab.getName().equals( "ab" ) ) {
3746                 return false;
3747             }
3748             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3749                                                                                             p1.getNode( "A" ) );
3750             if ( !ab2.getName().equals( "ab" ) ) {
3751                 return false;
3752             }
3753             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3754                                                                                             p1.getNode( "G" ) );
3755             if ( !gh2.getName().equals( "gh" ) ) {
3756                 return false;
3757             }
3758             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3759                                                                                             p1.getNode( "H" ) );
3760             if ( !gh3.getName().equals( "gh" ) ) {
3761                 return false;
3762             }
3763             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3764                                                                                             p1.getNode( "A" ) );
3765             if ( !abc.getName().equals( "abc" ) ) {
3766                 return false;
3767             }
3768             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3769                                                                                              p1.getNode( "C" ) );
3770             if ( !abc2.getName().equals( "abc" ) ) {
3771                 return false;
3772             }
3773             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3774                                                                                              p1.getNode( "D" ) );
3775             if ( !abcd.getName().equals( "abcd" ) ) {
3776                 return false;
3777             }
3778             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3779                                                                                               p1.getNode( "A" ) );
3780             if ( !abcd2.getName().equals( "abcd" ) ) {
3781                 return false;
3782             }
3783             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3784                                                                                                p1.getNode( "F" ) );
3785             if ( !abcdef.getName().equals( "abcdef" ) ) {
3786                 return false;
3787             }
3788             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3789                                                                                                 p1.getNode( "A" ) );
3790             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3791                 return false;
3792             }
3793             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3794                                                                                                 p1.getNode( "F" ) );
3795             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3796                 return false;
3797             }
3798             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3799                                                                                                 p1.getNode( "ab" ) );
3800             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3801                 return false;
3802             }
3803             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3804                                                                                               p1.getNode( "E" ) );
3805             if ( !abcde.getName().equals( "abcde" ) ) {
3806                 return false;
3807             }
3808             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3809                                                                                                p1.getNode( "A" ) );
3810             if ( !abcde2.getName().equals( "abcde" ) ) {
3811                 return false;
3812             }
3813             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3814                                                                                           p1.getNode( "abcdefgh" ) );
3815             if ( !r.getName().equals( "abcdefgh" ) ) {
3816                 return false;
3817             }
3818             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3819                                                                                            p1.getNode( "H" ) );
3820             if ( !r2.getName().equals( "abcdefgh" ) ) {
3821                 return false;
3822             }
3823             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3824                                                                                            p1.getNode( "A" ) );
3825             if ( !r3.getName().equals( "abcdefgh" ) ) {
3826                 return false;
3827             }
3828             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3829                                                                                                p1.getNode( "abcde" ) );
3830             if ( !abcde3.getName().equals( "abcde" ) ) {
3831                 return false;
3832             }
3833             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3834                                                                                                p1.getNode( "E" ) );
3835             if ( !abcde4.getName().equals( "abcde" ) ) {
3836                 return false;
3837             }
3838             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3839                                                                                             p1.getNode( "B" ) );
3840             if ( !ab3.getName().equals( "ab" ) ) {
3841                 return false;
3842             }
3843             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3844                                                                                             p1.getNode( "ab" ) );
3845             if ( !ab4.getName().equals( "ab" ) ) {
3846                 return false;
3847             }
3848             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3849             PhylogenyMethods.preOrderReId( p2 );
3850             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3851                                                                                            p2.getNode( "d" ) );
3852             if ( !cd.getName().equals( "cd" ) ) {
3853                 return false;
3854             }
3855             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3856                                                                                             p2.getNode( "c" ) );
3857             if ( !cd2.getName().equals( "cd" ) ) {
3858                 return false;
3859             }
3860             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3861                                                                                             p2.getNode( "e" ) );
3862             if ( !cde.getName().equals( "cde" ) ) {
3863                 return false;
3864             }
3865             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3866                                                                                              p2.getNode( "c" ) );
3867             if ( !cde2.getName().equals( "cde" ) ) {
3868                 return false;
3869             }
3870             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3871                                                                                              p2.getNode( "f" ) );
3872             if ( !cdef.getName().equals( "cdef" ) ) {
3873                 return false;
3874             }
3875             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3876                                                                                               p2.getNode( "f" ) );
3877             if ( !cdef2.getName().equals( "cdef" ) ) {
3878                 return false;
3879             }
3880             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3881                                                                                               p2.getNode( "d" ) );
3882             if ( !cdef3.getName().equals( "cdef" ) ) {
3883                 return false;
3884             }
3885             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3886                                                                                            p2.getNode( "a" ) );
3887             if ( !rt.getName().equals( "r" ) ) {
3888                 return false;
3889             }
3890             final Phylogeny p3 = factory
3891                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3892                              new NHXParser() )[ 0 ];
3893             PhylogenyMethods.preOrderReId( p3 );
3894             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3895                                                                                              p3.getNode( "c" ) );
3896             if ( !bc_3.getName().equals( "bc" ) ) {
3897                 return false;
3898             }
3899             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3900                                                                                              p3.getNode( "c" ) );
3901             if ( !ac_3.getName().equals( "abc" ) ) {
3902                 return false;
3903             }
3904             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3905                                                                                              p3.getNode( "d" ) );
3906             if ( !ad_3.getName().equals( "abcde" ) ) {
3907                 return false;
3908             }
3909             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3910                                                                                              p3.getNode( "f" ) );
3911             if ( !af_3.getName().equals( "abcdef" ) ) {
3912                 return false;
3913             }
3914             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3915                                                                                              p3.getNode( "g" ) );
3916             if ( !ag_3.getName().equals( "" ) ) {
3917                 return false;
3918             }
3919             if ( !ag_3.isRoot() ) {
3920                 return false;
3921             }
3922             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3923                                                                                              p3.getNode( "l" ) );
3924             if ( !al_3.getName().equals( "" ) ) {
3925                 return false;
3926             }
3927             if ( !al_3.isRoot() ) {
3928                 return false;
3929             }
3930             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3931                                                                                              p3.getNode( "l" ) );
3932             if ( !kl_3.getName().equals( "" ) ) {
3933                 return false;
3934             }
3935             if ( !kl_3.isRoot() ) {
3936                 return false;
3937             }
3938             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3939                                                                                              p3.getNode( "l" ) );
3940             if ( !fl_3.getName().equals( "" ) ) {
3941                 return false;
3942             }
3943             if ( !fl_3.isRoot() ) {
3944                 return false;
3945             }
3946             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3947                                                                                              p3.getNode( "k" ) );
3948             if ( !gk_3.getName().equals( "ghijk" ) ) {
3949                 return false;
3950             }
3951             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3952             PhylogenyMethods.preOrderReId( p4 );
3953             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3954                                                                                             p4.getNode( "c" ) );
3955             if ( !r_4.getName().equals( "r" ) ) {
3956                 return false;
3957             }
3958             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3959             PhylogenyMethods.preOrderReId( p5 );
3960             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3961                                                                                             p5.getNode( "c" ) );
3962             if ( !r_5.getName().equals( "root" ) ) {
3963                 return false;
3964             }
3965             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3966             PhylogenyMethods.preOrderReId( p6 );
3967             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3968                                                                                             p6.getNode( "a" ) );
3969             if ( !r_6.getName().equals( "rot" ) ) {
3970                 return false;
3971             }
3972             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3973             PhylogenyMethods.preOrderReId( p7 );
3974             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
3975                                                                                             p7.getNode( "e" ) );
3976             if ( !r_7.getName().equals( "rott" ) ) {
3977                 return false;
3978             }
3979             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3980                                                                                              p7.getNode( "a" ) );
3981             if ( !r_71.getName().equals( "rott" ) ) {
3982                 return false;
3983             }
3984             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3985                                                                                              p7.getNode( "rott" ) );
3986             if ( !r_72.getName().equals( "rott" ) ) {
3987                 return false;
3988             }
3989             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3990                                                                                              p7.getNode( "a" ) );
3991             if ( !r_73.getName().equals( "rott" ) ) {
3992                 return false;
3993             }
3994             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3995                                                                                              p7.getNode( "rott" ) );
3996             if ( !r_74.getName().equals( "rott" ) ) {
3997                 return false;
3998             }
3999             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4000                                                                                              p7.getNode( "e" ) );
4001             if ( !r_75.getName().equals( "e" ) ) {
4002                 return false;
4003             }
4004         }
4005         catch ( final Exception e ) {
4006             e.printStackTrace( System.out );
4007             return false;
4008         }
4009         return true;
4010     }
4011
4012     private static boolean testHmmscanOutputParser() {
4013         final String test_dir = Test.PATH_TO_TEST_DATA;
4014         try {
4015             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4016                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4017             parser1.parse();
4018             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4019                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4020             final List<Protein> proteins = parser2.parse();
4021             if ( parser2.getProteinsEncountered() != 4 ) {
4022                 return false;
4023             }
4024             if ( proteins.size() != 4 ) {
4025                 return false;
4026             }
4027             if ( parser2.getDomainsEncountered() != 69 ) {
4028                 return false;
4029             }
4030             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4031                 return false;
4032             }
4033             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4034                 return false;
4035             }
4036             final Protein p1 = proteins.get( 0 );
4037             if ( p1.getNumberOfProteinDomains() != 15 ) {
4038                 return false;
4039             }
4040             if ( p1.getLength() != 850 ) {
4041                 return false;
4042             }
4043             final Protein p2 = proteins.get( 1 );
4044             if ( p2.getNumberOfProteinDomains() != 51 ) {
4045                 return false;
4046             }
4047             if ( p2.getLength() != 1291 ) {
4048                 return false;
4049             }
4050             final Protein p3 = proteins.get( 2 );
4051             if ( p3.getNumberOfProteinDomains() != 2 ) {
4052                 return false;
4053             }
4054             final Protein p4 = proteins.get( 3 );
4055             if ( p4.getNumberOfProteinDomains() != 1 ) {
4056                 return false;
4057             }
4058             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4059                 return false;
4060             }
4061             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4062                 return false;
4063             }
4064             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4065                 return false;
4066             }
4067             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4068                 return false;
4069             }
4070             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4071                 return false;
4072             }
4073             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4074                 return false;
4075             }
4076             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4077                 return false;
4078             }
4079             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4080                 return false;
4081             }
4082             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4083                 return false;
4084             }
4085         }
4086         catch ( final Exception e ) {
4087             e.printStackTrace( System.out );
4088             return false;
4089         }
4090         return true;
4091     }
4092
4093     private static boolean testLastExternalNodeMethods() {
4094         try {
4095             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4096             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4097             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4098             final PhylogenyNode n1 = t0.getNode( "A" );
4099             if ( n1.isLastExternalNode() ) {
4100                 return false;
4101             }
4102             final PhylogenyNode n2 = t0.getNode( "B" );
4103             if ( n2.isLastExternalNode() ) {
4104                 return false;
4105             }
4106             final PhylogenyNode n3 = t0.getNode( "C" );
4107             if ( n3.isLastExternalNode() ) {
4108                 return false;
4109             }
4110             final PhylogenyNode n4 = t0.getNode( "D" );
4111             if ( !n4.isLastExternalNode() ) {
4112                 return false;
4113             }
4114         }
4115         catch ( final Exception e ) {
4116             e.printStackTrace( System.out );
4117             return false;
4118         }
4119         return true;
4120     }
4121
4122     private static boolean testLevelOrderIterator() {
4123         try {
4124             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4125             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4126             PhylogenyNodeIterator it0;
4127             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4128                 it0.next();
4129             }
4130             for( it0.reset(); it0.hasNext(); ) {
4131                 it0.next();
4132             }
4133             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4134             if ( !it.next().getName().equals( "r" ) ) {
4135                 return false;
4136             }
4137             if ( !it.next().getName().equals( "ab" ) ) {
4138                 return false;
4139             }
4140             if ( !it.next().getName().equals( "cd" ) ) {
4141                 return false;
4142             }
4143             if ( !it.next().getName().equals( "A" ) ) {
4144                 return false;
4145             }
4146             if ( !it.next().getName().equals( "B" ) ) {
4147                 return false;
4148             }
4149             if ( !it.next().getName().equals( "C" ) ) {
4150                 return false;
4151             }
4152             if ( !it.next().getName().equals( "D" ) ) {
4153                 return false;
4154             }
4155             if ( it.hasNext() ) {
4156                 return false;
4157             }
4158             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",
4159                                                  new NHXParser() )[ 0 ];
4160             PhylogenyNodeIterator it2;
4161             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4162                 it2.next();
4163             }
4164             for( it2.reset(); it2.hasNext(); ) {
4165                 it2.next();
4166             }
4167             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4168             if ( !it3.next().getName().equals( "r" ) ) {
4169                 return false;
4170             }
4171             if ( !it3.next().getName().equals( "abc" ) ) {
4172                 return false;
4173             }
4174             if ( !it3.next().getName().equals( "defg" ) ) {
4175                 return false;
4176             }
4177             if ( !it3.next().getName().equals( "A" ) ) {
4178                 return false;
4179             }
4180             if ( !it3.next().getName().equals( "B" ) ) {
4181                 return false;
4182             }
4183             if ( !it3.next().getName().equals( "C" ) ) {
4184                 return false;
4185             }
4186             if ( !it3.next().getName().equals( "D" ) ) {
4187                 return false;
4188             }
4189             if ( !it3.next().getName().equals( "E" ) ) {
4190                 return false;
4191             }
4192             if ( !it3.next().getName().equals( "F" ) ) {
4193                 return false;
4194             }
4195             if ( !it3.next().getName().equals( "G" ) ) {
4196                 return false;
4197             }
4198             if ( !it3.next().getName().equals( "1" ) ) {
4199                 return false;
4200             }
4201             if ( !it3.next().getName().equals( "2" ) ) {
4202                 return false;
4203             }
4204             if ( !it3.next().getName().equals( "3" ) ) {
4205                 return false;
4206             }
4207             if ( !it3.next().getName().equals( "4" ) ) {
4208                 return false;
4209             }
4210             if ( !it3.next().getName().equals( "5" ) ) {
4211                 return false;
4212             }
4213             if ( !it3.next().getName().equals( "6" ) ) {
4214                 return false;
4215             }
4216             if ( !it3.next().getName().equals( "f1" ) ) {
4217                 return false;
4218             }
4219             if ( !it3.next().getName().equals( "f2" ) ) {
4220                 return false;
4221             }
4222             if ( !it3.next().getName().equals( "f3" ) ) {
4223                 return false;
4224             }
4225             if ( !it3.next().getName().equals( "a" ) ) {
4226                 return false;
4227             }
4228             if ( !it3.next().getName().equals( "b" ) ) {
4229                 return false;
4230             }
4231             if ( !it3.next().getName().equals( "f21" ) ) {
4232                 return false;
4233             }
4234             if ( !it3.next().getName().equals( "X" ) ) {
4235                 return false;
4236             }
4237             if ( !it3.next().getName().equals( "Y" ) ) {
4238                 return false;
4239             }
4240             if ( !it3.next().getName().equals( "Z" ) ) {
4241                 return false;
4242             }
4243             if ( it3.hasNext() ) {
4244                 return false;
4245             }
4246             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4247             PhylogenyNodeIterator it4;
4248             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4249                 it4.next();
4250             }
4251             for( it4.reset(); it4.hasNext(); ) {
4252                 it4.next();
4253             }
4254             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4255             if ( !it5.next().getName().equals( "r" ) ) {
4256                 return false;
4257             }
4258             if ( !it5.next().getName().equals( "A" ) ) {
4259                 return false;
4260             }
4261             if ( !it5.next().getName().equals( "B" ) ) {
4262                 return false;
4263             }
4264             if ( !it5.next().getName().equals( "C" ) ) {
4265                 return false;
4266             }
4267             if ( !it5.next().getName().equals( "D" ) ) {
4268                 return false;
4269             }
4270             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4271             PhylogenyNodeIterator it6;
4272             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4273                 it6.next();
4274             }
4275             for( it6.reset(); it6.hasNext(); ) {
4276                 it6.next();
4277             }
4278             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4279             if ( !it7.next().getName().equals( "A" ) ) {
4280                 return false;
4281             }
4282             if ( it.hasNext() ) {
4283                 return false;
4284             }
4285         }
4286         catch ( final Exception e ) {
4287             e.printStackTrace( System.out );
4288             return false;
4289         }
4290         return true;
4291     }
4292
4293     private static boolean testNodeRemoval() {
4294         try {
4295             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4296             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4297             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
4298             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
4299                 return false;
4300             }
4301             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
4302             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
4303             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
4304                 return false;
4305             }
4306             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
4307             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
4308             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
4309                 return false;
4310             }
4311         }
4312         catch ( final Exception e ) {
4313             e.printStackTrace( System.out );
4314             return false;
4315         }
4316         return true;
4317     }
4318
4319     private static boolean testMidpointrooting() {
4320         try {
4321             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4322             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4323             PhylogenyMethods.midpointRoot( t0 );
4324             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4325                 return false;
4326             }
4327             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4328                 return false;
4329             }
4330             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4331                            1 ) ) {
4332                 return false;
4333             }
4334             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",
4335                                                  new NHXParser() )[ 0 ];
4336             if ( !t1.isRooted() ) {
4337                 return false;
4338             }
4339             PhylogenyMethods.midpointRoot( t1 );
4340             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4341                 return false;
4342             }
4343             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4344                 return false;
4345             }
4346             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4347                 return false;
4348             }
4349             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4350                 return false;
4351             }
4352             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4353                 return false;
4354             }
4355             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4356                 return false;
4357             }
4358             t1.reRoot( t1.getNode( "A" ) );
4359             PhylogenyMethods.midpointRoot( t1 );
4360             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4361                 return false;
4362             }
4363             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4364                 return false;
4365             }
4366             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4367                 return false;
4368             }
4369             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4370                 return false;
4371             }
4372             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4373                 System.exit( -1 );
4374                 return false;
4375             }
4376             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4377                 return false;
4378             }
4379         }
4380         catch ( final Exception e ) {
4381             e.printStackTrace( System.out );
4382             return false;
4383         }
4384         return true;
4385     }
4386
4387     private static boolean testNexusCharactersParsing() {
4388         try {
4389             final NexusCharactersParser parser = new NexusCharactersParser();
4390             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4391             parser.parse();
4392             String[] labels = parser.getCharStateLabels();
4393             if ( labels.length != 7 ) {
4394                 return false;
4395             }
4396             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4397                 return false;
4398             }
4399             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4400                 return false;
4401             }
4402             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4403                 return false;
4404             }
4405             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4406                 return false;
4407             }
4408             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4409                 return false;
4410             }
4411             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4412                 return false;
4413             }
4414             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4415                 return false;
4416             }
4417             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4418             parser.parse();
4419             labels = parser.getCharStateLabels();
4420             if ( labels.length != 7 ) {
4421                 return false;
4422             }
4423             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4424                 return false;
4425             }
4426             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4427                 return false;
4428             }
4429             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4430                 return false;
4431             }
4432             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4433                 return false;
4434             }
4435             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4436                 return false;
4437             }
4438             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4439                 return false;
4440             }
4441             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4442                 return false;
4443             }
4444         }
4445         catch ( final Exception e ) {
4446             e.printStackTrace( System.out );
4447             return false;
4448         }
4449         return true;
4450     }
4451
4452     private static boolean testNexusMatrixParsing() {
4453         try {
4454             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4455             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4456             parser.parse();
4457             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4458             if ( m.getNumberOfCharacters() != 9 ) {
4459                 return false;
4460             }
4461             if ( m.getNumberOfIdentifiers() != 5 ) {
4462                 return false;
4463             }
4464             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4465                 return false;
4466             }
4467             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4468                 return false;
4469             }
4470             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4471                 return false;
4472             }
4473             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4474                 return false;
4475             }
4476             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4477                 return false;
4478             }
4479             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4480                 return false;
4481             }
4482             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4483                 return false;
4484             }
4485             //            if ( labels.length != 7 ) {
4486             //                return false;
4487             //            }
4488             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4489             //                return false;
4490             //            }
4491             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4492             //                return false;
4493             //            }
4494             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4495             //                return false;
4496             //            }
4497             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4498             //                return false;
4499             //            }
4500             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4501             //                return false;
4502             //            }
4503             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4504             //                return false;
4505             //            }
4506             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4507             //                return false;
4508             //            }
4509             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4510             //            parser.parse();
4511             //            labels = parser.getCharStateLabels();
4512             //            if ( labels.length != 7 ) {
4513             //                return false;
4514             //            }
4515             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4516             //                return false;
4517             //            }
4518             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4519             //                return false;
4520             //            }
4521             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4522             //                return false;
4523             //            }
4524             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4525             //                return false;
4526             //            }
4527             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4528             //                return false;
4529             //            }
4530             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4531             //                return false;
4532             //            }
4533             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4534             //                return false;
4535             //            }
4536         }
4537         catch ( final Exception e ) {
4538             e.printStackTrace( System.out );
4539             return false;
4540         }
4541         return true;
4542     }
4543
4544     private static boolean testNexusTreeParsing() {
4545         try {
4546             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4547             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4548             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4549             if ( phylogenies.length != 1 ) {
4550                 return false;
4551             }
4552             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4553                 return false;
4554             }
4555             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4556                 return false;
4557             }
4558             phylogenies = null;
4559             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4560             if ( phylogenies.length != 1 ) {
4561                 return false;
4562             }
4563             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4564                 return false;
4565             }
4566             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4567                 return false;
4568             }
4569             phylogenies = null;
4570             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4571             if ( phylogenies.length != 1 ) {
4572                 return false;
4573             }
4574             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4575                 return false;
4576             }
4577             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4578                 return false;
4579             }
4580             if ( phylogenies[ 0 ].isRooted() ) {
4581                 return false;
4582             }
4583             phylogenies = null;
4584             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4585             if ( phylogenies.length != 18 ) {
4586                 return false;
4587             }
4588             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4589                 return false;
4590             }
4591             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4592                 return false;
4593             }
4594             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4595                 return false;
4596             }
4597             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4598                 return false;
4599             }
4600             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4601                 return false;
4602             }
4603             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4604                 return false;
4605             }
4606             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4607                 return false;
4608             }
4609             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4610                 return false;
4611             }
4612             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4613                 return false;
4614             }
4615             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4616                 return false;
4617             }
4618             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4619                 return false;
4620             }
4621             if ( phylogenies[ 8 ].isRooted() ) {
4622                 return false;
4623             }
4624             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4625                 return false;
4626             }
4627             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4628                 return false;
4629             }
4630             if ( !phylogenies[ 9 ].isRooted() ) {
4631                 return false;
4632             }
4633             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4634                 return false;
4635             }
4636             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4637                 return false;
4638             }
4639             if ( !phylogenies[ 10 ].isRooted() ) {
4640                 return false;
4641             }
4642             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4643                 return false;
4644             }
4645             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4646                 return false;
4647             }
4648             if ( phylogenies[ 11 ].isRooted() ) {
4649                 return false;
4650             }
4651             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4652                 return false;
4653             }
4654             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4655                 return false;
4656             }
4657             if ( !phylogenies[ 12 ].isRooted() ) {
4658                 return false;
4659             }
4660             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4661                 return false;
4662             }
4663             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4664                 return false;
4665             }
4666             if ( !phylogenies[ 13 ].isRooted() ) {
4667                 return false;
4668             }
4669             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4670                 return false;
4671             }
4672             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4673                 return false;
4674             }
4675             if ( !phylogenies[ 14 ].isRooted() ) {
4676                 return false;
4677             }
4678             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4679                 return false;
4680             }
4681             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4682                 return false;
4683             }
4684             if ( phylogenies[ 15 ].isRooted() ) {
4685                 return false;
4686             }
4687             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4688                 return false;
4689             }
4690             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4691                 return false;
4692             }
4693             if ( !phylogenies[ 16 ].isRooted() ) {
4694                 return false;
4695             }
4696             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4697                 return false;
4698             }
4699             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4700                 return false;
4701             }
4702             if ( phylogenies[ 17 ].isRooted() ) {
4703                 return false;
4704             }
4705             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4706                 return false;
4707             }
4708         }
4709         catch ( final Exception e ) {
4710             e.printStackTrace( System.out );
4711             return false;
4712         }
4713         return true;
4714     }
4715
4716     private static boolean testNexusTreeParsingIterating() {
4717         try {
4718             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
4719             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
4720             if ( !p.hasNext() ) {
4721                 return false;
4722             }
4723             Phylogeny phy = p.next();
4724             if ( phy == null ) {
4725                 return false;
4726             }
4727             if ( phy.getNumberOfExternalNodes() != 25 ) {
4728                 return false;
4729             }
4730             if ( !phy.getName().equals( "" ) ) {
4731                 return false;
4732             }
4733             if ( p.hasNext() ) {
4734                 return false;
4735             }
4736             phy = p.next();
4737             if ( phy != null ) {
4738                 return false;
4739             }
4740             //
4741             p.reset();
4742             if ( !p.hasNext() ) {
4743                 return false;
4744             }
4745             phy = p.next();
4746             if ( phy == null ) {
4747                 return false;
4748             }
4749             if ( phy.getNumberOfExternalNodes() != 25 ) {
4750                 return false;
4751             }
4752             if ( !phy.getName().equals( "" ) ) {
4753                 return false;
4754             }
4755             if ( p.hasNext() ) {
4756                 return false;
4757             }
4758             phy = p.next();
4759             if ( phy != null ) {
4760                 return false;
4761             }
4762             ////
4763             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
4764             if ( !p.hasNext() ) {
4765                 return false;
4766             }
4767             phy = p.next();
4768             if ( phy == null ) {
4769                 return false;
4770             }
4771             if ( phy.getNumberOfExternalNodes() != 10 ) {
4772                 return false;
4773             }
4774             if ( !phy.getName().equals( "name" ) ) {
4775                 return false;
4776             }
4777             if ( p.hasNext() ) {
4778                 return false;
4779             }
4780             phy = p.next();
4781             if ( phy != null ) {
4782                 return false;
4783             }
4784             //
4785             p.reset();
4786             if ( !p.hasNext() ) {
4787                 return false;
4788             }
4789             phy = p.next();
4790             if ( phy == null ) {
4791                 return false;
4792             }
4793             if ( phy.getNumberOfExternalNodes() != 10 ) {
4794                 return false;
4795             }
4796             if ( !phy.getName().equals( "name" ) ) {
4797                 return false;
4798             }
4799             if ( p.hasNext() ) {
4800                 return false;
4801             }
4802             phy = p.next();
4803             if ( phy != null ) {
4804                 return false;
4805             }
4806             ////
4807             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
4808             if ( !p.hasNext() ) {
4809                 return false;
4810             }
4811             phy = p.next();
4812             if ( phy == null ) {
4813                 return false;
4814             }
4815             if ( phy.getNumberOfExternalNodes() != 3 ) {
4816                 return false;
4817             }
4818             if ( !phy.getName().equals( "" ) ) {
4819                 return false;
4820             }
4821             if ( phy.isRooted() ) {
4822                 return false;
4823             }
4824             if ( p.hasNext() ) {
4825                 return false;
4826             }
4827             phy = p.next();
4828             if ( phy != null ) {
4829                 return false;
4830             }
4831             //
4832             p.reset();
4833             if ( !p.hasNext() ) {
4834                 return false;
4835             }
4836             phy = p.next();
4837             if ( phy == null ) {
4838                 return false;
4839             }
4840             if ( phy.getNumberOfExternalNodes() != 3 ) {
4841                 return false;
4842             }
4843             if ( !phy.getName().equals( "" ) ) {
4844                 return false;
4845             }
4846             if ( p.hasNext() ) {
4847                 return false;
4848             }
4849             phy = p.next();
4850             if ( phy != null ) {
4851                 return false;
4852             }
4853             ////
4854             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
4855             //            if ( phylogenies.length != 18 ) {
4856             //                return false;
4857             //            }
4858             //0
4859             if ( !p.hasNext() ) {
4860                 return false;
4861             }
4862             phy = p.next();
4863             if ( phy == null ) {
4864                 return false;
4865             }
4866             if ( phy.getNumberOfExternalNodes() != 10 ) {
4867                 return false;
4868             }
4869             if ( !phy.getName().equals( "tree 0" ) ) {
4870                 return false;
4871             }
4872             //1
4873             if ( !p.hasNext() ) {
4874                 return false;
4875             }
4876             phy = p.next();
4877             if ( phy == null ) {
4878                 return false;
4879             }
4880             if ( phy.getNumberOfExternalNodes() != 10 ) {
4881                 return false;
4882             }
4883             if ( !phy.getName().equals( "tree 1" ) ) {
4884                 return false;
4885             }
4886             //2
4887             if ( !p.hasNext() ) {
4888                 return false;
4889             }
4890             phy = p.next();
4891             if ( phy == null ) {
4892                 return false;
4893             }
4894             if ( phy.getNumberOfExternalNodes() != 3 ) {
4895                 return false;
4896             }
4897             if ( !phy.getName().equals( "" ) ) {
4898                 return false;
4899             }
4900             if ( phy.isRooted() ) {
4901                 return false;
4902             }
4903             //3
4904             if ( !p.hasNext() ) {
4905                 return false;
4906             }
4907             phy = p.next();
4908             if ( phy == null ) {
4909                 return false;
4910             }
4911             if ( phy.getNumberOfExternalNodes() != 4 ) {
4912                 return false;
4913             }
4914             if ( !phy.getName().equals( "" ) ) {
4915                 return false;
4916             }
4917             if ( !phy.isRooted() ) {
4918                 return false;
4919             }
4920             //4
4921             if ( !p.hasNext() ) {
4922                 return false;
4923             }
4924             phy = p.next();
4925             if ( phy == null ) {
4926                 return false;
4927             }
4928             if ( phy.getNumberOfExternalNodes() != 5 ) {
4929                 System.out.println( phy.getNumberOfExternalNodes() );
4930                 return false;
4931             }
4932             if ( !phy.getName().equals( "" ) ) {
4933                 return false;
4934             }
4935             if ( !phy.isRooted() ) {
4936                 return false;
4937             }
4938             //5
4939             if ( !p.hasNext() ) {
4940                 return false;
4941             }
4942             phy = p.next();
4943             if ( phy == null ) {
4944                 return false;
4945             }
4946             if ( phy.getNumberOfExternalNodes() != 3 ) {
4947                 return false;
4948             }
4949             if ( !phy.getName().equals( "" ) ) {
4950                 return false;
4951             }
4952             if ( phy.isRooted() ) {
4953                 return false;
4954             }
4955             //6
4956             if ( !p.hasNext() ) {
4957                 return false;
4958             }
4959             phy = p.next();
4960             if ( phy == null ) {
4961                 return false;
4962             }
4963             if ( phy.getNumberOfExternalNodes() != 2 ) {
4964                 return false;
4965             }
4966             if ( !phy.getName().equals( "" ) ) {
4967                 return false;
4968             }
4969             if ( !phy.isRooted() ) {
4970                 return false;
4971             }
4972             //7
4973             if ( !p.hasNext() ) {
4974                 return false;
4975             }
4976             phy = p.next();
4977             if ( phy.getNumberOfExternalNodes() != 3 ) {
4978                 return false;
4979             }
4980             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
4981                 return false;
4982             }
4983             if ( !phy.isRooted() ) {
4984                 return false;
4985             }
4986             //8
4987             if ( !p.hasNext() ) {
4988                 return false;
4989             }
4990             phy = p.next();
4991             if ( phy.getNumberOfExternalNodes() != 3 ) {
4992                 return false;
4993             }
4994             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
4995                 return false;
4996             }
4997             if ( !phy.getName().equals( "tree 8" ) ) {
4998                 return false;
4999             }
5000             //9
5001             if ( !p.hasNext() ) {
5002                 return false;
5003             }
5004             phy = p.next();
5005             if ( phy.getNumberOfExternalNodes() != 3 ) {
5006                 return false;
5007             }
5008             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
5009                 return false;
5010             }
5011             if ( !phy.getName().equals( "tree 9" ) ) {
5012                 return false;
5013             }
5014             //10
5015             if ( !p.hasNext() ) {
5016                 return false;
5017             }
5018             phy = p.next();
5019             if ( phy.getNumberOfExternalNodes() != 3 ) {
5020                 return false;
5021             }
5022             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5023                 return false;
5024             }
5025             if ( !phy.getName().equals( "tree 10" ) ) {
5026                 return false;
5027             }
5028             if ( !phy.isRooted() ) {
5029                 return false;
5030             }
5031             //11
5032             if ( !p.hasNext() ) {
5033                 return false;
5034             }
5035             phy = p.next();
5036             if ( phy.getNumberOfExternalNodes() != 3 ) {
5037                 return false;
5038             }
5039             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
5040                 return false;
5041             }
5042             if ( !phy.getName().equals( "tree 11" ) ) {
5043                 return false;
5044             }
5045             if ( phy.isRooted() ) {
5046                 return false;
5047             }
5048             //12
5049             if ( !p.hasNext() ) {
5050                 return false;
5051             }
5052             phy = p.next();
5053             if ( phy.getNumberOfExternalNodes() != 3 ) {
5054                 return false;
5055             }
5056             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
5057                 return false;
5058             }
5059             if ( !phy.getName().equals( "tree 12" ) ) {
5060                 return false;
5061             }
5062             if ( !phy.isRooted() ) {
5063                 return false;
5064             }
5065             //13
5066             if ( !p.hasNext() ) {
5067                 return false;
5068             }
5069             phy = p.next();
5070             if ( phy.getNumberOfExternalNodes() != 3 ) {
5071                 return false;
5072             }
5073             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5074                 return false;
5075             }
5076             if ( !phy.getName().equals( "tree 13" ) ) {
5077                 return false;
5078             }
5079             if ( !phy.isRooted() ) {
5080                 return false;
5081             }
5082             //14
5083             if ( !p.hasNext() ) {
5084                 return false;
5085             }
5086             phy = p.next();
5087             if ( phy.getNumberOfExternalNodes() != 10 ) {
5088                 System.out.println( phy.getNumberOfExternalNodes() );
5089                 return false;
5090             }
5091             if ( !phy
5092                     .toNewHampshire()
5093                     .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;" ) ) {
5094                 System.out.println( phy.toNewHampshire() );
5095                 return false;
5096             }
5097             if ( !phy.getName().equals( "tree 14" ) ) {
5098                 return false;
5099             }
5100             if ( !phy.isRooted() ) {
5101                 return false;
5102             }
5103             //15
5104             if ( !p.hasNext() ) {
5105                 return false;
5106             }
5107             phy = p.next();
5108             if ( phy.getNumberOfExternalNodes() != 10 ) {
5109                 System.out.println( phy.getNumberOfExternalNodes() );
5110                 return false;
5111             }
5112             if ( !phy
5113                     .toNewHampshire()
5114                     .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;" ) ) {
5115                 System.out.println( phy.toNewHampshire() );
5116                 return false;
5117             }
5118             if ( !phy.getName().equals( "tree 15" ) ) {
5119                 return false;
5120             }
5121             if ( phy.isRooted() ) {
5122                 return false;
5123             }
5124             //16
5125             if ( !p.hasNext() ) {
5126                 return false;
5127             }
5128             phy = p.next();
5129             if ( phy.getNumberOfExternalNodes() != 10 ) {
5130                 System.out.println( phy.getNumberOfExternalNodes() );
5131                 return false;
5132             }
5133             if ( !phy
5134                     .toNewHampshire()
5135                     .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;" ) ) {
5136                 System.out.println( phy.toNewHampshire() );
5137                 return false;
5138             }
5139             if ( !phy.getName().equals( "tree 16" ) ) {
5140                 return false;
5141             }
5142             if ( !phy.isRooted() ) {
5143                 return false;
5144             }
5145             //17
5146             if ( !p.hasNext() ) {
5147                 return false;
5148             }
5149             phy = p.next();
5150             if ( phy.getNumberOfExternalNodes() != 10 ) {
5151                 System.out.println( phy.getNumberOfExternalNodes() );
5152                 return false;
5153             }
5154             if ( !phy
5155                     .toNewHampshire()
5156                     .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;" ) ) {
5157                 System.out.println( phy.toNewHampshire() );
5158                 return false;
5159             }
5160             if ( !phy.getName().equals( "tree 17" ) ) {
5161                 return false;
5162             }
5163             if ( phy.isRooted() ) {
5164                 return false;
5165             }
5166             //
5167             if ( p.hasNext() ) {
5168                 return false;
5169             }
5170             phy = p.next();
5171             if ( phy != null ) {
5172                 return false;
5173             }
5174             p.reset();
5175             //0
5176             if ( !p.hasNext() ) {
5177                 return false;
5178             }
5179             phy = p.next();
5180             if ( phy == null ) {
5181                 return false;
5182             }
5183             if ( phy.getNumberOfExternalNodes() != 10 ) {
5184                 return false;
5185             }
5186             if ( !phy.getName().equals( "tree 0" ) ) {
5187                 return false;
5188             }
5189             //1
5190             if ( !p.hasNext() ) {
5191                 return false;
5192             }
5193             phy = p.next();
5194             if ( phy == null ) {
5195                 return false;
5196             }
5197             if ( phy.getNumberOfExternalNodes() != 10 ) {
5198                 return false;
5199             }
5200             if ( !phy.getName().equals( "tree 1" ) ) {
5201                 return false;
5202             }
5203             //2
5204             if ( !p.hasNext() ) {
5205                 return false;
5206             }
5207             phy = p.next();
5208             if ( phy == null ) {
5209                 return false;
5210             }
5211             if ( phy.getNumberOfExternalNodes() != 3 ) {
5212                 return false;
5213             }
5214             if ( !phy.getName().equals( "" ) ) {
5215                 return false;
5216             }
5217             if ( phy.isRooted() ) {
5218                 return false;
5219             }
5220             //3
5221             if ( !p.hasNext() ) {
5222                 return false;
5223             }
5224             phy = p.next();
5225             if ( phy == null ) {
5226                 return false;
5227             }
5228             if ( phy.getNumberOfExternalNodes() != 4 ) {
5229                 return false;
5230             }
5231             if ( !phy.getName().equals( "" ) ) {
5232                 return false;
5233             }
5234             if ( !phy.isRooted() ) {
5235                 return false;
5236             }
5237             //4
5238             if ( !p.hasNext() ) {
5239                 return false;
5240             }
5241             phy = p.next();
5242             if ( phy == null ) {
5243                 return false;
5244             }
5245             if ( phy.getNumberOfExternalNodes() != 5 ) {
5246                 System.out.println( phy.getNumberOfExternalNodes() );
5247                 return false;
5248             }
5249             if ( !phy.getName().equals( "" ) ) {
5250                 return false;
5251             }
5252             if ( !phy.isRooted() ) {
5253                 return false;
5254             }
5255             //5
5256             if ( !p.hasNext() ) {
5257                 return false;
5258             }
5259             phy = p.next();
5260             if ( phy == null ) {
5261                 return false;
5262             }
5263             if ( phy.getNumberOfExternalNodes() != 3 ) {
5264                 return false;
5265             }
5266             if ( !phy.getName().equals( "" ) ) {
5267                 return false;
5268             }
5269             if ( phy.isRooted() ) {
5270                 return false;
5271             }
5272         }
5273         catch ( final Exception e ) {
5274             e.printStackTrace( System.out );
5275             return false;
5276         }
5277         return true;
5278     }
5279
5280     private static boolean testNexusTreeParsingTranslating() {
5281         try {
5282             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5283             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5284             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
5285             if ( phylogenies.length != 1 ) {
5286                 return false;
5287             }
5288             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5289                 return false;
5290             }
5291             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5292                 return false;
5293             }
5294             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5295                 return false;
5296             }
5297             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5298                 return false;
5299             }
5300             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5301                     .equals( "Aranaeus" ) ) {
5302                 return false;
5303             }
5304             phylogenies = null;
5305             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
5306             if ( phylogenies.length != 3 ) {
5307                 return false;
5308             }
5309             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5310                 return false;
5311             }
5312             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5313                 return false;
5314             }
5315             if ( phylogenies[ 0 ].isRooted() ) {
5316                 return false;
5317             }
5318             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5319                 return false;
5320             }
5321             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5322                 return false;
5323             }
5324             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5325                     .equals( "Aranaeus" ) ) {
5326                 return false;
5327             }
5328             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5329                 return false;
5330             }
5331             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5332                 return false;
5333             }
5334             if ( phylogenies[ 1 ].isRooted() ) {
5335                 return false;
5336             }
5337             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5338                 return false;
5339             }
5340             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5341                 return false;
5342             }
5343             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5344                     .equals( "Aranaeus" ) ) {
5345                 return false;
5346             }
5347             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5348                 return false;
5349             }
5350             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5351                 return false;
5352             }
5353             if ( !phylogenies[ 2 ].isRooted() ) {
5354                 return false;
5355             }
5356             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5357                 return false;
5358             }
5359             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5360                 return false;
5361             }
5362             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5363                     .equals( "Aranaeus" ) ) {
5364                 return false;
5365             }
5366             phylogenies = null;
5367             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
5368             if ( phylogenies.length != 3 ) {
5369                 return false;
5370             }
5371             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5372                 return false;
5373             }
5374             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5375                 return false;
5376             }
5377             if ( phylogenies[ 0 ].isRooted() ) {
5378                 return false;
5379             }
5380             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5381                 return false;
5382             }
5383             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5384                 return false;
5385             }
5386             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5387                     .equals( "Aranaeus" ) ) {
5388                 return false;
5389             }
5390             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5391                 return false;
5392             }
5393             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5394                 return false;
5395             }
5396             if ( phylogenies[ 1 ].isRooted() ) {
5397                 return false;
5398             }
5399             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5400                 return false;
5401             }
5402             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5403                 return false;
5404             }
5405             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5406                     .equals( "Aranaeus" ) ) {
5407                 return false;
5408             }
5409             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5410                 return false;
5411             }
5412             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5413                 return false;
5414             }
5415             if ( !phylogenies[ 2 ].isRooted() ) {
5416                 return false;
5417             }
5418             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5419                 return false;
5420             }
5421             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5422                 return false;
5423             }
5424             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5425                     .equals( "Aranaeus" ) ) {
5426                 return false;
5427             }
5428         }
5429         catch ( final Exception e ) {
5430             e.printStackTrace( System.out );
5431             return false;
5432         }
5433         return true;
5434     }
5435
5436     private static boolean testNHParsing() {
5437         try {
5438             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5439             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
5440             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
5441                 return false;
5442             }
5443             final NHXParser nhxp = new NHXParser();
5444             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
5445             nhxp.setReplaceUnderscores( true );
5446             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
5447             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
5448                 return false;
5449             }
5450             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
5451                 return false;
5452             }
5453             final Phylogeny p1b = factory
5454                     .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 ",
5455                              new NHXParser() )[ 0 ];
5456             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
5457                 return false;
5458             }
5459             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
5460                 return false;
5461             }
5462             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
5463             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
5464             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
5465             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
5466             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
5467             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
5468             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
5469             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
5470             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
5471             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
5472             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
5473                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
5474                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
5475                                                     new NHXParser() );
5476             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
5477                 return false;
5478             }
5479             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
5480                 return false;
5481             }
5482             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
5483                 return false;
5484             }
5485             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
5486                 return false;
5487             }
5488             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
5489             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
5490             final String p16_S = "((A,B),C)";
5491             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
5492             if ( p16.length != 1 ) {
5493                 return false;
5494             }
5495             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
5496                 return false;
5497             }
5498             final String p17_S = "(C,(A,B))";
5499             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
5500             if ( p17.length != 1 ) {
5501                 return false;
5502             }
5503             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
5504                 return false;
5505             }
5506             final String p18_S = "((A,B),(C,D))";
5507             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
5508             if ( p18.length != 1 ) {
5509                 return false;
5510             }
5511             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
5512                 return false;
5513             }
5514             final String p19_S = "(((A,B),C),D)";
5515             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
5516             if ( p19.length != 1 ) {
5517                 return false;
5518             }
5519             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
5520                 return false;
5521             }
5522             final String p20_S = "(A,(B,(C,D)))";
5523             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
5524             if ( p20.length != 1 ) {
5525                 return false;
5526             }
5527             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
5528                 return false;
5529             }
5530             final String p21_S = "(A,(B,(C,(D,E))))";
5531             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
5532             if ( p21.length != 1 ) {
5533                 return false;
5534             }
5535             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
5536                 return false;
5537             }
5538             final String p22_S = "((((A,B),C),D),E)";
5539             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
5540             if ( p22.length != 1 ) {
5541                 return false;
5542             }
5543             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
5544                 return false;
5545             }
5546             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5547             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
5548             if ( p23.length != 1 ) {
5549                 System.out.println( "xl=" + p23.length );
5550                 System.exit( -1 );
5551                 return false;
5552             }
5553             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
5554                 return false;
5555             }
5556             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5557             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
5558             if ( p24.length != 1 ) {
5559                 return false;
5560             }
5561             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
5562                 return false;
5563             }
5564             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5565             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5566             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
5567             if ( p241.length != 2 ) {
5568                 return false;
5569             }
5570             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
5571                 return false;
5572             }
5573             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
5574                 return false;
5575             }
5576             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
5577                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
5578                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
5579                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
5580                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
5581                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
5582                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
5583                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
5584             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
5585             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
5586                 return false;
5587             }
5588             final String p26_S = "(A,B)ab";
5589             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
5590             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
5591                 return false;
5592             }
5593             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5594             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
5595             if ( p27s.length != 1 ) {
5596                 System.out.println( "xxl=" + p27s.length );
5597                 System.exit( -1 );
5598                 return false;
5599             }
5600             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5601                 System.out.println( p27s[ 0 ].toNewHampshireX() );
5602                 System.exit( -1 );
5603                 return false;
5604             }
5605             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
5606                                                     new NHXParser() );
5607             if ( p27.length != 1 ) {
5608                 System.out.println( "yl=" + p27.length );
5609                 System.exit( -1 );
5610                 return false;
5611             }
5612             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5613                 System.out.println( p27[ 0 ].toNewHampshireX() );
5614                 System.exit( -1 );
5615                 return false;
5616             }
5617             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5618             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5619             final String p28_S3 = "(A,B)ab";
5620             final String p28_S4 = "((((A,B),C),D),;E;)";
5621             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
5622                                                     new NHXParser() );
5623             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
5624                 return false;
5625             }
5626             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
5627                 return false;
5628             }
5629             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
5630                 return false;
5631             }
5632             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
5633                 return false;
5634             }
5635             if ( p28.length != 4 ) {
5636                 return false;
5637             }
5638             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";
5639             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
5640             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
5641                 return false;
5642             }
5643             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";
5644             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
5645             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
5646                 return false;
5647             }
5648             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
5649             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
5650             if ( ( p32.length != 0 ) ) {
5651                 return false;
5652             }
5653             final String p33_S = "A";
5654             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
5655             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
5656                 return false;
5657             }
5658             final String p34_S = "B;";
5659             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
5660             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
5661                 return false;
5662             }
5663             final String p35_S = "B:0.2";
5664             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
5665             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
5666                 return false;
5667             }
5668             final String p36_S = "(A)";
5669             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
5670             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
5671                 return false;
5672             }
5673             final String p37_S = "((A))";
5674             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
5675             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
5676                 return false;
5677             }
5678             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5679             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
5680             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
5681                 return false;
5682             }
5683             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5684             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
5685             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
5686                 return false;
5687             }
5688             final String p40_S = "(A,B,C)";
5689             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
5690             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
5691                 return false;
5692             }
5693             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
5694             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
5695             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
5696                 return false;
5697             }
5698             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
5699             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
5700             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
5701                 return false;
5702             }
5703             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)";
5704             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
5705             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
5706                 return false;
5707             }
5708             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)))";
5709             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
5710             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
5711                 return false;
5712             }
5713             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
5714             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
5715             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
5716                 return false;
5717             }
5718             final String p46_S = "";
5719             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
5720             if ( p46.length != 0 ) {
5721                 return false;
5722             }
5723             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
5724             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5725                 return false;
5726             }
5727             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5728             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5729                 return false;
5730             }
5731             final Phylogeny p49 = factory
5732                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
5733                              new NHXParser() )[ 0 ];
5734             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5735                 return false;
5736             }
5737             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5738             if ( p50.getNode( "A" ) == null ) {
5739                 return false;
5740             }
5741             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5742                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
5743                 return false;
5744             }
5745             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
5746                 return false;
5747             }
5748             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
5749                     .equals( "((A,B)88:2.0,C);" ) ) {
5750                 return false;
5751             }
5752             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5753             if ( p51.getNode( "A(A" ) == null ) {
5754                 return false;
5755             }
5756             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5757             if ( p52.getNode( "A(A" ) == null ) {
5758                 return false;
5759             }
5760             final Phylogeny p53 = factory
5761                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
5762                              new NHXParser() )[ 0 ];
5763             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
5764                 return false;
5765             }
5766             // 
5767             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
5768             if ( p54.getNode( "A" ) == null ) {
5769                 return false;
5770             }
5771             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5772                     .equals( "((A,B)[88],C);" ) ) {
5773                 return false;
5774             }
5775         }
5776         catch ( final Exception e ) {
5777             e.printStackTrace( System.out );
5778             return false;
5779         }
5780         return true;
5781     }
5782
5783     private static boolean testNHParsingIter() {
5784         try {
5785             final String p0_str = "(A,B);";
5786             final NHXParser p = new NHXParser();
5787             p.setSource( p0_str );
5788             if ( !p.hasNext() ) {
5789                 return false;
5790             }
5791             final Phylogeny p0 = p.next();
5792             if ( !p0.toNewHampshire().equals( p0_str ) ) {
5793                 System.out.println( p0.toNewHampshire() );
5794                 return false;
5795             }
5796             if ( p.hasNext() ) {
5797                 return false;
5798             }
5799             if ( p.next() != null ) {
5800                 return false;
5801             }
5802             //
5803             final String p00_str = "(A,B)root;";
5804             p.setSource( p00_str );
5805             final Phylogeny p00 = p.next();
5806             if ( !p00.toNewHampshire().equals( p00_str ) ) {
5807                 System.out.println( p00.toNewHampshire() );
5808                 return false;
5809             }
5810             //
5811             final String p000_str = "A;";
5812             p.setSource( p000_str );
5813             final Phylogeny p000 = p.next();
5814             if ( !p000.toNewHampshire().equals( p000_str ) ) {
5815                 System.out.println( p000.toNewHampshire() );
5816                 return false;
5817             }
5818             //
5819             final String p0000_str = "A";
5820             p.setSource( p0000_str );
5821             final Phylogeny p0000 = p.next();
5822             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
5823                 System.out.println( p0000.toNewHampshire() );
5824                 return false;
5825             }
5826             //
5827             p.setSource( "(A)" );
5828             final Phylogeny p00000 = p.next();
5829             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
5830                 System.out.println( p00000.toNewHampshire() );
5831                 return false;
5832             }
5833             //
5834             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
5835             p.setSource( p1_str );
5836             if ( !p.hasNext() ) {
5837                 return false;
5838             }
5839             final Phylogeny p1_0 = p.next();
5840             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
5841                 System.out.println( p1_0.toNewHampshire() );
5842                 return false;
5843             }
5844             if ( !p.hasNext() ) {
5845                 return false;
5846             }
5847             final Phylogeny p1_1 = p.next();
5848             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
5849                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
5850                 return false;
5851             }
5852             if ( !p.hasNext() ) {
5853                 return false;
5854             }
5855             final Phylogeny p1_2 = p.next();
5856             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
5857                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
5858                 return false;
5859             }
5860             if ( !p.hasNext() ) {
5861                 return false;
5862             }
5863             final Phylogeny p1_3 = p.next();
5864             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
5865                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
5866                 return false;
5867             }
5868             if ( p.hasNext() ) {
5869                 return false;
5870             }
5871             if ( p.next() != null ) {
5872                 return false;
5873             }
5874             //
5875             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
5876             p.setSource( p2_str );
5877             if ( !p.hasNext() ) {
5878                 return false;
5879             }
5880             Phylogeny p2_0 = p.next();
5881             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5882                 System.out.println( p2_0.toNewHampshire() );
5883                 return false;
5884             }
5885             if ( !p.hasNext() ) {
5886                 return false;
5887             }
5888             Phylogeny p2_1 = p.next();
5889             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5890                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5891                 return false;
5892             }
5893             if ( !p.hasNext() ) {
5894                 return false;
5895             }
5896             Phylogeny p2_2 = p.next();
5897             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5898                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5899                 return false;
5900             }
5901             if ( !p.hasNext() ) {
5902                 return false;
5903             }
5904             Phylogeny p2_3 = p.next();
5905             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5906                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5907                 return false;
5908             }
5909             if ( !p.hasNext() ) {
5910                 return false;
5911             }
5912             Phylogeny p2_4 = p.next();
5913             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5914                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5915                 return false;
5916             }
5917             if ( p.hasNext() ) {
5918                 return false;
5919             }
5920             if ( p.next() != null ) {
5921                 return false;
5922             }
5923             ////
5924             p.reset();
5925             if ( !p.hasNext() ) {
5926                 return false;
5927             }
5928             p2_0 = p.next();
5929             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5930                 System.out.println( p2_0.toNewHampshire() );
5931                 return false;
5932             }
5933             if ( !p.hasNext() ) {
5934                 return false;
5935             }
5936             p2_1 = p.next();
5937             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5938                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5939                 return false;
5940             }
5941             if ( !p.hasNext() ) {
5942                 return false;
5943             }
5944             p2_2 = p.next();
5945             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5946                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5947                 return false;
5948             }
5949             if ( !p.hasNext() ) {
5950                 return false;
5951             }
5952             p2_3 = p.next();
5953             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5954                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5955                 return false;
5956             }
5957             if ( !p.hasNext() ) {
5958                 return false;
5959             }
5960             p2_4 = p.next();
5961             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5962                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5963                 return false;
5964             }
5965             if ( p.hasNext() ) {
5966                 return false;
5967             }
5968             if ( p.next() != null ) {
5969                 return false;
5970             }
5971             //
5972             final String p3_str = "((A,B),C)abc";
5973             p.setSource( p3_str );
5974             if ( !p.hasNext() ) {
5975                 return false;
5976             }
5977             final Phylogeny p3_0 = p.next();
5978             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
5979                 return false;
5980             }
5981             if ( p.hasNext() ) {
5982                 return false;
5983             }
5984             if ( p.next() != null ) {
5985                 return false;
5986             }
5987             //
5988             final String p4_str = "((A,B)ab,C)abc";
5989             p.setSource( p4_str );
5990             if ( !p.hasNext() ) {
5991                 return false;
5992             }
5993             final Phylogeny p4_0 = p.next();
5994             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
5995                 return false;
5996             }
5997             if ( p.hasNext() ) {
5998                 return false;
5999             }
6000             if ( p.next() != null ) {
6001                 return false;
6002             }
6003             //
6004             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
6005             p.setSource( p5_str );
6006             if ( !p.hasNext() ) {
6007                 return false;
6008             }
6009             final Phylogeny p5_0 = p.next();
6010             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
6011                 return false;
6012             }
6013             if ( p.hasNext() ) {
6014                 return false;
6015             }
6016             if ( p.next() != null ) {
6017                 return false;
6018             }
6019             //
6020             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6021             p.setSource( p6_str );
6022             if ( !p.hasNext() ) {
6023                 return false;
6024             }
6025             Phylogeny p6_0 = p.next();
6026             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6027                 return false;
6028             }
6029             if ( p.hasNext() ) {
6030                 return false;
6031             }
6032             if ( p.next() != null ) {
6033                 return false;
6034             }
6035             p.reset();
6036             if ( !p.hasNext() ) {
6037                 return false;
6038             }
6039             p6_0 = p.next();
6040             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6041                 return false;
6042             }
6043             if ( p.hasNext() ) {
6044                 return false;
6045             }
6046             if ( p.next() != null ) {
6047                 return false;
6048             }
6049             //
6050             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6051             p.setSource( p7_str );
6052             if ( !p.hasNext() ) {
6053                 return false;
6054             }
6055             Phylogeny p7_0 = p.next();
6056             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6057                 return false;
6058             }
6059             if ( p.hasNext() ) {
6060                 return false;
6061             }
6062             if ( p.next() != null ) {
6063                 return false;
6064             }
6065             p.reset();
6066             if ( !p.hasNext() ) {
6067                 return false;
6068             }
6069             p7_0 = p.next();
6070             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6071                 return false;
6072             }
6073             if ( p.hasNext() ) {
6074                 return false;
6075             }
6076             if ( p.next() != null ) {
6077                 return false;
6078             }
6079             //
6080             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
6081             p.setSource( p8_str );
6082             if ( !p.hasNext() ) {
6083                 return false;
6084             }
6085             Phylogeny p8_0 = p.next();
6086             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6087                 return false;
6088             }
6089             if ( !p.hasNext() ) {
6090                 return false;
6091             }
6092             if ( !p.hasNext() ) {
6093                 return false;
6094             }
6095             Phylogeny p8_1 = p.next();
6096             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6097                 return false;
6098             }
6099             if ( p.hasNext() ) {
6100                 return false;
6101             }
6102             if ( p.next() != null ) {
6103                 return false;
6104             }
6105             p.reset();
6106             if ( !p.hasNext() ) {
6107                 return false;
6108             }
6109             p8_0 = p.next();
6110             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6111                 return false;
6112             }
6113             if ( !p.hasNext() ) {
6114                 return false;
6115             }
6116             p8_1 = p.next();
6117             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6118                 return false;
6119             }
6120             if ( p.hasNext() ) {
6121                 return false;
6122             }
6123             if ( p.next() != null ) {
6124                 return false;
6125             }
6126             p.reset();
6127             //
6128             p.setSource( "" );
6129             if ( p.hasNext() ) {
6130                 return false;
6131             }
6132             //
6133             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
6134             if ( !p.hasNext() ) {
6135                 return false;
6136             }
6137             Phylogeny p_27 = p.next();
6138             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6139                 System.out.println( p_27.toNewHampshireX() );
6140                 System.exit( -1 );
6141                 return false;
6142             }
6143             if ( p.hasNext() ) {
6144                 return false;
6145             }
6146             if ( p.next() != null ) {
6147                 return false;
6148             }
6149             p.reset();
6150             if ( !p.hasNext() ) {
6151                 return false;
6152             }
6153             p_27 = p.next();
6154             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6155                 System.out.println( p_27.toNewHampshireX() );
6156                 System.exit( -1 );
6157                 return false;
6158             }
6159             if ( p.hasNext() ) {
6160                 return false;
6161             }
6162             if ( p.next() != null ) {
6163                 return false;
6164             }
6165         }
6166         catch ( final Exception e ) {
6167             e.printStackTrace( System.out );
6168             return false;
6169         }
6170         return true;
6171     }
6172
6173     private static boolean testNHXconversion() {
6174         try {
6175             final PhylogenyNode n1 = new PhylogenyNode();
6176             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6177             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6178             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6179             final PhylogenyNode n5 = PhylogenyNode
6180                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
6181             final PhylogenyNode n6 = PhylogenyNode
6182                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
6183             if ( !n1.toNewHampshireX().equals( "" ) ) {
6184                 return false;
6185             }
6186             if ( !n2.toNewHampshireX().equals( "" ) ) {
6187                 return false;
6188             }
6189             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
6190                 return false;
6191             }
6192             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
6193                 return false;
6194             }
6195             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
6196                 return false;
6197             }
6198             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
6199                 System.out.println( n6.toNewHampshireX() );
6200                 return false;
6201             }
6202         }
6203         catch ( final Exception e ) {
6204             e.printStackTrace( System.out );
6205             return false;
6206         }
6207         return true;
6208     }
6209
6210     private static boolean testTaxonomyExtraction() {
6211         try {
6212             final PhylogenyNode n0 = PhylogenyNode
6213                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6214             if ( n0.getNodeData().isHasTaxonomy() ) {
6215                 return false;
6216             }
6217             final PhylogenyNode n1 = PhylogenyNode
6218                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6219             if ( n1.getNodeData().isHasTaxonomy() ) {
6220                 System.out.println( n1.toString() );
6221                 return false;
6222             }
6223             final PhylogenyNode n2 = PhylogenyNode
6224                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE );
6225             if ( !n2.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6226                 System.out.println( n2.toString() );
6227                 return false;
6228             }
6229             final PhylogenyNode n2x = PhylogenyNode
6230                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6231             if ( n2x.getNodeData().isHasTaxonomy() ) {
6232                 return false;
6233             }
6234             final PhylogenyNode n3 = PhylogenyNode
6235                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6236             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6237                 System.out.println( n3.toString() );
6238                 return false;
6239             }
6240             final PhylogenyNode n4 = PhylogenyNode
6241                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6242             if ( n4.getNodeData().isHasTaxonomy() ) {
6243                 System.out.println( n4.toString() );
6244                 return false;
6245             }
6246             final PhylogenyNode n5 = PhylogenyNode
6247                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6248             if ( n5.getNodeData().isHasTaxonomy() ) {
6249                 System.out.println( n5.toString() );
6250                 return false;
6251             }
6252             final PhylogenyNode n6 = PhylogenyNode
6253                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6254             if ( n6.getNodeData().isHasTaxonomy() ) {
6255                 System.out.println( n6.toString() );
6256                 return false;
6257             }
6258             final PhylogenyNode n7 = PhylogenyNode
6259                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6260             if ( n7.getNodeData().isHasTaxonomy() ) {
6261                 System.out.println( n7.toString() );
6262                 return false;
6263             }
6264             final PhylogenyNode n8 = PhylogenyNode
6265                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6266             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6267                 System.out.println( n8.toString() );
6268                 return false;
6269             }
6270             final PhylogenyNode n9 = PhylogenyNode
6271                     .createInstanceFromNhxString( "blag_12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6272             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6273                 System.out.println( n9.toString() );
6274                 return false;
6275             }
6276             final PhylogenyNode n10x = PhylogenyNode
6277                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6278             if ( n10x.getNodeData().isHasTaxonomy() ) {
6279                 System.out.println( n10x.toString() );
6280                 return false;
6281             }
6282             final PhylogenyNode n10xx = PhylogenyNode
6283                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6284             if ( n10xx.getNodeData().isHasTaxonomy() ) {
6285                 System.out.println( n10xx.toString() );
6286                 return false;
6287             }
6288             final PhylogenyNode n10 = PhylogenyNode
6289                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6290             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
6291                 System.out.println( n10.toString() );
6292                 return false;
6293             }
6294             final PhylogenyNode n11 = PhylogenyNode
6295                     .createInstanceFromNhxString( "blag_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6296             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
6297                 System.out.println( n11.toString() );
6298                 return false;
6299             }
6300             final PhylogenyNode n12 = PhylogenyNode
6301                     .createInstanceFromNhxString( "blag_Mus_musculus_musculus",
6302                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6303             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
6304                 System.out.println( n12.toString() );
6305                 return false;
6306             }
6307             final PhylogenyNode n13 = PhylogenyNode
6308                     .createInstanceFromNhxString( "blag_Mus_musculus1",
6309                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6310             if ( n13.getNodeData().isHasTaxonomy() ) {
6311                 System.out.println( n13.toString() );
6312                 return false;
6313             }
6314             final PhylogenyNode n14 = PhylogenyNode
6315                     .createInstanceFromNhxString( "blag_Mus_musculus_11",
6316                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6317             if ( n14.getNodeData().isHasTaxonomy() ) {
6318                 System.out.println( n14.toString() );
6319                 return false;
6320             }
6321             final PhylogenyNode n15 = PhylogenyNode
6322                     .createInstanceFromNhxString( "blag_Mus_musculus_v11",
6323                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6324             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus v11" ) ) {
6325                 System.out.println( n15.toString() );
6326                 return false;
6327             }
6328             final PhylogenyNode n16 = PhylogenyNode
6329                     .createInstanceFromNhxString( "blag_Mus_musculus_/11",
6330                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6331             if ( n16.getNodeData().isHasTaxonomy() ) {
6332                 System.out.println( n16.toString() );
6333                 return false;
6334             }
6335             final PhylogenyNode n17 = PhylogenyNode
6336                     .createInstanceFromNhxString( "blag_Mus_musculus_v",
6337                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6338             if ( n17.getNodeData().isHasTaxonomy() ) {
6339                 System.out.println( n17.toString() );
6340                 return false;
6341             }
6342         }
6343         catch ( final Exception e ) {
6344             e.printStackTrace( System.out );
6345             return false;
6346         }
6347         return true;
6348     }
6349
6350     private static boolean testNHXNodeParsing() {
6351         try {
6352             final PhylogenyNode n1 = new PhylogenyNode();
6353             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6354             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6355             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6356             final PhylogenyNode n5 = PhylogenyNode
6357                     .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]" );
6358             if ( !n3.getName().equals( "n3" ) ) {
6359                 return false;
6360             }
6361             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6362                 return false;
6363             }
6364             if ( n3.isDuplication() ) {
6365                 return false;
6366             }
6367             if ( n3.isHasAssignedEvent() ) {
6368                 return false;
6369             }
6370             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
6371                 return false;
6372             }
6373             if ( !n4.getName().equals( "n4" ) ) {
6374                 return false;
6375             }
6376             if ( n4.getDistanceToParent() != 0.01 ) {
6377                 return false;
6378             }
6379             if ( !n5.getName().equals( "n5" ) ) {
6380                 return false;
6381             }
6382             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
6383                 return false;
6384             }
6385             if ( n5.getDistanceToParent() != 0.1 ) {
6386                 return false;
6387             }
6388             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
6389                 return false;
6390             }
6391             if ( !n5.isDuplication() ) {
6392                 return false;
6393             }
6394             if ( !n5.isHasAssignedEvent() ) {
6395                 return false;
6396             }
6397             final PhylogenyNode n8 = PhylogenyNode
6398                     .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6399             if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
6400                 return false;
6401             }
6402             if ( PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
6403                 return false;
6404             }
6405             final PhylogenyNode n9 = PhylogenyNode
6406                     .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01",
6407                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6408             if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
6409                 return false;
6410             }
6411             if ( PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
6412                 return false;
6413             }
6414             final PhylogenyNode n10 = PhylogenyNode
6415                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6416             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
6417                 return false;
6418             }
6419             final PhylogenyNode n20 = PhylogenyNode
6420                     .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6421             if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
6422                 return false;
6423             }
6424             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
6425                 return false;
6426             }
6427             final PhylogenyNode n20x = PhylogenyNode
6428                     .createInstanceFromNhxString( "n20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6429             if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
6430                 return false;
6431             }
6432             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
6433                 return false;
6434             }
6435             final PhylogenyNode n20xx = PhylogenyNode
6436                     .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6437             if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
6438                 return false;
6439             }
6440             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
6441                 return false;
6442             }
6443             final PhylogenyNode n20xxx = PhylogenyNode
6444                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6445             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
6446                 return false;
6447             }
6448             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
6449                 return false;
6450             }
6451             final PhylogenyNode n20xxxx = PhylogenyNode
6452                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6453             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
6454                 return false;
6455             }
6456             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
6457                 return false;
6458             }
6459             final PhylogenyNode n21 = PhylogenyNode
6460                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6461             if ( !n21.getName().equals( "n21_PIG" ) ) {
6462                 return false;
6463             }
6464             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
6465                 return false;
6466             }
6467             final PhylogenyNode n21x = PhylogenyNode
6468                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6469             if ( !n21x.getName().equals( "n21_PIG" ) ) {
6470                 return false;
6471             }
6472             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
6473                 return false;
6474             }
6475             final PhylogenyNode n22 = PhylogenyNode
6476                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6477             if ( !n22.getName().equals( "n22/PIG" ) ) {
6478                 return false;
6479             }
6480             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
6481                 return false;
6482             }
6483             final PhylogenyNode n23 = PhylogenyNode
6484                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6485             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
6486                 return false;
6487             }
6488             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
6489                 return false;
6490             }
6491             final PhylogenyNode a = PhylogenyNode
6492                     .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6493             if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
6494                 return false;
6495             }
6496             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
6497                 return false;
6498             }
6499             final PhylogenyNode b = PhylogenyNode
6500                     .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6501             if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
6502                 return false;
6503             }
6504             if ( PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
6505                 return false;
6506             }
6507             final PhylogenyNode c = PhylogenyNode
6508                     .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
6509                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6510             if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
6511                 return false;
6512             }
6513             if ( PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
6514                 return false;
6515             }
6516             final PhylogenyNode c1 = PhylogenyNode
6517                     .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
6518                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6519             if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
6520                 return false;
6521             }
6522             if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
6523                 return false;
6524             }
6525             final PhylogenyNode c2 = PhylogenyNode
6526                     .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
6527                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6528             if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
6529                 return false;
6530             }
6531             if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
6532                 return false;
6533             }
6534             final PhylogenyNode d = PhylogenyNode
6535                     .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6536             if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
6537                 return false;
6538             }
6539             if ( PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
6540                 return false;
6541             }
6542             final PhylogenyNode e = PhylogenyNode
6543                     .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6544             if ( !e.getName().equals( "n10_RAT1" ) ) {
6545                 return false;
6546             }
6547             if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
6548                 return false;
6549             }
6550             final PhylogenyNode e2 = PhylogenyNode
6551                     .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6552             if ( !e2.getName().equals( "n10_RAT1" ) ) {
6553                 return false;
6554             }
6555             if ( PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
6556                 return false;
6557             }
6558             final PhylogenyNode e3 = PhylogenyNode
6559                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6560             if ( !e3.getName().equals( "n10_RAT~" ) ) {
6561                 return false;
6562             }
6563             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
6564                 return false;
6565             }
6566             final PhylogenyNode n11 = PhylogenyNode
6567                     .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
6568                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6569             if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
6570                 return false;
6571             }
6572             if ( n11.getDistanceToParent() != 0.4 ) {
6573                 return false;
6574             }
6575             if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
6576                 return false;
6577             }
6578             final PhylogenyNode n12 = PhylogenyNode
6579                     .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
6580                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6581             if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
6582                 return false;
6583             }
6584             if ( n12.getDistanceToParent() != 0.4 ) {
6585                 return false;
6586             }
6587             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
6588                 return false;
6589             }
6590             final PhylogenyNode m = PhylogenyNode
6591                     .createInstanceFromNhxString( "n10_MOUSEa", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6592             if ( !m.getName().equals( "n10_MOUSEa" ) ) {
6593                 return false;
6594             }
6595             if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
6596                 return false;
6597             }
6598             final PhylogenyNode o = PhylogenyNode
6599                     .createInstanceFromNhxString( "n10_MOUSE_", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6600             if ( !o.getName().equals( "n10_MOUSE_" ) ) {
6601                 return false;
6602             }
6603             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
6604                 return false;
6605             }
6606             if ( n1.getName().compareTo( "" ) != 0 ) {
6607                 return false;
6608             }
6609             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6610                 return false;
6611             }
6612             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6613                 return false;
6614             }
6615             if ( n2.getName().compareTo( "" ) != 0 ) {
6616                 return false;
6617             }
6618             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6619                 return false;
6620             }
6621             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6622                 return false;
6623             }
6624             final PhylogenyNode n00 = PhylogenyNode
6625                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
6626             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
6627                 return false;
6628             }
6629             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
6630                 return false;
6631             }
6632             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
6633             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
6634                 return false;
6635             }
6636             final PhylogenyNode n13 = PhylogenyNode
6637                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE );
6638             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
6639                 return false;
6640             }
6641             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
6642                 return false;
6643             }
6644             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6645                 return false;
6646             }
6647             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6648                 return false;
6649             }
6650             final PhylogenyNode n14 = PhylogenyNode
6651                     .createInstanceFromNhxString( "blah_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6652             if ( !n14.getName().equals( "blah_9QX45/1-2" ) ) {
6653                 return false;
6654             }
6655             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
6656                 return false;
6657             }
6658             final PhylogenyNode n15 = PhylogenyNode
6659                     .createInstanceFromNhxString( "something_wicked[123]",
6660                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6661             if ( !n15.getName().equals( "something_wicked" ) ) {
6662                 return false;
6663             }
6664             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
6665                 return false;
6666             }
6667             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
6668                 return false;
6669             }
6670             final PhylogenyNode n16 = PhylogenyNode
6671                     .createInstanceFromNhxString( "something_wicked2[9]",
6672                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6673             if ( !n16.getName().equals( "something_wicked2" ) ) {
6674                 return false;
6675             }
6676             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
6677                 return false;
6678             }
6679             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
6680                 return false;
6681             }
6682             final PhylogenyNode n17 = PhylogenyNode
6683                     .createInstanceFromNhxString( "something_wicked3[a]",
6684                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6685             if ( !n17.getName().equals( "something_wicked3" ) ) {
6686                 return false;
6687             }
6688             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
6689                 return false;
6690             }
6691             final PhylogenyNode n18 = PhylogenyNode
6692                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6693             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
6694                 return false;
6695             }
6696             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
6697                 return false;
6698             }
6699             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
6700                 return false;
6701             }
6702             final PhylogenyNode n19 = PhylogenyNode
6703                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6704             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
6705                 return false;
6706             }
6707             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6708                 return false;
6709             }
6710             final PhylogenyNode n30 = PhylogenyNode
6711                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
6712                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6713             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
6714                 return false;
6715             }
6716             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6717                 return false;
6718             }
6719             final PhylogenyNode n31 = PhylogenyNode
6720                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
6721                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6722             if ( n31.getNodeData().isHasTaxonomy() ) {
6723                 return false;
6724             }
6725             final PhylogenyNode n32 = PhylogenyNode
6726                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6727             if ( n32.getNodeData().isHasTaxonomy() ) {
6728                 return false;
6729             }
6730         }
6731         catch ( final Exception e ) {
6732             e.printStackTrace( System.out );
6733             return false;
6734         }
6735         return true;
6736     }
6737
6738     private static boolean testNHXParsing() {
6739         try {
6740             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6741             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
6742             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
6743                 return false;
6744             }
6745             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]";
6746             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
6747             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6748                 return false;
6749             }
6750             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]";
6751             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
6752             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
6753                 return false;
6754             }
6755             final Phylogeny[] p3 = factory
6756                     .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]",
6757                              new NHXParser() );
6758             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6759                 return false;
6760             }
6761             final Phylogeny[] p4 = factory
6762                     .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(]",
6763                              new NHXParser() );
6764             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6765                 return false;
6766             }
6767             final Phylogeny[] p5 = factory
6768                     .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(((]",
6769                              new NHXParser() );
6770             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6771                 return false;
6772             }
6773             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)";
6774             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)";
6775             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
6776             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
6777                 return false;
6778             }
6779             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)))";
6780             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)))";
6781             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
6782             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
6783                 return false;
6784             }
6785             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])   ))[,,, ])))))))";
6786             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
6787             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
6788             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
6789                 return false;
6790             }
6791             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
6792             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6793                 return false;
6794             }
6795             final Phylogeny p10 = factory
6796                     .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]",
6797                              new NHXParser() )[ 0 ];
6798             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6799                 return false;
6800             }
6801         }
6802         catch ( final Exception e ) {
6803             e.printStackTrace( System.out );
6804             return false;
6805         }
6806         return true;
6807     }
6808
6809     private static boolean testNHXParsingQuotes() {
6810         try {
6811             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6812             final NHXParser p = new NHXParser();
6813             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
6814             if ( phylogenies_0.length != 5 ) {
6815                 return false;
6816             }
6817             final Phylogeny phy = phylogenies_0[ 4 ];
6818             if ( phy.getNumberOfExternalNodes() != 7 ) {
6819                 return false;
6820             }
6821             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
6822                 return false;
6823             }
6824             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
6825                 return false;
6826             }
6827             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
6828                     .getScientificName().equals( "hsapiens" ) ) {
6829                 return false;
6830             }
6831             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
6832                 return false;
6833             }
6834             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
6835                 return false;
6836             }
6837             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
6838                 return false;
6839             }
6840             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
6841                 return false;
6842             }
6843             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
6844                 return false;
6845             }
6846             final NHXParser p1p = new NHXParser();
6847             p1p.setIgnoreQuotes( true );
6848             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
6849             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
6850                 return false;
6851             }
6852             final NHXParser p2p = new NHXParser();
6853             p1p.setIgnoreQuotes( false );
6854             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
6855             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
6856                 return false;
6857             }
6858             final NHXParser p3p = new NHXParser();
6859             p3p.setIgnoreQuotes( false );
6860             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
6861             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
6862                 return false;
6863             }
6864             final NHXParser p4p = new NHXParser();
6865             p4p.setIgnoreQuotes( false );
6866             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
6867             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
6868                 return false;
6869             }
6870             final Phylogeny p10 = factory
6871                     .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]",
6872                              new NHXParser() )[ 0 ];
6873             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]";
6874             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
6875                 return false;
6876             }
6877             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
6878             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
6879                 return false;
6880             }
6881             //
6882             final Phylogeny p12 = factory
6883                     .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]",
6884                              new NHXParser() )[ 0 ];
6885             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]";
6886             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
6887                 return false;
6888             }
6889             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
6890             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
6891                 return false;
6892             }
6893             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;";
6894             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
6895                 return false;
6896             }
6897             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
6898             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
6899                 return false;
6900             }
6901         }
6902         catch ( final Exception e ) {
6903             e.printStackTrace( System.out );
6904             return false;
6905         }
6906         return true;
6907     }
6908
6909     private static boolean testNHXParsingMB() {
6910         try {
6911             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6912             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
6913                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6914                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6915                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6916                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6917                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6918                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6919                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6920                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
6921             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
6922                 return false;
6923             }
6924             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
6925                 return false;
6926             }
6927             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
6928                            0.1100000000000000e+00 ) ) {
6929                 return false;
6930             }
6931             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
6932                 return false;
6933             }
6934             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
6935                 return false;
6936             }
6937             final Phylogeny p2 = factory
6938                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
6939                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6940                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6941                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6942                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6943                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6944                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6945                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6946                                      + "7.369400000000000e-02}])",
6947                              new NHXParser() )[ 0 ];
6948             if ( p2.getNode( "1" ) == null ) {
6949                 return false;
6950             }
6951             if ( p2.getNode( "2" ) == null ) {
6952                 return false;
6953             }
6954         }
6955         catch ( final Exception e ) {
6956             e.printStackTrace( System.out );
6957             System.exit( -1 );
6958             return false;
6959         }
6960         return true;
6961     }
6962
6963     private static boolean testPhylogenyBranch() {
6964         try {
6965             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
6966             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
6967             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
6968             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
6969             if ( !a1b1.equals( a1b1 ) ) {
6970                 return false;
6971             }
6972             if ( !a1b1.equals( b1a1 ) ) {
6973                 return false;
6974             }
6975             if ( !b1a1.equals( a1b1 ) ) {
6976                 return false;
6977             }
6978             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
6979             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
6980             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
6981             if ( a1_b1.equals( b1_a1 ) ) {
6982                 return false;
6983             }
6984             if ( a1_b1.equals( a1_b1_ ) ) {
6985                 return false;
6986             }
6987             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
6988             if ( !a1_b1.equals( b1_a1_ ) ) {
6989                 return false;
6990             }
6991             if ( a1_b1_.equals( b1_a1_ ) ) {
6992                 return false;
6993             }
6994             if ( !a1_b1_.equals( b1_a1 ) ) {
6995                 return false;
6996             }
6997         }
6998         catch ( final Exception e ) {
6999             e.printStackTrace( System.out );
7000             return false;
7001         }
7002         return true;
7003     }
7004
7005     private static boolean testPhyloXMLparsingOfDistributionElement() {
7006         try {
7007             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7008             PhyloXmlParser xml_parser = null;
7009             try {
7010                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
7011             }
7012             catch ( final Exception e ) {
7013                 // Do nothing -- means were not running from jar.
7014             }
7015             if ( xml_parser == null ) {
7016                 xml_parser = new PhyloXmlParser();
7017                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
7018                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
7019                 }
7020                 else {
7021                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
7022                 }
7023             }
7024             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
7025                                                               xml_parser );
7026             if ( xml_parser.getErrorCount() > 0 ) {
7027                 System.out.println( xml_parser.getErrorMessages().toString() );
7028                 return false;
7029             }
7030             if ( phylogenies_0.length != 1 ) {
7031                 return false;
7032             }
7033             final Phylogeny t1 = phylogenies_0[ 0 ];
7034             PhylogenyNode n = null;
7035             Distribution d = null;
7036             n = t1.getNode( "root node" );
7037             if ( !n.getNodeData().isHasDistribution() ) {
7038                 return false;
7039             }
7040             if ( n.getNodeData().getDistributions().size() != 1 ) {
7041                 return false;
7042             }
7043             d = n.getNodeData().getDistribution();
7044             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7045                 return false;
7046             }
7047             if ( d.getPoints().size() != 1 ) {
7048                 return false;
7049             }
7050             if ( d.getPolygons() != null ) {
7051                 return false;
7052             }
7053             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7054                 return false;
7055             }
7056             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7057                 return false;
7058             }
7059             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7060                 return false;
7061             }
7062             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7063                 return false;
7064             }
7065             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7066                 return false;
7067             }
7068             n = t1.getNode( "node a" );
7069             if ( !n.getNodeData().isHasDistribution() ) {
7070                 return false;
7071             }
7072             if ( n.getNodeData().getDistributions().size() != 2 ) {
7073                 return false;
7074             }
7075             d = n.getNodeData().getDistribution( 1 );
7076             if ( !d.getDesc().equals( "San Diego" ) ) {
7077                 return false;
7078             }
7079             if ( d.getPoints().size() != 1 ) {
7080                 return false;
7081             }
7082             if ( d.getPolygons() != null ) {
7083                 return false;
7084             }
7085             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7086                 return false;
7087             }
7088             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7089                 return false;
7090             }
7091             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7092                 return false;
7093             }
7094             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7095                 return false;
7096             }
7097             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7098                 return false;
7099             }
7100             n = t1.getNode( "node bb" );
7101             if ( !n.getNodeData().isHasDistribution() ) {
7102                 return false;
7103             }
7104             if ( n.getNodeData().getDistributions().size() != 1 ) {
7105                 return false;
7106             }
7107             d = n.getNodeData().getDistribution( 0 );
7108             if ( d.getPoints().size() != 3 ) {
7109                 return false;
7110             }
7111             if ( d.getPolygons().size() != 2 ) {
7112                 return false;
7113             }
7114             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7115                 return false;
7116             }
7117             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7118                 return false;
7119             }
7120             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7121                 return false;
7122             }
7123             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7124                 return false;
7125             }
7126             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7127                 return false;
7128             }
7129             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7130                 return false;
7131             }
7132             Polygon p = d.getPolygons().get( 0 );
7133             if ( p.getPoints().size() != 3 ) {
7134                 return false;
7135             }
7136             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7137                 return false;
7138             }
7139             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7140                 return false;
7141             }
7142             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7143                 return false;
7144             }
7145             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7146                 return false;
7147             }
7148             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7149                 return false;
7150             }
7151             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7152                 return false;
7153             }
7154             p = d.getPolygons().get( 1 );
7155             if ( p.getPoints().size() != 3 ) {
7156                 return false;
7157             }
7158             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7159                 return false;
7160             }
7161             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7162                 return false;
7163             }
7164             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7165                 return false;
7166             }
7167             // Roundtrip:
7168             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
7169             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
7170             if ( rt.length != 1 ) {
7171                 return false;
7172             }
7173             final Phylogeny t1_rt = rt[ 0 ];
7174             n = t1_rt.getNode( "root node" );
7175             if ( !n.getNodeData().isHasDistribution() ) {
7176                 return false;
7177             }
7178             if ( n.getNodeData().getDistributions().size() != 1 ) {
7179                 return false;
7180             }
7181             d = n.getNodeData().getDistribution();
7182             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7183                 return false;
7184             }
7185             if ( d.getPoints().size() != 1 ) {
7186                 return false;
7187             }
7188             if ( d.getPolygons() != null ) {
7189                 return false;
7190             }
7191             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7192                 return false;
7193             }
7194             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7195                 return false;
7196             }
7197             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7198                 return false;
7199             }
7200             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7201                 return false;
7202             }
7203             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7204                 return false;
7205             }
7206             n = t1_rt.getNode( "node a" );
7207             if ( !n.getNodeData().isHasDistribution() ) {
7208                 return false;
7209             }
7210             if ( n.getNodeData().getDistributions().size() != 2 ) {
7211                 return false;
7212             }
7213             d = n.getNodeData().getDistribution( 1 );
7214             if ( !d.getDesc().equals( "San Diego" ) ) {
7215                 return false;
7216             }
7217             if ( d.getPoints().size() != 1 ) {
7218                 return false;
7219             }
7220             if ( d.getPolygons() != null ) {
7221                 return false;
7222             }
7223             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7224                 return false;
7225             }
7226             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7227                 return false;
7228             }
7229             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7230                 return false;
7231             }
7232             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7233                 return false;
7234             }
7235             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7236                 return false;
7237             }
7238             n = t1_rt.getNode( "node bb" );
7239             if ( !n.getNodeData().isHasDistribution() ) {
7240                 return false;
7241             }
7242             if ( n.getNodeData().getDistributions().size() != 1 ) {
7243                 return false;
7244             }
7245             d = n.getNodeData().getDistribution( 0 );
7246             if ( d.getPoints().size() != 3 ) {
7247                 return false;
7248             }
7249             if ( d.getPolygons().size() != 2 ) {
7250                 return false;
7251             }
7252             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7253                 return false;
7254             }
7255             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7256                 return false;
7257             }
7258             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7259                 return false;
7260             }
7261             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7262                 return false;
7263             }
7264             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7265                 return false;
7266             }
7267             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7268                 return false;
7269             }
7270             p = d.getPolygons().get( 0 );
7271             if ( p.getPoints().size() != 3 ) {
7272                 return false;
7273             }
7274             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7275                 return false;
7276             }
7277             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7278                 return false;
7279             }
7280             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7281                 return false;
7282             }
7283             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7284                 return false;
7285             }
7286             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7287                 return false;
7288             }
7289             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7290                 return false;
7291             }
7292             p = d.getPolygons().get( 1 );
7293             if ( p.getPoints().size() != 3 ) {
7294                 return false;
7295             }
7296             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7297                 return false;
7298             }
7299             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7300                 return false;
7301             }
7302             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7303                 return false;
7304             }
7305         }
7306         catch ( final Exception e ) {
7307             e.printStackTrace( System.out );
7308             return false;
7309         }
7310         return true;
7311     }
7312
7313     private static boolean testPostOrderIterator() {
7314         try {
7315             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7316             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7317             PhylogenyNodeIterator it0;
7318             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
7319                 it0.next();
7320             }
7321             for( it0.reset(); it0.hasNext(); ) {
7322                 it0.next();
7323             }
7324             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7325             final PhylogenyNodeIterator it = t1.iteratorPostorder();
7326             if ( !it.next().getName().equals( "A" ) ) {
7327                 return false;
7328             }
7329             if ( !it.next().getName().equals( "B" ) ) {
7330                 return false;
7331             }
7332             if ( !it.next().getName().equals( "ab" ) ) {
7333                 return false;
7334             }
7335             if ( !it.next().getName().equals( "C" ) ) {
7336                 return false;
7337             }
7338             if ( !it.next().getName().equals( "D" ) ) {
7339                 return false;
7340             }
7341             if ( !it.next().getName().equals( "cd" ) ) {
7342                 return false;
7343             }
7344             if ( !it.next().getName().equals( "abcd" ) ) {
7345                 return false;
7346             }
7347             if ( !it.next().getName().equals( "E" ) ) {
7348                 return false;
7349             }
7350             if ( !it.next().getName().equals( "F" ) ) {
7351                 return false;
7352             }
7353             if ( !it.next().getName().equals( "ef" ) ) {
7354                 return false;
7355             }
7356             if ( !it.next().getName().equals( "G" ) ) {
7357                 return false;
7358             }
7359             if ( !it.next().getName().equals( "H" ) ) {
7360                 return false;
7361             }
7362             if ( !it.next().getName().equals( "gh" ) ) {
7363                 return false;
7364             }
7365             if ( !it.next().getName().equals( "efgh" ) ) {
7366                 return false;
7367             }
7368             if ( !it.next().getName().equals( "r" ) ) {
7369                 return false;
7370             }
7371             if ( it.hasNext() ) {
7372                 return false;
7373             }
7374         }
7375         catch ( final Exception e ) {
7376             e.printStackTrace( System.out );
7377             return false;
7378         }
7379         return true;
7380     }
7381
7382     private static boolean testPreOrderIterator() {
7383         try {
7384             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7385             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7386             PhylogenyNodeIterator it0;
7387             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
7388                 it0.next();
7389             }
7390             for( it0.reset(); it0.hasNext(); ) {
7391                 it0.next();
7392             }
7393             PhylogenyNodeIterator it = t0.iteratorPreorder();
7394             if ( !it.next().getName().equals( "r" ) ) {
7395                 return false;
7396             }
7397             if ( !it.next().getName().equals( "ab" ) ) {
7398                 return false;
7399             }
7400             if ( !it.next().getName().equals( "A" ) ) {
7401                 return false;
7402             }
7403             if ( !it.next().getName().equals( "B" ) ) {
7404                 return false;
7405             }
7406             if ( !it.next().getName().equals( "cd" ) ) {
7407                 return false;
7408             }
7409             if ( !it.next().getName().equals( "C" ) ) {
7410                 return false;
7411             }
7412             if ( !it.next().getName().equals( "D" ) ) {
7413                 return false;
7414             }
7415             if ( it.hasNext() ) {
7416                 return false;
7417             }
7418             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7419             it = t1.iteratorPreorder();
7420             if ( !it.next().getName().equals( "r" ) ) {
7421                 return false;
7422             }
7423             if ( !it.next().getName().equals( "abcd" ) ) {
7424                 return false;
7425             }
7426             if ( !it.next().getName().equals( "ab" ) ) {
7427                 return false;
7428             }
7429             if ( !it.next().getName().equals( "A" ) ) {
7430                 return false;
7431             }
7432             if ( !it.next().getName().equals( "B" ) ) {
7433                 return false;
7434             }
7435             if ( !it.next().getName().equals( "cd" ) ) {
7436                 return false;
7437             }
7438             if ( !it.next().getName().equals( "C" ) ) {
7439                 return false;
7440             }
7441             if ( !it.next().getName().equals( "D" ) ) {
7442                 return false;
7443             }
7444             if ( !it.next().getName().equals( "efgh" ) ) {
7445                 return false;
7446             }
7447             if ( !it.next().getName().equals( "ef" ) ) {
7448                 return false;
7449             }
7450             if ( !it.next().getName().equals( "E" ) ) {
7451                 return false;
7452             }
7453             if ( !it.next().getName().equals( "F" ) ) {
7454                 return false;
7455             }
7456             if ( !it.next().getName().equals( "gh" ) ) {
7457                 return false;
7458             }
7459             if ( !it.next().getName().equals( "G" ) ) {
7460                 return false;
7461             }
7462             if ( !it.next().getName().equals( "H" ) ) {
7463                 return false;
7464             }
7465             if ( it.hasNext() ) {
7466                 return false;
7467             }
7468         }
7469         catch ( final Exception e ) {
7470             e.printStackTrace( System.out );
7471             return false;
7472         }
7473         return true;
7474     }
7475
7476     private static boolean testPropertiesMap() {
7477         try {
7478             final PropertiesMap pm = new PropertiesMap();
7479             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7480             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7481             final Property p2 = new Property( "something:else",
7482                                               "?",
7483                                               "improbable:research",
7484                                               "xsd:decimal",
7485                                               AppliesTo.NODE );
7486             pm.addProperty( p0 );
7487             pm.addProperty( p1 );
7488             pm.addProperty( p2 );
7489             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
7490                 return false;
7491             }
7492             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
7493                 return false;
7494             }
7495             if ( pm.getProperties().size() != 3 ) {
7496                 return false;
7497             }
7498             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
7499                 return false;
7500             }
7501             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7502                 return false;
7503             }
7504             if ( pm.getProperties().size() != 3 ) {
7505                 return false;
7506             }
7507             pm.removeProperty( "dimensions:diameter" );
7508             if ( pm.getProperties().size() != 2 ) {
7509                 return false;
7510             }
7511             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
7512                 return false;
7513             }
7514             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7515                 return false;
7516             }
7517         }
7518         catch ( final Exception e ) {
7519             e.printStackTrace( System.out );
7520             return false;
7521         }
7522         return true;
7523     }
7524
7525     private static boolean testReIdMethods() {
7526         try {
7527             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7528             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
7529             final long count = PhylogenyNode.getNodeCount();
7530             p.levelOrderReID();
7531             if ( p.getNode( "r" ).getId() != count ) {
7532                 return false;
7533             }
7534             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
7535                 return false;
7536             }
7537             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
7538                 return false;
7539             }
7540             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
7541                 return false;
7542             }
7543             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
7544                 return false;
7545             }
7546             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
7547                 return false;
7548             }
7549             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
7550                 return false;
7551             }
7552             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
7553                 return false;
7554             }
7555             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
7556                 return false;
7557             }
7558             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
7559                 return false;
7560             }
7561             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
7562                 return false;
7563             }
7564             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
7565                 return false;
7566             }
7567             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
7568                 return false;
7569             }
7570             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
7571                 return false;
7572             }
7573             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
7574                 return false;
7575             }
7576         }
7577         catch ( final Exception e ) {
7578             e.printStackTrace( System.out );
7579             return false;
7580         }
7581         return true;
7582     }
7583
7584     private static boolean testRerooting() {
7585         try {
7586             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7587             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",
7588                                                  new NHXParser() )[ 0 ];
7589             if ( !t1.isRooted() ) {
7590                 return false;
7591             }
7592             t1.reRoot( t1.getNode( "D" ) );
7593             t1.reRoot( t1.getNode( "CD" ) );
7594             t1.reRoot( t1.getNode( "A" ) );
7595             t1.reRoot( t1.getNode( "B" ) );
7596             t1.reRoot( t1.getNode( "AB" ) );
7597             t1.reRoot( t1.getNode( "D" ) );
7598             t1.reRoot( t1.getNode( "C" ) );
7599             t1.reRoot( t1.getNode( "CD" ) );
7600             t1.reRoot( t1.getNode( "A" ) );
7601             t1.reRoot( t1.getNode( "B" ) );
7602             t1.reRoot( t1.getNode( "AB" ) );
7603             t1.reRoot( t1.getNode( "D" ) );
7604             t1.reRoot( t1.getNode( "D" ) );
7605             t1.reRoot( t1.getNode( "C" ) );
7606             t1.reRoot( t1.getNode( "A" ) );
7607             t1.reRoot( t1.getNode( "B" ) );
7608             t1.reRoot( t1.getNode( "AB" ) );
7609             t1.reRoot( t1.getNode( "C" ) );
7610             t1.reRoot( t1.getNode( "D" ) );
7611             t1.reRoot( t1.getNode( "CD" ) );
7612             t1.reRoot( t1.getNode( "D" ) );
7613             t1.reRoot( t1.getNode( "A" ) );
7614             t1.reRoot( t1.getNode( "B" ) );
7615             t1.reRoot( t1.getNode( "AB" ) );
7616             t1.reRoot( t1.getNode( "C" ) );
7617             t1.reRoot( t1.getNode( "D" ) );
7618             t1.reRoot( t1.getNode( "CD" ) );
7619             t1.reRoot( t1.getNode( "D" ) );
7620             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
7621                 return false;
7622             }
7623             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
7624                 return false;
7625             }
7626             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
7627                 return false;
7628             }
7629             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
7630                 return false;
7631             }
7632             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
7633                 return false;
7634             }
7635             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
7636                 return false;
7637             }
7638             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",
7639                                                  new NHXParser() )[ 0 ];
7640             t2.reRoot( t2.getNode( "A" ) );
7641             t2.reRoot( t2.getNode( "D" ) );
7642             t2.reRoot( t2.getNode( "ABC" ) );
7643             t2.reRoot( t2.getNode( "A" ) );
7644             t2.reRoot( t2.getNode( "B" ) );
7645             t2.reRoot( t2.getNode( "D" ) );
7646             t2.reRoot( t2.getNode( "C" ) );
7647             t2.reRoot( t2.getNode( "ABC" ) );
7648             t2.reRoot( t2.getNode( "A" ) );
7649             t2.reRoot( t2.getNode( "B" ) );
7650             t2.reRoot( t2.getNode( "AB" ) );
7651             t2.reRoot( t2.getNode( "AB" ) );
7652             t2.reRoot( t2.getNode( "D" ) );
7653             t2.reRoot( t2.getNode( "C" ) );
7654             t2.reRoot( t2.getNode( "B" ) );
7655             t2.reRoot( t2.getNode( "AB" ) );
7656             t2.reRoot( t2.getNode( "D" ) );
7657             t2.reRoot( t2.getNode( "D" ) );
7658             t2.reRoot( t2.getNode( "ABC" ) );
7659             t2.reRoot( t2.getNode( "A" ) );
7660             t2.reRoot( t2.getNode( "B" ) );
7661             t2.reRoot( t2.getNode( "AB" ) );
7662             t2.reRoot( t2.getNode( "D" ) );
7663             t2.reRoot( t2.getNode( "C" ) );
7664             t2.reRoot( t2.getNode( "ABC" ) );
7665             t2.reRoot( t2.getNode( "A" ) );
7666             t2.reRoot( t2.getNode( "B" ) );
7667             t2.reRoot( t2.getNode( "AB" ) );
7668             t2.reRoot( t2.getNode( "D" ) );
7669             t2.reRoot( t2.getNode( "D" ) );
7670             t2.reRoot( t2.getNode( "C" ) );
7671             t2.reRoot( t2.getNode( "A" ) );
7672             t2.reRoot( t2.getNode( "B" ) );
7673             t2.reRoot( t2.getNode( "AB" ) );
7674             t2.reRoot( t2.getNode( "C" ) );
7675             t2.reRoot( t2.getNode( "D" ) );
7676             t2.reRoot( t2.getNode( "ABC" ) );
7677             t2.reRoot( t2.getNode( "D" ) );
7678             t2.reRoot( t2.getNode( "A" ) );
7679             t2.reRoot( t2.getNode( "B" ) );
7680             t2.reRoot( t2.getNode( "AB" ) );
7681             t2.reRoot( t2.getNode( "C" ) );
7682             t2.reRoot( t2.getNode( "D" ) );
7683             t2.reRoot( t2.getNode( "ABC" ) );
7684             t2.reRoot( t2.getNode( "D" ) );
7685             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7686                 return false;
7687             }
7688             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7689                 return false;
7690             }
7691             t2.reRoot( t2.getNode( "ABC" ) );
7692             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7693                 return false;
7694             }
7695             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7696                 return false;
7697             }
7698             t2.reRoot( t2.getNode( "AB" ) );
7699             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7700                 return false;
7701             }
7702             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7703                 return false;
7704             }
7705             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7706                 return false;
7707             }
7708             t2.reRoot( t2.getNode( "AB" ) );
7709             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7710                 return false;
7711             }
7712             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7713                 return false;
7714             }
7715             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7716                 return false;
7717             }
7718             t2.reRoot( t2.getNode( "D" ) );
7719             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7720                 return false;
7721             }
7722             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7723                 return false;
7724             }
7725             t2.reRoot( t2.getNode( "ABC" ) );
7726             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7727                 return false;
7728             }
7729             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7730                 return false;
7731             }
7732             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
7733                                                  new NHXParser() )[ 0 ];
7734             t3.reRoot( t3.getNode( "B" ) );
7735             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7736                 return false;
7737             }
7738             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7739                 return false;
7740             }
7741             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7742                 return false;
7743             }
7744             t3.reRoot( t3.getNode( "B" ) );
7745             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7746                 return false;
7747             }
7748             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7749                 return false;
7750             }
7751             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7752                 return false;
7753             }
7754             t3.reRoot( t3.getRoot() );
7755             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7756                 return false;
7757             }
7758             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7759                 return false;
7760             }
7761             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7762                 return false;
7763             }
7764         }
7765         catch ( final Exception e ) {
7766             e.printStackTrace( System.out );
7767             return false;
7768         }
7769         return true;
7770     }
7771
7772     private static boolean testSDIse() {
7773         try {
7774             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7775             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
7776             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
7777             gene1.setRooted( true );
7778             species1.setRooted( true );
7779             final SDI sdi = new SDI( gene1, species1 );
7780             if ( !gene1.getRoot().isDuplication() ) {
7781                 return false;
7782             }
7783             final Phylogeny species2 = factory
7784                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7785                              new NHXParser() )[ 0 ];
7786             final Phylogeny gene2 = factory
7787                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7788                              new NHXParser() )[ 0 ];
7789             species2.setRooted( true );
7790             gene2.setRooted( true );
7791             final SDI sdi2 = new SDI( gene2, species2 );
7792             if ( sdi2.getDuplicationsSum() != 0 ) {
7793                 return false;
7794             }
7795             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
7796                 return false;
7797             }
7798             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
7799                 return false;
7800             }
7801             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
7802                 return false;
7803             }
7804             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
7805                 return false;
7806             }
7807             if ( !gene2.getNode( "r" ).isSpeciation() ) {
7808                 return false;
7809             }
7810             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
7811                 return false;
7812             }
7813             final Phylogeny species3 = factory
7814                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7815                              new NHXParser() )[ 0 ];
7816             final Phylogeny gene3 = factory
7817                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7818                              new NHXParser() )[ 0 ];
7819             species3.setRooted( true );
7820             gene3.setRooted( true );
7821             final SDI sdi3 = new SDI( gene3, species3 );
7822             if ( sdi3.getDuplicationsSum() != 1 ) {
7823                 return false;
7824             }
7825             if ( !gene3.getNode( "aa" ).isDuplication() ) {
7826                 return false;
7827             }
7828             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
7829                 return false;
7830             }
7831             final Phylogeny species4 = factory
7832                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7833                              new NHXParser() )[ 0 ];
7834             final Phylogeny gene4 = factory
7835                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7836                              new NHXParser() )[ 0 ];
7837             species4.setRooted( true );
7838             gene4.setRooted( true );
7839             final SDI sdi4 = new SDI( gene4, species4 );
7840             if ( sdi4.getDuplicationsSum() != 1 ) {
7841                 return false;
7842             }
7843             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
7844                 return false;
7845             }
7846             if ( !gene4.getNode( "abc" ).isDuplication() ) {
7847                 return false;
7848             }
7849             if ( gene4.getNode( "abcd" ).isDuplication() ) {
7850                 return false;
7851             }
7852             if ( species4.getNumberOfExternalNodes() != 6 ) {
7853                 return false;
7854             }
7855             if ( gene4.getNumberOfExternalNodes() != 6 ) {
7856                 return false;
7857             }
7858             final Phylogeny species5 = factory
7859                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7860                              new NHXParser() )[ 0 ];
7861             final Phylogeny gene5 = factory
7862                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7863                              new NHXParser() )[ 0 ];
7864             species5.setRooted( true );
7865             gene5.setRooted( true );
7866             final SDI sdi5 = new SDI( gene5, species5 );
7867             if ( sdi5.getDuplicationsSum() != 2 ) {
7868                 return false;
7869             }
7870             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
7871                 return false;
7872             }
7873             if ( !gene5.getNode( "adc" ).isDuplication() ) {
7874                 return false;
7875             }
7876             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
7877                 return false;
7878             }
7879             if ( species5.getNumberOfExternalNodes() != 6 ) {
7880                 return false;
7881             }
7882             if ( gene5.getNumberOfExternalNodes() != 6 ) {
7883                 return false;
7884             }
7885             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
7886             // Conjecture for Comparing Molecular Phylogenies"
7887             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
7888             final Phylogeny species6 = factory
7889                     .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,"
7890                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
7891                              new NHXParser() )[ 0 ];
7892             final Phylogeny gene6 = factory
7893                     .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,"
7894                                      + "((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,"
7895                                      + "(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;",
7896                              new NHXParser() )[ 0 ];
7897             species6.setRooted( true );
7898             gene6.setRooted( true );
7899             final SDI sdi6 = new SDI( gene6, species6 );
7900             if ( sdi6.getDuplicationsSum() != 3 ) {
7901                 return false;
7902             }
7903             if ( !gene6.getNode( "r" ).isDuplication() ) {
7904                 return false;
7905             }
7906             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
7907                 return false;
7908             }
7909             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
7910                 return false;
7911             }
7912             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
7913                 return false;
7914             }
7915             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
7916                 return false;
7917             }
7918             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
7919                 return false;
7920             }
7921             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
7922                 return false;
7923             }
7924             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
7925                 return false;
7926             }
7927             sdi6.computeMappingCostL();
7928             if ( sdi6.computeMappingCostL() != 17 ) {
7929                 return false;
7930             }
7931             if ( species6.getNumberOfExternalNodes() != 9 ) {
7932                 return false;
7933             }
7934             if ( gene6.getNumberOfExternalNodes() != 9 ) {
7935                 return false;
7936             }
7937             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
7938                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
7939                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
7940                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
7941                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
7942             species7.setRooted( true );
7943             final Phylogeny gene7_1 = Test
7944                     .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])" );
7945             gene7_1.setRooted( true );
7946             final SDI sdi7 = new SDI( gene7_1, species7 );
7947             if ( sdi7.getDuplicationsSum() != 0 ) {
7948                 return false;
7949             }
7950             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
7951                 return false;
7952             }
7953             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
7954                 return false;
7955             }
7956             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
7957                 return false;
7958             }
7959             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
7960                 return false;
7961             }
7962             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
7963                 return false;
7964             }
7965             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
7966                 return false;
7967             }
7968             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
7969                 return false;
7970             }
7971             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
7972                 return false;
7973             }
7974             final Phylogeny gene7_2 = Test
7975                     .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])" );
7976             gene7_2.setRooted( true );
7977             final SDI sdi7_2 = new SDI( gene7_2, species7 );
7978             if ( sdi7_2.getDuplicationsSum() != 1 ) {
7979                 return false;
7980             }
7981             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
7982                 return false;
7983             }
7984             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
7985                 return false;
7986             }
7987             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
7988                 return false;
7989             }
7990             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
7991                 return false;
7992             }
7993             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
7994                 return false;
7995             }
7996             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
7997                 return false;
7998             }
7999             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
8000                 return false;
8001             }
8002             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
8003                 return false;
8004             }
8005             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
8006                 return false;
8007             }
8008         }
8009         catch ( final Exception e ) {
8010             return false;
8011         }
8012         return true;
8013     }
8014
8015     private static boolean testSDIunrooted() {
8016         try {
8017             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8018             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
8019             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
8020             final Iterator<PhylogenyBranch> iter = l.iterator();
8021             PhylogenyBranch br = iter.next();
8022             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
8023                 return false;
8024             }
8025             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
8026                 return false;
8027             }
8028             br = iter.next();
8029             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8030                 return false;
8031             }
8032             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8033                 return false;
8034             }
8035             br = iter.next();
8036             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
8037                 return false;
8038             }
8039             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
8040                 return false;
8041             }
8042             br = iter.next();
8043             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8044                 return false;
8045             }
8046             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8047                 return false;
8048             }
8049             br = iter.next();
8050             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8051                 return false;
8052             }
8053             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8054                 return false;
8055             }
8056             br = iter.next();
8057             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8058                 return false;
8059             }
8060             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8061                 return false;
8062             }
8063             br = iter.next();
8064             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8065                 return false;
8066             }
8067             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8068                 return false;
8069             }
8070             br = iter.next();
8071             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8072                 return false;
8073             }
8074             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8075                 return false;
8076             }
8077             br = iter.next();
8078             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8079                 return false;
8080             }
8081             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8082                 return false;
8083             }
8084             br = iter.next();
8085             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8086                 return false;
8087             }
8088             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8089                 return false;
8090             }
8091             br = iter.next();
8092             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8093                 return false;
8094             }
8095             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8096                 return false;
8097             }
8098             br = iter.next();
8099             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
8100                 return false;
8101             }
8102             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
8103                 return false;
8104             }
8105             br = iter.next();
8106             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8107                 return false;
8108             }
8109             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8110                 return false;
8111             }
8112             br = iter.next();
8113             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
8114                 return false;
8115             }
8116             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
8117                 return false;
8118             }
8119             br = iter.next();
8120             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
8121                 return false;
8122             }
8123             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
8124                 return false;
8125             }
8126             if ( iter.hasNext() ) {
8127                 return false;
8128             }
8129             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
8130             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
8131             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
8132             br = iter1.next();
8133             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8134                 return false;
8135             }
8136             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8137                 return false;
8138             }
8139             br = iter1.next();
8140             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8141                 return false;
8142             }
8143             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8144                 return false;
8145             }
8146             br = iter1.next();
8147             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8148                 return false;
8149             }
8150             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8151                 return false;
8152             }
8153             if ( iter1.hasNext() ) {
8154                 return false;
8155             }
8156             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
8157             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
8158             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
8159             br = iter2.next();
8160             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8161                 return false;
8162             }
8163             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8164                 return false;
8165             }
8166             br = iter2.next();
8167             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8168                 return false;
8169             }
8170             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8171                 return false;
8172             }
8173             br = iter2.next();
8174             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8175                 return false;
8176             }
8177             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8178                 return false;
8179             }
8180             if ( iter2.hasNext() ) {
8181                 return false;
8182             }
8183             final Phylogeny species0 = factory
8184                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
8185                              new NHXParser() )[ 0 ];
8186             final Phylogeny gene1 = factory
8187                     .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])",
8188                              new NHXParser() )[ 0 ];
8189             species0.setRooted( true );
8190             gene1.setRooted( true );
8191             final SDIR sdi_unrooted = new SDIR();
8192             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
8193             if ( sdi_unrooted.getCount() != 1 ) {
8194                 return false;
8195             }
8196             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
8197                 return false;
8198             }
8199             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
8200                 return false;
8201             }
8202             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
8203                 return false;
8204             }
8205             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8206                 return false;
8207             }
8208             final Phylogeny gene2 = factory
8209                     .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])",
8210                              new NHXParser() )[ 0 ];
8211             gene2.setRooted( true );
8212             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
8213             if ( sdi_unrooted.getCount() != 1 ) {
8214                 return false;
8215             }
8216             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8217                 return false;
8218             }
8219             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8220                 return false;
8221             }
8222             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
8223                 return false;
8224             }
8225             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8226                 return false;
8227             }
8228             final Phylogeny species6 = factory
8229                     .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,"
8230                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8231                              new NHXParser() )[ 0 ];
8232             final Phylogeny gene6 = factory
8233                     .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],"
8234                                      + "(((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],"
8235                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8236                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8237                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8238                              new NHXParser() )[ 0 ];
8239             species6.setRooted( true );
8240             gene6.setRooted( true );
8241             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
8242             if ( sdi_unrooted.getCount() != 1 ) {
8243                 return false;
8244             }
8245             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8246                 return false;
8247             }
8248             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8249                 return false;
8250             }
8251             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8252                 return false;
8253             }
8254             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8255                 return false;
8256             }
8257             if ( !p6[ 0 ].getRoot().isDuplication() ) {
8258                 return false;
8259             }
8260             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8261                 return false;
8262             }
8263             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8264                 return false;
8265             }
8266             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
8267                 return false;
8268             }
8269             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8270                 return false;
8271             }
8272             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
8273                 return false;
8274             }
8275             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
8276                 return false;
8277             }
8278             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8279                 return false;
8280             }
8281             p6 = null;
8282             final Phylogeny species7 = factory
8283                     .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,"
8284                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8285                              new NHXParser() )[ 0 ];
8286             final Phylogeny gene7 = factory
8287                     .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],"
8288                                      + "(((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],"
8289                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8290                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8291                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8292                              new NHXParser() )[ 0 ];
8293             species7.setRooted( true );
8294             gene7.setRooted( true );
8295             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
8296             if ( sdi_unrooted.getCount() != 1 ) {
8297                 return false;
8298             }
8299             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8300                 return false;
8301             }
8302             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8303                 return false;
8304             }
8305             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8306                 return false;
8307             }
8308             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
8309                 return false;
8310             }
8311             if ( !p7[ 0 ].getRoot().isDuplication() ) {
8312                 return false;
8313             }
8314             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8315                 return false;
8316             }
8317             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8318                 return false;
8319             }
8320             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
8321                 return false;
8322             }
8323             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8324                 return false;
8325             }
8326             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
8327                 return false;
8328             }
8329             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
8330                 return false;
8331             }
8332             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8333                 return false;
8334             }
8335             p7 = null;
8336             final Phylogeny species8 = factory
8337                     .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,"
8338                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8339                              new NHXParser() )[ 0 ];
8340             final Phylogeny gene8 = factory
8341                     .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],"
8342                                      + "(((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],"
8343                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8344                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8345                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8346                              new NHXParser() )[ 0 ];
8347             species8.setRooted( true );
8348             gene8.setRooted( true );
8349             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
8350             if ( sdi_unrooted.getCount() != 1 ) {
8351                 return false;
8352             }
8353             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8354                 return false;
8355             }
8356             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8357                 return false;
8358             }
8359             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8360                 return false;
8361             }
8362             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8363                 return false;
8364             }
8365             if ( !p8[ 0 ].getRoot().isDuplication() ) {
8366                 return false;
8367             }
8368             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8369                 return false;
8370             }
8371             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8372                 return false;
8373             }
8374             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
8375                 return false;
8376             }
8377             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8378                 return false;
8379             }
8380             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
8381                 return false;
8382             }
8383             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
8384                 return false;
8385             }
8386             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8387                 return false;
8388             }
8389             p8 = null;
8390         }
8391         catch ( final Exception e ) {
8392             e.printStackTrace( System.out );
8393             return false;
8394         }
8395         return true;
8396     }
8397
8398     private static boolean testSplit() {
8399         try {
8400             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8401             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8402             //Archaeopteryx.createApplication( p0 );
8403             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8404             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8405             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8406             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8407             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8408             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8409             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8410             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8411             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8412             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8413             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
8414             // System.out.println( s0.toString() );
8415             //
8416             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8417             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8418             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8419             if ( s0.match( query_nodes ) ) {
8420                 return false;
8421             }
8422             query_nodes = new HashSet<PhylogenyNode>();
8423             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8424             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8425             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8426             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8430             if ( !s0.match( query_nodes ) ) {
8431                 return false;
8432             }
8433             //
8434             query_nodes = new HashSet<PhylogenyNode>();
8435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8438             if ( !s0.match( query_nodes ) ) {
8439                 return false;
8440             }
8441             //
8442             query_nodes = new HashSet<PhylogenyNode>();
8443             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8444             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8445             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8447             if ( !s0.match( query_nodes ) ) {
8448                 return false;
8449             }
8450             //
8451             query_nodes = new HashSet<PhylogenyNode>();
8452             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8453             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8456             if ( !s0.match( query_nodes ) ) {
8457                 return false;
8458             }
8459             //
8460             query_nodes = new HashSet<PhylogenyNode>();
8461             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8464             if ( !s0.match( query_nodes ) ) {
8465                 return false;
8466             }
8467             //
8468             query_nodes = new HashSet<PhylogenyNode>();
8469             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8471             if ( !s0.match( query_nodes ) ) {
8472                 return false;
8473             }
8474             //
8475             query_nodes = new HashSet<PhylogenyNode>();
8476             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8477             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8478             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8481             if ( !s0.match( query_nodes ) ) {
8482                 return false;
8483             }
8484             //
8485             query_nodes = new HashSet<PhylogenyNode>();
8486             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8487             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8489             if ( !s0.match( query_nodes ) ) {
8490                 return false;
8491             }
8492             //
8493             query_nodes = new HashSet<PhylogenyNode>();
8494             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8498             if ( !s0.match( query_nodes ) ) {
8499                 return false;
8500             }
8501             //
8502             query_nodes = new HashSet<PhylogenyNode>();
8503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8504             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8505             if ( s0.match( query_nodes ) ) {
8506                 return false;
8507             }
8508             //
8509             query_nodes = new HashSet<PhylogenyNode>();
8510             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8511             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8513             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8514             if ( s0.match( query_nodes ) ) {
8515                 return false;
8516             }
8517             //
8518             query_nodes = new HashSet<PhylogenyNode>();
8519             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8520             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8521             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8522             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8523             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8524             if ( s0.match( query_nodes ) ) {
8525                 return false;
8526             }
8527             //
8528             query_nodes = new HashSet<PhylogenyNode>();
8529             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8532             if ( s0.match( query_nodes ) ) {
8533                 return false;
8534             }
8535             //
8536             query_nodes = new HashSet<PhylogenyNode>();
8537             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8538             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8539             if ( s0.match( query_nodes ) ) {
8540                 return false;
8541             }
8542             //
8543             query_nodes = new HashSet<PhylogenyNode>();
8544             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8545             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8546             if ( s0.match( query_nodes ) ) {
8547                 return false;
8548             }
8549             //
8550             query_nodes = new HashSet<PhylogenyNode>();
8551             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8552             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8553             if ( s0.match( query_nodes ) ) {
8554                 return false;
8555             }
8556             //
8557             query_nodes = new HashSet<PhylogenyNode>();
8558             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8559             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8560             if ( s0.match( query_nodes ) ) {
8561                 return false;
8562             }
8563             //
8564             query_nodes = new HashSet<PhylogenyNode>();
8565             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8566             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8567             if ( s0.match( query_nodes ) ) {
8568                 return false;
8569             }
8570             //
8571             query_nodes = new HashSet<PhylogenyNode>();
8572             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8573             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8574             if ( s0.match( query_nodes ) ) {
8575                 return false;
8576             }
8577             //
8578             query_nodes = new HashSet<PhylogenyNode>();
8579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8582             if ( s0.match( query_nodes ) ) {
8583                 return false;
8584             }
8585             //
8586             query_nodes = new HashSet<PhylogenyNode>();
8587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8590             if ( s0.match( query_nodes ) ) {
8591                 return false;
8592             }
8593             //
8594             query_nodes = new HashSet<PhylogenyNode>();
8595             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8596             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8597             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8598             if ( s0.match( query_nodes ) ) {
8599                 return false;
8600             }
8601             //
8602             query_nodes = new HashSet<PhylogenyNode>();
8603             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8604             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8606             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8607             if ( s0.match( query_nodes ) ) {
8608                 return false;
8609             }
8610             /////////
8611             //            query_nodes = new HashSet<PhylogenyNode>();
8612             //            query_nodes.add( new PhylogenyNode( "X" ) );
8613             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8614             //            query_nodes.add( new PhylogenyNode( "A" ) );
8615             //            query_nodes.add( new PhylogenyNode( "B" ) );
8616             //            query_nodes.add( new PhylogenyNode( "C" ) );
8617             //            query_nodes.add( new PhylogenyNode( "D" ) );
8618             //            query_nodes.add( new PhylogenyNode( "E" ) );
8619             //            query_nodes.add( new PhylogenyNode( "F" ) );
8620             //            query_nodes.add( new PhylogenyNode( "G" ) );
8621             //            if ( !s0.match( query_nodes ) ) {
8622             //                return false;
8623             //            }
8624             //            query_nodes = new HashSet<PhylogenyNode>();
8625             //            query_nodes.add( new PhylogenyNode( "X" ) );
8626             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8627             //            query_nodes.add( new PhylogenyNode( "A" ) );
8628             //            query_nodes.add( new PhylogenyNode( "B" ) );
8629             //            query_nodes.add( new PhylogenyNode( "C" ) );
8630             //            if ( !s0.match( query_nodes ) ) {
8631             //                return false;
8632             //            }
8633             //            //
8634             //            query_nodes = new HashSet<PhylogenyNode>();
8635             //            query_nodes.add( new PhylogenyNode( "X" ) );
8636             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8637             //            query_nodes.add( new PhylogenyNode( "D" ) );
8638             //            query_nodes.add( new PhylogenyNode( "E" ) );
8639             //            query_nodes.add( new PhylogenyNode( "F" ) );
8640             //            query_nodes.add( new PhylogenyNode( "G" ) );
8641             //            if ( !s0.match( query_nodes ) ) {
8642             //                return false;
8643             //            }
8644             //            //
8645             //            query_nodes = new HashSet<PhylogenyNode>();
8646             //            query_nodes.add( new PhylogenyNode( "X" ) );
8647             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8648             //            query_nodes.add( new PhylogenyNode( "A" ) );
8649             //            query_nodes.add( new PhylogenyNode( "B" ) );
8650             //            query_nodes.add( new PhylogenyNode( "C" ) );
8651             //            query_nodes.add( new PhylogenyNode( "D" ) );
8652             //            if ( !s0.match( query_nodes ) ) {
8653             //                return false;
8654             //            }
8655             //            //
8656             //            query_nodes = new HashSet<PhylogenyNode>();
8657             //            query_nodes.add( new PhylogenyNode( "X" ) );
8658             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8659             //            query_nodes.add( new PhylogenyNode( "E" ) );
8660             //            query_nodes.add( new PhylogenyNode( "F" ) );
8661             //            query_nodes.add( new PhylogenyNode( "G" ) );
8662             //            if ( !s0.match( query_nodes ) ) {
8663             //                return false;
8664             //            }
8665             //            //
8666             //            query_nodes = new HashSet<PhylogenyNode>();
8667             //            query_nodes.add( new PhylogenyNode( "X" ) );
8668             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8669             //            query_nodes.add( new PhylogenyNode( "F" ) );
8670             //            query_nodes.add( new PhylogenyNode( "G" ) );
8671             //            if ( !s0.match( query_nodes ) ) {
8672             //                return false;
8673             //            }
8674             //
8675             query_nodes = new HashSet<PhylogenyNode>();
8676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8680             if ( s0.match( query_nodes ) ) {
8681                 return false;
8682             }
8683             //
8684             query_nodes = new HashSet<PhylogenyNode>();
8685             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8689             if ( s0.match( query_nodes ) ) {
8690                 return false;
8691             }
8692             ///////////////////////////
8693             //
8694             query_nodes = new HashSet<PhylogenyNode>();
8695             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8699             if ( s0.match( query_nodes ) ) {
8700                 return false;
8701             }
8702             //
8703             query_nodes = new HashSet<PhylogenyNode>();
8704             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8705             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8707             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8708             if ( s0.match( query_nodes ) ) {
8709                 return false;
8710             }
8711             //
8712             query_nodes = new HashSet<PhylogenyNode>();
8713             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8714             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8715             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8716             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8717             if ( s0.match( query_nodes ) ) {
8718                 return false;
8719             }
8720             //
8721             query_nodes = new HashSet<PhylogenyNode>();
8722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8726             if ( s0.match( query_nodes ) ) {
8727                 return false;
8728             }
8729             //
8730             query_nodes = new HashSet<PhylogenyNode>();
8731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8735             if ( s0.match( query_nodes ) ) {
8736                 return false;
8737             }
8738             //
8739             query_nodes = new HashSet<PhylogenyNode>();
8740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8741             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8743             if ( s0.match( query_nodes ) ) {
8744                 return false;
8745             }
8746             //
8747             query_nodes = new HashSet<PhylogenyNode>();
8748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8753             if ( s0.match( query_nodes ) ) {
8754                 return false;
8755             }
8756             //
8757             query_nodes = new HashSet<PhylogenyNode>();
8758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8759             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8761             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8762             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8763             if ( s0.match( query_nodes ) ) {
8764                 return false;
8765             }
8766             //
8767             query_nodes = new HashSet<PhylogenyNode>();
8768             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8769             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8770             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8771             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8773             if ( s0.match( query_nodes ) ) {
8774                 return false;
8775             }
8776             //
8777             query_nodes = new HashSet<PhylogenyNode>();
8778             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8779             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8781             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8782             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8783             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8784             if ( s0.match( query_nodes ) ) {
8785                 return false;
8786             }
8787         }
8788         catch ( final Exception e ) {
8789             e.printStackTrace();
8790             return false;
8791         }
8792         return true;
8793     }
8794
8795     private static boolean testSplitStrict() {
8796         try {
8797             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8798             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8799             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8800             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8801             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8802             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8803             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8804             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8805             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8806             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8807             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
8808             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8809             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8810             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8811             if ( s0.match( query_nodes ) ) {
8812                 return false;
8813             }
8814             query_nodes = new HashSet<PhylogenyNode>();
8815             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8816             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8817             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8818             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8819             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8822             if ( !s0.match( query_nodes ) ) {
8823                 return false;
8824             }
8825             //
8826             query_nodes = new HashSet<PhylogenyNode>();
8827             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8830             if ( !s0.match( query_nodes ) ) {
8831                 return false;
8832             }
8833             //
8834             query_nodes = new HashSet<PhylogenyNode>();
8835             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8836             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8837             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8838             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8839             if ( !s0.match( query_nodes ) ) {
8840                 return false;
8841             }
8842             //
8843             query_nodes = new HashSet<PhylogenyNode>();
8844             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8845             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8846             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8847             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8848             if ( !s0.match( query_nodes ) ) {
8849                 return false;
8850             }
8851             //
8852             query_nodes = new HashSet<PhylogenyNode>();
8853             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8854             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8855             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8856             if ( !s0.match( query_nodes ) ) {
8857                 return false;
8858             }
8859             //
8860             query_nodes = new HashSet<PhylogenyNode>();
8861             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8863             if ( !s0.match( query_nodes ) ) {
8864                 return false;
8865             }
8866             //
8867             query_nodes = new HashSet<PhylogenyNode>();
8868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8873             if ( !s0.match( query_nodes ) ) {
8874                 return false;
8875             }
8876             //
8877             query_nodes = new HashSet<PhylogenyNode>();
8878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8881             if ( !s0.match( query_nodes ) ) {
8882                 return false;
8883             }
8884             //
8885             query_nodes = new HashSet<PhylogenyNode>();
8886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8890             if ( !s0.match( query_nodes ) ) {
8891                 return false;
8892             }
8893             //
8894             query_nodes = new HashSet<PhylogenyNode>();
8895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8897             if ( s0.match( query_nodes ) ) {
8898                 return false;
8899             }
8900             //
8901             query_nodes = new HashSet<PhylogenyNode>();
8902             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8903             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8906             if ( s0.match( query_nodes ) ) {
8907                 return false;
8908             }
8909             //
8910             query_nodes = new HashSet<PhylogenyNode>();
8911             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8912             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8913             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8916             if ( s0.match( query_nodes ) ) {
8917                 return false;
8918             }
8919             //
8920             query_nodes = new HashSet<PhylogenyNode>();
8921             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8924             if ( s0.match( query_nodes ) ) {
8925                 return false;
8926             }
8927             //
8928             query_nodes = new HashSet<PhylogenyNode>();
8929             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8931             if ( s0.match( query_nodes ) ) {
8932                 return false;
8933             }
8934             //
8935             query_nodes = new HashSet<PhylogenyNode>();
8936             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8937             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8938             if ( s0.match( query_nodes ) ) {
8939                 return false;
8940             }
8941             //
8942             query_nodes = new HashSet<PhylogenyNode>();
8943             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8944             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8945             if ( s0.match( query_nodes ) ) {
8946                 return false;
8947             }
8948             //
8949             query_nodes = new HashSet<PhylogenyNode>();
8950             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8951             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8952             if ( s0.match( query_nodes ) ) {
8953                 return false;
8954             }
8955             //
8956             query_nodes = new HashSet<PhylogenyNode>();
8957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8958             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8959             if ( s0.match( query_nodes ) ) {
8960                 return false;
8961             }
8962             //
8963             query_nodes = new HashSet<PhylogenyNode>();
8964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8966             if ( s0.match( query_nodes ) ) {
8967                 return false;
8968             }
8969             //
8970             query_nodes = new HashSet<PhylogenyNode>();
8971             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8972             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8974             if ( s0.match( query_nodes ) ) {
8975                 return false;
8976             }
8977             //
8978             query_nodes = new HashSet<PhylogenyNode>();
8979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8982             if ( s0.match( query_nodes ) ) {
8983                 return false;
8984             }
8985             //
8986             query_nodes = new HashSet<PhylogenyNode>();
8987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8990             if ( s0.match( query_nodes ) ) {
8991                 return false;
8992             }
8993             //
8994             query_nodes = new HashSet<PhylogenyNode>();
8995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8997             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8998             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8999             if ( s0.match( query_nodes ) ) {
9000                 return false;
9001             }
9002         }
9003         catch ( final Exception e ) {
9004             e.printStackTrace();
9005             return false;
9006         }
9007         return true;
9008     }
9009
9010     private static boolean testSubtreeDeletion() {
9011         try {
9012             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9013             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9014             t1.deleteSubtree( t1.getNode( "A" ), false );
9015             if ( t1.getNumberOfExternalNodes() != 5 ) {
9016                 return false;
9017             }
9018             t1.toNewHampshireX();
9019             t1.deleteSubtree( t1.getNode( "E" ), false );
9020             if ( t1.getNumberOfExternalNodes() != 4 ) {
9021                 return false;
9022             }
9023             t1.toNewHampshireX();
9024             t1.deleteSubtree( t1.getNode( "F" ), false );
9025             if ( t1.getNumberOfExternalNodes() != 3 ) {
9026                 return false;
9027             }
9028             t1.toNewHampshireX();
9029             t1.deleteSubtree( t1.getNode( "D" ), false );
9030             t1.toNewHampshireX();
9031             if ( t1.getNumberOfExternalNodes() != 3 ) {
9032                 return false;
9033             }
9034             t1.deleteSubtree( t1.getNode( "def" ), false );
9035             t1.toNewHampshireX();
9036             if ( t1.getNumberOfExternalNodes() != 2 ) {
9037                 return false;
9038             }
9039             t1.deleteSubtree( t1.getNode( "B" ), false );
9040             t1.toNewHampshireX();
9041             if ( t1.getNumberOfExternalNodes() != 1 ) {
9042                 return false;
9043             }
9044             t1.deleteSubtree( t1.getNode( "C" ), false );
9045             t1.toNewHampshireX();
9046             if ( t1.getNumberOfExternalNodes() != 1 ) {
9047                 return false;
9048             }
9049             t1.deleteSubtree( t1.getNode( "abc" ), false );
9050             t1.toNewHampshireX();
9051             if ( t1.getNumberOfExternalNodes() != 1 ) {
9052                 return false;
9053             }
9054             t1.deleteSubtree( t1.getNode( "r" ), false );
9055             if ( t1.getNumberOfExternalNodes() != 0 ) {
9056                 return false;
9057             }
9058             if ( !t1.isEmpty() ) {
9059                 return false;
9060             }
9061             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9062             t2.deleteSubtree( t2.getNode( "A" ), false );
9063             t2.toNewHampshireX();
9064             if ( t2.getNumberOfExternalNodes() != 5 ) {
9065                 return false;
9066             }
9067             t2.deleteSubtree( t2.getNode( "abc" ), false );
9068             t2.toNewHampshireX();
9069             if ( t2.getNumberOfExternalNodes() != 3 ) {
9070                 return false;
9071             }
9072             t2.deleteSubtree( t2.getNode( "def" ), false );
9073             t2.toNewHampshireX();
9074             if ( t2.getNumberOfExternalNodes() != 1 ) {
9075                 return false;
9076             }
9077         }
9078         catch ( final Exception e ) {
9079             e.printStackTrace( System.out );
9080             return false;
9081         }
9082         return true;
9083     }
9084
9085     private static boolean testSupportCount() {
9086         try {
9087             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9088             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
9089             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
9090                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
9091                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
9092                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
9093                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
9094                                                               new NHXParser() );
9095             SupportCount.count( t0_1, phylogenies_1, true, false );
9096             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
9097             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
9098                                                                       + "(((((A,B),C),D),E),((F,G),X))"
9099                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
9100                                                                       + "(((((A,B),C),D),E),(F,G))"
9101                                                                       + "(((((A,B),C),D),E),(F,G))"
9102                                                                       + "(((((A,B),C),D),E),(F,G))"
9103                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
9104                                                                       + "(((((A,B),C),D),E),(F,G))"
9105                                                                       + "((((((A,B),C),D),E),F),G)"
9106                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
9107                                                               new NHXParser() );
9108             SupportCount.count( t0_2, phylogenies_2, true, false );
9109             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
9110             while ( it.hasNext() ) {
9111                 final PhylogenyNode n = it.next();
9112                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
9113                     return false;
9114                 }
9115             }
9116             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
9117             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
9118                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
9119             SupportCount.count( t0_3, phylogenies_3, true, false );
9120             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
9121             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
9122                 return false;
9123             }
9124             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
9125                 return false;
9126             }
9127             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
9128                 return false;
9129             }
9130             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
9131                 return false;
9132             }
9133             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
9134                 return false;
9135             }
9136             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
9137                 return false;
9138             }
9139             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
9140                 return false;
9141             }
9142             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
9143                 return false;
9144             }
9145             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
9146                 return false;
9147             }
9148             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
9149                 return false;
9150             }
9151             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9152             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
9153                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
9154             SupportCount.count( t0_4, phylogenies_4, true, false );
9155             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
9156             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
9157                 return false;
9158             }
9159             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
9160                 return false;
9161             }
9162             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
9163                 return false;
9164             }
9165             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
9166                 return false;
9167             }
9168             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
9169                 return false;
9170             }
9171             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
9172                 return false;
9173             }
9174             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
9175                 return false;
9176             }
9177             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
9178                 return false;
9179             }
9180             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
9181                 return false;
9182             }
9183             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
9184                 return false;
9185             }
9186             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9187             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9188             double d = SupportCount.compare( b1, a, true, true, true );
9189             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
9190                 return false;
9191             }
9192             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9193             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9194             d = SupportCount.compare( b2, a, true, true, true );
9195             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
9196                 return false;
9197             }
9198             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9199             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
9200             d = SupportCount.compare( b3, a, true, true, true );
9201             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
9202                 return false;
9203             }
9204             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
9205             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
9206             d = SupportCount.compare( b4, a, true, true, false );
9207             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
9208                 return false;
9209             }
9210         }
9211         catch ( final Exception e ) {
9212             e.printStackTrace( System.out );
9213             return false;
9214         }
9215         return true;
9216     }
9217
9218     private static boolean testSupportTransfer() {
9219         try {
9220             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9221             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)",
9222                                                  new NHXParser() )[ 0 ];
9223             final Phylogeny p2 = factory
9224                     .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 ];
9225             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
9226                 return false;
9227             }
9228             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
9229                 return false;
9230             }
9231             support_transfer.moveBranchLengthsToBootstrap( p1 );
9232             support_transfer.transferSupportValues( p1, p2 );
9233             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
9234                 return false;
9235             }
9236             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
9237                 return false;
9238             }
9239             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
9240                 return false;
9241             }
9242             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
9243                 return false;
9244             }
9245             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
9246                 return false;
9247             }
9248             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
9249                 return false;
9250             }
9251             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
9252                 return false;
9253             }
9254             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
9255                 return false;
9256             }
9257         }
9258         catch ( final Exception e ) {
9259             e.printStackTrace( System.out );
9260             return false;
9261         }
9262         return true;
9263     }
9264
9265     private static boolean testUniprotTaxonomySearch() {
9266         try {
9267             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
9268                                                                                                  10 );
9269             if ( results.size() != 1 ) {
9270                 return false;
9271             }
9272             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9273                 return false;
9274             }
9275             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9276                 return false;
9277             }
9278             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9279                 return false;
9280             }
9281             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9282                 return false;
9283             }
9284             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9285                 return false;
9286             }
9287             results = null;
9288             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
9289             if ( results.size() != 1 ) {
9290                 return false;
9291             }
9292             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9293                 return false;
9294             }
9295             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9296                 return false;
9297             }
9298             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9299                 return false;
9300             }
9301             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9302                 return false;
9303             }
9304             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9305                 return false;
9306             }
9307             results = null;
9308             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
9309             if ( results.size() != 1 ) {
9310                 return false;
9311             }
9312             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9313                 return false;
9314             }
9315             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9316                 return false;
9317             }
9318             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9319                 return false;
9320             }
9321             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9322                 return false;
9323             }
9324             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9325                 return false;
9326             }
9327             results = null;
9328             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
9329             if ( results.size() != 1 ) {
9330                 return false;
9331             }
9332             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9333                 return false;
9334             }
9335             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9336                 return false;
9337             }
9338             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9339                 return false;
9340             }
9341             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9342                 return false;
9343             }
9344             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9345                 return false;
9346             }
9347             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
9348                 return false;
9349             }
9350             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
9351                 return false;
9352             }
9353             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
9354                     .equals( "Nematostella vectensis" ) ) {
9355                 System.out.println( results.get( 0 ).getLineage() );
9356                 return false;
9357             }
9358         }
9359         catch ( final IOException e ) {
9360             System.out.println();
9361             System.out.println( "the following might be due to absence internet connection:" );
9362             e.printStackTrace( System.out );
9363             return true;
9364         }
9365         catch ( final Exception e ) {
9366             return false;
9367         }
9368         return true;
9369     }
9370
9371     private static boolean testEmblEntryRetrieval() {
9372         //The format for GenBank Accession numbers are:
9373         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
9374         //Protein:    3 letters + 5 numerals
9375         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
9376         if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
9377             return false;
9378         }
9379         if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) {
9380             return false;
9381         }
9382         if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
9383             return false;
9384         }
9385         if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
9386             return false;
9387         }
9388         if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
9389             return false;
9390         }
9391         if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
9392             return false;
9393         }
9394         if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
9395             return false;
9396         }
9397         if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
9398             return false;
9399         }
9400         if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
9401             return false;
9402         }
9403         if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
9404             return false;
9405         }
9406         if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
9407             return false;
9408         }
9409         if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
9410             return false;
9411         }
9412         if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
9413             return false;
9414         }
9415         return true;
9416     }
9417
9418     private static boolean testUniprotEntryRetrieval() {
9419         if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) {
9420             return false;
9421         }
9422         if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) {
9423             return false;
9424         }
9425         if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) {
9426             return false;
9427         }
9428         if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) {
9429             return false;
9430         }
9431         if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) {
9432             return false;
9433         }
9434         if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) {
9435             return false;
9436         }
9437         if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) {
9438             return false;
9439         }
9440         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) {
9441             return false;
9442         }
9443         if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) {
9444             return false;
9445         }
9446         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) {
9447             return false;
9448         }
9449         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) {
9450             return false;
9451         }
9452         if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) {
9453             return false;
9454         }
9455         if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) {
9456             return false;
9457         }
9458         try {
9459             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
9460             if ( !entry.getAccession().equals( "P12345" ) ) {
9461                 return false;
9462             }
9463             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
9464                 return false;
9465             }
9466             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
9467                 return false;
9468             }
9469             if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) {
9470                 return false;
9471             }
9472             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
9473                 return false;
9474             }
9475         }
9476         catch ( final IOException e ) {
9477             System.out.println();
9478             System.out.println( "the following might be due to absence internet connection:" );
9479             e.printStackTrace( System.out );
9480             return true;
9481         }
9482         catch ( final Exception e ) {
9483             return false;
9484         }
9485         return true;
9486     }
9487
9488     private static boolean testWabiTxSearch() {
9489         try {
9490             String result = "";
9491             result = TxSearch.searchSimple( "nematostella" );
9492             result = TxSearch.getTxId( "nematostella" );
9493             if ( !result.equals( "45350" ) ) {
9494                 return false;
9495             }
9496             result = TxSearch.getTxName( "45350" );
9497             if ( !result.equals( "Nematostella" ) ) {
9498                 return false;
9499             }
9500             result = TxSearch.getTxId( "nematostella vectensis" );
9501             if ( !result.equals( "45351" ) ) {
9502                 return false;
9503             }
9504             result = TxSearch.getTxName( "45351" );
9505             if ( !result.equals( "Nematostella vectensis" ) ) {
9506                 return false;
9507             }
9508             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
9509             if ( !result.equals( "536089" ) ) {
9510                 return false;
9511             }
9512             result = TxSearch.getTxName( "536089" );
9513             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
9514                 return false;
9515             }
9516             final List<String> queries = new ArrayList<String>();
9517             queries.add( "Campylobacter coli" );
9518             queries.add( "Escherichia coli" );
9519             queries.add( "Arabidopsis" );
9520             queries.add( "Trichoplax" );
9521             queries.add( "Samanea saman" );
9522             queries.add( "Kluyveromyces marxianus" );
9523             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
9524             queries.add( "Bornavirus parrot/PDD/2008" );
9525             final List<RANKS> ranks = new ArrayList<RANKS>();
9526             ranks.add( RANKS.SUPERKINGDOM );
9527             ranks.add( RANKS.KINGDOM );
9528             ranks.add( RANKS.FAMILY );
9529             ranks.add( RANKS.GENUS );
9530             ranks.add( RANKS.TRIBE );
9531             result = TxSearch.searchLineage( queries, ranks );
9532             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
9533             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
9534         }
9535         catch ( final Exception e ) {
9536             System.out.println();
9537             System.out.println( "the following might be due to absence internet connection:" );
9538             e.printStackTrace( System.out );
9539             return false;
9540         }
9541         return true;
9542     }
9543
9544     private static boolean testAminoAcidSequence() {
9545         try {
9546             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
9547             if ( aa1.getLength() != 13 ) {
9548                 return false;
9549             }
9550             if ( aa1.getResidueAt( 0 ) != 'A' ) {
9551                 return false;
9552             }
9553             if ( aa1.getResidueAt( 2 ) != 'K' ) {
9554                 return false;
9555             }
9556             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
9557                 return false;
9558             }
9559             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
9560             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
9561                 return false;
9562             }
9563             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
9564             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
9565                 return false;
9566             }
9567             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
9568             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
9569                 return false;
9570             }
9571         }
9572         catch ( final Exception e ) {
9573             e.printStackTrace();
9574             return false;
9575         }
9576         return true;
9577     }
9578
9579     private static boolean testCreateBalancedPhylogeny() {
9580         try {
9581             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
9582             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
9583                 return false;
9584             }
9585             if ( p0.getNumberOfExternalNodes() != 15625 ) {
9586                 return false;
9587             }
9588             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
9589             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
9590                 return false;
9591             }
9592             if ( p1.getNumberOfExternalNodes() != 100 ) {
9593                 return false;
9594             }
9595         }
9596         catch ( final Exception e ) {
9597             e.printStackTrace();
9598             return false;
9599         }
9600         return true;
9601     }
9602
9603     private static boolean testFastaParser() {
9604         try {
9605             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
9606                 return false;
9607             }
9608             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
9609                 return false;
9610             }
9611             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
9612             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
9613                 return false;
9614             }
9615             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
9616                 return false;
9617             }
9618             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
9619                 return false;
9620             }
9621             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
9622                 return false;
9623             }
9624             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
9625                 return false;
9626             }
9627             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
9628                 return false;
9629             }
9630         }
9631         catch ( final Exception e ) {
9632             e.printStackTrace();
9633             return false;
9634         }
9635         return true;
9636     }
9637
9638     private static boolean testGeneralMsaParser() {
9639         try {
9640             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
9641             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
9642             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
9643             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
9644             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
9645             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
9646             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
9647             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
9648             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9649                 return false;
9650             }
9651             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9652                 return false;
9653             }
9654             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9655                 return false;
9656             }
9657             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9658                 return false;
9659             }
9660             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9661                 return false;
9662             }
9663             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9664                 return false;
9665             }
9666             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9667                 return false;
9668             }
9669             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9670                 return false;
9671             }
9672             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9673                 return false;
9674             }
9675             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9676                 return false;
9677             }
9678             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9679                 return false;
9680             }
9681             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9682                 return false;
9683             }
9684             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
9685             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9686                 return false;
9687             }
9688             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9689                 return false;
9690             }
9691             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9692                 return false;
9693             }
9694             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
9695             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
9696                 return false;
9697             }
9698             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
9699                 return false;
9700             }
9701             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
9702                 return false;
9703             }
9704             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
9705             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9706                 return false;
9707             }
9708             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9709                 return false;
9710             }
9711             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9712                 return false;
9713             }
9714         }
9715         catch ( final Exception e ) {
9716             e.printStackTrace();
9717             return false;
9718         }
9719         return true;
9720     }
9721
9722     private static boolean testMafft( final String path ) {
9723         try {
9724             final List<String> opts = new ArrayList<String>();
9725             opts.add( "--maxiterate" );
9726             opts.add( "1000" );
9727             opts.add( "--localpair" );
9728             opts.add( "--quiet" );
9729             Msa msa = null;
9730             final MsaInferrer mafft = Mafft.createInstance( path );
9731             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
9732             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
9733                 return false;
9734             }
9735             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
9736                 return false;
9737             }
9738         }
9739         catch ( final Exception e ) {
9740             e.printStackTrace( System.out );
9741             return false;
9742         }
9743         return true;
9744     }
9745
9746     private static boolean testNextNodeWithCollapsing() {
9747         try {
9748             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9749             PhylogenyNode n;
9750             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
9751             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9752             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
9753             t0.getNode( "cd" ).setCollapse( true );
9754             t0.getNode( "cde" ).setCollapse( true );
9755             n = t0.getFirstExternalNode();
9756             while ( n != null ) {
9757                 ext.add( n );
9758                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9759             }
9760             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9761                 return false;
9762             }
9763             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9764                 return false;
9765             }
9766             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
9767                 return false;
9768             }
9769             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
9770                 return false;
9771             }
9772             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
9773                 return false;
9774             }
9775             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
9776                 return false;
9777             }
9778             ext.clear();
9779             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9780             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
9781             t1.getNode( "ab" ).setCollapse( true );
9782             t1.getNode( "cd" ).setCollapse( true );
9783             t1.getNode( "cde" ).setCollapse( true );
9784             n = t1.getNode( "ab" );
9785             ext = new ArrayList<PhylogenyNode>();
9786             while ( n != null ) {
9787                 ext.add( n );
9788                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9789             }
9790             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9791                 return false;
9792             }
9793             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9794                 return false;
9795             }
9796             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9797                 return false;
9798             }
9799             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
9800                 return false;
9801             }
9802             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
9803                 return false;
9804             }
9805             //
9806             //
9807             ext.clear();
9808             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9809             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
9810             t2.getNode( "ab" ).setCollapse( true );
9811             t2.getNode( "cd" ).setCollapse( true );
9812             t2.getNode( "cde" ).setCollapse( true );
9813             t2.getNode( "c" ).setCollapse( true );
9814             t2.getNode( "d" ).setCollapse( true );
9815             t2.getNode( "e" ).setCollapse( true );
9816             t2.getNode( "gh" ).setCollapse( true );
9817             n = t2.getNode( "ab" );
9818             ext = new ArrayList<PhylogenyNode>();
9819             while ( n != null ) {
9820                 ext.add( n );
9821                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9822             }
9823             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9824                 return false;
9825             }
9826             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9827                 return false;
9828             }
9829             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9830                 return false;
9831             }
9832             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
9833                 return false;
9834             }
9835             //
9836             //
9837             ext.clear();
9838             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9839             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
9840             t3.getNode( "ab" ).setCollapse( true );
9841             t3.getNode( "cd" ).setCollapse( true );
9842             t3.getNode( "cde" ).setCollapse( true );
9843             t3.getNode( "c" ).setCollapse( true );
9844             t3.getNode( "d" ).setCollapse( true );
9845             t3.getNode( "e" ).setCollapse( true );
9846             t3.getNode( "gh" ).setCollapse( true );
9847             t3.getNode( "fgh" ).setCollapse( true );
9848             n = t3.getNode( "ab" );
9849             ext = new ArrayList<PhylogenyNode>();
9850             while ( n != null ) {
9851                 ext.add( n );
9852                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9853             }
9854             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9855                 return false;
9856             }
9857             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9858                 return false;
9859             }
9860             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
9861                 return false;
9862             }
9863             //
9864             //
9865             ext.clear();
9866             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9867             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
9868             t4.getNode( "ab" ).setCollapse( true );
9869             t4.getNode( "cd" ).setCollapse( true );
9870             t4.getNode( "cde" ).setCollapse( true );
9871             t4.getNode( "c" ).setCollapse( true );
9872             t4.getNode( "d" ).setCollapse( true );
9873             t4.getNode( "e" ).setCollapse( true );
9874             t4.getNode( "gh" ).setCollapse( true );
9875             t4.getNode( "fgh" ).setCollapse( true );
9876             t4.getNode( "abcdefgh" ).setCollapse( true );
9877             n = t4.getNode( "abcdefgh" );
9878             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
9879                 return false;
9880             }
9881             //
9882             //
9883             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9884             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
9885             ext.clear();
9886             n = t5.getFirstExternalNode();
9887             while ( n != null ) {
9888                 ext.add( n );
9889                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9890             }
9891             if ( ext.size() != 8 ) {
9892                 return false;
9893             }
9894             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9895                 return false;
9896             }
9897             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9898                 return false;
9899             }
9900             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
9901                 return false;
9902             }
9903             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
9904                 return false;
9905             }
9906             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
9907                 return false;
9908             }
9909             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
9910                 return false;
9911             }
9912             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
9913                 return false;
9914             }
9915             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
9916                 return false;
9917             }
9918             //
9919             //
9920             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9921             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
9922             ext.clear();
9923             t6.getNode( "ab" ).setCollapse( true );
9924             n = t6.getNode( "ab" );
9925             while ( n != null ) {
9926                 ext.add( n );
9927                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9928             }
9929             if ( ext.size() != 7 ) {
9930                 return false;
9931             }
9932             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9933                 return false;
9934             }
9935             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
9936                 return false;
9937             }
9938             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
9939                 return false;
9940             }
9941             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9942                 return false;
9943             }
9944             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9945                 return false;
9946             }
9947             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9948                 return false;
9949             }
9950             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9951                 return false;
9952             }
9953             //
9954             //
9955             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9956             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
9957             ext.clear();
9958             t7.getNode( "cd" ).setCollapse( true );
9959             n = t7.getNode( "a" );
9960             while ( n != null ) {
9961                 ext.add( n );
9962                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9963             }
9964             if ( ext.size() != 7 ) {
9965                 return false;
9966             }
9967             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9968                 return false;
9969             }
9970             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9971                 return false;
9972             }
9973             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
9974                 return false;
9975             }
9976             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9977                 return false;
9978             }
9979             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9980                 return false;
9981             }
9982             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9983                 return false;
9984             }
9985             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9986                 return false;
9987             }
9988             //
9989             //
9990             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9991             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
9992             ext.clear();
9993             t8.getNode( "cd" ).setCollapse( true );
9994             t8.getNode( "c" ).setCollapse( true );
9995             t8.getNode( "d" ).setCollapse( true );
9996             n = t8.getNode( "a" );
9997             while ( n != null ) {
9998                 ext.add( n );
9999                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10000             }
10001             if ( ext.size() != 7 ) {
10002                 return false;
10003             }
10004             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10005                 return false;
10006             }
10007             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10008                 return false;
10009             }
10010             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10011                 System.out.println( "2 fail" );
10012                 return false;
10013             }
10014             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10015                 return false;
10016             }
10017             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10018                 return false;
10019             }
10020             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10021                 return false;
10022             }
10023             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10024                 return false;
10025             }
10026             //
10027             //
10028             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10029             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
10030             ext.clear();
10031             t9.getNode( "gh" ).setCollapse( true );
10032             n = t9.getNode( "a" );
10033             while ( n != null ) {
10034                 ext.add( n );
10035                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10036             }
10037             if ( ext.size() != 7 ) {
10038                 return false;
10039             }
10040             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10041                 return false;
10042             }
10043             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10044                 return false;
10045             }
10046             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10047                 return false;
10048             }
10049             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10050                 return false;
10051             }
10052             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10053                 return false;
10054             }
10055             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10056                 return false;
10057             }
10058             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10059                 return false;
10060             }
10061             //
10062             //
10063             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10064             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
10065             ext.clear();
10066             t10.getNode( "gh" ).setCollapse( true );
10067             t10.getNode( "g" ).setCollapse( true );
10068             t10.getNode( "h" ).setCollapse( true );
10069             n = t10.getNode( "a" );
10070             while ( n != null ) {
10071                 ext.add( n );
10072                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10073             }
10074             if ( ext.size() != 7 ) {
10075                 return false;
10076             }
10077             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10078                 return false;
10079             }
10080             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10081                 return false;
10082             }
10083             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10084                 return false;
10085             }
10086             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10087                 return false;
10088             }
10089             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10090                 return false;
10091             }
10092             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10093                 return false;
10094             }
10095             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10096                 return false;
10097             }
10098             //
10099             //
10100             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10101             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
10102             ext.clear();
10103             t11.getNode( "gh" ).setCollapse( true );
10104             t11.getNode( "fgh" ).setCollapse( true );
10105             n = t11.getNode( "a" );
10106             while ( n != null ) {
10107                 ext.add( n );
10108                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10109             }
10110             if ( ext.size() != 6 ) {
10111                 return false;
10112             }
10113             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10114                 return false;
10115             }
10116             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10117                 return false;
10118             }
10119             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10120                 return false;
10121             }
10122             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10123                 return false;
10124             }
10125             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10126                 return false;
10127             }
10128             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10129                 return false;
10130             }
10131             //
10132             //
10133             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10134             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
10135             ext.clear();
10136             t12.getNode( "gh" ).setCollapse( true );
10137             t12.getNode( "fgh" ).setCollapse( true );
10138             t12.getNode( "g" ).setCollapse( true );
10139             t12.getNode( "h" ).setCollapse( true );
10140             t12.getNode( "f" ).setCollapse( true );
10141             n = t12.getNode( "a" );
10142             while ( n != null ) {
10143                 ext.add( n );
10144                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10145             }
10146             if ( ext.size() != 6 ) {
10147                 return false;
10148             }
10149             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10150                 return false;
10151             }
10152             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10153                 return false;
10154             }
10155             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10156                 return false;
10157             }
10158             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10159                 return false;
10160             }
10161             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10162                 return false;
10163             }
10164             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10165                 return false;
10166             }
10167             //
10168             //
10169             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10170             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
10171             ext.clear();
10172             t13.getNode( "ab" ).setCollapse( true );
10173             t13.getNode( "b" ).setCollapse( true );
10174             t13.getNode( "fgh" ).setCollapse( true );
10175             t13.getNode( "gh" ).setCollapse( true );
10176             n = t13.getNode( "ab" );
10177             while ( n != null ) {
10178                 ext.add( n );
10179                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10180             }
10181             if ( ext.size() != 5 ) {
10182                 return false;
10183             }
10184             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10185                 return false;
10186             }
10187             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10188                 return false;
10189             }
10190             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10191                 return false;
10192             }
10193             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10194                 return false;
10195             }
10196             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10197                 return false;
10198             }
10199             //
10200             //
10201             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
10202             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
10203             ext.clear();
10204             t14.getNode( "ab" ).setCollapse( true );
10205             t14.getNode( "a" ).setCollapse( true );
10206             t14.getNode( "fgh" ).setCollapse( true );
10207             t14.getNode( "gh" ).setCollapse( true );
10208             n = t14.getNode( "ab" );
10209             while ( n != null ) {
10210                 ext.add( n );
10211                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10212             }
10213             if ( ext.size() != 5 ) {
10214                 return false;
10215             }
10216             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10217                 return false;
10218             }
10219             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10220                 return false;
10221             }
10222             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10223                 return false;
10224             }
10225             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10226                 return false;
10227             }
10228             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10229                 return false;
10230             }
10231             //
10232             //
10233             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" );
10234             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
10235             ext.clear();
10236             t15.getNode( "ab" ).setCollapse( true );
10237             t15.getNode( "a" ).setCollapse( true );
10238             t15.getNode( "fgh" ).setCollapse( true );
10239             t15.getNode( "gh" ).setCollapse( true );
10240             n = t15.getNode( "ab" );
10241             while ( n != null ) {
10242                 ext.add( n );
10243                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10244             }
10245             if ( ext.size() != 6 ) {
10246                 return false;
10247             }
10248             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10249                 return false;
10250             }
10251             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10252                 return false;
10253             }
10254             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10255                 return false;
10256             }
10257             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10258                 return false;
10259             }
10260             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
10261                 return false;
10262             }
10263             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10264                 return false;
10265             }
10266             //
10267             //
10268             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" );
10269             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
10270             ext.clear();
10271             t16.getNode( "ab" ).setCollapse( true );
10272             t16.getNode( "a" ).setCollapse( true );
10273             t16.getNode( "fgh" ).setCollapse( true );
10274             t16.getNode( "gh" ).setCollapse( true );
10275             t16.getNode( "cd" ).setCollapse( true );
10276             t16.getNode( "cde" ).setCollapse( true );
10277             t16.getNode( "d" ).setCollapse( true );
10278             t16.getNode( "x" ).setCollapse( true );
10279             n = t16.getNode( "ab" );
10280             while ( n != null ) {
10281                 ext.add( n );
10282                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10283             }
10284             if ( ext.size() != 4 ) {
10285                 return false;
10286             }
10287             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10288                 return false;
10289             }
10290             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
10291                 return false;
10292             }
10293             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
10294                 return false;
10295             }
10296             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
10297                 return false;
10298             }
10299         }
10300         catch ( final Exception e ) {
10301             e.printStackTrace( System.out );
10302             return false;
10303         }
10304         return true;
10305     }
10306
10307     private static boolean testMsaQualityMethod() {
10308         try {
10309             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
10310             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
10311             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
10312             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
10313             final List<Sequence> l = new ArrayList<Sequence>();
10314             l.add( s0 );
10315             l.add( s1 );
10316             l.add( s2 );
10317             l.add( s3 );
10318             final Msa msa = BasicMsa.createInstance( l );
10319             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
10320                 return false;
10321             }
10322             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
10323                 return false;
10324             }
10325             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
10326                 return false;
10327             }
10328             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
10329                 return false;
10330             }
10331         }
10332         catch ( final Exception e ) {
10333             e.printStackTrace( System.out );
10334             return false;
10335         }
10336         return true;
10337     }
10338
10339     private static boolean testSequenceIdParsing() {
10340         try {
10341             Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
10342             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10343                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10344                 if ( id != null ) {
10345                     System.out.println( "value   =" + id.getValue() );
10346                     System.out.println( "provider=" + id.getProvider() );
10347                 }
10348                 return false;
10349             }
10350             //
10351             id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
10352             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10353                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10354                 if ( id != null ) {
10355                     System.out.println( "value   =" + id.getValue() );
10356                     System.out.println( "provider=" + id.getProvider() );
10357                 }
10358                 return false;
10359             }
10360             //
10361             id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
10362             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10363                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10364                 if ( id != null ) {
10365                     System.out.println( "value   =" + id.getValue() );
10366                     System.out.println( "provider=" + id.getProvider() );
10367                 }
10368                 return false;
10369             }
10370             // 
10371             id = SequenceIdParser.parse( "gb_AAA96518_1" );
10372             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10373                     || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
10374                 if ( id != null ) {
10375                     System.out.println( "value   =" + id.getValue() );
10376                     System.out.println( "provider=" + id.getProvider() );
10377                 }
10378                 return false;
10379             }
10380             // 
10381             id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
10382             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10383                     || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
10384                 if ( id != null ) {
10385                     System.out.println( "value   =" + id.getValue() );
10386                     System.out.println( "provider=" + id.getProvider() );
10387                 }
10388                 return false;
10389             }
10390             // 
10391             id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
10392             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10393                     || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
10394                 if ( id != null ) {
10395                     System.out.println( "value   =" + id.getValue() );
10396                     System.out.println( "provider=" + id.getProvider() );
10397                 }
10398                 return false;
10399             }
10400             // 
10401             id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
10402             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10403                     || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
10404                 if ( id != null ) {
10405                     System.out.println( "value   =" + id.getValue() );
10406                     System.out.println( "provider=" + id.getProvider() );
10407                 }
10408                 return false;
10409             }
10410             // 
10411             id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
10412             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10413                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10414                 if ( id != null ) {
10415                     System.out.println( "value   =" + id.getValue() );
10416                     System.out.println( "provider=" + id.getProvider() );
10417                 }
10418                 return false;
10419             }
10420             // 
10421             id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
10422             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10423                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10424                 if ( id != null ) {
10425                     System.out.println( "value   =" + id.getValue() );
10426                     System.out.println( "provider=" + id.getProvider() );
10427                 }
10428                 return false;
10429             }
10430             // 
10431             id = SequenceIdParser.parse( "P4A123" );
10432             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10433                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10434                 if ( id != null ) {
10435                     System.out.println( "value   =" + id.getValue() );
10436                     System.out.println( "provider=" + id.getProvider() );
10437                 }
10438                 return false;
10439             }
10440             // 
10441             id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
10442             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10443                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10444                 if ( id != null ) {
10445                     System.out.println( "value   =" + id.getValue() );
10446                     System.out.println( "provider=" + id.getProvider() );
10447                 }
10448                 return false;
10449             }
10450             // 
10451             id = SequenceIdParser.parse( "XP_12345" );
10452             if ( id != null ) {
10453                 System.out.println( "value   =" + id.getValue() );
10454                 System.out.println( "provider=" + id.getProvider() );
10455                 return false;
10456             }
10457             // lcl_91970_unknown_
10458         }
10459         catch ( final Exception e ) {
10460             e.printStackTrace( System.out );
10461             return false;
10462         }
10463         return true;
10464     }
10465 }