bugfix
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.test;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Set;
39
40 import org.forester.application.support_transfer;
41 import org.forester.archaeopteryx.AptxUtil;
42 import org.forester.development.DevelopmentTools;
43 import org.forester.evoinference.TestPhylogenyReconstruction;
44 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
46 import org.forester.go.TestGo;
47 import org.forester.io.parsers.FastaParser;
48 import org.forester.io.parsers.GeneralMsaParser;
49 import org.forester.io.parsers.HmmscanPerDomainTableParser;
50 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
51 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
52 import org.forester.io.parsers.nexus.NexusCharactersParser;
53 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
54 import org.forester.io.parsers.nhx.NHXParser;
55 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
56 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
57 import org.forester.io.parsers.tol.TolParser;
58 import org.forester.io.parsers.util.ParserUtils;
59 import org.forester.io.writers.PhylogenyWriter;
60 import org.forester.io.writers.SequenceWriter;
61 import org.forester.msa.BasicMsa;
62 import org.forester.msa.Mafft;
63 import org.forester.msa.Msa;
64 import org.forester.msa.MsaInferrer;
65 import org.forester.msa.MsaMethods;
66 import org.forester.pccx.TestPccx;
67 import org.forester.phylogeny.Phylogeny;
68 import org.forester.phylogeny.PhylogenyBranch;
69 import org.forester.phylogeny.PhylogenyMethods;
70 import org.forester.phylogeny.PhylogenyNode;
71 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
72 import org.forester.phylogeny.data.Accession;
73 import org.forester.phylogeny.data.BinaryCharacters;
74 import org.forester.phylogeny.data.BranchWidth;
75 import org.forester.phylogeny.data.Confidence;
76 import org.forester.phylogeny.data.Distribution;
77 import org.forester.phylogeny.data.DomainArchitecture;
78 import org.forester.phylogeny.data.Event;
79 import org.forester.phylogeny.data.Identifier;
80 import org.forester.phylogeny.data.PhylogenyData;
81 import org.forester.phylogeny.data.PhylogenyDataUtil;
82 import org.forester.phylogeny.data.Polygon;
83 import org.forester.phylogeny.data.PropertiesMap;
84 import org.forester.phylogeny.data.Property;
85 import org.forester.phylogeny.data.Property.AppliesTo;
86 import org.forester.phylogeny.data.ProteinDomain;
87 import org.forester.phylogeny.data.Taxonomy;
88 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
89 import org.forester.phylogeny.factories.PhylogenyFactory;
90 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
91 import org.forester.protein.Protein;
92 import org.forester.rio.TestRIO;
93 import org.forester.sdi.SDI;
94 import org.forester.sdi.SDIR;
95 import org.forester.sdi.TestGSDI;
96 import org.forester.sequence.BasicSequence;
97 import org.forester.sequence.Sequence;
98 import org.forester.surfacing.TestSurfacing;
99 import org.forester.tools.ConfidenceAssessor;
100 import org.forester.tools.SupportCount;
101 import org.forester.tools.TreeSplitMatrix;
102 import org.forester.util.AsciiHistogram;
103 import org.forester.util.BasicDescriptiveStatistics;
104 import org.forester.util.BasicTable;
105 import org.forester.util.BasicTableParser;
106 import org.forester.util.DescriptiveStatistics;
107 import org.forester.util.ForesterConstants;
108 import org.forester.util.ForesterUtil;
109 import org.forester.util.GeneralTable;
110 import org.forester.util.SequenceIdParser;
111 import org.forester.ws.seqdb.SequenceDatabaseEntry;
112 import org.forester.ws.seqdb.SequenceDbWsTools;
113 import org.forester.ws.seqdb.UniProtTaxonomy;
114 import org.forester.ws.wabi.TxSearch;
115 import org.forester.ws.wabi.TxSearch.RANKS;
116 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
117 import org.forester.ws.wabi.TxSearch.TAX_RANK;
118
119 @SuppressWarnings( "unused")
120 public final class Test {
121
122     private final static double  ZERO_DIFF                 = 1.0E-9;
123     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
124                                                                    + ForesterUtil.getFileSeparator() + "test_data"
125                                                                    + ForesterUtil.getFileSeparator();
126     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
127                                                                    + ForesterUtil.getFileSeparator() + "resources"
128                                                                    + ForesterUtil.getFileSeparator();
129     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
130     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
131                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
132                                                                    + ForesterConstants.PHYLO_XML_XSD;
133     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
134                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
135                                                                    + ForesterConstants.PHYLO_XML_XSD;
136
137     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
138         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
139         return p;
140     }
141
142     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
143         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
144     }
145
146     public static boolean isEqual( final double a, final double b ) {
147         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
148     }
149
150     public static void main( final String[] args ) {
151         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
152         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
153                 + "]" );
154         Locale.setDefault( Locale.US );
155         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
156         int failed = 0;
157         int succeeded = 0;
158         System.out.print( "[Test if directory with files for testing exists/is readable: " );
159         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
160             System.out.println( "OK.]" );
161         }
162         else {
163             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
164             System.out.println( "Testing aborted." );
165             System.exit( -1 );
166         }
167         System.out.print( "[Test if resources directory exists/is readable: " );
168         if ( testDir( PATH_TO_RESOURCES ) ) {
169             System.out.println( "OK.]" );
170         }
171         else {
172             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
173             System.out.println( "Testing aborted." );
174             System.exit( -1 );
175         }
176         final long start_time = new Date().getTime();
177         System.out.print( "Sequence writer: " );
178         if ( testSequenceWriter() ) {
179             System.out.println( "OK." );
180             succeeded++;
181         }
182         else {
183             System.out.println( "failed." );
184             failed++;
185         }
186         System.out.print( "Sequence id parsing: " );
187         if ( testSequenceIdParsing() ) {
188             System.out.println( "OK." );
189             succeeded++;
190         }
191         else {
192             System.out.println( "failed." );
193             failed++;
194         }
195         System.out.print( "Hmmscan output parser: " );
196         if ( testHmmscanOutputParser() ) {
197             System.out.println( "OK." );
198             succeeded++;
199         }
200         else {
201             System.out.println( "failed." );
202             failed++;
203         }
204         System.out.print( "Basic node methods: " );
205         if ( Test.testBasicNodeMethods() ) {
206             System.out.println( "OK." );
207             succeeded++;
208         }
209         else {
210             System.out.println( "failed." );
211             failed++;
212         }
213         System.out.print( "Taxonomy code extraction: " );
214         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
215             System.out.println( "OK." );
216             succeeded++;
217         }
218         else {
219             System.out.println( "failed." );
220             failed++;
221         }
222         System.out.print( "Taxonomy extraction (general): " );
223         if ( Test.testTaxonomyExtraction() ) {
224             System.out.println( "OK." );
225             succeeded++;
226         }
227         else {
228             System.out.println( "failed." );
229             failed++;
230         }
231         System.out.print( "UniProtKB id extraction: " );
232         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
233             System.out.println( "OK." );
234             succeeded++;
235         }
236         else {
237             System.out.println( "failed." );
238             failed++;
239         }
240         System.out.print( "Uri for Aptx web sequence accession: " );
241         if ( Test.testCreateUriForSeqWeb() ) {
242             System.out.println( "OK." );
243             succeeded++;
244         }
245         else {
246             System.out.println( "failed." );
247             failed++;
248         }
249         System.out.print( "Basic node construction and parsing of NHX (node level): " );
250         if ( Test.testNHXNodeParsing() ) {
251             System.out.println( "OK." );
252             succeeded++;
253         }
254         else {
255             System.out.println( "failed." );
256             failed++;
257         }
258         System.out.print( "NHX parsing iterating: " );
259         if ( Test.testNHParsingIter() ) {
260             System.out.println( "OK." );
261             succeeded++;
262         }
263         else {
264             System.out.println( "failed." );
265             failed++;
266         }
267         System.out.print( "NH parsing: " );
268         if ( Test.testNHParsing() ) {
269             System.out.println( "OK." );
270             succeeded++;
271         }
272         else {
273             System.out.println( "failed." );
274             failed++;
275         }
276         System.out.print( "Conversion to NHX (node level): " );
277         if ( Test.testNHXconversion() ) {
278             System.out.println( "OK." );
279             succeeded++;
280         }
281         else {
282             System.out.println( "failed." );
283             failed++;
284         }
285         System.out.print( "NHX parsing: " );
286         if ( Test.testNHXParsing() ) {
287             System.out.println( "OK." );
288             succeeded++;
289         }
290         else {
291             System.out.println( "failed." );
292             failed++;
293         }
294         System.out.print( "NHX parsing with quotes: " );
295         if ( Test.testNHXParsingQuotes() ) {
296             System.out.println( "OK." );
297             succeeded++;
298         }
299         else {
300             System.out.println( "failed." );
301             failed++;
302         }
303         System.out.print( "NHX parsing (MrBayes): " );
304         if ( Test.testNHXParsingMB() ) {
305             System.out.println( "OK." );
306             succeeded++;
307         }
308         else {
309             System.out.println( "failed." );
310             failed++;
311         }
312         System.out.print( "Nexus characters parsing: " );
313         if ( Test.testNexusCharactersParsing() ) {
314             System.out.println( "OK." );
315             succeeded++;
316         }
317         else {
318             System.out.println( "failed." );
319             failed++;
320         }
321         System.out.print( "Nexus tree parsing iterating: " );
322         if ( Test.testNexusTreeParsingIterating() ) {
323             System.out.println( "OK." );
324             succeeded++;
325         }
326         else {
327             System.out.println( "failed." );
328             failed++;
329         }
330         System.out.print( "Nexus tree parsing: " );
331         if ( Test.testNexusTreeParsing() ) {
332             System.out.println( "OK." );
333             succeeded++;
334         }
335         else {
336             System.out.println( "failed." );
337             failed++;
338         }
339         System.out.print( "Nexus tree parsing (translating): " );
340         if ( Test.testNexusTreeParsingTranslating() ) {
341             System.out.println( "OK." );
342             succeeded++;
343         }
344         else {
345             System.out.println( "failed." );
346             failed++;
347         }
348         System.out.print( "Nexus matrix parsing: " );
349         if ( Test.testNexusMatrixParsing() ) {
350             System.out.println( "OK." );
351             succeeded++;
352         }
353         else {
354             System.out.println( "failed." );
355             failed++;
356         }
357         System.out.print( "Basic phyloXML parsing: " );
358         if ( Test.testBasicPhyloXMLparsing() ) {
359             System.out.println( "OK." );
360             succeeded++;
361         }
362         else {
363             System.out.println( "failed." );
364             failed++;
365         }
366         System.out.print( "Basic phyloXML parsing (validating against schema): " );
367         if ( testBasicPhyloXMLparsingValidating() ) {
368             System.out.println( "OK." );
369             succeeded++;
370         }
371         else {
372             System.out.println( "failed." );
373             failed++;
374         }
375         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
376         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
377             System.out.println( "OK." );
378             succeeded++;
379         }
380         else {
381             System.out.println( "failed." );
382             failed++;
383         }
384         System.out.print( "phyloXML Distribution Element: " );
385         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
386             System.out.println( "OK." );
387             succeeded++;
388         }
389         else {
390             System.out.println( "failed." );
391             failed++;
392         }
393         System.out.print( "Tol XML parsing: " );
394         if ( Test.testBasicTolXMLparsing() ) {
395             System.out.println( "OK." );
396             succeeded++;
397         }
398         else {
399             System.out.println( "failed." );
400             failed++;
401         }
402         System.out.print( "Copying of node data: " );
403         if ( Test.testCopyOfNodeData() ) {
404             System.out.println( "OK." );
405             succeeded++;
406         }
407         else {
408             System.out.println( "failed." );
409             failed++;
410         }
411         System.out.print( "Basic tree methods: " );
412         if ( Test.testBasicTreeMethods() ) {
413             System.out.println( "OK." );
414             succeeded++;
415         }
416         else {
417             System.out.println( "failed." );
418             failed++;
419         }
420         System.out.print( "Tree methods: " );
421         if ( Test.testTreeMethods() ) {
422             System.out.println( "OK." );
423             succeeded++;
424         }
425         else {
426             System.out.println( "failed." );
427             failed++;
428         }
429         System.out.print( "Postorder Iterator: " );
430         if ( Test.testPostOrderIterator() ) {
431             System.out.println( "OK." );
432             succeeded++;
433         }
434         else {
435             System.out.println( "failed." );
436             failed++;
437         }
438         System.out.print( "Preorder Iterator: " );
439         if ( Test.testPreOrderIterator() ) {
440             System.out.println( "OK." );
441             succeeded++;
442         }
443         else {
444             System.out.println( "failed." );
445             failed++;
446         }
447         System.out.print( "Levelorder Iterator: " );
448         if ( Test.testLevelOrderIterator() ) {
449             System.out.println( "OK." );
450             succeeded++;
451         }
452         else {
453             System.out.println( "failed." );
454             failed++;
455         }
456         System.out.print( "Re-id methods: " );
457         if ( Test.testReIdMethods() ) {
458             System.out.println( "OK." );
459             succeeded++;
460         }
461         else {
462             System.out.println( "failed." );
463             failed++;
464         }
465         System.out.print( "Methods on last external nodes: " );
466         if ( Test.testLastExternalNodeMethods() ) {
467             System.out.println( "OK." );
468             succeeded++;
469         }
470         else {
471             System.out.println( "failed." );
472             failed++;
473         }
474         System.out.print( "Methods on external nodes: " );
475         if ( Test.testExternalNodeRelatedMethods() ) {
476             System.out.println( "OK." );
477             succeeded++;
478         }
479         else {
480             System.out.println( "failed." );
481             failed++;
482         }
483         System.out.print( "Deletion of external nodes: " );
484         if ( Test.testDeletionOfExternalNodes() ) {
485             System.out.println( "OK." );
486             succeeded++;
487         }
488         else {
489             System.out.println( "failed." );
490             failed++;
491         }
492         System.out.print( "Subtree deletion: " );
493         if ( Test.testSubtreeDeletion() ) {
494             System.out.println( "OK." );
495             succeeded++;
496         }
497         else {
498             System.out.println( "failed." );
499             failed++;
500         }
501         System.out.print( "Phylogeny branch: " );
502         if ( Test.testPhylogenyBranch() ) {
503             System.out.println( "OK." );
504             succeeded++;
505         }
506         else {
507             System.out.println( "failed." );
508             failed++;
509         }
510         System.out.print( "Rerooting: " );
511         if ( Test.testRerooting() ) {
512             System.out.println( "OK." );
513             succeeded++;
514         }
515         else {
516             System.out.println( "failed." );
517             failed++;
518         }
519         System.out.print( "Mipoint rooting: " );
520         if ( Test.testMidpointrooting() ) {
521             System.out.println( "OK." );
522             succeeded++;
523         }
524         else {
525             System.out.println( "failed." );
526             failed++;
527         }
528         System.out.print( "Node removal: " );
529         if ( Test.testNodeRemoval() ) {
530             System.out.println( "OK." );
531             succeeded++;
532         }
533         else {
534             System.out.println( "failed." );
535             failed++;
536         }
537         System.out.print( "Support count: " );
538         if ( Test.testSupportCount() ) {
539             System.out.println( "OK." );
540             succeeded++;
541         }
542         else {
543             System.out.println( "failed." );
544             failed++;
545         }
546         System.out.print( "Support transfer: " );
547         if ( Test.testSupportTransfer() ) {
548             System.out.println( "OK." );
549             succeeded++;
550         }
551         else {
552             System.out.println( "failed." );
553             failed++;
554         }
555         System.out.print( "Finding of LCA: " );
556         if ( Test.testGetLCA() ) {
557             System.out.println( "OK." );
558             succeeded++;
559         }
560         else {
561             System.out.println( "failed." );
562             failed++;
563         }
564         System.out.print( "Finding of LCA 2: " );
565         if ( Test.testGetLCA2() ) {
566             System.out.println( "OK." );
567             succeeded++;
568         }
569         else {
570             System.out.println( "failed." );
571             failed++;
572         }
573         System.out.print( "Calculation of distance between nodes: " );
574         if ( Test.testGetDistance() ) {
575             System.out.println( "OK." );
576             succeeded++;
577         }
578         else {
579             System.out.println( "failed." );
580             failed++;
581         }
582         System.out.print( "Descriptive statistics: " );
583         if ( Test.testDescriptiveStatistics() ) {
584             System.out.println( "OK." );
585             succeeded++;
586         }
587         else {
588             System.out.println( "failed." );
589             failed++;
590         }
591         System.out.print( "Data objects and methods: " );
592         if ( Test.testDataObjects() ) {
593             System.out.println( "OK." );
594             succeeded++;
595         }
596         else {
597             System.out.println( "failed." );
598             failed++;
599         }
600         System.out.print( "Properties map: " );
601         if ( Test.testPropertiesMap() ) {
602             System.out.println( "OK." );
603             succeeded++;
604         }
605         else {
606             System.out.println( "failed." );
607             failed++;
608         }
609         System.out.print( "SDIse: " );
610         if ( Test.testSDIse() ) {
611             System.out.println( "OK." );
612             succeeded++;
613         }
614         else {
615             System.out.println( "failed." );
616             failed++;
617         }
618         System.out.print( "SDIunrooted: " );
619         if ( Test.testSDIunrooted() ) {
620             System.out.println( "OK." );
621             succeeded++;
622         }
623         else {
624             System.out.println( "failed." );
625             failed++;
626         }
627         System.out.print( "GSDI: " );
628         if ( TestGSDI.test() ) {
629             System.out.println( "OK." );
630             succeeded++;
631         }
632         else {
633             System.out.println( "failed." );
634             failed++;
635         }
636         System.out.print( "RIO: " );
637         if ( TestRIO.test() ) {
638             System.out.println( "OK." );
639             succeeded++;
640         }
641         else {
642             System.out.println( "failed." );
643             failed++;
644         }
645         System.out.print( "Phylogeny reconstruction:" );
646         System.out.println();
647         if ( TestPhylogenyReconstruction.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( "Analysis of domain architectures: " );
656         System.out.println();
657         if ( TestSurfacing.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( "GO: " );
666         System.out.println();
667         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
668             System.out.println( "OK." );
669             succeeded++;
670         }
671         else {
672             System.out.println( "failed." );
673             failed++;
674         }
675         System.out.print( "Modeling tools: " );
676         if ( TestPccx.test() ) {
677             System.out.println( "OK." );
678             succeeded++;
679         }
680         else {
681             System.out.println( "failed." );
682             failed++;
683         }
684         System.out.print( "Split Matrix strict: " );
685         if ( Test.testSplitStrict() ) {
686             System.out.println( "OK." );
687             succeeded++;
688         }
689         else {
690             System.out.println( "failed." );
691             failed++;
692         }
693         System.out.print( "Split Matrix: " );
694         if ( Test.testSplit() ) {
695             System.out.println( "OK." );
696             succeeded++;
697         }
698         else {
699             System.out.println( "failed." );
700             failed++;
701         }
702         System.out.print( "Confidence Assessor: " );
703         if ( Test.testConfidenceAssessor() ) {
704             System.out.println( "OK." );
705             succeeded++;
706         }
707         else {
708             System.out.println( "failed." );
709             failed++;
710         }
711         System.out.print( "Basic table: " );
712         if ( Test.testBasicTable() ) {
713             System.out.println( "OK." );
714             succeeded++;
715         }
716         else {
717             System.out.println( "failed." );
718             failed++;
719         }
720         System.out.print( "General table: " );
721         if ( Test.testGeneralTable() ) {
722             System.out.println( "OK." );
723             succeeded++;
724         }
725         else {
726             System.out.println( "failed." );
727             failed++;
728         }
729         System.out.print( "Amino acid sequence: " );
730         if ( Test.testAminoAcidSequence() ) {
731             System.out.println( "OK." );
732             succeeded++;
733         }
734         else {
735             System.out.println( "failed." );
736             failed++;
737         }
738         System.out.print( "General MSA parser: " );
739         if ( Test.testGeneralMsaParser() ) {
740             System.out.println( "OK." );
741             succeeded++;
742         }
743         else {
744             System.out.println( "failed." );
745             failed++;
746         }
747         System.out.print( "Fasta parser for msa: " );
748         if ( Test.testFastaParser() ) {
749             System.out.println( "OK." );
750             succeeded++;
751         }
752         else {
753             System.out.println( "failed." );
754             failed++;
755         }
756         System.out.print( "Creation of balanced phylogeny: " );
757         if ( Test.testCreateBalancedPhylogeny() ) {
758             System.out.println( "OK." );
759             succeeded++;
760         }
761         else {
762             System.out.println( "failed." );
763             failed++;
764         }
765         System.out.print( "EMBL Entry Retrieval: " );
766         if ( Test.testEmblEntryRetrieval() ) {
767             System.out.println( "OK." );
768             succeeded++;
769         }
770         else {
771             System.out.println( "failed." );
772             failed++;
773         }
774         System.out.print( "Uniprot Entry Retrieval: " );
775         if ( Test.testUniprotEntryRetrieval() ) {
776             System.out.println( "OK." );
777             succeeded++;
778         }
779         else {
780             System.out.println( "failed." );
781             failed++;
782         }
783         System.out.print( "Uniprot Taxonomy Search: " );
784         if ( Test.testUniprotTaxonomySearch() ) {
785             System.out.println( "OK." );
786             succeeded++;
787         }
788         else {
789             System.out.println( "failed." );
790             failed++;
791         }
792         //----
793         String path = "";
794         final String os = ForesterUtil.OS_NAME.toLowerCase();
795         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
796             path = "/usr/local/bin/mafft";
797         }
798         else if ( os.indexOf( "win" ) >= 0 ) {
799             path = "C:\\Program Files\\mafft-win\\mafft.bat";
800         }
801         else {
802             path = "/home/czmasek/bin/mafft";
803         }
804         if ( !MsaInferrer.isInstalled( path ) ) {
805             path = "mafft";
806         }
807         if ( !MsaInferrer.isInstalled( path ) ) {
808             path = "/usr/local/bin/mafft";
809         }
810         if ( MsaInferrer.isInstalled( path ) ) {
811             System.out.print( "MAFFT (external program): " );
812             if ( Test.testMafft( path ) ) {
813                 System.out.println( "OK." );
814                 succeeded++;
815             }
816             else {
817                 System.out.println( "failed [will not count towards failed tests]" );
818             }
819         }
820         //----
821         System.out.print( "Next nodes with collapsed: " );
822         if ( Test.testNextNodeWithCollapsing() ) {
823             System.out.println( "OK." );
824             succeeded++;
825         }
826         else {
827             System.out.println( "failed." );
828             failed++;
829         }
830         System.out.print( "Simple MSA quality: " );
831         if ( Test.testMsaQualityMethod() ) {
832             System.out.println( "OK." );
833             succeeded++;
834         }
835         else {
836             System.out.println( "failed." );
837             failed++;
838         }
839         System.out.println();
840         final Runtime rt = java.lang.Runtime.getRuntime();
841         final long free_memory = rt.freeMemory() / 1000000;
842         final long total_memory = rt.totalMemory() / 1000000;
843         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
844                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
845         System.out.println();
846         System.out.println( "Successful tests: " + succeeded );
847         System.out.println( "Failed     tests: " + failed );
848         System.out.println();
849         if ( failed < 1 ) {
850             System.out.println( "OK." );
851         }
852         else {
853             System.out.println( "Not OK." );
854         }
855     }
856
857     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
858         try {
859             PhylogenyNode n = new PhylogenyNode();
860             n.setName( "tr|B3RJ64" );
861             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
862                 return false;
863             }
864             n.setName( "tr.B3RJ64" );
865             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
866                 return false;
867             }
868             n.setName( "tr=B3RJ64" );
869             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
870                 return false;
871             }
872             n.setName( "tr-B3RJ64" );
873             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
874                 return false;
875             }
876             n.setName( "tr/B3RJ64" );
877             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
878                 return false;
879             }
880             n.setName( "tr\\B3RJ64" );
881             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
882                 return false;
883             }
884             n.setName( "tr_B3RJ64" );
885             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
886                 return false;
887             }
888             n.setName( " tr|B3RJ64 " );
889             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
890                 return false;
891             }
892             n.setName( "-tr|B3RJ64-" );
893             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
894                 return false;
895             }
896             n.setName( "-tr=B3RJ64-" );
897             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
898                 return false;
899             }
900             n.setName( "_tr=B3RJ64_" );
901             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
902                 return false;
903             }
904             n.setName( " tr_tr|B3RJ64_sp|123 " );
905             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
906                 return false;
907             }
908             n.setName( "sp|B3RJ64" );
909             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
910                 return false;
911             }
912             n.setName( "ssp|B3RJ64" );
913             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
914                 return false;
915             }
916             n.setName( "sp|B3RJ64C" );
917             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
918                 return false;
919             }
920             n.setName( "sp B3RJ64" );
921             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
922                 return false;
923             }
924             n.setName( "sp|B3RJ6X" );
925             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
926                 return false;
927             }
928             n.setName( "sp|B3RJ6" );
929             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
930                 return false;
931             }
932             n.setName( "K1PYK7_CRAGI" );
933             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
934                 return false;
935             }
936             n.setName( "K1PYK7_PEA" );
937             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) {
938                 return false;
939             }
940             n.setName( "K1PYK7_RAT" );
941             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) {
942                 return false;
943             }
944             n.setName( "K1PYK7_PIG" );
945             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
946                 return false;
947             }
948             n.setName( "~K1PYK7_PIG~" );
949             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
950                 return false;
951             }
952             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
953             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
954                 return false;
955             }
956             n.setName( "K1PYKX_CRAGI" );
957             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
958                 return false;
959             }
960             n.setName( "XXXXX_CRAGI" );
961             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) {
962                 return false;
963             }
964             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
965             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) {
966                 return false;
967             }
968             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
969             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
970                 return false;
971             }
972             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
973             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) {
974                 return false;
975             }
976             n = new PhylogenyNode();
977             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
978             seq.setSymbol( "K1PYK7_CRAGI" );
979             n.getNodeData().addSequence( seq );
980             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
981                 return false;
982             }
983             seq.setSymbol( "tr|B3RJ64" );
984             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
985                 return false;
986             }
987             n = new PhylogenyNode();
988             seq = new org.forester.phylogeny.data.Sequence();
989             seq.setName( "K1PYK7_CRAGI" );
990             n.getNodeData().addSequence( seq );
991             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
992                 return false;
993             }
994             seq.setName( "tr|B3RJ64" );
995             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
996                 return false;
997             }
998             n = new PhylogenyNode();
999             seq = new org.forester.phylogeny.data.Sequence();
1000             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
1001             n.getNodeData().addSequence( seq );
1002             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) {
1003                 return false;
1004             }
1005             n = new PhylogenyNode();
1006             seq = new org.forester.phylogeny.data.Sequence();
1007             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
1008             n.getNodeData().addSequence( seq );
1009             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
1010                 return false;
1011             }
1012             //
1013             n = new PhylogenyNode();
1014             n.setName( "ACP19736" );
1015             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1016                 return false;
1017             }
1018             n = new PhylogenyNode();
1019             n.setName( "_ACP19736_" );
1020             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1021                 return false;
1022             }
1023         }
1024         catch ( final Exception e ) {
1025             e.printStackTrace( System.out );
1026             return false;
1027         }
1028         return true;
1029     }
1030
1031     private static boolean testCreateUriForSeqWeb() {
1032         try {
1033             final PhylogenyNode n = new PhylogenyNode();
1034             n.setName( "tr|B3RJ64" );
1035             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
1036                 return false;
1037             }
1038             n.setName( "B0LM41_HUMAN" );
1039             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
1040                 return false;
1041             }
1042             n.setName( "NP_001025424" );
1043             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
1044                 return false;
1045             }
1046             n.setName( "_NM_001030253-" );
1047             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
1048                 return false;
1049             }
1050             n.setName( "XM_002122186" );
1051             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
1052                 return false;
1053             }
1054             n.setName( "dgh_AAA34956_gdg" );
1055             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
1056                 return false;
1057             }
1058             n.setName( "j40f4_Q06891.1_fndn2 fnr3" );
1059             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891.1" ) ) {
1060                 return false;
1061             }
1062             n.setName( "GI:394892" );
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             n.setName( "gi_394892" );
1068             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1069                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1070                 return false;
1071             }
1072             n.setName( "gi6335_gi_394892_56635_Gi_43" );
1073             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1074                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1075                 return false;
1076             }
1077         }
1078         catch ( final Exception e ) {
1079             e.printStackTrace( System.out );
1080             return false;
1081         }
1082         return true;
1083     }
1084
1085     private static boolean testExtractTaxonomyCodeFromNodeName() {
1086         try {
1087             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1088                     .equals( "MOUSE" ) ) {
1089                 return false;
1090             }
1091             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1092                     .equals( "RAT" ) ) {
1093                 return false;
1094             }
1095             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
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_MOUSE_function = 23445",
1104                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1105                     .equals( "MOUSE" ) ) {
1106                 return false;
1107             }
1108             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
1109                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1110                     .equals( "MOUSE" ) ) {
1111                 return false;
1112             }
1113             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
1114                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1115                 return false;
1116             }
1117             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
1118                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1119                 return false;
1120             }
1121             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1122                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1123                 return false;
1124             }
1125             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445",
1126                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1127                 return false;
1128             }
1129             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
1130                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1131                 return false;
1132             }
1133             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
1134                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1135                 return false;
1136             }
1137             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
1138                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1139                 return false;
1140             }
1141             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1142                     .equals( "RAT" ) ) {
1143                 return false;
1144             }
1145             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1146                     .equals( "PIG" ) ) {
1147                 return false;
1148             }
1149             if ( !ParserUtils
1150                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1151                     .equals( "MOUSE" ) ) {
1152                 return false;
1153             }
1154             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1155                     .equals( "MOUSE" ) ) {
1156                 return false;
1157             }
1158             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1159                     .equals( "MOUSE" ) ) {
1160                 return false;
1161             }
1162             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1163                     .equals( "MOUSE" ) ) {
1164                 return false;
1165             }
1166             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ) != null ) {
1167                 return false;
1168             }
1169             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "x_MOUSE_x", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1170                     .equals( "MOUSE" ) ) {
1171                 return false;
1172             }
1173         }
1174         catch ( final Exception e ) {
1175             e.printStackTrace( System.out );
1176             return false;
1177         }
1178         return true;
1179     }
1180
1181     private static boolean testBasicNodeMethods() {
1182         try {
1183             if ( PhylogenyNode.getNodeCount() != 0 ) {
1184                 return false;
1185             }
1186             final PhylogenyNode n1 = new PhylogenyNode();
1187             final PhylogenyNode n2 = PhylogenyNode
1188                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1189             final PhylogenyNode n3 = PhylogenyNode
1190                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1191             final PhylogenyNode n4 = PhylogenyNode
1192                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1193             if ( n1.isHasAssignedEvent() ) {
1194                 return false;
1195             }
1196             if ( PhylogenyNode.getNodeCount() != 4 ) {
1197                 return false;
1198             }
1199             if ( n3.getIndicator() != 0 ) {
1200                 return false;
1201             }
1202             if ( n3.getNumberOfExternalNodes() != 1 ) {
1203                 return false;
1204             }
1205             if ( !n3.isExternal() ) {
1206                 return false;
1207             }
1208             if ( !n3.isRoot() ) {
1209                 return false;
1210             }
1211             if ( !n4.getName().equals( "n4" ) ) {
1212                 return false;
1213             }
1214         }
1215         catch ( final Exception e ) {
1216             e.printStackTrace( System.out );
1217             return false;
1218         }
1219         return true;
1220     }
1221
1222     private static boolean testBasicPhyloXMLparsing() {
1223         try {
1224             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1225             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1226             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1227                                                               xml_parser );
1228             if ( xml_parser.getErrorCount() > 0 ) {
1229                 System.out.println( xml_parser.getErrorMessages().toString() );
1230                 return false;
1231             }
1232             if ( phylogenies_0.length != 4 ) {
1233                 return false;
1234             }
1235             final Phylogeny t1 = phylogenies_0[ 0 ];
1236             final Phylogeny t2 = phylogenies_0[ 1 ];
1237             final Phylogeny t3 = phylogenies_0[ 2 ];
1238             final Phylogeny t4 = phylogenies_0[ 3 ];
1239             if ( t1.getNumberOfExternalNodes() != 1 ) {
1240                 return false;
1241             }
1242             if ( !t1.isRooted() ) {
1243                 return false;
1244             }
1245             if ( t1.isRerootable() ) {
1246                 return false;
1247             }
1248             if ( !t1.getType().equals( "gene_tree" ) ) {
1249                 return false;
1250             }
1251             if ( t2.getNumberOfExternalNodes() != 2 ) {
1252                 return false;
1253             }
1254             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1255                 return false;
1256             }
1257             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1258                 return false;
1259             }
1260             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1261                 return false;
1262             }
1263             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1264                 return false;
1265             }
1266             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1267                 return false;
1268             }
1269             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1270                 return false;
1271             }
1272             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1273                     .startsWith( "actgtgggggt" ) ) {
1274                 return false;
1275             }
1276             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1277                     .startsWith( "ctgtgatgcat" ) ) {
1278                 return false;
1279             }
1280             if ( t3.getNumberOfExternalNodes() != 4 ) {
1281                 return false;
1282             }
1283             if ( !t1.getName().equals( "t1" ) ) {
1284                 return false;
1285             }
1286             if ( !t2.getName().equals( "t2" ) ) {
1287                 return false;
1288             }
1289             if ( !t3.getName().equals( "t3" ) ) {
1290                 return false;
1291             }
1292             if ( !t4.getName().equals( "t4" ) ) {
1293                 return false;
1294             }
1295             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1296                 return false;
1297             }
1298             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1299                 return false;
1300             }
1301             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1302                 return false;
1303             }
1304             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1305                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1306                 return false;
1307             }
1308             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1309                 return false;
1310             }
1311             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1312                 return false;
1313             }
1314             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1315                 return false;
1316             }
1317             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1318                     .equals( "apoptosis" ) ) {
1319                 return false;
1320             }
1321             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1322                     .equals( "GO:0006915" ) ) {
1323                 return false;
1324             }
1325             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1326                     .equals( "UniProtKB" ) ) {
1327                 return false;
1328             }
1329             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1330                     .equals( "experimental" ) ) {
1331                 return false;
1332             }
1333             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1334                     .equals( "function" ) ) {
1335                 return false;
1336             }
1337             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1338                     .getValue() != 1 ) {
1339                 return false;
1340             }
1341             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1342                     .getType().equals( "ml" ) ) {
1343                 return false;
1344             }
1345             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1346                     .equals( "apoptosis" ) ) {
1347                 return false;
1348             }
1349             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1350                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1351                 return false;
1352             }
1353             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1354                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1355                 return false;
1356             }
1357             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1358                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1359                 return false;
1360             }
1361             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1362                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1363                 return false;
1364             }
1365             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1366                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1367                 return false;
1368             }
1369             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1370                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1371                 return false;
1372             }
1373             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1374                     .equals( "GO:0005829" ) ) {
1375                 return false;
1376             }
1377             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1378                     .equals( "intracellular organelle" ) ) {
1379                 return false;
1380             }
1381             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1382                 return false;
1383             }
1384             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1385                     .equals( "UniProt link" ) ) ) {
1386                 return false;
1387             }
1388             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1389                 return false;
1390             }
1391         }
1392         catch ( final Exception e ) {
1393             e.printStackTrace( System.out );
1394             return false;
1395         }
1396         return true;
1397     }
1398
1399     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1400         try {
1401             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1402             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1403             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1404                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1405             }
1406             else {
1407                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1408             }
1409             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1410                                                               xml_parser );
1411             if ( xml_parser.getErrorCount() > 0 ) {
1412                 System.out.println( xml_parser.getErrorMessages().toString() );
1413                 return false;
1414             }
1415             if ( phylogenies_0.length != 4 ) {
1416                 return false;
1417             }
1418             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1419             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1420             if ( phylogenies_t1.length != 1 ) {
1421                 return false;
1422             }
1423             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1424             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1425                 return false;
1426             }
1427             if ( !t1_rt.isRooted() ) {
1428                 return false;
1429             }
1430             if ( t1_rt.isRerootable() ) {
1431                 return false;
1432             }
1433             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1434                 return false;
1435             }
1436             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1437             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1438             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1439             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1440                 return false;
1441             }
1442             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1443                 return false;
1444             }
1445             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1446                 return false;
1447             }
1448             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1449                 return false;
1450             }
1451             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1452                     .startsWith( "actgtgggggt" ) ) {
1453                 return false;
1454             }
1455             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1456                     .startsWith( "ctgtgatgcat" ) ) {
1457                 return false;
1458             }
1459             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1460             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1461             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1462             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1463             if ( phylogenies_1.length != 1 ) {
1464                 return false;
1465             }
1466             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1467             if ( !t3_rt.getName().equals( "t3" ) ) {
1468                 return false;
1469             }
1470             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1471                 return false;
1472             }
1473             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1474                 return false;
1475             }
1476             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1477                 return false;
1478             }
1479             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1480                 return false;
1481             }
1482             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1483                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1484                 return false;
1485             }
1486             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1487                 return false;
1488             }
1489             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1490                 return false;
1491             }
1492             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1493                     .equals( "UniProtKB" ) ) {
1494                 return false;
1495             }
1496             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1497                     .equals( "apoptosis" ) ) {
1498                 return false;
1499             }
1500             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1501                     .equals( "GO:0006915" ) ) {
1502                 return false;
1503             }
1504             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1505                     .equals( "UniProtKB" ) ) {
1506                 return false;
1507             }
1508             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1509                     .equals( "experimental" ) ) {
1510                 return false;
1511             }
1512             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1513                     .equals( "function" ) ) {
1514                 return false;
1515             }
1516             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1517                     .getValue() != 1 ) {
1518                 return false;
1519             }
1520             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1521                     .getType().equals( "ml" ) ) {
1522                 return false;
1523             }
1524             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1525                     .equals( "apoptosis" ) ) {
1526                 return false;
1527             }
1528             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1529                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1530                 return false;
1531             }
1532             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1533                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1534                 return false;
1535             }
1536             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1537                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1538                 return false;
1539             }
1540             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1541                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1542                 return false;
1543             }
1544             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1545                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1546                 return false;
1547             }
1548             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1549                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1550                 return false;
1551             }
1552             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1553                     .equals( "GO:0005829" ) ) {
1554                 return false;
1555             }
1556             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1557                     .equals( "intracellular organelle" ) ) {
1558                 return false;
1559             }
1560             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1561                 return false;
1562             }
1563             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1564                     .equals( "UniProt link" ) ) ) {
1565                 return false;
1566             }
1567             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1568                 return false;
1569             }
1570             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1571                 return false;
1572             }
1573             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1574                     .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." ) ) ) {
1575                 return false;
1576             }
1577             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1578                 return false;
1579             }
1580             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1581                 return false;
1582             }
1583             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1584                 return false;
1585             }
1586             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1587                 return false;
1588             }
1589             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1590                     .equals( "ncbi" ) ) {
1591                 return false;
1592             }
1593             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1594                 return false;
1595             }
1596             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1597                     .getName().equals( "B" ) ) {
1598                 return false;
1599             }
1600             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1601                     .getFrom() != 21 ) {
1602                 return false;
1603             }
1604             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1605                 return false;
1606             }
1607             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1608                     .getLength() != 24 ) {
1609                 return false;
1610             }
1611             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1612                     .getConfidence() != 2144 ) {
1613                 return false;
1614             }
1615             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1616                     .equals( "pfam" ) ) {
1617                 return false;
1618             }
1619             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1620                 return false;
1621             }
1622             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1623                 return false;
1624             }
1625             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1626                 return false;
1627             }
1628             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1629                 return false;
1630             }
1631             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1632             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1633                 return false;
1634             }
1635             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1636                 return false;
1637             }
1638             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1639                 return false;
1640             }
1641             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1642                 return false;
1643             }
1644             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1645                 return false;
1646             }
1647             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1648                 return false;
1649             }
1650             if ( taxbb.getSynonyms().size() != 2 ) {
1651                 return false;
1652             }
1653             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1654                 return false;
1655             }
1656             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1657                 return false;
1658             }
1659             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1660                 return false;
1661             }
1662             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1663                 return false;
1664             }
1665             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1666                 return false;
1667             }
1668             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1669                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1670                 ;
1671                 return false;
1672             }
1673             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1674                 return false;
1675             }
1676             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1677                 return false;
1678             }
1679             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1680                 return false;
1681             }
1682             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1683                 return false;
1684             }
1685             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1686                 return false;
1687             }
1688             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1689                 return false;
1690             }
1691             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1692                 return false;
1693             }
1694             //
1695             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1696                 return false;
1697             }
1698             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1699                     .equalsIgnoreCase( "435" ) ) {
1700                 return false;
1701             }
1702             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1703                 return false;
1704             }
1705             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1706                     .equalsIgnoreCase( "443.7" ) ) {
1707                 return false;
1708             }
1709             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1710                 return false;
1711             }
1712             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1713                 return false;
1714             }
1715             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1716                     .equalsIgnoreCase( "433" ) ) {
1717                 return false;
1718             }
1719         }
1720         catch ( final Exception e ) {
1721             e.printStackTrace( System.out );
1722             return false;
1723         }
1724         return true;
1725     }
1726
1727     private static boolean testBasicPhyloXMLparsingValidating() {
1728         try {
1729             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1730             PhyloXmlParser xml_parser = null;
1731             try {
1732                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1733             }
1734             catch ( final Exception e ) {
1735                 // Do nothing -- means were not running from jar.
1736             }
1737             if ( xml_parser == null ) {
1738                 xml_parser = new PhyloXmlParser();
1739                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1740                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1741                 }
1742                 else {
1743                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1744                 }
1745             }
1746             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1747                                                               xml_parser );
1748             if ( xml_parser.getErrorCount() > 0 ) {
1749                 System.out.println( xml_parser.getErrorMessages().toString() );
1750                 return false;
1751             }
1752             if ( phylogenies_0.length != 4 ) {
1753                 return false;
1754             }
1755             final Phylogeny t1 = phylogenies_0[ 0 ];
1756             final Phylogeny t2 = phylogenies_0[ 1 ];
1757             final Phylogeny t3 = phylogenies_0[ 2 ];
1758             final Phylogeny t4 = phylogenies_0[ 3 ];
1759             if ( !t1.getName().equals( "t1" ) ) {
1760                 return false;
1761             }
1762             if ( !t2.getName().equals( "t2" ) ) {
1763                 return false;
1764             }
1765             if ( !t3.getName().equals( "t3" ) ) {
1766                 return false;
1767             }
1768             if ( !t4.getName().equals( "t4" ) ) {
1769                 return false;
1770             }
1771             if ( t1.getNumberOfExternalNodes() != 1 ) {
1772                 return false;
1773             }
1774             if ( t2.getNumberOfExternalNodes() != 2 ) {
1775                 return false;
1776             }
1777             if ( t3.getNumberOfExternalNodes() != 4 ) {
1778                 return false;
1779             }
1780             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1781             final Phylogeny[] phylogenies_1 = factory.create( x2, 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_1.length != 4 ) {
1788                 return false;
1789             }
1790             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1791                                                               xml_parser );
1792             if ( xml_parser.getErrorCount() > 0 ) {
1793                 System.out.println( "errors:" );
1794                 System.out.println( xml_parser.getErrorMessages().toString() );
1795                 return false;
1796             }
1797             if ( phylogenies_2.length != 1 ) {
1798                 return false;
1799             }
1800             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1801                 return false;
1802             }
1803             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1804                                                               xml_parser );
1805             if ( xml_parser.getErrorCount() > 0 ) {
1806                 System.out.println( xml_parser.getErrorMessages().toString() );
1807                 return false;
1808             }
1809             if ( phylogenies_3.length != 2 ) {
1810                 return false;
1811             }
1812             final Phylogeny a = phylogenies_3[ 0 ];
1813             if ( !a.getName().equals( "tree 4" ) ) {
1814                 return false;
1815             }
1816             if ( a.getNumberOfExternalNodes() != 3 ) {
1817                 return false;
1818             }
1819             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1820                 return false;
1821             }
1822             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1823                 return false;
1824             }
1825             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1826                                                               xml_parser );
1827             if ( xml_parser.getErrorCount() > 0 ) {
1828                 System.out.println( xml_parser.getErrorMessages().toString() );
1829                 return false;
1830             }
1831             if ( phylogenies_4.length != 1 ) {
1832                 return false;
1833             }
1834             final Phylogeny s = phylogenies_4[ 0 ];
1835             if ( s.getNumberOfExternalNodes() != 6 ) {
1836                 return false;
1837             }
1838             s.getNode( "first" );
1839             s.getNode( "<>" );
1840             s.getNode( "\"<a'b&c'd\">\"" );
1841             s.getNode( "'''\"" );
1842             s.getNode( "\"\"\"" );
1843             s.getNode( "dick & doof" );
1844         }
1845         catch ( final Exception e ) {
1846             e.printStackTrace( System.out );
1847             return false;
1848         }
1849         return true;
1850     }
1851
1852     private static boolean testBasicTable() {
1853         try {
1854             final BasicTable<String> t0 = new BasicTable<String>();
1855             if ( t0.getNumberOfColumns() != 0 ) {
1856                 return false;
1857             }
1858             if ( t0.getNumberOfRows() != 0 ) {
1859                 return false;
1860             }
1861             t0.setValue( 3, 2, "23" );
1862             t0.setValue( 10, 1, "error" );
1863             t0.setValue( 10, 1, "110" );
1864             t0.setValue( 9, 1, "19" );
1865             t0.setValue( 1, 10, "101" );
1866             t0.setValue( 10, 10, "1010" );
1867             t0.setValue( 100, 10, "10100" );
1868             t0.setValue( 0, 0, "00" );
1869             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1870                 return false;
1871             }
1872             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1873                 return false;
1874             }
1875             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1876                 return false;
1877             }
1878             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1879                 return false;
1880             }
1881             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1882                 return false;
1883             }
1884             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1885                 return false;
1886             }
1887             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1888                 return false;
1889             }
1890             if ( t0.getNumberOfColumns() != 101 ) {
1891                 return false;
1892             }
1893             if ( t0.getNumberOfRows() != 11 ) {
1894                 return false;
1895             }
1896             if ( t0.getValueAsString( 49, 4 ) != null ) {
1897                 return false;
1898             }
1899             final String l = ForesterUtil.getLineSeparator();
1900             final StringBuffer source = new StringBuffer();
1901             source.append( "" + l );
1902             source.append( "# 1 1 1 1 1 1 1 1" + l );
1903             source.append( " 00 01 02 03" + l );
1904             source.append( "   10 11 12 13  " + l );
1905             source.append( "20 21 22 23 " + l );
1906             source.append( "    30  31    32 33" + l );
1907             source.append( "40 41 42 43" + l );
1908             source.append( "  # 1 1 1 1 1 " + l );
1909             source.append( "50 51 52 53 54" + l );
1910             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
1911             if ( t1.getNumberOfColumns() != 5 ) {
1912                 return false;
1913             }
1914             if ( t1.getNumberOfRows() != 6 ) {
1915                 return false;
1916             }
1917             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1918                 return false;
1919             }
1920             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1921                 return false;
1922             }
1923             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1924                 return false;
1925             }
1926             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1927                 return false;
1928             }
1929             final StringBuffer source1 = new StringBuffer();
1930             source1.append( "" + l );
1931             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1932             source1.append( " 00; 01 ;02;03" + l );
1933             source1.append( "   10; 11; 12; 13  " + l );
1934             source1.append( "20; 21; 22; 23 " + l );
1935             source1.append( "    30;  31;    32; 33" + l );
1936             source1.append( "40;41;42;43" + l );
1937             source1.append( "  # 1 1 1 1 1 " + l );
1938             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
1939             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
1940             if ( t2.getNumberOfColumns() != 5 ) {
1941                 return false;
1942             }
1943             if ( t2.getNumberOfRows() != 6 ) {
1944                 return false;
1945             }
1946             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1947                 return false;
1948             }
1949             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1950                 return false;
1951             }
1952             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1953                 return false;
1954             }
1955             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1956                 return false;
1957             }
1958             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1959                 return false;
1960             }
1961             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1962                 return false;
1963             }
1964             final StringBuffer source2 = new StringBuffer();
1965             source2.append( "" + l );
1966             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1967             source2.append( " 00; 01 ;02;03" + l );
1968             source2.append( "   10; 11; 12; 13  " + l );
1969             source2.append( "20; 21; 22; 23 " + l );
1970             source2.append( "                     " + l );
1971             source2.append( "    30;  31;    32; 33" + l );
1972             source2.append( "40;41;42;43" + l );
1973             source2.append( "  comment: 1 1 1 1 1 " + l );
1974             source2.append( ";;;50  ;   52; 53;;54   " + l );
1975             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1976                                                                         ';',
1977                                                                         false,
1978                                                                         false,
1979                                                                         "comment:",
1980                                                                         false );
1981             if ( tl.size() != 2 ) {
1982                 return false;
1983             }
1984             final BasicTable<String> t3 = tl.get( 0 );
1985             final BasicTable<String> t4 = tl.get( 1 );
1986             if ( t3.getNumberOfColumns() != 4 ) {
1987                 return false;
1988             }
1989             if ( t3.getNumberOfRows() != 3 ) {
1990                 return false;
1991             }
1992             if ( t4.getNumberOfColumns() != 4 ) {
1993                 return false;
1994             }
1995             if ( t4.getNumberOfRows() != 3 ) {
1996                 return false;
1997             }
1998             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1999                 return false;
2000             }
2001             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2002                 return false;
2003             }
2004         }
2005         catch ( final Exception e ) {
2006             e.printStackTrace( System.out );
2007             return false;
2008         }
2009         return true;
2010     }
2011
2012     private static boolean testBasicTolXMLparsing() {
2013         try {
2014             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2015             final TolParser parser = new TolParser();
2016             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2017             if ( parser.getErrorCount() > 0 ) {
2018                 System.out.println( parser.getErrorMessages().toString() );
2019                 return false;
2020             }
2021             if ( phylogenies_0.length != 1 ) {
2022                 return false;
2023             }
2024             final Phylogeny t1 = phylogenies_0[ 0 ];
2025             if ( t1.getNumberOfExternalNodes() != 5 ) {
2026                 return false;
2027             }
2028             if ( !t1.isRooted() ) {
2029                 return false;
2030             }
2031             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2032                 return false;
2033             }
2034             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2035                 return false;
2036             }
2037             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2038                 return false;
2039             }
2040             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2041                 return false;
2042             }
2043             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2044             if ( parser.getErrorCount() > 0 ) {
2045                 System.out.println( parser.getErrorMessages().toString() );
2046                 return false;
2047             }
2048             if ( phylogenies_1.length != 1 ) {
2049                 return false;
2050             }
2051             final Phylogeny t2 = phylogenies_1[ 0 ];
2052             if ( t2.getNumberOfExternalNodes() != 664 ) {
2053                 return false;
2054             }
2055             if ( !t2.isRooted() ) {
2056                 return false;
2057             }
2058             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2059                 return false;
2060             }
2061             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2062                 return false;
2063             }
2064             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2065                 return false;
2066             }
2067             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2068                 return false;
2069             }
2070             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2071                 return false;
2072             }
2073             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2074                     .equals( "Aquifex" ) ) {
2075                 return false;
2076             }
2077             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2078             if ( parser.getErrorCount() > 0 ) {
2079                 System.out.println( parser.getErrorMessages().toString() );
2080                 return false;
2081             }
2082             if ( phylogenies_2.length != 1 ) {
2083                 return false;
2084             }
2085             final Phylogeny t3 = phylogenies_2[ 0 ];
2086             if ( t3.getNumberOfExternalNodes() != 184 ) {
2087                 return false;
2088             }
2089             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2090                 return false;
2091             }
2092             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2093                 return false;
2094             }
2095             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2096                 return false;
2097             }
2098             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2099             if ( parser.getErrorCount() > 0 ) {
2100                 System.out.println( parser.getErrorMessages().toString() );
2101                 return false;
2102             }
2103             if ( phylogenies_3.length != 1 ) {
2104                 return false;
2105             }
2106             final Phylogeny t4 = phylogenies_3[ 0 ];
2107             if ( t4.getNumberOfExternalNodes() != 1 ) {
2108                 return false;
2109             }
2110             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2111                 return false;
2112             }
2113             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2114                 return false;
2115             }
2116             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2117                 return false;
2118             }
2119             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2120             if ( parser.getErrorCount() > 0 ) {
2121                 System.out.println( parser.getErrorMessages().toString() );
2122                 return false;
2123             }
2124             if ( phylogenies_4.length != 1 ) {
2125                 return false;
2126             }
2127             final Phylogeny t5 = phylogenies_4[ 0 ];
2128             if ( t5.getNumberOfExternalNodes() != 13 ) {
2129                 return false;
2130             }
2131             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2132                 return false;
2133             }
2134             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2135                 return false;
2136             }
2137             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2138                 return false;
2139             }
2140         }
2141         catch ( final Exception e ) {
2142             e.printStackTrace( System.out );
2143             return false;
2144         }
2145         return true;
2146     }
2147
2148     private static boolean testBasicTreeMethods() {
2149         try {
2150             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2151             final Phylogeny t1 = factory.create();
2152             if ( !t1.isEmpty() ) {
2153                 return false;
2154             }
2155             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2156             if ( t2.getNumberOfExternalNodes() != 4 ) {
2157                 return false;
2158             }
2159             if ( t2.getHeight() != 8.5 ) {
2160                 return false;
2161             }
2162             if ( !t2.isCompletelyBinary() ) {
2163                 return false;
2164             }
2165             if ( t2.isEmpty() ) {
2166                 return false;
2167             }
2168             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2169             if ( t3.getNumberOfExternalNodes() != 5 ) {
2170                 return false;
2171             }
2172             if ( t3.getHeight() != 11 ) {
2173                 return false;
2174             }
2175             if ( t3.isCompletelyBinary() ) {
2176                 return false;
2177             }
2178             final PhylogenyNode n = t3.getNode( "ABC" );
2179             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 ];
2180             if ( t4.getNumberOfExternalNodes() != 9 ) {
2181                 return false;
2182             }
2183             if ( t4.getHeight() != 11 ) {
2184                 return false;
2185             }
2186             if ( t4.isCompletelyBinary() ) {
2187                 return false;
2188             }
2189             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)" );
2190             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2191             if ( t5.getNumberOfExternalNodes() != 8 ) {
2192                 return false;
2193             }
2194             if ( t5.getHeight() != 15 ) {
2195                 return false;
2196             }
2197             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)" );
2198             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2199             if ( t6.getHeight() != 15 ) {
2200                 return false;
2201             }
2202             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)" );
2203             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2204             if ( t7.getHeight() != 15 ) {
2205                 return false;
2206             }
2207             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)" );
2208             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2209             if ( t8.getNumberOfExternalNodes() != 10 ) {
2210                 return false;
2211             }
2212             if ( t8.getHeight() != 15 ) {
2213                 return false;
2214             }
2215             final char[] a9 = new char[] { 'a' };
2216             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2217             if ( t9.getHeight() != 0 ) {
2218                 return false;
2219             }
2220             final char[] a10 = new char[] { 'a', ':', '6' };
2221             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2222             if ( t10.getHeight() != 6 ) {
2223                 return false;
2224             }
2225         }
2226         catch ( final Exception e ) {
2227             e.printStackTrace( System.out );
2228             return false;
2229         }
2230         return true;
2231     }
2232
2233     private static boolean testTreeMethods() {
2234         try {
2235             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2236             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
2237             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
2238             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
2239                 System.out.println( t0.toNewHampshireX() );
2240                 return false;
2241             }
2242             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
2243             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
2244             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
2245                 return false;
2246             }
2247             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
2248                 return false;
2249             }
2250             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
2251                 return false;
2252             }
2253         }
2254         catch ( final Exception e ) {
2255             e.printStackTrace( System.out );
2256             return false;
2257         }
2258         return true;
2259     }
2260
2261     private static boolean testConfidenceAssessor() {
2262         try {
2263             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2264             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2265             final Phylogeny[] ev0 = factory
2266                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2267                              new NHXParser() );
2268             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2269             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2270                 return false;
2271             }
2272             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2273                 return false;
2274             }
2275             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2276             final Phylogeny[] ev1 = factory
2277                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
2278                              new NHXParser() );
2279             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2280             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2281                 return false;
2282             }
2283             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2284                 return false;
2285             }
2286             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2287             final Phylogeny[] ev_b = factory
2288                     .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",
2289                              new NHXParser() );
2290             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2291             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2292                 return false;
2293             }
2294             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2295                 return false;
2296             }
2297             //
2298             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2299             final Phylogeny[] ev1x = factory
2300                     .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)));",
2301                              new NHXParser() );
2302             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2303             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2304                 return false;
2305             }
2306             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2307                 return false;
2308             }
2309             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2310             final Phylogeny[] ev_bx = factory
2311                     .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",
2312                              new NHXParser() );
2313             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2314             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2315                 return false;
2316             }
2317             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2318                 return false;
2319             }
2320             //
2321             final Phylogeny[] t2 = factory
2322                     .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);",
2323                              new NHXParser() );
2324             final Phylogeny[] ev2 = factory
2325                     .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);",
2326                              new NHXParser() );
2327             for( final Phylogeny target : t2 ) {
2328                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2329             }
2330             //
2331             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2332                                                  new NHXParser() )[ 0 ];
2333             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2334             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2335             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2336                 return false;
2337             }
2338             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2339                 return false;
2340             }
2341             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2342                 return false;
2343             }
2344         }
2345         catch ( final Exception e ) {
2346             e.printStackTrace();
2347             return false;
2348         }
2349         return true;
2350     }
2351
2352     private static boolean testCopyOfNodeData() {
2353         try {
2354             final PhylogenyNode n1 = PhylogenyNode
2355                     .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]" );
2356             final PhylogenyNode n2 = n1.copyNodeData();
2357             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2358                 return false;
2359             }
2360         }
2361         catch ( final Exception e ) {
2362             e.printStackTrace();
2363             return false;
2364         }
2365         return true;
2366     }
2367
2368     private static boolean testDataObjects() {
2369         try {
2370             final Confidence s0 = new Confidence();
2371             final Confidence s1 = new Confidence();
2372             if ( !s0.isEqual( s1 ) ) {
2373                 return false;
2374             }
2375             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2376             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2377             if ( s2.isEqual( s1 ) ) {
2378                 return false;
2379             }
2380             if ( !s2.isEqual( s3 ) ) {
2381                 return false;
2382             }
2383             final Confidence s4 = ( Confidence ) s3.copy();
2384             if ( !s4.isEqual( s3 ) ) {
2385                 return false;
2386             }
2387             s3.asSimpleText();
2388             s3.asText();
2389             // Taxonomy
2390             // ----------
2391             final Taxonomy t1 = new Taxonomy();
2392             final Taxonomy t2 = new Taxonomy();
2393             final Taxonomy t3 = new Taxonomy();
2394             final Taxonomy t4 = new Taxonomy();
2395             final Taxonomy t5 = new Taxonomy();
2396             t1.setIdentifier( new Identifier( "ecoli" ) );
2397             t1.setTaxonomyCode( "ECOLI" );
2398             t1.setScientificName( "E. coli" );
2399             t1.setCommonName( "coli" );
2400             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2401             if ( !t1.isEqual( t0 ) ) {
2402                 return false;
2403             }
2404             t2.setIdentifier( new Identifier( "ecoli" ) );
2405             t2.setTaxonomyCode( "OTHER" );
2406             t2.setScientificName( "what" );
2407             t2.setCommonName( "something" );
2408             if ( !t1.isEqual( t2 ) ) {
2409                 return false;
2410             }
2411             t2.setIdentifier( new Identifier( "nemve" ) );
2412             if ( t1.isEqual( t2 ) ) {
2413                 return false;
2414             }
2415             t1.setIdentifier( null );
2416             t3.setTaxonomyCode( "ECOLI" );
2417             t3.setScientificName( "what" );
2418             t3.setCommonName( "something" );
2419             if ( !t1.isEqual( t3 ) ) {
2420                 return false;
2421             }
2422             t1.setIdentifier( null );
2423             t1.setTaxonomyCode( "" );
2424             t4.setScientificName( "E. ColI" );
2425             t4.setCommonName( "something" );
2426             if ( !t1.isEqual( t4 ) ) {
2427                 return false;
2428             }
2429             t4.setScientificName( "B. subtilis" );
2430             t4.setCommonName( "something" );
2431             if ( t1.isEqual( t4 ) ) {
2432                 return false;
2433             }
2434             t1.setIdentifier( null );
2435             t1.setTaxonomyCode( "" );
2436             t1.setScientificName( "" );
2437             t5.setCommonName( "COLI" );
2438             if ( !t1.isEqual( t5 ) ) {
2439                 return false;
2440             }
2441             t5.setCommonName( "vibrio" );
2442             if ( t1.isEqual( t5 ) ) {
2443                 return false;
2444             }
2445             // Identifier
2446             // ----------
2447             final Identifier id0 = new Identifier( "123", "pfam" );
2448             final Identifier id1 = ( Identifier ) id0.copy();
2449             if ( !id1.isEqual( id1 ) ) {
2450                 return false;
2451             }
2452             if ( !id1.isEqual( id0 ) ) {
2453                 return false;
2454             }
2455             if ( !id0.isEqual( id1 ) ) {
2456                 return false;
2457             }
2458             id1.asSimpleText();
2459             id1.asText();
2460             // ProteinDomain
2461             // ---------------
2462             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2463             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2464             if ( !pd1.isEqual( pd1 ) ) {
2465                 return false;
2466             }
2467             if ( !pd1.isEqual( pd0 ) ) {
2468                 return false;
2469             }
2470             pd1.asSimpleText();
2471             pd1.asText();
2472             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2473             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2474             if ( !pd3.isEqual( pd3 ) ) {
2475                 return false;
2476             }
2477             if ( !pd2.isEqual( pd3 ) ) {
2478                 return false;
2479             }
2480             if ( !pd0.isEqual( pd3 ) ) {
2481                 return false;
2482             }
2483             pd3.asSimpleText();
2484             pd3.asText();
2485             // DomainArchitecture
2486             // ------------------
2487             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2488             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2489             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2490             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2491             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2492             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2493             domains0.add( d2 );
2494             domains0.add( d0 );
2495             domains0.add( d3 );
2496             domains0.add( d1 );
2497             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2498             if ( ds0.getNumberOfDomains() != 4 ) {
2499                 return false;
2500             }
2501             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2502             if ( !ds0.isEqual( ds0 ) ) {
2503                 return false;
2504             }
2505             if ( !ds0.isEqual( ds1 ) ) {
2506                 return false;
2507             }
2508             if ( ds1.getNumberOfDomains() != 4 ) {
2509                 return false;
2510             }
2511             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2512             domains1.add( d1 );
2513             domains1.add( d2 );
2514             domains1.add( d4 );
2515             domains1.add( d0 );
2516             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2517             if ( ds0.isEqual( ds2 ) ) {
2518                 return false;
2519             }
2520             ds1.asSimpleText();
2521             ds1.asText();
2522             ds1.toNHX();
2523             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2524             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2525                 System.out.println( ds3.toNHX() );
2526                 return false;
2527             }
2528             if ( ds3.getNumberOfDomains() != 3 ) {
2529                 return false;
2530             }
2531             // Event
2532             // -----
2533             final Event e1 = new Event( Event.EventType.fusion );
2534             if ( e1.isDuplication() ) {
2535                 return false;
2536             }
2537             if ( !e1.isFusion() ) {
2538                 return false;
2539             }
2540             if ( !e1.asText().toString().equals( "fusion" ) ) {
2541                 return false;
2542             }
2543             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2544                 return false;
2545             }
2546             final Event e11 = new Event( Event.EventType.fusion );
2547             if ( !e11.isEqual( e1 ) ) {
2548                 return false;
2549             }
2550             if ( !e11.toNHX().toString().equals( "" ) ) {
2551                 return false;
2552             }
2553             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2554             if ( e2.isDuplication() ) {
2555                 return false;
2556             }
2557             if ( !e2.isSpeciationOrDuplication() ) {
2558                 return false;
2559             }
2560             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2561                 return false;
2562             }
2563             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2564                 return false;
2565             }
2566             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2567                 return false;
2568             }
2569             if ( e11.isEqual( e2 ) ) {
2570                 return false;
2571             }
2572             final Event e2c = ( Event ) e2.copy();
2573             if ( !e2c.isEqual( e2 ) ) {
2574                 return false;
2575             }
2576             Event e3 = new Event( 1, 2, 3 );
2577             if ( e3.isDuplication() ) {
2578                 return false;
2579             }
2580             if ( e3.isSpeciation() ) {
2581                 return false;
2582             }
2583             if ( e3.isGeneLoss() ) {
2584                 return false;
2585             }
2586             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2587                 return false;
2588             }
2589             final Event e3c = ( Event ) e3.copy();
2590             final Event e3cc = ( Event ) e3c.copy();
2591             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2592                 return false;
2593             }
2594             e3 = null;
2595             if ( !e3c.isEqual( e3cc ) ) {
2596                 return false;
2597             }
2598             Event e4 = new Event( 1, 2, 3 );
2599             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2600                 return false;
2601             }
2602             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2603                 return false;
2604             }
2605             final Event e4c = ( Event ) e4.copy();
2606             e4 = null;
2607             final Event e4cc = ( Event ) e4c.copy();
2608             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2609                 return false;
2610             }
2611             if ( !e4c.isEqual( e4cc ) ) {
2612                 return false;
2613             }
2614             final Event e5 = new Event();
2615             if ( !e5.isUnassigned() ) {
2616                 return false;
2617             }
2618             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2619                 return false;
2620             }
2621             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2622                 return false;
2623             }
2624             final Event e6 = new Event( 1, 0, 0 );
2625             if ( !e6.asText().toString().equals( "duplication" ) ) {
2626                 return false;
2627             }
2628             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2629                 return false;
2630             }
2631             final Event e7 = new Event( 0, 1, 0 );
2632             if ( !e7.asText().toString().equals( "speciation" ) ) {
2633                 return false;
2634             }
2635             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2636                 return false;
2637             }
2638             final Event e8 = new Event( 0, 0, 1 );
2639             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2640                 return false;
2641             }
2642             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2643                 return false;
2644             }
2645         }
2646         catch ( final Exception e ) {
2647             e.printStackTrace( System.out );
2648             return false;
2649         }
2650         return true;
2651     }
2652
2653     private static boolean testDeletionOfExternalNodes() {
2654         try {
2655             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2656             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2657             final PhylogenyWriter w = new PhylogenyWriter();
2658             if ( t0.isEmpty() ) {
2659                 return false;
2660             }
2661             if ( t0.getNumberOfExternalNodes() != 1 ) {
2662                 return false;
2663             }
2664             t0.deleteSubtree( t0.getNode( "A" ), false );
2665             if ( t0.getNumberOfExternalNodes() != 0 ) {
2666                 return false;
2667             }
2668             if ( !t0.isEmpty() ) {
2669                 return false;
2670             }
2671             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2672             if ( t1.getNumberOfExternalNodes() != 2 ) {
2673                 return false;
2674             }
2675             t1.deleteSubtree( t1.getNode( "A" ), false );
2676             if ( t1.getNumberOfExternalNodes() != 1 ) {
2677                 return false;
2678             }
2679             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2680                 return false;
2681             }
2682             t1.deleteSubtree( t1.getNode( "B" ), false );
2683             if ( t1.getNumberOfExternalNodes() != 1 ) {
2684                 return false;
2685             }
2686             t1.deleteSubtree( t1.getNode( "r" ), false );
2687             if ( !t1.isEmpty() ) {
2688                 return false;
2689             }
2690             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2691             if ( t2.getNumberOfExternalNodes() != 3 ) {
2692                 return false;
2693             }
2694             t2.deleteSubtree( t2.getNode( "B" ), false );
2695             if ( t2.getNumberOfExternalNodes() != 2 ) {
2696                 return false;
2697             }
2698             t2.toNewHampshireX();
2699             PhylogenyNode n = t2.getNode( "A" );
2700             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2701                 return false;
2702             }
2703             t2.deleteSubtree( t2.getNode( "A" ), false );
2704             if ( t2.getNumberOfExternalNodes() != 2 ) {
2705                 return false;
2706             }
2707             t2.deleteSubtree( t2.getNode( "C" ), true );
2708             if ( t2.getNumberOfExternalNodes() != 1 ) {
2709                 return false;
2710             }
2711             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2712             if ( t3.getNumberOfExternalNodes() != 4 ) {
2713                 return false;
2714             }
2715             t3.deleteSubtree( t3.getNode( "B" ), true );
2716             if ( t3.getNumberOfExternalNodes() != 3 ) {
2717                 return false;
2718             }
2719             n = t3.getNode( "A" );
2720             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2721                 return false;
2722             }
2723             n = n.getNextExternalNode();
2724             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2725                 return false;
2726             }
2727             t3.deleteSubtree( t3.getNode( "A" ), true );
2728             if ( t3.getNumberOfExternalNodes() != 2 ) {
2729                 return false;
2730             }
2731             n = t3.getNode( "C" );
2732             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2733                 return false;
2734             }
2735             t3.deleteSubtree( t3.getNode( "C" ), true );
2736             if ( t3.getNumberOfExternalNodes() != 1 ) {
2737                 return false;
2738             }
2739             t3.deleteSubtree( t3.getNode( "D" ), true );
2740             if ( t3.getNumberOfExternalNodes() != 0 ) {
2741                 return false;
2742             }
2743             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2744             if ( t4.getNumberOfExternalNodes() != 6 ) {
2745                 return false;
2746             }
2747             t4.deleteSubtree( t4.getNode( "B2" ), true );
2748             if ( t4.getNumberOfExternalNodes() != 5 ) {
2749                 return false;
2750             }
2751             String s = w.toNewHampshire( t4, false, true ).toString();
2752             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2753                 return false;
2754             }
2755             t4.deleteSubtree( t4.getNode( "B11" ), true );
2756             if ( t4.getNumberOfExternalNodes() != 4 ) {
2757                 return false;
2758             }
2759             t4.deleteSubtree( t4.getNode( "C" ), true );
2760             if ( t4.getNumberOfExternalNodes() != 3 ) {
2761                 return false;
2762             }
2763             n = t4.getNode( "A" );
2764             n = n.getNextExternalNode();
2765             if ( !n.getName().equals( "B12" ) ) {
2766                 return false;
2767             }
2768             n = n.getNextExternalNode();
2769             if ( !n.getName().equals( "D" ) ) {
2770                 return false;
2771             }
2772             s = w.toNewHampshire( t4, false, true ).toString();
2773             if ( !s.equals( "((A,B12),D);" ) ) {
2774                 return false;
2775             }
2776             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2777             t5.deleteSubtree( t5.getNode( "A" ), true );
2778             if ( t5.getNumberOfExternalNodes() != 5 ) {
2779                 return false;
2780             }
2781             s = w.toNewHampshire( t5, false, true ).toString();
2782             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2783                 return false;
2784             }
2785             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2786             t6.deleteSubtree( t6.getNode( "B11" ), true );
2787             if ( t6.getNumberOfExternalNodes() != 5 ) {
2788                 return false;
2789             }
2790             s = w.toNewHampshire( t6, false, false ).toString();
2791             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2792                 return false;
2793             }
2794             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2795             t7.deleteSubtree( t7.getNode( "B12" ), true );
2796             if ( t7.getNumberOfExternalNodes() != 5 ) {
2797                 return false;
2798             }
2799             s = w.toNewHampshire( t7, false, true ).toString();
2800             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2801                 return false;
2802             }
2803             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2804             t8.deleteSubtree( t8.getNode( "B2" ), true );
2805             if ( t8.getNumberOfExternalNodes() != 5 ) {
2806                 return false;
2807             }
2808             s = w.toNewHampshire( t8, false, false ).toString();
2809             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2810                 return false;
2811             }
2812             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2813             t9.deleteSubtree( t9.getNode( "C" ), true );
2814             if ( t9.getNumberOfExternalNodes() != 5 ) {
2815                 return false;
2816             }
2817             s = w.toNewHampshire( t9, false, true ).toString();
2818             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2819                 return false;
2820             }
2821             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2822             t10.deleteSubtree( t10.getNode( "D" ), true );
2823             if ( t10.getNumberOfExternalNodes() != 5 ) {
2824                 return false;
2825             }
2826             s = w.toNewHampshire( t10, false, true ).toString();
2827             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2828                 return false;
2829             }
2830             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2831             t11.deleteSubtree( t11.getNode( "A" ), true );
2832             if ( t11.getNumberOfExternalNodes() != 2 ) {
2833                 return false;
2834             }
2835             s = w.toNewHampshire( t11, false, true ).toString();
2836             if ( !s.equals( "(B,C);" ) ) {
2837                 return false;
2838             }
2839             t11.deleteSubtree( t11.getNode( "C" ), true );
2840             if ( t11.getNumberOfExternalNodes() != 1 ) {
2841                 return false;
2842             }
2843             s = w.toNewHampshire( t11, false, false ).toString();
2844             if ( !s.equals( "B;" ) ) {
2845                 return false;
2846             }
2847             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2848             t12.deleteSubtree( t12.getNode( "B2" ), true );
2849             if ( t12.getNumberOfExternalNodes() != 8 ) {
2850                 return false;
2851             }
2852             s = w.toNewHampshire( t12, false, true ).toString();
2853             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2854                 return false;
2855             }
2856             t12.deleteSubtree( t12.getNode( "B3" ), true );
2857             if ( t12.getNumberOfExternalNodes() != 7 ) {
2858                 return false;
2859             }
2860             s = w.toNewHampshire( t12, false, true ).toString();
2861             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2862                 return false;
2863             }
2864             t12.deleteSubtree( t12.getNode( "C3" ), true );
2865             if ( t12.getNumberOfExternalNodes() != 6 ) {
2866                 return false;
2867             }
2868             s = w.toNewHampshire( t12, false, true ).toString();
2869             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2870                 return false;
2871             }
2872             t12.deleteSubtree( t12.getNode( "A1" ), true );
2873             if ( t12.getNumberOfExternalNodes() != 5 ) {
2874                 return false;
2875             }
2876             s = w.toNewHampshire( t12, false, true ).toString();
2877             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2878                 return false;
2879             }
2880             t12.deleteSubtree( t12.getNode( "B1" ), true );
2881             if ( t12.getNumberOfExternalNodes() != 4 ) {
2882                 return false;
2883             }
2884             s = w.toNewHampshire( t12, false, true ).toString();
2885             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2886                 return false;
2887             }
2888             t12.deleteSubtree( t12.getNode( "A3" ), true );
2889             if ( t12.getNumberOfExternalNodes() != 3 ) {
2890                 return false;
2891             }
2892             s = w.toNewHampshire( t12, false, true ).toString();
2893             if ( !s.equals( "(A2,(C1,C2));" ) ) {
2894                 return false;
2895             }
2896             t12.deleteSubtree( t12.getNode( "A2" ), true );
2897             if ( t12.getNumberOfExternalNodes() != 2 ) {
2898                 return false;
2899             }
2900             s = w.toNewHampshire( t12, false, true ).toString();
2901             if ( !s.equals( "(C1,C2);" ) ) {
2902                 return false;
2903             }
2904             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2905             t13.deleteSubtree( t13.getNode( "D" ), true );
2906             if ( t13.getNumberOfExternalNodes() != 4 ) {
2907                 return false;
2908             }
2909             s = w.toNewHampshire( t13, false, true ).toString();
2910             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2911                 return false;
2912             }
2913             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2914             t14.deleteSubtree( t14.getNode( "E" ), true );
2915             if ( t14.getNumberOfExternalNodes() != 5 ) {
2916                 return false;
2917             }
2918             s = w.toNewHampshire( t14, false, true ).toString();
2919             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2920                 return false;
2921             }
2922             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2923             t15.deleteSubtree( t15.getNode( "B2" ), true );
2924             if ( t15.getNumberOfExternalNodes() != 11 ) {
2925                 return false;
2926             }
2927             t15.deleteSubtree( t15.getNode( "B1" ), true );
2928             if ( t15.getNumberOfExternalNodes() != 10 ) {
2929                 return false;
2930             }
2931             t15.deleteSubtree( t15.getNode( "B3" ), true );
2932             if ( t15.getNumberOfExternalNodes() != 9 ) {
2933                 return false;
2934             }
2935             t15.deleteSubtree( t15.getNode( "B4" ), true );
2936             if ( t15.getNumberOfExternalNodes() != 8 ) {
2937                 return false;
2938             }
2939             t15.deleteSubtree( t15.getNode( "A1" ), true );
2940             if ( t15.getNumberOfExternalNodes() != 7 ) {
2941                 return false;
2942             }
2943             t15.deleteSubtree( t15.getNode( "C4" ), true );
2944             if ( t15.getNumberOfExternalNodes() != 6 ) {
2945                 return false;
2946             }
2947         }
2948         catch ( final Exception e ) {
2949             e.printStackTrace( System.out );
2950             return false;
2951         }
2952         return true;
2953     }
2954
2955     private static boolean testDescriptiveStatistics() {
2956         try {
2957             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2958             dss1.addValue( 82 );
2959             dss1.addValue( 78 );
2960             dss1.addValue( 70 );
2961             dss1.addValue( 58 );
2962             dss1.addValue( 42 );
2963             if ( dss1.getN() != 5 ) {
2964                 return false;
2965             }
2966             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2967                 return false;
2968             }
2969             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2970                 return false;
2971             }
2972             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2973                 return false;
2974             }
2975             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2976                 return false;
2977             }
2978             if ( !Test.isEqual( dss1.median(), 70 ) ) {
2979                 return false;
2980             }
2981             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2982                 return false;
2983             }
2984             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2985                 return false;
2986             }
2987             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2988                 return false;
2989             }
2990             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2991                 return false;
2992             }
2993             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2994                 return false;
2995             }
2996             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2997                 return false;
2998             }
2999             dss1.addValue( 123 );
3000             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3001                 return false;
3002             }
3003             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3004                 return false;
3005             }
3006             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3007                 return false;
3008             }
3009             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3010             dss2.addValue( -1.85 );
3011             dss2.addValue( 57.5 );
3012             dss2.addValue( 92.78 );
3013             dss2.addValue( 57.78 );
3014             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3015                 return false;
3016             }
3017             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3018                 return false;
3019             }
3020             final double[] a = dss2.getDataAsDoubleArray();
3021             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3022                 return false;
3023             }
3024             dss2.addValue( -100 );
3025             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3026                 return false;
3027             }
3028             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3029                 return false;
3030             }
3031             final double[] ds = new double[ 14 ];
3032             ds[ 0 ] = 34;
3033             ds[ 1 ] = 23;
3034             ds[ 2 ] = 1;
3035             ds[ 3 ] = 32;
3036             ds[ 4 ] = 11;
3037             ds[ 5 ] = 2;
3038             ds[ 6 ] = 12;
3039             ds[ 7 ] = 33;
3040             ds[ 8 ] = 13;
3041             ds[ 9 ] = 22;
3042             ds[ 10 ] = 21;
3043             ds[ 11 ] = 35;
3044             ds[ 12 ] = 24;
3045             ds[ 13 ] = 31;
3046             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3047             if ( bins.length != 4 ) {
3048                 return false;
3049             }
3050             if ( bins[ 0 ] != 2 ) {
3051                 return false;
3052             }
3053             if ( bins[ 1 ] != 3 ) {
3054                 return false;
3055             }
3056             if ( bins[ 2 ] != 4 ) {
3057                 return false;
3058             }
3059             if ( bins[ 3 ] != 5 ) {
3060                 return false;
3061             }
3062             final double[] ds1 = new double[ 9 ];
3063             ds1[ 0 ] = 10.0;
3064             ds1[ 1 ] = 19.0;
3065             ds1[ 2 ] = 9.999;
3066             ds1[ 3 ] = 0.0;
3067             ds1[ 4 ] = 39.9;
3068             ds1[ 5 ] = 39.999;
3069             ds1[ 6 ] = 30.0;
3070             ds1[ 7 ] = 19.999;
3071             ds1[ 8 ] = 30.1;
3072             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3073             if ( bins1.length != 4 ) {
3074                 return false;
3075             }
3076             if ( bins1[ 0 ] != 2 ) {
3077                 return false;
3078             }
3079             if ( bins1[ 1 ] != 3 ) {
3080                 return false;
3081             }
3082             if ( bins1[ 2 ] != 0 ) {
3083                 return false;
3084             }
3085             if ( bins1[ 3 ] != 4 ) {
3086                 return false;
3087             }
3088             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3089             if ( bins1_1.length != 3 ) {
3090                 return false;
3091             }
3092             if ( bins1_1[ 0 ] != 3 ) {
3093                 return false;
3094             }
3095             if ( bins1_1[ 1 ] != 2 ) {
3096                 return false;
3097             }
3098             if ( bins1_1[ 2 ] != 4 ) {
3099                 return false;
3100             }
3101             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3102             if ( bins1_2.length != 3 ) {
3103                 return false;
3104             }
3105             if ( bins1_2[ 0 ] != 2 ) {
3106                 return false;
3107             }
3108             if ( bins1_2[ 1 ] != 2 ) {
3109                 return false;
3110             }
3111             if ( bins1_2[ 2 ] != 2 ) {
3112                 return false;
3113             }
3114             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3115             dss3.addValue( 1 );
3116             dss3.addValue( 1 );
3117             dss3.addValue( 1 );
3118             dss3.addValue( 2 );
3119             dss3.addValue( 3 );
3120             dss3.addValue( 4 );
3121             dss3.addValue( 5 );
3122             dss3.addValue( 5 );
3123             dss3.addValue( 5 );
3124             dss3.addValue( 6 );
3125             dss3.addValue( 7 );
3126             dss3.addValue( 8 );
3127             dss3.addValue( 9 );
3128             dss3.addValue( 10 );
3129             dss3.addValue( 10 );
3130             dss3.addValue( 10 );
3131             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3132             histo.toStringBuffer( 10, '=', 40, 5 );
3133             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3134         }
3135         catch ( final Exception e ) {
3136             e.printStackTrace( System.out );
3137             return false;
3138         }
3139         return true;
3140     }
3141
3142     private static boolean testDir( final String file ) {
3143         try {
3144             final File f = new File( file );
3145             if ( !f.exists() ) {
3146                 return false;
3147             }
3148             if ( !f.isDirectory() ) {
3149                 return false;
3150             }
3151             if ( !f.canRead() ) {
3152                 return false;
3153             }
3154         }
3155         catch ( final Exception e ) {
3156             return false;
3157         }
3158         return true;
3159     }
3160
3161     private static boolean testExternalNodeRelatedMethods() {
3162         try {
3163             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3164             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3165             PhylogenyNode n = t1.getNode( "A" );
3166             n = n.getNextExternalNode();
3167             if ( !n.getName().equals( "B" ) ) {
3168                 return false;
3169             }
3170             n = n.getNextExternalNode();
3171             if ( !n.getName().equals( "C" ) ) {
3172                 return false;
3173             }
3174             n = n.getNextExternalNode();
3175             if ( !n.getName().equals( "D" ) ) {
3176                 return false;
3177             }
3178             n = t1.getNode( "B" );
3179             while ( !n.isLastExternalNode() ) {
3180                 n = n.getNextExternalNode();
3181             }
3182             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3183             n = t2.getNode( "A" );
3184             n = n.getNextExternalNode();
3185             if ( !n.getName().equals( "B" ) ) {
3186                 return false;
3187             }
3188             n = n.getNextExternalNode();
3189             if ( !n.getName().equals( "C" ) ) {
3190                 return false;
3191             }
3192             n = n.getNextExternalNode();
3193             if ( !n.getName().equals( "D" ) ) {
3194                 return false;
3195             }
3196             n = t2.getNode( "B" );
3197             while ( !n.isLastExternalNode() ) {
3198                 n = n.getNextExternalNode();
3199             }
3200             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3201             n = t3.getNode( "A" );
3202             n = n.getNextExternalNode();
3203             if ( !n.getName().equals( "B" ) ) {
3204                 return false;
3205             }
3206             n = n.getNextExternalNode();
3207             if ( !n.getName().equals( "C" ) ) {
3208                 return false;
3209             }
3210             n = n.getNextExternalNode();
3211             if ( !n.getName().equals( "D" ) ) {
3212                 return false;
3213             }
3214             n = n.getNextExternalNode();
3215             if ( !n.getName().equals( "E" ) ) {
3216                 return false;
3217             }
3218             n = n.getNextExternalNode();
3219             if ( !n.getName().equals( "F" ) ) {
3220                 return false;
3221             }
3222             n = n.getNextExternalNode();
3223             if ( !n.getName().equals( "G" ) ) {
3224                 return false;
3225             }
3226             n = n.getNextExternalNode();
3227             if ( !n.getName().equals( "H" ) ) {
3228                 return false;
3229             }
3230             n = t3.getNode( "B" );
3231             while ( !n.isLastExternalNode() ) {
3232                 n = n.getNextExternalNode();
3233             }
3234             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3235             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3236                 final PhylogenyNode node = iter.next();
3237             }
3238             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3239             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3240                 final PhylogenyNode node = iter.next();
3241             }
3242             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3243             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3244             if ( !iter.next().getName().equals( "A" ) ) {
3245                 return false;
3246             }
3247             if ( !iter.next().getName().equals( "B" ) ) {
3248                 return false;
3249             }
3250             if ( !iter.next().getName().equals( "C" ) ) {
3251                 return false;
3252             }
3253             if ( !iter.next().getName().equals( "D" ) ) {
3254                 return false;
3255             }
3256             if ( !iter.next().getName().equals( "E" ) ) {
3257                 return false;
3258             }
3259             if ( !iter.next().getName().equals( "F" ) ) {
3260                 return false;
3261             }
3262             if ( iter.hasNext() ) {
3263                 return false;
3264             }
3265         }
3266         catch ( final Exception e ) {
3267             e.printStackTrace( System.out );
3268             return false;
3269         }
3270         return true;
3271     }
3272
3273     private static boolean testGeneralTable() {
3274         try {
3275             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3276             t0.setValue( 3, 2, "23" );
3277             t0.setValue( 10, 1, "error" );
3278             t0.setValue( 10, 1, "110" );
3279             t0.setValue( 9, 1, "19" );
3280             t0.setValue( 1, 10, "101" );
3281             t0.setValue( 10, 10, "1010" );
3282             t0.setValue( 100, 10, "10100" );
3283             t0.setValue( 0, 0, "00" );
3284             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3285                 return false;
3286             }
3287             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3288                 return false;
3289             }
3290             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3291                 return false;
3292             }
3293             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3294                 return false;
3295             }
3296             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3297                 return false;
3298             }
3299             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3300                 return false;
3301             }
3302             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3303                 return false;
3304             }
3305             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3306                 return false;
3307             }
3308             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3309                 return false;
3310             }
3311             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3312             t1.setValue( "3", "2", "23" );
3313             t1.setValue( "10", "1", "error" );
3314             t1.setValue( "10", "1", "110" );
3315             t1.setValue( "9", "1", "19" );
3316             t1.setValue( "1", "10", "101" );
3317             t1.setValue( "10", "10", "1010" );
3318             t1.setValue( "100", "10", "10100" );
3319             t1.setValue( "0", "0", "00" );
3320             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3321             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3322                 return false;
3323             }
3324             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3325                 return false;
3326             }
3327             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3328                 return false;
3329             }
3330             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3331                 return false;
3332             }
3333             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3334                 return false;
3335             }
3336             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3337                 return false;
3338             }
3339             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3340                 return false;
3341             }
3342             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3343                 return false;
3344             }
3345             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3346                 return false;
3347             }
3348             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3349                 return false;
3350             }
3351         }
3352         catch ( final Exception e ) {
3353             e.printStackTrace( System.out );
3354             return false;
3355         }
3356         return true;
3357     }
3358
3359     private static boolean testGetDistance() {
3360         try {
3361             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3362             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",
3363                                                  new NHXParser() )[ 0 ];
3364             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3365                 return false;
3366             }
3367             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3368                 return false;
3369             }
3370             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3371                 return false;
3372             }
3373             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3374                 return false;
3375             }
3376             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3377                 return false;
3378             }
3379             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3380                 return false;
3381             }
3382             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3383                 return false;
3384             }
3385             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3386                 return false;
3387             }
3388             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3389                 return false;
3390             }
3391             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3392                 return false;
3393             }
3394             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3395                 return false;
3396             }
3397             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3398                 return false;
3399             }
3400             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3401                 return false;
3402             }
3403             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3404                 return false;
3405             }
3406             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3407                 return false;
3408             }
3409             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3410                 return false;
3411             }
3412             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3413                 return false;
3414             }
3415             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3416                 return false;
3417             }
3418             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3419                 return false;
3420             }
3421             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3422                 return false;
3423             }
3424             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3425                 return false;
3426             }
3427             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3428                 return false;
3429             }
3430             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3431                 return false;
3432             }
3433             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3434                 return false;
3435             }
3436             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3437                 return false;
3438             }
3439             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3440                 return false;
3441             }
3442             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3443                 return false;
3444             }
3445             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3446                 return false;
3447             }
3448             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3449                 return false;
3450             }
3451             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3452                 return false;
3453             }
3454             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3455                 return false;
3456             }
3457             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",
3458                                                  new NHXParser() )[ 0 ];
3459             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3460                 return false;
3461             }
3462             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3463                 return false;
3464             }
3465             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3466                 return false;
3467             }
3468             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3469                 return false;
3470             }
3471             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3472                 return false;
3473             }
3474             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3475                 return false;
3476             }
3477             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3478                 return false;
3479             }
3480             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3481                 return false;
3482             }
3483             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3484                 return false;
3485             }
3486             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3487                 return false;
3488             }
3489             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3490                 return false;
3491             }
3492         }
3493         catch ( final Exception e ) {
3494             e.printStackTrace( System.out );
3495             return false;
3496         }
3497         return true;
3498     }
3499
3500     private static boolean testGetLCA() {
3501         try {
3502             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3503             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3504                                                  new NHXParser() )[ 0 ];
3505             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3506             if ( !A.getName().equals( "A" ) ) {
3507                 return false;
3508             }
3509             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3510             if ( !gh.getName().equals( "gh" ) ) {
3511                 return false;
3512             }
3513             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3514             if ( !ab.getName().equals( "ab" ) ) {
3515                 return false;
3516             }
3517             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3518             if ( !ab2.getName().equals( "ab" ) ) {
3519                 return false;
3520             }
3521             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3522             if ( !gh2.getName().equals( "gh" ) ) {
3523                 return false;
3524             }
3525             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3526             if ( !gh3.getName().equals( "gh" ) ) {
3527                 return false;
3528             }
3529             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3530             if ( !abc.getName().equals( "abc" ) ) {
3531                 return false;
3532             }
3533             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3534             if ( !abc2.getName().equals( "abc" ) ) {
3535                 return false;
3536             }
3537             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3538             if ( !abcd.getName().equals( "abcd" ) ) {
3539                 return false;
3540             }
3541             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3542             if ( !abcd2.getName().equals( "abcd" ) ) {
3543                 return false;
3544             }
3545             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3546             if ( !abcdef.getName().equals( "abcdef" ) ) {
3547                 return false;
3548             }
3549             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3550             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3551                 return false;
3552             }
3553             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3554             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3555                 return false;
3556             }
3557             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3558             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3559                 return false;
3560             }
3561             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3562             if ( !abcde.getName().equals( "abcde" ) ) {
3563                 return false;
3564             }
3565             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3566             if ( !abcde2.getName().equals( "abcde" ) ) {
3567                 return false;
3568             }
3569             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3570             if ( !r.getName().equals( "abcdefgh" ) ) {
3571                 return false;
3572             }
3573             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3574             if ( !r2.getName().equals( "abcdefgh" ) ) {
3575                 return false;
3576             }
3577             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3578             if ( !r3.getName().equals( "abcdefgh" ) ) {
3579                 return false;
3580             }
3581             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3582             if ( !abcde3.getName().equals( "abcde" ) ) {
3583                 return false;
3584             }
3585             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3586             if ( !abcde4.getName().equals( "abcde" ) ) {
3587                 return false;
3588             }
3589             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3590             if ( !ab3.getName().equals( "ab" ) ) {
3591                 return false;
3592             }
3593             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3594             if ( !ab4.getName().equals( "ab" ) ) {
3595                 return false;
3596             }
3597             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3598             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3599             if ( !cd.getName().equals( "cd" ) ) {
3600                 return false;
3601             }
3602             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3603             if ( !cd2.getName().equals( "cd" ) ) {
3604                 return false;
3605             }
3606             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3607             if ( !cde.getName().equals( "cde" ) ) {
3608                 return false;
3609             }
3610             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3611             if ( !cde2.getName().equals( "cde" ) ) {
3612                 return false;
3613             }
3614             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3615             if ( !cdef.getName().equals( "cdef" ) ) {
3616                 return false;
3617             }
3618             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3619             if ( !cdef2.getName().equals( "cdef" ) ) {
3620                 return false;
3621             }
3622             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3623             if ( !cdef3.getName().equals( "cdef" ) ) {
3624                 return false;
3625             }
3626             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3627             if ( !rt.getName().equals( "r" ) ) {
3628                 return false;
3629             }
3630             final Phylogeny p3 = factory
3631                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3632                              new NHXParser() )[ 0 ];
3633             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3634             if ( !bc_3.getName().equals( "bc" ) ) {
3635                 return false;
3636             }
3637             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3638             if ( !ac_3.getName().equals( "abc" ) ) {
3639                 return false;
3640             }
3641             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3642             if ( !ad_3.getName().equals( "abcde" ) ) {
3643                 return false;
3644             }
3645             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3646             if ( !af_3.getName().equals( "abcdef" ) ) {
3647                 return false;
3648             }
3649             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3650             if ( !ag_3.getName().equals( "" ) ) {
3651                 return false;
3652             }
3653             if ( !ag_3.isRoot() ) {
3654                 return false;
3655             }
3656             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3657             if ( !al_3.getName().equals( "" ) ) {
3658                 return false;
3659             }
3660             if ( !al_3.isRoot() ) {
3661                 return false;
3662             }
3663             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3664             if ( !kl_3.getName().equals( "" ) ) {
3665                 return false;
3666             }
3667             if ( !kl_3.isRoot() ) {
3668                 return false;
3669             }
3670             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3671             if ( !fl_3.getName().equals( "" ) ) {
3672                 return false;
3673             }
3674             if ( !fl_3.isRoot() ) {
3675                 return false;
3676             }
3677             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3678             if ( !gk_3.getName().equals( "ghijk" ) ) {
3679                 return false;
3680             }
3681             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3682             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3683             if ( !r_4.getName().equals( "r" ) ) {
3684                 return false;
3685             }
3686             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3687             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3688             if ( !r_5.getName().equals( "root" ) ) {
3689                 return false;
3690             }
3691             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3692             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3693             if ( !r_6.getName().equals( "rot" ) ) {
3694                 return false;
3695             }
3696             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3697             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3698             if ( !r_7.getName().equals( "rott" ) ) {
3699                 return false;
3700             }
3701         }
3702         catch ( final Exception e ) {
3703             e.printStackTrace( System.out );
3704             return false;
3705         }
3706         return true;
3707     }
3708
3709     private static boolean testGetLCA2() {
3710         try {
3711             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3712             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3713             PhylogenyMethods.preOrderReId( p_a );
3714             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3715                                                                                               p_a.getNode( "a" ) );
3716             if ( !p_a_1.getName().equals( "a" ) ) {
3717                 return false;
3718             }
3719             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3720             PhylogenyMethods.preOrderReId( p_b );
3721             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3722                                                                                               p_b.getNode( "a" ) );
3723             if ( !p_b_1.getName().equals( "b" ) ) {
3724                 return false;
3725             }
3726             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3727                                                                                               p_b.getNode( "b" ) );
3728             if ( !p_b_2.getName().equals( "b" ) ) {
3729                 return false;
3730             }
3731             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3732             PhylogenyMethods.preOrderReId( p_c );
3733             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3734                                                                                               p_c.getNode( "a" ) );
3735             if ( !p_c_1.getName().equals( "b" ) ) {
3736                 return false;
3737             }
3738             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3739                                                                                               p_c.getNode( "c" ) );
3740             if ( !p_c_2.getName().equals( "c" ) ) {
3741                 System.out.println( p_c_2.getName() );
3742                 System.exit( -1 );
3743                 return false;
3744             }
3745             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3746                                                                                               p_c.getNode( "b" ) );
3747             if ( !p_c_3.getName().equals( "b" ) ) {
3748                 return false;
3749             }
3750             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3751                                                                                               p_c.getNode( "a" ) );
3752             if ( !p_c_4.getName().equals( "c" ) ) {
3753                 return false;
3754             }
3755             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3756                                                  new NHXParser() )[ 0 ];
3757             PhylogenyMethods.preOrderReId( p1 );
3758             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3759                                                                                           p1.getNode( "A" ) );
3760             if ( !A.getName().equals( "A" ) ) {
3761                 return false;
3762             }
3763             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3764                                                                                            p1.getNode( "gh" ) );
3765             if ( !gh.getName().equals( "gh" ) ) {
3766                 return false;
3767             }
3768             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3769                                                                                            p1.getNode( "B" ) );
3770             if ( !ab.getName().equals( "ab" ) ) {
3771                 return false;
3772             }
3773             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3774                                                                                             p1.getNode( "A" ) );
3775             if ( !ab2.getName().equals( "ab" ) ) {
3776                 return false;
3777             }
3778             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3779                                                                                             p1.getNode( "G" ) );
3780             if ( !gh2.getName().equals( "gh" ) ) {
3781                 return false;
3782             }
3783             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3784                                                                                             p1.getNode( "H" ) );
3785             if ( !gh3.getName().equals( "gh" ) ) {
3786                 return false;
3787             }
3788             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3789                                                                                             p1.getNode( "A" ) );
3790             if ( !abc.getName().equals( "abc" ) ) {
3791                 return false;
3792             }
3793             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3794                                                                                              p1.getNode( "C" ) );
3795             if ( !abc2.getName().equals( "abc" ) ) {
3796                 return false;
3797             }
3798             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3799                                                                                              p1.getNode( "D" ) );
3800             if ( !abcd.getName().equals( "abcd" ) ) {
3801                 return false;
3802             }
3803             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3804                                                                                               p1.getNode( "A" ) );
3805             if ( !abcd2.getName().equals( "abcd" ) ) {
3806                 return false;
3807             }
3808             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3809                                                                                                p1.getNode( "F" ) );
3810             if ( !abcdef.getName().equals( "abcdef" ) ) {
3811                 return false;
3812             }
3813             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3814                                                                                                 p1.getNode( "A" ) );
3815             if ( !abcdef2.getName().equals( "abcdef" ) ) {
3816                 return false;
3817             }
3818             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3819                                                                                                 p1.getNode( "F" ) );
3820             if ( !abcdef3.getName().equals( "abcdef" ) ) {
3821                 return false;
3822             }
3823             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3824                                                                                                 p1.getNode( "ab" ) );
3825             if ( !abcdef4.getName().equals( "abcdef" ) ) {
3826                 return false;
3827             }
3828             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3829                                                                                               p1.getNode( "E" ) );
3830             if ( !abcde.getName().equals( "abcde" ) ) {
3831                 return false;
3832             }
3833             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3834                                                                                                p1.getNode( "A" ) );
3835             if ( !abcde2.getName().equals( "abcde" ) ) {
3836                 return false;
3837             }
3838             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3839                                                                                           p1.getNode( "abcdefgh" ) );
3840             if ( !r.getName().equals( "abcdefgh" ) ) {
3841                 return false;
3842             }
3843             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3844                                                                                            p1.getNode( "H" ) );
3845             if ( !r2.getName().equals( "abcdefgh" ) ) {
3846                 return false;
3847             }
3848             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3849                                                                                            p1.getNode( "A" ) );
3850             if ( !r3.getName().equals( "abcdefgh" ) ) {
3851                 return false;
3852             }
3853             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3854                                                                                                p1.getNode( "abcde" ) );
3855             if ( !abcde3.getName().equals( "abcde" ) ) {
3856                 return false;
3857             }
3858             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3859                                                                                                p1.getNode( "E" ) );
3860             if ( !abcde4.getName().equals( "abcde" ) ) {
3861                 return false;
3862             }
3863             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3864                                                                                             p1.getNode( "B" ) );
3865             if ( !ab3.getName().equals( "ab" ) ) {
3866                 return false;
3867             }
3868             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3869                                                                                             p1.getNode( "ab" ) );
3870             if ( !ab4.getName().equals( "ab" ) ) {
3871                 return false;
3872             }
3873             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3874             PhylogenyMethods.preOrderReId( p2 );
3875             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3876                                                                                            p2.getNode( "d" ) );
3877             if ( !cd.getName().equals( "cd" ) ) {
3878                 return false;
3879             }
3880             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3881                                                                                             p2.getNode( "c" ) );
3882             if ( !cd2.getName().equals( "cd" ) ) {
3883                 return false;
3884             }
3885             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3886                                                                                             p2.getNode( "e" ) );
3887             if ( !cde.getName().equals( "cde" ) ) {
3888                 return false;
3889             }
3890             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3891                                                                                              p2.getNode( "c" ) );
3892             if ( !cde2.getName().equals( "cde" ) ) {
3893                 return false;
3894             }
3895             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3896                                                                                              p2.getNode( "f" ) );
3897             if ( !cdef.getName().equals( "cdef" ) ) {
3898                 return false;
3899             }
3900             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3901                                                                                               p2.getNode( "f" ) );
3902             if ( !cdef2.getName().equals( "cdef" ) ) {
3903                 return false;
3904             }
3905             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3906                                                                                               p2.getNode( "d" ) );
3907             if ( !cdef3.getName().equals( "cdef" ) ) {
3908                 return false;
3909             }
3910             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3911                                                                                            p2.getNode( "a" ) );
3912             if ( !rt.getName().equals( "r" ) ) {
3913                 return false;
3914             }
3915             final Phylogeny p3 = factory
3916                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3917                              new NHXParser() )[ 0 ];
3918             PhylogenyMethods.preOrderReId( p3 );
3919             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3920                                                                                              p3.getNode( "c" ) );
3921             if ( !bc_3.getName().equals( "bc" ) ) {
3922                 return false;
3923             }
3924             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3925                                                                                              p3.getNode( "c" ) );
3926             if ( !ac_3.getName().equals( "abc" ) ) {
3927                 return false;
3928             }
3929             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3930                                                                                              p3.getNode( "d" ) );
3931             if ( !ad_3.getName().equals( "abcde" ) ) {
3932                 return false;
3933             }
3934             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3935                                                                                              p3.getNode( "f" ) );
3936             if ( !af_3.getName().equals( "abcdef" ) ) {
3937                 return false;
3938             }
3939             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3940                                                                                              p3.getNode( "g" ) );
3941             if ( !ag_3.getName().equals( "" ) ) {
3942                 return false;
3943             }
3944             if ( !ag_3.isRoot() ) {
3945                 return false;
3946             }
3947             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3948                                                                                              p3.getNode( "l" ) );
3949             if ( !al_3.getName().equals( "" ) ) {
3950                 return false;
3951             }
3952             if ( !al_3.isRoot() ) {
3953                 return false;
3954             }
3955             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3956                                                                                              p3.getNode( "l" ) );
3957             if ( !kl_3.getName().equals( "" ) ) {
3958                 return false;
3959             }
3960             if ( !kl_3.isRoot() ) {
3961                 return false;
3962             }
3963             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3964                                                                                              p3.getNode( "l" ) );
3965             if ( !fl_3.getName().equals( "" ) ) {
3966                 return false;
3967             }
3968             if ( !fl_3.isRoot() ) {
3969                 return false;
3970             }
3971             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3972                                                                                              p3.getNode( "k" ) );
3973             if ( !gk_3.getName().equals( "ghijk" ) ) {
3974                 return false;
3975             }
3976             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3977             PhylogenyMethods.preOrderReId( p4 );
3978             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3979                                                                                             p4.getNode( "c" ) );
3980             if ( !r_4.getName().equals( "r" ) ) {
3981                 return false;
3982             }
3983             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3984             PhylogenyMethods.preOrderReId( p5 );
3985             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3986                                                                                             p5.getNode( "c" ) );
3987             if ( !r_5.getName().equals( "root" ) ) {
3988                 return false;
3989             }
3990             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3991             PhylogenyMethods.preOrderReId( p6 );
3992             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3993                                                                                             p6.getNode( "a" ) );
3994             if ( !r_6.getName().equals( "rot" ) ) {
3995                 return false;
3996             }
3997             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3998             PhylogenyMethods.preOrderReId( p7 );
3999             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4000                                                                                             p7.getNode( "e" ) );
4001             if ( !r_7.getName().equals( "rott" ) ) {
4002                 return false;
4003             }
4004             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4005                                                                                              p7.getNode( "a" ) );
4006             if ( !r_71.getName().equals( "rott" ) ) {
4007                 return false;
4008             }
4009             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4010                                                                                              p7.getNode( "rott" ) );
4011             if ( !r_72.getName().equals( "rott" ) ) {
4012                 return false;
4013             }
4014             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4015                                                                                              p7.getNode( "a" ) );
4016             if ( !r_73.getName().equals( "rott" ) ) {
4017                 return false;
4018             }
4019             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4020                                                                                              p7.getNode( "rott" ) );
4021             if ( !r_74.getName().equals( "rott" ) ) {
4022                 return false;
4023             }
4024             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4025                                                                                              p7.getNode( "e" ) );
4026             if ( !r_75.getName().equals( "e" ) ) {
4027                 return false;
4028             }
4029         }
4030         catch ( final Exception e ) {
4031             e.printStackTrace( System.out );
4032             return false;
4033         }
4034         return true;
4035     }
4036
4037     private static boolean testHmmscanOutputParser() {
4038         final String test_dir = Test.PATH_TO_TEST_DATA;
4039         try {
4040             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4041                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4042             parser1.parse();
4043             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4044                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4045             final List<Protein> proteins = parser2.parse();
4046             if ( parser2.getProteinsEncountered() != 4 ) {
4047                 return false;
4048             }
4049             if ( proteins.size() != 4 ) {
4050                 return false;
4051             }
4052             if ( parser2.getDomainsEncountered() != 69 ) {
4053                 return false;
4054             }
4055             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4056                 return false;
4057             }
4058             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4059                 return false;
4060             }
4061             final Protein p1 = proteins.get( 0 );
4062             if ( p1.getNumberOfProteinDomains() != 15 ) {
4063                 return false;
4064             }
4065             if ( p1.getLength() != 850 ) {
4066                 return false;
4067             }
4068             final Protein p2 = proteins.get( 1 );
4069             if ( p2.getNumberOfProteinDomains() != 51 ) {
4070                 return false;
4071             }
4072             if ( p2.getLength() != 1291 ) {
4073                 return false;
4074             }
4075             final Protein p3 = proteins.get( 2 );
4076             if ( p3.getNumberOfProteinDomains() != 2 ) {
4077                 return false;
4078             }
4079             final Protein p4 = proteins.get( 3 );
4080             if ( p4.getNumberOfProteinDomains() != 1 ) {
4081                 return false;
4082             }
4083             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4084                 return false;
4085             }
4086             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4087                 return false;
4088             }
4089             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4090                 return false;
4091             }
4092             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4093                 return false;
4094             }
4095             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4096                 return false;
4097             }
4098             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4099                 return false;
4100             }
4101             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4102                 return false;
4103             }
4104             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4105                 return false;
4106             }
4107             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4108                 return false;
4109             }
4110         }
4111         catch ( final Exception e ) {
4112             e.printStackTrace( System.out );
4113             return false;
4114         }
4115         return true;
4116     }
4117
4118     private static boolean testLastExternalNodeMethods() {
4119         try {
4120             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4121             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4122             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4123             final PhylogenyNode n1 = t0.getNode( "A" );
4124             if ( n1.isLastExternalNode() ) {
4125                 return false;
4126             }
4127             final PhylogenyNode n2 = t0.getNode( "B" );
4128             if ( n2.isLastExternalNode() ) {
4129                 return false;
4130             }
4131             final PhylogenyNode n3 = t0.getNode( "C" );
4132             if ( n3.isLastExternalNode() ) {
4133                 return false;
4134             }
4135             final PhylogenyNode n4 = t0.getNode( "D" );
4136             if ( !n4.isLastExternalNode() ) {
4137                 return false;
4138             }
4139         }
4140         catch ( final Exception e ) {
4141             e.printStackTrace( System.out );
4142             return false;
4143         }
4144         return true;
4145     }
4146
4147     private static boolean testLevelOrderIterator() {
4148         try {
4149             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4150             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4151             PhylogenyNodeIterator it0;
4152             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4153                 it0.next();
4154             }
4155             for( it0.reset(); it0.hasNext(); ) {
4156                 it0.next();
4157             }
4158             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4159             if ( !it.next().getName().equals( "r" ) ) {
4160                 return false;
4161             }
4162             if ( !it.next().getName().equals( "ab" ) ) {
4163                 return false;
4164             }
4165             if ( !it.next().getName().equals( "cd" ) ) {
4166                 return false;
4167             }
4168             if ( !it.next().getName().equals( "A" ) ) {
4169                 return false;
4170             }
4171             if ( !it.next().getName().equals( "B" ) ) {
4172                 return false;
4173             }
4174             if ( !it.next().getName().equals( "C" ) ) {
4175                 return false;
4176             }
4177             if ( !it.next().getName().equals( "D" ) ) {
4178                 return false;
4179             }
4180             if ( it.hasNext() ) {
4181                 return false;
4182             }
4183             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",
4184                                                  new NHXParser() )[ 0 ];
4185             PhylogenyNodeIterator it2;
4186             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4187                 it2.next();
4188             }
4189             for( it2.reset(); it2.hasNext(); ) {
4190                 it2.next();
4191             }
4192             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4193             if ( !it3.next().getName().equals( "r" ) ) {
4194                 return false;
4195             }
4196             if ( !it3.next().getName().equals( "abc" ) ) {
4197                 return false;
4198             }
4199             if ( !it3.next().getName().equals( "defg" ) ) {
4200                 return false;
4201             }
4202             if ( !it3.next().getName().equals( "A" ) ) {
4203                 return false;
4204             }
4205             if ( !it3.next().getName().equals( "B" ) ) {
4206                 return false;
4207             }
4208             if ( !it3.next().getName().equals( "C" ) ) {
4209                 return false;
4210             }
4211             if ( !it3.next().getName().equals( "D" ) ) {
4212                 return false;
4213             }
4214             if ( !it3.next().getName().equals( "E" ) ) {
4215                 return false;
4216             }
4217             if ( !it3.next().getName().equals( "F" ) ) {
4218                 return false;
4219             }
4220             if ( !it3.next().getName().equals( "G" ) ) {
4221                 return false;
4222             }
4223             if ( !it3.next().getName().equals( "1" ) ) {
4224                 return false;
4225             }
4226             if ( !it3.next().getName().equals( "2" ) ) {
4227                 return false;
4228             }
4229             if ( !it3.next().getName().equals( "3" ) ) {
4230                 return false;
4231             }
4232             if ( !it3.next().getName().equals( "4" ) ) {
4233                 return false;
4234             }
4235             if ( !it3.next().getName().equals( "5" ) ) {
4236                 return false;
4237             }
4238             if ( !it3.next().getName().equals( "6" ) ) {
4239                 return false;
4240             }
4241             if ( !it3.next().getName().equals( "f1" ) ) {
4242                 return false;
4243             }
4244             if ( !it3.next().getName().equals( "f2" ) ) {
4245                 return false;
4246             }
4247             if ( !it3.next().getName().equals( "f3" ) ) {
4248                 return false;
4249             }
4250             if ( !it3.next().getName().equals( "a" ) ) {
4251                 return false;
4252             }
4253             if ( !it3.next().getName().equals( "b" ) ) {
4254                 return false;
4255             }
4256             if ( !it3.next().getName().equals( "f21" ) ) {
4257                 return false;
4258             }
4259             if ( !it3.next().getName().equals( "X" ) ) {
4260                 return false;
4261             }
4262             if ( !it3.next().getName().equals( "Y" ) ) {
4263                 return false;
4264             }
4265             if ( !it3.next().getName().equals( "Z" ) ) {
4266                 return false;
4267             }
4268             if ( it3.hasNext() ) {
4269                 return false;
4270             }
4271             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4272             PhylogenyNodeIterator it4;
4273             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4274                 it4.next();
4275             }
4276             for( it4.reset(); it4.hasNext(); ) {
4277                 it4.next();
4278             }
4279             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4280             if ( !it5.next().getName().equals( "r" ) ) {
4281                 return false;
4282             }
4283             if ( !it5.next().getName().equals( "A" ) ) {
4284                 return false;
4285             }
4286             if ( !it5.next().getName().equals( "B" ) ) {
4287                 return false;
4288             }
4289             if ( !it5.next().getName().equals( "C" ) ) {
4290                 return false;
4291             }
4292             if ( !it5.next().getName().equals( "D" ) ) {
4293                 return false;
4294             }
4295             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4296             PhylogenyNodeIterator it6;
4297             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4298                 it6.next();
4299             }
4300             for( it6.reset(); it6.hasNext(); ) {
4301                 it6.next();
4302             }
4303             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4304             if ( !it7.next().getName().equals( "A" ) ) {
4305                 return false;
4306             }
4307             if ( it.hasNext() ) {
4308                 return false;
4309             }
4310         }
4311         catch ( final Exception e ) {
4312             e.printStackTrace( System.out );
4313             return false;
4314         }
4315         return true;
4316     }
4317
4318     private static boolean testNodeRemoval() {
4319         try {
4320             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4321             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4322             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
4323             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
4324                 return false;
4325             }
4326             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
4327             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
4328             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
4329                 return false;
4330             }
4331             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
4332             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
4333             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
4334                 return false;
4335             }
4336         }
4337         catch ( final Exception e ) {
4338             e.printStackTrace( System.out );
4339             return false;
4340         }
4341         return true;
4342     }
4343
4344     private static boolean testMidpointrooting() {
4345         try {
4346             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4347             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4348             PhylogenyMethods.midpointRoot( t0 );
4349             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4350                 return false;
4351             }
4352             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4353                 return false;
4354             }
4355             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4356                            1 ) ) {
4357                 return false;
4358             }
4359             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",
4360                                                  new NHXParser() )[ 0 ];
4361             if ( !t1.isRooted() ) {
4362                 return false;
4363             }
4364             PhylogenyMethods.midpointRoot( t1 );
4365             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4366                 return false;
4367             }
4368             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4369                 return false;
4370             }
4371             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4372                 return false;
4373             }
4374             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4375                 return false;
4376             }
4377             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4378                 return false;
4379             }
4380             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4381                 return false;
4382             }
4383             t1.reRoot( t1.getNode( "A" ) );
4384             PhylogenyMethods.midpointRoot( t1 );
4385             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4386                 return false;
4387             }
4388             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4389                 return false;
4390             }
4391             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4392                 return false;
4393             }
4394             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4395                 return false;
4396             }
4397             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4398                 System.exit( -1 );
4399                 return false;
4400             }
4401             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4402                 return false;
4403             }
4404         }
4405         catch ( final Exception e ) {
4406             e.printStackTrace( System.out );
4407             return false;
4408         }
4409         return true;
4410     }
4411
4412     private static boolean testNexusCharactersParsing() {
4413         try {
4414             final NexusCharactersParser parser = new NexusCharactersParser();
4415             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4416             parser.parse();
4417             String[] labels = parser.getCharStateLabels();
4418             if ( labels.length != 7 ) {
4419                 return false;
4420             }
4421             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4422                 return false;
4423             }
4424             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4425                 return false;
4426             }
4427             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4428                 return false;
4429             }
4430             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4431                 return false;
4432             }
4433             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4434                 return false;
4435             }
4436             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4437                 return false;
4438             }
4439             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4440                 return false;
4441             }
4442             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4443             parser.parse();
4444             labels = parser.getCharStateLabels();
4445             if ( labels.length != 7 ) {
4446                 return false;
4447             }
4448             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4449                 return false;
4450             }
4451             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4452                 return false;
4453             }
4454             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4455                 return false;
4456             }
4457             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4458                 return false;
4459             }
4460             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4461                 return false;
4462             }
4463             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4464                 return false;
4465             }
4466             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4467                 return false;
4468             }
4469         }
4470         catch ( final Exception e ) {
4471             e.printStackTrace( System.out );
4472             return false;
4473         }
4474         return true;
4475     }
4476
4477     private static boolean testNexusMatrixParsing() {
4478         try {
4479             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4480             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4481             parser.parse();
4482             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4483             if ( m.getNumberOfCharacters() != 9 ) {
4484                 return false;
4485             }
4486             if ( m.getNumberOfIdentifiers() != 5 ) {
4487                 return false;
4488             }
4489             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4490                 return false;
4491             }
4492             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4493                 return false;
4494             }
4495             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4496                 return false;
4497             }
4498             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4499                 return false;
4500             }
4501             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4502                 return false;
4503             }
4504             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4505                 return false;
4506             }
4507             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4508                 return false;
4509             }
4510             //            if ( labels.length != 7 ) {
4511             //                return false;
4512             //            }
4513             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4514             //                return false;
4515             //            }
4516             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4517             //                return false;
4518             //            }
4519             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4520             //                return false;
4521             //            }
4522             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4523             //                return false;
4524             //            }
4525             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4526             //                return false;
4527             //            }
4528             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4529             //                return false;
4530             //            }
4531             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4532             //                return false;
4533             //            }
4534             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4535             //            parser.parse();
4536             //            labels = parser.getCharStateLabels();
4537             //            if ( labels.length != 7 ) {
4538             //                return false;
4539             //            }
4540             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4541             //                return false;
4542             //            }
4543             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4544             //                return false;
4545             //            }
4546             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4547             //                return false;
4548             //            }
4549             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4550             //                return false;
4551             //            }
4552             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4553             //                return false;
4554             //            }
4555             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4556             //                return false;
4557             //            }
4558             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4559             //                return false;
4560             //            }
4561         }
4562         catch ( final Exception e ) {
4563             e.printStackTrace( System.out );
4564             return false;
4565         }
4566         return true;
4567     }
4568
4569     private static boolean testNexusTreeParsing() {
4570         try {
4571             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4572             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4573             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4574             if ( phylogenies.length != 1 ) {
4575                 return false;
4576             }
4577             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4578                 return false;
4579             }
4580             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4581                 return false;
4582             }
4583             phylogenies = null;
4584             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4585             if ( phylogenies.length != 1 ) {
4586                 return false;
4587             }
4588             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4589                 return false;
4590             }
4591             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4592                 return false;
4593             }
4594             phylogenies = null;
4595             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4596             if ( phylogenies.length != 1 ) {
4597                 return false;
4598             }
4599             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4600                 return false;
4601             }
4602             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4603                 return false;
4604             }
4605             if ( phylogenies[ 0 ].isRooted() ) {
4606                 return false;
4607             }
4608             phylogenies = null;
4609             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4610             if ( phylogenies.length != 18 ) {
4611                 return false;
4612             }
4613             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4614                 return false;
4615             }
4616             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4617                 return false;
4618             }
4619             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4620                 return false;
4621             }
4622             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4623                 return false;
4624             }
4625             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4626                 return false;
4627             }
4628             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4629                 return false;
4630             }
4631             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4632                 return false;
4633             }
4634             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4635                 return false;
4636             }
4637             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4638                 return false;
4639             }
4640             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4641                 return false;
4642             }
4643             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4644                 return false;
4645             }
4646             if ( phylogenies[ 8 ].isRooted() ) {
4647                 return false;
4648             }
4649             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4650                 return false;
4651             }
4652             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4653                 return false;
4654             }
4655             if ( !phylogenies[ 9 ].isRooted() ) {
4656                 return false;
4657             }
4658             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4659                 return false;
4660             }
4661             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4662                 return false;
4663             }
4664             if ( !phylogenies[ 10 ].isRooted() ) {
4665                 return false;
4666             }
4667             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4668                 return false;
4669             }
4670             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4671                 return false;
4672             }
4673             if ( phylogenies[ 11 ].isRooted() ) {
4674                 return false;
4675             }
4676             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4677                 return false;
4678             }
4679             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4680                 return false;
4681             }
4682             if ( !phylogenies[ 12 ].isRooted() ) {
4683                 return false;
4684             }
4685             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4686                 return false;
4687             }
4688             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4689                 return false;
4690             }
4691             if ( !phylogenies[ 13 ].isRooted() ) {
4692                 return false;
4693             }
4694             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4695                 return false;
4696             }
4697             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4698                 return false;
4699             }
4700             if ( !phylogenies[ 14 ].isRooted() ) {
4701                 return false;
4702             }
4703             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4704                 return false;
4705             }
4706             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4707                 return false;
4708             }
4709             if ( phylogenies[ 15 ].isRooted() ) {
4710                 return false;
4711             }
4712             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4713                 return false;
4714             }
4715             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4716                 return false;
4717             }
4718             if ( !phylogenies[ 16 ].isRooted() ) {
4719                 return false;
4720             }
4721             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4722                 return false;
4723             }
4724             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4725                 return false;
4726             }
4727             if ( phylogenies[ 17 ].isRooted() ) {
4728                 return false;
4729             }
4730             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4731                 return false;
4732             }
4733         }
4734         catch ( final Exception e ) {
4735             e.printStackTrace( System.out );
4736             return false;
4737         }
4738         return true;
4739     }
4740
4741     private static boolean testNexusTreeParsingIterating() {
4742         try {
4743             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
4744             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
4745             if ( !p.hasNext() ) {
4746                 return false;
4747             }
4748             Phylogeny phy = p.next();
4749             if ( phy == null ) {
4750                 return false;
4751             }
4752             if ( phy.getNumberOfExternalNodes() != 25 ) {
4753                 return false;
4754             }
4755             if ( !phy.getName().equals( "" ) ) {
4756                 return false;
4757             }
4758             if ( p.hasNext() ) {
4759                 return false;
4760             }
4761             phy = p.next();
4762             if ( phy != null ) {
4763                 return false;
4764             }
4765             //
4766             p.reset();
4767             if ( !p.hasNext() ) {
4768                 return false;
4769             }
4770             phy = p.next();
4771             if ( phy == null ) {
4772                 return false;
4773             }
4774             if ( phy.getNumberOfExternalNodes() != 25 ) {
4775                 return false;
4776             }
4777             if ( !phy.getName().equals( "" ) ) {
4778                 return false;
4779             }
4780             if ( p.hasNext() ) {
4781                 return false;
4782             }
4783             phy = p.next();
4784             if ( phy != null ) {
4785                 return false;
4786             }
4787             ////
4788             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
4789             if ( !p.hasNext() ) {
4790                 return false;
4791             }
4792             phy = p.next();
4793             if ( phy == null ) {
4794                 return false;
4795             }
4796             if ( phy.getNumberOfExternalNodes() != 10 ) {
4797                 return false;
4798             }
4799             if ( !phy.getName().equals( "name" ) ) {
4800                 return false;
4801             }
4802             if ( p.hasNext() ) {
4803                 return false;
4804             }
4805             phy = p.next();
4806             if ( phy != null ) {
4807                 return false;
4808             }
4809             //
4810             p.reset();
4811             if ( !p.hasNext() ) {
4812                 return false;
4813             }
4814             phy = p.next();
4815             if ( phy == null ) {
4816                 return false;
4817             }
4818             if ( phy.getNumberOfExternalNodes() != 10 ) {
4819                 return false;
4820             }
4821             if ( !phy.getName().equals( "name" ) ) {
4822                 return false;
4823             }
4824             if ( p.hasNext() ) {
4825                 return false;
4826             }
4827             phy = p.next();
4828             if ( phy != null ) {
4829                 return false;
4830             }
4831             ////
4832             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
4833             if ( !p.hasNext() ) {
4834                 return false;
4835             }
4836             phy = p.next();
4837             if ( phy == null ) {
4838                 return false;
4839             }
4840             if ( phy.getNumberOfExternalNodes() != 3 ) {
4841                 return false;
4842             }
4843             if ( !phy.getName().equals( "" ) ) {
4844                 return false;
4845             }
4846             if ( phy.isRooted() ) {
4847                 return false;
4848             }
4849             if ( p.hasNext() ) {
4850                 return false;
4851             }
4852             phy = p.next();
4853             if ( phy != null ) {
4854                 return false;
4855             }
4856             //
4857             p.reset();
4858             if ( !p.hasNext() ) {
4859                 return false;
4860             }
4861             phy = p.next();
4862             if ( phy == null ) {
4863                 return false;
4864             }
4865             if ( phy.getNumberOfExternalNodes() != 3 ) {
4866                 return false;
4867             }
4868             if ( !phy.getName().equals( "" ) ) {
4869                 return false;
4870             }
4871             if ( p.hasNext() ) {
4872                 return false;
4873             }
4874             phy = p.next();
4875             if ( phy != null ) {
4876                 return false;
4877             }
4878             ////
4879             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
4880             //            if ( phylogenies.length != 18 ) {
4881             //                return false;
4882             //            }
4883             //0
4884             if ( !p.hasNext() ) {
4885                 return false;
4886             }
4887             phy = p.next();
4888             if ( phy == null ) {
4889                 return false;
4890             }
4891             if ( phy.getNumberOfExternalNodes() != 10 ) {
4892                 return false;
4893             }
4894             if ( !phy.getName().equals( "tree 0" ) ) {
4895                 return false;
4896             }
4897             //1
4898             if ( !p.hasNext() ) {
4899                 return false;
4900             }
4901             phy = p.next();
4902             if ( phy == null ) {
4903                 return false;
4904             }
4905             if ( phy.getNumberOfExternalNodes() != 10 ) {
4906                 return false;
4907             }
4908             if ( !phy.getName().equals( "tree 1" ) ) {
4909                 return false;
4910             }
4911             //2
4912             if ( !p.hasNext() ) {
4913                 return false;
4914             }
4915             phy = p.next();
4916             if ( phy == null ) {
4917                 return false;
4918             }
4919             if ( phy.getNumberOfExternalNodes() != 3 ) {
4920                 return false;
4921             }
4922             if ( !phy.getName().equals( "" ) ) {
4923                 return false;
4924             }
4925             if ( phy.isRooted() ) {
4926                 return false;
4927             }
4928             //3
4929             if ( !p.hasNext() ) {
4930                 return false;
4931             }
4932             phy = p.next();
4933             if ( phy == null ) {
4934                 return false;
4935             }
4936             if ( phy.getNumberOfExternalNodes() != 4 ) {
4937                 return false;
4938             }
4939             if ( !phy.getName().equals( "" ) ) {
4940                 return false;
4941             }
4942             if ( !phy.isRooted() ) {
4943                 return false;
4944             }
4945             //4
4946             if ( !p.hasNext() ) {
4947                 return false;
4948             }
4949             phy = p.next();
4950             if ( phy == null ) {
4951                 return false;
4952             }
4953             if ( phy.getNumberOfExternalNodes() != 5 ) {
4954                 System.out.println( phy.getNumberOfExternalNodes() );
4955                 return false;
4956             }
4957             if ( !phy.getName().equals( "" ) ) {
4958                 return false;
4959             }
4960             if ( !phy.isRooted() ) {
4961                 return false;
4962             }
4963             //5
4964             if ( !p.hasNext() ) {
4965                 return false;
4966             }
4967             phy = p.next();
4968             if ( phy == null ) {
4969                 return false;
4970             }
4971             if ( phy.getNumberOfExternalNodes() != 3 ) {
4972                 return false;
4973             }
4974             if ( !phy.getName().equals( "" ) ) {
4975                 return false;
4976             }
4977             if ( phy.isRooted() ) {
4978                 return false;
4979             }
4980             //6
4981             if ( !p.hasNext() ) {
4982                 return false;
4983             }
4984             phy = p.next();
4985             if ( phy == null ) {
4986                 return false;
4987             }
4988             if ( phy.getNumberOfExternalNodes() != 2 ) {
4989                 return false;
4990             }
4991             if ( !phy.getName().equals( "" ) ) {
4992                 return false;
4993             }
4994             if ( !phy.isRooted() ) {
4995                 return false;
4996             }
4997             //7
4998             if ( !p.hasNext() ) {
4999                 return false;
5000             }
5001             phy = p.next();
5002             if ( phy.getNumberOfExternalNodes() != 3 ) {
5003                 return false;
5004             }
5005             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5006                 return false;
5007             }
5008             if ( !phy.isRooted() ) {
5009                 return false;
5010             }
5011             //8
5012             if ( !p.hasNext() ) {
5013                 return false;
5014             }
5015             phy = p.next();
5016             if ( phy.getNumberOfExternalNodes() != 3 ) {
5017                 return false;
5018             }
5019             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
5020                 return false;
5021             }
5022             if ( !phy.getName().equals( "tree 8" ) ) {
5023                 return false;
5024             }
5025             //9
5026             if ( !p.hasNext() ) {
5027                 return false;
5028             }
5029             phy = p.next();
5030             if ( phy.getNumberOfExternalNodes() != 3 ) {
5031                 return false;
5032             }
5033             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
5034                 return false;
5035             }
5036             if ( !phy.getName().equals( "tree 9" ) ) {
5037                 return false;
5038             }
5039             //10
5040             if ( !p.hasNext() ) {
5041                 return false;
5042             }
5043             phy = p.next();
5044             if ( phy.getNumberOfExternalNodes() != 3 ) {
5045                 return false;
5046             }
5047             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5048                 return false;
5049             }
5050             if ( !phy.getName().equals( "tree 10" ) ) {
5051                 return false;
5052             }
5053             if ( !phy.isRooted() ) {
5054                 return false;
5055             }
5056             //11
5057             if ( !p.hasNext() ) {
5058                 return false;
5059             }
5060             phy = p.next();
5061             if ( phy.getNumberOfExternalNodes() != 3 ) {
5062                 return false;
5063             }
5064             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
5065                 return false;
5066             }
5067             if ( !phy.getName().equals( "tree 11" ) ) {
5068                 return false;
5069             }
5070             if ( phy.isRooted() ) {
5071                 return false;
5072             }
5073             //12
5074             if ( !p.hasNext() ) {
5075                 return false;
5076             }
5077             phy = p.next();
5078             if ( phy.getNumberOfExternalNodes() != 3 ) {
5079                 return false;
5080             }
5081             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
5082                 return false;
5083             }
5084             if ( !phy.getName().equals( "tree 12" ) ) {
5085                 return false;
5086             }
5087             if ( !phy.isRooted() ) {
5088                 return false;
5089             }
5090             //13
5091             if ( !p.hasNext() ) {
5092                 return false;
5093             }
5094             phy = p.next();
5095             if ( phy.getNumberOfExternalNodes() != 3 ) {
5096                 return false;
5097             }
5098             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5099                 return false;
5100             }
5101             if ( !phy.getName().equals( "tree 13" ) ) {
5102                 return false;
5103             }
5104             if ( !phy.isRooted() ) {
5105                 return false;
5106             }
5107             //14
5108             if ( !p.hasNext() ) {
5109                 return false;
5110             }
5111             phy = p.next();
5112             if ( phy.getNumberOfExternalNodes() != 10 ) {
5113                 System.out.println( phy.getNumberOfExternalNodes() );
5114                 return false;
5115             }
5116             if ( !phy
5117                     .toNewHampshire()
5118                     .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;" ) ) {
5119                 System.out.println( phy.toNewHampshire() );
5120                 return false;
5121             }
5122             if ( !phy.getName().equals( "tree 14" ) ) {
5123                 return false;
5124             }
5125             if ( !phy.isRooted() ) {
5126                 return false;
5127             }
5128             //15
5129             if ( !p.hasNext() ) {
5130                 return false;
5131             }
5132             phy = p.next();
5133             if ( phy.getNumberOfExternalNodes() != 10 ) {
5134                 System.out.println( phy.getNumberOfExternalNodes() );
5135                 return false;
5136             }
5137             if ( !phy
5138                     .toNewHampshire()
5139                     .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;" ) ) {
5140                 System.out.println( phy.toNewHampshire() );
5141                 return false;
5142             }
5143             if ( !phy.getName().equals( "tree 15" ) ) {
5144                 return false;
5145             }
5146             if ( phy.isRooted() ) {
5147                 return false;
5148             }
5149             //16
5150             if ( !p.hasNext() ) {
5151                 return false;
5152             }
5153             phy = p.next();
5154             if ( phy.getNumberOfExternalNodes() != 10 ) {
5155                 System.out.println( phy.getNumberOfExternalNodes() );
5156                 return false;
5157             }
5158             if ( !phy
5159                     .toNewHampshire()
5160                     .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;" ) ) {
5161                 System.out.println( phy.toNewHampshire() );
5162                 return false;
5163             }
5164             if ( !phy.getName().equals( "tree 16" ) ) {
5165                 return false;
5166             }
5167             if ( !phy.isRooted() ) {
5168                 return false;
5169             }
5170             //17
5171             if ( !p.hasNext() ) {
5172                 return false;
5173             }
5174             phy = p.next();
5175             if ( phy.getNumberOfExternalNodes() != 10 ) {
5176                 System.out.println( phy.getNumberOfExternalNodes() );
5177                 return false;
5178             }
5179             if ( !phy
5180                     .toNewHampshire()
5181                     .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;" ) ) {
5182                 System.out.println( phy.toNewHampshire() );
5183                 return false;
5184             }
5185             if ( !phy.getName().equals( "tree 17" ) ) {
5186                 return false;
5187             }
5188             if ( phy.isRooted() ) {
5189                 return false;
5190             }
5191             //
5192             if ( p.hasNext() ) {
5193                 return false;
5194             }
5195             phy = p.next();
5196             if ( phy != null ) {
5197                 return false;
5198             }
5199             p.reset();
5200             //0
5201             if ( !p.hasNext() ) {
5202                 return false;
5203             }
5204             phy = p.next();
5205             if ( phy == null ) {
5206                 return false;
5207             }
5208             if ( phy.getNumberOfExternalNodes() != 10 ) {
5209                 return false;
5210             }
5211             if ( !phy.getName().equals( "tree 0" ) ) {
5212                 return false;
5213             }
5214             //1
5215             if ( !p.hasNext() ) {
5216                 return false;
5217             }
5218             phy = p.next();
5219             if ( phy == null ) {
5220                 return false;
5221             }
5222             if ( phy.getNumberOfExternalNodes() != 10 ) {
5223                 return false;
5224             }
5225             if ( !phy.getName().equals( "tree 1" ) ) {
5226                 return false;
5227             }
5228             //2
5229             if ( !p.hasNext() ) {
5230                 return false;
5231             }
5232             phy = p.next();
5233             if ( phy == null ) {
5234                 return false;
5235             }
5236             if ( phy.getNumberOfExternalNodes() != 3 ) {
5237                 return false;
5238             }
5239             if ( !phy.getName().equals( "" ) ) {
5240                 return false;
5241             }
5242             if ( phy.isRooted() ) {
5243                 return false;
5244             }
5245             //3
5246             if ( !p.hasNext() ) {
5247                 return false;
5248             }
5249             phy = p.next();
5250             if ( phy == null ) {
5251                 return false;
5252             }
5253             if ( phy.getNumberOfExternalNodes() != 4 ) {
5254                 return false;
5255             }
5256             if ( !phy.getName().equals( "" ) ) {
5257                 return false;
5258             }
5259             if ( !phy.isRooted() ) {
5260                 return false;
5261             }
5262             //4
5263             if ( !p.hasNext() ) {
5264                 return false;
5265             }
5266             phy = p.next();
5267             if ( phy == null ) {
5268                 return false;
5269             }
5270             if ( phy.getNumberOfExternalNodes() != 5 ) {
5271                 System.out.println( phy.getNumberOfExternalNodes() );
5272                 return false;
5273             }
5274             if ( !phy.getName().equals( "" ) ) {
5275                 return false;
5276             }
5277             if ( !phy.isRooted() ) {
5278                 return false;
5279             }
5280             //5
5281             if ( !p.hasNext() ) {
5282                 return false;
5283             }
5284             phy = p.next();
5285             if ( phy == null ) {
5286                 return false;
5287             }
5288             if ( phy.getNumberOfExternalNodes() != 3 ) {
5289                 return false;
5290             }
5291             if ( !phy.getName().equals( "" ) ) {
5292                 return false;
5293             }
5294             if ( phy.isRooted() ) {
5295                 return false;
5296             }
5297         }
5298         catch ( final Exception e ) {
5299             e.printStackTrace( System.out );
5300             return false;
5301         }
5302         return true;
5303     }
5304
5305     private static boolean testNexusTreeParsingTranslating() {
5306         try {
5307             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5308             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5309             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
5310             if ( phylogenies.length != 1 ) {
5311                 return false;
5312             }
5313             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5314                 return false;
5315             }
5316             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5317                 return false;
5318             }
5319             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5320                 return false;
5321             }
5322             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5323                 return false;
5324             }
5325             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5326                     .equals( "Aranaeus" ) ) {
5327                 return false;
5328             }
5329             phylogenies = null;
5330             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
5331             if ( phylogenies.length != 3 ) {
5332                 return false;
5333             }
5334             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5335                 return false;
5336             }
5337             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5338                 return false;
5339             }
5340             if ( phylogenies[ 0 ].isRooted() ) {
5341                 return false;
5342             }
5343             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5344                 return false;
5345             }
5346             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5347                 return false;
5348             }
5349             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5350                     .equals( "Aranaeus" ) ) {
5351                 return false;
5352             }
5353             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5354                 return false;
5355             }
5356             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5357                 return false;
5358             }
5359             if ( phylogenies[ 1 ].isRooted() ) {
5360                 return false;
5361             }
5362             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5363                 return false;
5364             }
5365             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5366                 return false;
5367             }
5368             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5369                     .equals( "Aranaeus" ) ) {
5370                 return false;
5371             }
5372             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5373                 return false;
5374             }
5375             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5376                 return false;
5377             }
5378             if ( !phylogenies[ 2 ].isRooted() ) {
5379                 return false;
5380             }
5381             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5382                 return false;
5383             }
5384             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5385                 return false;
5386             }
5387             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5388                     .equals( "Aranaeus" ) ) {
5389                 return false;
5390             }
5391             phylogenies = null;
5392             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
5393             if ( phylogenies.length != 3 ) {
5394                 return false;
5395             }
5396             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5397                 return false;
5398             }
5399             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5400                 return false;
5401             }
5402             if ( phylogenies[ 0 ].isRooted() ) {
5403                 return false;
5404             }
5405             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5406                 return false;
5407             }
5408             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5409                 return false;
5410             }
5411             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5412                     .equals( "Aranaeus" ) ) {
5413                 return false;
5414             }
5415             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5416                 return false;
5417             }
5418             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5419                 return false;
5420             }
5421             if ( phylogenies[ 1 ].isRooted() ) {
5422                 return false;
5423             }
5424             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5425                 return false;
5426             }
5427             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5428                 return false;
5429             }
5430             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5431                     .equals( "Aranaeus" ) ) {
5432                 return false;
5433             }
5434             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5435                 return false;
5436             }
5437             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5438                 return false;
5439             }
5440             if ( !phylogenies[ 2 ].isRooted() ) {
5441                 return false;
5442             }
5443             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5444                 return false;
5445             }
5446             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5447                 return false;
5448             }
5449             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5450                     .equals( "Aranaeus" ) ) {
5451                 return false;
5452             }
5453         }
5454         catch ( final Exception e ) {
5455             e.printStackTrace( System.out );
5456             return false;
5457         }
5458         return true;
5459     }
5460
5461     private static boolean testNHParsing() {
5462         try {
5463             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5464             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
5465             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
5466                 return false;
5467             }
5468             final NHXParser nhxp = new NHXParser();
5469             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
5470             nhxp.setReplaceUnderscores( true );
5471             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
5472             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
5473                 return false;
5474             }
5475             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
5476                 return false;
5477             }
5478             final Phylogeny p1b = factory
5479                     .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 ",
5480                              new NHXParser() )[ 0 ];
5481             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
5482                 return false;
5483             }
5484             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
5485                 return false;
5486             }
5487             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
5488             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
5489             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
5490             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
5491             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
5492             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
5493             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
5494             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
5495             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
5496             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
5497             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
5498                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
5499                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
5500                                                     new NHXParser() );
5501             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
5502                 return false;
5503             }
5504             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
5505                 return false;
5506             }
5507             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
5508                 return false;
5509             }
5510             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
5511                 return false;
5512             }
5513             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
5514             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
5515             final String p16_S = "((A,B),C)";
5516             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
5517             if ( p16.length != 1 ) {
5518                 return false;
5519             }
5520             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
5521                 return false;
5522             }
5523             final String p17_S = "(C,(A,B))";
5524             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
5525             if ( p17.length != 1 ) {
5526                 return false;
5527             }
5528             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
5529                 return false;
5530             }
5531             final String p18_S = "((A,B),(C,D))";
5532             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
5533             if ( p18.length != 1 ) {
5534                 return false;
5535             }
5536             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
5537                 return false;
5538             }
5539             final String p19_S = "(((A,B),C),D)";
5540             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
5541             if ( p19.length != 1 ) {
5542                 return false;
5543             }
5544             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
5545                 return false;
5546             }
5547             final String p20_S = "(A,(B,(C,D)))";
5548             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
5549             if ( p20.length != 1 ) {
5550                 return false;
5551             }
5552             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
5553                 return false;
5554             }
5555             final String p21_S = "(A,(B,(C,(D,E))))";
5556             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
5557             if ( p21.length != 1 ) {
5558                 return false;
5559             }
5560             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
5561                 return false;
5562             }
5563             final String p22_S = "((((A,B),C),D),E)";
5564             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
5565             if ( p22.length != 1 ) {
5566                 return false;
5567             }
5568             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
5569                 return false;
5570             }
5571             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5572             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
5573             if ( p23.length != 1 ) {
5574                 System.out.println( "xl=" + p23.length );
5575                 System.exit( -1 );
5576                 return false;
5577             }
5578             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
5579                 return false;
5580             }
5581             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5582             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
5583             if ( p24.length != 1 ) {
5584                 return false;
5585             }
5586             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
5587                 return false;
5588             }
5589             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5590             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5591             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
5592             if ( p241.length != 2 ) {
5593                 return false;
5594             }
5595             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
5596                 return false;
5597             }
5598             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
5599                 return false;
5600             }
5601             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
5602                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
5603                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
5604                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
5605                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
5606                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
5607                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
5608                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
5609             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
5610             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
5611                 return false;
5612             }
5613             final String p26_S = "(A,B)ab";
5614             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
5615             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
5616                 return false;
5617             }
5618             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5619             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
5620             if ( p27s.length != 1 ) {
5621                 System.out.println( "xxl=" + p27s.length );
5622                 System.exit( -1 );
5623                 return false;
5624             }
5625             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5626                 System.out.println( p27s[ 0 ].toNewHampshireX() );
5627                 System.exit( -1 );
5628                 return false;
5629             }
5630             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
5631                                                     new NHXParser() );
5632             if ( p27.length != 1 ) {
5633                 System.out.println( "yl=" + p27.length );
5634                 System.exit( -1 );
5635                 return false;
5636             }
5637             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5638                 System.out.println( p27[ 0 ].toNewHampshireX() );
5639                 System.exit( -1 );
5640                 return false;
5641             }
5642             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5643             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5644             final String p28_S3 = "(A,B)ab";
5645             final String p28_S4 = "((((A,B),C),D),;E;)";
5646             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
5647                                                     new NHXParser() );
5648             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
5649                 return false;
5650             }
5651             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
5652                 return false;
5653             }
5654             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
5655                 return false;
5656             }
5657             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
5658                 return false;
5659             }
5660             if ( p28.length != 4 ) {
5661                 return false;
5662             }
5663             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";
5664             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
5665             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
5666                 return false;
5667             }
5668             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";
5669             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
5670             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
5671                 return false;
5672             }
5673             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
5674             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
5675             if ( ( p32.length != 0 ) ) {
5676                 return false;
5677             }
5678             final String p33_S = "A";
5679             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
5680             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
5681                 return false;
5682             }
5683             final String p34_S = "B;";
5684             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
5685             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
5686                 return false;
5687             }
5688             final String p35_S = "B:0.2";
5689             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
5690             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
5691                 return false;
5692             }
5693             final String p36_S = "(A)";
5694             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
5695             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
5696                 return false;
5697             }
5698             final String p37_S = "((A))";
5699             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
5700             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
5701                 return false;
5702             }
5703             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5704             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
5705             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
5706                 return false;
5707             }
5708             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5709             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
5710             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
5711                 return false;
5712             }
5713             final String p40_S = "(A,B,C)";
5714             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
5715             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
5716                 return false;
5717             }
5718             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
5719             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
5720             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
5721                 return false;
5722             }
5723             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
5724             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
5725             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
5726                 return false;
5727             }
5728             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)";
5729             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
5730             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
5731                 return false;
5732             }
5733             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)))";
5734             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
5735             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
5736                 return false;
5737             }
5738             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
5739             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
5740             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
5741                 return false;
5742             }
5743             final String p46_S = "";
5744             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
5745             if ( p46.length != 0 ) {
5746                 return false;
5747             }
5748             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
5749             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5750                 return false;
5751             }
5752             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5753             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5754                 return false;
5755             }
5756             final Phylogeny p49 = factory
5757                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
5758                              new NHXParser() )[ 0 ];
5759             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5760                 return false;
5761             }
5762             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5763             if ( p50.getNode( "A" ) == null ) {
5764                 return false;
5765             }
5766             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5767                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
5768                 return false;
5769             }
5770             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
5771                 return false;
5772             }
5773             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
5774                     .equals( "((A,B)88:2.0,C);" ) ) {
5775                 return false;
5776             }
5777             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5778             if ( p51.getNode( "A(A" ) == null ) {
5779                 return false;
5780             }
5781             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5782             if ( p52.getNode( "A(A" ) == null ) {
5783                 return false;
5784             }
5785             final Phylogeny p53 = factory
5786                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
5787                              new NHXParser() )[ 0 ];
5788             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
5789                 return false;
5790             }
5791             // 
5792             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
5793             if ( p54.getNode( "A" ) == null ) {
5794                 return false;
5795             }
5796             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5797                     .equals( "((A,B)[88],C);" ) ) {
5798                 return false;
5799             }
5800         }
5801         catch ( final Exception e ) {
5802             e.printStackTrace( System.out );
5803             return false;
5804         }
5805         return true;
5806     }
5807
5808     private static boolean testNHParsingIter() {
5809         try {
5810             final String p0_str = "(A,B);";
5811             final NHXParser p = new NHXParser();
5812             p.setSource( p0_str );
5813             if ( !p.hasNext() ) {
5814                 return false;
5815             }
5816             final Phylogeny p0 = p.next();
5817             if ( !p0.toNewHampshire().equals( p0_str ) ) {
5818                 System.out.println( p0.toNewHampshire() );
5819                 return false;
5820             }
5821             if ( p.hasNext() ) {
5822                 return false;
5823             }
5824             if ( p.next() != null ) {
5825                 return false;
5826             }
5827             //
5828             final String p00_str = "(A,B)root;";
5829             p.setSource( p00_str );
5830             final Phylogeny p00 = p.next();
5831             if ( !p00.toNewHampshire().equals( p00_str ) ) {
5832                 System.out.println( p00.toNewHampshire() );
5833                 return false;
5834             }
5835             //
5836             final String p000_str = "A;";
5837             p.setSource( p000_str );
5838             final Phylogeny p000 = p.next();
5839             if ( !p000.toNewHampshire().equals( p000_str ) ) {
5840                 System.out.println( p000.toNewHampshire() );
5841                 return false;
5842             }
5843             //
5844             final String p0000_str = "A";
5845             p.setSource( p0000_str );
5846             final Phylogeny p0000 = p.next();
5847             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
5848                 System.out.println( p0000.toNewHampshire() );
5849                 return false;
5850             }
5851             //
5852             p.setSource( "(A)" );
5853             final Phylogeny p00000 = p.next();
5854             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
5855                 System.out.println( p00000.toNewHampshire() );
5856                 return false;
5857             }
5858             //
5859             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
5860             p.setSource( p1_str );
5861             if ( !p.hasNext() ) {
5862                 return false;
5863             }
5864             final Phylogeny p1_0 = p.next();
5865             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
5866                 System.out.println( p1_0.toNewHampshire() );
5867                 return false;
5868             }
5869             if ( !p.hasNext() ) {
5870                 return false;
5871             }
5872             final Phylogeny p1_1 = p.next();
5873             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
5874                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
5875                 return false;
5876             }
5877             if ( !p.hasNext() ) {
5878                 return false;
5879             }
5880             final Phylogeny p1_2 = p.next();
5881             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
5882                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
5883                 return false;
5884             }
5885             if ( !p.hasNext() ) {
5886                 return false;
5887             }
5888             final Phylogeny p1_3 = p.next();
5889             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
5890                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
5891                 return false;
5892             }
5893             if ( p.hasNext() ) {
5894                 return false;
5895             }
5896             if ( p.next() != null ) {
5897                 return false;
5898             }
5899             //
5900             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
5901             p.setSource( p2_str );
5902             if ( !p.hasNext() ) {
5903                 return false;
5904             }
5905             Phylogeny p2_0 = p.next();
5906             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5907                 System.out.println( p2_0.toNewHampshire() );
5908                 return false;
5909             }
5910             if ( !p.hasNext() ) {
5911                 return false;
5912             }
5913             Phylogeny p2_1 = p.next();
5914             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5915                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5916                 return false;
5917             }
5918             if ( !p.hasNext() ) {
5919                 return false;
5920             }
5921             Phylogeny p2_2 = p.next();
5922             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5923                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5924                 return false;
5925             }
5926             if ( !p.hasNext() ) {
5927                 return false;
5928             }
5929             Phylogeny p2_3 = p.next();
5930             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5931                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5932                 return false;
5933             }
5934             if ( !p.hasNext() ) {
5935                 return false;
5936             }
5937             Phylogeny p2_4 = p.next();
5938             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5939                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5940                 return false;
5941             }
5942             if ( p.hasNext() ) {
5943                 return false;
5944             }
5945             if ( p.next() != null ) {
5946                 return false;
5947             }
5948             ////
5949             p.reset();
5950             if ( !p.hasNext() ) {
5951                 return false;
5952             }
5953             p2_0 = p.next();
5954             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5955                 System.out.println( p2_0.toNewHampshire() );
5956                 return false;
5957             }
5958             if ( !p.hasNext() ) {
5959                 return false;
5960             }
5961             p2_1 = p.next();
5962             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5963                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5964                 return false;
5965             }
5966             if ( !p.hasNext() ) {
5967                 return false;
5968             }
5969             p2_2 = p.next();
5970             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5971                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5972                 return false;
5973             }
5974             if ( !p.hasNext() ) {
5975                 return false;
5976             }
5977             p2_3 = p.next();
5978             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5979                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5980                 return false;
5981             }
5982             if ( !p.hasNext() ) {
5983                 return false;
5984             }
5985             p2_4 = p.next();
5986             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5987                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5988                 return false;
5989             }
5990             if ( p.hasNext() ) {
5991                 return false;
5992             }
5993             if ( p.next() != null ) {
5994                 return false;
5995             }
5996             //
5997             final String p3_str = "((A,B),C)abc";
5998             p.setSource( p3_str );
5999             if ( !p.hasNext() ) {
6000                 return false;
6001             }
6002             final Phylogeny p3_0 = p.next();
6003             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
6004                 return false;
6005             }
6006             if ( p.hasNext() ) {
6007                 return false;
6008             }
6009             if ( p.next() != null ) {
6010                 return false;
6011             }
6012             //
6013             final String p4_str = "((A,B)ab,C)abc";
6014             p.setSource( p4_str );
6015             if ( !p.hasNext() ) {
6016                 return false;
6017             }
6018             final Phylogeny p4_0 = p.next();
6019             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
6020                 return false;
6021             }
6022             if ( p.hasNext() ) {
6023                 return false;
6024             }
6025             if ( p.next() != null ) {
6026                 return false;
6027             }
6028             //
6029             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
6030             p.setSource( p5_str );
6031             if ( !p.hasNext() ) {
6032                 return false;
6033             }
6034             final Phylogeny p5_0 = p.next();
6035             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
6036                 return false;
6037             }
6038             if ( p.hasNext() ) {
6039                 return false;
6040             }
6041             if ( p.next() != null ) {
6042                 return false;
6043             }
6044             //
6045             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6046             p.setSource( p6_str );
6047             if ( !p.hasNext() ) {
6048                 return false;
6049             }
6050             Phylogeny p6_0 = p.next();
6051             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6052                 return false;
6053             }
6054             if ( p.hasNext() ) {
6055                 return false;
6056             }
6057             if ( p.next() != null ) {
6058                 return false;
6059             }
6060             p.reset();
6061             if ( !p.hasNext() ) {
6062                 return false;
6063             }
6064             p6_0 = p.next();
6065             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6066                 return false;
6067             }
6068             if ( p.hasNext() ) {
6069                 return false;
6070             }
6071             if ( p.next() != null ) {
6072                 return false;
6073             }
6074             //
6075             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6076             p.setSource( p7_str );
6077             if ( !p.hasNext() ) {
6078                 return false;
6079             }
6080             Phylogeny p7_0 = p.next();
6081             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6082                 return false;
6083             }
6084             if ( p.hasNext() ) {
6085                 return false;
6086             }
6087             if ( p.next() != null ) {
6088                 return false;
6089             }
6090             p.reset();
6091             if ( !p.hasNext() ) {
6092                 return false;
6093             }
6094             p7_0 = p.next();
6095             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6096                 return false;
6097             }
6098             if ( p.hasNext() ) {
6099                 return false;
6100             }
6101             if ( p.next() != null ) {
6102                 return false;
6103             }
6104             //
6105             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
6106             p.setSource( p8_str );
6107             if ( !p.hasNext() ) {
6108                 return false;
6109             }
6110             Phylogeny p8_0 = p.next();
6111             if ( !p8_0.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.hasNext() ) {
6118                 return false;
6119             }
6120             Phylogeny p8_1 = p.next();
6121             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6122                 return false;
6123             }
6124             if ( p.hasNext() ) {
6125                 return false;
6126             }
6127             if ( p.next() != null ) {
6128                 return false;
6129             }
6130             p.reset();
6131             if ( !p.hasNext() ) {
6132                 return false;
6133             }
6134             p8_0 = p.next();
6135             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6136                 return false;
6137             }
6138             if ( !p.hasNext() ) {
6139                 return false;
6140             }
6141             p8_1 = p.next();
6142             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6143                 return false;
6144             }
6145             if ( p.hasNext() ) {
6146                 return false;
6147             }
6148             if ( p.next() != null ) {
6149                 return false;
6150             }
6151             p.reset();
6152             //
6153             p.setSource( "" );
6154             if ( p.hasNext() ) {
6155                 return false;
6156             }
6157             //
6158             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
6159             if ( !p.hasNext() ) {
6160                 return false;
6161             }
6162             Phylogeny p_27 = p.next();
6163             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6164                 System.out.println( p_27.toNewHampshireX() );
6165                 System.exit( -1 );
6166                 return false;
6167             }
6168             if ( p.hasNext() ) {
6169                 return false;
6170             }
6171             if ( p.next() != null ) {
6172                 return false;
6173             }
6174             p.reset();
6175             if ( !p.hasNext() ) {
6176                 return false;
6177             }
6178             p_27 = p.next();
6179             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6180                 System.out.println( p_27.toNewHampshireX() );
6181                 System.exit( -1 );
6182                 return false;
6183             }
6184             if ( p.hasNext() ) {
6185                 return false;
6186             }
6187             if ( p.next() != null ) {
6188                 return false;
6189             }
6190         }
6191         catch ( final Exception e ) {
6192             e.printStackTrace( System.out );
6193             return false;
6194         }
6195         return true;
6196     }
6197
6198     private static boolean testNHXconversion() {
6199         try {
6200             final PhylogenyNode n1 = new PhylogenyNode();
6201             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6202             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6203             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6204             final PhylogenyNode n5 = PhylogenyNode
6205                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
6206             final PhylogenyNode n6 = PhylogenyNode
6207                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
6208             if ( !n1.toNewHampshireX().equals( "" ) ) {
6209                 return false;
6210             }
6211             if ( !n2.toNewHampshireX().equals( "" ) ) {
6212                 return false;
6213             }
6214             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
6215                 return false;
6216             }
6217             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
6218                 return false;
6219             }
6220             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
6221                 return false;
6222             }
6223             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
6224                 System.out.println( n6.toNewHampshireX() );
6225                 return false;
6226             }
6227         }
6228         catch ( final Exception e ) {
6229             e.printStackTrace( System.out );
6230             return false;
6231         }
6232         return true;
6233     }
6234
6235     private static boolean testTaxonomyExtraction() {
6236         try {
6237             final PhylogenyNode n0 = PhylogenyNode
6238                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6239             if ( n0.getNodeData().isHasTaxonomy() ) {
6240                 return false;
6241             }
6242             final PhylogenyNode n1 = PhylogenyNode
6243                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6244             if ( n1.getNodeData().isHasTaxonomy() ) {
6245                 System.out.println( n1.toString() );
6246                 return false;
6247             }
6248             final PhylogenyNode n2x = PhylogenyNode
6249                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6250             if ( n2x.getNodeData().isHasTaxonomy() ) {
6251                 return false;
6252             }
6253             final PhylogenyNode n3 = PhylogenyNode
6254                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6255             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6256                 System.out.println( n3.toString() );
6257                 return false;
6258             }
6259             final PhylogenyNode n4 = PhylogenyNode
6260                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6261             if ( n4.getNodeData().isHasTaxonomy() ) {
6262                 System.out.println( n4.toString() );
6263                 return false;
6264             }
6265             final PhylogenyNode n5 = PhylogenyNode
6266                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6267             if ( n5.getNodeData().isHasTaxonomy() ) {
6268                 System.out.println( n5.toString() );
6269                 return false;
6270             }
6271             final PhylogenyNode n6 = PhylogenyNode
6272                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6273             if ( n6.getNodeData().isHasTaxonomy() ) {
6274                 System.out.println( n6.toString() );
6275                 return false;
6276             }
6277             final PhylogenyNode n7 = PhylogenyNode
6278                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6279             if ( n7.getNodeData().isHasTaxonomy() ) {
6280                 System.out.println( n7.toString() );
6281                 return false;
6282             }
6283             final PhylogenyNode n8 = PhylogenyNode
6284                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6285             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6286                 System.out.println( n8.toString() );
6287                 return false;
6288             }
6289             final PhylogenyNode n9 = PhylogenyNode
6290                     .createInstanceFromNhxString( "blag_12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6291             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6292                 System.out.println( n9.toString() );
6293                 return false;
6294             }
6295             final PhylogenyNode n10x = PhylogenyNode
6296                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6297             if ( n10x.getNodeData().isHasTaxonomy() ) {
6298                 System.out.println( n10x.toString() );
6299                 return false;
6300             }
6301             final PhylogenyNode n10xx = PhylogenyNode
6302                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6303             if ( n10xx.getNodeData().isHasTaxonomy() ) {
6304                 System.out.println( n10xx.toString() );
6305                 return false;
6306             }
6307             final PhylogenyNode n10 = PhylogenyNode
6308                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6309             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
6310                 System.out.println( n10.toString() );
6311                 return false;
6312             }
6313             final PhylogenyNode n11 = PhylogenyNode
6314                     .createInstanceFromNhxString( "blag_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6315             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
6316                 System.out.println( n11.toString() );
6317                 return false;
6318             }
6319             final PhylogenyNode n12 = PhylogenyNode
6320                     .createInstanceFromNhxString( "blag_Mus_musculus_musculus",
6321                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6322             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
6323                 System.out.println( n12.toString() );
6324                 return false;
6325             }
6326             final PhylogenyNode n13 = PhylogenyNode
6327                     .createInstanceFromNhxString( "blag_Mus_musculus1",
6328                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6329             if ( n13.getNodeData().isHasTaxonomy() ) {
6330                 System.out.println( n13.toString() );
6331                 return false;
6332             }
6333             final PhylogenyNode n14 = PhylogenyNode
6334                     .createInstanceFromNhxString( "blag_Mus_musculus_11",
6335                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6336             if ( n14.getNodeData().isHasTaxonomy() ) {
6337                 System.out.println( n14.toString() );
6338                 return false;
6339             }
6340             final PhylogenyNode n15 = PhylogenyNode
6341                     .createInstanceFromNhxString( "blag_Mus_musculus_v11",
6342                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6343             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus v11" ) ) {
6344                 System.out.println( n15.toString() );
6345                 return false;
6346             }
6347             final PhylogenyNode n16 = PhylogenyNode
6348                     .createInstanceFromNhxString( "blag_Mus_musculus_/11",
6349                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6350             if ( n16.getNodeData().isHasTaxonomy() ) {
6351                 System.out.println( n16.toString() );
6352                 return false;
6353             }
6354             final PhylogenyNode n17 = PhylogenyNode
6355                     .createInstanceFromNhxString( "blag_Mus_musculus_v",
6356                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6357             if ( n17.getNodeData().isHasTaxonomy() ) {
6358                 System.out.println( n17.toString() );
6359                 return false;
6360             }
6361         }
6362         catch ( final Exception e ) {
6363             e.printStackTrace( System.out );
6364             return false;
6365         }
6366         return true;
6367     }
6368
6369     private static boolean testNHXNodeParsing() {
6370         try {
6371             final PhylogenyNode n1 = new PhylogenyNode();
6372             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6373             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6374             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6375             final PhylogenyNode n5 = PhylogenyNode
6376                     .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]" );
6377             if ( !n3.getName().equals( "n3" ) ) {
6378                 return false;
6379             }
6380             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6381                 return false;
6382             }
6383             if ( n3.isDuplication() ) {
6384                 return false;
6385             }
6386             if ( n3.isHasAssignedEvent() ) {
6387                 return false;
6388             }
6389             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
6390                 return false;
6391             }
6392             if ( !n4.getName().equals( "n4" ) ) {
6393                 return false;
6394             }
6395             if ( n4.getDistanceToParent() != 0.01 ) {
6396                 return false;
6397             }
6398             if ( !n5.getName().equals( "n5" ) ) {
6399                 return false;
6400             }
6401             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
6402                 return false;
6403             }
6404             if ( n5.getDistanceToParent() != 0.1 ) {
6405                 return false;
6406             }
6407             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
6408                 return false;
6409             }
6410             if ( !n5.isDuplication() ) {
6411                 return false;
6412             }
6413             if ( !n5.isHasAssignedEvent() ) {
6414                 return false;
6415             }
6416             final PhylogenyNode n8 = PhylogenyNode
6417                     .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6418             if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
6419                 return false;
6420             }
6421             if ( PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
6422                 return false;
6423             }
6424             final PhylogenyNode n9 = PhylogenyNode
6425                     .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01",
6426                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6427             if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
6428                 return false;
6429             }
6430             if ( PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
6431                 return false;
6432             }
6433             final PhylogenyNode n10 = PhylogenyNode
6434                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6435             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
6436                 return false;
6437             }
6438             final PhylogenyNode n20 = PhylogenyNode
6439                     .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6440             if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
6441                 return false;
6442             }
6443             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
6444                 return false;
6445             }
6446             final PhylogenyNode n20x = PhylogenyNode
6447                     .createInstanceFromNhxString( "n20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6448             if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
6449                 return false;
6450             }
6451             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
6452                 return false;
6453             }
6454             final PhylogenyNode n20xx = PhylogenyNode
6455                     .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6456             if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
6457                 return false;
6458             }
6459             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
6460                 return false;
6461             }
6462             final PhylogenyNode n20xxx = PhylogenyNode
6463                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6464             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
6465                 return false;
6466             }
6467             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
6468                 return false;
6469             }
6470             final PhylogenyNode n20xxxx = PhylogenyNode
6471                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6472             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
6473                 return false;
6474             }
6475             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
6476                 return false;
6477             }
6478             final PhylogenyNode n21 = PhylogenyNode
6479                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6480             if ( !n21.getName().equals( "n21_PIG" ) ) {
6481                 return false;
6482             }
6483             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
6484                 return false;
6485             }
6486             final PhylogenyNode n21x = PhylogenyNode
6487                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6488             if ( !n21x.getName().equals( "n21_PIG" ) ) {
6489                 return false;
6490             }
6491             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
6492                 return false;
6493             }
6494             final PhylogenyNode n22 = PhylogenyNode
6495                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6496             if ( !n22.getName().equals( "n22/PIG" ) ) {
6497                 return false;
6498             }
6499             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
6500                 return false;
6501             }
6502             final PhylogenyNode n23 = PhylogenyNode
6503                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6504             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
6505                 return false;
6506             }
6507             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
6508                 return false;
6509             }
6510             final PhylogenyNode a = PhylogenyNode
6511                     .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6512             if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
6513                 return false;
6514             }
6515             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
6516                 return false;
6517             }
6518             final PhylogenyNode b = PhylogenyNode
6519                     .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6520             if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
6521                 return false;
6522             }
6523             if ( PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
6524                 return false;
6525             }
6526             final PhylogenyNode c = PhylogenyNode
6527                     .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
6528                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6529             if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
6530                 return false;
6531             }
6532             if ( PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
6533                 return false;
6534             }
6535             final PhylogenyNode c1 = PhylogenyNode
6536                     .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
6537                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6538             if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
6539                 return false;
6540             }
6541             if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
6542                 return false;
6543             }
6544             final PhylogenyNode c2 = PhylogenyNode
6545                     .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
6546                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6547             if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
6548                 return false;
6549             }
6550             if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
6551                 return false;
6552             }
6553             final PhylogenyNode d = PhylogenyNode
6554                     .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6555             if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
6556                 return false;
6557             }
6558             if ( PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
6559                 return false;
6560             }
6561             final PhylogenyNode e = PhylogenyNode
6562                     .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6563             if ( !e.getName().equals( "n10_RAT1" ) ) {
6564                 return false;
6565             }
6566             if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
6567                 return false;
6568             }
6569             final PhylogenyNode e2 = PhylogenyNode
6570                     .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6571             if ( !e2.getName().equals( "n10_RAT1" ) ) {
6572                 return false;
6573             }
6574             if ( PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
6575                 return false;
6576             }
6577             final PhylogenyNode e3 = PhylogenyNode
6578                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6579             if ( !e3.getName().equals( "n10_RAT~" ) ) {
6580                 return false;
6581             }
6582             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
6583                 return false;
6584             }
6585             final PhylogenyNode n11 = PhylogenyNode
6586                     .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
6587                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6588             if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
6589                 return false;
6590             }
6591             if ( n11.getDistanceToParent() != 0.4 ) {
6592                 return false;
6593             }
6594             if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
6595                 return false;
6596             }
6597             final PhylogenyNode n12 = PhylogenyNode
6598                     .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
6599                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6600             if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
6601                 return false;
6602             }
6603             if ( n12.getDistanceToParent() != 0.4 ) {
6604                 return false;
6605             }
6606             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
6607                 return false;
6608             }
6609             final PhylogenyNode m = PhylogenyNode
6610                     .createInstanceFromNhxString( "n10_MOUSEa", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6611             if ( !m.getName().equals( "n10_MOUSEa" ) ) {
6612                 return false;
6613             }
6614             if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
6615                 return false;
6616             }
6617             final PhylogenyNode o = PhylogenyNode
6618                     .createInstanceFromNhxString( "n10_MOUSE_", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6619             if ( !o.getName().equals( "n10_MOUSE_" ) ) {
6620                 return false;
6621             }
6622             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
6623                 return false;
6624             }
6625             if ( n1.getName().compareTo( "" ) != 0 ) {
6626                 return false;
6627             }
6628             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6629                 return false;
6630             }
6631             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6632                 return false;
6633             }
6634             if ( n2.getName().compareTo( "" ) != 0 ) {
6635                 return false;
6636             }
6637             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6638                 return false;
6639             }
6640             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6641                 return false;
6642             }
6643             final PhylogenyNode n00 = PhylogenyNode
6644                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
6645             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
6646                 return false;
6647             }
6648             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
6649                 return false;
6650             }
6651             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
6652             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
6653                 return false;
6654             }
6655             final PhylogenyNode n13 = PhylogenyNode
6656                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6657             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
6658                 return false;
6659             }
6660             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
6661                 return false;
6662             }
6663             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6664                 return false;
6665             }
6666             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6667                 return false;
6668             }
6669             final PhylogenyNode n14 = PhylogenyNode
6670                     .createInstanceFromNhxString( "blah_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6671             if ( !n14.getName().equals( "blah_9QX45/1-2" ) ) {
6672                 return false;
6673             }
6674             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
6675                 return false;
6676             }
6677             final PhylogenyNode n15 = PhylogenyNode
6678                     .createInstanceFromNhxString( "something_wicked[123]",
6679                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6680             if ( !n15.getName().equals( "something_wicked" ) ) {
6681                 return false;
6682             }
6683             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
6684                 return false;
6685             }
6686             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
6687                 return false;
6688             }
6689             final PhylogenyNode n16 = PhylogenyNode
6690                     .createInstanceFromNhxString( "something_wicked2[9]",
6691                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6692             if ( !n16.getName().equals( "something_wicked2" ) ) {
6693                 return false;
6694             }
6695             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
6696                 return false;
6697             }
6698             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
6699                 return false;
6700             }
6701             final PhylogenyNode n17 = PhylogenyNode
6702                     .createInstanceFromNhxString( "something_wicked3[a]",
6703                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6704             if ( !n17.getName().equals( "something_wicked3" ) ) {
6705                 return false;
6706             }
6707             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
6708                 return false;
6709             }
6710             final PhylogenyNode n18 = PhylogenyNode
6711                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6712             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
6713                 return false;
6714             }
6715             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
6716                 return false;
6717             }
6718             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
6719                 return false;
6720             }
6721             final PhylogenyNode n19 = PhylogenyNode
6722                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6723             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
6724                 return false;
6725             }
6726             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6727                 return false;
6728             }
6729             final PhylogenyNode n30 = PhylogenyNode
6730                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
6731                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6732             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
6733                 return false;
6734             }
6735             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6736                 return false;
6737             }
6738             final PhylogenyNode n31 = PhylogenyNode
6739                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
6740                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6741             if ( n31.getNodeData().isHasTaxonomy() ) {
6742                 return false;
6743             }
6744             final PhylogenyNode n32 = PhylogenyNode
6745                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6746             if ( n32.getNodeData().isHasTaxonomy() ) {
6747                 return false;
6748             }
6749             final PhylogenyNode n40 = PhylogenyNode
6750                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6751             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6752                 return false;
6753             }
6754             final PhylogenyNode n41 = PhylogenyNode
6755                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6756             if ( n41.getNodeData().isHasTaxonomy() ) {
6757                 return false;
6758             }
6759             final PhylogenyNode n42 = PhylogenyNode
6760                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6761             if ( n42.getNodeData().isHasTaxonomy() ) {
6762                 return false;
6763             }
6764             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
6765                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
6766             if ( n43.getNodeData().isHasTaxonomy() ) {
6767                 return false;
6768             }
6769             final PhylogenyNode n44 = PhylogenyNode
6770                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6771             if ( n44.getNodeData().isHasTaxonomy() ) {
6772                 return false;
6773             }
6774         }
6775         catch ( final Exception e ) {
6776             e.printStackTrace( System.out );
6777             return false;
6778         }
6779         return true;
6780     }
6781
6782     private static boolean testNHXParsing() {
6783         try {
6784             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6785             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
6786             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
6787                 return false;
6788             }
6789             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]";
6790             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
6791             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6792                 return false;
6793             }
6794             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]";
6795             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
6796             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
6797                 return false;
6798             }
6799             final Phylogeny[] p3 = factory
6800                     .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]",
6801                              new NHXParser() );
6802             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6803                 return false;
6804             }
6805             final Phylogeny[] p4 = factory
6806                     .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(]",
6807                              new NHXParser() );
6808             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6809                 return false;
6810             }
6811             final Phylogeny[] p5 = factory
6812                     .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(((]",
6813                              new NHXParser() );
6814             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6815                 return false;
6816             }
6817             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)";
6818             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)";
6819             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
6820             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
6821                 return false;
6822             }
6823             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)))";
6824             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)))";
6825             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
6826             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
6827                 return false;
6828             }
6829             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])   ))[,,, ])))))))";
6830             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
6831             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
6832             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
6833                 return false;
6834             }
6835             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
6836             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6837                 return false;
6838             }
6839             final Phylogeny p10 = factory
6840                     .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]",
6841                              new NHXParser() )[ 0 ];
6842             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6843                 return false;
6844             }
6845         }
6846         catch ( final Exception e ) {
6847             e.printStackTrace( System.out );
6848             return false;
6849         }
6850         return true;
6851     }
6852
6853     private static boolean testNHXParsingQuotes() {
6854         try {
6855             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6856             final NHXParser p = new NHXParser();
6857             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
6858             if ( phylogenies_0.length != 5 ) {
6859                 return false;
6860             }
6861             final Phylogeny phy = phylogenies_0[ 4 ];
6862             if ( phy.getNumberOfExternalNodes() != 7 ) {
6863                 return false;
6864             }
6865             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
6866                 return false;
6867             }
6868             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
6869                 return false;
6870             }
6871             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
6872                     .getScientificName().equals( "hsapiens" ) ) {
6873                 return false;
6874             }
6875             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
6876                 return false;
6877             }
6878             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
6879                 return false;
6880             }
6881             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
6882                 return false;
6883             }
6884             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
6885                 return false;
6886             }
6887             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
6888                 return false;
6889             }
6890             final NHXParser p1p = new NHXParser();
6891             p1p.setIgnoreQuotes( true );
6892             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
6893             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
6894                 return false;
6895             }
6896             final NHXParser p2p = new NHXParser();
6897             p1p.setIgnoreQuotes( false );
6898             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
6899             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
6900                 return false;
6901             }
6902             final NHXParser p3p = new NHXParser();
6903             p3p.setIgnoreQuotes( false );
6904             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
6905             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
6906                 return false;
6907             }
6908             final NHXParser p4p = new NHXParser();
6909             p4p.setIgnoreQuotes( false );
6910             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
6911             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
6912                 return false;
6913             }
6914             final Phylogeny p10 = factory
6915                     .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]",
6916                              new NHXParser() )[ 0 ];
6917             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]";
6918             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
6919                 return false;
6920             }
6921             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
6922             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
6923                 return false;
6924             }
6925             //
6926             final Phylogeny p12 = factory
6927                     .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]",
6928                              new NHXParser() )[ 0 ];
6929             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]";
6930             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
6931                 return false;
6932             }
6933             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
6934             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
6935                 return false;
6936             }
6937             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;";
6938             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
6939                 return false;
6940             }
6941             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
6942             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
6943                 return false;
6944             }
6945         }
6946         catch ( final Exception e ) {
6947             e.printStackTrace( System.out );
6948             return false;
6949         }
6950         return true;
6951     }
6952
6953     private static boolean testNHXParsingMB() {
6954         try {
6955             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6956             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
6957                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6958                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6959                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6960                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6961                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6962                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6963                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6964                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
6965             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
6966                 return false;
6967             }
6968             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
6969                 return false;
6970             }
6971             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
6972                            0.1100000000000000e+00 ) ) {
6973                 return false;
6974             }
6975             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
6976                 return false;
6977             }
6978             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
6979                 return false;
6980             }
6981             final Phylogeny p2 = factory
6982                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
6983                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6984                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6985                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6986                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6987                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6988                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6989                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6990                                      + "7.369400000000000e-02}])",
6991                              new NHXParser() )[ 0 ];
6992             if ( p2.getNode( "1" ) == null ) {
6993                 return false;
6994             }
6995             if ( p2.getNode( "2" ) == null ) {
6996                 return false;
6997             }
6998         }
6999         catch ( final Exception e ) {
7000             e.printStackTrace( System.out );
7001             System.exit( -1 );
7002             return false;
7003         }
7004         return true;
7005     }
7006
7007     private static boolean testPhylogenyBranch() {
7008         try {
7009             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
7010             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
7011             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
7012             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
7013             if ( !a1b1.equals( a1b1 ) ) {
7014                 return false;
7015             }
7016             if ( !a1b1.equals( b1a1 ) ) {
7017                 return false;
7018             }
7019             if ( !b1a1.equals( a1b1 ) ) {
7020                 return false;
7021             }
7022             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
7023             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
7024             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
7025             if ( a1_b1.equals( b1_a1 ) ) {
7026                 return false;
7027             }
7028             if ( a1_b1.equals( a1_b1_ ) ) {
7029                 return false;
7030             }
7031             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
7032             if ( !a1_b1.equals( b1_a1_ ) ) {
7033                 return false;
7034             }
7035             if ( a1_b1_.equals( b1_a1_ ) ) {
7036                 return false;
7037             }
7038             if ( !a1_b1_.equals( b1_a1 ) ) {
7039                 return false;
7040             }
7041         }
7042         catch ( final Exception e ) {
7043             e.printStackTrace( System.out );
7044             return false;
7045         }
7046         return true;
7047     }
7048
7049     private static boolean testPhyloXMLparsingOfDistributionElement() {
7050         try {
7051             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7052             PhyloXmlParser xml_parser = null;
7053             try {
7054                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
7055             }
7056             catch ( final Exception e ) {
7057                 // Do nothing -- means were not running from jar.
7058             }
7059             if ( xml_parser == null ) {
7060                 xml_parser = new PhyloXmlParser();
7061                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
7062                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
7063                 }
7064                 else {
7065                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
7066                 }
7067             }
7068             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
7069                                                               xml_parser );
7070             if ( xml_parser.getErrorCount() > 0 ) {
7071                 System.out.println( xml_parser.getErrorMessages().toString() );
7072                 return false;
7073             }
7074             if ( phylogenies_0.length != 1 ) {
7075                 return false;
7076             }
7077             final Phylogeny t1 = phylogenies_0[ 0 ];
7078             PhylogenyNode n = null;
7079             Distribution d = null;
7080             n = t1.getNode( "root node" );
7081             if ( !n.getNodeData().isHasDistribution() ) {
7082                 return false;
7083             }
7084             if ( n.getNodeData().getDistributions().size() != 1 ) {
7085                 return false;
7086             }
7087             d = n.getNodeData().getDistribution();
7088             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7089                 return false;
7090             }
7091             if ( d.getPoints().size() != 1 ) {
7092                 return false;
7093             }
7094             if ( d.getPolygons() != null ) {
7095                 return false;
7096             }
7097             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7098                 return false;
7099             }
7100             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7101                 return false;
7102             }
7103             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7104                 return false;
7105             }
7106             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7107                 return false;
7108             }
7109             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7110                 return false;
7111             }
7112             n = t1.getNode( "node a" );
7113             if ( !n.getNodeData().isHasDistribution() ) {
7114                 return false;
7115             }
7116             if ( n.getNodeData().getDistributions().size() != 2 ) {
7117                 return false;
7118             }
7119             d = n.getNodeData().getDistribution( 1 );
7120             if ( !d.getDesc().equals( "San Diego" ) ) {
7121                 return false;
7122             }
7123             if ( d.getPoints().size() != 1 ) {
7124                 return false;
7125             }
7126             if ( d.getPolygons() != null ) {
7127                 return false;
7128             }
7129             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7130                 return false;
7131             }
7132             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7133                 return false;
7134             }
7135             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7136                 return false;
7137             }
7138             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7139                 return false;
7140             }
7141             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7142                 return false;
7143             }
7144             n = t1.getNode( "node bb" );
7145             if ( !n.getNodeData().isHasDistribution() ) {
7146                 return false;
7147             }
7148             if ( n.getNodeData().getDistributions().size() != 1 ) {
7149                 return false;
7150             }
7151             d = n.getNodeData().getDistribution( 0 );
7152             if ( d.getPoints().size() != 3 ) {
7153                 return false;
7154             }
7155             if ( d.getPolygons().size() != 2 ) {
7156                 return false;
7157             }
7158             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7159                 return false;
7160             }
7161             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7162                 return false;
7163             }
7164             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7165                 return false;
7166             }
7167             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7168                 return false;
7169             }
7170             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7171                 return false;
7172             }
7173             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7174                 return false;
7175             }
7176             Polygon p = d.getPolygons().get( 0 );
7177             if ( p.getPoints().size() != 3 ) {
7178                 return false;
7179             }
7180             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7181                 return false;
7182             }
7183             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7184                 return false;
7185             }
7186             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7187                 return false;
7188             }
7189             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7190                 return false;
7191             }
7192             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7193                 return false;
7194             }
7195             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7196                 return false;
7197             }
7198             p = d.getPolygons().get( 1 );
7199             if ( p.getPoints().size() != 3 ) {
7200                 return false;
7201             }
7202             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7203                 return false;
7204             }
7205             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7206                 return false;
7207             }
7208             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7209                 return false;
7210             }
7211             // Roundtrip:
7212             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
7213             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
7214             if ( rt.length != 1 ) {
7215                 return false;
7216             }
7217             final Phylogeny t1_rt = rt[ 0 ];
7218             n = t1_rt.getNode( "root node" );
7219             if ( !n.getNodeData().isHasDistribution() ) {
7220                 return false;
7221             }
7222             if ( n.getNodeData().getDistributions().size() != 1 ) {
7223                 return false;
7224             }
7225             d = n.getNodeData().getDistribution();
7226             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7227                 return false;
7228             }
7229             if ( d.getPoints().size() != 1 ) {
7230                 return false;
7231             }
7232             if ( d.getPolygons() != null ) {
7233                 return false;
7234             }
7235             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7236                 return false;
7237             }
7238             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7239                 return false;
7240             }
7241             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7242                 return false;
7243             }
7244             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7245                 return false;
7246             }
7247             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7248                 return false;
7249             }
7250             n = t1_rt.getNode( "node a" );
7251             if ( !n.getNodeData().isHasDistribution() ) {
7252                 return false;
7253             }
7254             if ( n.getNodeData().getDistributions().size() != 2 ) {
7255                 return false;
7256             }
7257             d = n.getNodeData().getDistribution( 1 );
7258             if ( !d.getDesc().equals( "San Diego" ) ) {
7259                 return false;
7260             }
7261             if ( d.getPoints().size() != 1 ) {
7262                 return false;
7263             }
7264             if ( d.getPolygons() != null ) {
7265                 return false;
7266             }
7267             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7268                 return false;
7269             }
7270             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7271                 return false;
7272             }
7273             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7274                 return false;
7275             }
7276             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7277                 return false;
7278             }
7279             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7280                 return false;
7281             }
7282             n = t1_rt.getNode( "node bb" );
7283             if ( !n.getNodeData().isHasDistribution() ) {
7284                 return false;
7285             }
7286             if ( n.getNodeData().getDistributions().size() != 1 ) {
7287                 return false;
7288             }
7289             d = n.getNodeData().getDistribution( 0 );
7290             if ( d.getPoints().size() != 3 ) {
7291                 return false;
7292             }
7293             if ( d.getPolygons().size() != 2 ) {
7294                 return false;
7295             }
7296             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7297                 return false;
7298             }
7299             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7300                 return false;
7301             }
7302             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7303                 return false;
7304             }
7305             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7306                 return false;
7307             }
7308             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7309                 return false;
7310             }
7311             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7312                 return false;
7313             }
7314             p = d.getPolygons().get( 0 );
7315             if ( p.getPoints().size() != 3 ) {
7316                 return false;
7317             }
7318             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7319                 return false;
7320             }
7321             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7322                 return false;
7323             }
7324             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7325                 return false;
7326             }
7327             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7328                 return false;
7329             }
7330             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7331                 return false;
7332             }
7333             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7334                 return false;
7335             }
7336             p = d.getPolygons().get( 1 );
7337             if ( p.getPoints().size() != 3 ) {
7338                 return false;
7339             }
7340             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7341                 return false;
7342             }
7343             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7344                 return false;
7345             }
7346             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7347                 return false;
7348             }
7349         }
7350         catch ( final Exception e ) {
7351             e.printStackTrace( System.out );
7352             return false;
7353         }
7354         return true;
7355     }
7356
7357     private static boolean testPostOrderIterator() {
7358         try {
7359             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7360             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7361             PhylogenyNodeIterator it0;
7362             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
7363                 it0.next();
7364             }
7365             for( it0.reset(); it0.hasNext(); ) {
7366                 it0.next();
7367             }
7368             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7369             final PhylogenyNodeIterator it = t1.iteratorPostorder();
7370             if ( !it.next().getName().equals( "A" ) ) {
7371                 return false;
7372             }
7373             if ( !it.next().getName().equals( "B" ) ) {
7374                 return false;
7375             }
7376             if ( !it.next().getName().equals( "ab" ) ) {
7377                 return false;
7378             }
7379             if ( !it.next().getName().equals( "C" ) ) {
7380                 return false;
7381             }
7382             if ( !it.next().getName().equals( "D" ) ) {
7383                 return false;
7384             }
7385             if ( !it.next().getName().equals( "cd" ) ) {
7386                 return false;
7387             }
7388             if ( !it.next().getName().equals( "abcd" ) ) {
7389                 return false;
7390             }
7391             if ( !it.next().getName().equals( "E" ) ) {
7392                 return false;
7393             }
7394             if ( !it.next().getName().equals( "F" ) ) {
7395                 return false;
7396             }
7397             if ( !it.next().getName().equals( "ef" ) ) {
7398                 return false;
7399             }
7400             if ( !it.next().getName().equals( "G" ) ) {
7401                 return false;
7402             }
7403             if ( !it.next().getName().equals( "H" ) ) {
7404                 return false;
7405             }
7406             if ( !it.next().getName().equals( "gh" ) ) {
7407                 return false;
7408             }
7409             if ( !it.next().getName().equals( "efgh" ) ) {
7410                 return false;
7411             }
7412             if ( !it.next().getName().equals( "r" ) ) {
7413                 return false;
7414             }
7415             if ( it.hasNext() ) {
7416                 return false;
7417             }
7418         }
7419         catch ( final Exception e ) {
7420             e.printStackTrace( System.out );
7421             return false;
7422         }
7423         return true;
7424     }
7425
7426     private static boolean testPreOrderIterator() {
7427         try {
7428             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7429             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7430             PhylogenyNodeIterator it0;
7431             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
7432                 it0.next();
7433             }
7434             for( it0.reset(); it0.hasNext(); ) {
7435                 it0.next();
7436             }
7437             PhylogenyNodeIterator it = t0.iteratorPreorder();
7438             if ( !it.next().getName().equals( "r" ) ) {
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.hasNext() ) {
7460                 return false;
7461             }
7462             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7463             it = t1.iteratorPreorder();
7464             if ( !it.next().getName().equals( "r" ) ) {
7465                 return false;
7466             }
7467             if ( !it.next().getName().equals( "abcd" ) ) {
7468                 return false;
7469             }
7470             if ( !it.next().getName().equals( "ab" ) ) {
7471                 return false;
7472             }
7473             if ( !it.next().getName().equals( "A" ) ) {
7474                 return false;
7475             }
7476             if ( !it.next().getName().equals( "B" ) ) {
7477                 return false;
7478             }
7479             if ( !it.next().getName().equals( "cd" ) ) {
7480                 return false;
7481             }
7482             if ( !it.next().getName().equals( "C" ) ) {
7483                 return false;
7484             }
7485             if ( !it.next().getName().equals( "D" ) ) {
7486                 return false;
7487             }
7488             if ( !it.next().getName().equals( "efgh" ) ) {
7489                 return false;
7490             }
7491             if ( !it.next().getName().equals( "ef" ) ) {
7492                 return false;
7493             }
7494             if ( !it.next().getName().equals( "E" ) ) {
7495                 return false;
7496             }
7497             if ( !it.next().getName().equals( "F" ) ) {
7498                 return false;
7499             }
7500             if ( !it.next().getName().equals( "gh" ) ) {
7501                 return false;
7502             }
7503             if ( !it.next().getName().equals( "G" ) ) {
7504                 return false;
7505             }
7506             if ( !it.next().getName().equals( "H" ) ) {
7507                 return false;
7508             }
7509             if ( it.hasNext() ) {
7510                 return false;
7511             }
7512         }
7513         catch ( final Exception e ) {
7514             e.printStackTrace( System.out );
7515             return false;
7516         }
7517         return true;
7518     }
7519
7520     private static boolean testPropertiesMap() {
7521         try {
7522             final PropertiesMap pm = new PropertiesMap();
7523             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7524             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7525             final Property p2 = new Property( "something:else",
7526                                               "?",
7527                                               "improbable:research",
7528                                               "xsd:decimal",
7529                                               AppliesTo.NODE );
7530             pm.addProperty( p0 );
7531             pm.addProperty( p1 );
7532             pm.addProperty( p2 );
7533             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
7534                 return false;
7535             }
7536             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
7537                 return false;
7538             }
7539             if ( pm.getProperties().size() != 3 ) {
7540                 return false;
7541             }
7542             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
7543                 return false;
7544             }
7545             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7546                 return false;
7547             }
7548             if ( pm.getProperties().size() != 3 ) {
7549                 return false;
7550             }
7551             pm.removeProperty( "dimensions:diameter" );
7552             if ( pm.getProperties().size() != 2 ) {
7553                 return false;
7554             }
7555             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
7556                 return false;
7557             }
7558             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7559                 return false;
7560             }
7561         }
7562         catch ( final Exception e ) {
7563             e.printStackTrace( System.out );
7564             return false;
7565         }
7566         return true;
7567     }
7568
7569     private static boolean testReIdMethods() {
7570         try {
7571             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7572             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
7573             final long count = PhylogenyNode.getNodeCount();
7574             p.levelOrderReID();
7575             if ( p.getNode( "r" ).getId() != count ) {
7576                 return false;
7577             }
7578             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
7579                 return false;
7580             }
7581             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
7582                 return false;
7583             }
7584             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
7585                 return false;
7586             }
7587             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
7588                 return false;
7589             }
7590             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
7591                 return false;
7592             }
7593             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
7594                 return false;
7595             }
7596             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
7597                 return false;
7598             }
7599             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
7600                 return false;
7601             }
7602             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
7603                 return false;
7604             }
7605             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
7606                 return false;
7607             }
7608             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
7609                 return false;
7610             }
7611             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
7612                 return false;
7613             }
7614             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
7615                 return false;
7616             }
7617             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
7618                 return false;
7619             }
7620         }
7621         catch ( final Exception e ) {
7622             e.printStackTrace( System.out );
7623             return false;
7624         }
7625         return true;
7626     }
7627
7628     private static boolean testRerooting() {
7629         try {
7630             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7631             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",
7632                                                  new NHXParser() )[ 0 ];
7633             if ( !t1.isRooted() ) {
7634                 return false;
7635             }
7636             t1.reRoot( t1.getNode( "D" ) );
7637             t1.reRoot( t1.getNode( "CD" ) );
7638             t1.reRoot( t1.getNode( "A" ) );
7639             t1.reRoot( t1.getNode( "B" ) );
7640             t1.reRoot( t1.getNode( "AB" ) );
7641             t1.reRoot( t1.getNode( "D" ) );
7642             t1.reRoot( t1.getNode( "C" ) );
7643             t1.reRoot( t1.getNode( "CD" ) );
7644             t1.reRoot( t1.getNode( "A" ) );
7645             t1.reRoot( t1.getNode( "B" ) );
7646             t1.reRoot( t1.getNode( "AB" ) );
7647             t1.reRoot( t1.getNode( "D" ) );
7648             t1.reRoot( t1.getNode( "D" ) );
7649             t1.reRoot( t1.getNode( "C" ) );
7650             t1.reRoot( t1.getNode( "A" ) );
7651             t1.reRoot( t1.getNode( "B" ) );
7652             t1.reRoot( t1.getNode( "AB" ) );
7653             t1.reRoot( t1.getNode( "C" ) );
7654             t1.reRoot( t1.getNode( "D" ) );
7655             t1.reRoot( t1.getNode( "CD" ) );
7656             t1.reRoot( t1.getNode( "D" ) );
7657             t1.reRoot( t1.getNode( "A" ) );
7658             t1.reRoot( t1.getNode( "B" ) );
7659             t1.reRoot( t1.getNode( "AB" ) );
7660             t1.reRoot( t1.getNode( "C" ) );
7661             t1.reRoot( t1.getNode( "D" ) );
7662             t1.reRoot( t1.getNode( "CD" ) );
7663             t1.reRoot( t1.getNode( "D" ) );
7664             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
7665                 return false;
7666             }
7667             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
7668                 return false;
7669             }
7670             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
7671                 return false;
7672             }
7673             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
7674                 return false;
7675             }
7676             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
7677                 return false;
7678             }
7679             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
7680                 return false;
7681             }
7682             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",
7683                                                  new NHXParser() )[ 0 ];
7684             t2.reRoot( t2.getNode( "A" ) );
7685             t2.reRoot( t2.getNode( "D" ) );
7686             t2.reRoot( t2.getNode( "ABC" ) );
7687             t2.reRoot( t2.getNode( "A" ) );
7688             t2.reRoot( t2.getNode( "B" ) );
7689             t2.reRoot( t2.getNode( "D" ) );
7690             t2.reRoot( t2.getNode( "C" ) );
7691             t2.reRoot( t2.getNode( "ABC" ) );
7692             t2.reRoot( t2.getNode( "A" ) );
7693             t2.reRoot( t2.getNode( "B" ) );
7694             t2.reRoot( t2.getNode( "AB" ) );
7695             t2.reRoot( t2.getNode( "AB" ) );
7696             t2.reRoot( t2.getNode( "D" ) );
7697             t2.reRoot( t2.getNode( "C" ) );
7698             t2.reRoot( t2.getNode( "B" ) );
7699             t2.reRoot( t2.getNode( "AB" ) );
7700             t2.reRoot( t2.getNode( "D" ) );
7701             t2.reRoot( t2.getNode( "D" ) );
7702             t2.reRoot( t2.getNode( "ABC" ) );
7703             t2.reRoot( t2.getNode( "A" ) );
7704             t2.reRoot( t2.getNode( "B" ) );
7705             t2.reRoot( t2.getNode( "AB" ) );
7706             t2.reRoot( t2.getNode( "D" ) );
7707             t2.reRoot( t2.getNode( "C" ) );
7708             t2.reRoot( t2.getNode( "ABC" ) );
7709             t2.reRoot( t2.getNode( "A" ) );
7710             t2.reRoot( t2.getNode( "B" ) );
7711             t2.reRoot( t2.getNode( "AB" ) );
7712             t2.reRoot( t2.getNode( "D" ) );
7713             t2.reRoot( t2.getNode( "D" ) );
7714             t2.reRoot( t2.getNode( "C" ) );
7715             t2.reRoot( t2.getNode( "A" ) );
7716             t2.reRoot( t2.getNode( "B" ) );
7717             t2.reRoot( t2.getNode( "AB" ) );
7718             t2.reRoot( t2.getNode( "C" ) );
7719             t2.reRoot( t2.getNode( "D" ) );
7720             t2.reRoot( t2.getNode( "ABC" ) );
7721             t2.reRoot( t2.getNode( "D" ) );
7722             t2.reRoot( t2.getNode( "A" ) );
7723             t2.reRoot( t2.getNode( "B" ) );
7724             t2.reRoot( t2.getNode( "AB" ) );
7725             t2.reRoot( t2.getNode( "C" ) );
7726             t2.reRoot( t2.getNode( "D" ) );
7727             t2.reRoot( t2.getNode( "ABC" ) );
7728             t2.reRoot( t2.getNode( "D" ) );
7729             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7730                 return false;
7731             }
7732             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7733                 return false;
7734             }
7735             t2.reRoot( t2.getNode( "ABC" ) );
7736             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7737                 return false;
7738             }
7739             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7740                 return false;
7741             }
7742             t2.reRoot( t2.getNode( "AB" ) );
7743             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7744                 return false;
7745             }
7746             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7747                 return false;
7748             }
7749             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7750                 return false;
7751             }
7752             t2.reRoot( t2.getNode( "AB" ) );
7753             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7754                 return false;
7755             }
7756             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7757                 return false;
7758             }
7759             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7760                 return false;
7761             }
7762             t2.reRoot( t2.getNode( "D" ) );
7763             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7764                 return false;
7765             }
7766             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7767                 return false;
7768             }
7769             t2.reRoot( t2.getNode( "ABC" ) );
7770             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7771                 return false;
7772             }
7773             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7774                 return false;
7775             }
7776             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
7777                                                  new NHXParser() )[ 0 ];
7778             t3.reRoot( t3.getNode( "B" ) );
7779             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7780                 return false;
7781             }
7782             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7783                 return false;
7784             }
7785             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7786                 return false;
7787             }
7788             t3.reRoot( t3.getNode( "B" ) );
7789             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7790                 return false;
7791             }
7792             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7793                 return false;
7794             }
7795             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7796                 return false;
7797             }
7798             t3.reRoot( t3.getRoot() );
7799             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7800                 return false;
7801             }
7802             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7803                 return false;
7804             }
7805             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7806                 return false;
7807             }
7808         }
7809         catch ( final Exception e ) {
7810             e.printStackTrace( System.out );
7811             return false;
7812         }
7813         return true;
7814     }
7815
7816     private static boolean testSDIse() {
7817         try {
7818             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7819             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
7820             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
7821             gene1.setRooted( true );
7822             species1.setRooted( true );
7823             final SDI sdi = new SDI( gene1, species1 );
7824             if ( !gene1.getRoot().isDuplication() ) {
7825                 return false;
7826             }
7827             final Phylogeny species2 = factory
7828                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7829                              new NHXParser() )[ 0 ];
7830             final Phylogeny gene2 = factory
7831                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7832                              new NHXParser() )[ 0 ];
7833             species2.setRooted( true );
7834             gene2.setRooted( true );
7835             final SDI sdi2 = new SDI( gene2, species2 );
7836             if ( sdi2.getDuplicationsSum() != 0 ) {
7837                 return false;
7838             }
7839             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
7840                 return false;
7841             }
7842             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
7843                 return false;
7844             }
7845             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
7846                 return false;
7847             }
7848             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
7849                 return false;
7850             }
7851             if ( !gene2.getNode( "r" ).isSpeciation() ) {
7852                 return false;
7853             }
7854             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
7855                 return false;
7856             }
7857             final Phylogeny species3 = factory
7858                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7859                              new NHXParser() )[ 0 ];
7860             final Phylogeny gene3 = factory
7861                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7862                              new NHXParser() )[ 0 ];
7863             species3.setRooted( true );
7864             gene3.setRooted( true );
7865             final SDI sdi3 = new SDI( gene3, species3 );
7866             if ( sdi3.getDuplicationsSum() != 1 ) {
7867                 return false;
7868             }
7869             if ( !gene3.getNode( "aa" ).isDuplication() ) {
7870                 return false;
7871             }
7872             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
7873                 return false;
7874             }
7875             final Phylogeny species4 = factory
7876                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7877                              new NHXParser() )[ 0 ];
7878             final Phylogeny gene4 = factory
7879                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7880                              new NHXParser() )[ 0 ];
7881             species4.setRooted( true );
7882             gene4.setRooted( true );
7883             final SDI sdi4 = new SDI( gene4, species4 );
7884             if ( sdi4.getDuplicationsSum() != 1 ) {
7885                 return false;
7886             }
7887             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
7888                 return false;
7889             }
7890             if ( !gene4.getNode( "abc" ).isDuplication() ) {
7891                 return false;
7892             }
7893             if ( gene4.getNode( "abcd" ).isDuplication() ) {
7894                 return false;
7895             }
7896             if ( species4.getNumberOfExternalNodes() != 6 ) {
7897                 return false;
7898             }
7899             if ( gene4.getNumberOfExternalNodes() != 6 ) {
7900                 return false;
7901             }
7902             final Phylogeny species5 = factory
7903                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7904                              new NHXParser() )[ 0 ];
7905             final Phylogeny gene5 = factory
7906                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7907                              new NHXParser() )[ 0 ];
7908             species5.setRooted( true );
7909             gene5.setRooted( true );
7910             final SDI sdi5 = new SDI( gene5, species5 );
7911             if ( sdi5.getDuplicationsSum() != 2 ) {
7912                 return false;
7913             }
7914             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
7915                 return false;
7916             }
7917             if ( !gene5.getNode( "adc" ).isDuplication() ) {
7918                 return false;
7919             }
7920             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
7921                 return false;
7922             }
7923             if ( species5.getNumberOfExternalNodes() != 6 ) {
7924                 return false;
7925             }
7926             if ( gene5.getNumberOfExternalNodes() != 6 ) {
7927                 return false;
7928             }
7929             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
7930             // Conjecture for Comparing Molecular Phylogenies"
7931             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
7932             final Phylogeny species6 = factory
7933                     .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,"
7934                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
7935                              new NHXParser() )[ 0 ];
7936             final Phylogeny gene6 = factory
7937                     .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,"
7938                                      + "((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,"
7939                                      + "(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;",
7940                              new NHXParser() )[ 0 ];
7941             species6.setRooted( true );
7942             gene6.setRooted( true );
7943             final SDI sdi6 = new SDI( gene6, species6 );
7944             if ( sdi6.getDuplicationsSum() != 3 ) {
7945                 return false;
7946             }
7947             if ( !gene6.getNode( "r" ).isDuplication() ) {
7948                 return false;
7949             }
7950             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
7951                 return false;
7952             }
7953             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
7954                 return false;
7955             }
7956             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
7957                 return false;
7958             }
7959             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
7960                 return false;
7961             }
7962             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
7963                 return false;
7964             }
7965             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
7966                 return false;
7967             }
7968             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
7969                 return false;
7970             }
7971             sdi6.computeMappingCostL();
7972             if ( sdi6.computeMappingCostL() != 17 ) {
7973                 return false;
7974             }
7975             if ( species6.getNumberOfExternalNodes() != 9 ) {
7976                 return false;
7977             }
7978             if ( gene6.getNumberOfExternalNodes() != 9 ) {
7979                 return false;
7980             }
7981             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
7982                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
7983                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
7984                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
7985                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
7986             species7.setRooted( true );
7987             final Phylogeny gene7_1 = Test
7988                     .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])" );
7989             gene7_1.setRooted( true );
7990             final SDI sdi7 = new SDI( gene7_1, species7 );
7991             if ( sdi7.getDuplicationsSum() != 0 ) {
7992                 return false;
7993             }
7994             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
7995                 return false;
7996             }
7997             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
7998                 return false;
7999             }
8000             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
8001                 return false;
8002             }
8003             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
8004                 return false;
8005             }
8006             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
8007                 return false;
8008             }
8009             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
8010                 return false;
8011             }
8012             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
8013                 return false;
8014             }
8015             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
8016                 return false;
8017             }
8018             final Phylogeny gene7_2 = Test
8019                     .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])" );
8020             gene7_2.setRooted( true );
8021             final SDI sdi7_2 = new SDI( gene7_2, species7 );
8022             if ( sdi7_2.getDuplicationsSum() != 1 ) {
8023                 return false;
8024             }
8025             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
8026                 return false;
8027             }
8028             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
8029                 return false;
8030             }
8031             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
8032                 return false;
8033             }
8034             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
8035                 return false;
8036             }
8037             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
8038                 return false;
8039             }
8040             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
8041                 return false;
8042             }
8043             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
8044                 return false;
8045             }
8046             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
8047                 return false;
8048             }
8049             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
8050                 return false;
8051             }
8052         }
8053         catch ( final Exception e ) {
8054             return false;
8055         }
8056         return true;
8057     }
8058
8059     private static boolean testSDIunrooted() {
8060         try {
8061             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8062             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
8063             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
8064             final Iterator<PhylogenyBranch> iter = l.iterator();
8065             PhylogenyBranch br = iter.next();
8066             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
8067                 return false;
8068             }
8069             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
8070                 return false;
8071             }
8072             br = iter.next();
8073             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8074                 return false;
8075             }
8076             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8077                 return false;
8078             }
8079             br = iter.next();
8080             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
8081                 return false;
8082             }
8083             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
8084                 return false;
8085             }
8086             br = iter.next();
8087             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8088                 return false;
8089             }
8090             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8091                 return false;
8092             }
8093             br = iter.next();
8094             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8095                 return false;
8096             }
8097             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8098                 return false;
8099             }
8100             br = iter.next();
8101             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8102                 return false;
8103             }
8104             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8105                 return false;
8106             }
8107             br = iter.next();
8108             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8109                 return false;
8110             }
8111             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8112                 return false;
8113             }
8114             br = iter.next();
8115             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8116                 return false;
8117             }
8118             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8119                 return false;
8120             }
8121             br = iter.next();
8122             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8123                 return false;
8124             }
8125             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8126                 return false;
8127             }
8128             br = iter.next();
8129             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8130                 return false;
8131             }
8132             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8133                 return false;
8134             }
8135             br = iter.next();
8136             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8137                 return false;
8138             }
8139             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8140                 return false;
8141             }
8142             br = iter.next();
8143             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
8144                 return false;
8145             }
8146             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
8147                 return false;
8148             }
8149             br = iter.next();
8150             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8151                 return false;
8152             }
8153             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8154                 return false;
8155             }
8156             br = iter.next();
8157             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
8158                 return false;
8159             }
8160             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
8161                 return false;
8162             }
8163             br = iter.next();
8164             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
8165                 return false;
8166             }
8167             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
8168                 return false;
8169             }
8170             if ( iter.hasNext() ) {
8171                 return false;
8172             }
8173             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
8174             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
8175             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
8176             br = iter1.next();
8177             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8178                 return false;
8179             }
8180             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8181                 return false;
8182             }
8183             br = iter1.next();
8184             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8185                 return false;
8186             }
8187             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8188                 return false;
8189             }
8190             br = iter1.next();
8191             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8192                 return false;
8193             }
8194             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8195                 return false;
8196             }
8197             if ( iter1.hasNext() ) {
8198                 return false;
8199             }
8200             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
8201             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
8202             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
8203             br = iter2.next();
8204             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8205                 return false;
8206             }
8207             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8208                 return false;
8209             }
8210             br = iter2.next();
8211             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8212                 return false;
8213             }
8214             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8215                 return false;
8216             }
8217             br = iter2.next();
8218             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8219                 return false;
8220             }
8221             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8222                 return false;
8223             }
8224             if ( iter2.hasNext() ) {
8225                 return false;
8226             }
8227             final Phylogeny species0 = factory
8228                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
8229                              new NHXParser() )[ 0 ];
8230             final Phylogeny gene1 = factory
8231                     .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])",
8232                              new NHXParser() )[ 0 ];
8233             species0.setRooted( true );
8234             gene1.setRooted( true );
8235             final SDIR sdi_unrooted = new SDIR();
8236             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
8237             if ( sdi_unrooted.getCount() != 1 ) {
8238                 return false;
8239             }
8240             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
8241                 return false;
8242             }
8243             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
8244                 return false;
8245             }
8246             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
8247                 return false;
8248             }
8249             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8250                 return false;
8251             }
8252             final Phylogeny gene2 = factory
8253                     .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])",
8254                              new NHXParser() )[ 0 ];
8255             gene2.setRooted( true );
8256             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
8257             if ( sdi_unrooted.getCount() != 1 ) {
8258                 return false;
8259             }
8260             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8261                 return false;
8262             }
8263             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8264                 return false;
8265             }
8266             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
8267                 return false;
8268             }
8269             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8270                 return false;
8271             }
8272             final Phylogeny species6 = factory
8273                     .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,"
8274                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8275                              new NHXParser() )[ 0 ];
8276             final Phylogeny gene6 = factory
8277                     .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],"
8278                                      + "(((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],"
8279                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8280                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8281                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8282                              new NHXParser() )[ 0 ];
8283             species6.setRooted( true );
8284             gene6.setRooted( true );
8285             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
8286             if ( sdi_unrooted.getCount() != 1 ) {
8287                 return false;
8288             }
8289             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8290                 return false;
8291             }
8292             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8293                 return false;
8294             }
8295             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8296                 return false;
8297             }
8298             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8299                 return false;
8300             }
8301             if ( !p6[ 0 ].getRoot().isDuplication() ) {
8302                 return false;
8303             }
8304             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8305                 return false;
8306             }
8307             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8308                 return false;
8309             }
8310             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
8311                 return false;
8312             }
8313             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8314                 return false;
8315             }
8316             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
8317                 return false;
8318             }
8319             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
8320                 return false;
8321             }
8322             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8323                 return false;
8324             }
8325             p6 = null;
8326             final Phylogeny species7 = factory
8327                     .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,"
8328                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8329                              new NHXParser() )[ 0 ];
8330             final Phylogeny gene7 = factory
8331                     .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],"
8332                                      + "(((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],"
8333                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8334                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8335                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8336                              new NHXParser() )[ 0 ];
8337             species7.setRooted( true );
8338             gene7.setRooted( true );
8339             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
8340             if ( sdi_unrooted.getCount() != 1 ) {
8341                 return false;
8342             }
8343             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8344                 return false;
8345             }
8346             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8347                 return false;
8348             }
8349             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8350                 return false;
8351             }
8352             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
8353                 return false;
8354             }
8355             if ( !p7[ 0 ].getRoot().isDuplication() ) {
8356                 return false;
8357             }
8358             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8359                 return false;
8360             }
8361             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8362                 return false;
8363             }
8364             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
8365                 return false;
8366             }
8367             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8368                 return false;
8369             }
8370             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
8371                 return false;
8372             }
8373             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
8374                 return false;
8375             }
8376             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8377                 return false;
8378             }
8379             p7 = null;
8380             final Phylogeny species8 = factory
8381                     .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,"
8382                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8383                              new NHXParser() )[ 0 ];
8384             final Phylogeny gene8 = factory
8385                     .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],"
8386                                      + "(((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],"
8387                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8388                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8389                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8390                              new NHXParser() )[ 0 ];
8391             species8.setRooted( true );
8392             gene8.setRooted( true );
8393             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
8394             if ( sdi_unrooted.getCount() != 1 ) {
8395                 return false;
8396             }
8397             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8398                 return false;
8399             }
8400             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8401                 return false;
8402             }
8403             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8404                 return false;
8405             }
8406             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8407                 return false;
8408             }
8409             if ( !p8[ 0 ].getRoot().isDuplication() ) {
8410                 return false;
8411             }
8412             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8413                 return false;
8414             }
8415             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8416                 return false;
8417             }
8418             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
8419                 return false;
8420             }
8421             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8422                 return false;
8423             }
8424             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
8425                 return false;
8426             }
8427             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
8428                 return false;
8429             }
8430             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8431                 return false;
8432             }
8433             p8 = null;
8434         }
8435         catch ( final Exception e ) {
8436             e.printStackTrace( System.out );
8437             return false;
8438         }
8439         return true;
8440     }
8441
8442     private static boolean testSplit() {
8443         try {
8444             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8445             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8446             //Archaeopteryx.createApplication( p0 );
8447             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8448             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8449             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8450             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8451             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8452             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8453             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8454             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8455             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8456             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8457             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
8458             // System.out.println( s0.toString() );
8459             //
8460             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8461             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8463             if ( s0.match( query_nodes ) ) {
8464                 return false;
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             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8474             if ( !s0.match( query_nodes ) ) {
8475                 return false;
8476             }
8477             //
8478             query_nodes = new HashSet<PhylogenyNode>();
8479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8482             if ( !s0.match( query_nodes ) ) {
8483                 return false;
8484             }
8485             //
8486             query_nodes = new HashSet<PhylogenyNode>();
8487             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8490             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8491             if ( !s0.match( query_nodes ) ) {
8492                 return false;
8493             }
8494             //
8495             query_nodes = new HashSet<PhylogenyNode>();
8496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8498             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8499             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8500             if ( !s0.match( query_nodes ) ) {
8501                 return false;
8502             }
8503             //
8504             query_nodes = new HashSet<PhylogenyNode>();
8505             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8506             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8507             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8508             if ( !s0.match( query_nodes ) ) {
8509                 return false;
8510             }
8511             //
8512             query_nodes = new HashSet<PhylogenyNode>();
8513             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8514             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8515             if ( !s0.match( query_nodes ) ) {
8516                 return false;
8517             }
8518             //
8519             query_nodes = new HashSet<PhylogenyNode>();
8520             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8521             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8522             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8523             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8524             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8525             if ( !s0.match( query_nodes ) ) {
8526                 return false;
8527             }
8528             //
8529             query_nodes = new HashSet<PhylogenyNode>();
8530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8533             if ( !s0.match( query_nodes ) ) {
8534                 return false;
8535             }
8536             //
8537             query_nodes = new HashSet<PhylogenyNode>();
8538             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8541             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8542             if ( !s0.match( query_nodes ) ) {
8543                 return false;
8544             }
8545             //
8546             query_nodes = new HashSet<PhylogenyNode>();
8547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8549             if ( s0.match( query_nodes ) ) {
8550                 return false;
8551             }
8552             //
8553             query_nodes = new HashSet<PhylogenyNode>();
8554             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8557             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8558             if ( s0.match( query_nodes ) ) {
8559                 return false;
8560             }
8561             //
8562             query_nodes = new HashSet<PhylogenyNode>();
8563             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8564             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8565             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8566             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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( "B" ) );
8575             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8576             if ( s0.match( query_nodes ) ) {
8577                 return false;
8578             }
8579             //
8580             query_nodes = new HashSet<PhylogenyNode>();
8581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8582             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8583             if ( s0.match( query_nodes ) ) {
8584                 return false;
8585             }
8586             //
8587             query_nodes = new HashSet<PhylogenyNode>();
8588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8590             if ( s0.match( query_nodes ) ) {
8591                 return false;
8592             }
8593             //
8594             query_nodes = new HashSet<PhylogenyNode>();
8595             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8596             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
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( "E" ) );
8604             if ( s0.match( query_nodes ) ) {
8605                 return false;
8606             }
8607             //
8608             query_nodes = new HashSet<PhylogenyNode>();
8609             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8610             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8611             if ( s0.match( query_nodes ) ) {
8612                 return false;
8613             }
8614             //
8615             query_nodes = new HashSet<PhylogenyNode>();
8616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8618             if ( s0.match( query_nodes ) ) {
8619                 return false;
8620             }
8621             //
8622             query_nodes = new HashSet<PhylogenyNode>();
8623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8626             if ( s0.match( query_nodes ) ) {
8627                 return false;
8628             }
8629             //
8630             query_nodes = new HashSet<PhylogenyNode>();
8631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8634             if ( s0.match( query_nodes ) ) {
8635                 return false;
8636             }
8637             //
8638             query_nodes = new HashSet<PhylogenyNode>();
8639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8641             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8642             if ( s0.match( query_nodes ) ) {
8643                 return false;
8644             }
8645             //
8646             query_nodes = new HashSet<PhylogenyNode>();
8647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8649             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8650             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8651             if ( s0.match( query_nodes ) ) {
8652                 return false;
8653             }
8654             /////////
8655             //            query_nodes = new HashSet<PhylogenyNode>();
8656             //            query_nodes.add( new PhylogenyNode( "X" ) );
8657             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8658             //            query_nodes.add( new PhylogenyNode( "A" ) );
8659             //            query_nodes.add( new PhylogenyNode( "B" ) );
8660             //            query_nodes.add( new PhylogenyNode( "C" ) );
8661             //            query_nodes.add( new PhylogenyNode( "D" ) );
8662             //            query_nodes.add( new PhylogenyNode( "E" ) );
8663             //            query_nodes.add( new PhylogenyNode( "F" ) );
8664             //            query_nodes.add( new PhylogenyNode( "G" ) );
8665             //            if ( !s0.match( query_nodes ) ) {
8666             //                return false;
8667             //            }
8668             //            query_nodes = new HashSet<PhylogenyNode>();
8669             //            query_nodes.add( new PhylogenyNode( "X" ) );
8670             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8671             //            query_nodes.add( new PhylogenyNode( "A" ) );
8672             //            query_nodes.add( new PhylogenyNode( "B" ) );
8673             //            query_nodes.add( new PhylogenyNode( "C" ) );
8674             //            if ( !s0.match( query_nodes ) ) {
8675             //                return false;
8676             //            }
8677             //            //
8678             //            query_nodes = new HashSet<PhylogenyNode>();
8679             //            query_nodes.add( new PhylogenyNode( "X" ) );
8680             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8681             //            query_nodes.add( new PhylogenyNode( "D" ) );
8682             //            query_nodes.add( new PhylogenyNode( "E" ) );
8683             //            query_nodes.add( new PhylogenyNode( "F" ) );
8684             //            query_nodes.add( new PhylogenyNode( "G" ) );
8685             //            if ( !s0.match( query_nodes ) ) {
8686             //                return false;
8687             //            }
8688             //            //
8689             //            query_nodes = new HashSet<PhylogenyNode>();
8690             //            query_nodes.add( new PhylogenyNode( "X" ) );
8691             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8692             //            query_nodes.add( new PhylogenyNode( "A" ) );
8693             //            query_nodes.add( new PhylogenyNode( "B" ) );
8694             //            query_nodes.add( new PhylogenyNode( "C" ) );
8695             //            query_nodes.add( new PhylogenyNode( "D" ) );
8696             //            if ( !s0.match( query_nodes ) ) {
8697             //                return false;
8698             //            }
8699             //            //
8700             //            query_nodes = new HashSet<PhylogenyNode>();
8701             //            query_nodes.add( new PhylogenyNode( "X" ) );
8702             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8703             //            query_nodes.add( new PhylogenyNode( "E" ) );
8704             //            query_nodes.add( new PhylogenyNode( "F" ) );
8705             //            query_nodes.add( new PhylogenyNode( "G" ) );
8706             //            if ( !s0.match( query_nodes ) ) {
8707             //                return false;
8708             //            }
8709             //            //
8710             //            query_nodes = new HashSet<PhylogenyNode>();
8711             //            query_nodes.add( new PhylogenyNode( "X" ) );
8712             //            query_nodes.add( new PhylogenyNode( "Y" ) );
8713             //            query_nodes.add( new PhylogenyNode( "F" ) );
8714             //            query_nodes.add( new PhylogenyNode( "G" ) );
8715             //            if ( !s0.match( query_nodes ) ) {
8716             //                return false;
8717             //            }
8718             //
8719             query_nodes = new HashSet<PhylogenyNode>();
8720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8724             if ( s0.match( query_nodes ) ) {
8725                 return false;
8726             }
8727             //
8728             query_nodes = new HashSet<PhylogenyNode>();
8729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8733             if ( s0.match( query_nodes ) ) {
8734                 return false;
8735             }
8736             ///////////////////////////
8737             //
8738             query_nodes = new HashSet<PhylogenyNode>();
8739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8741             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8743             if ( s0.match( query_nodes ) ) {
8744                 return false;
8745             }
8746             //
8747             query_nodes = new HashSet<PhylogenyNode>();
8748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8752             if ( s0.match( query_nodes ) ) {
8753                 return false;
8754             }
8755             //
8756             query_nodes = new HashSet<PhylogenyNode>();
8757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8759             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8761             if ( s0.match( query_nodes ) ) {
8762                 return false;
8763             }
8764             //
8765             query_nodes = new HashSet<PhylogenyNode>();
8766             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8767             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8768             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8769             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8770             if ( s0.match( query_nodes ) ) {
8771                 return false;
8772             }
8773             //
8774             query_nodes = new HashSet<PhylogenyNode>();
8775             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8776             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8777             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8778             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8779             if ( s0.match( query_nodes ) ) {
8780                 return false;
8781             }
8782             //
8783             query_nodes = new HashSet<PhylogenyNode>();
8784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8785             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8786             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8787             if ( s0.match( query_nodes ) ) {
8788                 return false;
8789             }
8790             //
8791             query_nodes = new HashSet<PhylogenyNode>();
8792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8793             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8794             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8795             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8797             if ( s0.match( query_nodes ) ) {
8798                 return false;
8799             }
8800             //
8801             query_nodes = new HashSet<PhylogenyNode>();
8802             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8803             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8807             if ( s0.match( query_nodes ) ) {
8808                 return false;
8809             }
8810             //
8811             query_nodes = new HashSet<PhylogenyNode>();
8812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8815             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8816             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8817             if ( s0.match( query_nodes ) ) {
8818                 return false;
8819             }
8820             //
8821             query_nodes = new HashSet<PhylogenyNode>();
8822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8824             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8825             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8826             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8827             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8828             if ( s0.match( query_nodes ) ) {
8829                 return false;
8830             }
8831         }
8832         catch ( final Exception e ) {
8833             e.printStackTrace();
8834             return false;
8835         }
8836         return true;
8837     }
8838
8839     private static boolean testSplitStrict() {
8840         try {
8841             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8842             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8843             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8844             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8845             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8846             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8847             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8848             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8849             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8850             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8851             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
8852             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8853             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8854             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8855             if ( s0.match( query_nodes ) ) {
8856                 return false;
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             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8866             if ( !s0.match( query_nodes ) ) {
8867                 return false;
8868             }
8869             //
8870             query_nodes = new HashSet<PhylogenyNode>();
8871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8874             if ( !s0.match( query_nodes ) ) {
8875                 return false;
8876             }
8877             //
8878             query_nodes = new HashSet<PhylogenyNode>();
8879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8882             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8883             if ( !s0.match( query_nodes ) ) {
8884                 return false;
8885             }
8886             //
8887             query_nodes = new HashSet<PhylogenyNode>();
8888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8892             if ( !s0.match( query_nodes ) ) {
8893                 return false;
8894             }
8895             //
8896             query_nodes = new HashSet<PhylogenyNode>();
8897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8900             if ( !s0.match( query_nodes ) ) {
8901                 return false;
8902             }
8903             //
8904             query_nodes = new HashSet<PhylogenyNode>();
8905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8907             if ( !s0.match( query_nodes ) ) {
8908                 return false;
8909             }
8910             //
8911             query_nodes = new HashSet<PhylogenyNode>();
8912             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8913             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8917             if ( !s0.match( query_nodes ) ) {
8918                 return false;
8919             }
8920             //
8921             query_nodes = new HashSet<PhylogenyNode>();
8922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8925             if ( !s0.match( query_nodes ) ) {
8926                 return false;
8927             }
8928             //
8929             query_nodes = new HashSet<PhylogenyNode>();
8930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8931             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8932             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8933             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8934             if ( !s0.match( query_nodes ) ) {
8935                 return false;
8936             }
8937             //
8938             query_nodes = new HashSet<PhylogenyNode>();
8939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8940             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8941             if ( s0.match( query_nodes ) ) {
8942                 return false;
8943             }
8944             //
8945             query_nodes = new HashSet<PhylogenyNode>();
8946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8947             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8949             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8950             if ( s0.match( query_nodes ) ) {
8951                 return false;
8952             }
8953             //
8954             query_nodes = new HashSet<PhylogenyNode>();
8955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8958             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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( "B" ) );
8967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8968             if ( s0.match( query_nodes ) ) {
8969                 return false;
8970             }
8971             //
8972             query_nodes = new HashSet<PhylogenyNode>();
8973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8974             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8975             if ( s0.match( query_nodes ) ) {
8976                 return false;
8977             }
8978             //
8979             query_nodes = new HashSet<PhylogenyNode>();
8980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8982             if ( s0.match( query_nodes ) ) {
8983                 return false;
8984             }
8985             //
8986             query_nodes = new HashSet<PhylogenyNode>();
8987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
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( "E" ) );
8996             if ( s0.match( query_nodes ) ) {
8997                 return false;
8998             }
8999             //
9000             query_nodes = new HashSet<PhylogenyNode>();
9001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9003             if ( s0.match( query_nodes ) ) {
9004                 return false;
9005             }
9006             //
9007             query_nodes = new HashSet<PhylogenyNode>();
9008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9010             if ( s0.match( query_nodes ) ) {
9011                 return false;
9012             }
9013             //
9014             query_nodes = new HashSet<PhylogenyNode>();
9015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9018             if ( s0.match( query_nodes ) ) {
9019                 return false;
9020             }
9021             //
9022             query_nodes = new HashSet<PhylogenyNode>();
9023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9024             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9025             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9026             if ( s0.match( query_nodes ) ) {
9027                 return false;
9028             }
9029             //
9030             query_nodes = new HashSet<PhylogenyNode>();
9031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9033             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9034             if ( s0.match( query_nodes ) ) {
9035                 return false;
9036             }
9037             //
9038             query_nodes = new HashSet<PhylogenyNode>();
9039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9041             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9042             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9043             if ( s0.match( query_nodes ) ) {
9044                 return false;
9045             }
9046         }
9047         catch ( final Exception e ) {
9048             e.printStackTrace();
9049             return false;
9050         }
9051         return true;
9052     }
9053
9054     private static boolean testSubtreeDeletion() {
9055         try {
9056             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9057             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9058             t1.deleteSubtree( t1.getNode( "A" ), false );
9059             if ( t1.getNumberOfExternalNodes() != 5 ) {
9060                 return false;
9061             }
9062             t1.toNewHampshireX();
9063             t1.deleteSubtree( t1.getNode( "E" ), false );
9064             if ( t1.getNumberOfExternalNodes() != 4 ) {
9065                 return false;
9066             }
9067             t1.toNewHampshireX();
9068             t1.deleteSubtree( t1.getNode( "F" ), false );
9069             if ( t1.getNumberOfExternalNodes() != 3 ) {
9070                 return false;
9071             }
9072             t1.toNewHampshireX();
9073             t1.deleteSubtree( t1.getNode( "D" ), false );
9074             t1.toNewHampshireX();
9075             if ( t1.getNumberOfExternalNodes() != 3 ) {
9076                 return false;
9077             }
9078             t1.deleteSubtree( t1.getNode( "def" ), false );
9079             t1.toNewHampshireX();
9080             if ( t1.getNumberOfExternalNodes() != 2 ) {
9081                 return false;
9082             }
9083             t1.deleteSubtree( t1.getNode( "B" ), false );
9084             t1.toNewHampshireX();
9085             if ( t1.getNumberOfExternalNodes() != 1 ) {
9086                 return false;
9087             }
9088             t1.deleteSubtree( t1.getNode( "C" ), false );
9089             t1.toNewHampshireX();
9090             if ( t1.getNumberOfExternalNodes() != 1 ) {
9091                 return false;
9092             }
9093             t1.deleteSubtree( t1.getNode( "abc" ), false );
9094             t1.toNewHampshireX();
9095             if ( t1.getNumberOfExternalNodes() != 1 ) {
9096                 return false;
9097             }
9098             t1.deleteSubtree( t1.getNode( "r" ), false );
9099             if ( t1.getNumberOfExternalNodes() != 0 ) {
9100                 return false;
9101             }
9102             if ( !t1.isEmpty() ) {
9103                 return false;
9104             }
9105             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9106             t2.deleteSubtree( t2.getNode( "A" ), false );
9107             t2.toNewHampshireX();
9108             if ( t2.getNumberOfExternalNodes() != 5 ) {
9109                 return false;
9110             }
9111             t2.deleteSubtree( t2.getNode( "abc" ), false );
9112             t2.toNewHampshireX();
9113             if ( t2.getNumberOfExternalNodes() != 3 ) {
9114                 return false;
9115             }
9116             t2.deleteSubtree( t2.getNode( "def" ), false );
9117             t2.toNewHampshireX();
9118             if ( t2.getNumberOfExternalNodes() != 1 ) {
9119                 return false;
9120             }
9121         }
9122         catch ( final Exception e ) {
9123             e.printStackTrace( System.out );
9124             return false;
9125         }
9126         return true;
9127     }
9128
9129     private static boolean testSupportCount() {
9130         try {
9131             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9132             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
9133             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
9134                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
9135                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
9136                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
9137                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
9138                                                               new NHXParser() );
9139             SupportCount.count( t0_1, phylogenies_1, true, false );
9140             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
9141             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
9142                                                                       + "(((((A,B),C),D),E),((F,G),X))"
9143                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
9144                                                                       + "(((((A,B),C),D),E),(F,G))"
9145                                                                       + "(((((A,B),C),D),E),(F,G))"
9146                                                                       + "(((((A,B),C),D),E),(F,G))"
9147                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
9148                                                                       + "(((((A,B),C),D),E),(F,G))"
9149                                                                       + "((((((A,B),C),D),E),F),G)"
9150                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
9151                                                               new NHXParser() );
9152             SupportCount.count( t0_2, phylogenies_2, true, false );
9153             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
9154             while ( it.hasNext() ) {
9155                 final PhylogenyNode n = it.next();
9156                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
9157                     return false;
9158                 }
9159             }
9160             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
9161             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
9162                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
9163             SupportCount.count( t0_3, phylogenies_3, true, false );
9164             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
9165             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
9166                 return false;
9167             }
9168             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
9169                 return false;
9170             }
9171             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
9172                 return false;
9173             }
9174             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
9175                 return false;
9176             }
9177             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
9178                 return false;
9179             }
9180             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
9181                 return false;
9182             }
9183             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
9184                 return false;
9185             }
9186             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
9187                 return false;
9188             }
9189             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
9190                 return false;
9191             }
9192             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
9193                 return false;
9194             }
9195             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9196             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
9197                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
9198             SupportCount.count( t0_4, phylogenies_4, true, false );
9199             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
9200             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
9201                 return false;
9202             }
9203             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
9204                 return false;
9205             }
9206             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
9207                 return false;
9208             }
9209             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
9210                 return false;
9211             }
9212             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
9213                 return false;
9214             }
9215             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
9216                 return false;
9217             }
9218             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
9219                 return false;
9220             }
9221             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
9222                 return false;
9223             }
9224             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
9225                 return false;
9226             }
9227             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
9228                 return false;
9229             }
9230             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9231             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9232             double d = SupportCount.compare( b1, a, true, true, true );
9233             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
9234                 return false;
9235             }
9236             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9237             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9238             d = SupportCount.compare( b2, a, true, true, true );
9239             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
9240                 return false;
9241             }
9242             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9243             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
9244             d = SupportCount.compare( b3, a, true, true, true );
9245             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
9246                 return false;
9247             }
9248             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
9249             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
9250             d = SupportCount.compare( b4, a, true, true, false );
9251             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
9252                 return false;
9253             }
9254         }
9255         catch ( final Exception e ) {
9256             e.printStackTrace( System.out );
9257             return false;
9258         }
9259         return true;
9260     }
9261
9262     private static boolean testSupportTransfer() {
9263         try {
9264             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9265             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)",
9266                                                  new NHXParser() )[ 0 ];
9267             final Phylogeny p2 = factory
9268                     .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 ];
9269             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
9270                 return false;
9271             }
9272             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
9273                 return false;
9274             }
9275             support_transfer.moveBranchLengthsToBootstrap( p1 );
9276             support_transfer.transferSupportValues( p1, p2 );
9277             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
9278                 return false;
9279             }
9280             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
9281                 return false;
9282             }
9283             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
9284                 return false;
9285             }
9286             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
9287                 return false;
9288             }
9289             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
9290                 return false;
9291             }
9292             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
9293                 return false;
9294             }
9295             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
9296                 return false;
9297             }
9298             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
9299                 return false;
9300             }
9301         }
9302         catch ( final Exception e ) {
9303             e.printStackTrace( System.out );
9304             return false;
9305         }
9306         return true;
9307     }
9308
9309     private static boolean testUniprotTaxonomySearch() {
9310         try {
9311             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
9312                                                                                                  10 );
9313             if ( results.size() != 1 ) {
9314                 return false;
9315             }
9316             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9317                 return false;
9318             }
9319             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9320                 return false;
9321             }
9322             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9323                 return false;
9324             }
9325             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9326                 return false;
9327             }
9328             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9329                 return false;
9330             }
9331             results = null;
9332             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
9333             if ( results.size() != 1 ) {
9334                 return false;
9335             }
9336             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9337                 return false;
9338             }
9339             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9340                 return false;
9341             }
9342             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9343                 return false;
9344             }
9345             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9346                 return false;
9347             }
9348             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9349                 return false;
9350             }
9351             results = null;
9352             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
9353             if ( results.size() != 1 ) {
9354                 return false;
9355             }
9356             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9357                 return false;
9358             }
9359             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9360                 return false;
9361             }
9362             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9363                 return false;
9364             }
9365             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9366                 return false;
9367             }
9368             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9369                 return false;
9370             }
9371             results = null;
9372             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
9373             if ( results.size() != 1 ) {
9374                 return false;
9375             }
9376             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9377                 return false;
9378             }
9379             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9380                 return false;
9381             }
9382             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9383                 return false;
9384             }
9385             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9386                 return false;
9387             }
9388             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9389                 return false;
9390             }
9391             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
9392                 return false;
9393             }
9394             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
9395                 return false;
9396             }
9397             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
9398                     .equals( "Nematostella vectensis" ) ) {
9399                 System.out.println( results.get( 0 ).getLineage() );
9400                 return false;
9401             }
9402         }
9403         catch ( final IOException e ) {
9404             System.out.println();
9405             System.out.println( "the following might be due to absence internet connection:" );
9406             e.printStackTrace( System.out );
9407             return true;
9408         }
9409         catch ( final Exception e ) {
9410             return false;
9411         }
9412         return true;
9413     }
9414
9415     private static boolean testEmblEntryRetrieval() {
9416         //The format for GenBank Accession numbers are:
9417         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
9418         //Protein:    3 letters + 5 numerals
9419         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
9420         if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
9421             return false;
9422         }
9423         if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861.2" ).equals( "AY423861.2" ) ) {
9424             return false;
9425         }
9426         if ( !SequenceIdParser.parseGenbankAccessor( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
9427             return false;
9428         }
9429         if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
9430             return false;
9431         }
9432         if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
9433             return false;
9434         }
9435         if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
9436             return false;
9437         }
9438         if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
9439             return false;
9440         }
9441         if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
9442             return false;
9443         }
9444         if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
9445             return false;
9446         }
9447         if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
9448             return false;
9449         }
9450         if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
9451             return false;
9452         }
9453         if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
9454             return false;
9455         }
9456         if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
9457             return false;
9458         }
9459         if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
9460             return false;
9461         }
9462         return true;
9463     }
9464
9465     private static boolean testUniprotEntryRetrieval() {
9466         try {
9467             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
9468             if ( !entry.getAccession().equals( "P12345" ) ) {
9469                 return false;
9470             }
9471             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
9472                 return false;
9473             }
9474             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
9475                 return false;
9476             }
9477             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
9478                 return false;
9479             }
9480         }
9481         catch ( final IOException e ) {
9482             System.out.println();
9483             System.out.println( "the following might be due to absence internet connection:" );
9484             e.printStackTrace( System.out );
9485             return true;
9486         }
9487         catch ( final Exception e ) {
9488             return false;
9489         }
9490         return true;
9491     }
9492
9493     private static boolean testWabiTxSearch() {
9494         try {
9495             String result = "";
9496             result = TxSearch.searchSimple( "nematostella" );
9497             result = TxSearch.getTxId( "nematostella" );
9498             if ( !result.equals( "45350" ) ) {
9499                 return false;
9500             }
9501             result = TxSearch.getTxName( "45350" );
9502             if ( !result.equals( "Nematostella" ) ) {
9503                 return false;
9504             }
9505             result = TxSearch.getTxId( "nematostella vectensis" );
9506             if ( !result.equals( "45351" ) ) {
9507                 return false;
9508             }
9509             result = TxSearch.getTxName( "45351" );
9510             if ( !result.equals( "Nematostella vectensis" ) ) {
9511                 return false;
9512             }
9513             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
9514             if ( !result.equals( "536089" ) ) {
9515                 return false;
9516             }
9517             result = TxSearch.getTxName( "536089" );
9518             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
9519                 return false;
9520             }
9521             final List<String> queries = new ArrayList<String>();
9522             queries.add( "Campylobacter coli" );
9523             queries.add( "Escherichia coli" );
9524             queries.add( "Arabidopsis" );
9525             queries.add( "Trichoplax" );
9526             queries.add( "Samanea saman" );
9527             queries.add( "Kluyveromyces marxianus" );
9528             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
9529             queries.add( "Bornavirus parrot/PDD/2008" );
9530             final List<RANKS> ranks = new ArrayList<RANKS>();
9531             ranks.add( RANKS.SUPERKINGDOM );
9532             ranks.add( RANKS.KINGDOM );
9533             ranks.add( RANKS.FAMILY );
9534             ranks.add( RANKS.GENUS );
9535             ranks.add( RANKS.TRIBE );
9536             result = TxSearch.searchLineage( queries, ranks );
9537             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
9538             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
9539         }
9540         catch ( final Exception e ) {
9541             System.out.println();
9542             System.out.println( "the following might be due to absence internet connection:" );
9543             e.printStackTrace( System.out );
9544             return false;
9545         }
9546         return true;
9547     }
9548
9549     private static boolean testAminoAcidSequence() {
9550         try {
9551             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
9552             if ( aa1.getLength() != 13 ) {
9553                 return false;
9554             }
9555             if ( aa1.getResidueAt( 0 ) != 'A' ) {
9556                 return false;
9557             }
9558             if ( aa1.getResidueAt( 2 ) != 'K' ) {
9559                 return false;
9560             }
9561             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
9562                 return false;
9563             }
9564             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
9565             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
9566                 return false;
9567             }
9568             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
9569             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
9570                 return false;
9571             }
9572             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
9573             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
9574                 return false;
9575             }
9576         }
9577         catch ( final Exception e ) {
9578             e.printStackTrace();
9579             return false;
9580         }
9581         return true;
9582     }
9583
9584     private static boolean testSequenceWriter() {
9585         try {
9586             final String n = ForesterUtil.LINE_SEPARATOR;
9587             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9588                 return false;
9589             }
9590             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9591                 return false;
9592             }
9593             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9594                 return false;
9595             }
9596             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9597                 return false;
9598             }
9599             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9600                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9601                 return false;
9602             }
9603             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9604                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9605                 return false;
9606             }
9607         }
9608         catch ( final Exception e ) {
9609             e.printStackTrace();
9610             return false;
9611         }
9612         return true;
9613     }
9614
9615     private static boolean testCreateBalancedPhylogeny() {
9616         try {
9617             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
9618             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
9619                 return false;
9620             }
9621             if ( p0.getNumberOfExternalNodes() != 15625 ) {
9622                 return false;
9623             }
9624             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
9625             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
9626                 return false;
9627             }
9628             if ( p1.getNumberOfExternalNodes() != 100 ) {
9629                 return false;
9630             }
9631         }
9632         catch ( final Exception e ) {
9633             e.printStackTrace();
9634             return false;
9635         }
9636         return true;
9637     }
9638
9639     private static boolean testFastaParser() {
9640         try {
9641             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
9642                 return false;
9643             }
9644             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
9645                 return false;
9646             }
9647             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
9648             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
9649                 return false;
9650             }
9651             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
9652                 return false;
9653             }
9654             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
9655                 return false;
9656             }
9657             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
9658                 return false;
9659             }
9660             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
9661                 return false;
9662             }
9663             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
9664                 return false;
9665             }
9666         }
9667         catch ( final Exception e ) {
9668             e.printStackTrace();
9669             return false;
9670         }
9671         return true;
9672     }
9673
9674     private static boolean testGeneralMsaParser() {
9675         try {
9676             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
9677             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
9678             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
9679             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
9680             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
9681             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
9682             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
9683             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
9684             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9685                 return false;
9686             }
9687             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9688                 return false;
9689             }
9690             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9691                 return false;
9692             }
9693             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9694                 return false;
9695             }
9696             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9697                 return false;
9698             }
9699             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9700                 return false;
9701             }
9702             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9703                 return false;
9704             }
9705             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9706                 return false;
9707             }
9708             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9709                 return false;
9710             }
9711             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9712                 return false;
9713             }
9714             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9715                 return false;
9716             }
9717             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9718                 return false;
9719             }
9720             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
9721             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9722                 return false;
9723             }
9724             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9725                 return false;
9726             }
9727             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9728                 return false;
9729             }
9730             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
9731             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
9732                 return false;
9733             }
9734             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
9735                 return false;
9736             }
9737             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
9738                 return false;
9739             }
9740             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
9741             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9742                 return false;
9743             }
9744             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9745                 return false;
9746             }
9747             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9748                 return false;
9749             }
9750         }
9751         catch ( final Exception e ) {
9752             e.printStackTrace();
9753             return false;
9754         }
9755         return true;
9756     }
9757
9758     private static boolean testMafft( final String path ) {
9759         try {
9760             final List<String> opts = new ArrayList<String>();
9761             opts.add( "--maxiterate" );
9762             opts.add( "1000" );
9763             opts.add( "--localpair" );
9764             opts.add( "--quiet" );
9765             Msa msa = null;
9766             final MsaInferrer mafft = Mafft.createInstance( path );
9767             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
9768             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
9769                 return false;
9770             }
9771             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
9772                 return false;
9773             }
9774         }
9775         catch ( final Exception e ) {
9776             e.printStackTrace( System.out );
9777             return false;
9778         }
9779         return true;
9780     }
9781
9782     private static boolean testNextNodeWithCollapsing() {
9783         try {
9784             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9785             PhylogenyNode n;
9786             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
9787             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9788             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
9789             t0.getNode( "cd" ).setCollapse( true );
9790             t0.getNode( "cde" ).setCollapse( true );
9791             n = t0.getFirstExternalNode();
9792             while ( n != null ) {
9793                 ext.add( n );
9794                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9795             }
9796             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9797                 return false;
9798             }
9799             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9800                 return false;
9801             }
9802             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
9803                 return false;
9804             }
9805             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
9806                 return false;
9807             }
9808             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
9809                 return false;
9810             }
9811             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
9812                 return false;
9813             }
9814             ext.clear();
9815             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9816             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
9817             t1.getNode( "ab" ).setCollapse( true );
9818             t1.getNode( "cd" ).setCollapse( true );
9819             t1.getNode( "cde" ).setCollapse( true );
9820             n = t1.getNode( "ab" );
9821             ext = new ArrayList<PhylogenyNode>();
9822             while ( n != null ) {
9823                 ext.add( n );
9824                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9825             }
9826             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9827                 return false;
9828             }
9829             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9830                 return false;
9831             }
9832             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9833                 return false;
9834             }
9835             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
9836                 return false;
9837             }
9838             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
9839                 return false;
9840             }
9841             //
9842             //
9843             ext.clear();
9844             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9845             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
9846             t2.getNode( "ab" ).setCollapse( true );
9847             t2.getNode( "cd" ).setCollapse( true );
9848             t2.getNode( "cde" ).setCollapse( true );
9849             t2.getNode( "c" ).setCollapse( true );
9850             t2.getNode( "d" ).setCollapse( true );
9851             t2.getNode( "e" ).setCollapse( true );
9852             t2.getNode( "gh" ).setCollapse( true );
9853             n = t2.getNode( "ab" );
9854             ext = new ArrayList<PhylogenyNode>();
9855             while ( n != null ) {
9856                 ext.add( n );
9857                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9858             }
9859             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9860                 return false;
9861             }
9862             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9863                 return false;
9864             }
9865             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9866                 return false;
9867             }
9868             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
9869                 return false;
9870             }
9871             //
9872             //
9873             ext.clear();
9874             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9875             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
9876             t3.getNode( "ab" ).setCollapse( true );
9877             t3.getNode( "cd" ).setCollapse( true );
9878             t3.getNode( "cde" ).setCollapse( true );
9879             t3.getNode( "c" ).setCollapse( true );
9880             t3.getNode( "d" ).setCollapse( true );
9881             t3.getNode( "e" ).setCollapse( true );
9882             t3.getNode( "gh" ).setCollapse( true );
9883             t3.getNode( "fgh" ).setCollapse( true );
9884             n = t3.getNode( "ab" );
9885             ext = new ArrayList<PhylogenyNode>();
9886             while ( n != null ) {
9887                 ext.add( n );
9888                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9889             }
9890             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9891                 return false;
9892             }
9893             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9894                 return false;
9895             }
9896             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
9897                 return false;
9898             }
9899             //
9900             //
9901             ext.clear();
9902             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9903             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
9904             t4.getNode( "ab" ).setCollapse( true );
9905             t4.getNode( "cd" ).setCollapse( true );
9906             t4.getNode( "cde" ).setCollapse( true );
9907             t4.getNode( "c" ).setCollapse( true );
9908             t4.getNode( "d" ).setCollapse( true );
9909             t4.getNode( "e" ).setCollapse( true );
9910             t4.getNode( "gh" ).setCollapse( true );
9911             t4.getNode( "fgh" ).setCollapse( true );
9912             t4.getNode( "abcdefgh" ).setCollapse( true );
9913             n = t4.getNode( "abcdefgh" );
9914             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
9915                 return false;
9916             }
9917             //
9918             //
9919             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9920             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
9921             ext.clear();
9922             n = t5.getFirstExternalNode();
9923             while ( n != null ) {
9924                 ext.add( n );
9925                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9926             }
9927             if ( ext.size() != 8 ) {
9928                 return false;
9929             }
9930             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9931                 return false;
9932             }
9933             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9934                 return false;
9935             }
9936             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
9937                 return false;
9938             }
9939             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
9940                 return false;
9941             }
9942             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
9943                 return false;
9944             }
9945             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
9946                 return false;
9947             }
9948             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
9949                 return false;
9950             }
9951             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
9952                 return false;
9953             }
9954             //
9955             //
9956             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9957             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
9958             ext.clear();
9959             t6.getNode( "ab" ).setCollapse( true );
9960             n = t6.getNode( "ab" );
9961             while ( n != null ) {
9962                 ext.add( n );
9963                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9964             }
9965             if ( ext.size() != 7 ) {
9966                 return false;
9967             }
9968             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9969                 return false;
9970             }
9971             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
9972                 return false;
9973             }
9974             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
9975                 return false;
9976             }
9977             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9978                 return false;
9979             }
9980             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9981                 return false;
9982             }
9983             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9984                 return false;
9985             }
9986             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9987                 return false;
9988             }
9989             //
9990             //
9991             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9992             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
9993             ext.clear();
9994             t7.getNode( "cd" ).setCollapse( true );
9995             n = t7.getNode( "a" );
9996             while ( n != null ) {
9997                 ext.add( n );
9998                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9999             }
10000             if ( ext.size() != 7 ) {
10001                 return false;
10002             }
10003             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10004                 return false;
10005             }
10006             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10007                 return false;
10008             }
10009             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10010                 return false;
10011             }
10012             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10013                 return false;
10014             }
10015             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10016                 return false;
10017             }
10018             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10019                 return false;
10020             }
10021             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10022                 return false;
10023             }
10024             //
10025             //
10026             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
10027             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
10028             ext.clear();
10029             t8.getNode( "cd" ).setCollapse( true );
10030             t8.getNode( "c" ).setCollapse( true );
10031             t8.getNode( "d" ).setCollapse( true );
10032             n = t8.getNode( "a" );
10033             while ( n != null ) {
10034                 ext.add( n );
10035                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10036             }
10037             if ( ext.size() != 7 ) {
10038                 return false;
10039             }
10040             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10041                 return false;
10042             }
10043             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10044                 return false;
10045             }
10046             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10047                 System.out.println( "2 fail" );
10048                 return false;
10049             }
10050             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10051                 return false;
10052             }
10053             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10054                 return false;
10055             }
10056             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10057                 return false;
10058             }
10059             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10060                 return false;
10061             }
10062             //
10063             //
10064             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10065             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
10066             ext.clear();
10067             t9.getNode( "gh" ).setCollapse( true );
10068             n = t9.getNode( "a" );
10069             while ( n != null ) {
10070                 ext.add( n );
10071                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10072             }
10073             if ( ext.size() != 7 ) {
10074                 return false;
10075             }
10076             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10077                 return false;
10078             }
10079             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10080                 return false;
10081             }
10082             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10083                 return false;
10084             }
10085             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10086                 return false;
10087             }
10088             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10089                 return false;
10090             }
10091             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10092                 return false;
10093             }
10094             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10095                 return false;
10096             }
10097             //
10098             //
10099             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10100             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
10101             ext.clear();
10102             t10.getNode( "gh" ).setCollapse( true );
10103             t10.getNode( "g" ).setCollapse( true );
10104             t10.getNode( "h" ).setCollapse( true );
10105             n = t10.getNode( "a" );
10106             while ( n != null ) {
10107                 ext.add( n );
10108                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10109             }
10110             if ( ext.size() != 7 ) {
10111                 return false;
10112             }
10113             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10114                 return false;
10115             }
10116             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10117                 return false;
10118             }
10119             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10120                 return false;
10121             }
10122             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10123                 return false;
10124             }
10125             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10126                 return false;
10127             }
10128             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10129                 return false;
10130             }
10131             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10132                 return false;
10133             }
10134             //
10135             //
10136             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10137             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
10138             ext.clear();
10139             t11.getNode( "gh" ).setCollapse( true );
10140             t11.getNode( "fgh" ).setCollapse( true );
10141             n = t11.getNode( "a" );
10142             while ( n != null ) {
10143                 ext.add( n );
10144                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10145             }
10146             if ( ext.size() != 6 ) {
10147                 return false;
10148             }
10149             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10150                 return false;
10151             }
10152             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10153                 return false;
10154             }
10155             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10156                 return false;
10157             }
10158             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10159                 return false;
10160             }
10161             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10162                 return false;
10163             }
10164             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10165                 return false;
10166             }
10167             //
10168             //
10169             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10170             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
10171             ext.clear();
10172             t12.getNode( "gh" ).setCollapse( true );
10173             t12.getNode( "fgh" ).setCollapse( true );
10174             t12.getNode( "g" ).setCollapse( true );
10175             t12.getNode( "h" ).setCollapse( true );
10176             t12.getNode( "f" ).setCollapse( true );
10177             n = t12.getNode( "a" );
10178             while ( n != null ) {
10179                 ext.add( n );
10180                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10181             }
10182             if ( ext.size() != 6 ) {
10183                 return false;
10184             }
10185             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10186                 return false;
10187             }
10188             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10189                 return false;
10190             }
10191             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10192                 return false;
10193             }
10194             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10195                 return false;
10196             }
10197             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10198                 return false;
10199             }
10200             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10201                 return false;
10202             }
10203             //
10204             //
10205             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10206             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
10207             ext.clear();
10208             t13.getNode( "ab" ).setCollapse( true );
10209             t13.getNode( "b" ).setCollapse( true );
10210             t13.getNode( "fgh" ).setCollapse( true );
10211             t13.getNode( "gh" ).setCollapse( true );
10212             n = t13.getNode( "ab" );
10213             while ( n != null ) {
10214                 ext.add( n );
10215                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10216             }
10217             if ( ext.size() != 5 ) {
10218                 return false;
10219             }
10220             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10221                 return false;
10222             }
10223             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10224                 return false;
10225             }
10226             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10227                 return false;
10228             }
10229             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10230                 return false;
10231             }
10232             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10233                 return false;
10234             }
10235             //
10236             //
10237             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
10238             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
10239             ext.clear();
10240             t14.getNode( "ab" ).setCollapse( true );
10241             t14.getNode( "a" ).setCollapse( true );
10242             t14.getNode( "fgh" ).setCollapse( true );
10243             t14.getNode( "gh" ).setCollapse( true );
10244             n = t14.getNode( "ab" );
10245             while ( n != null ) {
10246                 ext.add( n );
10247                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10248             }
10249             if ( ext.size() != 5 ) {
10250                 return false;
10251             }
10252             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10253                 return false;
10254             }
10255             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10256                 return false;
10257             }
10258             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10259                 return false;
10260             }
10261             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10262                 return false;
10263             }
10264             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10265                 return false;
10266             }
10267             //
10268             //
10269             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" );
10270             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
10271             ext.clear();
10272             t15.getNode( "ab" ).setCollapse( true );
10273             t15.getNode( "a" ).setCollapse( true );
10274             t15.getNode( "fgh" ).setCollapse( true );
10275             t15.getNode( "gh" ).setCollapse( true );
10276             n = t15.getNode( "ab" );
10277             while ( n != null ) {
10278                 ext.add( n );
10279                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10280             }
10281             if ( ext.size() != 6 ) {
10282                 return false;
10283             }
10284             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10285                 return false;
10286             }
10287             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10288                 return false;
10289             }
10290             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10291                 return false;
10292             }
10293             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10294                 return false;
10295             }
10296             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
10297                 return false;
10298             }
10299             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10300                 return false;
10301             }
10302             //
10303             //
10304             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" );
10305             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
10306             ext.clear();
10307             t16.getNode( "ab" ).setCollapse( true );
10308             t16.getNode( "a" ).setCollapse( true );
10309             t16.getNode( "fgh" ).setCollapse( true );
10310             t16.getNode( "gh" ).setCollapse( true );
10311             t16.getNode( "cd" ).setCollapse( true );
10312             t16.getNode( "cde" ).setCollapse( true );
10313             t16.getNode( "d" ).setCollapse( true );
10314             t16.getNode( "x" ).setCollapse( true );
10315             n = t16.getNode( "ab" );
10316             while ( n != null ) {
10317                 ext.add( n );
10318                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10319             }
10320             if ( ext.size() != 4 ) {
10321                 return false;
10322             }
10323             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10324                 return false;
10325             }
10326             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
10327                 return false;
10328             }
10329             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
10330                 return false;
10331             }
10332             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
10333                 return false;
10334             }
10335         }
10336         catch ( final Exception e ) {
10337             e.printStackTrace( System.out );
10338             return false;
10339         }
10340         return true;
10341     }
10342
10343     private static boolean testMsaQualityMethod() {
10344         try {
10345             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
10346             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
10347             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
10348             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
10349             final List<Sequence> l = new ArrayList<Sequence>();
10350             l.add( s0 );
10351             l.add( s1 );
10352             l.add( s2 );
10353             l.add( s3 );
10354             final Msa msa = BasicMsa.createInstance( l );
10355             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
10356                 return false;
10357             }
10358             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
10359                 return false;
10360             }
10361             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
10362                 return false;
10363             }
10364             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
10365                 return false;
10366             }
10367         }
10368         catch ( final Exception e ) {
10369             e.printStackTrace( System.out );
10370             return false;
10371         }
10372         return true;
10373     }
10374
10375     private static boolean testSequenceIdParsing() {
10376         try {
10377             Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
10378             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10379                     || !id.getValue().equals( "ADF31344" ) || !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( "segmented worms|gb_ADF31344" );
10388             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10389                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
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( "segmented worms gb_ADF31344 and more" );
10398             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10399                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
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( "gb_AAA96518_1" );
10408             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10409                     || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
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( "gb_EHB07727_1_rodents_" );
10418             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10419                     || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
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( "dbj_BAF37827_1_turtles_" );
10428             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10429                     || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
10430                 if ( id != null ) {
10431                     System.out.println( "value   =" + id.getValue() );
10432                     System.out.println( "provider=" + id.getProvider() );
10433                 }
10434                 return false;
10435             }
10436             // 
10437             id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
10438             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10439                     || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
10440                 if ( id != null ) {
10441                     System.out.println( "value   =" + id.getValue() );
10442                     System.out.println( "provider=" + id.getProvider() );
10443                 }
10444                 return false;
10445             }
10446             // 
10447             id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
10448             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10449                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10450                 if ( id != null ) {
10451                     System.out.println( "value   =" + id.getValue() );
10452                     System.out.println( "provider=" + id.getProvider() );
10453                 }
10454                 return false;
10455             }
10456             // 
10457             id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
10458             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10459                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10460                 if ( id != null ) {
10461                     System.out.println( "value   =" + id.getValue() );
10462                     System.out.println( "provider=" + id.getProvider() );
10463                 }
10464                 return false;
10465             }
10466             // 
10467             id = SequenceIdParser.parse( "P4A123" );
10468             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10469                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10470                 if ( id != null ) {
10471                     System.out.println( "value   =" + id.getValue() );
10472                     System.out.println( "provider=" + id.getProvider() );
10473                 }
10474                 return false;
10475             }
10476             // 
10477             id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
10478             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10479                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10480                 if ( id != null ) {
10481                     System.out.println( "value   =" + id.getValue() );
10482                     System.out.println( "provider=" + id.getProvider() );
10483                 }
10484                 return false;
10485             }
10486             // 
10487             id = SequenceIdParser.parse( "XP_12345" );
10488             if ( id != null ) {
10489                 System.out.println( "value   =" + id.getValue() );
10490                 System.out.println( "provider=" + id.getProvider() );
10491                 return false;
10492             }
10493             // lcl_91970_unknown_
10494         }
10495         catch ( final Exception e ) {
10496             e.printStackTrace( System.out );
10497             return false;
10498         }
10499         return true;
10500     }
10501 }