inprogress
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.test;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Set;
39
40 import org.forester.application.support_transfer;
41 import org.forester.archaeopteryx.AptxUtil;
42 import org.forester.development.DevelopmentTools;
43 import org.forester.evoinference.TestPhylogenyReconstruction;
44 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
46 import org.forester.go.TestGo;
47 import org.forester.io.parsers.FastaParser;
48 import org.forester.io.parsers.GeneralMsaParser;
49 import org.forester.io.parsers.HmmscanPerDomainTableParser;
50 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
51 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
52 import org.forester.io.parsers.nexus.NexusCharactersParser;
53 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
54 import org.forester.io.parsers.nhx.NHXParser;
55 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
56 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
57 import org.forester.io.parsers.tol.TolParser;
58 import org.forester.io.parsers.util.ParserUtils;
59 import org.forester.io.writers.PhylogenyWriter;
60 import org.forester.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.BasicDomain;
92 import org.forester.protein.BasicProtein;
93 import org.forester.protein.Domain;
94 import org.forester.protein.DomainId;
95 import org.forester.protein.Protein;
96 import org.forester.protein.ProteinId;
97 import org.forester.rio.TestRIO;
98 import org.forester.sdi.SDI;
99 import org.forester.sdi.SDIR;
100 import org.forester.sdi.TestGSDI;
101 import org.forester.sequence.BasicSequence;
102 import org.forester.sequence.Sequence;
103 import org.forester.species.BasicSpecies;
104 import org.forester.species.Species;
105 import org.forester.surfacing.TestSurfacing;
106 import org.forester.tools.ConfidenceAssessor;
107 import org.forester.tools.SupportCount;
108 import org.forester.tools.TreeSplitMatrix;
109 import org.forester.util.AsciiHistogram;
110 import org.forester.util.BasicDescriptiveStatistics;
111 import org.forester.util.BasicTable;
112 import org.forester.util.BasicTableParser;
113 import org.forester.util.DescriptiveStatistics;
114 import org.forester.util.ForesterConstants;
115 import org.forester.util.ForesterUtil;
116 import org.forester.util.GeneralTable;
117 import org.forester.util.SequenceIdParser;
118 import org.forester.ws.seqdb.SequenceDatabaseEntry;
119 import org.forester.ws.seqdb.SequenceDbWsTools;
120 import org.forester.ws.seqdb.UniProtTaxonomy;
121 import org.forester.ws.wabi.TxSearch;
122 import org.forester.ws.wabi.TxSearch.RANKS;
123 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
124 import org.forester.ws.wabi.TxSearch.TAX_RANK;
125
126 @SuppressWarnings( "unused")
127 public final class Test {
128
129     private final static double  ZERO_DIFF                 = 1.0E-9;
130     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
131                                                                    + ForesterUtil.getFileSeparator() + "test_data"
132                                                                    + ForesterUtil.getFileSeparator();
133     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
134                                                                    + ForesterUtil.getFileSeparator() + "resources"
135                                                                    + ForesterUtil.getFileSeparator();
136     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
137     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
138                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
139                                                                    + ForesterConstants.PHYLO_XML_XSD;
140     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
141                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
142                                                                    + ForesterConstants.PHYLO_XML_XSD;
143
144     public static boolean isEqual( final double a, final double b ) {
145         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
146     }
147
148     public static void main( final String[] args ) {
149         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
150         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
151                 + "]" );
152         Locale.setDefault( Locale.US );
153         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
154         int failed = 0;
155         int succeeded = 0;
156         System.out.print( "[Test if directory with files for testing exists/is readable: " );
157         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
158             System.out.println( "OK.]" );
159         }
160         else {
161             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
162             System.out.println( "Testing aborted." );
163             System.exit( -1 );
164         }
165         System.out.print( "[Test if resources directory exists/is readable: " );
166         if ( testDir( PATH_TO_RESOURCES ) ) {
167             System.out.println( "OK.]" );
168         }
169         else {
170             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
171             System.out.println( "Testing aborted." );
172             System.exit( -1 );
173         }
174         final long start_time = new Date().getTime();
175         System.out.print( "Domain id: " );
176         if ( !testDomainId() ) {
177             System.out.println( "failed." );
178             failed++;
179         }
180         else {
181             succeeded++;
182         }
183         System.out.println( "OK." );
184         System.out.print( "Protein id: " );
185         if ( !testProteinId() ) {
186             System.out.println( "failed." );
187             failed++;
188         }
189         else {
190             succeeded++;
191         }
192         System.out.println( "OK." );
193         System.out.print( "Species: " );
194         if ( !testSpecies() ) {
195             System.out.println( "failed." );
196             failed++;
197         }
198         else {
199             succeeded++;
200         }
201         System.out.println( "OK." );
202         System.out.print( "Basic domain: " );
203         if ( !testBasicDomain() ) {
204             System.out.println( "failed." );
205             failed++;
206         }
207         else {
208             succeeded++;
209         }
210         System.out.println( "OK." );
211         System.out.print( "Basic protein: " );
212         if ( !testBasicProtein() ) {
213             System.out.println( "failed." );
214             failed++;
215         }
216         else {
217             succeeded++;
218         }
219         System.out.println( "OK." );
220         System.out.print( "Sequence writer: " );
221         if ( testSequenceWriter() ) {
222             System.out.println( "OK." );
223             succeeded++;
224         }
225         else {
226             System.out.println( "failed." );
227             failed++;
228         }
229         System.out.print( "Sequence id parsing: " );
230         if ( testSequenceIdParsing() ) {
231             System.out.println( "OK." );
232             succeeded++;
233         }
234         else {
235             System.out.println( "failed." );
236             failed++;
237         }
238         System.out.print( "Hmmscan output parser: " );
239         if ( testHmmscanOutputParser() ) {
240             System.out.println( "OK." );
241             succeeded++;
242         }
243         else {
244             System.out.println( "failed." );
245             failed++;
246         }
247         System.out.print( "Basic node methods: " );
248         if ( Test.testBasicNodeMethods() ) {
249             System.out.println( "OK." );
250             succeeded++;
251         }
252         else {
253             System.out.println( "failed." );
254             failed++;
255         }
256         System.out.print( "Taxonomy code extraction: " );
257         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
258             System.out.println( "OK." );
259             succeeded++;
260         }
261         else {
262             System.out.println( "failed." );
263             failed++;
264         }
265         System.out.print( "SN extraction: " );
266         if ( Test.testExtractSNFromNodeName() ) {
267             System.out.println( "OK." );
268             succeeded++;
269         }
270         else {
271             System.out.println( "failed." );
272             failed++;
273         }
274         System.out.print( "Taxonomy extraction (general): " );
275         if ( Test.testTaxonomyExtraction() ) {
276             System.out.println( "OK." );
277             succeeded++;
278         }
279         else {
280             System.out.println( "failed." );
281             failed++;
282         }
283         System.out.print( "UniProtKB id extraction: " );
284         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
285             System.out.println( "OK." );
286             succeeded++;
287         }
288         else {
289             System.out.println( "failed." );
290             failed++;
291         }
292         System.out.print( "Uri for Aptx web sequence accession: " );
293         if ( Test.testCreateUriForSeqWeb() ) {
294             System.out.println( "OK." );
295             succeeded++;
296         }
297         else {
298             System.out.println( "failed." );
299             failed++;
300         }
301         System.out.print( "Basic node construction and parsing of NHX (node level): " );
302         if ( Test.testNHXNodeParsing() ) {
303             System.out.println( "OK." );
304             succeeded++;
305         }
306         else {
307             System.out.println( "failed." );
308             failed++;
309         }
310         System.out.print( "NHX parsing iterating: " );
311         if ( Test.testNHParsingIter() ) {
312             System.out.println( "OK." );
313             succeeded++;
314         }
315         else {
316             System.out.println( "failed." );
317             failed++;
318         }
319         System.out.print( "NH parsing: " );
320         if ( Test.testNHParsing() ) {
321             System.out.println( "OK." );
322             succeeded++;
323         }
324         else {
325             System.out.println( "failed." );
326             failed++;
327         }
328         System.out.print( "Conversion to NHX (node level): " );
329         if ( Test.testNHXconversion() ) {
330             System.out.println( "OK." );
331             succeeded++;
332         }
333         else {
334             System.out.println( "failed." );
335             failed++;
336         }
337         System.out.print( "NHX parsing: " );
338         if ( Test.testNHXParsing() ) {
339             System.out.println( "OK." );
340             succeeded++;
341         }
342         else {
343             System.out.println( "failed." );
344             failed++;
345         }
346         System.out.print( "NHX parsing with quotes: " );
347         if ( Test.testNHXParsingQuotes() ) {
348             System.out.println( "OK." );
349             succeeded++;
350         }
351         else {
352             System.out.println( "failed." );
353             failed++;
354         }
355         System.out.print( "NHX parsing (MrBayes): " );
356         if ( Test.testNHXParsingMB() ) {
357             System.out.println( "OK." );
358             succeeded++;
359         }
360         else {
361             System.out.println( "failed." );
362             failed++;
363         }
364         System.out.print( "Nexus characters parsing: " );
365         if ( Test.testNexusCharactersParsing() ) {
366             System.out.println( "OK." );
367             succeeded++;
368         }
369         else {
370             System.out.println( "failed." );
371             failed++;
372         }
373         System.out.print( "Nexus tree parsing iterating: " );
374         if ( Test.testNexusTreeParsingIterating() ) {
375             System.out.println( "OK." );
376             succeeded++;
377         }
378         else {
379             System.out.println( "failed." );
380             failed++;
381         }
382         System.out.print( "Nexus tree parsing: " );
383         if ( Test.testNexusTreeParsing() ) {
384             System.out.println( "OK." );
385             succeeded++;
386         }
387         else {
388             System.out.println( "failed." );
389             failed++;
390         }
391         System.out.print( "Nexus tree parsing (translating): " );
392         if ( Test.testNexusTreeParsingTranslating() ) {
393             System.out.println( "OK." );
394             succeeded++;
395         }
396         else {
397             System.out.println( "failed." );
398             failed++;
399         }
400         System.out.print( "Nexus matrix parsing: " );
401         if ( Test.testNexusMatrixParsing() ) {
402             System.out.println( "OK." );
403             succeeded++;
404         }
405         else {
406             System.out.println( "failed." );
407             failed++;
408         }
409         System.out.print( "Basic phyloXML parsing: " );
410         if ( Test.testBasicPhyloXMLparsing() ) {
411             System.out.println( "OK." );
412             succeeded++;
413         }
414         else {
415             System.out.println( "failed." );
416             failed++;
417         }
418         System.out.print( "Basic phyloXML parsing (validating against schema): " );
419         if ( testBasicPhyloXMLparsingValidating() ) {
420             System.out.println( "OK." );
421             succeeded++;
422         }
423         else {
424             System.out.println( "failed." );
425             failed++;
426         }
427         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
428         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
429             System.out.println( "OK." );
430             succeeded++;
431         }
432         else {
433             System.out.println( "failed." );
434             failed++;
435         }
436         System.out.print( "phyloXML Distribution Element: " );
437         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
438             System.out.println( "OK." );
439             succeeded++;
440         }
441         else {
442             System.out.println( "failed." );
443             failed++;
444         }
445         System.out.print( "Tol XML parsing: " );
446         if ( Test.testBasicTolXMLparsing() ) {
447             System.out.println( "OK." );
448             succeeded++;
449         }
450         else {
451             System.out.println( "failed." );
452             failed++;
453         }
454         System.out.print( "Copying of node data: " );
455         if ( Test.testCopyOfNodeData() ) {
456             System.out.println( "OK." );
457             succeeded++;
458         }
459         else {
460             System.out.println( "failed." );
461             failed++;
462         }
463         System.out.print( "Basic tree methods: " );
464         if ( Test.testBasicTreeMethods() ) {
465             System.out.println( "OK." );
466             succeeded++;
467         }
468         else {
469             System.out.println( "failed." );
470             failed++;
471         }
472         System.out.print( "Tree methods: " );
473         if ( Test.testTreeMethods() ) {
474             System.out.println( "OK." );
475             succeeded++;
476         }
477         else {
478             System.out.println( "failed." );
479             failed++;
480         }
481         System.out.print( "Postorder Iterator: " );
482         if ( Test.testPostOrderIterator() ) {
483             System.out.println( "OK." );
484             succeeded++;
485         }
486         else {
487             System.out.println( "failed." );
488             failed++;
489         }
490         System.out.print( "Preorder Iterator: " );
491         if ( Test.testPreOrderIterator() ) {
492             System.out.println( "OK." );
493             succeeded++;
494         }
495         else {
496             System.out.println( "failed." );
497             failed++;
498         }
499         System.out.print( "Levelorder Iterator: " );
500         if ( Test.testLevelOrderIterator() ) {
501             System.out.println( "OK." );
502             succeeded++;
503         }
504         else {
505             System.out.println( "failed." );
506             failed++;
507         }
508         System.out.print( "Re-id methods: " );
509         if ( Test.testReIdMethods() ) {
510             System.out.println( "OK." );
511             succeeded++;
512         }
513         else {
514             System.out.println( "failed." );
515             failed++;
516         }
517         System.out.print( "Methods on last external nodes: " );
518         if ( Test.testLastExternalNodeMethods() ) {
519             System.out.println( "OK." );
520             succeeded++;
521         }
522         else {
523             System.out.println( "failed." );
524             failed++;
525         }
526         System.out.print( "Methods on external nodes: " );
527         if ( Test.testExternalNodeRelatedMethods() ) {
528             System.out.println( "OK." );
529             succeeded++;
530         }
531         else {
532             System.out.println( "failed." );
533             failed++;
534         }
535         System.out.print( "Deletion of external nodes: " );
536         if ( Test.testDeletionOfExternalNodes() ) {
537             System.out.println( "OK." );
538             succeeded++;
539         }
540         else {
541             System.out.println( "failed." );
542             failed++;
543         }
544         System.out.print( "Subtree deletion: " );
545         if ( Test.testSubtreeDeletion() ) {
546             System.out.println( "OK." );
547             succeeded++;
548         }
549         else {
550             System.out.println( "failed." );
551             failed++;
552         }
553         System.out.print( "Phylogeny branch: " );
554         if ( Test.testPhylogenyBranch() ) {
555             System.out.println( "OK." );
556             succeeded++;
557         }
558         else {
559             System.out.println( "failed." );
560             failed++;
561         }
562         System.out.print( "Rerooting: " );
563         if ( Test.testRerooting() ) {
564             System.out.println( "OK." );
565             succeeded++;
566         }
567         else {
568             System.out.println( "failed." );
569             failed++;
570         }
571         System.out.print( "Mipoint rooting: " );
572         if ( Test.testMidpointrooting() ) {
573             System.out.println( "OK." );
574             succeeded++;
575         }
576         else {
577             System.out.println( "failed." );
578             failed++;
579         }
580         System.out.print( "Node removal: " );
581         if ( Test.testNodeRemoval() ) {
582             System.out.println( "OK." );
583             succeeded++;
584         }
585         else {
586             System.out.println( "failed." );
587             failed++;
588         }
589         System.out.print( "Support count: " );
590         if ( Test.testSupportCount() ) {
591             System.out.println( "OK." );
592             succeeded++;
593         }
594         else {
595             System.out.println( "failed." );
596             failed++;
597         }
598         System.out.print( "Support transfer: " );
599         if ( Test.testSupportTransfer() ) {
600             System.out.println( "OK." );
601             succeeded++;
602         }
603         else {
604             System.out.println( "failed." );
605             failed++;
606         }
607         System.out.print( "Finding of LCA: " );
608         if ( Test.testGetLCA() ) {
609             System.out.println( "OK." );
610             succeeded++;
611         }
612         else {
613             System.out.println( "failed." );
614             failed++;
615         }
616         System.out.print( "Finding of LCA 2: " );
617         if ( Test.testGetLCA2() ) {
618             System.out.println( "OK." );
619             succeeded++;
620         }
621         else {
622             System.out.println( "failed." );
623             failed++;
624         }
625         System.out.print( "Calculation of distance between nodes: " );
626         if ( Test.testGetDistance() ) {
627             System.out.println( "OK." );
628             succeeded++;
629         }
630         else {
631             System.out.println( "failed." );
632             failed++;
633         }
634         System.out.print( "Descriptive statistics: " );
635         if ( Test.testDescriptiveStatistics() ) {
636             System.out.println( "OK." );
637             succeeded++;
638         }
639         else {
640             System.out.println( "failed." );
641             failed++;
642         }
643         System.out.print( "Data objects and methods: " );
644         if ( Test.testDataObjects() ) {
645             System.out.println( "OK." );
646             succeeded++;
647         }
648         else {
649             System.out.println( "failed." );
650             failed++;
651         }
652         System.out.print( "Properties map: " );
653         if ( Test.testPropertiesMap() ) {
654             System.out.println( "OK." );
655             succeeded++;
656         }
657         else {
658             System.out.println( "failed." );
659             failed++;
660         }
661         System.out.print( "SDIse: " );
662         if ( Test.testSDIse() ) {
663             System.out.println( "OK." );
664             succeeded++;
665         }
666         else {
667             System.out.println( "failed." );
668             failed++;
669         }
670         System.out.print( "SDIunrooted: " );
671         if ( Test.testSDIunrooted() ) {
672             System.out.println( "OK." );
673             succeeded++;
674         }
675         else {
676             System.out.println( "failed." );
677             failed++;
678         }
679         System.out.print( "GSDI: " );
680         if ( TestGSDI.test() ) {
681             System.out.println( "OK." );
682             succeeded++;
683         }
684         else {
685             System.out.println( "failed." );
686             failed++;
687         }
688         System.out.print( "RIO: " );
689         if ( TestRIO.test() ) {
690             System.out.println( "OK." );
691             succeeded++;
692         }
693         else {
694             System.out.println( "failed." );
695             failed++;
696         }
697         System.out.print( "Phylogeny reconstruction:" );
698         System.out.println();
699         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
700             System.out.println( "OK." );
701             succeeded++;
702         }
703         else {
704             System.out.println( "failed." );
705             failed++;
706         }
707         System.out.print( "Analysis of domain architectures: " );
708         System.out.println();
709         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
710             System.out.println( "OK." );
711             succeeded++;
712         }
713         else {
714             System.out.println( "failed." );
715             failed++;
716         }
717         System.out.print( "GO: " );
718         System.out.println();
719         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
720             System.out.println( "OK." );
721             succeeded++;
722         }
723         else {
724             System.out.println( "failed." );
725             failed++;
726         }
727         System.out.print( "Modeling tools: " );
728         if ( TestPccx.test() ) {
729             System.out.println( "OK." );
730             succeeded++;
731         }
732         else {
733             System.out.println( "failed." );
734             failed++;
735         }
736         System.out.print( "Split Matrix strict: " );
737         if ( Test.testSplitStrict() ) {
738             System.out.println( "OK." );
739             succeeded++;
740         }
741         else {
742             System.out.println( "failed." );
743             failed++;
744         }
745         System.out.print( "Split Matrix: " );
746         if ( Test.testSplit() ) {
747             System.out.println( "OK." );
748             succeeded++;
749         }
750         else {
751             System.out.println( "failed." );
752             failed++;
753         }
754         System.out.print( "Confidence Assessor: " );
755         if ( Test.testConfidenceAssessor() ) {
756             System.out.println( "OK." );
757             succeeded++;
758         }
759         else {
760             System.out.println( "failed." );
761             failed++;
762         }
763         System.out.print( "Basic table: " );
764         if ( Test.testBasicTable() ) {
765             System.out.println( "OK." );
766             succeeded++;
767         }
768         else {
769             System.out.println( "failed." );
770             failed++;
771         }
772         System.out.print( "General table: " );
773         if ( Test.testGeneralTable() ) {
774             System.out.println( "OK." );
775             succeeded++;
776         }
777         else {
778             System.out.println( "failed." );
779             failed++;
780         }
781         System.out.print( "Amino acid sequence: " );
782         if ( Test.testAminoAcidSequence() ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "General MSA parser: " );
791         if ( Test.testGeneralMsaParser() ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "Fasta parser for msa: " );
800         if ( Test.testFastaParser() ) {
801             System.out.println( "OK." );
802             succeeded++;
803         }
804         else {
805             System.out.println( "failed." );
806             failed++;
807         }
808         System.out.print( "Creation of balanced phylogeny: " );
809         if ( Test.testCreateBalancedPhylogeny() ) {
810             System.out.println( "OK." );
811             succeeded++;
812         }
813         else {
814             System.out.println( "failed." );
815             failed++;
816         }
817         System.out.print( "EMBL Entry Retrieval: " );
818         if ( Test.testEmblEntryRetrieval() ) {
819             System.out.println( "OK." );
820             succeeded++;
821         }
822         else {
823             System.out.println( "failed." );
824             failed++;
825         }
826         System.out.print( "Uniprot Entry Retrieval: " );
827         if ( Test.testUniprotEntryRetrieval() ) {
828             System.out.println( "OK." );
829             succeeded++;
830         }
831         else {
832             System.out.println( "failed." );
833             failed++;
834         }
835         System.out.print( "Uniprot Taxonomy Search: " );
836         if ( Test.testUniprotTaxonomySearch() ) {
837             System.out.println( "OK." );
838             succeeded++;
839         }
840         else {
841             System.out.println( "failed." );
842             failed++;
843         }
844         //----
845         String path = "";
846         final String os = ForesterUtil.OS_NAME.toLowerCase();
847         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
848             path = "/usr/local/bin/mafft";
849         }
850         else if ( os.indexOf( "win" ) >= 0 ) {
851             path = "C:\\Program Files\\mafft-win\\mafft.bat";
852         }
853         else {
854             path = "/home/czmasek/bin/mafft";
855         }
856         if ( !MsaInferrer.isInstalled( path ) ) {
857             path = "mafft";
858         }
859         if ( !MsaInferrer.isInstalled( path ) ) {
860             path = "/usr/local/bin/mafft";
861         }
862         if ( MsaInferrer.isInstalled( path ) ) {
863             System.out.print( "MAFFT (external program): " );
864             if ( Test.testMafft( path ) ) {
865                 System.out.println( "OK." );
866                 succeeded++;
867             }
868             else {
869                 System.out.println( "failed [will not count towards failed tests]" );
870             }
871         }
872         //----
873         System.out.print( "Next nodes with collapsed: " );
874         if ( Test.testNextNodeWithCollapsing() ) {
875             System.out.println( "OK." );
876             succeeded++;
877         }
878         else {
879             System.out.println( "failed." );
880             failed++;
881         }
882         System.out.print( "Simple MSA quality: " );
883         if ( Test.testMsaQualityMethod() ) {
884             System.out.println( "OK." );
885             succeeded++;
886         }
887         else {
888             System.out.println( "failed." );
889             failed++;
890         }
891         System.out.println();
892         final Runtime rt = java.lang.Runtime.getRuntime();
893         final long free_memory = rt.freeMemory() / 1000000;
894         final long total_memory = rt.totalMemory() / 1000000;
895         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
896                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
897         System.out.println();
898         System.out.println( "Successful tests: " + succeeded );
899         System.out.println( "Failed     tests: " + failed );
900         System.out.println();
901         if ( failed < 1 ) {
902             System.out.println( "OK." );
903         }
904         else {
905             System.out.println( "Not OK." );
906         }
907     }
908
909     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
910         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
911         return p;
912     }
913
914     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
915         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
916     }
917
918     private static boolean testAminoAcidSequence() {
919         try {
920             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
921             if ( aa1.getLength() != 13 ) {
922                 return false;
923             }
924             if ( aa1.getResidueAt( 0 ) != 'A' ) {
925                 return false;
926             }
927             if ( aa1.getResidueAt( 2 ) != 'K' ) {
928                 return false;
929             }
930             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
931                 return false;
932             }
933             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
934             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
935                 return false;
936             }
937             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
938             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
939                 return false;
940             }
941             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
942             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
943                 return false;
944             }
945         }
946         catch ( final Exception e ) {
947             e.printStackTrace();
948             return false;
949         }
950         return true;
951     }
952
953     private static boolean testBasicDomain() {
954         try {
955             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
956             if ( !pd.getDomainId().getId().equals( "id" ) ) {
957                 return false;
958             }
959             if ( pd.getNumber() != 1 ) {
960                 return false;
961             }
962             if ( pd.getTotalCount() != 4 ) {
963                 return false;
964             }
965             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
966                 return false;
967             }
968             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
969             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
970             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
971             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
972             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
973             if ( !a1.equals( a1 ) ) {
974                 return false;
975             }
976             if ( !a1.equals( a1_copy ) ) {
977                 return false;
978             }
979             if ( !a1.equals( a1_equal ) ) {
980                 return false;
981             }
982             if ( !a1.equals( a2 ) ) {
983                 return false;
984             }
985             if ( a1.equals( a3 ) ) {
986                 return false;
987             }
988             if ( a1.compareTo( a1 ) != 0 ) {
989                 return false;
990             }
991             if ( a1.compareTo( a1_copy ) != 0 ) {
992                 return false;
993             }
994             if ( a1.compareTo( a1_equal ) != 0 ) {
995                 return false;
996             }
997             if ( a1.compareTo( a2 ) != 0 ) {
998                 return false;
999             }
1000             if ( a1.compareTo( a3 ) != 0 ) {
1001                 return false;
1002             }
1003         }
1004         catch ( final Exception e ) {
1005             e.printStackTrace( System.out );
1006             return false;
1007         }
1008         return true;
1009     }
1010
1011     private static boolean testBasicNodeMethods() {
1012         try {
1013             if ( PhylogenyNode.getNodeCount() != 0 ) {
1014                 return false;
1015             }
1016             final PhylogenyNode n1 = new PhylogenyNode();
1017             final PhylogenyNode n2 = PhylogenyNode
1018                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1019             final PhylogenyNode n3 = PhylogenyNode
1020                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1021             final PhylogenyNode n4 = PhylogenyNode
1022                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1023             if ( n1.isHasAssignedEvent() ) {
1024                 return false;
1025             }
1026             if ( PhylogenyNode.getNodeCount() != 4 ) {
1027                 return false;
1028             }
1029             if ( n3.getIndicator() != 0 ) {
1030                 return false;
1031             }
1032             if ( n3.getNumberOfExternalNodes() != 1 ) {
1033                 return false;
1034             }
1035             if ( !n3.isExternal() ) {
1036                 return false;
1037             }
1038             if ( !n3.isRoot() ) {
1039                 return false;
1040             }
1041             if ( !n4.getName().equals( "n4" ) ) {
1042                 return false;
1043             }
1044         }
1045         catch ( final Exception e ) {
1046             e.printStackTrace( System.out );
1047             return false;
1048         }
1049         return true;
1050     }
1051
1052     private static boolean testBasicPhyloXMLparsing() {
1053         try {
1054             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1055             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1056             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1057                                                               xml_parser );
1058             if ( xml_parser.getErrorCount() > 0 ) {
1059                 System.out.println( xml_parser.getErrorMessages().toString() );
1060                 return false;
1061             }
1062             if ( phylogenies_0.length != 4 ) {
1063                 return false;
1064             }
1065             final Phylogeny t1 = phylogenies_0[ 0 ];
1066             final Phylogeny t2 = phylogenies_0[ 1 ];
1067             final Phylogeny t3 = phylogenies_0[ 2 ];
1068             final Phylogeny t4 = phylogenies_0[ 3 ];
1069             if ( t1.getNumberOfExternalNodes() != 1 ) {
1070                 return false;
1071             }
1072             if ( !t1.isRooted() ) {
1073                 return false;
1074             }
1075             if ( t1.isRerootable() ) {
1076                 return false;
1077             }
1078             if ( !t1.getType().equals( "gene_tree" ) ) {
1079                 return false;
1080             }
1081             if ( t2.getNumberOfExternalNodes() != 2 ) {
1082                 return false;
1083             }
1084             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1085                 return false;
1086             }
1087             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1088                 return false;
1089             }
1090             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1091                 return false;
1092             }
1093             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1094                 return false;
1095             }
1096             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1097                 return false;
1098             }
1099             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1100                 return false;
1101             }
1102             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1103                     .startsWith( "actgtgggggt" ) ) {
1104                 return false;
1105             }
1106             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1107                     .startsWith( "ctgtgatgcat" ) ) {
1108                 return false;
1109             }
1110             if ( t3.getNumberOfExternalNodes() != 4 ) {
1111                 return false;
1112             }
1113             if ( !t1.getName().equals( "t1" ) ) {
1114                 return false;
1115             }
1116             if ( !t2.getName().equals( "t2" ) ) {
1117                 return false;
1118             }
1119             if ( !t3.getName().equals( "t3" ) ) {
1120                 return false;
1121             }
1122             if ( !t4.getName().equals( "t4" ) ) {
1123                 return false;
1124             }
1125             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1126                 return false;
1127             }
1128             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1129                 return false;
1130             }
1131             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1132                 return false;
1133             }
1134             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1135                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1136                 return false;
1137             }
1138             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1139                 return false;
1140             }
1141             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1142                 return false;
1143             }
1144             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1145                 return false;
1146             }
1147             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1148                     .equals( "apoptosis" ) ) {
1149                 return false;
1150             }
1151             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1152                     .equals( "GO:0006915" ) ) {
1153                 return false;
1154             }
1155             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1156                     .equals( "UniProtKB" ) ) {
1157                 return false;
1158             }
1159             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1160                     .equals( "experimental" ) ) {
1161                 return false;
1162             }
1163             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1164                     .equals( "function" ) ) {
1165                 return false;
1166             }
1167             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1168                     .getValue() != 1 ) {
1169                 return false;
1170             }
1171             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1172                     .getType().equals( "ml" ) ) {
1173                 return false;
1174             }
1175             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1176                     .equals( "apoptosis" ) ) {
1177                 return false;
1178             }
1179             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1180                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1181                 return false;
1182             }
1183             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1184                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1185                 return false;
1186             }
1187             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1188                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1189                 return false;
1190             }
1191             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1192                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1193                 return false;
1194             }
1195             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1196                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1197                 return false;
1198             }
1199             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1200                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1201                 return false;
1202             }
1203             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1204                     .equals( "GO:0005829" ) ) {
1205                 return false;
1206             }
1207             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1208                     .equals( "intracellular organelle" ) ) {
1209                 return false;
1210             }
1211             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1212                 return false;
1213             }
1214             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1215                     .equals( "UniProt link" ) ) ) {
1216                 return false;
1217             }
1218             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1219                 return false;
1220             }
1221         }
1222         catch ( final Exception e ) {
1223             e.printStackTrace( System.out );
1224             return false;
1225         }
1226         return true;
1227     }
1228
1229     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1230         try {
1231             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1232             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1233             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1234                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1235             }
1236             else {
1237                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1238             }
1239             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1240                                                               xml_parser );
1241             if ( xml_parser.getErrorCount() > 0 ) {
1242                 System.out.println( xml_parser.getErrorMessages().toString() );
1243                 return false;
1244             }
1245             if ( phylogenies_0.length != 4 ) {
1246                 return false;
1247             }
1248             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1249             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1250             if ( phylogenies_t1.length != 1 ) {
1251                 return false;
1252             }
1253             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1254             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1255                 return false;
1256             }
1257             if ( !t1_rt.isRooted() ) {
1258                 return false;
1259             }
1260             if ( t1_rt.isRerootable() ) {
1261                 return false;
1262             }
1263             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1264                 return false;
1265             }
1266             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1267             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1268             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1269             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1270                 return false;
1271             }
1272             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1273                 return false;
1274             }
1275             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1276                 return false;
1277             }
1278             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1279                 return false;
1280             }
1281             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1282                     .startsWith( "actgtgggggt" ) ) {
1283                 return false;
1284             }
1285             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1286                     .startsWith( "ctgtgatgcat" ) ) {
1287                 return false;
1288             }
1289             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1290             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1291             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1292             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1293             if ( phylogenies_1.length != 1 ) {
1294                 return false;
1295             }
1296             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1297             if ( !t3_rt.getName().equals( "t3" ) ) {
1298                 return false;
1299             }
1300             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1301                 return false;
1302             }
1303             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1304                 return false;
1305             }
1306             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1307                 return false;
1308             }
1309             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1310                 return false;
1311             }
1312             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1313                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1314                 return false;
1315             }
1316             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1317                 return false;
1318             }
1319             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1320                 return false;
1321             }
1322             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1323                     .equals( "UniProtKB" ) ) {
1324                 return false;
1325             }
1326             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1327                     .equals( "apoptosis" ) ) {
1328                 return false;
1329             }
1330             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1331                     .equals( "GO:0006915" ) ) {
1332                 return false;
1333             }
1334             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1335                     .equals( "UniProtKB" ) ) {
1336                 return false;
1337             }
1338             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1339                     .equals( "experimental" ) ) {
1340                 return false;
1341             }
1342             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1343                     .equals( "function" ) ) {
1344                 return false;
1345             }
1346             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1347                     .getValue() != 1 ) {
1348                 return false;
1349             }
1350             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1351                     .getType().equals( "ml" ) ) {
1352                 return false;
1353             }
1354             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1355                     .equals( "apoptosis" ) ) {
1356                 return false;
1357             }
1358             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1359                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1360                 return false;
1361             }
1362             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1363                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1364                 return false;
1365             }
1366             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1367                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1368                 return false;
1369             }
1370             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1371                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1372                 return false;
1373             }
1374             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1375                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1376                 return false;
1377             }
1378             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1379                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1380                 return false;
1381             }
1382             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1383                     .equals( "GO:0005829" ) ) {
1384                 return false;
1385             }
1386             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1387                     .equals( "intracellular organelle" ) ) {
1388                 return false;
1389             }
1390             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1391                 return false;
1392             }
1393             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1394                     .equals( "UniProt link" ) ) ) {
1395                 return false;
1396             }
1397             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1398                 return false;
1399             }
1400             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1401                 return false;
1402             }
1403             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1404                     .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." ) ) ) {
1405                 return false;
1406             }
1407             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1408                 return false;
1409             }
1410             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1411                 return false;
1412             }
1413             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1414                 return false;
1415             }
1416             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1417                 return false;
1418             }
1419             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1420                     .equals( "ncbi" ) ) {
1421                 return false;
1422             }
1423             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1424                 return false;
1425             }
1426             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1427                     .getName().equals( "B" ) ) {
1428                 return false;
1429             }
1430             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1431                     .getFrom() != 21 ) {
1432                 return false;
1433             }
1434             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1435                 return false;
1436             }
1437             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1438                     .getLength() != 24 ) {
1439                 return false;
1440             }
1441             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1442                     .getConfidence() != 2144 ) {
1443                 return false;
1444             }
1445             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1446                     .equals( "pfam" ) ) {
1447                 return false;
1448             }
1449             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1450                 return false;
1451             }
1452             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1453                 return false;
1454             }
1455             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1456                 return false;
1457             }
1458             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1459                 return false;
1460             }
1461             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1462             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1463                 return false;
1464             }
1465             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1466                 return false;
1467             }
1468             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1469                 return false;
1470             }
1471             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1472                 return false;
1473             }
1474             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1475                 return false;
1476             }
1477             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1478                 return false;
1479             }
1480             if ( taxbb.getSynonyms().size() != 2 ) {
1481                 return false;
1482             }
1483             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1484                 return false;
1485             }
1486             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1487                 return false;
1488             }
1489             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1490                 return false;
1491             }
1492             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1493                 return false;
1494             }
1495             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1496                 return false;
1497             }
1498             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1499                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1500                 ;
1501                 return false;
1502             }
1503             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1504                 return false;
1505             }
1506             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1507                 return false;
1508             }
1509             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1510                 return false;
1511             }
1512             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1513                 return false;
1514             }
1515             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1516                 return false;
1517             }
1518             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1519                 return false;
1520             }
1521             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1522                 return false;
1523             }
1524             //
1525             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1526                 return false;
1527             }
1528             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1529                     .equalsIgnoreCase( "435" ) ) {
1530                 return false;
1531             }
1532             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1533                 return false;
1534             }
1535             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1536                     .equalsIgnoreCase( "443.7" ) ) {
1537                 return false;
1538             }
1539             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1540                 return false;
1541             }
1542             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1543                 return false;
1544             }
1545             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1546                     .equalsIgnoreCase( "433" ) ) {
1547                 return false;
1548             }
1549         }
1550         catch ( final Exception e ) {
1551             e.printStackTrace( System.out );
1552             return false;
1553         }
1554         return true;
1555     }
1556
1557     private static boolean testBasicPhyloXMLparsingValidating() {
1558         try {
1559             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1560             PhyloXmlParser xml_parser = null;
1561             try {
1562                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1563             }
1564             catch ( final Exception e ) {
1565                 // Do nothing -- means were not running from jar.
1566             }
1567             if ( xml_parser == null ) {
1568                 xml_parser = new PhyloXmlParser();
1569                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1570                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1571                 }
1572                 else {
1573                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1574                 }
1575             }
1576             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1577                                                               xml_parser );
1578             if ( xml_parser.getErrorCount() > 0 ) {
1579                 System.out.println( xml_parser.getErrorMessages().toString() );
1580                 return false;
1581             }
1582             if ( phylogenies_0.length != 4 ) {
1583                 return false;
1584             }
1585             final Phylogeny t1 = phylogenies_0[ 0 ];
1586             final Phylogeny t2 = phylogenies_0[ 1 ];
1587             final Phylogeny t3 = phylogenies_0[ 2 ];
1588             final Phylogeny t4 = phylogenies_0[ 3 ];
1589             if ( !t1.getName().equals( "t1" ) ) {
1590                 return false;
1591             }
1592             if ( !t2.getName().equals( "t2" ) ) {
1593                 return false;
1594             }
1595             if ( !t3.getName().equals( "t3" ) ) {
1596                 return false;
1597             }
1598             if ( !t4.getName().equals( "t4" ) ) {
1599                 return false;
1600             }
1601             if ( t1.getNumberOfExternalNodes() != 1 ) {
1602                 return false;
1603             }
1604             if ( t2.getNumberOfExternalNodes() != 2 ) {
1605                 return false;
1606             }
1607             if ( t3.getNumberOfExternalNodes() != 4 ) {
1608                 return false;
1609             }
1610             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1611             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1612             if ( xml_parser.getErrorCount() > 0 ) {
1613                 System.out.println( "errors:" );
1614                 System.out.println( xml_parser.getErrorMessages().toString() );
1615                 return false;
1616             }
1617             if ( phylogenies_1.length != 4 ) {
1618                 return false;
1619             }
1620             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1621                                                               xml_parser );
1622             if ( xml_parser.getErrorCount() > 0 ) {
1623                 System.out.println( "errors:" );
1624                 System.out.println( xml_parser.getErrorMessages().toString() );
1625                 return false;
1626             }
1627             if ( phylogenies_2.length != 1 ) {
1628                 return false;
1629             }
1630             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1631                 return false;
1632             }
1633             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1634                                                               xml_parser );
1635             if ( xml_parser.getErrorCount() > 0 ) {
1636                 System.out.println( xml_parser.getErrorMessages().toString() );
1637                 return false;
1638             }
1639             if ( phylogenies_3.length != 2 ) {
1640                 return false;
1641             }
1642             final Phylogeny a = phylogenies_3[ 0 ];
1643             if ( !a.getName().equals( "tree 4" ) ) {
1644                 return false;
1645             }
1646             if ( a.getNumberOfExternalNodes() != 3 ) {
1647                 return false;
1648             }
1649             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1650                 return false;
1651             }
1652             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1653                 return false;
1654             }
1655             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1656                                                               xml_parser );
1657             if ( xml_parser.getErrorCount() > 0 ) {
1658                 System.out.println( xml_parser.getErrorMessages().toString() );
1659                 return false;
1660             }
1661             if ( phylogenies_4.length != 1 ) {
1662                 return false;
1663             }
1664             final Phylogeny s = phylogenies_4[ 0 ];
1665             if ( s.getNumberOfExternalNodes() != 6 ) {
1666                 return false;
1667             }
1668             s.getNode( "first" );
1669             s.getNode( "<>" );
1670             s.getNode( "\"<a'b&c'd\">\"" );
1671             s.getNode( "'''\"" );
1672             s.getNode( "\"\"\"" );
1673             s.getNode( "dick & doof" );
1674         }
1675         catch ( final Exception e ) {
1676             e.printStackTrace( System.out );
1677             return false;
1678         }
1679         return true;
1680     }
1681
1682     private static boolean testBasicProtein() {
1683         try {
1684             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
1685             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1686             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1687             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1688             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1689             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1690             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1691             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1692             p0.addProteinDomain( y );
1693             p0.addProteinDomain( e );
1694             p0.addProteinDomain( b );
1695             p0.addProteinDomain( c );
1696             p0.addProteinDomain( d );
1697             p0.addProteinDomain( a );
1698             p0.addProteinDomain( x );
1699             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
1700                 return false;
1701             }
1702             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
1703                 return false;
1704             }
1705             //
1706             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
1707             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1708             aa0.addProteinDomain( a1 );
1709             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
1710                 return false;
1711             }
1712             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
1713                 return false;
1714             }
1715             //
1716             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
1717             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1718             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1719             aa1.addProteinDomain( a11 );
1720             aa1.addProteinDomain( a12 );
1721             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
1722                 return false;
1723             }
1724             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
1725                 return false;
1726             }
1727             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1728             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
1729                 return false;
1730             }
1731             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1732                 return false;
1733             }
1734             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
1735                 return false;
1736             }
1737             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1738             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
1739                 return false;
1740             }
1741             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1742                 return false;
1743             }
1744             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
1745                 return false;
1746             }
1747             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
1748                 return false;
1749             }
1750             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1751             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
1752                 return false;
1753             }
1754             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
1755                 return false;
1756             }
1757             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
1758                 return false;
1759             }
1760             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
1761                 return false;
1762             }
1763             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1764             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
1765                 return false;
1766             }
1767             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
1768                 return false;
1769             }
1770             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
1771                 return false;
1772             }
1773             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
1774                 return false;
1775             }
1776             //
1777             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
1778             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1779             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1780             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1781             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1782             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1783             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
1784             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
1785             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
1786             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
1787             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
1788             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1789             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1790             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
1791             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
1792             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
1793             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
1794             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
1795             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
1796             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
1797             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
1798             p00.addProteinDomain( y0 );
1799             p00.addProteinDomain( e0 );
1800             p00.addProteinDomain( b0 );
1801             p00.addProteinDomain( c0 );
1802             p00.addProteinDomain( d0 );
1803             p00.addProteinDomain( a0 );
1804             p00.addProteinDomain( x0 );
1805             p00.addProteinDomain( y1 );
1806             p00.addProteinDomain( y2 );
1807             p00.addProteinDomain( y3 );
1808             p00.addProteinDomain( e1 );
1809             p00.addProteinDomain( e2 );
1810             p00.addProteinDomain( e3 );
1811             p00.addProteinDomain( e4 );
1812             p00.addProteinDomain( e5 );
1813             p00.addProteinDomain( z0 );
1814             p00.addProteinDomain( z1 );
1815             p00.addProteinDomain( z2 );
1816             p00.addProteinDomain( zz0 );
1817             p00.addProteinDomain( zz1 );
1818             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
1819                 return false;
1820             }
1821             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
1822                 return false;
1823             }
1824             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1825                 return false;
1826             }
1827             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1828                 return false;
1829             }
1830             if ( !p00.toDomainArchitectureString( "~", 7, "" ).equals( "a~b~c~d~e~e~e~e~e~e~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1831                 return false;
1832             }
1833             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
1834             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1835             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
1836             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
1837             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
1838             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
1839             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
1840             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
1841             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
1842             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
1843             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
1844             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
1845             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
1846             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
1847             p.addProteinDomain( B15 );
1848             p.addProteinDomain( C50 );
1849             p.addProteinDomain( A60 );
1850             p.addProteinDomain( A30 );
1851             p.addProteinDomain( C70 );
1852             p.addProteinDomain( B35 );
1853             p.addProteinDomain( B40 );
1854             p.addProteinDomain( A0 );
1855             p.addProteinDomain( A10 );
1856             p.addProteinDomain( A20 );
1857             p.addProteinDomain( B25 );
1858             p.addProteinDomain( D80 );
1859             List<DomainId> domains_ids = new ArrayList<DomainId>();
1860             domains_ids.add( new DomainId( "A" ) );
1861             domains_ids.add( new DomainId( "B" ) );
1862             domains_ids.add( new DomainId( "C" ) );
1863             if ( !p.contains( domains_ids, false ) ) {
1864                 return false;
1865             }
1866             if ( !p.contains( domains_ids, true ) ) {
1867                 return false;
1868             }
1869             domains_ids.add( new DomainId( "X" ) );
1870             if ( p.contains( domains_ids, false ) ) {
1871                 return false;
1872             }
1873             if ( p.contains( domains_ids, true ) ) {
1874                 return false;
1875             }
1876             domains_ids = new ArrayList<DomainId>();
1877             domains_ids.add( new DomainId( "A" ) );
1878             domains_ids.add( new DomainId( "C" ) );
1879             domains_ids.add( new DomainId( "D" ) );
1880             if ( !p.contains( domains_ids, false ) ) {
1881                 return false;
1882             }
1883             if ( !p.contains( domains_ids, true ) ) {
1884                 return false;
1885             }
1886             domains_ids = new ArrayList<DomainId>();
1887             domains_ids.add( new DomainId( "A" ) );
1888             domains_ids.add( new DomainId( "D" ) );
1889             domains_ids.add( new DomainId( "C" ) );
1890             if ( !p.contains( domains_ids, false ) ) {
1891                 return false;
1892             }
1893             if ( p.contains( domains_ids, true ) ) {
1894                 return false;
1895             }
1896             domains_ids = new ArrayList<DomainId>();
1897             domains_ids.add( new DomainId( "A" ) );
1898             domains_ids.add( new DomainId( "A" ) );
1899             domains_ids.add( new DomainId( "B" ) );
1900             if ( !p.contains( domains_ids, false ) ) {
1901                 return false;
1902             }
1903             if ( !p.contains( domains_ids, true ) ) {
1904                 return false;
1905             }
1906             domains_ids = new ArrayList<DomainId>();
1907             domains_ids.add( new DomainId( "A" ) );
1908             domains_ids.add( new DomainId( "A" ) );
1909             domains_ids.add( new DomainId( "A" ) );
1910             domains_ids.add( new DomainId( "B" ) );
1911             domains_ids.add( new DomainId( "B" ) );
1912             if ( !p.contains( domains_ids, false ) ) {
1913                 return false;
1914             }
1915             if ( !p.contains( domains_ids, true ) ) {
1916                 return false;
1917             }
1918             domains_ids = new ArrayList<DomainId>();
1919             domains_ids.add( new DomainId( "A" ) );
1920             domains_ids.add( new DomainId( "A" ) );
1921             domains_ids.add( new DomainId( "A" ) );
1922             domains_ids.add( new DomainId( "A" ) );
1923             domains_ids.add( new DomainId( "B" ) );
1924             domains_ids.add( new DomainId( "B" ) );
1925             if ( !p.contains( domains_ids, false ) ) {
1926                 return false;
1927             }
1928             if ( !p.contains( domains_ids, true ) ) {
1929                 return false;
1930             }
1931             domains_ids = new ArrayList<DomainId>();
1932             domains_ids.add( new DomainId( "A" ) );
1933             domains_ids.add( new DomainId( "A" ) );
1934             domains_ids.add( new DomainId( "A" ) );
1935             domains_ids.add( new DomainId( "A" ) );
1936             domains_ids.add( new DomainId( "A" ) );
1937             domains_ids.add( new DomainId( "B" ) );
1938             domains_ids.add( new DomainId( "B" ) );
1939             if ( !p.contains( domains_ids, false ) ) {
1940                 return false;
1941             }
1942             if ( p.contains( domains_ids, true ) ) {
1943                 return false;
1944             }
1945             domains_ids = new ArrayList<DomainId>();
1946             domains_ids.add( new DomainId( "A" ) );
1947             domains_ids.add( new DomainId( "A" ) );
1948             domains_ids.add( new DomainId( "B" ) );
1949             domains_ids.add( new DomainId( "A" ) );
1950             domains_ids.add( new DomainId( "B" ) );
1951             domains_ids.add( new DomainId( "A" ) );
1952             domains_ids.add( new DomainId( "B" ) );
1953             domains_ids.add( new DomainId( "B" ) );
1954             domains_ids.add( new DomainId( "C" ) );
1955             domains_ids.add( new DomainId( "A" ) );
1956             domains_ids.add( new DomainId( "C" ) );
1957             domains_ids.add( new DomainId( "D" ) );
1958             if ( !p.contains( domains_ids, false ) ) {
1959                 return false;
1960             }
1961             if ( !p.contains( domains_ids, true ) ) {
1962                 return false;
1963             }
1964             domains_ids = new ArrayList<DomainId>();
1965             domains_ids.add( new DomainId( "A" ) );
1966             domains_ids.add( new DomainId( "B" ) );
1967             domains_ids.add( new DomainId( "A" ) );
1968             domains_ids.add( new DomainId( "B" ) );
1969             domains_ids.add( new DomainId( "A" ) );
1970             domains_ids.add( new DomainId( "B" ) );
1971             domains_ids.add( new DomainId( "B" ) );
1972             domains_ids.add( new DomainId( "A" ) );
1973             domains_ids.add( new DomainId( "C" ) );
1974             domains_ids.add( new DomainId( "D" ) );
1975             if ( !p.contains( domains_ids, false ) ) {
1976                 return false;
1977             }
1978             if ( !p.contains( domains_ids, true ) ) {
1979                 return false;
1980             }
1981             domains_ids = new ArrayList<DomainId>();
1982             domains_ids.add( new DomainId( "A" ) );
1983             domains_ids.add( new DomainId( "A" ) );
1984             domains_ids.add( new DomainId( "B" ) );
1985             domains_ids.add( new DomainId( "A" ) );
1986             domains_ids.add( new DomainId( "B" ) );
1987             domains_ids.add( new DomainId( "A" ) );
1988             domains_ids.add( new DomainId( "B" ) );
1989             domains_ids.add( new DomainId( "B" ) );
1990             domains_ids.add( new DomainId( "C" ) );
1991             domains_ids.add( new DomainId( "C" ) );
1992             domains_ids.add( new DomainId( "A" ) );
1993             domains_ids.add( new DomainId( "C" ) );
1994             domains_ids.add( new DomainId( "D" ) );
1995             if ( !p.contains( domains_ids, false ) ) {
1996                 return false;
1997             }
1998             if ( p.contains( domains_ids, true ) ) {
1999                 return false;
2000             }
2001             domains_ids = new ArrayList<DomainId>();
2002             domains_ids.add( new DomainId( "A" ) );
2003             domains_ids.add( new DomainId( "A" ) );
2004             domains_ids.add( new DomainId( "A" ) );
2005             domains_ids.add( new DomainId( "B" ) );
2006             domains_ids.add( new DomainId( "A" ) );
2007             domains_ids.add( new DomainId( "B" ) );
2008             domains_ids.add( new DomainId( "A" ) );
2009             domains_ids.add( new DomainId( "B" ) );
2010             domains_ids.add( new DomainId( "B" ) );
2011             domains_ids.add( new DomainId( "C" ) );
2012             domains_ids.add( new DomainId( "A" ) );
2013             domains_ids.add( new DomainId( "C" ) );
2014             domains_ids.add( new DomainId( "D" ) );
2015             if ( !p.contains( domains_ids, false ) ) {
2016                 return false;
2017             }
2018             if ( p.contains( domains_ids, true ) ) {
2019                 return false;
2020             }
2021             domains_ids = new ArrayList<DomainId>();
2022             domains_ids.add( new DomainId( "A" ) );
2023             domains_ids.add( new DomainId( "A" ) );
2024             domains_ids.add( new DomainId( "B" ) );
2025             domains_ids.add( new DomainId( "A" ) );
2026             domains_ids.add( new DomainId( "B" ) );
2027             domains_ids.add( new DomainId( "A" ) );
2028             domains_ids.add( new DomainId( "B" ) );
2029             domains_ids.add( new DomainId( "B" ) );
2030             domains_ids.add( new DomainId( "A" ) );
2031             domains_ids.add( new DomainId( "D" ) );
2032             if ( !p.contains( domains_ids, false ) ) {
2033                 return false;
2034             }
2035             if ( !p.contains( domains_ids, true ) ) {
2036                 return false;
2037             }
2038             domains_ids = new ArrayList<DomainId>();
2039             domains_ids.add( new DomainId( "A" ) );
2040             domains_ids.add( new DomainId( "A" ) );
2041             domains_ids.add( new DomainId( "B" ) );
2042             domains_ids.add( new DomainId( "A" ) );
2043             domains_ids.add( new DomainId( "B" ) );
2044             domains_ids.add( new DomainId( "A" ) );
2045             domains_ids.add( new DomainId( "B" ) );
2046             domains_ids.add( new DomainId( "B" ) );
2047             domains_ids.add( new DomainId( "C" ) );
2048             domains_ids.add( new DomainId( "A" ) );
2049             domains_ids.add( new DomainId( "C" ) );
2050             domains_ids.add( new DomainId( "D" ) );
2051             domains_ids.add( new DomainId( "X" ) );
2052             if ( p.contains( domains_ids, false ) ) {
2053                 return false;
2054             }
2055             if ( p.contains( domains_ids, true ) ) {
2056                 return false;
2057             }
2058             domains_ids = new ArrayList<DomainId>();
2059             domains_ids.add( new DomainId( "X" ) );
2060             domains_ids.add( new DomainId( "A" ) );
2061             domains_ids.add( new DomainId( "A" ) );
2062             domains_ids.add( new DomainId( "B" ) );
2063             domains_ids.add( new DomainId( "A" ) );
2064             domains_ids.add( new DomainId( "B" ) );
2065             domains_ids.add( new DomainId( "A" ) );
2066             domains_ids.add( new DomainId( "B" ) );
2067             domains_ids.add( new DomainId( "B" ) );
2068             domains_ids.add( new DomainId( "C" ) );
2069             domains_ids.add( new DomainId( "A" ) );
2070             domains_ids.add( new DomainId( "C" ) );
2071             domains_ids.add( new DomainId( "D" ) );
2072             if ( p.contains( domains_ids, false ) ) {
2073                 return false;
2074             }
2075             if ( p.contains( domains_ids, true ) ) {
2076                 return false;
2077             }
2078             domains_ids = new ArrayList<DomainId>();
2079             domains_ids.add( new DomainId( "A" ) );
2080             domains_ids.add( new DomainId( "A" ) );
2081             domains_ids.add( new DomainId( "B" ) );
2082             domains_ids.add( new DomainId( "A" ) );
2083             domains_ids.add( new DomainId( "B" ) );
2084             domains_ids.add( new DomainId( "B" ) );
2085             domains_ids.add( new DomainId( "A" ) );
2086             domains_ids.add( new DomainId( "B" ) );
2087             domains_ids.add( new DomainId( "C" ) );
2088             domains_ids.add( new DomainId( "A" ) );
2089             domains_ids.add( new DomainId( "C" ) );
2090             domains_ids.add( new DomainId( "D" ) );
2091             if ( !p.contains( domains_ids, false ) ) {
2092                 return false;
2093             }
2094             if ( p.contains( domains_ids, true ) ) {
2095                 return false;
2096             }
2097         }
2098         catch ( final Exception e ) {
2099             e.printStackTrace( System.out );
2100             return false;
2101         }
2102         return true;
2103     }
2104
2105     private static boolean testBasicTable() {
2106         try {
2107             final BasicTable<String> t0 = new BasicTable<String>();
2108             if ( t0.getNumberOfColumns() != 0 ) {
2109                 return false;
2110             }
2111             if ( t0.getNumberOfRows() != 0 ) {
2112                 return false;
2113             }
2114             t0.setValue( 3, 2, "23" );
2115             t0.setValue( 10, 1, "error" );
2116             t0.setValue( 10, 1, "110" );
2117             t0.setValue( 9, 1, "19" );
2118             t0.setValue( 1, 10, "101" );
2119             t0.setValue( 10, 10, "1010" );
2120             t0.setValue( 100, 10, "10100" );
2121             t0.setValue( 0, 0, "00" );
2122             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2123                 return false;
2124             }
2125             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2126                 return false;
2127             }
2128             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2129                 return false;
2130             }
2131             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2132                 return false;
2133             }
2134             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2135                 return false;
2136             }
2137             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2138                 return false;
2139             }
2140             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2141                 return false;
2142             }
2143             if ( t0.getNumberOfColumns() != 101 ) {
2144                 return false;
2145             }
2146             if ( t0.getNumberOfRows() != 11 ) {
2147                 return false;
2148             }
2149             if ( t0.getValueAsString( 49, 4 ) != null ) {
2150                 return false;
2151             }
2152             final String l = ForesterUtil.getLineSeparator();
2153             final StringBuffer source = new StringBuffer();
2154             source.append( "" + l );
2155             source.append( "# 1 1 1 1 1 1 1 1" + l );
2156             source.append( " 00 01 02 03" + l );
2157             source.append( "   10 11 12 13  " + l );
2158             source.append( "20 21 22 23 " + l );
2159             source.append( "    30  31    32 33" + l );
2160             source.append( "40 41 42 43" + l );
2161             source.append( "  # 1 1 1 1 1 " + l );
2162             source.append( "50 51 52 53 54" + l );
2163             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2164             if ( t1.getNumberOfColumns() != 5 ) {
2165                 return false;
2166             }
2167             if ( t1.getNumberOfRows() != 6 ) {
2168                 return false;
2169             }
2170             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2171                 return false;
2172             }
2173             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2174                 return false;
2175             }
2176             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2177                 return false;
2178             }
2179             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2180                 return false;
2181             }
2182             final StringBuffer source1 = new StringBuffer();
2183             source1.append( "" + l );
2184             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2185             source1.append( " 00; 01 ;02;03" + l );
2186             source1.append( "   10; 11; 12; 13  " + l );
2187             source1.append( "20; 21; 22; 23 " + l );
2188             source1.append( "    30;  31;    32; 33" + l );
2189             source1.append( "40;41;42;43" + l );
2190             source1.append( "  # 1 1 1 1 1 " + l );
2191             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2192             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2193             if ( t2.getNumberOfColumns() != 5 ) {
2194                 return false;
2195             }
2196             if ( t2.getNumberOfRows() != 6 ) {
2197                 return false;
2198             }
2199             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2200                 return false;
2201             }
2202             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2203                 return false;
2204             }
2205             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2206                 return false;
2207             }
2208             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2209                 return false;
2210             }
2211             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2212                 return false;
2213             }
2214             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2215                 return false;
2216             }
2217             final StringBuffer source2 = new StringBuffer();
2218             source2.append( "" + l );
2219             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2220             source2.append( " 00; 01 ;02;03" + l );
2221             source2.append( "   10; 11; 12; 13  " + l );
2222             source2.append( "20; 21; 22; 23 " + l );
2223             source2.append( "                     " + l );
2224             source2.append( "    30;  31;    32; 33" + l );
2225             source2.append( "40;41;42;43" + l );
2226             source2.append( "  comment: 1 1 1 1 1 " + l );
2227             source2.append( ";;;50  ;   52; 53;;54   " + l );
2228             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2229                                                                         ';',
2230                                                                         false,
2231                                                                         false,
2232                                                                         "comment:",
2233                                                                         false );
2234             if ( tl.size() != 2 ) {
2235                 return false;
2236             }
2237             final BasicTable<String> t3 = tl.get( 0 );
2238             final BasicTable<String> t4 = tl.get( 1 );
2239             if ( t3.getNumberOfColumns() != 4 ) {
2240                 return false;
2241             }
2242             if ( t3.getNumberOfRows() != 3 ) {
2243                 return false;
2244             }
2245             if ( t4.getNumberOfColumns() != 4 ) {
2246                 return false;
2247             }
2248             if ( t4.getNumberOfRows() != 3 ) {
2249                 return false;
2250             }
2251             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2252                 return false;
2253             }
2254             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2255                 return false;
2256             }
2257         }
2258         catch ( final Exception e ) {
2259             e.printStackTrace( System.out );
2260             return false;
2261         }
2262         return true;
2263     }
2264
2265     private static boolean testBasicTolXMLparsing() {
2266         try {
2267             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2268             final TolParser parser = new TolParser();
2269             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2270             if ( parser.getErrorCount() > 0 ) {
2271                 System.out.println( parser.getErrorMessages().toString() );
2272                 return false;
2273             }
2274             if ( phylogenies_0.length != 1 ) {
2275                 return false;
2276             }
2277             final Phylogeny t1 = phylogenies_0[ 0 ];
2278             if ( t1.getNumberOfExternalNodes() != 5 ) {
2279                 return false;
2280             }
2281             if ( !t1.isRooted() ) {
2282                 return false;
2283             }
2284             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2285                 return false;
2286             }
2287             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2288                 return false;
2289             }
2290             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2291                 return false;
2292             }
2293             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2294                 return false;
2295             }
2296             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2297             if ( parser.getErrorCount() > 0 ) {
2298                 System.out.println( parser.getErrorMessages().toString() );
2299                 return false;
2300             }
2301             if ( phylogenies_1.length != 1 ) {
2302                 return false;
2303             }
2304             final Phylogeny t2 = phylogenies_1[ 0 ];
2305             if ( t2.getNumberOfExternalNodes() != 664 ) {
2306                 return false;
2307             }
2308             if ( !t2.isRooted() ) {
2309                 return false;
2310             }
2311             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2312                 return false;
2313             }
2314             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2315                 return false;
2316             }
2317             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2318                 return false;
2319             }
2320             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2321                 return false;
2322             }
2323             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2324                 return false;
2325             }
2326             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2327                     .equals( "Aquifex" ) ) {
2328                 return false;
2329             }
2330             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2331             if ( parser.getErrorCount() > 0 ) {
2332                 System.out.println( parser.getErrorMessages().toString() );
2333                 return false;
2334             }
2335             if ( phylogenies_2.length != 1 ) {
2336                 return false;
2337             }
2338             final Phylogeny t3 = phylogenies_2[ 0 ];
2339             if ( t3.getNumberOfExternalNodes() != 184 ) {
2340                 return false;
2341             }
2342             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2343                 return false;
2344             }
2345             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2346                 return false;
2347             }
2348             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2349                 return false;
2350             }
2351             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2352             if ( parser.getErrorCount() > 0 ) {
2353                 System.out.println( parser.getErrorMessages().toString() );
2354                 return false;
2355             }
2356             if ( phylogenies_3.length != 1 ) {
2357                 return false;
2358             }
2359             final Phylogeny t4 = phylogenies_3[ 0 ];
2360             if ( t4.getNumberOfExternalNodes() != 1 ) {
2361                 return false;
2362             }
2363             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2364                 return false;
2365             }
2366             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2367                 return false;
2368             }
2369             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2370                 return false;
2371             }
2372             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2373             if ( parser.getErrorCount() > 0 ) {
2374                 System.out.println( parser.getErrorMessages().toString() );
2375                 return false;
2376             }
2377             if ( phylogenies_4.length != 1 ) {
2378                 return false;
2379             }
2380             final Phylogeny t5 = phylogenies_4[ 0 ];
2381             if ( t5.getNumberOfExternalNodes() != 13 ) {
2382                 return false;
2383             }
2384             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2385                 return false;
2386             }
2387             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2388                 return false;
2389             }
2390             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2391                 return false;
2392             }
2393         }
2394         catch ( final Exception e ) {
2395             e.printStackTrace( System.out );
2396             return false;
2397         }
2398         return true;
2399     }
2400
2401     private static boolean testBasicTreeMethods() {
2402         try {
2403             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2404             final Phylogeny t1 = factory.create();
2405             if ( !t1.isEmpty() ) {
2406                 return false;
2407             }
2408             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2409             if ( t2.getNumberOfExternalNodes() != 4 ) {
2410                 return false;
2411             }
2412             if ( t2.getHeight() != 8.5 ) {
2413                 return false;
2414             }
2415             if ( !t2.isCompletelyBinary() ) {
2416                 return false;
2417             }
2418             if ( t2.isEmpty() ) {
2419                 return false;
2420             }
2421             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2422             if ( t3.getNumberOfExternalNodes() != 5 ) {
2423                 return false;
2424             }
2425             if ( t3.getHeight() != 11 ) {
2426                 return false;
2427             }
2428             if ( t3.isCompletelyBinary() ) {
2429                 return false;
2430             }
2431             final PhylogenyNode n = t3.getNode( "ABC" );
2432             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 ];
2433             if ( t4.getNumberOfExternalNodes() != 9 ) {
2434                 return false;
2435             }
2436             if ( t4.getHeight() != 11 ) {
2437                 return false;
2438             }
2439             if ( t4.isCompletelyBinary() ) {
2440                 return false;
2441             }
2442             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)" );
2443             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2444             if ( t5.getNumberOfExternalNodes() != 8 ) {
2445                 return false;
2446             }
2447             if ( t5.getHeight() != 15 ) {
2448                 return false;
2449             }
2450             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)" );
2451             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2452             if ( t6.getHeight() != 15 ) {
2453                 return false;
2454             }
2455             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)" );
2456             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2457             if ( t7.getHeight() != 15 ) {
2458                 return false;
2459             }
2460             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)" );
2461             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2462             if ( t8.getNumberOfExternalNodes() != 10 ) {
2463                 return false;
2464             }
2465             if ( t8.getHeight() != 15 ) {
2466                 return false;
2467             }
2468             final char[] a9 = new char[] { 'a' };
2469             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2470             if ( t9.getHeight() != 0 ) {
2471                 return false;
2472             }
2473             final char[] a10 = new char[] { 'a', ':', '6' };
2474             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2475             if ( t10.getHeight() != 6 ) {
2476                 return false;
2477             }
2478         }
2479         catch ( final Exception e ) {
2480             e.printStackTrace( System.out );
2481             return false;
2482         }
2483         return true;
2484     }
2485
2486     private static boolean testConfidenceAssessor() {
2487         try {
2488             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2489             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2490             final Phylogeny[] ev0 = factory
2491                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2492                              new NHXParser() );
2493             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2494             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2495                 return false;
2496             }
2497             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2498                 return false;
2499             }
2500             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2501             final Phylogeny[] ev1 = factory
2502                     .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)));",
2503                              new NHXParser() );
2504             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2505             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2506                 return false;
2507             }
2508             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2509                 return false;
2510             }
2511             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2512             final Phylogeny[] ev_b = factory
2513                     .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",
2514                              new NHXParser() );
2515             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2516             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2517                 return false;
2518             }
2519             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2520                 return false;
2521             }
2522             //
2523             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2524             final Phylogeny[] ev1x = factory
2525                     .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)));",
2526                              new NHXParser() );
2527             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2528             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2529                 return false;
2530             }
2531             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2532                 return false;
2533             }
2534             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2535             final Phylogeny[] ev_bx = factory
2536                     .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",
2537                              new NHXParser() );
2538             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2539             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2540                 return false;
2541             }
2542             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2543                 return false;
2544             }
2545             //
2546             final Phylogeny[] t2 = factory
2547                     .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);",
2548                              new NHXParser() );
2549             final Phylogeny[] ev2 = factory
2550                     .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);",
2551                              new NHXParser() );
2552             for( final Phylogeny target : t2 ) {
2553                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2554             }
2555             //
2556             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2557                                                  new NHXParser() )[ 0 ];
2558             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2559             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2560             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2561                 return false;
2562             }
2563             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2564                 return false;
2565             }
2566             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2567                 return false;
2568             }
2569         }
2570         catch ( final Exception e ) {
2571             e.printStackTrace();
2572             return false;
2573         }
2574         return true;
2575     }
2576
2577     private static boolean testCopyOfNodeData() {
2578         try {
2579             final PhylogenyNode n1 = PhylogenyNode
2580                     .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]" );
2581             final PhylogenyNode n2 = n1.copyNodeData();
2582             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2583                 return false;
2584             }
2585         }
2586         catch ( final Exception e ) {
2587             e.printStackTrace();
2588             return false;
2589         }
2590         return true;
2591     }
2592
2593     private static boolean testCreateBalancedPhylogeny() {
2594         try {
2595             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2596             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2597                 return false;
2598             }
2599             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2600                 return false;
2601             }
2602             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2603             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2604                 return false;
2605             }
2606             if ( p1.getNumberOfExternalNodes() != 100 ) {
2607                 return false;
2608             }
2609         }
2610         catch ( final Exception e ) {
2611             e.printStackTrace();
2612             return false;
2613         }
2614         return true;
2615     }
2616
2617     private static boolean testCreateUriForSeqWeb() {
2618         try {
2619             final PhylogenyNode n = new PhylogenyNode();
2620             n.setName( "tr|B3RJ64" );
2621             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2622                 return false;
2623             }
2624             n.setName( "B0LM41_HUMAN" );
2625             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2626                 return false;
2627             }
2628             n.setName( "NP_001025424" );
2629             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2630                 return false;
2631             }
2632             n.setName( "_NM_001030253-" );
2633             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2634                 return false;
2635             }
2636             n.setName( "XM_002122186" );
2637             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2638                 return false;
2639             }
2640             n.setName( "dgh_AAA34956_gdg" );
2641             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2642                 return false;
2643             }
2644             n.setName( "j40f4_Q06891.1_fndn2 fnr3" );
2645             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891.1" ) ) {
2646                 return false;
2647             }
2648             n.setName( "GI:394892" );
2649             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2650                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
2651                 return false;
2652             }
2653             n.setName( "gi_394892" );
2654             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2655                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
2656                 return false;
2657             }
2658             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2659             if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2660                 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
2661                 return false;
2662             }
2663         }
2664         catch ( final Exception e ) {
2665             e.printStackTrace( System.out );
2666             return false;
2667         }
2668         return true;
2669     }
2670
2671     private static boolean testDataObjects() {
2672         try {
2673             final Confidence s0 = new Confidence();
2674             final Confidence s1 = new Confidence();
2675             if ( !s0.isEqual( s1 ) ) {
2676                 return false;
2677             }
2678             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2679             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2680             if ( s2.isEqual( s1 ) ) {
2681                 return false;
2682             }
2683             if ( !s2.isEqual( s3 ) ) {
2684                 return false;
2685             }
2686             final Confidence s4 = ( Confidence ) s3.copy();
2687             if ( !s4.isEqual( s3 ) ) {
2688                 return false;
2689             }
2690             s3.asSimpleText();
2691             s3.asText();
2692             // Taxonomy
2693             // ----------
2694             final Taxonomy t1 = new Taxonomy();
2695             final Taxonomy t2 = new Taxonomy();
2696             final Taxonomy t3 = new Taxonomy();
2697             final Taxonomy t4 = new Taxonomy();
2698             final Taxonomy t5 = new Taxonomy();
2699             t1.setIdentifier( new Identifier( "ecoli" ) );
2700             t1.setTaxonomyCode( "ECOLI" );
2701             t1.setScientificName( "E. coli" );
2702             t1.setCommonName( "coli" );
2703             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2704             if ( !t1.isEqual( t0 ) ) {
2705                 return false;
2706             }
2707             t2.setIdentifier( new Identifier( "ecoli" ) );
2708             t2.setTaxonomyCode( "OTHER" );
2709             t2.setScientificName( "what" );
2710             t2.setCommonName( "something" );
2711             if ( !t1.isEqual( t2 ) ) {
2712                 return false;
2713             }
2714             t2.setIdentifier( new Identifier( "nemve" ) );
2715             if ( t1.isEqual( t2 ) ) {
2716                 return false;
2717             }
2718             t1.setIdentifier( null );
2719             t3.setTaxonomyCode( "ECOLI" );
2720             t3.setScientificName( "what" );
2721             t3.setCommonName( "something" );
2722             if ( !t1.isEqual( t3 ) ) {
2723                 return false;
2724             }
2725             t1.setIdentifier( null );
2726             t1.setTaxonomyCode( "" );
2727             t4.setScientificName( "E. ColI" );
2728             t4.setCommonName( "something" );
2729             if ( !t1.isEqual( t4 ) ) {
2730                 return false;
2731             }
2732             t4.setScientificName( "B. subtilis" );
2733             t4.setCommonName( "something" );
2734             if ( t1.isEqual( t4 ) ) {
2735                 return false;
2736             }
2737             t1.setIdentifier( null );
2738             t1.setTaxonomyCode( "" );
2739             t1.setScientificName( "" );
2740             t5.setCommonName( "COLI" );
2741             if ( !t1.isEqual( t5 ) ) {
2742                 return false;
2743             }
2744             t5.setCommonName( "vibrio" );
2745             if ( t1.isEqual( t5 ) ) {
2746                 return false;
2747             }
2748             // Identifier
2749             // ----------
2750             final Identifier id0 = new Identifier( "123", "pfam" );
2751             final Identifier id1 = ( Identifier ) id0.copy();
2752             if ( !id1.isEqual( id1 ) ) {
2753                 return false;
2754             }
2755             if ( !id1.isEqual( id0 ) ) {
2756                 return false;
2757             }
2758             if ( !id0.isEqual( id1 ) ) {
2759                 return false;
2760             }
2761             id1.asSimpleText();
2762             id1.asText();
2763             // ProteinDomain
2764             // ---------------
2765             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2766             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2767             if ( !pd1.isEqual( pd1 ) ) {
2768                 return false;
2769             }
2770             if ( !pd1.isEqual( pd0 ) ) {
2771                 return false;
2772             }
2773             pd1.asSimpleText();
2774             pd1.asText();
2775             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2776             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2777             if ( !pd3.isEqual( pd3 ) ) {
2778                 return false;
2779             }
2780             if ( !pd2.isEqual( pd3 ) ) {
2781                 return false;
2782             }
2783             if ( !pd0.isEqual( pd3 ) ) {
2784                 return false;
2785             }
2786             pd3.asSimpleText();
2787             pd3.asText();
2788             // DomainArchitecture
2789             // ------------------
2790             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2791             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2792             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2793             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2794             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2795             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2796             domains0.add( d2 );
2797             domains0.add( d0 );
2798             domains0.add( d3 );
2799             domains0.add( d1 );
2800             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2801             if ( ds0.getNumberOfDomains() != 4 ) {
2802                 return false;
2803             }
2804             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2805             if ( !ds0.isEqual( ds0 ) ) {
2806                 return false;
2807             }
2808             if ( !ds0.isEqual( ds1 ) ) {
2809                 return false;
2810             }
2811             if ( ds1.getNumberOfDomains() != 4 ) {
2812                 return false;
2813             }
2814             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2815             domains1.add( d1 );
2816             domains1.add( d2 );
2817             domains1.add( d4 );
2818             domains1.add( d0 );
2819             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2820             if ( ds0.isEqual( ds2 ) ) {
2821                 return false;
2822             }
2823             ds1.asSimpleText();
2824             ds1.asText();
2825             ds1.toNHX();
2826             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2827             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2828                 System.out.println( ds3.toNHX() );
2829                 return false;
2830             }
2831             if ( ds3.getNumberOfDomains() != 3 ) {
2832                 return false;
2833             }
2834             // Event
2835             // -----
2836             final Event e1 = new Event( Event.EventType.fusion );
2837             if ( e1.isDuplication() ) {
2838                 return false;
2839             }
2840             if ( !e1.isFusion() ) {
2841                 return false;
2842             }
2843             if ( !e1.asText().toString().equals( "fusion" ) ) {
2844                 return false;
2845             }
2846             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2847                 return false;
2848             }
2849             final Event e11 = new Event( Event.EventType.fusion );
2850             if ( !e11.isEqual( e1 ) ) {
2851                 return false;
2852             }
2853             if ( !e11.toNHX().toString().equals( "" ) ) {
2854                 return false;
2855             }
2856             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2857             if ( e2.isDuplication() ) {
2858                 return false;
2859             }
2860             if ( !e2.isSpeciationOrDuplication() ) {
2861                 return false;
2862             }
2863             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2864                 return false;
2865             }
2866             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2867                 return false;
2868             }
2869             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2870                 return false;
2871             }
2872             if ( e11.isEqual( e2 ) ) {
2873                 return false;
2874             }
2875             final Event e2c = ( Event ) e2.copy();
2876             if ( !e2c.isEqual( e2 ) ) {
2877                 return false;
2878             }
2879             Event e3 = new Event( 1, 2, 3 );
2880             if ( e3.isDuplication() ) {
2881                 return false;
2882             }
2883             if ( e3.isSpeciation() ) {
2884                 return false;
2885             }
2886             if ( e3.isGeneLoss() ) {
2887                 return false;
2888             }
2889             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2890                 return false;
2891             }
2892             final Event e3c = ( Event ) e3.copy();
2893             final Event e3cc = ( Event ) e3c.copy();
2894             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2895                 return false;
2896             }
2897             e3 = null;
2898             if ( !e3c.isEqual( e3cc ) ) {
2899                 return false;
2900             }
2901             Event e4 = new Event( 1, 2, 3 );
2902             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2903                 return false;
2904             }
2905             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2906                 return false;
2907             }
2908             final Event e4c = ( Event ) e4.copy();
2909             e4 = null;
2910             final Event e4cc = ( Event ) e4c.copy();
2911             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2912                 return false;
2913             }
2914             if ( !e4c.isEqual( e4cc ) ) {
2915                 return false;
2916             }
2917             final Event e5 = new Event();
2918             if ( !e5.isUnassigned() ) {
2919                 return false;
2920             }
2921             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2922                 return false;
2923             }
2924             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2925                 return false;
2926             }
2927             final Event e6 = new Event( 1, 0, 0 );
2928             if ( !e6.asText().toString().equals( "duplication" ) ) {
2929                 return false;
2930             }
2931             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2932                 return false;
2933             }
2934             final Event e7 = new Event( 0, 1, 0 );
2935             if ( !e7.asText().toString().equals( "speciation" ) ) {
2936                 return false;
2937             }
2938             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2939                 return false;
2940             }
2941             final Event e8 = new Event( 0, 0, 1 );
2942             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2943                 return false;
2944             }
2945             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2946                 return false;
2947             }
2948         }
2949         catch ( final Exception e ) {
2950             e.printStackTrace( System.out );
2951             return false;
2952         }
2953         return true;
2954     }
2955
2956     private static boolean testDeletionOfExternalNodes() {
2957         try {
2958             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2959             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2960             final PhylogenyWriter w = new PhylogenyWriter();
2961             if ( t0.isEmpty() ) {
2962                 return false;
2963             }
2964             if ( t0.getNumberOfExternalNodes() != 1 ) {
2965                 return false;
2966             }
2967             t0.deleteSubtree( t0.getNode( "A" ), false );
2968             if ( t0.getNumberOfExternalNodes() != 0 ) {
2969                 return false;
2970             }
2971             if ( !t0.isEmpty() ) {
2972                 return false;
2973             }
2974             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2975             if ( t1.getNumberOfExternalNodes() != 2 ) {
2976                 return false;
2977             }
2978             t1.deleteSubtree( t1.getNode( "A" ), false );
2979             if ( t1.getNumberOfExternalNodes() != 1 ) {
2980                 return false;
2981             }
2982             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2983                 return false;
2984             }
2985             t1.deleteSubtree( t1.getNode( "B" ), false );
2986             if ( t1.getNumberOfExternalNodes() != 1 ) {
2987                 return false;
2988             }
2989             t1.deleteSubtree( t1.getNode( "r" ), false );
2990             if ( !t1.isEmpty() ) {
2991                 return false;
2992             }
2993             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2994             if ( t2.getNumberOfExternalNodes() != 3 ) {
2995                 return false;
2996             }
2997             t2.deleteSubtree( t2.getNode( "B" ), false );
2998             if ( t2.getNumberOfExternalNodes() != 2 ) {
2999                 return false;
3000             }
3001             t2.toNewHampshireX();
3002             PhylogenyNode n = t2.getNode( "A" );
3003             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3004                 return false;
3005             }
3006             t2.deleteSubtree( t2.getNode( "A" ), false );
3007             if ( t2.getNumberOfExternalNodes() != 2 ) {
3008                 return false;
3009             }
3010             t2.deleteSubtree( t2.getNode( "C" ), true );
3011             if ( t2.getNumberOfExternalNodes() != 1 ) {
3012                 return false;
3013             }
3014             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3015             if ( t3.getNumberOfExternalNodes() != 4 ) {
3016                 return false;
3017             }
3018             t3.deleteSubtree( t3.getNode( "B" ), true );
3019             if ( t3.getNumberOfExternalNodes() != 3 ) {
3020                 return false;
3021             }
3022             n = t3.getNode( "A" );
3023             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3024                 return false;
3025             }
3026             n = n.getNextExternalNode();
3027             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3028                 return false;
3029             }
3030             t3.deleteSubtree( t3.getNode( "A" ), true );
3031             if ( t3.getNumberOfExternalNodes() != 2 ) {
3032                 return false;
3033             }
3034             n = t3.getNode( "C" );
3035             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3036                 return false;
3037             }
3038             t3.deleteSubtree( t3.getNode( "C" ), true );
3039             if ( t3.getNumberOfExternalNodes() != 1 ) {
3040                 return false;
3041             }
3042             t3.deleteSubtree( t3.getNode( "D" ), true );
3043             if ( t3.getNumberOfExternalNodes() != 0 ) {
3044                 return false;
3045             }
3046             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3047             if ( t4.getNumberOfExternalNodes() != 6 ) {
3048                 return false;
3049             }
3050             t4.deleteSubtree( t4.getNode( "B2" ), true );
3051             if ( t4.getNumberOfExternalNodes() != 5 ) {
3052                 return false;
3053             }
3054             String s = w.toNewHampshire( t4, false, true ).toString();
3055             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3056                 return false;
3057             }
3058             t4.deleteSubtree( t4.getNode( "B11" ), true );
3059             if ( t4.getNumberOfExternalNodes() != 4 ) {
3060                 return false;
3061             }
3062             t4.deleteSubtree( t4.getNode( "C" ), true );
3063             if ( t4.getNumberOfExternalNodes() != 3 ) {
3064                 return false;
3065             }
3066             n = t4.getNode( "A" );
3067             n = n.getNextExternalNode();
3068             if ( !n.getName().equals( "B12" ) ) {
3069                 return false;
3070             }
3071             n = n.getNextExternalNode();
3072             if ( !n.getName().equals( "D" ) ) {
3073                 return false;
3074             }
3075             s = w.toNewHampshire( t4, false, true ).toString();
3076             if ( !s.equals( "((A,B12),D);" ) ) {
3077                 return false;
3078             }
3079             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3080             t5.deleteSubtree( t5.getNode( "A" ), true );
3081             if ( t5.getNumberOfExternalNodes() != 5 ) {
3082                 return false;
3083             }
3084             s = w.toNewHampshire( t5, false, true ).toString();
3085             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3086                 return false;
3087             }
3088             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3089             t6.deleteSubtree( t6.getNode( "B11" ), true );
3090             if ( t6.getNumberOfExternalNodes() != 5 ) {
3091                 return false;
3092             }
3093             s = w.toNewHampshire( t6, false, false ).toString();
3094             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3095                 return false;
3096             }
3097             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3098             t7.deleteSubtree( t7.getNode( "B12" ), true );
3099             if ( t7.getNumberOfExternalNodes() != 5 ) {
3100                 return false;
3101             }
3102             s = w.toNewHampshire( t7, false, true ).toString();
3103             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3104                 return false;
3105             }
3106             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3107             t8.deleteSubtree( t8.getNode( "B2" ), true );
3108             if ( t8.getNumberOfExternalNodes() != 5 ) {
3109                 return false;
3110             }
3111             s = w.toNewHampshire( t8, false, false ).toString();
3112             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3113                 return false;
3114             }
3115             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3116             t9.deleteSubtree( t9.getNode( "C" ), true );
3117             if ( t9.getNumberOfExternalNodes() != 5 ) {
3118                 return false;
3119             }
3120             s = w.toNewHampshire( t9, false, true ).toString();
3121             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3122                 return false;
3123             }
3124             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3125             t10.deleteSubtree( t10.getNode( "D" ), true );
3126             if ( t10.getNumberOfExternalNodes() != 5 ) {
3127                 return false;
3128             }
3129             s = w.toNewHampshire( t10, false, true ).toString();
3130             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3131                 return false;
3132             }
3133             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3134             t11.deleteSubtree( t11.getNode( "A" ), true );
3135             if ( t11.getNumberOfExternalNodes() != 2 ) {
3136                 return false;
3137             }
3138             s = w.toNewHampshire( t11, false, true ).toString();
3139             if ( !s.equals( "(B,C);" ) ) {
3140                 return false;
3141             }
3142             t11.deleteSubtree( t11.getNode( "C" ), true );
3143             if ( t11.getNumberOfExternalNodes() != 1 ) {
3144                 return false;
3145             }
3146             s = w.toNewHampshire( t11, false, false ).toString();
3147             if ( !s.equals( "B;" ) ) {
3148                 return false;
3149             }
3150             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3151             t12.deleteSubtree( t12.getNode( "B2" ), true );
3152             if ( t12.getNumberOfExternalNodes() != 8 ) {
3153                 return false;
3154             }
3155             s = w.toNewHampshire( t12, false, true ).toString();
3156             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3157                 return false;
3158             }
3159             t12.deleteSubtree( t12.getNode( "B3" ), true );
3160             if ( t12.getNumberOfExternalNodes() != 7 ) {
3161                 return false;
3162             }
3163             s = w.toNewHampshire( t12, false, true ).toString();
3164             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3165                 return false;
3166             }
3167             t12.deleteSubtree( t12.getNode( "C3" ), true );
3168             if ( t12.getNumberOfExternalNodes() != 6 ) {
3169                 return false;
3170             }
3171             s = w.toNewHampshire( t12, false, true ).toString();
3172             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3173                 return false;
3174             }
3175             t12.deleteSubtree( t12.getNode( "A1" ), true );
3176             if ( t12.getNumberOfExternalNodes() != 5 ) {
3177                 return false;
3178             }
3179             s = w.toNewHampshire( t12, false, true ).toString();
3180             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3181                 return false;
3182             }
3183             t12.deleteSubtree( t12.getNode( "B1" ), true );
3184             if ( t12.getNumberOfExternalNodes() != 4 ) {
3185                 return false;
3186             }
3187             s = w.toNewHampshire( t12, false, true ).toString();
3188             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3189                 return false;
3190             }
3191             t12.deleteSubtree( t12.getNode( "A3" ), true );
3192             if ( t12.getNumberOfExternalNodes() != 3 ) {
3193                 return false;
3194             }
3195             s = w.toNewHampshire( t12, false, true ).toString();
3196             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3197                 return false;
3198             }
3199             t12.deleteSubtree( t12.getNode( "A2" ), true );
3200             if ( t12.getNumberOfExternalNodes() != 2 ) {
3201                 return false;
3202             }
3203             s = w.toNewHampshire( t12, false, true ).toString();
3204             if ( !s.equals( "(C1,C2);" ) ) {
3205                 return false;
3206             }
3207             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3208             t13.deleteSubtree( t13.getNode( "D" ), true );
3209             if ( t13.getNumberOfExternalNodes() != 4 ) {
3210                 return false;
3211             }
3212             s = w.toNewHampshire( t13, false, true ).toString();
3213             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3214                 return false;
3215             }
3216             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3217             t14.deleteSubtree( t14.getNode( "E" ), true );
3218             if ( t14.getNumberOfExternalNodes() != 5 ) {
3219                 return false;
3220             }
3221             s = w.toNewHampshire( t14, false, true ).toString();
3222             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3223                 return false;
3224             }
3225             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3226             t15.deleteSubtree( t15.getNode( "B2" ), true );
3227             if ( t15.getNumberOfExternalNodes() != 11 ) {
3228                 return false;
3229             }
3230             t15.deleteSubtree( t15.getNode( "B1" ), true );
3231             if ( t15.getNumberOfExternalNodes() != 10 ) {
3232                 return false;
3233             }
3234             t15.deleteSubtree( t15.getNode( "B3" ), true );
3235             if ( t15.getNumberOfExternalNodes() != 9 ) {
3236                 return false;
3237             }
3238             t15.deleteSubtree( t15.getNode( "B4" ), true );
3239             if ( t15.getNumberOfExternalNodes() != 8 ) {
3240                 return false;
3241             }
3242             t15.deleteSubtree( t15.getNode( "A1" ), true );
3243             if ( t15.getNumberOfExternalNodes() != 7 ) {
3244                 return false;
3245             }
3246             t15.deleteSubtree( t15.getNode( "C4" ), true );
3247             if ( t15.getNumberOfExternalNodes() != 6 ) {
3248                 return false;
3249             }
3250         }
3251         catch ( final Exception e ) {
3252             e.printStackTrace( System.out );
3253             return false;
3254         }
3255         return true;
3256     }
3257
3258     private static boolean testDescriptiveStatistics() {
3259         try {
3260             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3261             dss1.addValue( 82 );
3262             dss1.addValue( 78 );
3263             dss1.addValue( 70 );
3264             dss1.addValue( 58 );
3265             dss1.addValue( 42 );
3266             if ( dss1.getN() != 5 ) {
3267                 return false;
3268             }
3269             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3270                 return false;
3271             }
3272             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3273                 return false;
3274             }
3275             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3276                 return false;
3277             }
3278             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3279                 return false;
3280             }
3281             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3282                 return false;
3283             }
3284             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3285                 return false;
3286             }
3287             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3288                 return false;
3289             }
3290             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3291                 return false;
3292             }
3293             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3294                 return false;
3295             }
3296             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3297                 return false;
3298             }
3299             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3300                 return false;
3301             }
3302             dss1.addValue( 123 );
3303             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3304                 return false;
3305             }
3306             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3307                 return false;
3308             }
3309             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3310                 return false;
3311             }
3312             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3313             dss2.addValue( -1.85 );
3314             dss2.addValue( 57.5 );
3315             dss2.addValue( 92.78 );
3316             dss2.addValue( 57.78 );
3317             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3318                 return false;
3319             }
3320             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3321                 return false;
3322             }
3323             final double[] a = dss2.getDataAsDoubleArray();
3324             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3325                 return false;
3326             }
3327             dss2.addValue( -100 );
3328             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3329                 return false;
3330             }
3331             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3332                 return false;
3333             }
3334             final double[] ds = new double[ 14 ];
3335             ds[ 0 ] = 34;
3336             ds[ 1 ] = 23;
3337             ds[ 2 ] = 1;
3338             ds[ 3 ] = 32;
3339             ds[ 4 ] = 11;
3340             ds[ 5 ] = 2;
3341             ds[ 6 ] = 12;
3342             ds[ 7 ] = 33;
3343             ds[ 8 ] = 13;
3344             ds[ 9 ] = 22;
3345             ds[ 10 ] = 21;
3346             ds[ 11 ] = 35;
3347             ds[ 12 ] = 24;
3348             ds[ 13 ] = 31;
3349             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3350             if ( bins.length != 4 ) {
3351                 return false;
3352             }
3353             if ( bins[ 0 ] != 2 ) {
3354                 return false;
3355             }
3356             if ( bins[ 1 ] != 3 ) {
3357                 return false;
3358             }
3359             if ( bins[ 2 ] != 4 ) {
3360                 return false;
3361             }
3362             if ( bins[ 3 ] != 5 ) {
3363                 return false;
3364             }
3365             final double[] ds1 = new double[ 9 ];
3366             ds1[ 0 ] = 10.0;
3367             ds1[ 1 ] = 19.0;
3368             ds1[ 2 ] = 9.999;
3369             ds1[ 3 ] = 0.0;
3370             ds1[ 4 ] = 39.9;
3371             ds1[ 5 ] = 39.999;
3372             ds1[ 6 ] = 30.0;
3373             ds1[ 7 ] = 19.999;
3374             ds1[ 8 ] = 30.1;
3375             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3376             if ( bins1.length != 4 ) {
3377                 return false;
3378             }
3379             if ( bins1[ 0 ] != 2 ) {
3380                 return false;
3381             }
3382             if ( bins1[ 1 ] != 3 ) {
3383                 return false;
3384             }
3385             if ( bins1[ 2 ] != 0 ) {
3386                 return false;
3387             }
3388             if ( bins1[ 3 ] != 4 ) {
3389                 return false;
3390             }
3391             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3392             if ( bins1_1.length != 3 ) {
3393                 return false;
3394             }
3395             if ( bins1_1[ 0 ] != 3 ) {
3396                 return false;
3397             }
3398             if ( bins1_1[ 1 ] != 2 ) {
3399                 return false;
3400             }
3401             if ( bins1_1[ 2 ] != 4 ) {
3402                 return false;
3403             }
3404             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3405             if ( bins1_2.length != 3 ) {
3406                 return false;
3407             }
3408             if ( bins1_2[ 0 ] != 2 ) {
3409                 return false;
3410             }
3411             if ( bins1_2[ 1 ] != 2 ) {
3412                 return false;
3413             }
3414             if ( bins1_2[ 2 ] != 2 ) {
3415                 return false;
3416             }
3417             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3418             dss3.addValue( 1 );
3419             dss3.addValue( 1 );
3420             dss3.addValue( 1 );
3421             dss3.addValue( 2 );
3422             dss3.addValue( 3 );
3423             dss3.addValue( 4 );
3424             dss3.addValue( 5 );
3425             dss3.addValue( 5 );
3426             dss3.addValue( 5 );
3427             dss3.addValue( 6 );
3428             dss3.addValue( 7 );
3429             dss3.addValue( 8 );
3430             dss3.addValue( 9 );
3431             dss3.addValue( 10 );
3432             dss3.addValue( 10 );
3433             dss3.addValue( 10 );
3434             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3435             histo.toStringBuffer( 10, '=', 40, 5 );
3436             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3437         }
3438         catch ( final Exception e ) {
3439             e.printStackTrace( System.out );
3440             return false;
3441         }
3442         return true;
3443     }
3444
3445     private static boolean testDir( final String file ) {
3446         try {
3447             final File f = new File( file );
3448             if ( !f.exists() ) {
3449                 return false;
3450             }
3451             if ( !f.isDirectory() ) {
3452                 return false;
3453             }
3454             if ( !f.canRead() ) {
3455                 return false;
3456             }
3457         }
3458         catch ( final Exception e ) {
3459             return false;
3460         }
3461         return true;
3462     }
3463
3464     private static boolean testDomainId() {
3465         try {
3466             final DomainId id1 = new DomainId( "a" );
3467             final DomainId id2 = new DomainId( "a" );
3468             final DomainId id3 = new DomainId( "A" );
3469             final DomainId id4 = new DomainId( "b" );
3470             if ( !id1.equals( id1 ) ) {
3471                 return false;
3472             }
3473             if ( id1.getId().equals( "x" ) ) {
3474                 return false;
3475             }
3476             if ( id1.getId().equals( null ) ) {
3477                 return false;
3478             }
3479             if ( !id1.equals( id2 ) ) {
3480                 return false;
3481             }
3482             if ( id1.equals( id3 ) ) {
3483                 return false;
3484             }
3485             if ( id1.hashCode() != id1.hashCode() ) {
3486                 return false;
3487             }
3488             if ( id1.hashCode() != id2.hashCode() ) {
3489                 return false;
3490             }
3491             if ( id1.hashCode() == id3.hashCode() ) {
3492                 return false;
3493             }
3494             if ( id1.compareTo( id1 ) != 0 ) {
3495                 return false;
3496             }
3497             if ( id1.compareTo( id2 ) != 0 ) {
3498                 return false;
3499             }
3500             if ( id1.compareTo( id3 ) != 0 ) {
3501                 return false;
3502             }
3503             if ( id1.compareTo( id4 ) >= 0 ) {
3504                 return false;
3505             }
3506             if ( id4.compareTo( id1 ) <= 0 ) {
3507                 return false;
3508             }
3509             if ( !id4.getId().equals( "b" ) ) {
3510                 return false;
3511             }
3512             final DomainId id5 = new DomainId( " C " );
3513             if ( !id5.getId().equals( "C" ) ) {
3514                 return false;
3515             }
3516             if ( id5.equals( id1 ) ) {
3517                 return false;
3518             }
3519         }
3520         catch ( final Exception e ) {
3521             e.printStackTrace( System.out );
3522             return false;
3523         }
3524         return true;
3525     }
3526
3527     private static boolean testEmblEntryRetrieval() {
3528         //The format for GenBank Accession numbers are:
3529         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
3530         //Protein:    3 letters + 5 numerals
3531         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
3532         if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
3533             return false;
3534         }
3535         if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861.2" ).equals( "AY423861.2" ) ) {
3536             return false;
3537         }
3538         if ( !SequenceIdParser.parseGenbankAccessor( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
3539             return false;
3540         }
3541         if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
3542             return false;
3543         }
3544         if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
3545             return false;
3546         }
3547         if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
3548             return false;
3549         }
3550         if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
3551             return false;
3552         }
3553         if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
3554             return false;
3555         }
3556         if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
3557             return false;
3558         }
3559         if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
3560             return false;
3561         }
3562         if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
3563             return false;
3564         }
3565         if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
3566             return false;
3567         }
3568         if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
3569             return false;
3570         }
3571         if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
3572             return false;
3573         }
3574         return true;
3575     }
3576
3577     private static boolean testExternalNodeRelatedMethods() {
3578         try {
3579             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3580             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3581             PhylogenyNode n = t1.getNode( "A" );
3582             n = n.getNextExternalNode();
3583             if ( !n.getName().equals( "B" ) ) {
3584                 return false;
3585             }
3586             n = n.getNextExternalNode();
3587             if ( !n.getName().equals( "C" ) ) {
3588                 return false;
3589             }
3590             n = n.getNextExternalNode();
3591             if ( !n.getName().equals( "D" ) ) {
3592                 return false;
3593             }
3594             n = t1.getNode( "B" );
3595             while ( !n.isLastExternalNode() ) {
3596                 n = n.getNextExternalNode();
3597             }
3598             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3599             n = t2.getNode( "A" );
3600             n = n.getNextExternalNode();
3601             if ( !n.getName().equals( "B" ) ) {
3602                 return false;
3603             }
3604             n = n.getNextExternalNode();
3605             if ( !n.getName().equals( "C" ) ) {
3606                 return false;
3607             }
3608             n = n.getNextExternalNode();
3609             if ( !n.getName().equals( "D" ) ) {
3610                 return false;
3611             }
3612             n = t2.getNode( "B" );
3613             while ( !n.isLastExternalNode() ) {
3614                 n = n.getNextExternalNode();
3615             }
3616             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3617             n = t3.getNode( "A" );
3618             n = n.getNextExternalNode();
3619             if ( !n.getName().equals( "B" ) ) {
3620                 return false;
3621             }
3622             n = n.getNextExternalNode();
3623             if ( !n.getName().equals( "C" ) ) {
3624                 return false;
3625             }
3626             n = n.getNextExternalNode();
3627             if ( !n.getName().equals( "D" ) ) {
3628                 return false;
3629             }
3630             n = n.getNextExternalNode();
3631             if ( !n.getName().equals( "E" ) ) {
3632                 return false;
3633             }
3634             n = n.getNextExternalNode();
3635             if ( !n.getName().equals( "F" ) ) {
3636                 return false;
3637             }
3638             n = n.getNextExternalNode();
3639             if ( !n.getName().equals( "G" ) ) {
3640                 return false;
3641             }
3642             n = n.getNextExternalNode();
3643             if ( !n.getName().equals( "H" ) ) {
3644                 return false;
3645             }
3646             n = t3.getNode( "B" );
3647             while ( !n.isLastExternalNode() ) {
3648                 n = n.getNextExternalNode();
3649             }
3650             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3651             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3652                 final PhylogenyNode node = iter.next();
3653             }
3654             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3655             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3656                 final PhylogenyNode node = iter.next();
3657             }
3658             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3659             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3660             if ( !iter.next().getName().equals( "A" ) ) {
3661                 return false;
3662             }
3663             if ( !iter.next().getName().equals( "B" ) ) {
3664                 return false;
3665             }
3666             if ( !iter.next().getName().equals( "C" ) ) {
3667                 return false;
3668             }
3669             if ( !iter.next().getName().equals( "D" ) ) {
3670                 return false;
3671             }
3672             if ( !iter.next().getName().equals( "E" ) ) {
3673                 return false;
3674             }
3675             if ( !iter.next().getName().equals( "F" ) ) {
3676                 return false;
3677             }
3678             if ( iter.hasNext() ) {
3679                 return false;
3680             }
3681         }
3682         catch ( final Exception e ) {
3683             e.printStackTrace( System.out );
3684             return false;
3685         }
3686         return true;
3687     }
3688
3689     private static boolean testExtractSNFromNodeName() {
3690         try {
3691             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
3692                 return false;
3693             }
3694             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
3695                     .equals( "Mus musculus musculus" ) ) {
3696                 return false;
3697             }
3698             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
3699                     .equals( "Mus musculus musculus" ) ) {
3700                 return false;
3701             }
3702             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
3703                 return false;
3704             }
3705             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
3706                     .equals( "Mus musculus" ) ) {
3707                 return false;
3708             }
3709         }
3710         catch ( final Exception e ) {
3711             e.printStackTrace( System.out );
3712             return false;
3713         }
3714         return true;
3715     }
3716
3717     private static boolean testExtractTaxonomyCodeFromNodeName() {
3718         try {
3719             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3720                 return false;
3721             }
3722             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3723                     .equals( "SOYBN" ) ) {
3724                 return false;
3725             }
3726             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3727                     .equals( "ARATH" ) ) {
3728                 return false;
3729             }
3730             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3731                     .equals( "ARATH" ) ) {
3732                 return false;
3733             }
3734             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3735                 return false;
3736             }
3737             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3738                 return false;
3739             }
3740             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3741                 return false;
3742             }
3743             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3744                     .equals( "SOYBN" ) ) {
3745                 return false;
3746             }
3747             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3748                     .equals( "SOYBN" ) ) {
3749                 return false;
3750             }
3751             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3752                     .equals( "SOYBN" ) ) {
3753                 return false;
3754             }
3755             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3756                     .equals( "SOYBN" ) ) {
3757                 return false;
3758             }
3759             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3760                     .equals( "SOYBN" ) ) {
3761                 return false;
3762             }
3763             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3764                     .equals( "SOYBN" ) ) {
3765                 return false;
3766             }
3767             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
3768                     .equals( "SOYBN" ) ) {
3769                 return false;
3770             }
3771             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
3772                     .equals( "SOYBN" ) ) {
3773                 return false;
3774             }
3775             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
3776                 return false;
3777             }
3778             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
3779                     .equals( "SOYBN" ) ) {
3780                 return false;
3781             }
3782             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
3783                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
3784                 return false;
3785             }
3786             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
3787                     .equals( "9YX45" ) ) {
3788                 return false;
3789             }
3790             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
3791                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3792                     .equals( "MOUSE" ) ) {
3793                 return false;
3794             }
3795             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
3796                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3797                     .equals( "MOUSE" ) ) {
3798                 return false;
3799             }
3800             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
3801                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3802                     .equals( "MOUSE" ) ) {
3803                 return false;
3804             }
3805             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
3806                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3807                 return false;
3808             }
3809             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
3810                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3811                 return false;
3812             }
3813             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3814                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3815                 return false;
3816             }
3817             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3818                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3819                 return false;
3820             }
3821             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
3822                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3823                 return false;
3824             }
3825             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
3826                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3827                 return false;
3828             }
3829             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
3830                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3831                 return false;
3832             }
3833             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3834                     .equals( "RAT" ) ) {
3835                 return false;
3836             }
3837             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3838                     .equals( "PIG" ) ) {
3839                 return false;
3840             }
3841             if ( !ParserUtils
3842                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3843                     .equals( "MOUSE" ) ) {
3844                 return false;
3845             }
3846             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3847                     .equals( "MOUSE" ) ) {
3848                 return false;
3849             }
3850             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3851                 return false;
3852             }
3853         }
3854         catch ( final Exception e ) {
3855             e.printStackTrace( System.out );
3856             return false;
3857         }
3858         return true;
3859     }
3860
3861     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
3862         try {
3863             PhylogenyNode n = new PhylogenyNode();
3864             n.setName( "tr|B3RJ64" );
3865             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3866                 return false;
3867             }
3868             n.setName( "tr.B3RJ64" );
3869             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3870                 return false;
3871             }
3872             n.setName( "tr=B3RJ64" );
3873             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3874                 return false;
3875             }
3876             n.setName( "tr-B3RJ64" );
3877             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3878                 return false;
3879             }
3880             n.setName( "tr/B3RJ64" );
3881             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3882                 return false;
3883             }
3884             n.setName( "tr\\B3RJ64" );
3885             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3886                 return false;
3887             }
3888             n.setName( "tr_B3RJ64" );
3889             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3890                 return false;
3891             }
3892             n.setName( " tr|B3RJ64 " );
3893             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3894                 return false;
3895             }
3896             n.setName( "-tr|B3RJ64-" );
3897             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3898                 return false;
3899             }
3900             n.setName( "-tr=B3RJ64-" );
3901             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3902                 return false;
3903             }
3904             n.setName( "_tr=B3RJ64_" );
3905             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3906                 return false;
3907             }
3908             n.setName( " tr_tr|B3RJ64_sp|123 " );
3909             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3910                 return false;
3911             }
3912             n.setName( "sp|B3RJ64" );
3913             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3914                 return false;
3915             }
3916             n.setName( "ssp|B3RJ64" );
3917             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3918                 return false;
3919             }
3920             n.setName( "sp|B3RJ64C" );
3921             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3922                 return false;
3923             }
3924             n.setName( "sp B3RJ64" );
3925             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3926                 return false;
3927             }
3928             n.setName( "sp|B3RJ6X" );
3929             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3930                 return false;
3931             }
3932             n.setName( "sp|B3RJ6" );
3933             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3934                 return false;
3935             }
3936             n.setName( "K1PYK7_CRAGI" );
3937             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3938                 return false;
3939             }
3940             n.setName( "K1PYK7_PEA" );
3941             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) {
3942                 return false;
3943             }
3944             n.setName( "K1PYK7_RAT" );
3945             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) {
3946                 return false;
3947             }
3948             n.setName( "K1PYK7_PIG" );
3949             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
3950                 return false;
3951             }
3952             n.setName( "~K1PYK7_PIG~" );
3953             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
3954                 return false;
3955             }
3956             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
3957             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3958                 return false;
3959             }
3960             n.setName( "K1PYKX_CRAGI" );
3961             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3962                 return false;
3963             }
3964             n.setName( "XXXXX_CRAGI" );
3965             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) {
3966                 return false;
3967             }
3968             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
3969             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) {
3970                 return false;
3971             }
3972             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
3973             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3974                 return false;
3975             }
3976             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
3977             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) {
3978                 return false;
3979             }
3980             n = new PhylogenyNode();
3981             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
3982             seq.setSymbol( "K1PYK7_CRAGI" );
3983             n.getNodeData().addSequence( seq );
3984             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3985                 return false;
3986             }
3987             seq.setSymbol( "tr|B3RJ64" );
3988             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3989                 return false;
3990             }
3991             n = new PhylogenyNode();
3992             seq = new org.forester.phylogeny.data.Sequence();
3993             seq.setName( "K1PYK7_CRAGI" );
3994             n.getNodeData().addSequence( seq );
3995             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3996                 return false;
3997             }
3998             seq.setName( "tr|B3RJ64" );
3999             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
4000                 return false;
4001             }
4002             n = new PhylogenyNode();
4003             seq = new org.forester.phylogeny.data.Sequence();
4004             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4005             n.getNodeData().addSequence( seq );
4006             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) {
4007                 return false;
4008             }
4009             n = new PhylogenyNode();
4010             seq = new org.forester.phylogeny.data.Sequence();
4011             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4012             n.getNodeData().addSequence( seq );
4013             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
4014                 return false;
4015             }
4016             //
4017             n = new PhylogenyNode();
4018             n.setName( "ACP19736" );
4019             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
4020                 return false;
4021             }
4022             n = new PhylogenyNode();
4023             n.setName( "_ACP19736_" );
4024             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
4025                 return false;
4026             }
4027         }
4028         catch ( final Exception e ) {
4029             e.printStackTrace( System.out );
4030             return false;
4031         }
4032         return true;
4033     }
4034
4035     private static boolean testFastaParser() {
4036         try {
4037             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4038                 return false;
4039             }
4040             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4041                 return false;
4042             }
4043             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4044             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4045                 return false;
4046             }
4047             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4048                 return false;
4049             }
4050             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4051                 return false;
4052             }
4053             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4054                 return false;
4055             }
4056             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4057                 return false;
4058             }
4059             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4060                 return false;
4061             }
4062         }
4063         catch ( final Exception e ) {
4064             e.printStackTrace();
4065             return false;
4066         }
4067         return true;
4068     }
4069
4070     private static boolean testGeneralMsaParser() {
4071         try {
4072             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4073             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4074             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4075             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4076             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4077             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4078             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4079             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4080             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4081                 return false;
4082             }
4083             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4084                 return false;
4085             }
4086             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4087                 return false;
4088             }
4089             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4090                 return false;
4091             }
4092             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4093                 return false;
4094             }
4095             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4096                 return false;
4097             }
4098             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4099                 return false;
4100             }
4101             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4102                 return false;
4103             }
4104             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4105                 return false;
4106             }
4107             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4108                 return false;
4109             }
4110             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4111                 return false;
4112             }
4113             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4114                 return false;
4115             }
4116             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4117             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4118                 return false;
4119             }
4120             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4121                 return false;
4122             }
4123             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4124                 return false;
4125             }
4126             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4127             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4128                 return false;
4129             }
4130             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4131                 return false;
4132             }
4133             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4134                 return false;
4135             }
4136             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4137             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4138                 return false;
4139             }
4140             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4141                 return false;
4142             }
4143             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4144                 return false;
4145             }
4146         }
4147         catch ( final Exception e ) {
4148             e.printStackTrace();
4149             return false;
4150         }
4151         return true;
4152     }
4153
4154     private static boolean testGeneralTable() {
4155         try {
4156             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4157             t0.setValue( 3, 2, "23" );
4158             t0.setValue( 10, 1, "error" );
4159             t0.setValue( 10, 1, "110" );
4160             t0.setValue( 9, 1, "19" );
4161             t0.setValue( 1, 10, "101" );
4162             t0.setValue( 10, 10, "1010" );
4163             t0.setValue( 100, 10, "10100" );
4164             t0.setValue( 0, 0, "00" );
4165             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4166                 return false;
4167             }
4168             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4169                 return false;
4170             }
4171             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4172                 return false;
4173             }
4174             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4175                 return false;
4176             }
4177             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4178                 return false;
4179             }
4180             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4181                 return false;
4182             }
4183             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4184                 return false;
4185             }
4186             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4187                 return false;
4188             }
4189             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4190                 return false;
4191             }
4192             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4193             t1.setValue( "3", "2", "23" );
4194             t1.setValue( "10", "1", "error" );
4195             t1.setValue( "10", "1", "110" );
4196             t1.setValue( "9", "1", "19" );
4197             t1.setValue( "1", "10", "101" );
4198             t1.setValue( "10", "10", "1010" );
4199             t1.setValue( "100", "10", "10100" );
4200             t1.setValue( "0", "0", "00" );
4201             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4202             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4203                 return false;
4204             }
4205             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4206                 return false;
4207             }
4208             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4209                 return false;
4210             }
4211             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4212                 return false;
4213             }
4214             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4215                 return false;
4216             }
4217             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4218                 return false;
4219             }
4220             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4221                 return false;
4222             }
4223             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4224                 return false;
4225             }
4226             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4227                 return false;
4228             }
4229             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4230                 return false;
4231             }
4232         }
4233         catch ( final Exception e ) {
4234             e.printStackTrace( System.out );
4235             return false;
4236         }
4237         return true;
4238     }
4239
4240     private static boolean testGetDistance() {
4241         try {
4242             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4243             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",
4244                                                  new NHXParser() )[ 0 ];
4245             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4246                 return false;
4247             }
4248             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4249                 return false;
4250             }
4251             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4252                 return false;
4253             }
4254             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4255                 return false;
4256             }
4257             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4258                 return false;
4259             }
4260             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4261                 return false;
4262             }
4263             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4264                 return false;
4265             }
4266             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4267                 return false;
4268             }
4269             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4270                 return false;
4271             }
4272             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4273                 return false;
4274             }
4275             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4276                 return false;
4277             }
4278             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4279                 return false;
4280             }
4281             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4282                 return false;
4283             }
4284             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4285                 return false;
4286             }
4287             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4288                 return false;
4289             }
4290             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4291                 return false;
4292             }
4293             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4294                 return false;
4295             }
4296             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4297                 return false;
4298             }
4299             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4300                 return false;
4301             }
4302             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4303                 return false;
4304             }
4305             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4306                 return false;
4307             }
4308             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4309                 return false;
4310             }
4311             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4312                 return false;
4313             }
4314             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4315                 return false;
4316             }
4317             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4318                 return false;
4319             }
4320             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4321                 return false;
4322             }
4323             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4324                 return false;
4325             }
4326             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4327                 return false;
4328             }
4329             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4330                 return false;
4331             }
4332             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4333                 return false;
4334             }
4335             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4336                 return false;
4337             }
4338             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",
4339                                                  new NHXParser() )[ 0 ];
4340             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4341                 return false;
4342             }
4343             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4344                 return false;
4345             }
4346             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4347                 return false;
4348             }
4349             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4350                 return false;
4351             }
4352             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4353                 return false;
4354             }
4355             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4356                 return false;
4357             }
4358             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4359                 return false;
4360             }
4361             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4362                 return false;
4363             }
4364             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4365                 return false;
4366             }
4367             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4368                 return false;
4369             }
4370             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4371                 return false;
4372             }
4373         }
4374         catch ( final Exception e ) {
4375             e.printStackTrace( System.out );
4376             return false;
4377         }
4378         return true;
4379     }
4380
4381     private static boolean testGetLCA() {
4382         try {
4383             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4384             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4385                                                  new NHXParser() )[ 0 ];
4386             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4387             if ( !A.getName().equals( "A" ) ) {
4388                 return false;
4389             }
4390             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4391             if ( !gh.getName().equals( "gh" ) ) {
4392                 return false;
4393             }
4394             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4395             if ( !ab.getName().equals( "ab" ) ) {
4396                 return false;
4397             }
4398             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4399             if ( !ab2.getName().equals( "ab" ) ) {
4400                 return false;
4401             }
4402             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4403             if ( !gh2.getName().equals( "gh" ) ) {
4404                 return false;
4405             }
4406             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4407             if ( !gh3.getName().equals( "gh" ) ) {
4408                 return false;
4409             }
4410             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4411             if ( !abc.getName().equals( "abc" ) ) {
4412                 return false;
4413             }
4414             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4415             if ( !abc2.getName().equals( "abc" ) ) {
4416                 return false;
4417             }
4418             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4419             if ( !abcd.getName().equals( "abcd" ) ) {
4420                 return false;
4421             }
4422             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4423             if ( !abcd2.getName().equals( "abcd" ) ) {
4424                 return false;
4425             }
4426             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4427             if ( !abcdef.getName().equals( "abcdef" ) ) {
4428                 return false;
4429             }
4430             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4431             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4432                 return false;
4433             }
4434             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4435             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4436                 return false;
4437             }
4438             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4439             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4440                 return false;
4441             }
4442             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4443             if ( !abcde.getName().equals( "abcde" ) ) {
4444                 return false;
4445             }
4446             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4447             if ( !abcde2.getName().equals( "abcde" ) ) {
4448                 return false;
4449             }
4450             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4451             if ( !r.getName().equals( "abcdefgh" ) ) {
4452                 return false;
4453             }
4454             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4455             if ( !r2.getName().equals( "abcdefgh" ) ) {
4456                 return false;
4457             }
4458             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4459             if ( !r3.getName().equals( "abcdefgh" ) ) {
4460                 return false;
4461             }
4462             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4463             if ( !abcde3.getName().equals( "abcde" ) ) {
4464                 return false;
4465             }
4466             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4467             if ( !abcde4.getName().equals( "abcde" ) ) {
4468                 return false;
4469             }
4470             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4471             if ( !ab3.getName().equals( "ab" ) ) {
4472                 return false;
4473             }
4474             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4475             if ( !ab4.getName().equals( "ab" ) ) {
4476                 return false;
4477             }
4478             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4479             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4480             if ( !cd.getName().equals( "cd" ) ) {
4481                 return false;
4482             }
4483             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4484             if ( !cd2.getName().equals( "cd" ) ) {
4485                 return false;
4486             }
4487             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4488             if ( !cde.getName().equals( "cde" ) ) {
4489                 return false;
4490             }
4491             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4492             if ( !cde2.getName().equals( "cde" ) ) {
4493                 return false;
4494             }
4495             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4496             if ( !cdef.getName().equals( "cdef" ) ) {
4497                 return false;
4498             }
4499             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4500             if ( !cdef2.getName().equals( "cdef" ) ) {
4501                 return false;
4502             }
4503             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4504             if ( !cdef3.getName().equals( "cdef" ) ) {
4505                 return false;
4506             }
4507             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4508             if ( !rt.getName().equals( "r" ) ) {
4509                 return false;
4510             }
4511             final Phylogeny p3 = factory
4512                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4513                              new NHXParser() )[ 0 ];
4514             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4515             if ( !bc_3.getName().equals( "bc" ) ) {
4516                 return false;
4517             }
4518             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4519             if ( !ac_3.getName().equals( "abc" ) ) {
4520                 return false;
4521             }
4522             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4523             if ( !ad_3.getName().equals( "abcde" ) ) {
4524                 return false;
4525             }
4526             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4527             if ( !af_3.getName().equals( "abcdef" ) ) {
4528                 return false;
4529             }
4530             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4531             if ( !ag_3.getName().equals( "" ) ) {
4532                 return false;
4533             }
4534             if ( !ag_3.isRoot() ) {
4535                 return false;
4536             }
4537             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4538             if ( !al_3.getName().equals( "" ) ) {
4539                 return false;
4540             }
4541             if ( !al_3.isRoot() ) {
4542                 return false;
4543             }
4544             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4545             if ( !kl_3.getName().equals( "" ) ) {
4546                 return false;
4547             }
4548             if ( !kl_3.isRoot() ) {
4549                 return false;
4550             }
4551             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4552             if ( !fl_3.getName().equals( "" ) ) {
4553                 return false;
4554             }
4555             if ( !fl_3.isRoot() ) {
4556                 return false;
4557             }
4558             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4559             if ( !gk_3.getName().equals( "ghijk" ) ) {
4560                 return false;
4561             }
4562             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4563             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4564             if ( !r_4.getName().equals( "r" ) ) {
4565                 return false;
4566             }
4567             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4568             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4569             if ( !r_5.getName().equals( "root" ) ) {
4570                 return false;
4571             }
4572             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4573             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4574             if ( !r_6.getName().equals( "rot" ) ) {
4575                 return false;
4576             }
4577             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4578             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4579             if ( !r_7.getName().equals( "rott" ) ) {
4580                 return false;
4581             }
4582         }
4583         catch ( final Exception e ) {
4584             e.printStackTrace( System.out );
4585             return false;
4586         }
4587         return true;
4588     }
4589
4590     private static boolean testGetLCA2() {
4591         try {
4592             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4593             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
4594             PhylogenyMethods.preOrderReId( p_a );
4595             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
4596                                                                                               p_a.getNode( "a" ) );
4597             if ( !p_a_1.getName().equals( "a" ) ) {
4598                 return false;
4599             }
4600             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4601             PhylogenyMethods.preOrderReId( p_b );
4602             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
4603                                                                                               p_b.getNode( "a" ) );
4604             if ( !p_b_1.getName().equals( "b" ) ) {
4605                 return false;
4606             }
4607             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
4608                                                                                               p_b.getNode( "b" ) );
4609             if ( !p_b_2.getName().equals( "b" ) ) {
4610                 return false;
4611             }
4612             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
4613             PhylogenyMethods.preOrderReId( p_c );
4614             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
4615                                                                                               p_c.getNode( "a" ) );
4616             if ( !p_c_1.getName().equals( "b" ) ) {
4617                 return false;
4618             }
4619             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4620                                                                                               p_c.getNode( "c" ) );
4621             if ( !p_c_2.getName().equals( "c" ) ) {
4622                 System.out.println( p_c_2.getName() );
4623                 System.exit( -1 );
4624                 return false;
4625             }
4626             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4627                                                                                               p_c.getNode( "b" ) );
4628             if ( !p_c_3.getName().equals( "b" ) ) {
4629                 return false;
4630             }
4631             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
4632                                                                                               p_c.getNode( "a" ) );
4633             if ( !p_c_4.getName().equals( "c" ) ) {
4634                 return false;
4635             }
4636             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4637                                                  new NHXParser() )[ 0 ];
4638             PhylogenyMethods.preOrderReId( p1 );
4639             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4640                                                                                           p1.getNode( "A" ) );
4641             if ( !A.getName().equals( "A" ) ) {
4642                 return false;
4643             }
4644             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
4645                                                                                            p1.getNode( "gh" ) );
4646             if ( !gh.getName().equals( "gh" ) ) {
4647                 return false;
4648             }
4649             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4650                                                                                            p1.getNode( "B" ) );
4651             if ( !ab.getName().equals( "ab" ) ) {
4652                 return false;
4653             }
4654             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4655                                                                                             p1.getNode( "A" ) );
4656             if ( !ab2.getName().equals( "ab" ) ) {
4657                 return false;
4658             }
4659             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4660                                                                                             p1.getNode( "G" ) );
4661             if ( !gh2.getName().equals( "gh" ) ) {
4662                 return false;
4663             }
4664             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
4665                                                                                             p1.getNode( "H" ) );
4666             if ( !gh3.getName().equals( "gh" ) ) {
4667                 return false;
4668             }
4669             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
4670                                                                                             p1.getNode( "A" ) );
4671             if ( !abc.getName().equals( "abc" ) ) {
4672                 return false;
4673             }
4674             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4675                                                                                              p1.getNode( "C" ) );
4676             if ( !abc2.getName().equals( "abc" ) ) {
4677                 return false;
4678             }
4679             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4680                                                                                              p1.getNode( "D" ) );
4681             if ( !abcd.getName().equals( "abcd" ) ) {
4682                 return false;
4683             }
4684             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
4685                                                                                               p1.getNode( "A" ) );
4686             if ( !abcd2.getName().equals( "abcd" ) ) {
4687                 return false;
4688             }
4689             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4690                                                                                                p1.getNode( "F" ) );
4691             if ( !abcdef.getName().equals( "abcdef" ) ) {
4692                 return false;
4693             }
4694             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4695                                                                                                 p1.getNode( "A" ) );
4696             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4697                 return false;
4698             }
4699             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4700                                                                                                 p1.getNode( "F" ) );
4701             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4702                 return false;
4703             }
4704             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4705                                                                                                 p1.getNode( "ab" ) );
4706             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4707                 return false;
4708             }
4709             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4710                                                                                               p1.getNode( "E" ) );
4711             if ( !abcde.getName().equals( "abcde" ) ) {
4712                 return false;
4713             }
4714             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4715                                                                                                p1.getNode( "A" ) );
4716             if ( !abcde2.getName().equals( "abcde" ) ) {
4717                 return false;
4718             }
4719             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
4720                                                                                           p1.getNode( "abcdefgh" ) );
4721             if ( !r.getName().equals( "abcdefgh" ) ) {
4722                 return false;
4723             }
4724             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4725                                                                                            p1.getNode( "H" ) );
4726             if ( !r2.getName().equals( "abcdefgh" ) ) {
4727                 return false;
4728             }
4729             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4730                                                                                            p1.getNode( "A" ) );
4731             if ( !r3.getName().equals( "abcdefgh" ) ) {
4732                 return false;
4733             }
4734             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4735                                                                                                p1.getNode( "abcde" ) );
4736             if ( !abcde3.getName().equals( "abcde" ) ) {
4737                 return false;
4738             }
4739             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
4740                                                                                                p1.getNode( "E" ) );
4741             if ( !abcde4.getName().equals( "abcde" ) ) {
4742                 return false;
4743             }
4744             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4745                                                                                             p1.getNode( "B" ) );
4746             if ( !ab3.getName().equals( "ab" ) ) {
4747                 return false;
4748             }
4749             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4750                                                                                             p1.getNode( "ab" ) );
4751             if ( !ab4.getName().equals( "ab" ) ) {
4752                 return false;
4753             }
4754             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4755             PhylogenyMethods.preOrderReId( p2 );
4756             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4757                                                                                            p2.getNode( "d" ) );
4758             if ( !cd.getName().equals( "cd" ) ) {
4759                 return false;
4760             }
4761             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4762                                                                                             p2.getNode( "c" ) );
4763             if ( !cd2.getName().equals( "cd" ) ) {
4764                 return false;
4765             }
4766             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4767                                                                                             p2.getNode( "e" ) );
4768             if ( !cde.getName().equals( "cde" ) ) {
4769                 return false;
4770             }
4771             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
4772                                                                                              p2.getNode( "c" ) );
4773             if ( !cde2.getName().equals( "cde" ) ) {
4774                 return false;
4775             }
4776             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4777                                                                                              p2.getNode( "f" ) );
4778             if ( !cdef.getName().equals( "cdef" ) ) {
4779                 return false;
4780             }
4781             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4782                                                                                               p2.getNode( "f" ) );
4783             if ( !cdef2.getName().equals( "cdef" ) ) {
4784                 return false;
4785             }
4786             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
4787                                                                                               p2.getNode( "d" ) );
4788             if ( !cdef3.getName().equals( "cdef" ) ) {
4789                 return false;
4790             }
4791             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4792                                                                                            p2.getNode( "a" ) );
4793             if ( !rt.getName().equals( "r" ) ) {
4794                 return false;
4795             }
4796             final Phylogeny p3 = factory
4797                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4798                              new NHXParser() )[ 0 ];
4799             PhylogenyMethods.preOrderReId( p3 );
4800             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
4801                                                                                              p3.getNode( "c" ) );
4802             if ( !bc_3.getName().equals( "bc" ) ) {
4803                 return false;
4804             }
4805             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4806                                                                                              p3.getNode( "c" ) );
4807             if ( !ac_3.getName().equals( "abc" ) ) {
4808                 return false;
4809             }
4810             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4811                                                                                              p3.getNode( "d" ) );
4812             if ( !ad_3.getName().equals( "abcde" ) ) {
4813                 return false;
4814             }
4815             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4816                                                                                              p3.getNode( "f" ) );
4817             if ( !af_3.getName().equals( "abcdef" ) ) {
4818                 return false;
4819             }
4820             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4821                                                                                              p3.getNode( "g" ) );
4822             if ( !ag_3.getName().equals( "" ) ) {
4823                 return false;
4824             }
4825             if ( !ag_3.isRoot() ) {
4826                 return false;
4827             }
4828             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4829                                                                                              p3.getNode( "l" ) );
4830             if ( !al_3.getName().equals( "" ) ) {
4831                 return false;
4832             }
4833             if ( !al_3.isRoot() ) {
4834                 return false;
4835             }
4836             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
4837                                                                                              p3.getNode( "l" ) );
4838             if ( !kl_3.getName().equals( "" ) ) {
4839                 return false;
4840             }
4841             if ( !kl_3.isRoot() ) {
4842                 return false;
4843             }
4844             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
4845                                                                                              p3.getNode( "l" ) );
4846             if ( !fl_3.getName().equals( "" ) ) {
4847                 return false;
4848             }
4849             if ( !fl_3.isRoot() ) {
4850                 return false;
4851             }
4852             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
4853                                                                                              p3.getNode( "k" ) );
4854             if ( !gk_3.getName().equals( "ghijk" ) ) {
4855                 return false;
4856             }
4857             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4858             PhylogenyMethods.preOrderReId( p4 );
4859             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
4860                                                                                             p4.getNode( "c" ) );
4861             if ( !r_4.getName().equals( "r" ) ) {
4862                 return false;
4863             }
4864             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4865             PhylogenyMethods.preOrderReId( p5 );
4866             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
4867                                                                                             p5.getNode( "c" ) );
4868             if ( !r_5.getName().equals( "root" ) ) {
4869                 return false;
4870             }
4871             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4872             PhylogenyMethods.preOrderReId( p6 );
4873             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
4874                                                                                             p6.getNode( "a" ) );
4875             if ( !r_6.getName().equals( "rot" ) ) {
4876                 return false;
4877             }
4878             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4879             PhylogenyMethods.preOrderReId( p7 );
4880             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4881                                                                                             p7.getNode( "e" ) );
4882             if ( !r_7.getName().equals( "rott" ) ) {
4883                 return false;
4884             }
4885             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4886                                                                                              p7.getNode( "a" ) );
4887             if ( !r_71.getName().equals( "rott" ) ) {
4888                 return false;
4889             }
4890             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4891                                                                                              p7.getNode( "rott" ) );
4892             if ( !r_72.getName().equals( "rott" ) ) {
4893                 return false;
4894             }
4895             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4896                                                                                              p7.getNode( "a" ) );
4897             if ( !r_73.getName().equals( "rott" ) ) {
4898                 return false;
4899             }
4900             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4901                                                                                              p7.getNode( "rott" ) );
4902             if ( !r_74.getName().equals( "rott" ) ) {
4903                 return false;
4904             }
4905             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4906                                                                                              p7.getNode( "e" ) );
4907             if ( !r_75.getName().equals( "e" ) ) {
4908                 return false;
4909             }
4910         }
4911         catch ( final Exception e ) {
4912             e.printStackTrace( System.out );
4913             return false;
4914         }
4915         return true;
4916     }
4917
4918     private static boolean testHmmscanOutputParser() {
4919         final String test_dir = Test.PATH_TO_TEST_DATA;
4920         try {
4921             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4922                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4923             parser1.parse();
4924             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4925                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4926             final List<Protein> proteins = parser2.parse();
4927             if ( parser2.getProteinsEncountered() != 4 ) {
4928                 return false;
4929             }
4930             if ( proteins.size() != 4 ) {
4931                 return false;
4932             }
4933             if ( parser2.getDomainsEncountered() != 69 ) {
4934                 return false;
4935             }
4936             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4937                 return false;
4938             }
4939             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4940                 return false;
4941             }
4942             final Protein p1 = proteins.get( 0 );
4943             if ( p1.getNumberOfProteinDomains() != 15 ) {
4944                 return false;
4945             }
4946             if ( p1.getLength() != 850 ) {
4947                 return false;
4948             }
4949             final Protein p2 = proteins.get( 1 );
4950             if ( p2.getNumberOfProteinDomains() != 51 ) {
4951                 return false;
4952             }
4953             if ( p2.getLength() != 1291 ) {
4954                 return false;
4955             }
4956             final Protein p3 = proteins.get( 2 );
4957             if ( p3.getNumberOfProteinDomains() != 2 ) {
4958                 return false;
4959             }
4960             final Protein p4 = proteins.get( 3 );
4961             if ( p4.getNumberOfProteinDomains() != 1 ) {
4962                 return false;
4963             }
4964             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4965                 return false;
4966             }
4967             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4968                 return false;
4969             }
4970             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4971                 return false;
4972             }
4973             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4974                 return false;
4975             }
4976             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4977                 return false;
4978             }
4979             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4980                 return false;
4981             }
4982             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4983                 return false;
4984             }
4985             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4986                 return false;
4987             }
4988             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4989                 return false;
4990             }
4991         }
4992         catch ( final Exception e ) {
4993             e.printStackTrace( System.out );
4994             return false;
4995         }
4996         return true;
4997     }
4998
4999     private static boolean testLastExternalNodeMethods() {
5000         try {
5001             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5002             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5003             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5004             final PhylogenyNode n1 = t0.getNode( "A" );
5005             if ( n1.isLastExternalNode() ) {
5006                 return false;
5007             }
5008             final PhylogenyNode n2 = t0.getNode( "B" );
5009             if ( n2.isLastExternalNode() ) {
5010                 return false;
5011             }
5012             final PhylogenyNode n3 = t0.getNode( "C" );
5013             if ( n3.isLastExternalNode() ) {
5014                 return false;
5015             }
5016             final PhylogenyNode n4 = t0.getNode( "D" );
5017             if ( !n4.isLastExternalNode() ) {
5018                 return false;
5019             }
5020         }
5021         catch ( final Exception e ) {
5022             e.printStackTrace( System.out );
5023             return false;
5024         }
5025         return true;
5026     }
5027
5028     private static boolean testLevelOrderIterator() {
5029         try {
5030             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5031             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5032             PhylogenyNodeIterator it0;
5033             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5034                 it0.next();
5035             }
5036             for( it0.reset(); it0.hasNext(); ) {
5037                 it0.next();
5038             }
5039             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5040             if ( !it.next().getName().equals( "r" ) ) {
5041                 return false;
5042             }
5043             if ( !it.next().getName().equals( "ab" ) ) {
5044                 return false;
5045             }
5046             if ( !it.next().getName().equals( "cd" ) ) {
5047                 return false;
5048             }
5049             if ( !it.next().getName().equals( "A" ) ) {
5050                 return false;
5051             }
5052             if ( !it.next().getName().equals( "B" ) ) {
5053                 return false;
5054             }
5055             if ( !it.next().getName().equals( "C" ) ) {
5056                 return false;
5057             }
5058             if ( !it.next().getName().equals( "D" ) ) {
5059                 return false;
5060             }
5061             if ( it.hasNext() ) {
5062                 return false;
5063             }
5064             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",
5065                                                  new NHXParser() )[ 0 ];
5066             PhylogenyNodeIterator it2;
5067             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5068                 it2.next();
5069             }
5070             for( it2.reset(); it2.hasNext(); ) {
5071                 it2.next();
5072             }
5073             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5074             if ( !it3.next().getName().equals( "r" ) ) {
5075                 return false;
5076             }
5077             if ( !it3.next().getName().equals( "abc" ) ) {
5078                 return false;
5079             }
5080             if ( !it3.next().getName().equals( "defg" ) ) {
5081                 return false;
5082             }
5083             if ( !it3.next().getName().equals( "A" ) ) {
5084                 return false;
5085             }
5086             if ( !it3.next().getName().equals( "B" ) ) {
5087                 return false;
5088             }
5089             if ( !it3.next().getName().equals( "C" ) ) {
5090                 return false;
5091             }
5092             if ( !it3.next().getName().equals( "D" ) ) {
5093                 return false;
5094             }
5095             if ( !it3.next().getName().equals( "E" ) ) {
5096                 return false;
5097             }
5098             if ( !it3.next().getName().equals( "F" ) ) {
5099                 return false;
5100             }
5101             if ( !it3.next().getName().equals( "G" ) ) {
5102                 return false;
5103             }
5104             if ( !it3.next().getName().equals( "1" ) ) {
5105                 return false;
5106             }
5107             if ( !it3.next().getName().equals( "2" ) ) {
5108                 return false;
5109             }
5110             if ( !it3.next().getName().equals( "3" ) ) {
5111                 return false;
5112             }
5113             if ( !it3.next().getName().equals( "4" ) ) {
5114                 return false;
5115             }
5116             if ( !it3.next().getName().equals( "5" ) ) {
5117                 return false;
5118             }
5119             if ( !it3.next().getName().equals( "6" ) ) {
5120                 return false;
5121             }
5122             if ( !it3.next().getName().equals( "f1" ) ) {
5123                 return false;
5124             }
5125             if ( !it3.next().getName().equals( "f2" ) ) {
5126                 return false;
5127             }
5128             if ( !it3.next().getName().equals( "f3" ) ) {
5129                 return false;
5130             }
5131             if ( !it3.next().getName().equals( "a" ) ) {
5132                 return false;
5133             }
5134             if ( !it3.next().getName().equals( "b" ) ) {
5135                 return false;
5136             }
5137             if ( !it3.next().getName().equals( "f21" ) ) {
5138                 return false;
5139             }
5140             if ( !it3.next().getName().equals( "X" ) ) {
5141                 return false;
5142             }
5143             if ( !it3.next().getName().equals( "Y" ) ) {
5144                 return false;
5145             }
5146             if ( !it3.next().getName().equals( "Z" ) ) {
5147                 return false;
5148             }
5149             if ( it3.hasNext() ) {
5150                 return false;
5151             }
5152             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5153             PhylogenyNodeIterator it4;
5154             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5155                 it4.next();
5156             }
5157             for( it4.reset(); it4.hasNext(); ) {
5158                 it4.next();
5159             }
5160             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5161             if ( !it5.next().getName().equals( "r" ) ) {
5162                 return false;
5163             }
5164             if ( !it5.next().getName().equals( "A" ) ) {
5165                 return false;
5166             }
5167             if ( !it5.next().getName().equals( "B" ) ) {
5168                 return false;
5169             }
5170             if ( !it5.next().getName().equals( "C" ) ) {
5171                 return false;
5172             }
5173             if ( !it5.next().getName().equals( "D" ) ) {
5174                 return false;
5175             }
5176             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5177             PhylogenyNodeIterator it6;
5178             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5179                 it6.next();
5180             }
5181             for( it6.reset(); it6.hasNext(); ) {
5182                 it6.next();
5183             }
5184             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5185             if ( !it7.next().getName().equals( "A" ) ) {
5186                 return false;
5187             }
5188             if ( it.hasNext() ) {
5189                 return false;
5190             }
5191         }
5192         catch ( final Exception e ) {
5193             e.printStackTrace( System.out );
5194             return false;
5195         }
5196         return true;
5197     }
5198
5199     private static boolean testMafft( final String path ) {
5200         try {
5201             final List<String> opts = new ArrayList<String>();
5202             opts.add( "--maxiterate" );
5203             opts.add( "1000" );
5204             opts.add( "--localpair" );
5205             opts.add( "--quiet" );
5206             Msa msa = null;
5207             final MsaInferrer mafft = Mafft.createInstance( path );
5208             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5209             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5210                 return false;
5211             }
5212             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5213                 return false;
5214             }
5215         }
5216         catch ( final Exception e ) {
5217             e.printStackTrace( System.out );
5218             return false;
5219         }
5220         return true;
5221     }
5222
5223     private static boolean testMidpointrooting() {
5224         try {
5225             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5226             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5227             PhylogenyMethods.midpointRoot( t0 );
5228             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5229                 return false;
5230             }
5231             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5232                 return false;
5233             }
5234             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5235                            1 ) ) {
5236                 return false;
5237             }
5238             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",
5239                                                  new NHXParser() )[ 0 ];
5240             if ( !t1.isRooted() ) {
5241                 return false;
5242             }
5243             PhylogenyMethods.midpointRoot( t1 );
5244             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5245                 return false;
5246             }
5247             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5248                 return false;
5249             }
5250             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5251                 return false;
5252             }
5253             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5254                 return false;
5255             }
5256             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5257                 return false;
5258             }
5259             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5260                 return false;
5261             }
5262             t1.reRoot( t1.getNode( "A" ) );
5263             PhylogenyMethods.midpointRoot( t1 );
5264             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5265                 return false;
5266             }
5267             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5268                 return false;
5269             }
5270             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5271                 return false;
5272             }
5273             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5274                 return false;
5275             }
5276             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5277                 System.exit( -1 );
5278                 return false;
5279             }
5280             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5281                 return false;
5282             }
5283         }
5284         catch ( final Exception e ) {
5285             e.printStackTrace( System.out );
5286             return false;
5287         }
5288         return true;
5289     }
5290
5291     private static boolean testMsaQualityMethod() {
5292         try {
5293             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5294             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5295             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5296             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5297             final List<Sequence> l = new ArrayList<Sequence>();
5298             l.add( s0 );
5299             l.add( s1 );
5300             l.add( s2 );
5301             l.add( s3 );
5302             final Msa msa = BasicMsa.createInstance( l );
5303             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5304                 return false;
5305             }
5306             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5307                 return false;
5308             }
5309             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5310                 return false;
5311             }
5312             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5313                 return false;
5314             }
5315         }
5316         catch ( final Exception e ) {
5317             e.printStackTrace( System.out );
5318             return false;
5319         }
5320         return true;
5321     }
5322
5323     private static boolean testNextNodeWithCollapsing() {
5324         try {
5325             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5326             PhylogenyNode n;
5327             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5328             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5329             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5330             t0.getNode( "cd" ).setCollapse( true );
5331             t0.getNode( "cde" ).setCollapse( true );
5332             n = t0.getFirstExternalNode();
5333             while ( n != null ) {
5334                 ext.add( n );
5335                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5336             }
5337             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5338                 return false;
5339             }
5340             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5341                 return false;
5342             }
5343             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5344                 return false;
5345             }
5346             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5347                 return false;
5348             }
5349             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5350                 return false;
5351             }
5352             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5353                 return false;
5354             }
5355             ext.clear();
5356             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5357             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5358             t1.getNode( "ab" ).setCollapse( true );
5359             t1.getNode( "cd" ).setCollapse( true );
5360             t1.getNode( "cde" ).setCollapse( true );
5361             n = t1.getNode( "ab" );
5362             ext = new ArrayList<PhylogenyNode>();
5363             while ( n != null ) {
5364                 ext.add( n );
5365                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5366             }
5367             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5368                 return false;
5369             }
5370             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5371                 return false;
5372             }
5373             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5374                 return false;
5375             }
5376             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5377                 return false;
5378             }
5379             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5380                 return false;
5381             }
5382             //
5383             //
5384             ext.clear();
5385             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5386             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5387             t2.getNode( "ab" ).setCollapse( true );
5388             t2.getNode( "cd" ).setCollapse( true );
5389             t2.getNode( "cde" ).setCollapse( true );
5390             t2.getNode( "c" ).setCollapse( true );
5391             t2.getNode( "d" ).setCollapse( true );
5392             t2.getNode( "e" ).setCollapse( true );
5393             t2.getNode( "gh" ).setCollapse( true );
5394             n = t2.getNode( "ab" );
5395             ext = new ArrayList<PhylogenyNode>();
5396             while ( n != null ) {
5397                 ext.add( n );
5398                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5399             }
5400             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5401                 return false;
5402             }
5403             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5404                 return false;
5405             }
5406             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5407                 return false;
5408             }
5409             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5410                 return false;
5411             }
5412             //
5413             //
5414             ext.clear();
5415             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5416             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5417             t3.getNode( "ab" ).setCollapse( true );
5418             t3.getNode( "cd" ).setCollapse( true );
5419             t3.getNode( "cde" ).setCollapse( true );
5420             t3.getNode( "c" ).setCollapse( true );
5421             t3.getNode( "d" ).setCollapse( true );
5422             t3.getNode( "e" ).setCollapse( true );
5423             t3.getNode( "gh" ).setCollapse( true );
5424             t3.getNode( "fgh" ).setCollapse( true );
5425             n = t3.getNode( "ab" );
5426             ext = new ArrayList<PhylogenyNode>();
5427             while ( n != null ) {
5428                 ext.add( n );
5429                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5430             }
5431             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5432                 return false;
5433             }
5434             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5435                 return false;
5436             }
5437             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5438                 return false;
5439             }
5440             //
5441             //
5442             ext.clear();
5443             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5444             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5445             t4.getNode( "ab" ).setCollapse( true );
5446             t4.getNode( "cd" ).setCollapse( true );
5447             t4.getNode( "cde" ).setCollapse( true );
5448             t4.getNode( "c" ).setCollapse( true );
5449             t4.getNode( "d" ).setCollapse( true );
5450             t4.getNode( "e" ).setCollapse( true );
5451             t4.getNode( "gh" ).setCollapse( true );
5452             t4.getNode( "fgh" ).setCollapse( true );
5453             t4.getNode( "abcdefgh" ).setCollapse( true );
5454             n = t4.getNode( "abcdefgh" );
5455             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5456                 return false;
5457             }
5458             //
5459             //
5460             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5461             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5462             ext.clear();
5463             n = t5.getFirstExternalNode();
5464             while ( n != null ) {
5465                 ext.add( n );
5466                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5467             }
5468             if ( ext.size() != 8 ) {
5469                 return false;
5470             }
5471             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5472                 return false;
5473             }
5474             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5475                 return false;
5476             }
5477             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5478                 return false;
5479             }
5480             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5481                 return false;
5482             }
5483             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5484                 return false;
5485             }
5486             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5487                 return false;
5488             }
5489             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5490                 return false;
5491             }
5492             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5493                 return false;
5494             }
5495             //
5496             //
5497             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5498             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5499             ext.clear();
5500             t6.getNode( "ab" ).setCollapse( true );
5501             n = t6.getNode( "ab" );
5502             while ( n != null ) {
5503                 ext.add( n );
5504                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5505             }
5506             if ( ext.size() != 7 ) {
5507                 return false;
5508             }
5509             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5510                 return false;
5511             }
5512             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5513                 return false;
5514             }
5515             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5516                 return false;
5517             }
5518             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5519                 return false;
5520             }
5521             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5522                 return false;
5523             }
5524             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5525                 return false;
5526             }
5527             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5528                 return false;
5529             }
5530             //
5531             //
5532             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5533             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5534             ext.clear();
5535             t7.getNode( "cd" ).setCollapse( true );
5536             n = t7.getNode( "a" );
5537             while ( n != null ) {
5538                 ext.add( n );
5539                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5540             }
5541             if ( ext.size() != 7 ) {
5542                 return false;
5543             }
5544             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5545                 return false;
5546             }
5547             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5548                 return false;
5549             }
5550             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5551                 return false;
5552             }
5553             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5554                 return false;
5555             }
5556             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5557                 return false;
5558             }
5559             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5560                 return false;
5561             }
5562             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5563                 return false;
5564             }
5565             //
5566             //
5567             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5568             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5569             ext.clear();
5570             t8.getNode( "cd" ).setCollapse( true );
5571             t8.getNode( "c" ).setCollapse( true );
5572             t8.getNode( "d" ).setCollapse( true );
5573             n = t8.getNode( "a" );
5574             while ( n != null ) {
5575                 ext.add( n );
5576                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5577             }
5578             if ( ext.size() != 7 ) {
5579                 return false;
5580             }
5581             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5582                 return false;
5583             }
5584             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5585                 return false;
5586             }
5587             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5588                 System.out.println( "2 fail" );
5589                 return false;
5590             }
5591             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5592                 return false;
5593             }
5594             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5595                 return false;
5596             }
5597             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5598                 return false;
5599             }
5600             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5601                 return false;
5602             }
5603             //
5604             //
5605             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5606             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
5607             ext.clear();
5608             t9.getNode( "gh" ).setCollapse( true );
5609             n = t9.getNode( "a" );
5610             while ( n != null ) {
5611                 ext.add( n );
5612                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5613             }
5614             if ( ext.size() != 7 ) {
5615                 return false;
5616             }
5617             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5618                 return false;
5619             }
5620             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5621                 return false;
5622             }
5623             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5624                 return false;
5625             }
5626             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5627                 return false;
5628             }
5629             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5630                 return false;
5631             }
5632             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5633                 return false;
5634             }
5635             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5636                 return false;
5637             }
5638             //
5639             //
5640             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5641             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
5642             ext.clear();
5643             t10.getNode( "gh" ).setCollapse( true );
5644             t10.getNode( "g" ).setCollapse( true );
5645             t10.getNode( "h" ).setCollapse( true );
5646             n = t10.getNode( "a" );
5647             while ( n != null ) {
5648                 ext.add( n );
5649                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5650             }
5651             if ( ext.size() != 7 ) {
5652                 return false;
5653             }
5654             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5655                 return false;
5656             }
5657             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5658                 return false;
5659             }
5660             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5661                 return false;
5662             }
5663             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5664                 return false;
5665             }
5666             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5667                 return false;
5668             }
5669             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5670                 return false;
5671             }
5672             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5673                 return false;
5674             }
5675             //
5676             //
5677             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5678             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
5679             ext.clear();
5680             t11.getNode( "gh" ).setCollapse( true );
5681             t11.getNode( "fgh" ).setCollapse( true );
5682             n = t11.getNode( "a" );
5683             while ( n != null ) {
5684                 ext.add( n );
5685                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5686             }
5687             if ( ext.size() != 6 ) {
5688                 return false;
5689             }
5690             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5691                 return false;
5692             }
5693             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5694                 return false;
5695             }
5696             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5697                 return false;
5698             }
5699             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5700                 return false;
5701             }
5702             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5703                 return false;
5704             }
5705             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5706                 return false;
5707             }
5708             //
5709             //
5710             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5711             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
5712             ext.clear();
5713             t12.getNode( "gh" ).setCollapse( true );
5714             t12.getNode( "fgh" ).setCollapse( true );
5715             t12.getNode( "g" ).setCollapse( true );
5716             t12.getNode( "h" ).setCollapse( true );
5717             t12.getNode( "f" ).setCollapse( true );
5718             n = t12.getNode( "a" );
5719             while ( n != null ) {
5720                 ext.add( n );
5721                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5722             }
5723             if ( ext.size() != 6 ) {
5724                 return false;
5725             }
5726             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5727                 return false;
5728             }
5729             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5730                 return false;
5731             }
5732             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5733                 return false;
5734             }
5735             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5736                 return false;
5737             }
5738             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5739                 return false;
5740             }
5741             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5742                 return false;
5743             }
5744             //
5745             //
5746             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5747             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
5748             ext.clear();
5749             t13.getNode( "ab" ).setCollapse( true );
5750             t13.getNode( "b" ).setCollapse( true );
5751             t13.getNode( "fgh" ).setCollapse( true );
5752             t13.getNode( "gh" ).setCollapse( true );
5753             n = t13.getNode( "ab" );
5754             while ( n != null ) {
5755                 ext.add( n );
5756                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5757             }
5758             if ( ext.size() != 5 ) {
5759                 return false;
5760             }
5761             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5762                 return false;
5763             }
5764             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5765                 return false;
5766             }
5767             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5768                 return false;
5769             }
5770             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5771                 return false;
5772             }
5773             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5774                 return false;
5775             }
5776             //
5777             //
5778             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
5779             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
5780             ext.clear();
5781             t14.getNode( "ab" ).setCollapse( true );
5782             t14.getNode( "a" ).setCollapse( true );
5783             t14.getNode( "fgh" ).setCollapse( true );
5784             t14.getNode( "gh" ).setCollapse( true );
5785             n = t14.getNode( "ab" );
5786             while ( n != null ) {
5787                 ext.add( n );
5788                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5789             }
5790             if ( ext.size() != 5 ) {
5791                 return false;
5792             }
5793             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5794                 return false;
5795             }
5796             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5797                 return false;
5798             }
5799             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5800                 return false;
5801             }
5802             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5803                 return false;
5804             }
5805             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5806                 return false;
5807             }
5808             //
5809             //
5810             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" );
5811             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
5812             ext.clear();
5813             t15.getNode( "ab" ).setCollapse( true );
5814             t15.getNode( "a" ).setCollapse( true );
5815             t15.getNode( "fgh" ).setCollapse( true );
5816             t15.getNode( "gh" ).setCollapse( true );
5817             n = t15.getNode( "ab" );
5818             while ( n != null ) {
5819                 ext.add( n );
5820                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5821             }
5822             if ( ext.size() != 6 ) {
5823                 return false;
5824             }
5825             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5826                 return false;
5827             }
5828             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5829                 return false;
5830             }
5831             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5832                 return false;
5833             }
5834             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5835                 return false;
5836             }
5837             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
5838                 return false;
5839             }
5840             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5841                 return false;
5842             }
5843             //
5844             //
5845             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" );
5846             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
5847             ext.clear();
5848             t16.getNode( "ab" ).setCollapse( true );
5849             t16.getNode( "a" ).setCollapse( true );
5850             t16.getNode( "fgh" ).setCollapse( true );
5851             t16.getNode( "gh" ).setCollapse( true );
5852             t16.getNode( "cd" ).setCollapse( true );
5853             t16.getNode( "cde" ).setCollapse( true );
5854             t16.getNode( "d" ).setCollapse( true );
5855             t16.getNode( "x" ).setCollapse( true );
5856             n = t16.getNode( "ab" );
5857             while ( n != null ) {
5858                 ext.add( n );
5859                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5860             }
5861             if ( ext.size() != 4 ) {
5862                 return false;
5863             }
5864             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5865                 return false;
5866             }
5867             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5868                 return false;
5869             }
5870             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
5871                 return false;
5872             }
5873             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
5874                 return false;
5875             }
5876         }
5877         catch ( final Exception e ) {
5878             e.printStackTrace( System.out );
5879             return false;
5880         }
5881         return true;
5882     }
5883
5884     private static boolean testNexusCharactersParsing() {
5885         try {
5886             final NexusCharactersParser parser = new NexusCharactersParser();
5887             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
5888             parser.parse();
5889             String[] labels = parser.getCharStateLabels();
5890             if ( labels.length != 7 ) {
5891                 return false;
5892             }
5893             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5894                 return false;
5895             }
5896             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5897                 return false;
5898             }
5899             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5900                 return false;
5901             }
5902             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5903                 return false;
5904             }
5905             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5906                 return false;
5907             }
5908             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5909                 return false;
5910             }
5911             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5912                 return false;
5913             }
5914             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5915             parser.parse();
5916             labels = parser.getCharStateLabels();
5917             if ( labels.length != 7 ) {
5918                 return false;
5919             }
5920             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5921                 return false;
5922             }
5923             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5924                 return false;
5925             }
5926             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5927                 return false;
5928             }
5929             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5930                 return false;
5931             }
5932             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5933                 return false;
5934             }
5935             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5936                 return false;
5937             }
5938             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5939                 return false;
5940             }
5941         }
5942         catch ( final Exception e ) {
5943             e.printStackTrace( System.out );
5944             return false;
5945         }
5946         return true;
5947     }
5948
5949     private static boolean testNexusMatrixParsing() {
5950         try {
5951             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
5952             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
5953             parser.parse();
5954             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
5955             if ( m.getNumberOfCharacters() != 9 ) {
5956                 return false;
5957             }
5958             if ( m.getNumberOfIdentifiers() != 5 ) {
5959                 return false;
5960             }
5961             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
5962                 return false;
5963             }
5964             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
5965                 return false;
5966             }
5967             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
5968                 return false;
5969             }
5970             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
5971                 return false;
5972             }
5973             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
5974                 return false;
5975             }
5976             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
5977                 return false;
5978             }
5979             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
5980                 return false;
5981             }
5982             //            if ( labels.length != 7 ) {
5983             //                return false;
5984             //            }
5985             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5986             //                return false;
5987             //            }
5988             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5989             //                return false;
5990             //            }
5991             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5992             //                return false;
5993             //            }
5994             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5995             //                return false;
5996             //            }
5997             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5998             //                return false;
5999             //            }
6000             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6001             //                return false;
6002             //            }
6003             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6004             //                return false;
6005             //            }
6006             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6007             //            parser.parse();
6008             //            labels = parser.getCharStateLabels();
6009             //            if ( labels.length != 7 ) {
6010             //                return false;
6011             //            }
6012             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6013             //                return false;
6014             //            }
6015             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6016             //                return false;
6017             //            }
6018             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6019             //                return false;
6020             //            }
6021             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6022             //                return false;
6023             //            }
6024             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6025             //                return false;
6026             //            }
6027             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6028             //                return false;
6029             //            }
6030             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6031             //                return false;
6032             //            }
6033         }
6034         catch ( final Exception e ) {
6035             e.printStackTrace( System.out );
6036             return false;
6037         }
6038         return true;
6039     }
6040
6041     private static boolean testNexusTreeParsing() {
6042         try {
6043             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6044             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6045             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6046             if ( phylogenies.length != 1 ) {
6047                 return false;
6048             }
6049             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6050                 return false;
6051             }
6052             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6053                 return false;
6054             }
6055             phylogenies = null;
6056             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6057             if ( phylogenies.length != 1 ) {
6058                 return false;
6059             }
6060             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6061                 return false;
6062             }
6063             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6064                 return false;
6065             }
6066             phylogenies = null;
6067             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6068             if ( phylogenies.length != 1 ) {
6069                 return false;
6070             }
6071             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6072                 return false;
6073             }
6074             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6075                 return false;
6076             }
6077             if ( phylogenies[ 0 ].isRooted() ) {
6078                 return false;
6079             }
6080             phylogenies = null;
6081             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6082             if ( phylogenies.length != 18 ) {
6083                 return false;
6084             }
6085             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6086                 return false;
6087             }
6088             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6089                 return false;
6090             }
6091             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6092                 return false;
6093             }
6094             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6095                 return false;
6096             }
6097             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6098                 return false;
6099             }
6100             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6101                 return false;
6102             }
6103             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6104                 return false;
6105             }
6106             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6107                 return false;
6108             }
6109             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6110                 return false;
6111             }
6112             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6113                 return false;
6114             }
6115             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6116                 return false;
6117             }
6118             if ( phylogenies[ 8 ].isRooted() ) {
6119                 return false;
6120             }
6121             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6122                 return false;
6123             }
6124             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6125                 return false;
6126             }
6127             if ( !phylogenies[ 9 ].isRooted() ) {
6128                 return false;
6129             }
6130             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6131                 return false;
6132             }
6133             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6134                 return false;
6135             }
6136             if ( !phylogenies[ 10 ].isRooted() ) {
6137                 return false;
6138             }
6139             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6140                 return false;
6141             }
6142             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6143                 return false;
6144             }
6145             if ( phylogenies[ 11 ].isRooted() ) {
6146                 return false;
6147             }
6148             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6149                 return false;
6150             }
6151             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6152                 return false;
6153             }
6154             if ( !phylogenies[ 12 ].isRooted() ) {
6155                 return false;
6156             }
6157             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6158                 return false;
6159             }
6160             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6161                 return false;
6162             }
6163             if ( !phylogenies[ 13 ].isRooted() ) {
6164                 return false;
6165             }
6166             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6167                 return false;
6168             }
6169             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6170                 return false;
6171             }
6172             if ( !phylogenies[ 14 ].isRooted() ) {
6173                 return false;
6174             }
6175             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6176                 return false;
6177             }
6178             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6179                 return false;
6180             }
6181             if ( phylogenies[ 15 ].isRooted() ) {
6182                 return false;
6183             }
6184             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6185                 return false;
6186             }
6187             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6188                 return false;
6189             }
6190             if ( !phylogenies[ 16 ].isRooted() ) {
6191                 return false;
6192             }
6193             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6194                 return false;
6195             }
6196             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6197                 return false;
6198             }
6199             if ( phylogenies[ 17 ].isRooted() ) {
6200                 return false;
6201             }
6202             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6203                 return false;
6204             }
6205         }
6206         catch ( final Exception e ) {
6207             e.printStackTrace( System.out );
6208             return false;
6209         }
6210         return true;
6211     }
6212
6213     private static boolean testNexusTreeParsingIterating() {
6214         try {
6215             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6216             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6217             if ( !p.hasNext() ) {
6218                 return false;
6219             }
6220             Phylogeny phy = p.next();
6221             if ( phy == null ) {
6222                 return false;
6223             }
6224             if ( phy.getNumberOfExternalNodes() != 25 ) {
6225                 return false;
6226             }
6227             if ( !phy.getName().equals( "" ) ) {
6228                 return false;
6229             }
6230             if ( p.hasNext() ) {
6231                 return false;
6232             }
6233             phy = p.next();
6234             if ( phy != null ) {
6235                 return false;
6236             }
6237             //
6238             p.reset();
6239             if ( !p.hasNext() ) {
6240                 return false;
6241             }
6242             phy = p.next();
6243             if ( phy == null ) {
6244                 return false;
6245             }
6246             if ( phy.getNumberOfExternalNodes() != 25 ) {
6247                 return false;
6248             }
6249             if ( !phy.getName().equals( "" ) ) {
6250                 return false;
6251             }
6252             if ( p.hasNext() ) {
6253                 return false;
6254             }
6255             phy = p.next();
6256             if ( phy != null ) {
6257                 return false;
6258             }
6259             ////
6260             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6261             if ( !p.hasNext() ) {
6262                 return false;
6263             }
6264             phy = p.next();
6265             if ( phy == null ) {
6266                 return false;
6267             }
6268             if ( phy.getNumberOfExternalNodes() != 10 ) {
6269                 return false;
6270             }
6271             if ( !phy.getName().equals( "name" ) ) {
6272                 return false;
6273             }
6274             if ( p.hasNext() ) {
6275                 return false;
6276             }
6277             phy = p.next();
6278             if ( phy != null ) {
6279                 return false;
6280             }
6281             //
6282             p.reset();
6283             if ( !p.hasNext() ) {
6284                 return false;
6285             }
6286             phy = p.next();
6287             if ( phy == null ) {
6288                 return false;
6289             }
6290             if ( phy.getNumberOfExternalNodes() != 10 ) {
6291                 return false;
6292             }
6293             if ( !phy.getName().equals( "name" ) ) {
6294                 return false;
6295             }
6296             if ( p.hasNext() ) {
6297                 return false;
6298             }
6299             phy = p.next();
6300             if ( phy != null ) {
6301                 return false;
6302             }
6303             ////
6304             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6305             if ( !p.hasNext() ) {
6306                 return false;
6307             }
6308             phy = p.next();
6309             if ( phy == null ) {
6310                 return false;
6311             }
6312             if ( phy.getNumberOfExternalNodes() != 3 ) {
6313                 return false;
6314             }
6315             if ( !phy.getName().equals( "" ) ) {
6316                 return false;
6317             }
6318             if ( phy.isRooted() ) {
6319                 return false;
6320             }
6321             if ( p.hasNext() ) {
6322                 return false;
6323             }
6324             phy = p.next();
6325             if ( phy != null ) {
6326                 return false;
6327             }
6328             //
6329             p.reset();
6330             if ( !p.hasNext() ) {
6331                 return false;
6332             }
6333             phy = p.next();
6334             if ( phy == null ) {
6335                 return false;
6336             }
6337             if ( phy.getNumberOfExternalNodes() != 3 ) {
6338                 return false;
6339             }
6340             if ( !phy.getName().equals( "" ) ) {
6341                 return false;
6342             }
6343             if ( p.hasNext() ) {
6344                 return false;
6345             }
6346             phy = p.next();
6347             if ( phy != null ) {
6348                 return false;
6349             }
6350             ////
6351             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6352             //            if ( phylogenies.length != 18 ) {
6353             //                return false;
6354             //            }
6355             //0
6356             if ( !p.hasNext() ) {
6357                 return false;
6358             }
6359             phy = p.next();
6360             if ( phy == null ) {
6361                 return false;
6362             }
6363             if ( phy.getNumberOfExternalNodes() != 10 ) {
6364                 return false;
6365             }
6366             if ( !phy.getName().equals( "tree 0" ) ) {
6367                 return false;
6368             }
6369             //1
6370             if ( !p.hasNext() ) {
6371                 return false;
6372             }
6373             phy = p.next();
6374             if ( phy == null ) {
6375                 return false;
6376             }
6377             if ( phy.getNumberOfExternalNodes() != 10 ) {
6378                 return false;
6379             }
6380             if ( !phy.getName().equals( "tree 1" ) ) {
6381                 return false;
6382             }
6383             //2
6384             if ( !p.hasNext() ) {
6385                 return false;
6386             }
6387             phy = p.next();
6388             if ( phy == null ) {
6389                 return false;
6390             }
6391             if ( phy.getNumberOfExternalNodes() != 3 ) {
6392                 return false;
6393             }
6394             if ( !phy.getName().equals( "" ) ) {
6395                 return false;
6396             }
6397             if ( phy.isRooted() ) {
6398                 return false;
6399             }
6400             //3
6401             if ( !p.hasNext() ) {
6402                 return false;
6403             }
6404             phy = p.next();
6405             if ( phy == null ) {
6406                 return false;
6407             }
6408             if ( phy.getNumberOfExternalNodes() != 4 ) {
6409                 return false;
6410             }
6411             if ( !phy.getName().equals( "" ) ) {
6412                 return false;
6413             }
6414             if ( !phy.isRooted() ) {
6415                 return false;
6416             }
6417             //4
6418             if ( !p.hasNext() ) {
6419                 return false;
6420             }
6421             phy = p.next();
6422             if ( phy == null ) {
6423                 return false;
6424             }
6425             if ( phy.getNumberOfExternalNodes() != 5 ) {
6426                 System.out.println( phy.getNumberOfExternalNodes() );
6427                 return false;
6428             }
6429             if ( !phy.getName().equals( "" ) ) {
6430                 return false;
6431             }
6432             if ( !phy.isRooted() ) {
6433                 return false;
6434             }
6435             //5
6436             if ( !p.hasNext() ) {
6437                 return false;
6438             }
6439             phy = p.next();
6440             if ( phy == null ) {
6441                 return false;
6442             }
6443             if ( phy.getNumberOfExternalNodes() != 3 ) {
6444                 return false;
6445             }
6446             if ( !phy.getName().equals( "" ) ) {
6447                 return false;
6448             }
6449             if ( phy.isRooted() ) {
6450                 return false;
6451             }
6452             //6
6453             if ( !p.hasNext() ) {
6454                 return false;
6455             }
6456             phy = p.next();
6457             if ( phy == null ) {
6458                 return false;
6459             }
6460             if ( phy.getNumberOfExternalNodes() != 2 ) {
6461                 return false;
6462             }
6463             if ( !phy.getName().equals( "" ) ) {
6464                 return false;
6465             }
6466             if ( !phy.isRooted() ) {
6467                 return false;
6468             }
6469             //7
6470             if ( !p.hasNext() ) {
6471                 return false;
6472             }
6473             phy = p.next();
6474             if ( phy.getNumberOfExternalNodes() != 3 ) {
6475                 return false;
6476             }
6477             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6478                 return false;
6479             }
6480             if ( !phy.isRooted() ) {
6481                 return false;
6482             }
6483             //8
6484             if ( !p.hasNext() ) {
6485                 return false;
6486             }
6487             phy = p.next();
6488             if ( phy.getNumberOfExternalNodes() != 3 ) {
6489                 return false;
6490             }
6491             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6492                 return false;
6493             }
6494             if ( !phy.getName().equals( "tree 8" ) ) {
6495                 return false;
6496             }
6497             //9
6498             if ( !p.hasNext() ) {
6499                 return false;
6500             }
6501             phy = p.next();
6502             if ( phy.getNumberOfExternalNodes() != 3 ) {
6503                 return false;
6504             }
6505             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6506                 return false;
6507             }
6508             if ( !phy.getName().equals( "tree 9" ) ) {
6509                 return false;
6510             }
6511             //10
6512             if ( !p.hasNext() ) {
6513                 return false;
6514             }
6515             phy = p.next();
6516             if ( phy.getNumberOfExternalNodes() != 3 ) {
6517                 return false;
6518             }
6519             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6520                 return false;
6521             }
6522             if ( !phy.getName().equals( "tree 10" ) ) {
6523                 return false;
6524             }
6525             if ( !phy.isRooted() ) {
6526                 return false;
6527             }
6528             //11
6529             if ( !p.hasNext() ) {
6530                 return false;
6531             }
6532             phy = p.next();
6533             if ( phy.getNumberOfExternalNodes() != 3 ) {
6534                 return false;
6535             }
6536             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6537                 return false;
6538             }
6539             if ( !phy.getName().equals( "tree 11" ) ) {
6540                 return false;
6541             }
6542             if ( phy.isRooted() ) {
6543                 return false;
6544             }
6545             //12
6546             if ( !p.hasNext() ) {
6547                 return false;
6548             }
6549             phy = p.next();
6550             if ( phy.getNumberOfExternalNodes() != 3 ) {
6551                 return false;
6552             }
6553             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6554                 return false;
6555             }
6556             if ( !phy.getName().equals( "tree 12" ) ) {
6557                 return false;
6558             }
6559             if ( !phy.isRooted() ) {
6560                 return false;
6561             }
6562             //13
6563             if ( !p.hasNext() ) {
6564                 return false;
6565             }
6566             phy = p.next();
6567             if ( phy.getNumberOfExternalNodes() != 3 ) {
6568                 return false;
6569             }
6570             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6571                 return false;
6572             }
6573             if ( !phy.getName().equals( "tree 13" ) ) {
6574                 return false;
6575             }
6576             if ( !phy.isRooted() ) {
6577                 return false;
6578             }
6579             //14
6580             if ( !p.hasNext() ) {
6581                 return false;
6582             }
6583             phy = p.next();
6584             if ( phy.getNumberOfExternalNodes() != 10 ) {
6585                 System.out.println( phy.getNumberOfExternalNodes() );
6586                 return false;
6587             }
6588             if ( !phy
6589                     .toNewHampshire()
6590                     .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;" ) ) {
6591                 System.out.println( phy.toNewHampshire() );
6592                 return false;
6593             }
6594             if ( !phy.getName().equals( "tree 14" ) ) {
6595                 return false;
6596             }
6597             if ( !phy.isRooted() ) {
6598                 return false;
6599             }
6600             //15
6601             if ( !p.hasNext() ) {
6602                 return false;
6603             }
6604             phy = p.next();
6605             if ( phy.getNumberOfExternalNodes() != 10 ) {
6606                 System.out.println( phy.getNumberOfExternalNodes() );
6607                 return false;
6608             }
6609             if ( !phy
6610                     .toNewHampshire()
6611                     .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;" ) ) {
6612                 System.out.println( phy.toNewHampshire() );
6613                 return false;
6614             }
6615             if ( !phy.getName().equals( "tree 15" ) ) {
6616                 return false;
6617             }
6618             if ( phy.isRooted() ) {
6619                 return false;
6620             }
6621             //16
6622             if ( !p.hasNext() ) {
6623                 return false;
6624             }
6625             phy = p.next();
6626             if ( phy.getNumberOfExternalNodes() != 10 ) {
6627                 System.out.println( phy.getNumberOfExternalNodes() );
6628                 return false;
6629             }
6630             if ( !phy
6631                     .toNewHampshire()
6632                     .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;" ) ) {
6633                 System.out.println( phy.toNewHampshire() );
6634                 return false;
6635             }
6636             if ( !phy.getName().equals( "tree 16" ) ) {
6637                 return false;
6638             }
6639             if ( !phy.isRooted() ) {
6640                 return false;
6641             }
6642             //17
6643             if ( !p.hasNext() ) {
6644                 return false;
6645             }
6646             phy = p.next();
6647             if ( phy.getNumberOfExternalNodes() != 10 ) {
6648                 System.out.println( phy.getNumberOfExternalNodes() );
6649                 return false;
6650             }
6651             if ( !phy
6652                     .toNewHampshire()
6653                     .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;" ) ) {
6654                 System.out.println( phy.toNewHampshire() );
6655                 return false;
6656             }
6657             if ( !phy.getName().equals( "tree 17" ) ) {
6658                 return false;
6659             }
6660             if ( phy.isRooted() ) {
6661                 return false;
6662             }
6663             //
6664             if ( p.hasNext() ) {
6665                 return false;
6666             }
6667             phy = p.next();
6668             if ( phy != null ) {
6669                 return false;
6670             }
6671             p.reset();
6672             //0
6673             if ( !p.hasNext() ) {
6674                 return false;
6675             }
6676             phy = p.next();
6677             if ( phy == null ) {
6678                 return false;
6679             }
6680             if ( phy.getNumberOfExternalNodes() != 10 ) {
6681                 return false;
6682             }
6683             if ( !phy.getName().equals( "tree 0" ) ) {
6684                 return false;
6685             }
6686             //1
6687             if ( !p.hasNext() ) {
6688                 return false;
6689             }
6690             phy = p.next();
6691             if ( phy == null ) {
6692                 return false;
6693             }
6694             if ( phy.getNumberOfExternalNodes() != 10 ) {
6695                 return false;
6696             }
6697             if ( !phy.getName().equals( "tree 1" ) ) {
6698                 return false;
6699             }
6700             //2
6701             if ( !p.hasNext() ) {
6702                 return false;
6703             }
6704             phy = p.next();
6705             if ( phy == null ) {
6706                 return false;
6707             }
6708             if ( phy.getNumberOfExternalNodes() != 3 ) {
6709                 return false;
6710             }
6711             if ( !phy.getName().equals( "" ) ) {
6712                 return false;
6713             }
6714             if ( phy.isRooted() ) {
6715                 return false;
6716             }
6717             //3
6718             if ( !p.hasNext() ) {
6719                 return false;
6720             }
6721             phy = p.next();
6722             if ( phy == null ) {
6723                 return false;
6724             }
6725             if ( phy.getNumberOfExternalNodes() != 4 ) {
6726                 return false;
6727             }
6728             if ( !phy.getName().equals( "" ) ) {
6729                 return false;
6730             }
6731             if ( !phy.isRooted() ) {
6732                 return false;
6733             }
6734             //4
6735             if ( !p.hasNext() ) {
6736                 return false;
6737             }
6738             phy = p.next();
6739             if ( phy == null ) {
6740                 return false;
6741             }
6742             if ( phy.getNumberOfExternalNodes() != 5 ) {
6743                 System.out.println( phy.getNumberOfExternalNodes() );
6744                 return false;
6745             }
6746             if ( !phy.getName().equals( "" ) ) {
6747                 return false;
6748             }
6749             if ( !phy.isRooted() ) {
6750                 return false;
6751             }
6752             //5
6753             if ( !p.hasNext() ) {
6754                 return false;
6755             }
6756             phy = p.next();
6757             if ( phy == null ) {
6758                 return false;
6759             }
6760             if ( phy.getNumberOfExternalNodes() != 3 ) {
6761                 return false;
6762             }
6763             if ( !phy.getName().equals( "" ) ) {
6764                 return false;
6765             }
6766             if ( phy.isRooted() ) {
6767                 return false;
6768             }
6769         }
6770         catch ( final Exception e ) {
6771             e.printStackTrace( System.out );
6772             return false;
6773         }
6774         return true;
6775     }
6776
6777     private static boolean testNexusTreeParsingTranslating() {
6778         try {
6779             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6780             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6781             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
6782             if ( phylogenies.length != 1 ) {
6783                 return false;
6784             }
6785             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6786                 return false;
6787             }
6788             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6789                 return false;
6790             }
6791             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6792                 return false;
6793             }
6794             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6795                 return false;
6796             }
6797             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6798                     .equals( "Aranaeus" ) ) {
6799                 return false;
6800             }
6801             phylogenies = null;
6802             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
6803             if ( phylogenies.length != 3 ) {
6804                 return false;
6805             }
6806             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6807                 return false;
6808             }
6809             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6810                 return false;
6811             }
6812             if ( phylogenies[ 0 ].isRooted() ) {
6813                 return false;
6814             }
6815             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6816                 return false;
6817             }
6818             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6819                 return false;
6820             }
6821             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6822                     .equals( "Aranaeus" ) ) {
6823                 return false;
6824             }
6825             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6826                 return false;
6827             }
6828             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6829                 return false;
6830             }
6831             if ( phylogenies[ 1 ].isRooted() ) {
6832                 return false;
6833             }
6834             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6835                 return false;
6836             }
6837             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6838                 return false;
6839             }
6840             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6841                     .equals( "Aranaeus" ) ) {
6842                 return false;
6843             }
6844             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6845                 return false;
6846             }
6847             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6848                 return false;
6849             }
6850             if ( !phylogenies[ 2 ].isRooted() ) {
6851                 return false;
6852             }
6853             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6854                 return false;
6855             }
6856             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6857                 return false;
6858             }
6859             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6860                     .equals( "Aranaeus" ) ) {
6861                 return false;
6862             }
6863             phylogenies = null;
6864             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
6865             if ( phylogenies.length != 3 ) {
6866                 return false;
6867             }
6868             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6869                 return false;
6870             }
6871             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6872                 return false;
6873             }
6874             if ( phylogenies[ 0 ].isRooted() ) {
6875                 return false;
6876             }
6877             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6878                 return false;
6879             }
6880             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6881                 return false;
6882             }
6883             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6884                     .equals( "Aranaeus" ) ) {
6885                 return false;
6886             }
6887             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6888                 return false;
6889             }
6890             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6891                 return false;
6892             }
6893             if ( phylogenies[ 1 ].isRooted() ) {
6894                 return false;
6895             }
6896             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6897                 return false;
6898             }
6899             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6900                 return false;
6901             }
6902             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6903                     .equals( "Aranaeus" ) ) {
6904                 return false;
6905             }
6906             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6907                 return false;
6908             }
6909             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6910                 return false;
6911             }
6912             if ( !phylogenies[ 2 ].isRooted() ) {
6913                 return false;
6914             }
6915             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6916                 return false;
6917             }
6918             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6919                 return false;
6920             }
6921             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6922                     .equals( "Aranaeus" ) ) {
6923                 return false;
6924             }
6925         }
6926         catch ( final Exception e ) {
6927             e.printStackTrace( System.out );
6928             return false;
6929         }
6930         return true;
6931     }
6932
6933     private static boolean testNHParsing() {
6934         try {
6935             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6936             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
6937             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
6938                 return false;
6939             }
6940             final NHXParser nhxp = new NHXParser();
6941             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
6942             nhxp.setReplaceUnderscores( true );
6943             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
6944             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
6945                 return false;
6946             }
6947             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
6948                 return false;
6949             }
6950             final Phylogeny p1b = factory
6951                     .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 ",
6952                              new NHXParser() )[ 0 ];
6953             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
6954                 return false;
6955             }
6956             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
6957                 return false;
6958             }
6959             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
6960             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
6961             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
6962             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
6963             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
6964             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
6965             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
6966             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
6967             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
6968             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
6969             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
6970                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
6971                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
6972                                                     new NHXParser() );
6973             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
6974                 return false;
6975             }
6976             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
6977                 return false;
6978             }
6979             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
6980                 return false;
6981             }
6982             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
6983                 return false;
6984             }
6985             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
6986             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
6987             final String p16_S = "((A,B),C)";
6988             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
6989             if ( p16.length != 1 ) {
6990                 return false;
6991             }
6992             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
6993                 return false;
6994             }
6995             final String p17_S = "(C,(A,B))";
6996             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
6997             if ( p17.length != 1 ) {
6998                 return false;
6999             }
7000             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7001                 return false;
7002             }
7003             final String p18_S = "((A,B),(C,D))";
7004             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7005             if ( p18.length != 1 ) {
7006                 return false;
7007             }
7008             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7009                 return false;
7010             }
7011             final String p19_S = "(((A,B),C),D)";
7012             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7013             if ( p19.length != 1 ) {
7014                 return false;
7015             }
7016             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7017                 return false;
7018             }
7019             final String p20_S = "(A,(B,(C,D)))";
7020             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7021             if ( p20.length != 1 ) {
7022                 return false;
7023             }
7024             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7025                 return false;
7026             }
7027             final String p21_S = "(A,(B,(C,(D,E))))";
7028             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7029             if ( p21.length != 1 ) {
7030                 return false;
7031             }
7032             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7033                 return false;
7034             }
7035             final String p22_S = "((((A,B),C),D),E)";
7036             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7037             if ( p22.length != 1 ) {
7038                 return false;
7039             }
7040             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7041                 return false;
7042             }
7043             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7044             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7045             if ( p23.length != 1 ) {
7046                 System.out.println( "xl=" + p23.length );
7047                 System.exit( -1 );
7048                 return false;
7049             }
7050             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7051                 return false;
7052             }
7053             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7054             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7055             if ( p24.length != 1 ) {
7056                 return false;
7057             }
7058             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7059                 return false;
7060             }
7061             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7062             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7063             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7064             if ( p241.length != 2 ) {
7065                 return false;
7066             }
7067             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7068                 return false;
7069             }
7070             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7071                 return false;
7072             }
7073             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7074                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7075                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7076                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7077                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7078                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7079                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7080                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7081             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7082             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7083                 return false;
7084             }
7085             final String p26_S = "(A,B)ab";
7086             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7087             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7088                 return false;
7089             }
7090             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7091             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7092             if ( p27s.length != 1 ) {
7093                 System.out.println( "xxl=" + p27s.length );
7094                 System.exit( -1 );
7095                 return false;
7096             }
7097             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7098                 System.out.println( p27s[ 0 ].toNewHampshireX() );
7099                 System.exit( -1 );
7100                 return false;
7101             }
7102             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7103                                                     new NHXParser() );
7104             if ( p27.length != 1 ) {
7105                 System.out.println( "yl=" + p27.length );
7106                 System.exit( -1 );
7107                 return false;
7108             }
7109             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7110                 System.out.println( p27[ 0 ].toNewHampshireX() );
7111                 System.exit( -1 );
7112                 return false;
7113             }
7114             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7115             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7116             final String p28_S3 = "(A,B)ab";
7117             final String p28_S4 = "((((A,B),C),D),;E;)";
7118             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7119                                                     new NHXParser() );
7120             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7121                 return false;
7122             }
7123             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7124                 return false;
7125             }
7126             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7127                 return false;
7128             }
7129             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7130                 return false;
7131             }
7132             if ( p28.length != 4 ) {
7133                 return false;
7134             }
7135             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";
7136             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
7137             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
7138                 return false;
7139             }
7140             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";
7141             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
7142             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
7143                 return false;
7144             }
7145             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
7146             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
7147             if ( ( p32.length != 0 ) ) {
7148                 return false;
7149             }
7150             final String p33_S = "A";
7151             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
7152             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
7153                 return false;
7154             }
7155             final String p34_S = "B;";
7156             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
7157             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
7158                 return false;
7159             }
7160             final String p35_S = "B:0.2";
7161             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7162             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7163                 return false;
7164             }
7165             final String p36_S = "(A)";
7166             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7167             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7168                 return false;
7169             }
7170             final String p37_S = "((A))";
7171             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7172             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7173                 return false;
7174             }
7175             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7176             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7177             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7178                 return false;
7179             }
7180             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7181             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7182             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7183                 return false;
7184             }
7185             final String p40_S = "(A,B,C)";
7186             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7187             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7188                 return false;
7189             }
7190             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7191             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7192             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7193                 return false;
7194             }
7195             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7196             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7197             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7198                 return false;
7199             }
7200             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)";
7201             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7202             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7203                 return false;
7204             }
7205             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)))";
7206             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7207             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7208                 return false;
7209             }
7210             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7211             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7212             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7213                 return false;
7214             }
7215             final String p46_S = "";
7216             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7217             if ( p46.length != 0 ) {
7218                 return false;
7219             }
7220             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7221             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7222                 return false;
7223             }
7224             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7225             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7226                 return false;
7227             }
7228             final Phylogeny p49 = factory
7229                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7230                              new NHXParser() )[ 0 ];
7231             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7232                 return false;
7233             }
7234             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7235             if ( p50.getNode( "A" ) == null ) {
7236                 return false;
7237             }
7238             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7239                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7240                 return false;
7241             }
7242             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7243                 return false;
7244             }
7245             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7246                     .equals( "((A,B)88:2.0,C);" ) ) {
7247                 return false;
7248             }
7249             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7250             if ( p51.getNode( "A(A" ) == null ) {
7251                 return false;
7252             }
7253             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7254             if ( p52.getNode( "A(A" ) == null ) {
7255                 return false;
7256             }
7257             final Phylogeny p53 = factory
7258                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7259                              new NHXParser() )[ 0 ];
7260             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7261                 return false;
7262             }
7263             // 
7264             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7265             if ( p54.getNode( "A" ) == null ) {
7266                 return false;
7267             }
7268             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7269                     .equals( "((A,B)[88],C);" ) ) {
7270                 return false;
7271             }
7272         }
7273         catch ( final Exception e ) {
7274             e.printStackTrace( System.out );
7275             return false;
7276         }
7277         return true;
7278     }
7279
7280     private static boolean testNHParsingIter() {
7281         try {
7282             final String p0_str = "(A,B);";
7283             final NHXParser p = new NHXParser();
7284             p.setSource( p0_str );
7285             if ( !p.hasNext() ) {
7286                 return false;
7287             }
7288             final Phylogeny p0 = p.next();
7289             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7290                 System.out.println( p0.toNewHampshire() );
7291                 return false;
7292             }
7293             if ( p.hasNext() ) {
7294                 return false;
7295             }
7296             if ( p.next() != null ) {
7297                 return false;
7298             }
7299             //
7300             final String p00_str = "(A,B)root;";
7301             p.setSource( p00_str );
7302             final Phylogeny p00 = p.next();
7303             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7304                 System.out.println( p00.toNewHampshire() );
7305                 return false;
7306             }
7307             //
7308             final String p000_str = "A;";
7309             p.setSource( p000_str );
7310             final Phylogeny p000 = p.next();
7311             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7312                 System.out.println( p000.toNewHampshire() );
7313                 return false;
7314             }
7315             //
7316             final String p0000_str = "A";
7317             p.setSource( p0000_str );
7318             final Phylogeny p0000 = p.next();
7319             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7320                 System.out.println( p0000.toNewHampshire() );
7321                 return false;
7322             }
7323             //
7324             p.setSource( "(A)" );
7325             final Phylogeny p00000 = p.next();
7326             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7327                 System.out.println( p00000.toNewHampshire() );
7328                 return false;
7329             }
7330             //
7331             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7332             p.setSource( p1_str );
7333             if ( !p.hasNext() ) {
7334                 return false;
7335             }
7336             final Phylogeny p1_0 = p.next();
7337             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7338                 System.out.println( p1_0.toNewHampshire() );
7339                 return false;
7340             }
7341             if ( !p.hasNext() ) {
7342                 return false;
7343             }
7344             final Phylogeny p1_1 = p.next();
7345             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7346                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7347                 return false;
7348             }
7349             if ( !p.hasNext() ) {
7350                 return false;
7351             }
7352             final Phylogeny p1_2 = p.next();
7353             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7354                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7355                 return false;
7356             }
7357             if ( !p.hasNext() ) {
7358                 return false;
7359             }
7360             final Phylogeny p1_3 = p.next();
7361             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7362                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7363                 return false;
7364             }
7365             if ( p.hasNext() ) {
7366                 return false;
7367             }
7368             if ( p.next() != null ) {
7369                 return false;
7370             }
7371             //
7372             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7373             p.setSource( p2_str );
7374             if ( !p.hasNext() ) {
7375                 return false;
7376             }
7377             Phylogeny p2_0 = p.next();
7378             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7379                 System.out.println( p2_0.toNewHampshire() );
7380                 return false;
7381             }
7382             if ( !p.hasNext() ) {
7383                 return false;
7384             }
7385             Phylogeny p2_1 = p.next();
7386             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7387                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7388                 return false;
7389             }
7390             if ( !p.hasNext() ) {
7391                 return false;
7392             }
7393             Phylogeny p2_2 = p.next();
7394             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7395                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7396                 return false;
7397             }
7398             if ( !p.hasNext() ) {
7399                 return false;
7400             }
7401             Phylogeny p2_3 = p.next();
7402             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7403                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7404                 return false;
7405             }
7406             if ( !p.hasNext() ) {
7407                 return false;
7408             }
7409             Phylogeny p2_4 = p.next();
7410             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7411                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7412                 return false;
7413             }
7414             if ( p.hasNext() ) {
7415                 return false;
7416             }
7417             if ( p.next() != null ) {
7418                 return false;
7419             }
7420             ////
7421             p.reset();
7422             if ( !p.hasNext() ) {
7423                 return false;
7424             }
7425             p2_0 = p.next();
7426             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7427                 System.out.println( p2_0.toNewHampshire() );
7428                 return false;
7429             }
7430             if ( !p.hasNext() ) {
7431                 return false;
7432             }
7433             p2_1 = p.next();
7434             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7435                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7436                 return false;
7437             }
7438             if ( !p.hasNext() ) {
7439                 return false;
7440             }
7441             p2_2 = p.next();
7442             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7443                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7444                 return false;
7445             }
7446             if ( !p.hasNext() ) {
7447                 return false;
7448             }
7449             p2_3 = p.next();
7450             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7451                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7452                 return false;
7453             }
7454             if ( !p.hasNext() ) {
7455                 return false;
7456             }
7457             p2_4 = p.next();
7458             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7459                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7460                 return false;
7461             }
7462             if ( p.hasNext() ) {
7463                 return false;
7464             }
7465             if ( p.next() != null ) {
7466                 return false;
7467             }
7468             //
7469             final String p3_str = "((A,B),C)abc";
7470             p.setSource( p3_str );
7471             if ( !p.hasNext() ) {
7472                 return false;
7473             }
7474             final Phylogeny p3_0 = p.next();
7475             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7476                 return false;
7477             }
7478             if ( p.hasNext() ) {
7479                 return false;
7480             }
7481             if ( p.next() != null ) {
7482                 return false;
7483             }
7484             //
7485             final String p4_str = "((A,B)ab,C)abc";
7486             p.setSource( p4_str );
7487             if ( !p.hasNext() ) {
7488                 return false;
7489             }
7490             final Phylogeny p4_0 = p.next();
7491             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7492                 return false;
7493             }
7494             if ( p.hasNext() ) {
7495                 return false;
7496             }
7497             if ( p.next() != null ) {
7498                 return false;
7499             }
7500             //
7501             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7502             p.setSource( p5_str );
7503             if ( !p.hasNext() ) {
7504                 return false;
7505             }
7506             final Phylogeny p5_0 = p.next();
7507             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7508                 return false;
7509             }
7510             if ( p.hasNext() ) {
7511                 return false;
7512             }
7513             if ( p.next() != null ) {
7514                 return false;
7515             }
7516             //
7517             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7518             p.setSource( p6_str );
7519             if ( !p.hasNext() ) {
7520                 return false;
7521             }
7522             Phylogeny p6_0 = p.next();
7523             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7524                 return false;
7525             }
7526             if ( p.hasNext() ) {
7527                 return false;
7528             }
7529             if ( p.next() != null ) {
7530                 return false;
7531             }
7532             p.reset();
7533             if ( !p.hasNext() ) {
7534                 return false;
7535             }
7536             p6_0 = p.next();
7537             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7538                 return false;
7539             }
7540             if ( p.hasNext() ) {
7541                 return false;
7542             }
7543             if ( p.next() != null ) {
7544                 return false;
7545             }
7546             //
7547             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7548             p.setSource( p7_str );
7549             if ( !p.hasNext() ) {
7550                 return false;
7551             }
7552             Phylogeny p7_0 = p.next();
7553             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7554                 return false;
7555             }
7556             if ( p.hasNext() ) {
7557                 return false;
7558             }
7559             if ( p.next() != null ) {
7560                 return false;
7561             }
7562             p.reset();
7563             if ( !p.hasNext() ) {
7564                 return false;
7565             }
7566             p7_0 = p.next();
7567             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7568                 return false;
7569             }
7570             if ( p.hasNext() ) {
7571                 return false;
7572             }
7573             if ( p.next() != null ) {
7574                 return false;
7575             }
7576             //
7577             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7578             p.setSource( p8_str );
7579             if ( !p.hasNext() ) {
7580                 return false;
7581             }
7582             Phylogeny p8_0 = p.next();
7583             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7584                 return false;
7585             }
7586             if ( !p.hasNext() ) {
7587                 return false;
7588             }
7589             if ( !p.hasNext() ) {
7590                 return false;
7591             }
7592             Phylogeny p8_1 = p.next();
7593             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7594                 return false;
7595             }
7596             if ( p.hasNext() ) {
7597                 return false;
7598             }
7599             if ( p.next() != null ) {
7600                 return false;
7601             }
7602             p.reset();
7603             if ( !p.hasNext() ) {
7604                 return false;
7605             }
7606             p8_0 = p.next();
7607             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7608                 return false;
7609             }
7610             if ( !p.hasNext() ) {
7611                 return false;
7612             }
7613             p8_1 = p.next();
7614             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7615                 return false;
7616             }
7617             if ( p.hasNext() ) {
7618                 return false;
7619             }
7620             if ( p.next() != null ) {
7621                 return false;
7622             }
7623             p.reset();
7624             //
7625             p.setSource( "" );
7626             if ( p.hasNext() ) {
7627                 return false;
7628             }
7629             //
7630             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
7631             if ( !p.hasNext() ) {
7632                 return false;
7633             }
7634             Phylogeny p_27 = p.next();
7635             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7636                 System.out.println( p_27.toNewHampshireX() );
7637                 System.exit( -1 );
7638                 return false;
7639             }
7640             if ( p.hasNext() ) {
7641                 return false;
7642             }
7643             if ( p.next() != null ) {
7644                 return false;
7645             }
7646             p.reset();
7647             if ( !p.hasNext() ) {
7648                 return false;
7649             }
7650             p_27 = p.next();
7651             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7652                 System.out.println( p_27.toNewHampshireX() );
7653                 System.exit( -1 );
7654                 return false;
7655             }
7656             if ( p.hasNext() ) {
7657                 return false;
7658             }
7659             if ( p.next() != null ) {
7660                 return false;
7661             }
7662         }
7663         catch ( final Exception e ) {
7664             e.printStackTrace( System.out );
7665             return false;
7666         }
7667         return true;
7668     }
7669
7670     private static boolean testNHXconversion() {
7671         try {
7672             final PhylogenyNode n1 = new PhylogenyNode();
7673             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7674             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7675             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7676             final PhylogenyNode n5 = PhylogenyNode
7677                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
7678             final PhylogenyNode n6 = PhylogenyNode
7679                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
7680             if ( !n1.toNewHampshireX().equals( "" ) ) {
7681                 return false;
7682             }
7683             if ( !n2.toNewHampshireX().equals( "" ) ) {
7684                 return false;
7685             }
7686             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
7687                 return false;
7688             }
7689             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
7690                 return false;
7691             }
7692             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
7693                 return false;
7694             }
7695             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
7696                 System.out.println( n6.toNewHampshireX() );
7697                 return false;
7698             }
7699         }
7700         catch ( final Exception e ) {
7701             e.printStackTrace( System.out );
7702             return false;
7703         }
7704         return true;
7705     }
7706
7707     private static boolean testNHXNodeParsing() {
7708         try {
7709             final PhylogenyNode n1 = new PhylogenyNode();
7710             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7711             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7712             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7713             final PhylogenyNode n5 = PhylogenyNode
7714                     .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]" );
7715             if ( !n3.getName().equals( "n3" ) ) {
7716                 return false;
7717             }
7718             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7719                 return false;
7720             }
7721             if ( n3.isDuplication() ) {
7722                 return false;
7723             }
7724             if ( n3.isHasAssignedEvent() ) {
7725                 return false;
7726             }
7727             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
7728                 return false;
7729             }
7730             if ( !n4.getName().equals( "n4" ) ) {
7731                 return false;
7732             }
7733             if ( n4.getDistanceToParent() != 0.01 ) {
7734                 return false;
7735             }
7736             if ( !n5.getName().equals( "n5" ) ) {
7737                 return false;
7738             }
7739             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
7740                 return false;
7741             }
7742             if ( n5.getDistanceToParent() != 0.1 ) {
7743                 return false;
7744             }
7745             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
7746                 return false;
7747             }
7748             if ( !n5.isDuplication() ) {
7749                 return false;
7750             }
7751             if ( !n5.isHasAssignedEvent() ) {
7752                 return false;
7753             }
7754             final PhylogenyNode n8 = PhylogenyNode
7755                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
7756                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7757             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7758                 return false;
7759             }
7760             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
7761                 return false;
7762             }
7763             final PhylogenyNode n9 = PhylogenyNode
7764                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
7765                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7766             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
7767                 return false;
7768             }
7769             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
7770                 return false;
7771             }
7772             final PhylogenyNode n10 = PhylogenyNode
7773                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7774             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
7775                 return false;
7776             }
7777             final PhylogenyNode n20 = PhylogenyNode
7778                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7779             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7780                 return false;
7781             }
7782             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
7783                 return false;
7784             }
7785             final PhylogenyNode n20x = PhylogenyNode
7786                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7787             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
7788                 return false;
7789             }
7790             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
7791                 return false;
7792             }
7793             final PhylogenyNode n20xx = PhylogenyNode
7794                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7795             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
7796                 return false;
7797             }
7798             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
7799                 return false;
7800             }
7801             final PhylogenyNode n20xxx = PhylogenyNode
7802                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7803             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
7804                 return false;
7805             }
7806             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
7807                 return false;
7808             }
7809             final PhylogenyNode n20xxxx = PhylogenyNode
7810                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7811             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
7812                 return false;
7813             }
7814             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
7815                 return false;
7816             }
7817             final PhylogenyNode n21 = PhylogenyNode
7818                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7819             if ( !n21.getName().equals( "N21_PIG" ) ) {
7820                 return false;
7821             }
7822             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
7823                 return false;
7824             }
7825             final PhylogenyNode n21x = PhylogenyNode
7826                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7827             if ( !n21x.getName().equals( "n21_PIG" ) ) {
7828                 return false;
7829             }
7830             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
7831                 return false;
7832             }
7833             final PhylogenyNode n22 = PhylogenyNode
7834                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7835             if ( !n22.getName().equals( "n22/PIG" ) ) {
7836                 return false;
7837             }
7838             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
7839                 return false;
7840             }
7841             final PhylogenyNode n23 = PhylogenyNode
7842                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7843             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
7844                 return false;
7845             }
7846             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
7847                 return false;
7848             }
7849             final PhylogenyNode a = PhylogenyNode
7850                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7851             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7852                 return false;
7853             }
7854             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
7855                 return false;
7856             }
7857             final PhylogenyNode c1 = PhylogenyNode
7858                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
7859                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7860             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
7861                 return false;
7862             }
7863             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
7864                 return false;
7865             }
7866             final PhylogenyNode c2 = PhylogenyNode
7867                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
7868                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7869             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
7870                 return false;
7871             }
7872             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
7873                 return false;
7874             }
7875             final PhylogenyNode e3 = PhylogenyNode
7876                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7877             if ( !e3.getName().equals( "n10_RAT~" ) ) {
7878                 return false;
7879             }
7880             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
7881                 return false;
7882             }
7883             final PhylogenyNode n11 = PhylogenyNode
7884                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
7885                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7886             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
7887                 return false;
7888             }
7889             if ( n11.getDistanceToParent() != 0.4 ) {
7890                 return false;
7891             }
7892             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
7893                 return false;
7894             }
7895             final PhylogenyNode n12 = PhylogenyNode
7896                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
7897                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7898             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
7899                 return false;
7900             }
7901             if ( n12.getDistanceToParent() != 0.4 ) {
7902                 return false;
7903             }
7904             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
7905                 return false;
7906             }
7907             final PhylogenyNode o = PhylogenyNode
7908                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7909             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
7910                 return false;
7911             }
7912             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
7913                 return false;
7914             }
7915             if ( n1.getName().compareTo( "" ) != 0 ) {
7916                 return false;
7917             }
7918             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7919                 return false;
7920             }
7921             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7922                 return false;
7923             }
7924             if ( n2.getName().compareTo( "" ) != 0 ) {
7925                 return false;
7926             }
7927             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7928                 return false;
7929             }
7930             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7931                 return false;
7932             }
7933             final PhylogenyNode n00 = PhylogenyNode
7934                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
7935             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
7936                 return false;
7937             }
7938             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
7939                 return false;
7940             }
7941             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
7942             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
7943                 return false;
7944             }
7945             final PhylogenyNode n13 = PhylogenyNode
7946                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7947             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
7948                 return false;
7949             }
7950             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
7951                 return false;
7952             }
7953             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7954                 return false;
7955             }
7956             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7957                 return false;
7958             }
7959             final PhylogenyNode n14 = PhylogenyNode
7960                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7961             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
7962                 return false;
7963             }
7964             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
7965                 return false;
7966             }
7967             final PhylogenyNode n15 = PhylogenyNode
7968                     .createInstanceFromNhxString( "something_wicked[123]",
7969                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7970             if ( !n15.getName().equals( "something_wicked" ) ) {
7971                 return false;
7972             }
7973             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
7974                 return false;
7975             }
7976             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
7977                 return false;
7978             }
7979             final PhylogenyNode n16 = PhylogenyNode
7980                     .createInstanceFromNhxString( "something_wicked2[9]",
7981                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7982             if ( !n16.getName().equals( "something_wicked2" ) ) {
7983                 return false;
7984             }
7985             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
7986                 return false;
7987             }
7988             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
7989                 return false;
7990             }
7991             final PhylogenyNode n17 = PhylogenyNode
7992                     .createInstanceFromNhxString( "something_wicked3[a]",
7993                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7994             if ( !n17.getName().equals( "something_wicked3" ) ) {
7995                 return false;
7996             }
7997             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
7998                 return false;
7999             }
8000             final PhylogenyNode n18 = PhylogenyNode
8001                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8002             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8003                 return false;
8004             }
8005             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8006                 return false;
8007             }
8008             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8009                 return false;
8010             }
8011             final PhylogenyNode n19 = PhylogenyNode
8012                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8013             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
8014                 return false;
8015             }
8016             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8017                 return false;
8018             }
8019             final PhylogenyNode n30 = PhylogenyNode
8020                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
8021                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8022             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
8023                 return false;
8024             }
8025             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8026                 return false;
8027             }
8028             final PhylogenyNode n31 = PhylogenyNode
8029                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
8030                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8031             if ( n31.getNodeData().isHasTaxonomy() ) {
8032                 return false;
8033             }
8034             final PhylogenyNode n32 = PhylogenyNode
8035                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8036             if ( n32.getNodeData().isHasTaxonomy() ) {
8037                 return false;
8038             }
8039             final PhylogenyNode n40 = PhylogenyNode
8040                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8041             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8042                 return false;
8043             }
8044             final PhylogenyNode n41 = PhylogenyNode
8045                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8046             if ( n41.getNodeData().isHasTaxonomy() ) {
8047                 return false;
8048             }
8049             final PhylogenyNode n42 = PhylogenyNode
8050                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8051             if ( n42.getNodeData().isHasTaxonomy() ) {
8052                 return false;
8053             }
8054             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
8055                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
8056             if ( n43.getNodeData().isHasTaxonomy() ) {
8057                 return false;
8058             }
8059             final PhylogenyNode n44 = PhylogenyNode
8060                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8061             if ( n44.getNodeData().isHasTaxonomy() ) {
8062                 return false;
8063             }
8064         }
8065         catch ( final Exception e ) {
8066             e.printStackTrace( System.out );
8067             return false;
8068         }
8069         return true;
8070     }
8071
8072     private static boolean testNHXParsing() {
8073         try {
8074             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8075             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
8076             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
8077                 return false;
8078             }
8079             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]";
8080             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
8081             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8082                 return false;
8083             }
8084             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]";
8085             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
8086             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
8087                 return false;
8088             }
8089             final Phylogeny[] p3 = factory
8090                     .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]",
8091                              new NHXParser() );
8092             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8093                 return false;
8094             }
8095             final Phylogeny[] p4 = factory
8096                     .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(]",
8097                              new NHXParser() );
8098             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8099                 return false;
8100             }
8101             final Phylogeny[] p5 = factory
8102                     .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(((]",
8103                              new NHXParser() );
8104             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8105                 return false;
8106             }
8107             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)";
8108             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)";
8109             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
8110             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
8111                 return false;
8112             }
8113             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)))";
8114             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)))";
8115             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
8116             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
8117                 return false;
8118             }
8119             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])   ))[,,, ])))))))";
8120             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
8121             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
8122             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
8123                 return false;
8124             }
8125             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
8126             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8127                 return false;
8128             }
8129             final Phylogeny p10 = factory
8130                     .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]",
8131                              new NHXParser() )[ 0 ];
8132             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8133                 return false;
8134             }
8135         }
8136         catch ( final Exception e ) {
8137             e.printStackTrace( System.out );
8138             return false;
8139         }
8140         return true;
8141     }
8142
8143     private static boolean testNHXParsingMB() {
8144         try {
8145             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8146             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
8147                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8148                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8149                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8150                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8151                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8152                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8153                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8154                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
8155             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
8156                 return false;
8157             }
8158             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
8159                 return false;
8160             }
8161             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8162                            0.1100000000000000e+00 ) ) {
8163                 return false;
8164             }
8165             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8166                 return false;
8167             }
8168             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8169                 return false;
8170             }
8171             final Phylogeny p2 = factory
8172                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8173                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8174                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8175                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8176                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8177                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8178                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8179                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8180                                      + "7.369400000000000e-02}])",
8181                              new NHXParser() )[ 0 ];
8182             if ( p2.getNode( "1" ) == null ) {
8183                 return false;
8184             }
8185             if ( p2.getNode( "2" ) == null ) {
8186                 return false;
8187             }
8188         }
8189         catch ( final Exception e ) {
8190             e.printStackTrace( System.out );
8191             System.exit( -1 );
8192             return false;
8193         }
8194         return true;
8195     }
8196
8197     private static boolean testNHXParsingQuotes() {
8198         try {
8199             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8200             final NHXParser p = new NHXParser();
8201             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8202             if ( phylogenies_0.length != 5 ) {
8203                 return false;
8204             }
8205             final Phylogeny phy = phylogenies_0[ 4 ];
8206             if ( phy.getNumberOfExternalNodes() != 7 ) {
8207                 return false;
8208             }
8209             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8210                 return false;
8211             }
8212             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8213                 return false;
8214             }
8215             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8216                     .getScientificName().equals( "hsapiens" ) ) {
8217                 return false;
8218             }
8219             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8220                 return false;
8221             }
8222             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8223                 return false;
8224             }
8225             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8226                 return false;
8227             }
8228             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8229                 return false;
8230             }
8231             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8232                 return false;
8233             }
8234             final NHXParser p1p = new NHXParser();
8235             p1p.setIgnoreQuotes( true );
8236             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8237             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8238                 return false;
8239             }
8240             final NHXParser p2p = new NHXParser();
8241             p1p.setIgnoreQuotes( false );
8242             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8243             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8244                 return false;
8245             }
8246             final NHXParser p3p = new NHXParser();
8247             p3p.setIgnoreQuotes( false );
8248             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8249             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8250                 return false;
8251             }
8252             final NHXParser p4p = new NHXParser();
8253             p4p.setIgnoreQuotes( false );
8254             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8255             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8256                 return false;
8257             }
8258             final Phylogeny p10 = factory
8259                     .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]",
8260                              new NHXParser() )[ 0 ];
8261             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]";
8262             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8263                 return false;
8264             }
8265             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8266             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8267                 return false;
8268             }
8269             //
8270             final Phylogeny p12 = factory
8271                     .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]",
8272                              new NHXParser() )[ 0 ];
8273             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]";
8274             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8275                 return false;
8276             }
8277             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8278             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8279                 return false;
8280             }
8281             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;";
8282             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8283                 return false;
8284             }
8285             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8286             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8287                 return false;
8288             }
8289         }
8290         catch ( final Exception e ) {
8291             e.printStackTrace( System.out );
8292             return false;
8293         }
8294         return true;
8295     }
8296
8297     private static boolean testNodeRemoval() {
8298         try {
8299             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8300             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8301             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8302             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8303                 return false;
8304             }
8305             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8306             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8307             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8308                 return false;
8309             }
8310             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8311             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8312             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8313                 return false;
8314             }
8315         }
8316         catch ( final Exception e ) {
8317             e.printStackTrace( System.out );
8318             return false;
8319         }
8320         return true;
8321     }
8322
8323     private static boolean testPhylogenyBranch() {
8324         try {
8325             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8326             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8327             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8328             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8329             if ( !a1b1.equals( a1b1 ) ) {
8330                 return false;
8331             }
8332             if ( !a1b1.equals( b1a1 ) ) {
8333                 return false;
8334             }
8335             if ( !b1a1.equals( a1b1 ) ) {
8336                 return false;
8337             }
8338             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8339             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8340             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8341             if ( a1_b1.equals( b1_a1 ) ) {
8342                 return false;
8343             }
8344             if ( a1_b1.equals( a1_b1_ ) ) {
8345                 return false;
8346             }
8347             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8348             if ( !a1_b1.equals( b1_a1_ ) ) {
8349                 return false;
8350             }
8351             if ( a1_b1_.equals( b1_a1_ ) ) {
8352                 return false;
8353             }
8354             if ( !a1_b1_.equals( b1_a1 ) ) {
8355                 return false;
8356             }
8357         }
8358         catch ( final Exception e ) {
8359             e.printStackTrace( System.out );
8360             return false;
8361         }
8362         return true;
8363     }
8364
8365     private static boolean testPhyloXMLparsingOfDistributionElement() {
8366         try {
8367             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8368             PhyloXmlParser xml_parser = null;
8369             try {
8370                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8371             }
8372             catch ( final Exception e ) {
8373                 // Do nothing -- means were not running from jar.
8374             }
8375             if ( xml_parser == null ) {
8376                 xml_parser = new PhyloXmlParser();
8377                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8378                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8379                 }
8380                 else {
8381                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8382                 }
8383             }
8384             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8385                                                               xml_parser );
8386             if ( xml_parser.getErrorCount() > 0 ) {
8387                 System.out.println( xml_parser.getErrorMessages().toString() );
8388                 return false;
8389             }
8390             if ( phylogenies_0.length != 1 ) {
8391                 return false;
8392             }
8393             final Phylogeny t1 = phylogenies_0[ 0 ];
8394             PhylogenyNode n = null;
8395             Distribution d = null;
8396             n = t1.getNode( "root node" );
8397             if ( !n.getNodeData().isHasDistribution() ) {
8398                 return false;
8399             }
8400             if ( n.getNodeData().getDistributions().size() != 1 ) {
8401                 return false;
8402             }
8403             d = n.getNodeData().getDistribution();
8404             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8405                 return false;
8406             }
8407             if ( d.getPoints().size() != 1 ) {
8408                 return false;
8409             }
8410             if ( d.getPolygons() != null ) {
8411                 return false;
8412             }
8413             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8414                 return false;
8415             }
8416             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8417                 return false;
8418             }
8419             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8420                 return false;
8421             }
8422             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8423                 return false;
8424             }
8425             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8426                 return false;
8427             }
8428             n = t1.getNode( "node a" );
8429             if ( !n.getNodeData().isHasDistribution() ) {
8430                 return false;
8431             }
8432             if ( n.getNodeData().getDistributions().size() != 2 ) {
8433                 return false;
8434             }
8435             d = n.getNodeData().getDistribution( 1 );
8436             if ( !d.getDesc().equals( "San Diego" ) ) {
8437                 return false;
8438             }
8439             if ( d.getPoints().size() != 1 ) {
8440                 return false;
8441             }
8442             if ( d.getPolygons() != null ) {
8443                 return false;
8444             }
8445             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8446                 return false;
8447             }
8448             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8449                 return false;
8450             }
8451             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8452                 return false;
8453             }
8454             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8455                 return false;
8456             }
8457             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8458                 return false;
8459             }
8460             n = t1.getNode( "node bb" );
8461             if ( !n.getNodeData().isHasDistribution() ) {
8462                 return false;
8463             }
8464             if ( n.getNodeData().getDistributions().size() != 1 ) {
8465                 return false;
8466             }
8467             d = n.getNodeData().getDistribution( 0 );
8468             if ( d.getPoints().size() != 3 ) {
8469                 return false;
8470             }
8471             if ( d.getPolygons().size() != 2 ) {
8472                 return false;
8473             }
8474             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8475                 return false;
8476             }
8477             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8478                 return false;
8479             }
8480             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8481                 return false;
8482             }
8483             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8484                 return false;
8485             }
8486             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8487                 return false;
8488             }
8489             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8490                 return false;
8491             }
8492             Polygon p = d.getPolygons().get( 0 );
8493             if ( p.getPoints().size() != 3 ) {
8494                 return false;
8495             }
8496             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8497                 return false;
8498             }
8499             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8500                 return false;
8501             }
8502             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8503                 return false;
8504             }
8505             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8506                 return false;
8507             }
8508             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8509                 return false;
8510             }
8511             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8512                 return false;
8513             }
8514             p = d.getPolygons().get( 1 );
8515             if ( p.getPoints().size() != 3 ) {
8516                 return false;
8517             }
8518             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8519                 return false;
8520             }
8521             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8522                 return false;
8523             }
8524             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8525                 return false;
8526             }
8527             // Roundtrip:
8528             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
8529             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
8530             if ( rt.length != 1 ) {
8531                 return false;
8532             }
8533             final Phylogeny t1_rt = rt[ 0 ];
8534             n = t1_rt.getNode( "root node" );
8535             if ( !n.getNodeData().isHasDistribution() ) {
8536                 return false;
8537             }
8538             if ( n.getNodeData().getDistributions().size() != 1 ) {
8539                 return false;
8540             }
8541             d = n.getNodeData().getDistribution();
8542             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8543                 return false;
8544             }
8545             if ( d.getPoints().size() != 1 ) {
8546                 return false;
8547             }
8548             if ( d.getPolygons() != null ) {
8549                 return false;
8550             }
8551             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8552                 return false;
8553             }
8554             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8555                 return false;
8556             }
8557             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8558                 return false;
8559             }
8560             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8561                 return false;
8562             }
8563             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8564                 return false;
8565             }
8566             n = t1_rt.getNode( "node a" );
8567             if ( !n.getNodeData().isHasDistribution() ) {
8568                 return false;
8569             }
8570             if ( n.getNodeData().getDistributions().size() != 2 ) {
8571                 return false;
8572             }
8573             d = n.getNodeData().getDistribution( 1 );
8574             if ( !d.getDesc().equals( "San Diego" ) ) {
8575                 return false;
8576             }
8577             if ( d.getPoints().size() != 1 ) {
8578                 return false;
8579             }
8580             if ( d.getPolygons() != null ) {
8581                 return false;
8582             }
8583             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8584                 return false;
8585             }
8586             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8587                 return false;
8588             }
8589             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8590                 return false;
8591             }
8592             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8593                 return false;
8594             }
8595             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8596                 return false;
8597             }
8598             n = t1_rt.getNode( "node bb" );
8599             if ( !n.getNodeData().isHasDistribution() ) {
8600                 return false;
8601             }
8602             if ( n.getNodeData().getDistributions().size() != 1 ) {
8603                 return false;
8604             }
8605             d = n.getNodeData().getDistribution( 0 );
8606             if ( d.getPoints().size() != 3 ) {
8607                 return false;
8608             }
8609             if ( d.getPolygons().size() != 2 ) {
8610                 return false;
8611             }
8612             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8613                 return false;
8614             }
8615             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8616                 return false;
8617             }
8618             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8619                 return false;
8620             }
8621             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8622                 return false;
8623             }
8624             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8625                 return false;
8626             }
8627             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8628                 return false;
8629             }
8630             p = d.getPolygons().get( 0 );
8631             if ( p.getPoints().size() != 3 ) {
8632                 return false;
8633             }
8634             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8635                 return false;
8636             }
8637             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8638                 return false;
8639             }
8640             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8641                 return false;
8642             }
8643             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8644                 return false;
8645             }
8646             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8647                 return false;
8648             }
8649             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8650                 return false;
8651             }
8652             p = d.getPolygons().get( 1 );
8653             if ( p.getPoints().size() != 3 ) {
8654                 return false;
8655             }
8656             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8657                 return false;
8658             }
8659             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8660                 return false;
8661             }
8662             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8663                 return false;
8664             }
8665         }
8666         catch ( final Exception e ) {
8667             e.printStackTrace( System.out );
8668             return false;
8669         }
8670         return true;
8671     }
8672
8673     private static boolean testPostOrderIterator() {
8674         try {
8675             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8676             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8677             PhylogenyNodeIterator it0;
8678             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
8679                 it0.next();
8680             }
8681             for( it0.reset(); it0.hasNext(); ) {
8682                 it0.next();
8683             }
8684             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8685             final PhylogenyNodeIterator it = t1.iteratorPostorder();
8686             if ( !it.next().getName().equals( "A" ) ) {
8687                 return false;
8688             }
8689             if ( !it.next().getName().equals( "B" ) ) {
8690                 return false;
8691             }
8692             if ( !it.next().getName().equals( "ab" ) ) {
8693                 return false;
8694             }
8695             if ( !it.next().getName().equals( "C" ) ) {
8696                 return false;
8697             }
8698             if ( !it.next().getName().equals( "D" ) ) {
8699                 return false;
8700             }
8701             if ( !it.next().getName().equals( "cd" ) ) {
8702                 return false;
8703             }
8704             if ( !it.next().getName().equals( "abcd" ) ) {
8705                 return false;
8706             }
8707             if ( !it.next().getName().equals( "E" ) ) {
8708                 return false;
8709             }
8710             if ( !it.next().getName().equals( "F" ) ) {
8711                 return false;
8712             }
8713             if ( !it.next().getName().equals( "ef" ) ) {
8714                 return false;
8715             }
8716             if ( !it.next().getName().equals( "G" ) ) {
8717                 return false;
8718             }
8719             if ( !it.next().getName().equals( "H" ) ) {
8720                 return false;
8721             }
8722             if ( !it.next().getName().equals( "gh" ) ) {
8723                 return false;
8724             }
8725             if ( !it.next().getName().equals( "efgh" ) ) {
8726                 return false;
8727             }
8728             if ( !it.next().getName().equals( "r" ) ) {
8729                 return false;
8730             }
8731             if ( it.hasNext() ) {
8732                 return false;
8733             }
8734         }
8735         catch ( final Exception e ) {
8736             e.printStackTrace( System.out );
8737             return false;
8738         }
8739         return true;
8740     }
8741
8742     private static boolean testPreOrderIterator() {
8743         try {
8744             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8745             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8746             PhylogenyNodeIterator it0;
8747             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
8748                 it0.next();
8749             }
8750             for( it0.reset(); it0.hasNext(); ) {
8751                 it0.next();
8752             }
8753             PhylogenyNodeIterator it = t0.iteratorPreorder();
8754             if ( !it.next().getName().equals( "r" ) ) {
8755                 return false;
8756             }
8757             if ( !it.next().getName().equals( "ab" ) ) {
8758                 return false;
8759             }
8760             if ( !it.next().getName().equals( "A" ) ) {
8761                 return false;
8762             }
8763             if ( !it.next().getName().equals( "B" ) ) {
8764                 return false;
8765             }
8766             if ( !it.next().getName().equals( "cd" ) ) {
8767                 return false;
8768             }
8769             if ( !it.next().getName().equals( "C" ) ) {
8770                 return false;
8771             }
8772             if ( !it.next().getName().equals( "D" ) ) {
8773                 return false;
8774             }
8775             if ( it.hasNext() ) {
8776                 return false;
8777             }
8778             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8779             it = t1.iteratorPreorder();
8780             if ( !it.next().getName().equals( "r" ) ) {
8781                 return false;
8782             }
8783             if ( !it.next().getName().equals( "abcd" ) ) {
8784                 return false;
8785             }
8786             if ( !it.next().getName().equals( "ab" ) ) {
8787                 return false;
8788             }
8789             if ( !it.next().getName().equals( "A" ) ) {
8790                 return false;
8791             }
8792             if ( !it.next().getName().equals( "B" ) ) {
8793                 return false;
8794             }
8795             if ( !it.next().getName().equals( "cd" ) ) {
8796                 return false;
8797             }
8798             if ( !it.next().getName().equals( "C" ) ) {
8799                 return false;
8800             }
8801             if ( !it.next().getName().equals( "D" ) ) {
8802                 return false;
8803             }
8804             if ( !it.next().getName().equals( "efgh" ) ) {
8805                 return false;
8806             }
8807             if ( !it.next().getName().equals( "ef" ) ) {
8808                 return false;
8809             }
8810             if ( !it.next().getName().equals( "E" ) ) {
8811                 return false;
8812             }
8813             if ( !it.next().getName().equals( "F" ) ) {
8814                 return false;
8815             }
8816             if ( !it.next().getName().equals( "gh" ) ) {
8817                 return false;
8818             }
8819             if ( !it.next().getName().equals( "G" ) ) {
8820                 return false;
8821             }
8822             if ( !it.next().getName().equals( "H" ) ) {
8823                 return false;
8824             }
8825             if ( it.hasNext() ) {
8826                 return false;
8827             }
8828         }
8829         catch ( final Exception e ) {
8830             e.printStackTrace( System.out );
8831             return false;
8832         }
8833         return true;
8834     }
8835
8836     private static boolean testPropertiesMap() {
8837         try {
8838             final PropertiesMap pm = new PropertiesMap();
8839             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8840             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8841             final Property p2 = new Property( "something:else",
8842                                               "?",
8843                                               "improbable:research",
8844                                               "xsd:decimal",
8845                                               AppliesTo.NODE );
8846             pm.addProperty( p0 );
8847             pm.addProperty( p1 );
8848             pm.addProperty( p2 );
8849             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
8850                 return false;
8851             }
8852             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
8853                 return false;
8854             }
8855             if ( pm.getProperties().size() != 3 ) {
8856                 return false;
8857             }
8858             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
8859                 return false;
8860             }
8861             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8862                 return false;
8863             }
8864             if ( pm.getProperties().size() != 3 ) {
8865                 return false;
8866             }
8867             pm.removeProperty( "dimensions:diameter" );
8868             if ( pm.getProperties().size() != 2 ) {
8869                 return false;
8870             }
8871             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
8872                 return false;
8873             }
8874             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8875                 return false;
8876             }
8877         }
8878         catch ( final Exception e ) {
8879             e.printStackTrace( System.out );
8880             return false;
8881         }
8882         return true;
8883     }
8884
8885     private static boolean testProteinId() {
8886         try {
8887             final ProteinId id1 = new ProteinId( "a" );
8888             final ProteinId id2 = new ProteinId( "a" );
8889             final ProteinId id3 = new ProteinId( "A" );
8890             final ProteinId id4 = new ProteinId( "b" );
8891             if ( !id1.equals( id1 ) ) {
8892                 return false;
8893             }
8894             if ( id1.getId().equals( "x" ) ) {
8895                 return false;
8896             }
8897             if ( id1.getId().equals( null ) ) {
8898                 return false;
8899             }
8900             if ( !id1.equals( id2 ) ) {
8901                 return false;
8902             }
8903             if ( id1.equals( id3 ) ) {
8904                 return false;
8905             }
8906             if ( id1.hashCode() != id1.hashCode() ) {
8907                 return false;
8908             }
8909             if ( id1.hashCode() != id2.hashCode() ) {
8910                 return false;
8911             }
8912             if ( id1.hashCode() == id3.hashCode() ) {
8913                 return false;
8914             }
8915             if ( id1.compareTo( id1 ) != 0 ) {
8916                 return false;
8917             }
8918             if ( id1.compareTo( id2 ) != 0 ) {
8919                 return false;
8920             }
8921             if ( id1.compareTo( id3 ) != 0 ) {
8922                 return false;
8923             }
8924             if ( id1.compareTo( id4 ) >= 0 ) {
8925                 return false;
8926             }
8927             if ( id4.compareTo( id1 ) <= 0 ) {
8928                 return false;
8929             }
8930             if ( !id4.getId().equals( "b" ) ) {
8931                 return false;
8932             }
8933             final ProteinId id5 = new ProteinId( " C " );
8934             if ( !id5.getId().equals( "C" ) ) {
8935                 return false;
8936             }
8937             if ( id5.equals( id1 ) ) {
8938                 return false;
8939             }
8940         }
8941         catch ( final Exception e ) {
8942             e.printStackTrace( System.out );
8943             return false;
8944         }
8945         return true;
8946     }
8947
8948     private static boolean testReIdMethods() {
8949         try {
8950             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8951             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
8952             final long count = PhylogenyNode.getNodeCount();
8953             p.levelOrderReID();
8954             if ( p.getNode( "r" ).getId() != count ) {
8955                 return false;
8956             }
8957             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
8958                 return false;
8959             }
8960             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
8961                 return false;
8962             }
8963             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
8964                 return false;
8965             }
8966             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
8967                 return false;
8968             }
8969             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
8970                 return false;
8971             }
8972             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
8973                 return false;
8974             }
8975             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
8976                 return false;
8977             }
8978             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
8979                 return false;
8980             }
8981             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
8982                 return false;
8983             }
8984             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
8985                 return false;
8986             }
8987             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
8988                 return false;
8989             }
8990             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
8991                 return false;
8992             }
8993             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
8994                 return false;
8995             }
8996             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
8997                 return false;
8998             }
8999         }
9000         catch ( final Exception e ) {
9001             e.printStackTrace( System.out );
9002             return false;
9003         }
9004         return true;
9005     }
9006
9007     private static boolean testRerooting() {
9008         try {
9009             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9010             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",
9011                                                  new NHXParser() )[ 0 ];
9012             if ( !t1.isRooted() ) {
9013                 return false;
9014             }
9015             t1.reRoot( t1.getNode( "D" ) );
9016             t1.reRoot( t1.getNode( "CD" ) );
9017             t1.reRoot( t1.getNode( "A" ) );
9018             t1.reRoot( t1.getNode( "B" ) );
9019             t1.reRoot( t1.getNode( "AB" ) );
9020             t1.reRoot( t1.getNode( "D" ) );
9021             t1.reRoot( t1.getNode( "C" ) );
9022             t1.reRoot( t1.getNode( "CD" ) );
9023             t1.reRoot( t1.getNode( "A" ) );
9024             t1.reRoot( t1.getNode( "B" ) );
9025             t1.reRoot( t1.getNode( "AB" ) );
9026             t1.reRoot( t1.getNode( "D" ) );
9027             t1.reRoot( t1.getNode( "D" ) );
9028             t1.reRoot( t1.getNode( "C" ) );
9029             t1.reRoot( t1.getNode( "A" ) );
9030             t1.reRoot( t1.getNode( "B" ) );
9031             t1.reRoot( t1.getNode( "AB" ) );
9032             t1.reRoot( t1.getNode( "C" ) );
9033             t1.reRoot( t1.getNode( "D" ) );
9034             t1.reRoot( t1.getNode( "CD" ) );
9035             t1.reRoot( t1.getNode( "D" ) );
9036             t1.reRoot( t1.getNode( "A" ) );
9037             t1.reRoot( t1.getNode( "B" ) );
9038             t1.reRoot( t1.getNode( "AB" ) );
9039             t1.reRoot( t1.getNode( "C" ) );
9040             t1.reRoot( t1.getNode( "D" ) );
9041             t1.reRoot( t1.getNode( "CD" ) );
9042             t1.reRoot( t1.getNode( "D" ) );
9043             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
9044                 return false;
9045             }
9046             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
9047                 return false;
9048             }
9049             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
9050                 return false;
9051             }
9052             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
9053                 return false;
9054             }
9055             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
9056                 return false;
9057             }
9058             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
9059                 return false;
9060             }
9061             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",
9062                                                  new NHXParser() )[ 0 ];
9063             t2.reRoot( t2.getNode( "A" ) );
9064             t2.reRoot( t2.getNode( "D" ) );
9065             t2.reRoot( t2.getNode( "ABC" ) );
9066             t2.reRoot( t2.getNode( "A" ) );
9067             t2.reRoot( t2.getNode( "B" ) );
9068             t2.reRoot( t2.getNode( "D" ) );
9069             t2.reRoot( t2.getNode( "C" ) );
9070             t2.reRoot( t2.getNode( "ABC" ) );
9071             t2.reRoot( t2.getNode( "A" ) );
9072             t2.reRoot( t2.getNode( "B" ) );
9073             t2.reRoot( t2.getNode( "AB" ) );
9074             t2.reRoot( t2.getNode( "AB" ) );
9075             t2.reRoot( t2.getNode( "D" ) );
9076             t2.reRoot( t2.getNode( "C" ) );
9077             t2.reRoot( t2.getNode( "B" ) );
9078             t2.reRoot( t2.getNode( "AB" ) );
9079             t2.reRoot( t2.getNode( "D" ) );
9080             t2.reRoot( t2.getNode( "D" ) );
9081             t2.reRoot( t2.getNode( "ABC" ) );
9082             t2.reRoot( t2.getNode( "A" ) );
9083             t2.reRoot( t2.getNode( "B" ) );
9084             t2.reRoot( t2.getNode( "AB" ) );
9085             t2.reRoot( t2.getNode( "D" ) );
9086             t2.reRoot( t2.getNode( "C" ) );
9087             t2.reRoot( t2.getNode( "ABC" ) );
9088             t2.reRoot( t2.getNode( "A" ) );
9089             t2.reRoot( t2.getNode( "B" ) );
9090             t2.reRoot( t2.getNode( "AB" ) );
9091             t2.reRoot( t2.getNode( "D" ) );
9092             t2.reRoot( t2.getNode( "D" ) );
9093             t2.reRoot( t2.getNode( "C" ) );
9094             t2.reRoot( t2.getNode( "A" ) );
9095             t2.reRoot( t2.getNode( "B" ) );
9096             t2.reRoot( t2.getNode( "AB" ) );
9097             t2.reRoot( t2.getNode( "C" ) );
9098             t2.reRoot( t2.getNode( "D" ) );
9099             t2.reRoot( t2.getNode( "ABC" ) );
9100             t2.reRoot( t2.getNode( "D" ) );
9101             t2.reRoot( t2.getNode( "A" ) );
9102             t2.reRoot( t2.getNode( "B" ) );
9103             t2.reRoot( t2.getNode( "AB" ) );
9104             t2.reRoot( t2.getNode( "C" ) );
9105             t2.reRoot( t2.getNode( "D" ) );
9106             t2.reRoot( t2.getNode( "ABC" ) );
9107             t2.reRoot( t2.getNode( "D" ) );
9108             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9109                 return false;
9110             }
9111             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9112                 return false;
9113             }
9114             t2.reRoot( t2.getNode( "ABC" ) );
9115             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9116                 return false;
9117             }
9118             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9119                 return false;
9120             }
9121             t2.reRoot( t2.getNode( "AB" ) );
9122             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9123                 return false;
9124             }
9125             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9126                 return false;
9127             }
9128             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9129                 return false;
9130             }
9131             t2.reRoot( t2.getNode( "AB" ) );
9132             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9133                 return false;
9134             }
9135             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9136                 return false;
9137             }
9138             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9139                 return false;
9140             }
9141             t2.reRoot( t2.getNode( "D" ) );
9142             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9143                 return false;
9144             }
9145             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9146                 return false;
9147             }
9148             t2.reRoot( t2.getNode( "ABC" ) );
9149             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9150                 return false;
9151             }
9152             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9153                 return false;
9154             }
9155             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
9156                                                  new NHXParser() )[ 0 ];
9157             t3.reRoot( t3.getNode( "B" ) );
9158             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9159                 return false;
9160             }
9161             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9162                 return false;
9163             }
9164             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9165                 return false;
9166             }
9167             t3.reRoot( t3.getNode( "B" ) );
9168             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9169                 return false;
9170             }
9171             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9172                 return false;
9173             }
9174             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9175                 return false;
9176             }
9177             t3.reRoot( t3.getRoot() );
9178             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9179                 return false;
9180             }
9181             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9182                 return false;
9183             }
9184             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9185                 return false;
9186             }
9187         }
9188         catch ( final Exception e ) {
9189             e.printStackTrace( System.out );
9190             return false;
9191         }
9192         return true;
9193     }
9194
9195     private static boolean testSDIse() {
9196         try {
9197             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9198             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9199             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9200             gene1.setRooted( true );
9201             species1.setRooted( true );
9202             final SDI sdi = new SDI( gene1, species1 );
9203             if ( !gene1.getRoot().isDuplication() ) {
9204                 return false;
9205             }
9206             final Phylogeny species2 = factory
9207                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9208                              new NHXParser() )[ 0 ];
9209             final Phylogeny gene2 = factory
9210                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9211                              new NHXParser() )[ 0 ];
9212             species2.setRooted( true );
9213             gene2.setRooted( true );
9214             final SDI sdi2 = new SDI( gene2, species2 );
9215             if ( sdi2.getDuplicationsSum() != 0 ) {
9216                 return false;
9217             }
9218             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9219                 return false;
9220             }
9221             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9222                 return false;
9223             }
9224             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9225                 return false;
9226             }
9227             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9228                 return false;
9229             }
9230             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9231                 return false;
9232             }
9233             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9234                 return false;
9235             }
9236             final Phylogeny species3 = factory
9237                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9238                              new NHXParser() )[ 0 ];
9239             final Phylogeny gene3 = factory
9240                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9241                              new NHXParser() )[ 0 ];
9242             species3.setRooted( true );
9243             gene3.setRooted( true );
9244             final SDI sdi3 = new SDI( gene3, species3 );
9245             if ( sdi3.getDuplicationsSum() != 1 ) {
9246                 return false;
9247             }
9248             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9249                 return false;
9250             }
9251             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9252                 return false;
9253             }
9254             final Phylogeny species4 = factory
9255                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9256                              new NHXParser() )[ 0 ];
9257             final Phylogeny gene4 = factory
9258                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9259                              new NHXParser() )[ 0 ];
9260             species4.setRooted( true );
9261             gene4.setRooted( true );
9262             final SDI sdi4 = new SDI( gene4, species4 );
9263             if ( sdi4.getDuplicationsSum() != 1 ) {
9264                 return false;
9265             }
9266             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9267                 return false;
9268             }
9269             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9270                 return false;
9271             }
9272             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9273                 return false;
9274             }
9275             if ( species4.getNumberOfExternalNodes() != 6 ) {
9276                 return false;
9277             }
9278             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9279                 return false;
9280             }
9281             final Phylogeny species5 = factory
9282                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9283                              new NHXParser() )[ 0 ];
9284             final Phylogeny gene5 = factory
9285                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9286                              new NHXParser() )[ 0 ];
9287             species5.setRooted( true );
9288             gene5.setRooted( true );
9289             final SDI sdi5 = new SDI( gene5, species5 );
9290             if ( sdi5.getDuplicationsSum() != 2 ) {
9291                 return false;
9292             }
9293             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9294                 return false;
9295             }
9296             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9297                 return false;
9298             }
9299             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9300                 return false;
9301             }
9302             if ( species5.getNumberOfExternalNodes() != 6 ) {
9303                 return false;
9304             }
9305             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9306                 return false;
9307             }
9308             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9309             // Conjecture for Comparing Molecular Phylogenies"
9310             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9311             final Phylogeny species6 = factory
9312                     .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,"
9313                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9314                              new NHXParser() )[ 0 ];
9315             final Phylogeny gene6 = factory
9316                     .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,"
9317                                      + "((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,"
9318                                      + "(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;",
9319                              new NHXParser() )[ 0 ];
9320             species6.setRooted( true );
9321             gene6.setRooted( true );
9322             final SDI sdi6 = new SDI( gene6, species6 );
9323             if ( sdi6.getDuplicationsSum() != 3 ) {
9324                 return false;
9325             }
9326             if ( !gene6.getNode( "r" ).isDuplication() ) {
9327                 return false;
9328             }
9329             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9330                 return false;
9331             }
9332             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9333                 return false;
9334             }
9335             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9336                 return false;
9337             }
9338             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9339                 return false;
9340             }
9341             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9342                 return false;
9343             }
9344             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9345                 return false;
9346             }
9347             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9348                 return false;
9349             }
9350             sdi6.computeMappingCostL();
9351             if ( sdi6.computeMappingCostL() != 17 ) {
9352                 return false;
9353             }
9354             if ( species6.getNumberOfExternalNodes() != 9 ) {
9355                 return false;
9356             }
9357             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9358                 return false;
9359             }
9360             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9361                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9362                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9363                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9364                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9365             species7.setRooted( true );
9366             final Phylogeny gene7_1 = Test
9367                     .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])" );
9368             gene7_1.setRooted( true );
9369             final SDI sdi7 = new SDI( gene7_1, species7 );
9370             if ( sdi7.getDuplicationsSum() != 0 ) {
9371                 return false;
9372             }
9373             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9374                 return false;
9375             }
9376             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9377                 return false;
9378             }
9379             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9380                 return false;
9381             }
9382             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9383                 return false;
9384             }
9385             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9386                 return false;
9387             }
9388             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9389                 return false;
9390             }
9391             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9392                 return false;
9393             }
9394             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9395                 return false;
9396             }
9397             final Phylogeny gene7_2 = Test
9398                     .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])" );
9399             gene7_2.setRooted( true );
9400             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9401             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9402                 return false;
9403             }
9404             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9405                 return false;
9406             }
9407             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9408                 return false;
9409             }
9410             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9411                 return false;
9412             }
9413             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9414                 return false;
9415             }
9416             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9417                 return false;
9418             }
9419             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9420                 return false;
9421             }
9422             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9423                 return false;
9424             }
9425             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9426                 return false;
9427             }
9428             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9429                 return false;
9430             }
9431         }
9432         catch ( final Exception e ) {
9433             return false;
9434         }
9435         return true;
9436     }
9437
9438     private static boolean testSDIunrooted() {
9439         try {
9440             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9441             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9442             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9443             final Iterator<PhylogenyBranch> iter = l.iterator();
9444             PhylogenyBranch br = iter.next();
9445             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9446                 return false;
9447             }
9448             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9449                 return false;
9450             }
9451             br = iter.next();
9452             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9453                 return false;
9454             }
9455             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9456                 return false;
9457             }
9458             br = iter.next();
9459             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9460                 return false;
9461             }
9462             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9463                 return false;
9464             }
9465             br = iter.next();
9466             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9467                 return false;
9468             }
9469             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9470                 return false;
9471             }
9472             br = iter.next();
9473             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9474                 return false;
9475             }
9476             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9477                 return false;
9478             }
9479             br = iter.next();
9480             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9481                 return false;
9482             }
9483             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9484                 return false;
9485             }
9486             br = iter.next();
9487             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9488                 return false;
9489             }
9490             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9491                 return false;
9492             }
9493             br = iter.next();
9494             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9495                 return false;
9496             }
9497             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9498                 return false;
9499             }
9500             br = iter.next();
9501             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9502                 return false;
9503             }
9504             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9505                 return false;
9506             }
9507             br = iter.next();
9508             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9509                 return false;
9510             }
9511             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9512                 return false;
9513             }
9514             br = iter.next();
9515             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9516                 return false;
9517             }
9518             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9519                 return false;
9520             }
9521             br = iter.next();
9522             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
9523                 return false;
9524             }
9525             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
9526                 return false;
9527             }
9528             br = iter.next();
9529             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9530                 return false;
9531             }
9532             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9533                 return false;
9534             }
9535             br = iter.next();
9536             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
9537                 return false;
9538             }
9539             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
9540                 return false;
9541             }
9542             br = iter.next();
9543             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
9544                 return false;
9545             }
9546             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
9547                 return false;
9548             }
9549             if ( iter.hasNext() ) {
9550                 return false;
9551             }
9552             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
9553             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
9554             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
9555             br = iter1.next();
9556             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9557                 return false;
9558             }
9559             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9560                 return false;
9561             }
9562             br = iter1.next();
9563             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9564                 return false;
9565             }
9566             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9567                 return false;
9568             }
9569             br = iter1.next();
9570             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9571                 return false;
9572             }
9573             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9574                 return false;
9575             }
9576             if ( iter1.hasNext() ) {
9577                 return false;
9578             }
9579             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
9580             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
9581             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
9582             br = iter2.next();
9583             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9584                 return false;
9585             }
9586             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9587                 return false;
9588             }
9589             br = iter2.next();
9590             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9591                 return false;
9592             }
9593             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9594                 return false;
9595             }
9596             br = iter2.next();
9597             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9598                 return false;
9599             }
9600             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9601                 return false;
9602             }
9603             if ( iter2.hasNext() ) {
9604                 return false;
9605             }
9606             final Phylogeny species0 = factory
9607                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9608                              new NHXParser() )[ 0 ];
9609             final Phylogeny gene1 = factory
9610                     .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])",
9611                              new NHXParser() )[ 0 ];
9612             species0.setRooted( true );
9613             gene1.setRooted( true );
9614             final SDIR sdi_unrooted = new SDIR();
9615             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
9616             if ( sdi_unrooted.getCount() != 1 ) {
9617                 return false;
9618             }
9619             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
9620                 return false;
9621             }
9622             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
9623                 return false;
9624             }
9625             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
9626                 return false;
9627             }
9628             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9629                 return false;
9630             }
9631             final Phylogeny gene2 = factory
9632                     .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])",
9633                              new NHXParser() )[ 0 ];
9634             gene2.setRooted( true );
9635             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
9636             if ( sdi_unrooted.getCount() != 1 ) {
9637                 return false;
9638             }
9639             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9640                 return false;
9641             }
9642             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9643                 return false;
9644             }
9645             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
9646                 return false;
9647             }
9648             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9649                 return false;
9650             }
9651             final Phylogeny species6 = factory
9652                     .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,"
9653                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9654                              new NHXParser() )[ 0 ];
9655             final Phylogeny gene6 = factory
9656                     .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],"
9657                                      + "(((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],"
9658                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9659                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9660                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9661                              new NHXParser() )[ 0 ];
9662             species6.setRooted( true );
9663             gene6.setRooted( true );
9664             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
9665             if ( sdi_unrooted.getCount() != 1 ) {
9666                 return false;
9667             }
9668             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9669                 return false;
9670             }
9671             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9672                 return false;
9673             }
9674             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9675                 return false;
9676             }
9677             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9678                 return false;
9679             }
9680             if ( !p6[ 0 ].getRoot().isDuplication() ) {
9681                 return false;
9682             }
9683             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9684                 return false;
9685             }
9686             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9687                 return false;
9688             }
9689             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
9690                 return false;
9691             }
9692             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9693                 return false;
9694             }
9695             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
9696                 return false;
9697             }
9698             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
9699                 return false;
9700             }
9701             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9702                 return false;
9703             }
9704             p6 = null;
9705             final Phylogeny species7 = factory
9706                     .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,"
9707                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9708                              new NHXParser() )[ 0 ];
9709             final Phylogeny gene7 = factory
9710                     .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],"
9711                                      + "(((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],"
9712                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9713                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9714                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9715                              new NHXParser() )[ 0 ];
9716             species7.setRooted( true );
9717             gene7.setRooted( true );
9718             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
9719             if ( sdi_unrooted.getCount() != 1 ) {
9720                 return false;
9721             }
9722             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9723                 return false;
9724             }
9725             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9726                 return false;
9727             }
9728             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9729                 return false;
9730             }
9731             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
9732                 return false;
9733             }
9734             if ( !p7[ 0 ].getRoot().isDuplication() ) {
9735                 return false;
9736             }
9737             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9738                 return false;
9739             }
9740             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9741                 return false;
9742             }
9743             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
9744                 return false;
9745             }
9746             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9747                 return false;
9748             }
9749             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
9750                 return false;
9751             }
9752             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
9753                 return false;
9754             }
9755             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9756                 return false;
9757             }
9758             p7 = null;
9759             final Phylogeny species8 = factory
9760                     .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,"
9761                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9762                              new NHXParser() )[ 0 ];
9763             final Phylogeny gene8 = factory
9764                     .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],"
9765                                      + "(((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],"
9766                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9767                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9768                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9769                              new NHXParser() )[ 0 ];
9770             species8.setRooted( true );
9771             gene8.setRooted( true );
9772             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
9773             if ( sdi_unrooted.getCount() != 1 ) {
9774                 return false;
9775             }
9776             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9777                 return false;
9778             }
9779             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9780                 return false;
9781             }
9782             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9783                 return false;
9784             }
9785             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9786                 return false;
9787             }
9788             if ( !p8[ 0 ].getRoot().isDuplication() ) {
9789                 return false;
9790             }
9791             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9792                 return false;
9793             }
9794             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9795                 return false;
9796             }
9797             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
9798                 return false;
9799             }
9800             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9801                 return false;
9802             }
9803             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
9804                 return false;
9805             }
9806             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
9807                 return false;
9808             }
9809             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9810                 return false;
9811             }
9812             p8 = null;
9813         }
9814         catch ( final Exception e ) {
9815             e.printStackTrace( System.out );
9816             return false;
9817         }
9818         return true;
9819     }
9820
9821     private static boolean testSequenceIdParsing() {
9822         try {
9823             Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
9824             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9825                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9826                 if ( id != null ) {
9827                     System.out.println( "value   =" + id.getValue() );
9828                     System.out.println( "provider=" + id.getProvider() );
9829                 }
9830                 return false;
9831             }
9832             //
9833             id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
9834             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9835                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9836                 if ( id != null ) {
9837                     System.out.println( "value   =" + id.getValue() );
9838                     System.out.println( "provider=" + id.getProvider() );
9839                 }
9840                 return false;
9841             }
9842             //
9843             id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
9844             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9845                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9846                 if ( id != null ) {
9847                     System.out.println( "value   =" + id.getValue() );
9848                     System.out.println( "provider=" + id.getProvider() );
9849                 }
9850                 return false;
9851             }
9852             // 
9853             id = SequenceIdParser.parse( "gb_AAA96518_1" );
9854             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9855                     || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
9856                 if ( id != null ) {
9857                     System.out.println( "value   =" + id.getValue() );
9858                     System.out.println( "provider=" + id.getProvider() );
9859                 }
9860                 return false;
9861             }
9862             // 
9863             id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
9864             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9865                     || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
9866                 if ( id != null ) {
9867                     System.out.println( "value   =" + id.getValue() );
9868                     System.out.println( "provider=" + id.getProvider() );
9869                 }
9870                 return false;
9871             }
9872             // 
9873             id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
9874             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9875                     || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
9876                 if ( id != null ) {
9877                     System.out.println( "value   =" + id.getValue() );
9878                     System.out.println( "provider=" + id.getProvider() );
9879                 }
9880                 return false;
9881             }
9882             // 
9883             id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
9884             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9885                     || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
9886                 if ( id != null ) {
9887                     System.out.println( "value   =" + id.getValue() );
9888                     System.out.println( "provider=" + id.getProvider() );
9889                 }
9890                 return false;
9891             }
9892             // 
9893             id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
9894             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9895                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
9896                 if ( id != null ) {
9897                     System.out.println( "value   =" + id.getValue() );
9898                     System.out.println( "provider=" + id.getProvider() );
9899                 }
9900                 return false;
9901             }
9902             // 
9903             id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
9904             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9905                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
9906                 if ( id != null ) {
9907                     System.out.println( "value   =" + id.getValue() );
9908                     System.out.println( "provider=" + id.getProvider() );
9909                 }
9910                 return false;
9911             }
9912             // 
9913             id = SequenceIdParser.parse( "P4A123" );
9914             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9915                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9916                 if ( id != null ) {
9917                     System.out.println( "value   =" + id.getValue() );
9918                     System.out.println( "provider=" + id.getProvider() );
9919                 }
9920                 return false;
9921             }
9922             // 
9923             id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
9924             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9925                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9926                 if ( id != null ) {
9927                     System.out.println( "value   =" + id.getValue() );
9928                     System.out.println( "provider=" + id.getProvider() );
9929                 }
9930                 return false;
9931             }
9932             // 
9933             id = SequenceIdParser.parse( "XP_12345" );
9934             if ( id != null ) {
9935                 System.out.println( "value   =" + id.getValue() );
9936                 System.out.println( "provider=" + id.getProvider() );
9937                 return false;
9938             }
9939             // lcl_91970_unknown_
9940         }
9941         catch ( final Exception e ) {
9942             e.printStackTrace( System.out );
9943             return false;
9944         }
9945         return true;
9946     }
9947
9948     private static boolean testSequenceWriter() {
9949         try {
9950             final String n = ForesterUtil.LINE_SEPARATOR;
9951             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9952                 return false;
9953             }
9954             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9955                 return false;
9956             }
9957             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9958                 return false;
9959             }
9960             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9961                 return false;
9962             }
9963             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9964                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9965                 return false;
9966             }
9967             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9968                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9969                 return false;
9970             }
9971         }
9972         catch ( final Exception e ) {
9973             e.printStackTrace();
9974             return false;
9975         }
9976         return true;
9977     }
9978
9979     private static boolean testSpecies() {
9980         try {
9981             final Species s1 = new BasicSpecies( "a" );
9982             final Species s2 = new BasicSpecies( "a" );
9983             final Species s3 = new BasicSpecies( "A" );
9984             final Species s4 = new BasicSpecies( "b" );
9985             if ( !s1.equals( s1 ) ) {
9986                 return false;
9987             }
9988             if ( s1.getSpeciesId().equals( "x" ) ) {
9989                 return false;
9990             }
9991             if ( s1.getSpeciesId().equals( null ) ) {
9992                 return false;
9993             }
9994             if ( !s1.equals( s2 ) ) {
9995                 return false;
9996             }
9997             if ( s1.equals( s3 ) ) {
9998                 return false;
9999             }
10000             if ( s1.hashCode() != s1.hashCode() ) {
10001                 return false;
10002             }
10003             if ( s1.hashCode() != s2.hashCode() ) {
10004                 return false;
10005             }
10006             if ( s1.hashCode() == s3.hashCode() ) {
10007                 return false;
10008             }
10009             if ( s1.compareTo( s1 ) != 0 ) {
10010                 return false;
10011             }
10012             if ( s1.compareTo( s2 ) != 0 ) {
10013                 return false;
10014             }
10015             if ( s1.compareTo( s3 ) != 0 ) {
10016                 return false;
10017             }
10018             if ( s1.compareTo( s4 ) >= 0 ) {
10019                 return false;
10020             }
10021             if ( s4.compareTo( s1 ) <= 0 ) {
10022                 return false;
10023             }
10024             if ( !s4.getSpeciesId().equals( "b" ) ) {
10025                 return false;
10026             }
10027             final Species s5 = new BasicSpecies( " C " );
10028             if ( !s5.getSpeciesId().equals( "C" ) ) {
10029                 return false;
10030             }
10031             if ( s5.equals( s1 ) ) {
10032                 return false;
10033             }
10034         }
10035         catch ( final Exception e ) {
10036             e.printStackTrace( System.out );
10037             return false;
10038         }
10039         return true;
10040     }
10041
10042     private static boolean testSplit() {
10043         try {
10044             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10045             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10046             //Archaeopteryx.createApplication( p0 );
10047             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10048             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10049             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10050             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10051             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10052             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10053             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10054             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10055             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10056             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10057             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
10058             // System.out.println( s0.toString() );
10059             //
10060             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10063             if ( s0.match( query_nodes ) ) {
10064                 return false;
10065             }
10066             query_nodes = new HashSet<PhylogenyNode>();
10067             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10068             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10070             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10071             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10072             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10074             if ( !s0.match( query_nodes ) ) {
10075                 return false;
10076             }
10077             //
10078             query_nodes = new HashSet<PhylogenyNode>();
10079             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10080             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10081             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10082             if ( !s0.match( query_nodes ) ) {
10083                 return false;
10084             }
10085             //
10086             query_nodes = new HashSet<PhylogenyNode>();
10087             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10089             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10090             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10091             if ( !s0.match( query_nodes ) ) {
10092                 return false;
10093             }
10094             //
10095             query_nodes = new HashSet<PhylogenyNode>();
10096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10098             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10099             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10100             if ( !s0.match( query_nodes ) ) {
10101                 return false;
10102             }
10103             //
10104             query_nodes = new HashSet<PhylogenyNode>();
10105             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10108             if ( !s0.match( query_nodes ) ) {
10109                 return false;
10110             }
10111             //
10112             query_nodes = new HashSet<PhylogenyNode>();
10113             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10115             if ( !s0.match( query_nodes ) ) {
10116                 return false;
10117             }
10118             //
10119             query_nodes = new HashSet<PhylogenyNode>();
10120             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10121             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10122             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10123             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10124             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10125             if ( !s0.match( query_nodes ) ) {
10126                 return false;
10127             }
10128             //
10129             query_nodes = new HashSet<PhylogenyNode>();
10130             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10131             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10133             if ( !s0.match( query_nodes ) ) {
10134                 return false;
10135             }
10136             //
10137             query_nodes = new HashSet<PhylogenyNode>();
10138             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10139             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10142             if ( !s0.match( query_nodes ) ) {
10143                 return false;
10144             }
10145             //
10146             query_nodes = new HashSet<PhylogenyNode>();
10147             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10148             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10149             if ( s0.match( query_nodes ) ) {
10150                 return false;
10151             }
10152             //
10153             query_nodes = new HashSet<PhylogenyNode>();
10154             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10155             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10156             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10158             if ( s0.match( query_nodes ) ) {
10159                 return false;
10160             }
10161             //
10162             query_nodes = new HashSet<PhylogenyNode>();
10163             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10164             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10167             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10168             if ( s0.match( query_nodes ) ) {
10169                 return false;
10170             }
10171             //
10172             query_nodes = new HashSet<PhylogenyNode>();
10173             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10174             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10175             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10176             if ( s0.match( query_nodes ) ) {
10177                 return false;
10178             }
10179             //
10180             query_nodes = new HashSet<PhylogenyNode>();
10181             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10182             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10183             if ( s0.match( query_nodes ) ) {
10184                 return false;
10185             }
10186             //
10187             query_nodes = new HashSet<PhylogenyNode>();
10188             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10189             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10190             if ( s0.match( query_nodes ) ) {
10191                 return false;
10192             }
10193             //
10194             query_nodes = new HashSet<PhylogenyNode>();
10195             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10196             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10197             if ( s0.match( query_nodes ) ) {
10198                 return false;
10199             }
10200             //
10201             query_nodes = new HashSet<PhylogenyNode>();
10202             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10203             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10204             if ( s0.match( query_nodes ) ) {
10205                 return false;
10206             }
10207             //
10208             query_nodes = new HashSet<PhylogenyNode>();
10209             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10210             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10211             if ( s0.match( query_nodes ) ) {
10212                 return false;
10213             }
10214             //
10215             query_nodes = new HashSet<PhylogenyNode>();
10216             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10217             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10218             if ( s0.match( query_nodes ) ) {
10219                 return false;
10220             }
10221             //
10222             query_nodes = new HashSet<PhylogenyNode>();
10223             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10224             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10225             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10226             if ( s0.match( query_nodes ) ) {
10227                 return false;
10228             }
10229             //
10230             query_nodes = new HashSet<PhylogenyNode>();
10231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10232             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10233             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10234             if ( s0.match( query_nodes ) ) {
10235                 return false;
10236             }
10237             //
10238             query_nodes = new HashSet<PhylogenyNode>();
10239             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10240             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10241             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10242             if ( s0.match( query_nodes ) ) {
10243                 return false;
10244             }
10245             //
10246             query_nodes = new HashSet<PhylogenyNode>();
10247             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10248             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10249             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10250             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10251             if ( s0.match( query_nodes ) ) {
10252                 return false;
10253             }
10254             /////////
10255             //            query_nodes = new HashSet<PhylogenyNode>();
10256             //            query_nodes.add( new PhylogenyNode( "X" ) );
10257             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10258             //            query_nodes.add( new PhylogenyNode( "A" ) );
10259             //            query_nodes.add( new PhylogenyNode( "B" ) );
10260             //            query_nodes.add( new PhylogenyNode( "C" ) );
10261             //            query_nodes.add( new PhylogenyNode( "D" ) );
10262             //            query_nodes.add( new PhylogenyNode( "E" ) );
10263             //            query_nodes.add( new PhylogenyNode( "F" ) );
10264             //            query_nodes.add( new PhylogenyNode( "G" ) );
10265             //            if ( !s0.match( query_nodes ) ) {
10266             //                return false;
10267             //            }
10268             //            query_nodes = new HashSet<PhylogenyNode>();
10269             //            query_nodes.add( new PhylogenyNode( "X" ) );
10270             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10271             //            query_nodes.add( new PhylogenyNode( "A" ) );
10272             //            query_nodes.add( new PhylogenyNode( "B" ) );
10273             //            query_nodes.add( new PhylogenyNode( "C" ) );
10274             //            if ( !s0.match( query_nodes ) ) {
10275             //                return false;
10276             //            }
10277             //            //
10278             //            query_nodes = new HashSet<PhylogenyNode>();
10279             //            query_nodes.add( new PhylogenyNode( "X" ) );
10280             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10281             //            query_nodes.add( new PhylogenyNode( "D" ) );
10282             //            query_nodes.add( new PhylogenyNode( "E" ) );
10283             //            query_nodes.add( new PhylogenyNode( "F" ) );
10284             //            query_nodes.add( new PhylogenyNode( "G" ) );
10285             //            if ( !s0.match( query_nodes ) ) {
10286             //                return false;
10287             //            }
10288             //            //
10289             //            query_nodes = new HashSet<PhylogenyNode>();
10290             //            query_nodes.add( new PhylogenyNode( "X" ) );
10291             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10292             //            query_nodes.add( new PhylogenyNode( "A" ) );
10293             //            query_nodes.add( new PhylogenyNode( "B" ) );
10294             //            query_nodes.add( new PhylogenyNode( "C" ) );
10295             //            query_nodes.add( new PhylogenyNode( "D" ) );
10296             //            if ( !s0.match( query_nodes ) ) {
10297             //                return false;
10298             //            }
10299             //            //
10300             //            query_nodes = new HashSet<PhylogenyNode>();
10301             //            query_nodes.add( new PhylogenyNode( "X" ) );
10302             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10303             //            query_nodes.add( new PhylogenyNode( "E" ) );
10304             //            query_nodes.add( new PhylogenyNode( "F" ) );
10305             //            query_nodes.add( new PhylogenyNode( "G" ) );
10306             //            if ( !s0.match( query_nodes ) ) {
10307             //                return false;
10308             //            }
10309             //            //
10310             //            query_nodes = new HashSet<PhylogenyNode>();
10311             //            query_nodes.add( new PhylogenyNode( "X" ) );
10312             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10313             //            query_nodes.add( new PhylogenyNode( "F" ) );
10314             //            query_nodes.add( new PhylogenyNode( "G" ) );
10315             //            if ( !s0.match( query_nodes ) ) {
10316             //                return false;
10317             //            }
10318             //
10319             query_nodes = new HashSet<PhylogenyNode>();
10320             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10321             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10322             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10323             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10324             if ( s0.match( query_nodes ) ) {
10325                 return false;
10326             }
10327             //
10328             query_nodes = new HashSet<PhylogenyNode>();
10329             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10330             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10331             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10332             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10333             if ( s0.match( query_nodes ) ) {
10334                 return false;
10335             }
10336             ///////////////////////////
10337             //
10338             query_nodes = new HashSet<PhylogenyNode>();
10339             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10340             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10341             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10342             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10343             if ( s0.match( query_nodes ) ) {
10344                 return false;
10345             }
10346             //
10347             query_nodes = new HashSet<PhylogenyNode>();
10348             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10349             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10350             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10351             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10352             if ( s0.match( query_nodes ) ) {
10353                 return false;
10354             }
10355             //
10356             query_nodes = new HashSet<PhylogenyNode>();
10357             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10358             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10360             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10361             if ( s0.match( query_nodes ) ) {
10362                 return false;
10363             }
10364             //
10365             query_nodes = new HashSet<PhylogenyNode>();
10366             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10367             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10368             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10370             if ( s0.match( query_nodes ) ) {
10371                 return false;
10372             }
10373             //
10374             query_nodes = new HashSet<PhylogenyNode>();
10375             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10376             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10377             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10378             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10379             if ( s0.match( query_nodes ) ) {
10380                 return false;
10381             }
10382             //
10383             query_nodes = new HashSet<PhylogenyNode>();
10384             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10385             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10386             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10387             if ( s0.match( query_nodes ) ) {
10388                 return false;
10389             }
10390             //
10391             query_nodes = new HashSet<PhylogenyNode>();
10392             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10393             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10394             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10396             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10397             if ( s0.match( query_nodes ) ) {
10398                 return false;
10399             }
10400             //
10401             query_nodes = new HashSet<PhylogenyNode>();
10402             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10404             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10405             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10406             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10407             if ( s0.match( query_nodes ) ) {
10408                 return false;
10409             }
10410             //
10411             query_nodes = new HashSet<PhylogenyNode>();
10412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10415             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10416             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10417             if ( s0.match( query_nodes ) ) {
10418                 return false;
10419             }
10420             //
10421             query_nodes = new HashSet<PhylogenyNode>();
10422             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10423             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10424             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10425             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10426             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10428             if ( s0.match( query_nodes ) ) {
10429                 return false;
10430             }
10431         }
10432         catch ( final Exception e ) {
10433             e.printStackTrace();
10434             return false;
10435         }
10436         return true;
10437     }
10438
10439     private static boolean testSplitStrict() {
10440         try {
10441             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10442             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10443             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10444             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10445             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10446             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10447             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10448             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10449             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10450             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10451             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
10452             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10453             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10455             if ( s0.match( query_nodes ) ) {
10456                 return false;
10457             }
10458             query_nodes = new HashSet<PhylogenyNode>();
10459             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10460             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10461             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10465             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10466             if ( !s0.match( query_nodes ) ) {
10467                 return false;
10468             }
10469             //
10470             query_nodes = new HashSet<PhylogenyNode>();
10471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10474             if ( !s0.match( query_nodes ) ) {
10475                 return false;
10476             }
10477             //
10478             query_nodes = new HashSet<PhylogenyNode>();
10479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10482             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10483             if ( !s0.match( query_nodes ) ) {
10484                 return false;
10485             }
10486             //
10487             query_nodes = new HashSet<PhylogenyNode>();
10488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10490             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10491             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10492             if ( !s0.match( query_nodes ) ) {
10493                 return false;
10494             }
10495             //
10496             query_nodes = new HashSet<PhylogenyNode>();
10497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10498             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10499             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10500             if ( !s0.match( query_nodes ) ) {
10501                 return false;
10502             }
10503             //
10504             query_nodes = new HashSet<PhylogenyNode>();
10505             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10506             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10507             if ( !s0.match( query_nodes ) ) {
10508                 return false;
10509             }
10510             //
10511             query_nodes = new HashSet<PhylogenyNode>();
10512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10513             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10514             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10515             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10516             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10517             if ( !s0.match( query_nodes ) ) {
10518                 return false;
10519             }
10520             //
10521             query_nodes = new HashSet<PhylogenyNode>();
10522             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10523             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10524             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10525             if ( !s0.match( query_nodes ) ) {
10526                 return false;
10527             }
10528             //
10529             query_nodes = new HashSet<PhylogenyNode>();
10530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10533             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10534             if ( !s0.match( query_nodes ) ) {
10535                 return false;
10536             }
10537             //
10538             query_nodes = new HashSet<PhylogenyNode>();
10539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10541             if ( s0.match( query_nodes ) ) {
10542                 return false;
10543             }
10544             //
10545             query_nodes = new HashSet<PhylogenyNode>();
10546             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10550             if ( s0.match( query_nodes ) ) {
10551                 return false;
10552             }
10553             //
10554             query_nodes = new HashSet<PhylogenyNode>();
10555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10557             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10558             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10559             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10560             if ( s0.match( query_nodes ) ) {
10561                 return false;
10562             }
10563             //
10564             query_nodes = new HashSet<PhylogenyNode>();
10565             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10566             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10567             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10568             if ( s0.match( query_nodes ) ) {
10569                 return false;
10570             }
10571             //
10572             query_nodes = new HashSet<PhylogenyNode>();
10573             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10574             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10575             if ( s0.match( query_nodes ) ) {
10576                 return false;
10577             }
10578             //
10579             query_nodes = new HashSet<PhylogenyNode>();
10580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10582             if ( s0.match( query_nodes ) ) {
10583                 return false;
10584             }
10585             //
10586             query_nodes = new HashSet<PhylogenyNode>();
10587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10589             if ( s0.match( query_nodes ) ) {
10590                 return false;
10591             }
10592             //
10593             query_nodes = new HashSet<PhylogenyNode>();
10594             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10595             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10596             if ( s0.match( query_nodes ) ) {
10597                 return false;
10598             }
10599             //
10600             query_nodes = new HashSet<PhylogenyNode>();
10601             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10602             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10603             if ( s0.match( query_nodes ) ) {
10604                 return false;
10605             }
10606             //
10607             query_nodes = new HashSet<PhylogenyNode>();
10608             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10609             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10610             if ( s0.match( query_nodes ) ) {
10611                 return false;
10612             }
10613             //
10614             query_nodes = new HashSet<PhylogenyNode>();
10615             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10618             if ( s0.match( query_nodes ) ) {
10619                 return false;
10620             }
10621             //
10622             query_nodes = new HashSet<PhylogenyNode>();
10623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10626             if ( s0.match( query_nodes ) ) {
10627                 return false;
10628             }
10629             //
10630             query_nodes = new HashSet<PhylogenyNode>();
10631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10634             if ( s0.match( query_nodes ) ) {
10635                 return false;
10636             }
10637             //
10638             query_nodes = new HashSet<PhylogenyNode>();
10639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10641             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10642             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10643             if ( s0.match( query_nodes ) ) {
10644                 return false;
10645             }
10646         }
10647         catch ( final Exception e ) {
10648             e.printStackTrace();
10649             return false;
10650         }
10651         return true;
10652     }
10653
10654     private static boolean testSubtreeDeletion() {
10655         try {
10656             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10657             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10658             t1.deleteSubtree( t1.getNode( "A" ), false );
10659             if ( t1.getNumberOfExternalNodes() != 5 ) {
10660                 return false;
10661             }
10662             t1.toNewHampshireX();
10663             t1.deleteSubtree( t1.getNode( "E" ), false );
10664             if ( t1.getNumberOfExternalNodes() != 4 ) {
10665                 return false;
10666             }
10667             t1.toNewHampshireX();
10668             t1.deleteSubtree( t1.getNode( "F" ), false );
10669             if ( t1.getNumberOfExternalNodes() != 3 ) {
10670                 return false;
10671             }
10672             t1.toNewHampshireX();
10673             t1.deleteSubtree( t1.getNode( "D" ), false );
10674             t1.toNewHampshireX();
10675             if ( t1.getNumberOfExternalNodes() != 3 ) {
10676                 return false;
10677             }
10678             t1.deleteSubtree( t1.getNode( "def" ), false );
10679             t1.toNewHampshireX();
10680             if ( t1.getNumberOfExternalNodes() != 2 ) {
10681                 return false;
10682             }
10683             t1.deleteSubtree( t1.getNode( "B" ), false );
10684             t1.toNewHampshireX();
10685             if ( t1.getNumberOfExternalNodes() != 1 ) {
10686                 return false;
10687             }
10688             t1.deleteSubtree( t1.getNode( "C" ), false );
10689             t1.toNewHampshireX();
10690             if ( t1.getNumberOfExternalNodes() != 1 ) {
10691                 return false;
10692             }
10693             t1.deleteSubtree( t1.getNode( "abc" ), false );
10694             t1.toNewHampshireX();
10695             if ( t1.getNumberOfExternalNodes() != 1 ) {
10696                 return false;
10697             }
10698             t1.deleteSubtree( t1.getNode( "r" ), false );
10699             if ( t1.getNumberOfExternalNodes() != 0 ) {
10700                 return false;
10701             }
10702             if ( !t1.isEmpty() ) {
10703                 return false;
10704             }
10705             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10706             t2.deleteSubtree( t2.getNode( "A" ), false );
10707             t2.toNewHampshireX();
10708             if ( t2.getNumberOfExternalNodes() != 5 ) {
10709                 return false;
10710             }
10711             t2.deleteSubtree( t2.getNode( "abc" ), false );
10712             t2.toNewHampshireX();
10713             if ( t2.getNumberOfExternalNodes() != 3 ) {
10714                 return false;
10715             }
10716             t2.deleteSubtree( t2.getNode( "def" ), false );
10717             t2.toNewHampshireX();
10718             if ( t2.getNumberOfExternalNodes() != 1 ) {
10719                 return false;
10720             }
10721         }
10722         catch ( final Exception e ) {
10723             e.printStackTrace( System.out );
10724             return false;
10725         }
10726         return true;
10727     }
10728
10729     private static boolean testSupportCount() {
10730         try {
10731             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10732             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
10733             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
10734                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
10735                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
10736                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
10737                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
10738                                                               new NHXParser() );
10739             SupportCount.count( t0_1, phylogenies_1, true, false );
10740             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
10741             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
10742                                                                       + "(((((A,B),C),D),E),((F,G),X))"
10743                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
10744                                                                       + "(((((A,B),C),D),E),(F,G))"
10745                                                                       + "(((((A,B),C),D),E),(F,G))"
10746                                                                       + "(((((A,B),C),D),E),(F,G))"
10747                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
10748                                                                       + "(((((A,B),C),D),E),(F,G))"
10749                                                                       + "((((((A,B),C),D),E),F),G)"
10750                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
10751                                                               new NHXParser() );
10752             SupportCount.count( t0_2, phylogenies_2, true, false );
10753             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
10754             while ( it.hasNext() ) {
10755                 final PhylogenyNode n = it.next();
10756                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
10757                     return false;
10758                 }
10759             }
10760             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
10761             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
10762                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
10763             SupportCount.count( t0_3, phylogenies_3, true, false );
10764             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
10765             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
10766                 return false;
10767             }
10768             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
10769                 return false;
10770             }
10771             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
10772                 return false;
10773             }
10774             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
10775                 return false;
10776             }
10777             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
10778                 return false;
10779             }
10780             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
10781                 return false;
10782             }
10783             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
10784                 return false;
10785             }
10786             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
10787                 return false;
10788             }
10789             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
10790                 return false;
10791             }
10792             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
10793                 return false;
10794             }
10795             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10796             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
10797                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
10798             SupportCount.count( t0_4, phylogenies_4, true, false );
10799             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
10800             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
10801                 return false;
10802             }
10803             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
10804                 return false;
10805             }
10806             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
10807                 return false;
10808             }
10809             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
10810                 return false;
10811             }
10812             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
10813                 return false;
10814             }
10815             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
10816                 return false;
10817             }
10818             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
10819                 return false;
10820             }
10821             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
10822                 return false;
10823             }
10824             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
10825                 return false;
10826             }
10827             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
10828                 return false;
10829             }
10830             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10831             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10832             double d = SupportCount.compare( b1, a, true, true, true );
10833             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
10834                 return false;
10835             }
10836             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10837             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10838             d = SupportCount.compare( b2, a, true, true, true );
10839             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
10840                 return false;
10841             }
10842             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10843             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
10844             d = SupportCount.compare( b3, a, true, true, true );
10845             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
10846                 return false;
10847             }
10848             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
10849             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
10850             d = SupportCount.compare( b4, a, true, true, false );
10851             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
10852                 return false;
10853             }
10854         }
10855         catch ( final Exception e ) {
10856             e.printStackTrace( System.out );
10857             return false;
10858         }
10859         return true;
10860     }
10861
10862     private static boolean testSupportTransfer() {
10863         try {
10864             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10865             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)",
10866                                                  new NHXParser() )[ 0 ];
10867             final Phylogeny p2 = factory
10868                     .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 ];
10869             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
10870                 return false;
10871             }
10872             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
10873                 return false;
10874             }
10875             support_transfer.moveBranchLengthsToBootstrap( p1 );
10876             support_transfer.transferSupportValues( p1, p2 );
10877             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
10878                 return false;
10879             }
10880             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
10881                 return false;
10882             }
10883             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
10884                 return false;
10885             }
10886             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
10887                 return false;
10888             }
10889             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
10890                 return false;
10891             }
10892             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
10893                 return false;
10894             }
10895             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
10896                 return false;
10897             }
10898             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
10899                 return false;
10900             }
10901         }
10902         catch ( final Exception e ) {
10903             e.printStackTrace( System.out );
10904             return false;
10905         }
10906         return true;
10907     }
10908
10909     private static boolean testTaxonomyExtraction() {
10910         try {
10911             final PhylogenyNode n0 = PhylogenyNode
10912                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10913             if ( n0.getNodeData().isHasTaxonomy() ) {
10914                 return false;
10915             }
10916             final PhylogenyNode n1 = PhylogenyNode
10917                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10918             if ( n1.getNodeData().isHasTaxonomy() ) {
10919                 System.out.println( n1.toString() );
10920                 return false;
10921             }
10922             final PhylogenyNode n2x = PhylogenyNode
10923                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10924             if ( n2x.getNodeData().isHasTaxonomy() ) {
10925                 return false;
10926             }
10927             final PhylogenyNode n3 = PhylogenyNode
10928                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10929             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10930                 System.out.println( n3.toString() );
10931                 return false;
10932             }
10933             final PhylogenyNode n4 = PhylogenyNode
10934                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10935             if ( n4.getNodeData().isHasTaxonomy() ) {
10936                 System.out.println( n4.toString() );
10937                 return false;
10938             }
10939             final PhylogenyNode n5 = PhylogenyNode
10940                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10941             if ( n5.getNodeData().isHasTaxonomy() ) {
10942                 System.out.println( n5.toString() );
10943                 return false;
10944             }
10945             final PhylogenyNode n6 = PhylogenyNode
10946                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10947             if ( n6.getNodeData().isHasTaxonomy() ) {
10948                 System.out.println( n6.toString() );
10949                 return false;
10950             }
10951             final PhylogenyNode n7 = PhylogenyNode
10952                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10953             if ( n7.getNodeData().isHasTaxonomy() ) {
10954                 System.out.println( n7.toString() );
10955                 return false;
10956             }
10957             final PhylogenyNode n8 = PhylogenyNode
10958                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10959             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10960                 System.out.println( n8.toString() );
10961                 return false;
10962             }
10963             final PhylogenyNode n9 = PhylogenyNode
10964                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10965             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10966                 System.out.println( n9.toString() );
10967                 return false;
10968             }
10969             final PhylogenyNode n10x = PhylogenyNode
10970                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10971             if ( n10x.getNodeData().isHasTaxonomy() ) {
10972                 System.out.println( n10x.toString() );
10973                 return false;
10974             }
10975             final PhylogenyNode n10xx = PhylogenyNode
10976                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10977             if ( n10xx.getNodeData().isHasTaxonomy() ) {
10978                 System.out.println( n10xx.toString() );
10979                 return false;
10980             }
10981             final PhylogenyNode n10 = PhylogenyNode
10982                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10983             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
10984                 System.out.println( n10.toString() );
10985                 return false;
10986             }
10987             final PhylogenyNode n11 = PhylogenyNode
10988                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10989             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
10990                 System.out.println( n11.toString() );
10991                 return false;
10992             }
10993             final PhylogenyNode n12 = PhylogenyNode
10994                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
10995                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10996             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
10997                 System.out.println( n12.toString() );
10998                 return false;
10999             }
11000             final PhylogenyNode n13 = PhylogenyNode
11001                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11002             if ( n13.getNodeData().isHasTaxonomy() ) {
11003                 System.out.println( n13.toString() );
11004                 return false;
11005             }
11006         }
11007         catch ( final Exception e ) {
11008             e.printStackTrace( System.out );
11009             return false;
11010         }
11011         return true;
11012     }
11013
11014     private static boolean testTreeMethods() {
11015         try {
11016             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11017             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
11018             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
11019             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
11020                 System.out.println( t0.toNewHampshireX() );
11021                 return false;
11022             }
11023             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
11024             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
11025             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
11026                 return false;
11027             }
11028             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
11029                 return false;
11030             }
11031             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
11032                 return false;
11033             }
11034         }
11035         catch ( final Exception e ) {
11036             e.printStackTrace( System.out );
11037             return false;
11038         }
11039         return true;
11040     }
11041
11042     private static boolean testUniprotEntryRetrieval() {
11043         try {
11044             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
11045             if ( !entry.getAccession().equals( "P12345" ) ) {
11046                 return false;
11047             }
11048             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
11049                 return false;
11050             }
11051             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
11052                 return false;
11053             }
11054             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
11055                 return false;
11056             }
11057         }
11058         catch ( final IOException e ) {
11059             System.out.println();
11060             System.out.println( "the following might be due to absence internet connection:" );
11061             e.printStackTrace( System.out );
11062             return true;
11063         }
11064         catch ( final Exception e ) {
11065             return false;
11066         }
11067         return true;
11068     }
11069
11070     private static boolean testUniprotTaxonomySearch() {
11071         try {
11072             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
11073                                                                                                  10 );
11074             if ( results.size() != 1 ) {
11075                 return false;
11076             }
11077             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11078                 return false;
11079             }
11080             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11081                 return false;
11082             }
11083             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11084                 return false;
11085             }
11086             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11087                 return false;
11088             }
11089             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11090                 return false;
11091             }
11092             results = null;
11093             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
11094             if ( results.size() != 1 ) {
11095                 return false;
11096             }
11097             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11098                 return false;
11099             }
11100             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11101                 return false;
11102             }
11103             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11104                 return false;
11105             }
11106             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11107                 return false;
11108             }
11109             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11110                 return false;
11111             }
11112             results = null;
11113             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
11114             if ( results.size() != 1 ) {
11115                 return false;
11116             }
11117             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11118                 return false;
11119             }
11120             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11121                 return false;
11122             }
11123             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11124                 return false;
11125             }
11126             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11127                 return false;
11128             }
11129             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11130                 return false;
11131             }
11132             results = null;
11133             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
11134             if ( results.size() != 1 ) {
11135                 return false;
11136             }
11137             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11138                 return false;
11139             }
11140             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11141                 return false;
11142             }
11143             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11144                 return false;
11145             }
11146             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11147                 return false;
11148             }
11149             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11150                 return false;
11151             }
11152             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
11153                 return false;
11154             }
11155             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
11156                 return false;
11157             }
11158             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11159                     .equals( "Nematostella vectensis" ) ) {
11160                 System.out.println( results.get( 0 ).getLineage() );
11161                 return false;
11162             }
11163         }
11164         catch ( final IOException e ) {
11165             System.out.println();
11166             System.out.println( "the following might be due to absence internet connection:" );
11167             e.printStackTrace( System.out );
11168             return true;
11169         }
11170         catch ( final Exception e ) {
11171             return false;
11172         }
11173         return true;
11174     }
11175
11176     private static boolean testWabiTxSearch() {
11177         try {
11178             String result = "";
11179             result = TxSearch.searchSimple( "nematostella" );
11180             result = TxSearch.getTxId( "nematostella" );
11181             if ( !result.equals( "45350" ) ) {
11182                 return false;
11183             }
11184             result = TxSearch.getTxName( "45350" );
11185             if ( !result.equals( "Nematostella" ) ) {
11186                 return false;
11187             }
11188             result = TxSearch.getTxId( "nematostella vectensis" );
11189             if ( !result.equals( "45351" ) ) {
11190                 return false;
11191             }
11192             result = TxSearch.getTxName( "45351" );
11193             if ( !result.equals( "Nematostella vectensis" ) ) {
11194                 return false;
11195             }
11196             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11197             if ( !result.equals( "536089" ) ) {
11198                 return false;
11199             }
11200             result = TxSearch.getTxName( "536089" );
11201             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11202                 return false;
11203             }
11204             final List<String> queries = new ArrayList<String>();
11205             queries.add( "Campylobacter coli" );
11206             queries.add( "Escherichia coli" );
11207             queries.add( "Arabidopsis" );
11208             queries.add( "Trichoplax" );
11209             queries.add( "Samanea saman" );
11210             queries.add( "Kluyveromyces marxianus" );
11211             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11212             queries.add( "Bornavirus parrot/PDD/2008" );
11213             final List<RANKS> ranks = new ArrayList<RANKS>();
11214             ranks.add( RANKS.SUPERKINGDOM );
11215             ranks.add( RANKS.KINGDOM );
11216             ranks.add( RANKS.FAMILY );
11217             ranks.add( RANKS.GENUS );
11218             ranks.add( RANKS.TRIBE );
11219             result = TxSearch.searchLineage( queries, ranks );
11220             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11221             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11222         }
11223         catch ( final Exception e ) {
11224             System.out.println();
11225             System.out.println( "the following might be due to absence internet connection:" );
11226             e.printStackTrace( System.out );
11227             return false;
11228         }
11229         return true;
11230     }
11231 }