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