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