inprogress
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.test;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Set;
39 import java.util.SortedSet;
40
41 import org.forester.application.support_transfer;
42 import org.forester.archaeopteryx.TreePanelUtil;
43 import org.forester.development.DevelopmentTools;
44 import org.forester.evoinference.TestPhylogenyReconstruction;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
46 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
47 import org.forester.go.TestGo;
48 import org.forester.io.parsers.FastaParser;
49 import org.forester.io.parsers.GeneralMsaParser;
50 import org.forester.io.parsers.HmmscanPerDomainTableParser;
51 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
52 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
53 import org.forester.io.parsers.nexus.NexusCharactersParser;
54 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
55 import org.forester.io.parsers.nhx.NHXParser;
56 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
57 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
58 import org.forester.io.parsers.tol.TolParser;
59 import org.forester.io.parsers.util.ParserUtils;
60 import org.forester.io.writers.PhylogenyWriter;
61 import org.forester.io.writers.SequenceWriter;
62 import org.forester.msa.BasicMsa;
63 import org.forester.msa.Mafft;
64 import org.forester.msa.Msa;
65 import org.forester.msa.MsaInferrer;
66 import org.forester.msa.MsaMethods;
67 import org.forester.pccx.TestPccx;
68 import org.forester.phylogeny.Phylogeny;
69 import org.forester.phylogeny.PhylogenyBranch;
70 import org.forester.phylogeny.PhylogenyMethods;
71 import org.forester.phylogeny.PhylogenyNode;
72 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
73 import org.forester.phylogeny.data.Accession;
74 import org.forester.phylogeny.data.BinaryCharacters;
75 import org.forester.phylogeny.data.BranchWidth;
76 import org.forester.phylogeny.data.Confidence;
77 import org.forester.phylogeny.data.Distribution;
78 import org.forester.phylogeny.data.DomainArchitecture;
79 import org.forester.phylogeny.data.Event;
80 import org.forester.phylogeny.data.Identifier;
81 import org.forester.phylogeny.data.PhylogenyData;
82 import org.forester.phylogeny.data.PhylogenyDataUtil;
83 import org.forester.phylogeny.data.Polygon;
84 import org.forester.phylogeny.data.PropertiesMap;
85 import org.forester.phylogeny.data.Property;
86 import org.forester.phylogeny.data.Property.AppliesTo;
87 import org.forester.phylogeny.data.ProteinDomain;
88 import org.forester.phylogeny.data.Taxonomy;
89 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
90 import org.forester.phylogeny.factories.PhylogenyFactory;
91 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
92 import org.forester.protein.BasicDomain;
93 import org.forester.protein.BasicProtein;
94 import org.forester.protein.Domain;
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( "Protein id: " );
176         if ( !testProteinId() ) {
177             System.out.println( "failed." );
178             failed++;
179         }
180         else {
181             succeeded++;
182         }
183         System.out.println( "OK." );
184         System.out.print( "Species: " );
185         if ( !testSpecies() ) {
186             System.out.println( "failed." );
187             failed++;
188         }
189         else {
190             succeeded++;
191         }
192         System.out.println( "OK." );
193         System.out.print( "Basic domain: " );
194         if ( !testBasicDomain() ) {
195             System.out.println( "failed." );
196             failed++;
197         }
198         else {
199             succeeded++;
200         }
201         System.out.println( "OK." );
202         System.out.print( "Basic protein: " );
203         if ( !testBasicProtein() ) {
204             System.out.println( "failed." );
205             failed++;
206         }
207         else {
208             succeeded++;
209         }
210         System.out.println( "OK." );
211         System.out.print( "Sequence writer: " );
212         if ( testSequenceWriter() ) {
213             System.out.println( "OK." );
214             succeeded++;
215         }
216         else {
217             System.out.println( "failed." );
218             failed++;
219         }
220         System.out.print( "Sequence id parsing: " );
221         if ( testSequenceIdParsing() ) {
222             System.out.println( "OK." );
223             succeeded++;
224         }
225         else {
226             System.out.println( "failed." );
227             failed++;
228         }
229         System.out.print( "Hmmscan output parser: " );
230         if ( testHmmscanOutputParser() ) {
231             System.out.println( "OK." );
232             succeeded++;
233         }
234         else {
235             System.out.println( "failed." );
236             failed++;
237         }
238         System.out.print( "Basic node methods: " );
239         if ( Test.testBasicNodeMethods() ) {
240             System.out.println( "OK." );
241             succeeded++;
242         }
243         else {
244             System.out.println( "failed." );
245             failed++;
246         }
247         System.out.print( "Taxonomy code extraction: " );
248         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
249             System.out.println( "OK." );
250             succeeded++;
251         }
252         else {
253             System.out.println( "failed." );
254             failed++;
255         }
256         System.out.print( "SN extraction: " );
257         if ( Test.testExtractSNFromNodeName() ) {
258             System.out.println( "OK." );
259             succeeded++;
260         }
261         else {
262             System.out.println( "failed." );
263             failed++;
264         }
265         System.out.print( "Taxonomy extraction (general): " );
266         if ( Test.testTaxonomyExtraction() ) {
267             System.out.println( "OK." );
268             succeeded++;
269         }
270         else {
271             System.out.println( "failed." );
272             failed++;
273         }
274         System.out.print( "UniProtKB id extraction: " );
275         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
276             System.out.println( "OK." );
277             succeeded++;
278         }
279         else {
280             System.out.println( "failed." );
281             failed++;
282         }
283         System.out.print( "Uri for Aptx web sequence accession: " );
284         if ( Test.testCreateUriForSeqWeb() ) {
285             System.out.println( "OK." );
286             succeeded++;
287         }
288         else {
289             System.out.println( "failed." );
290             failed++;
291         }
292         System.out.print( "Basic node construction and parsing of NHX (node level): " );
293         if ( Test.testNHXNodeParsing() ) {
294             System.out.println( "OK." );
295             succeeded++;
296         }
297         else {
298             System.out.println( "failed." );
299             failed++;
300         }
301         System.out.print( "NHX parsing iterating: " );
302         if ( Test.testNHParsingIter() ) {
303             System.out.println( "OK." );
304             succeeded++;
305         }
306         else {
307             System.out.println( "failed." );
308             failed++;
309         }
310         System.out.print( "NH parsing: " );
311         if ( Test.testNHParsing() ) {
312             System.out.println( "OK." );
313             succeeded++;
314         }
315         else {
316             System.out.println( "failed." );
317             failed++;
318         }
319         System.out.print( "Conversion to NHX (node level): " );
320         if ( Test.testNHXconversion() ) {
321             System.out.println( "OK." );
322             succeeded++;
323         }
324         else {
325             System.out.println( "failed." );
326             failed++;
327         }
328         System.out.print( "NHX parsing: " );
329         if ( Test.testNHXParsing() ) {
330             System.out.println( "OK." );
331             succeeded++;
332         }
333         else {
334             System.out.println( "failed." );
335             failed++;
336         }
337         System.out.print( "NHX parsing with quotes: " );
338         if ( Test.testNHXParsingQuotes() ) {
339             System.out.println( "OK." );
340             succeeded++;
341         }
342         else {
343             System.out.println( "failed." );
344             failed++;
345         }
346         System.out.print( "NHX parsing (MrBayes): " );
347         if ( Test.testNHXParsingMB() ) {
348             System.out.println( "OK." );
349             succeeded++;
350         }
351         else {
352             System.out.println( "failed." );
353             failed++;
354         }
355         System.out.print( "Nexus characters parsing: " );
356         if ( Test.testNexusCharactersParsing() ) {
357             System.out.println( "OK." );
358             succeeded++;
359         }
360         else {
361             System.out.println( "failed." );
362             failed++;
363         }
364         System.out.print( "Nexus tree parsing iterating: " );
365         if ( Test.testNexusTreeParsingIterating() ) {
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: " );
374         if ( Test.testNexusTreeParsing() ) {
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 (translating): " );
383         if ( Test.testNexusTreeParsingTranslating() ) {
384             System.out.println( "OK." );
385             succeeded++;
386         }
387         else {
388             System.out.println( "failed." );
389             failed++;
390         }
391         System.out.print( "Nexus matrix parsing: " );
392         if ( Test.testNexusMatrixParsing() ) {
393             System.out.println( "OK." );
394             succeeded++;
395         }
396         else {
397             System.out.println( "failed." );
398             failed++;
399         }
400         System.out.print( "Basic phyloXML parsing: " );
401         if ( Test.testBasicPhyloXMLparsing() ) {
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 (validating against schema): " );
410         if ( testBasicPhyloXMLparsingValidating() ) {
411             System.out.println( "OK." );
412             succeeded++;
413         }
414         else {
415             System.out.println( "failed." );
416             failed++;
417         }
418         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
419         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
420             System.out.println( "OK." );
421             succeeded++;
422         }
423         else {
424             System.out.println( "failed." );
425             failed++;
426         }
427         System.out.print( "phyloXML Distribution Element: " );
428         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
429             System.out.println( "OK." );
430             succeeded++;
431         }
432         else {
433             System.out.println( "failed." );
434             failed++;
435         }
436         System.out.print( "Tol XML parsing: " );
437         if ( Test.testBasicTolXMLparsing() ) {
438             System.out.println( "OK." );
439             succeeded++;
440         }
441         else {
442             System.out.println( "failed." );
443             failed++;
444         }
445         System.out.print( "Copying of node data: " );
446         if ( Test.testCopyOfNodeData() ) {
447             System.out.println( "OK." );
448             succeeded++;
449         }
450         else {
451             System.out.println( "failed." );
452             failed++;
453         }
454         System.out.print( "Basic tree methods: " );
455         if ( Test.testBasicTreeMethods() ) {
456             System.out.println( "OK." );
457             succeeded++;
458         }
459         else {
460             System.out.println( "failed." );
461             failed++;
462         }
463         System.out.print( "Tree methods: " );
464         if ( Test.testTreeMethods() ) {
465             System.out.println( "OK." );
466             succeeded++;
467         }
468         else {
469             System.out.println( "failed." );
470             failed++;
471         }
472         System.out.print( "Postorder Iterator: " );
473         if ( Test.testPostOrderIterator() ) {
474             System.out.println( "OK." );
475             succeeded++;
476         }
477         else {
478             System.out.println( "failed." );
479             failed++;
480         }
481         System.out.print( "Preorder Iterator: " );
482         if ( Test.testPreOrderIterator() ) {
483             System.out.println( "OK." );
484             succeeded++;
485         }
486         else {
487             System.out.println( "failed." );
488             failed++;
489         }
490         System.out.print( "Levelorder Iterator: " );
491         if ( Test.testLevelOrderIterator() ) {
492             System.out.println( "OK." );
493             succeeded++;
494         }
495         else {
496             System.out.println( "failed." );
497             failed++;
498         }
499         System.out.print( "Re-id methods: " );
500         if ( Test.testReIdMethods() ) {
501             System.out.println( "OK." );
502             succeeded++;
503         }
504         else {
505             System.out.println( "failed." );
506             failed++;
507         }
508         System.out.print( "Methods on last external nodes: " );
509         if ( Test.testLastExternalNodeMethods() ) {
510             System.out.println( "OK." );
511             succeeded++;
512         }
513         else {
514             System.out.println( "failed." );
515             failed++;
516         }
517         System.out.print( "Methods on external nodes: " );
518         if ( Test.testExternalNodeRelatedMethods() ) {
519             System.out.println( "OK." );
520             succeeded++;
521         }
522         else {
523             System.out.println( "failed." );
524             failed++;
525         }
526         System.out.print( "Deletion of external nodes: " );
527         if ( Test.testDeletionOfExternalNodes() ) {
528             System.out.println( "OK." );
529             succeeded++;
530         }
531         else {
532             System.out.println( "failed." );
533             failed++;
534         }
535         System.out.print( "Subtree deletion: " );
536         if ( Test.testSubtreeDeletion() ) {
537             System.out.println( "OK." );
538             succeeded++;
539         }
540         else {
541             System.out.println( "failed." );
542             failed++;
543         }
544         System.out.print( "Phylogeny branch: " );
545         if ( Test.testPhylogenyBranch() ) {
546             System.out.println( "OK." );
547             succeeded++;
548         }
549         else {
550             System.out.println( "failed." );
551             failed++;
552         }
553         System.out.print( "Rerooting: " );
554         if ( Test.testRerooting() ) {
555             System.out.println( "OK." );
556             succeeded++;
557         }
558         else {
559             System.out.println( "failed." );
560             failed++;
561         }
562         System.out.print( "Mipoint rooting: " );
563         if ( Test.testMidpointrooting() ) {
564             System.out.println( "OK." );
565             succeeded++;
566         }
567         else {
568             System.out.println( "failed." );
569             failed++;
570         }
571         System.out.print( "Node removal: " );
572         if ( Test.testNodeRemoval() ) {
573             System.out.println( "OK." );
574             succeeded++;
575         }
576         else {
577             System.out.println( "failed." );
578             failed++;
579         }
580         System.out.print( "Support count: " );
581         if ( Test.testSupportCount() ) {
582             System.out.println( "OK." );
583             succeeded++;
584         }
585         else {
586             System.out.println( "failed." );
587             failed++;
588         }
589         System.out.print( "Support transfer: " );
590         if ( Test.testSupportTransfer() ) {
591             System.out.println( "OK." );
592             succeeded++;
593         }
594         else {
595             System.out.println( "failed." );
596             failed++;
597         }
598         System.out.print( "Finding of LCA: " );
599         if ( Test.testGetLCA() ) {
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 2: " );
608         if ( Test.testGetLCA2() ) {
609             System.out.println( "OK." );
610             succeeded++;
611         }
612         else {
613             System.out.println( "failed." );
614             failed++;
615         }
616         System.out.print( "Calculation of distance between nodes: " );
617         if ( Test.testGetDistance() ) {
618             System.out.println( "OK." );
619             succeeded++;
620         }
621         else {
622             System.out.println( "failed." );
623             failed++;
624         }
625         System.out.print( "Descriptive statistics: " );
626         if ( Test.testDescriptiveStatistics() ) {
627             System.out.println( "OK." );
628             succeeded++;
629         }
630         else {
631             System.out.println( "failed." );
632             failed++;
633         }
634         System.out.print( "Data objects and methods: " );
635         if ( Test.testDataObjects() ) {
636             System.out.println( "OK." );
637             succeeded++;
638         }
639         else {
640             System.out.println( "failed." );
641             failed++;
642         }
643         System.out.print( "Properties map: " );
644         if ( Test.testPropertiesMap() ) {
645             System.out.println( "OK." );
646             succeeded++;
647         }
648         else {
649             System.out.println( "failed." );
650             failed++;
651         }
652         System.out.print( "SDIse: " );
653         if ( Test.testSDIse() ) {
654             System.out.println( "OK." );
655             succeeded++;
656         }
657         else {
658             System.out.println( "failed." );
659             failed++;
660         }
661         System.out.print( "SDIunrooted: " );
662         if ( Test.testSDIunrooted() ) {
663             System.out.println( "OK." );
664             succeeded++;
665         }
666         else {
667             System.out.println( "failed." );
668             failed++;
669         }
670         System.out.print( "GSDI: " );
671         if ( TestGSDI.test() ) {
672             System.out.println( "OK." );
673             succeeded++;
674         }
675         else {
676             System.out.println( "failed." );
677             failed++;
678         }
679         System.out.print( "RIO: " );
680         if ( TestRIO.test() ) {
681             System.out.println( "OK." );
682             succeeded++;
683         }
684         else {
685             System.out.println( "failed." );
686             failed++;
687         }
688         System.out.print( "Phylogeny reconstruction:" );
689         System.out.println();
690         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
691             System.out.println( "OK." );
692             succeeded++;
693         }
694         else {
695             System.out.println( "failed." );
696             failed++;
697         }
698         System.out.print( "Analysis of domain architectures: " );
699         System.out.println();
700         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
701             System.out.println( "OK." );
702             succeeded++;
703         }
704         else {
705             System.out.println( "failed." );
706             failed++;
707         }
708         System.out.print( "GO: " );
709         System.out.println();
710         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
711             System.out.println( "OK." );
712             succeeded++;
713         }
714         else {
715             System.out.println( "failed." );
716             failed++;
717         }
718         System.out.print( "Modeling tools: " );
719         if ( TestPccx.test() ) {
720             System.out.println( "OK." );
721             succeeded++;
722         }
723         else {
724             System.out.println( "failed." );
725             failed++;
726         }
727         System.out.print( "Split Matrix strict: " );
728         if ( Test.testSplitStrict() ) {
729             System.out.println( "OK." );
730             succeeded++;
731         }
732         else {
733             System.out.println( "failed." );
734             failed++;
735         }
736         System.out.print( "Split Matrix: " );
737         if ( Test.testSplit() ) {
738             System.out.println( "OK." );
739             succeeded++;
740         }
741         else {
742             System.out.println( "failed." );
743             failed++;
744         }
745         System.out.print( "Confidence Assessor: " );
746         if ( Test.testConfidenceAssessor() ) {
747             System.out.println( "OK." );
748             succeeded++;
749         }
750         else {
751             System.out.println( "failed." );
752             failed++;
753         }
754         System.out.print( "Basic table: " );
755         if ( Test.testBasicTable() ) {
756             System.out.println( "OK." );
757             succeeded++;
758         }
759         else {
760             System.out.println( "failed." );
761             failed++;
762         }
763         System.out.print( "General table: " );
764         if ( Test.testGeneralTable() ) {
765             System.out.println( "OK." );
766             succeeded++;
767         }
768         else {
769             System.out.println( "failed." );
770             failed++;
771         }
772         System.out.print( "Amino acid sequence: " );
773         if ( Test.testAminoAcidSequence() ) {
774             System.out.println( "OK." );
775             succeeded++;
776         }
777         else {
778             System.out.println( "failed." );
779             failed++;
780         }
781         System.out.print( "General MSA parser: " );
782         if ( Test.testGeneralMsaParser() ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "Fasta parser for msa: " );
791         if ( Test.testFastaParser() ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "Creation of balanced phylogeny: " );
800         if ( Test.testCreateBalancedPhylogeny() ) {
801             System.out.println( "OK." );
802             succeeded++;
803         }
804         else {
805             System.out.println( "failed." );
806             failed++;
807         }
808         System.out.print( "EMBL Entry Retrieval: " );
809         if ( Test.testEmblEntryRetrieval() ) {
810             System.out.println( "OK." );
811             succeeded++;
812         }
813         else {
814             System.out.println( "failed." );
815             failed++;
816         }
817         System.out.print( "Uniprot Entry Retrieval: " );
818         if ( Test.testUniprotEntryRetrieval() ) {
819             System.out.println( "OK." );
820             succeeded++;
821         }
822         else {
823             System.out.println( "failed." );
824             failed++;
825         }
826         System.out.print( "Uniprot Taxonomy Search: " );
827         if ( Test.testUniprotTaxonomySearch() ) {
828             System.out.println( "OK." );
829             succeeded++;
830         }
831         else {
832             System.out.println( "failed." );
833             failed++;
834         }
835         //----
836         String path = "";
837         final String os = ForesterUtil.OS_NAME.toLowerCase();
838         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
839             path = "/usr/local/bin/mafft";
840         }
841         else if ( os.indexOf( "win" ) >= 0 ) {
842             path = "C:\\Program Files\\mafft-win\\mafft.bat";
843         }
844         else {
845             path = "/home/czmasek/bin/mafft";
846         }
847         if ( !MsaInferrer.isInstalled( path ) ) {
848             path = "mafft";
849         }
850         if ( !MsaInferrer.isInstalled( path ) ) {
851             path = "/usr/local/bin/mafft";
852         }
853         if ( MsaInferrer.isInstalled( path ) ) {
854             System.out.print( "MAFFT (external program): " );
855             if ( Test.testMafft( path ) ) {
856                 System.out.println( "OK." );
857                 succeeded++;
858             }
859             else {
860                 System.out.println( "failed [will not count towards failed tests]" );
861             }
862         }
863         //----
864         System.out.print( "Next nodes with collapsed: " );
865         if ( Test.testNextNodeWithCollapsing() ) {
866             System.out.println( "OK." );
867             succeeded++;
868         }
869         else {
870             System.out.println( "failed." );
871             failed++;
872         }
873         System.out.print( "Simple MSA quality: " );
874         if ( Test.testMsaQualityMethod() ) {
875             System.out.println( "OK." );
876             succeeded++;
877         }
878         else {
879             System.out.println( "failed." );
880             failed++;
881         }
882         System.out.println();
883         final Runtime rt = java.lang.Runtime.getRuntime();
884         final long free_memory = rt.freeMemory() / 1000000;
885         final long total_memory = rt.totalMemory() / 1000000;
886         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
887                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
888         System.out.println();
889         System.out.println( "Successful tests: " + succeeded );
890         System.out.println( "Failed     tests: " + failed );
891         System.out.println();
892         if ( failed < 1 ) {
893             System.out.println( "OK." );
894         }
895         else {
896             System.out.println( "Not OK." );
897         }
898     }
899
900     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
901         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
902         return p;
903     }
904
905     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
906         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
907     }
908
909     private static boolean testAminoAcidSequence() {
910         try {
911             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
912             if ( aa1.getLength() != 13 ) {
913                 return false;
914             }
915             if ( aa1.getResidueAt( 0 ) != 'A' ) {
916                 return false;
917             }
918             if ( aa1.getResidueAt( 2 ) != 'K' ) {
919                 return false;
920             }
921             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
922                 return false;
923             }
924             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
925             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
926                 return false;
927             }
928             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
929             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
930                 return false;
931             }
932             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
933             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
934                 return false;
935             }
936         }
937         catch ( final Exception e ) {
938             e.printStackTrace();
939             return false;
940         }
941         return true;
942     }
943
944     private static boolean testBasicDomain() {
945         try {
946             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
947             if ( !pd.getDomainId().equals( "id" ) ) {
948                 return false;
949             }
950             if ( pd.getNumber() != 1 ) {
951                 return false;
952             }
953             if ( pd.getTotalCount() != 4 ) {
954                 return false;
955             }
956             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
957                 return false;
958             }
959             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
960             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
961             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
962             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
963             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
964             if ( !a1.equals( a1 ) ) {
965                 return false;
966             }
967             if ( !a1.equals( a1_copy ) ) {
968                 return false;
969             }
970             if ( !a1.equals( a1_equal ) ) {
971                 return false;
972             }
973             if ( !a1.equals( a2 ) ) {
974                 return false;
975             }
976             if ( a1.equals( a3 ) ) {
977                 return false;
978             }
979             if ( a1.compareTo( a1 ) != 0 ) {
980                 return false;
981             }
982             if ( a1.compareTo( a1_copy ) != 0 ) {
983                 return false;
984             }
985             if ( a1.compareTo( a1_equal ) != 0 ) {
986                 return false;
987             }
988             if ( a1.compareTo( a2 ) != 0 ) {
989                 return false;
990             }
991             if ( a1.compareTo( a3 ) == 0 ) {
992                 return false;
993             }
994         }
995         catch ( final Exception e ) {
996             e.printStackTrace( System.out );
997             return false;
998         }
999         return true;
1000     }
1001
1002     private static boolean testBasicNodeMethods() {
1003         try {
1004             if ( PhylogenyNode.getNodeCount() != 0 ) {
1005                 return false;
1006             }
1007             final PhylogenyNode n1 = new PhylogenyNode();
1008             final PhylogenyNode n2 = PhylogenyNode
1009                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1010             final PhylogenyNode n3 = PhylogenyNode
1011                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1012             final PhylogenyNode n4 = PhylogenyNode
1013                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1014             if ( n1.isHasAssignedEvent() ) {
1015                 return false;
1016             }
1017             if ( PhylogenyNode.getNodeCount() != 4 ) {
1018                 return false;
1019             }
1020             if ( n3.getIndicator() != 0 ) {
1021                 return false;
1022             }
1023             if ( n3.getNumberOfExternalNodes() != 1 ) {
1024                 return false;
1025             }
1026             if ( !n3.isExternal() ) {
1027                 return false;
1028             }
1029             if ( !n3.isRoot() ) {
1030                 return false;
1031             }
1032             if ( !n4.getName().equals( "n4" ) ) {
1033                 return false;
1034             }
1035         }
1036         catch ( final Exception e ) {
1037             e.printStackTrace( System.out );
1038             return false;
1039         }
1040         return true;
1041     }
1042
1043     private static boolean testBasicPhyloXMLparsing() {
1044         try {
1045             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1046             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1047             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1048                                                               xml_parser );
1049             if ( xml_parser.getErrorCount() > 0 ) {
1050                 System.out.println( xml_parser.getErrorMessages().toString() );
1051                 return false;
1052             }
1053             if ( phylogenies_0.length != 4 ) {
1054                 return false;
1055             }
1056             final Phylogeny t1 = phylogenies_0[ 0 ];
1057             final Phylogeny t2 = phylogenies_0[ 1 ];
1058             final Phylogeny t3 = phylogenies_0[ 2 ];
1059             final Phylogeny t4 = phylogenies_0[ 3 ];
1060             if ( t1.getNumberOfExternalNodes() != 1 ) {
1061                 return false;
1062             }
1063             if ( !t1.isRooted() ) {
1064                 return false;
1065             }
1066             if ( t1.isRerootable() ) {
1067                 return false;
1068             }
1069             if ( !t1.getType().equals( "gene_tree" ) ) {
1070                 return false;
1071             }
1072             if ( t2.getNumberOfExternalNodes() != 2 ) {
1073                 return false;
1074             }
1075             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1076                 return false;
1077             }
1078             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1079                 return false;
1080             }
1081             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1082                 return false;
1083             }
1084             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1085                 return false;
1086             }
1087             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1088                 return false;
1089             }
1090             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1091                 return false;
1092             }
1093             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1094                     .startsWith( "actgtgggggt" ) ) {
1095                 return false;
1096             }
1097             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1098                     .startsWith( "ctgtgatgcat" ) ) {
1099                 return false;
1100             }
1101             if ( t3.getNumberOfExternalNodes() != 4 ) {
1102                 return false;
1103             }
1104             if ( !t1.getName().equals( "t1" ) ) {
1105                 return false;
1106             }
1107             if ( !t2.getName().equals( "t2" ) ) {
1108                 return false;
1109             }
1110             if ( !t3.getName().equals( "t3" ) ) {
1111                 return false;
1112             }
1113             if ( !t4.getName().equals( "t4" ) ) {
1114                 return false;
1115             }
1116             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1117                 return false;
1118             }
1119             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1120                 return false;
1121             }
1122             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1123                 return false;
1124             }
1125             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1126                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1127                 return false;
1128             }
1129             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1130                 return false;
1131             }
1132             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1133                 return false;
1134             }
1135             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1136                 return false;
1137             }
1138             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1139                     .equals( "apoptosis" ) ) {
1140                 return false;
1141             }
1142             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1143                     .equals( "GO:0006915" ) ) {
1144                 return false;
1145             }
1146             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1147                     .equals( "UniProtKB" ) ) {
1148                 return false;
1149             }
1150             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1151                     .equals( "experimental" ) ) {
1152                 return false;
1153             }
1154             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1155                     .equals( "function" ) ) {
1156                 return false;
1157             }
1158             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1159                     .getValue() != 1 ) {
1160                 return false;
1161             }
1162             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1163                     .getType().equals( "ml" ) ) {
1164                 return false;
1165             }
1166             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1167                     .equals( "apoptosis" ) ) {
1168                 return false;
1169             }
1170             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1171                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1172                 return false;
1173             }
1174             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1175                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1176                 return false;
1177             }
1178             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1179                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1180                 return false;
1181             }
1182             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1183                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1184                 return false;
1185             }
1186             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1187                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1188                 return false;
1189             }
1190             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1191                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1192                 return false;
1193             }
1194             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1195                     .equals( "GO:0005829" ) ) {
1196                 return false;
1197             }
1198             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1199                     .equals( "intracellular organelle" ) ) {
1200                 return false;
1201             }
1202             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1203                 return false;
1204             }
1205             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1206                     .equals( "UniProt link" ) ) ) {
1207                 return false;
1208             }
1209             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1210                 return false;
1211             }
1212             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1213             if ( x.size() != 4 ) {
1214                 return false;
1215             }
1216             int c = 0;
1217             for( final Accession acc : x ) {
1218                 if ( c == 0 ) {
1219                     if ( !acc.getSource().equals( "KEGG" ) ) {
1220                         return false;
1221                     }
1222                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1223                         return false;
1224                     }
1225                 }
1226                 c++;
1227             }
1228         }
1229         catch ( final Exception e ) {
1230             e.printStackTrace( System.out );
1231             return false;
1232         }
1233         return true;
1234     }
1235
1236     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1237         try {
1238             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1239             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1240             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1241                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1242             }
1243             else {
1244                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1245             }
1246             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1247                                                               xml_parser );
1248             if ( xml_parser.getErrorCount() > 0 ) {
1249                 System.out.println( xml_parser.getErrorMessages().toString() );
1250                 return false;
1251             }
1252             if ( phylogenies_0.length != 4 ) {
1253                 return false;
1254             }
1255             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1256             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1257             if ( phylogenies_t1.length != 1 ) {
1258                 return false;
1259             }
1260             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1261             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1262                 return false;
1263             }
1264             if ( !t1_rt.isRooted() ) {
1265                 return false;
1266             }
1267             if ( t1_rt.isRerootable() ) {
1268                 return false;
1269             }
1270             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1271                 return false;
1272             }
1273             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1274             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1275             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1276             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1277                 return false;
1278             }
1279             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1280                 return false;
1281             }
1282             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1283                 return false;
1284             }
1285             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1286                 return false;
1287             }
1288             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1289                     .startsWith( "actgtgggggt" ) ) {
1290                 return false;
1291             }
1292             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1293                     .startsWith( "ctgtgatgcat" ) ) {
1294                 return false;
1295             }
1296             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1297             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1298             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1299             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1300             if ( phylogenies_1.length != 1 ) {
1301                 return false;
1302             }
1303             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1304             if ( !t3_rt.getName().equals( "t3" ) ) {
1305                 return false;
1306             }
1307             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1308                 return false;
1309             }
1310             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1311                 return false;
1312             }
1313             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1314                 return false;
1315             }
1316             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1317                 return false;
1318             }
1319             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1320                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1321                 return false;
1322             }
1323             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1324                 return false;
1325             }
1326             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1327                 return false;
1328             }
1329             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1330                     .equals( "UniProtKB" ) ) {
1331                 return false;
1332             }
1333             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1334                     .equals( "apoptosis" ) ) {
1335                 return false;
1336             }
1337             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1338                     .equals( "GO:0006915" ) ) {
1339                 return false;
1340             }
1341             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1342                     .equals( "UniProtKB" ) ) {
1343                 return false;
1344             }
1345             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1346                     .equals( "experimental" ) ) {
1347                 return false;
1348             }
1349             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1350                     .equals( "function" ) ) {
1351                 return false;
1352             }
1353             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1354                     .getValue() != 1 ) {
1355                 return false;
1356             }
1357             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1358                     .getType().equals( "ml" ) ) {
1359                 return false;
1360             }
1361             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1362                     .equals( "apoptosis" ) ) {
1363                 return false;
1364             }
1365             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1366                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1367                 return false;
1368             }
1369             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1370                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1371                 return false;
1372             }
1373             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1374                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1375                 return false;
1376             }
1377             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1378                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1379                 return false;
1380             }
1381             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1382                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1383                 return false;
1384             }
1385             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1386                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1387                 return false;
1388             }
1389             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1390                     .equals( "GO:0005829" ) ) {
1391                 return false;
1392             }
1393             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1394                     .equals( "intracellular organelle" ) ) {
1395                 return false;
1396             }
1397             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1398                 return false;
1399             }
1400             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1401                     .equals( "UniProt link" ) ) ) {
1402                 return false;
1403             }
1404             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1405                 return false;
1406             }
1407             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1408                 return false;
1409             }
1410             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1411                     .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." ) ) ) {
1412                 return false;
1413             }
1414             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1415                 return false;
1416             }
1417             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1418                 return false;
1419             }
1420             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1421                 return false;
1422             }
1423             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1424                 return false;
1425             }
1426             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1427                     .equals( "ncbi" ) ) {
1428                 return false;
1429             }
1430             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1431                 return false;
1432             }
1433             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1434                     .getName().equals( "B" ) ) {
1435                 return false;
1436             }
1437             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1438                     .getFrom() != 21 ) {
1439                 return false;
1440             }
1441             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1442                 return false;
1443             }
1444             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1445                     .getLength() != 24 ) {
1446                 return false;
1447             }
1448             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1449                     .getConfidence() != 2144 ) {
1450                 return false;
1451             }
1452             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1453                     .equals( "pfam" ) ) {
1454                 return false;
1455             }
1456             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1457                 return false;
1458             }
1459             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1460                 return false;
1461             }
1462             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1463                 return false;
1464             }
1465             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1466                 return false;
1467             }
1468             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1469             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1470                 return false;
1471             }
1472             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1473                 return false;
1474             }
1475             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1476                 return false;
1477             }
1478             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1479                 return false;
1480             }
1481             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1482                 return false;
1483             }
1484             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1485                 return false;
1486             }
1487             if ( taxbb.getSynonyms().size() != 2 ) {
1488                 return false;
1489             }
1490             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1491                 return false;
1492             }
1493             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1494                 return false;
1495             }
1496             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1497                 return false;
1498             }
1499             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1500                 return false;
1501             }
1502             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1503                 return false;
1504             }
1505             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1506                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1507                 return false;
1508             }
1509             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1510                 return false;
1511             }
1512             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1513                 return false;
1514             }
1515             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1516                 return false;
1517             }
1518             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1519                 return false;
1520             }
1521             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1522                 return false;
1523             }
1524             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1525                 return false;
1526             }
1527             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1528                 return false;
1529             }
1530             //
1531             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1532                 return false;
1533             }
1534             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1535                     .equalsIgnoreCase( "435" ) ) {
1536                 return false;
1537             }
1538             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1539                 return false;
1540             }
1541             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1542                     .equalsIgnoreCase( "443.7" ) ) {
1543                 return false;
1544             }
1545             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1546                 return false;
1547             }
1548             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1549                 return false;
1550             }
1551             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1552                     .equalsIgnoreCase( "433" ) ) {
1553                 return false;
1554             }
1555             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
1556                     .getCrossReferences();
1557             if ( x.size() != 4 ) {
1558                 return false;
1559             }
1560             int c = 0;
1561             for( final Accession acc : x ) {
1562                 if ( c == 0 ) {
1563                     if ( !acc.getSource().equals( "KEGG" ) ) {
1564                         return false;
1565                     }
1566                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1567                         return false;
1568                     }
1569                 }
1570                 c++;
1571             }
1572         }
1573         catch ( final Exception e ) {
1574             e.printStackTrace( System.out );
1575             return false;
1576         }
1577         return true;
1578     }
1579
1580     private static boolean testBasicPhyloXMLparsingValidating() {
1581         try {
1582             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1583             PhyloXmlParser xml_parser = null;
1584             try {
1585                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1586             }
1587             catch ( final Exception e ) {
1588                 // Do nothing -- means were not running from jar.
1589             }
1590             if ( xml_parser == null ) {
1591                 xml_parser = new PhyloXmlParser();
1592                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1593                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1594                 }
1595                 else {
1596                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1597                 }
1598             }
1599             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1600                                                               xml_parser );
1601             if ( xml_parser.getErrorCount() > 0 ) {
1602                 System.out.println( xml_parser.getErrorMessages().toString() );
1603                 return false;
1604             }
1605             if ( phylogenies_0.length != 4 ) {
1606                 return false;
1607             }
1608             final Phylogeny t1 = phylogenies_0[ 0 ];
1609             final Phylogeny t2 = phylogenies_0[ 1 ];
1610             final Phylogeny t3 = phylogenies_0[ 2 ];
1611             final Phylogeny t4 = phylogenies_0[ 3 ];
1612             if ( !t1.getName().equals( "t1" ) ) {
1613                 return false;
1614             }
1615             if ( !t2.getName().equals( "t2" ) ) {
1616                 return false;
1617             }
1618             if ( !t3.getName().equals( "t3" ) ) {
1619                 return false;
1620             }
1621             if ( !t4.getName().equals( "t4" ) ) {
1622                 return false;
1623             }
1624             if ( t1.getNumberOfExternalNodes() != 1 ) {
1625                 return false;
1626             }
1627             if ( t2.getNumberOfExternalNodes() != 2 ) {
1628                 return false;
1629             }
1630             if ( t3.getNumberOfExternalNodes() != 4 ) {
1631                 return false;
1632             }
1633             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1634             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1635             if ( xml_parser.getErrorCount() > 0 ) {
1636                 System.out.println( "errors:" );
1637                 System.out.println( xml_parser.getErrorMessages().toString() );
1638                 return false;
1639             }
1640             if ( phylogenies_1.length != 4 ) {
1641                 return false;
1642             }
1643             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1644                                                               xml_parser );
1645             if ( xml_parser.getErrorCount() > 0 ) {
1646                 System.out.println( "errors:" );
1647                 System.out.println( xml_parser.getErrorMessages().toString() );
1648                 return false;
1649             }
1650             if ( phylogenies_2.length != 1 ) {
1651                 return false;
1652             }
1653             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1654                 return false;
1655             }
1656             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1657                                                               xml_parser );
1658             if ( xml_parser.getErrorCount() > 0 ) {
1659                 System.out.println( xml_parser.getErrorMessages().toString() );
1660                 return false;
1661             }
1662             if ( phylogenies_3.length != 2 ) {
1663                 return false;
1664             }
1665             final Phylogeny a = phylogenies_3[ 0 ];
1666             if ( !a.getName().equals( "tree 4" ) ) {
1667                 return false;
1668             }
1669             if ( a.getNumberOfExternalNodes() != 3 ) {
1670                 return false;
1671             }
1672             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1673                 return false;
1674             }
1675             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1676                 return false;
1677             }
1678             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1679                                                               xml_parser );
1680             if ( xml_parser.getErrorCount() > 0 ) {
1681                 System.out.println( xml_parser.getErrorMessages().toString() );
1682                 return false;
1683             }
1684             if ( phylogenies_4.length != 1 ) {
1685                 return false;
1686             }
1687             final Phylogeny s = phylogenies_4[ 0 ];
1688             if ( s.getNumberOfExternalNodes() != 6 ) {
1689                 return false;
1690             }
1691             s.getNode( "first" );
1692             s.getNode( "<>" );
1693             s.getNode( "\"<a'b&c'd\">\"" );
1694             s.getNode( "'''\"" );
1695             s.getNode( "\"\"\"" );
1696             s.getNode( "dick & doof" );
1697         }
1698         catch ( final Exception e ) {
1699             e.printStackTrace( System.out );
1700             return false;
1701         }
1702         return true;
1703     }
1704
1705     private static boolean testBasicProtein() {
1706         try {
1707             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
1708             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1709             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1710             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1711             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1712             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1713             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1714             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1715             p0.addProteinDomain( y );
1716             p0.addProteinDomain( e );
1717             p0.addProteinDomain( b );
1718             p0.addProteinDomain( c );
1719             p0.addProteinDomain( d );
1720             p0.addProteinDomain( a );
1721             p0.addProteinDomain( x );
1722             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
1723                 return false;
1724             }
1725             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
1726                 return false;
1727             }
1728             //
1729             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
1730             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1731             aa0.addProteinDomain( a1 );
1732             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
1733                 return false;
1734             }
1735             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
1736                 return false;
1737             }
1738             //
1739             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
1740             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1741             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1742             aa1.addProteinDomain( a11 );
1743             aa1.addProteinDomain( a12 );
1744             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
1745                 return false;
1746             }
1747             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
1748                 return false;
1749             }
1750             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1751             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
1752                 return false;
1753             }
1754             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1755                 return false;
1756             }
1757             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
1758                 return false;
1759             }
1760             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1761             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
1762                 return false;
1763             }
1764             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1765                 return false;
1766             }
1767             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
1768                 return false;
1769             }
1770             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
1771                 return false;
1772             }
1773             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1774             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
1775                 return false;
1776             }
1777             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
1778                 return false;
1779             }
1780             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
1781                 return false;
1782             }
1783             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
1784                 return false;
1785             }
1786             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1787             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
1788                 return false;
1789             }
1790             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
1791                 return false;
1792             }
1793             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
1794                 return false;
1795             }
1796             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
1797                 return false;
1798             }
1799             //
1800             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
1801             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1802             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1803             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1804             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1805             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1806             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
1807             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
1808             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
1809             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
1810             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
1811             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1812             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1813             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
1814             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
1815             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
1816             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
1817             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
1818             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
1819             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
1820             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
1821             p00.addProteinDomain( y0 );
1822             p00.addProteinDomain( e0 );
1823             p00.addProteinDomain( b0 );
1824             p00.addProteinDomain( c0 );
1825             p00.addProteinDomain( d0 );
1826             p00.addProteinDomain( a0 );
1827             p00.addProteinDomain( x0 );
1828             p00.addProteinDomain( y1 );
1829             p00.addProteinDomain( y2 );
1830             p00.addProteinDomain( y3 );
1831             p00.addProteinDomain( e1 );
1832             p00.addProteinDomain( e2 );
1833             p00.addProteinDomain( e3 );
1834             p00.addProteinDomain( e4 );
1835             p00.addProteinDomain( e5 );
1836             p00.addProteinDomain( z0 );
1837             p00.addProteinDomain( z1 );
1838             p00.addProteinDomain( z2 );
1839             p00.addProteinDomain( zz0 );
1840             p00.addProteinDomain( zz1 );
1841             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
1842                 return false;
1843             }
1844             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
1845                 return false;
1846             }
1847             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1848                 return false;
1849             }
1850             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1851                 return false;
1852             }
1853             if ( !p00.toDomainArchitectureString( "~", 7, "" ).equals( "a~b~c~d~e~e~e~e~e~e~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1854                 return false;
1855             }
1856             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
1857             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1858             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
1859             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
1860             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
1861             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
1862             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
1863             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
1864             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
1865             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
1866             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
1867             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
1868             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
1869             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
1870             p.addProteinDomain( B15 );
1871             p.addProteinDomain( C50 );
1872             p.addProteinDomain( A60 );
1873             p.addProteinDomain( A30 );
1874             p.addProteinDomain( C70 );
1875             p.addProteinDomain( B35 );
1876             p.addProteinDomain( B40 );
1877             p.addProteinDomain( A0 );
1878             p.addProteinDomain( A10 );
1879             p.addProteinDomain( A20 );
1880             p.addProteinDomain( B25 );
1881             p.addProteinDomain( D80 );
1882             List<String> domains_ids = new ArrayList<String>();
1883             domains_ids.add( "A" );
1884             domains_ids.add( "B" );
1885             domains_ids.add( "C" );
1886             if ( !p.contains( domains_ids, false ) ) {
1887                 return false;
1888             }
1889             if ( !p.contains( domains_ids, true ) ) {
1890                 return false;
1891             }
1892             domains_ids.add( "X" );
1893             if ( p.contains( domains_ids, false ) ) {
1894                 return false;
1895             }
1896             if ( p.contains( domains_ids, true ) ) {
1897                 return false;
1898             }
1899             domains_ids = new ArrayList<String>();
1900             domains_ids.add( "A" );
1901             domains_ids.add( "C" );
1902             domains_ids.add( "D" );
1903             if ( !p.contains( domains_ids, false ) ) {
1904                 return false;
1905             }
1906             if ( !p.contains( domains_ids, true ) ) {
1907                 return false;
1908             }
1909             domains_ids = new ArrayList<String>();
1910             domains_ids.add( "A" );
1911             domains_ids.add( "D" );
1912             domains_ids.add( "C" );
1913             if ( !p.contains( domains_ids, false ) ) {
1914                 return false;
1915             }
1916             if ( p.contains( domains_ids, true ) ) {
1917                 return false;
1918             }
1919             domains_ids = new ArrayList<String>();
1920             domains_ids.add( "A" );
1921             domains_ids.add( "A" );
1922             domains_ids.add( "B" );
1923             if ( !p.contains( domains_ids, false ) ) {
1924                 return false;
1925             }
1926             if ( !p.contains( domains_ids, true ) ) {
1927                 return false;
1928             }
1929             domains_ids = new ArrayList<String>();
1930             domains_ids.add( "A" );
1931             domains_ids.add( "A" );
1932             domains_ids.add( "A" );
1933             domains_ids.add( "B" );
1934             domains_ids.add( "B" );
1935             if ( !p.contains( domains_ids, false ) ) {
1936                 return false;
1937             }
1938             if ( !p.contains( domains_ids, true ) ) {
1939                 return false;
1940             }
1941             domains_ids = new ArrayList<String>();
1942             domains_ids.add( "A" );
1943             domains_ids.add( "A" );
1944             domains_ids.add( "B" );
1945             domains_ids.add( "A" );
1946             domains_ids.add( "B" );
1947             domains_ids.add( "B" );
1948             domains_ids.add( "A" );
1949             domains_ids.add( "B" );
1950             domains_ids.add( "C" );
1951             domains_ids.add( "A" );
1952             domains_ids.add( "C" );
1953             domains_ids.add( "D" );
1954             if ( !p.contains( domains_ids, false ) ) {
1955                 return false;
1956             }
1957             if ( p.contains( domains_ids, true ) ) {
1958                 return false;
1959             }
1960         }
1961         catch ( final Exception e ) {
1962             e.printStackTrace( System.out );
1963             return false;
1964         }
1965         return true;
1966     }
1967
1968     private static boolean testBasicTable() {
1969         try {
1970             final BasicTable<String> t0 = new BasicTable<String>();
1971             if ( t0.getNumberOfColumns() != 0 ) {
1972                 return false;
1973             }
1974             if ( t0.getNumberOfRows() != 0 ) {
1975                 return false;
1976             }
1977             t0.setValue( 3, 2, "23" );
1978             t0.setValue( 10, 1, "error" );
1979             t0.setValue( 10, 1, "110" );
1980             t0.setValue( 9, 1, "19" );
1981             t0.setValue( 1, 10, "101" );
1982             t0.setValue( 10, 10, "1010" );
1983             t0.setValue( 100, 10, "10100" );
1984             t0.setValue( 0, 0, "00" );
1985             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1986                 return false;
1987             }
1988             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1989                 return false;
1990             }
1991             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1992                 return false;
1993             }
1994             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1995                 return false;
1996             }
1997             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1998                 return false;
1999             }
2000             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2001                 return false;
2002             }
2003             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2004                 return false;
2005             }
2006             if ( t0.getNumberOfColumns() != 101 ) {
2007                 return false;
2008             }
2009             if ( t0.getNumberOfRows() != 11 ) {
2010                 return false;
2011             }
2012             if ( t0.getValueAsString( 49, 4 ) != null ) {
2013                 return false;
2014             }
2015             final String l = ForesterUtil.getLineSeparator();
2016             final StringBuffer source = new StringBuffer();
2017             source.append( "" + l );
2018             source.append( "# 1 1 1 1 1 1 1 1" + l );
2019             source.append( " 00 01 02 03" + l );
2020             source.append( "   10 11 12 13  " + l );
2021             source.append( "20 21 22 23 " + l );
2022             source.append( "    30  31    32 33" + l );
2023             source.append( "40 41 42 43" + l );
2024             source.append( "  # 1 1 1 1 1 " + l );
2025             source.append( "50 51 52 53 54" + l );
2026             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2027             if ( t1.getNumberOfColumns() != 5 ) {
2028                 return false;
2029             }
2030             if ( t1.getNumberOfRows() != 6 ) {
2031                 return false;
2032             }
2033             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2034                 return false;
2035             }
2036             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2037                 return false;
2038             }
2039             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2040                 return false;
2041             }
2042             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2043                 return false;
2044             }
2045             final StringBuffer source1 = new StringBuffer();
2046             source1.append( "" + l );
2047             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2048             source1.append( " 00; 01 ;02;03" + l );
2049             source1.append( "   10; 11; 12; 13  " + l );
2050             source1.append( "20; 21; 22; 23 " + l );
2051             source1.append( "    30;  31;    32; 33" + l );
2052             source1.append( "40;41;42;43" + l );
2053             source1.append( "  # 1 1 1 1 1 " + l );
2054             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2055             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2056             if ( t2.getNumberOfColumns() != 5 ) {
2057                 return false;
2058             }
2059             if ( t2.getNumberOfRows() != 6 ) {
2060                 return false;
2061             }
2062             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2063                 return false;
2064             }
2065             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2066                 return false;
2067             }
2068             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2069                 return false;
2070             }
2071             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2072                 return false;
2073             }
2074             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2075                 return false;
2076             }
2077             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2078                 return false;
2079             }
2080             final StringBuffer source2 = new StringBuffer();
2081             source2.append( "" + l );
2082             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2083             source2.append( " 00; 01 ;02;03" + l );
2084             source2.append( "   10; 11; 12; 13  " + l );
2085             source2.append( "20; 21; 22; 23 " + l );
2086             source2.append( "                     " + l );
2087             source2.append( "    30;  31;    32; 33" + l );
2088             source2.append( "40;41;42;43" + l );
2089             source2.append( "  comment: 1 1 1 1 1 " + l );
2090             source2.append( ";;;50  ;   52; 53;;54   " + l );
2091             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2092                                                                         ';',
2093                                                                         false,
2094                                                                         false,
2095                                                                         "comment:",
2096                                                                         false );
2097             if ( tl.size() != 2 ) {
2098                 return false;
2099             }
2100             final BasicTable<String> t3 = tl.get( 0 );
2101             final BasicTable<String> t4 = tl.get( 1 );
2102             if ( t3.getNumberOfColumns() != 4 ) {
2103                 return false;
2104             }
2105             if ( t3.getNumberOfRows() != 3 ) {
2106                 return false;
2107             }
2108             if ( t4.getNumberOfColumns() != 4 ) {
2109                 return false;
2110             }
2111             if ( t4.getNumberOfRows() != 3 ) {
2112                 return false;
2113             }
2114             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2115                 return false;
2116             }
2117             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2118                 return false;
2119             }
2120         }
2121         catch ( final Exception e ) {
2122             e.printStackTrace( System.out );
2123             return false;
2124         }
2125         return true;
2126     }
2127
2128     private static boolean testBasicTolXMLparsing() {
2129         try {
2130             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2131             final TolParser parser = new TolParser();
2132             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2133             if ( parser.getErrorCount() > 0 ) {
2134                 System.out.println( parser.getErrorMessages().toString() );
2135                 return false;
2136             }
2137             if ( phylogenies_0.length != 1 ) {
2138                 return false;
2139             }
2140             final Phylogeny t1 = phylogenies_0[ 0 ];
2141             if ( t1.getNumberOfExternalNodes() != 5 ) {
2142                 return false;
2143             }
2144             if ( !t1.isRooted() ) {
2145                 return false;
2146             }
2147             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2148                 return false;
2149             }
2150             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2151                 return false;
2152             }
2153             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2154                 return false;
2155             }
2156             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2157                 return false;
2158             }
2159             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2160             if ( parser.getErrorCount() > 0 ) {
2161                 System.out.println( parser.getErrorMessages().toString() );
2162                 return false;
2163             }
2164             if ( phylogenies_1.length != 1 ) {
2165                 return false;
2166             }
2167             final Phylogeny t2 = phylogenies_1[ 0 ];
2168             if ( t2.getNumberOfExternalNodes() != 664 ) {
2169                 return false;
2170             }
2171             if ( !t2.isRooted() ) {
2172                 return false;
2173             }
2174             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2175                 return false;
2176             }
2177             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2178                 return false;
2179             }
2180             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2181                 return false;
2182             }
2183             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2184                 return false;
2185             }
2186             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2187                 return false;
2188             }
2189             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2190                     .equals( "Aquifex" ) ) {
2191                 return false;
2192             }
2193             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2194             if ( parser.getErrorCount() > 0 ) {
2195                 System.out.println( parser.getErrorMessages().toString() );
2196                 return false;
2197             }
2198             if ( phylogenies_2.length != 1 ) {
2199                 return false;
2200             }
2201             final Phylogeny t3 = phylogenies_2[ 0 ];
2202             if ( t3.getNumberOfExternalNodes() != 184 ) {
2203                 return false;
2204             }
2205             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2206                 return false;
2207             }
2208             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2209                 return false;
2210             }
2211             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2212                 return false;
2213             }
2214             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2215             if ( parser.getErrorCount() > 0 ) {
2216                 System.out.println( parser.getErrorMessages().toString() );
2217                 return false;
2218             }
2219             if ( phylogenies_3.length != 1 ) {
2220                 return false;
2221             }
2222             final Phylogeny t4 = phylogenies_3[ 0 ];
2223             if ( t4.getNumberOfExternalNodes() != 1 ) {
2224                 return false;
2225             }
2226             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2227                 return false;
2228             }
2229             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2230                 return false;
2231             }
2232             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2233                 return false;
2234             }
2235             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2236             if ( parser.getErrorCount() > 0 ) {
2237                 System.out.println( parser.getErrorMessages().toString() );
2238                 return false;
2239             }
2240             if ( phylogenies_4.length != 1 ) {
2241                 return false;
2242             }
2243             final Phylogeny t5 = phylogenies_4[ 0 ];
2244             if ( t5.getNumberOfExternalNodes() != 13 ) {
2245                 return false;
2246             }
2247             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2248                 return false;
2249             }
2250             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2251                 return false;
2252             }
2253             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2254                 return false;
2255             }
2256         }
2257         catch ( final Exception e ) {
2258             e.printStackTrace( System.out );
2259             return false;
2260         }
2261         return true;
2262     }
2263
2264     private static boolean testBasicTreeMethods() {
2265         try {
2266             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2267             final Phylogeny t1 = factory.create();
2268             if ( !t1.isEmpty() ) {
2269                 return false;
2270             }
2271             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2272             if ( t2.getNumberOfExternalNodes() != 4 ) {
2273                 return false;
2274             }
2275             if ( t2.getHeight() != 8.5 ) {
2276                 return false;
2277             }
2278             if ( !t2.isCompletelyBinary() ) {
2279                 return false;
2280             }
2281             if ( t2.isEmpty() ) {
2282                 return false;
2283             }
2284             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2285             if ( t3.getNumberOfExternalNodes() != 5 ) {
2286                 return false;
2287             }
2288             if ( t3.getHeight() != 11 ) {
2289                 return false;
2290             }
2291             if ( t3.isCompletelyBinary() ) {
2292                 return false;
2293             }
2294             final PhylogenyNode n = t3.getNode( "ABC" );
2295             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 ];
2296             if ( t4.getNumberOfExternalNodes() != 9 ) {
2297                 return false;
2298             }
2299             if ( t4.getHeight() != 11 ) {
2300                 return false;
2301             }
2302             if ( t4.isCompletelyBinary() ) {
2303                 return false;
2304             }
2305             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)" );
2306             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2307             if ( t5.getNumberOfExternalNodes() != 8 ) {
2308                 return false;
2309             }
2310             if ( t5.getHeight() != 15 ) {
2311                 return false;
2312             }
2313             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)" );
2314             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2315             if ( t6.getHeight() != 15 ) {
2316                 return false;
2317             }
2318             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)" );
2319             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2320             if ( t7.getHeight() != 15 ) {
2321                 return false;
2322             }
2323             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)" );
2324             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2325             if ( t8.getNumberOfExternalNodes() != 10 ) {
2326                 return false;
2327             }
2328             if ( t8.getHeight() != 15 ) {
2329                 return false;
2330             }
2331             final char[] a9 = new char[] { 'a' };
2332             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2333             if ( t9.getHeight() != 0 ) {
2334                 return false;
2335             }
2336             final char[] a10 = new char[] { 'a', ':', '6' };
2337             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2338             if ( t10.getHeight() != 6 ) {
2339                 return false;
2340             }
2341         }
2342         catch ( final Exception e ) {
2343             e.printStackTrace( System.out );
2344             return false;
2345         }
2346         return true;
2347     }
2348
2349     private static boolean testConfidenceAssessor() {
2350         try {
2351             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2352             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2353             final Phylogeny[] ev0 = factory
2354                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2355                              new NHXParser() );
2356             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2357             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2358                 return false;
2359             }
2360             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2361                 return false;
2362             }
2363             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2364             final Phylogeny[] ev1 = factory
2365                     .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)));",
2366                              new NHXParser() );
2367             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2368             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2369                 return false;
2370             }
2371             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2372                 return false;
2373             }
2374             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2375             final Phylogeny[] ev_b = factory
2376                     .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",
2377                              new NHXParser() );
2378             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2379             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2380                 return false;
2381             }
2382             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2383                 return false;
2384             }
2385             //
2386             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2387             final Phylogeny[] ev1x = factory
2388                     .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)));",
2389                              new NHXParser() );
2390             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2391             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2392                 return false;
2393             }
2394             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2395                 return false;
2396             }
2397             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2398             final Phylogeny[] ev_bx = factory
2399                     .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",
2400                              new NHXParser() );
2401             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2402             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2403                 return false;
2404             }
2405             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2406                 return false;
2407             }
2408             //
2409             final Phylogeny[] t2 = factory
2410                     .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);",
2411                              new NHXParser() );
2412             final Phylogeny[] ev2 = factory
2413                     .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);",
2414                              new NHXParser() );
2415             for( final Phylogeny target : t2 ) {
2416                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2417             }
2418             //
2419             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2420                                                  new NHXParser() )[ 0 ];
2421             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2422             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2423             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2424                 return false;
2425             }
2426             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2427                 return false;
2428             }
2429             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2430                 return false;
2431             }
2432         }
2433         catch ( final Exception e ) {
2434             e.printStackTrace();
2435             return false;
2436         }
2437         return true;
2438     }
2439
2440     private static boolean testCopyOfNodeData() {
2441         try {
2442             final PhylogenyNode n1 = PhylogenyNode
2443                     .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]" );
2444             final PhylogenyNode n2 = n1.copyNodeData();
2445             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2446                 return false;
2447             }
2448         }
2449         catch ( final Exception e ) {
2450             e.printStackTrace();
2451             return false;
2452         }
2453         return true;
2454     }
2455
2456     private static boolean testCreateBalancedPhylogeny() {
2457         try {
2458             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2459             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2460                 return false;
2461             }
2462             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2463                 return false;
2464             }
2465             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2466             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2467                 return false;
2468             }
2469             if ( p1.getNumberOfExternalNodes() != 100 ) {
2470                 return false;
2471             }
2472         }
2473         catch ( final Exception e ) {
2474             e.printStackTrace();
2475             return false;
2476         }
2477         return true;
2478     }
2479
2480     private static boolean testCreateUriForSeqWeb() {
2481         try {
2482             final PhylogenyNode n = new PhylogenyNode();
2483             n.setName( "tr|B3RJ64" );
2484             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2485                 return false;
2486             }
2487             n.setName( "B0LM41_HUMAN" );
2488             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2489                 return false;
2490             }
2491             n.setName( "NP_001025424" );
2492             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2493                 return false;
2494             }
2495             n.setName( "_NM_001030253-" );
2496             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2497                 return false;
2498             }
2499             n.setName( "XM_002122186" );
2500             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2501                 return false;
2502             }
2503             n.setName( "dgh_AAA34956_gdg" );
2504             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2505                 return false;
2506             }
2507             n.setName( "j40f4_Q06891.1_fndn2 fnr3" );
2508             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891.1" ) ) {
2509                 return false;
2510             }
2511             n.setName( "GI:394892" );
2512             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2513                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2514                 return false;
2515             }
2516             n.setName( "gi_394892" );
2517             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2518                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2519                 return false;
2520             }
2521             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2522             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2523                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2524                 return false;
2525             }
2526         }
2527         catch ( final Exception e ) {
2528             e.printStackTrace( System.out );
2529             return false;
2530         }
2531         return true;
2532     }
2533
2534     private static boolean testDataObjects() {
2535         try {
2536             final Confidence s0 = new Confidence();
2537             final Confidence s1 = new Confidence();
2538             if ( !s0.isEqual( s1 ) ) {
2539                 return false;
2540             }
2541             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2542             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2543             if ( s2.isEqual( s1 ) ) {
2544                 return false;
2545             }
2546             if ( !s2.isEqual( s3 ) ) {
2547                 return false;
2548             }
2549             final Confidence s4 = ( Confidence ) s3.copy();
2550             if ( !s4.isEqual( s3 ) ) {
2551                 return false;
2552             }
2553             s3.asSimpleText();
2554             s3.asText();
2555             // Taxonomy
2556             // ----------
2557             final Taxonomy t1 = new Taxonomy();
2558             final Taxonomy t2 = new Taxonomy();
2559             final Taxonomy t3 = new Taxonomy();
2560             final Taxonomy t4 = new Taxonomy();
2561             final Taxonomy t5 = new Taxonomy();
2562             t1.setIdentifier( new Identifier( "ecoli" ) );
2563             t1.setTaxonomyCode( "ECOLI" );
2564             t1.setScientificName( "E. coli" );
2565             t1.setCommonName( "coli" );
2566             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2567             if ( !t1.isEqual( t0 ) ) {
2568                 return false;
2569             }
2570             t2.setIdentifier( new Identifier( "ecoli" ) );
2571             t2.setTaxonomyCode( "OTHER" );
2572             t2.setScientificName( "what" );
2573             t2.setCommonName( "something" );
2574             if ( !t1.isEqual( t2 ) ) {
2575                 return false;
2576             }
2577             t2.setIdentifier( new Identifier( "nemve" ) );
2578             if ( t1.isEqual( t2 ) ) {
2579                 return false;
2580             }
2581             t1.setIdentifier( null );
2582             t3.setTaxonomyCode( "ECOLI" );
2583             t3.setScientificName( "what" );
2584             t3.setCommonName( "something" );
2585             if ( !t1.isEqual( t3 ) ) {
2586                 return false;
2587             }
2588             t1.setIdentifier( null );
2589             t1.setTaxonomyCode( "" );
2590             t4.setScientificName( "E. ColI" );
2591             t4.setCommonName( "something" );
2592             if ( !t1.isEqual( t4 ) ) {
2593                 return false;
2594             }
2595             t4.setScientificName( "B. subtilis" );
2596             t4.setCommonName( "something" );
2597             if ( t1.isEqual( t4 ) ) {
2598                 return false;
2599             }
2600             t1.setIdentifier( null );
2601             t1.setTaxonomyCode( "" );
2602             t1.setScientificName( "" );
2603             t5.setCommonName( "COLI" );
2604             if ( !t1.isEqual( t5 ) ) {
2605                 return false;
2606             }
2607             t5.setCommonName( "vibrio" );
2608             if ( t1.isEqual( t5 ) ) {
2609                 return false;
2610             }
2611             // Identifier
2612             // ----------
2613             final Identifier id0 = new Identifier( "123", "pfam" );
2614             final Identifier id1 = ( Identifier ) id0.copy();
2615             if ( !id1.isEqual( id1 ) ) {
2616                 return false;
2617             }
2618             if ( !id1.isEqual( id0 ) ) {
2619                 return false;
2620             }
2621             if ( !id0.isEqual( id1 ) ) {
2622                 return false;
2623             }
2624             id1.asSimpleText();
2625             id1.asText();
2626             // ProteinDomain
2627             // ---------------
2628             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2629             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2630             if ( !pd1.isEqual( pd1 ) ) {
2631                 return false;
2632             }
2633             if ( !pd1.isEqual( pd0 ) ) {
2634                 return false;
2635             }
2636             pd1.asSimpleText();
2637             pd1.asText();
2638             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2639             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2640             if ( !pd3.isEqual( pd3 ) ) {
2641                 return false;
2642             }
2643             if ( !pd2.isEqual( pd3 ) ) {
2644                 return false;
2645             }
2646             if ( !pd0.isEqual( pd3 ) ) {
2647                 return false;
2648             }
2649             pd3.asSimpleText();
2650             pd3.asText();
2651             // DomainArchitecture
2652             // ------------------
2653             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2654             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2655             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2656             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2657             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2658             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2659             domains0.add( d2 );
2660             domains0.add( d0 );
2661             domains0.add( d3 );
2662             domains0.add( d1 );
2663             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2664             if ( ds0.getNumberOfDomains() != 4 ) {
2665                 return false;
2666             }
2667             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2668             if ( !ds0.isEqual( ds0 ) ) {
2669                 return false;
2670             }
2671             if ( !ds0.isEqual( ds1 ) ) {
2672                 return false;
2673             }
2674             if ( ds1.getNumberOfDomains() != 4 ) {
2675                 return false;
2676             }
2677             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2678             domains1.add( d1 );
2679             domains1.add( d2 );
2680             domains1.add( d4 );
2681             domains1.add( d0 );
2682             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2683             if ( ds0.isEqual( ds2 ) ) {
2684                 return false;
2685             }
2686             ds1.asSimpleText();
2687             ds1.asText();
2688             ds1.toNHX();
2689             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2690             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2691                 System.out.println( ds3.toNHX() );
2692                 return false;
2693             }
2694             if ( ds3.getNumberOfDomains() != 3 ) {
2695                 return false;
2696             }
2697             // Event
2698             // -----
2699             final Event e1 = new Event( Event.EventType.fusion );
2700             if ( e1.isDuplication() ) {
2701                 return false;
2702             }
2703             if ( !e1.isFusion() ) {
2704                 return false;
2705             }
2706             if ( !e1.asText().toString().equals( "fusion" ) ) {
2707                 return false;
2708             }
2709             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2710                 return false;
2711             }
2712             final Event e11 = new Event( Event.EventType.fusion );
2713             if ( !e11.isEqual( e1 ) ) {
2714                 return false;
2715             }
2716             if ( !e11.toNHX().toString().equals( "" ) ) {
2717                 return false;
2718             }
2719             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2720             if ( e2.isDuplication() ) {
2721                 return false;
2722             }
2723             if ( !e2.isSpeciationOrDuplication() ) {
2724                 return false;
2725             }
2726             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2727                 return false;
2728             }
2729             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2730                 return false;
2731             }
2732             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2733                 return false;
2734             }
2735             if ( e11.isEqual( e2 ) ) {
2736                 return false;
2737             }
2738             final Event e2c = ( Event ) e2.copy();
2739             if ( !e2c.isEqual( e2 ) ) {
2740                 return false;
2741             }
2742             Event e3 = new Event( 1, 2, 3 );
2743             if ( e3.isDuplication() ) {
2744                 return false;
2745             }
2746             if ( e3.isSpeciation() ) {
2747                 return false;
2748             }
2749             if ( e3.isGeneLoss() ) {
2750                 return false;
2751             }
2752             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2753                 return false;
2754             }
2755             final Event e3c = ( Event ) e3.copy();
2756             final Event e3cc = ( Event ) e3c.copy();
2757             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2758                 return false;
2759             }
2760             e3 = null;
2761             if ( !e3c.isEqual( e3cc ) ) {
2762                 return false;
2763             }
2764             Event e4 = new Event( 1, 2, 3 );
2765             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2766                 return false;
2767             }
2768             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2769                 return false;
2770             }
2771             final Event e4c = ( Event ) e4.copy();
2772             e4 = null;
2773             final Event e4cc = ( Event ) e4c.copy();
2774             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2775                 return false;
2776             }
2777             if ( !e4c.isEqual( e4cc ) ) {
2778                 return false;
2779             }
2780             final Event e5 = new Event();
2781             if ( !e5.isUnassigned() ) {
2782                 return false;
2783             }
2784             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2785                 return false;
2786             }
2787             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2788                 return false;
2789             }
2790             final Event e6 = new Event( 1, 0, 0 );
2791             if ( !e6.asText().toString().equals( "duplication" ) ) {
2792                 return false;
2793             }
2794             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2795                 return false;
2796             }
2797             final Event e7 = new Event( 0, 1, 0 );
2798             if ( !e7.asText().toString().equals( "speciation" ) ) {
2799                 return false;
2800             }
2801             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2802                 return false;
2803             }
2804             final Event e8 = new Event( 0, 0, 1 );
2805             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2806                 return false;
2807             }
2808             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2809                 return false;
2810             }
2811         }
2812         catch ( final Exception e ) {
2813             e.printStackTrace( System.out );
2814             return false;
2815         }
2816         return true;
2817     }
2818
2819     private static boolean testDeletionOfExternalNodes() {
2820         try {
2821             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2822             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2823             final PhylogenyWriter w = new PhylogenyWriter();
2824             if ( t0.isEmpty() ) {
2825                 return false;
2826             }
2827             if ( t0.getNumberOfExternalNodes() != 1 ) {
2828                 return false;
2829             }
2830             t0.deleteSubtree( t0.getNode( "A" ), false );
2831             if ( t0.getNumberOfExternalNodes() != 0 ) {
2832                 return false;
2833             }
2834             if ( !t0.isEmpty() ) {
2835                 return false;
2836             }
2837             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2838             if ( t1.getNumberOfExternalNodes() != 2 ) {
2839                 return false;
2840             }
2841             t1.deleteSubtree( t1.getNode( "A" ), false );
2842             if ( t1.getNumberOfExternalNodes() != 1 ) {
2843                 return false;
2844             }
2845             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2846                 return false;
2847             }
2848             t1.deleteSubtree( t1.getNode( "B" ), false );
2849             if ( t1.getNumberOfExternalNodes() != 1 ) {
2850                 return false;
2851             }
2852             t1.deleteSubtree( t1.getNode( "r" ), false );
2853             if ( !t1.isEmpty() ) {
2854                 return false;
2855             }
2856             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2857             if ( t2.getNumberOfExternalNodes() != 3 ) {
2858                 return false;
2859             }
2860             t2.deleteSubtree( t2.getNode( "B" ), false );
2861             if ( t2.getNumberOfExternalNodes() != 2 ) {
2862                 return false;
2863             }
2864             t2.toNewHampshireX();
2865             PhylogenyNode n = t2.getNode( "A" );
2866             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2867                 return false;
2868             }
2869             t2.deleteSubtree( t2.getNode( "A" ), false );
2870             if ( t2.getNumberOfExternalNodes() != 2 ) {
2871                 return false;
2872             }
2873             t2.deleteSubtree( t2.getNode( "C" ), true );
2874             if ( t2.getNumberOfExternalNodes() != 1 ) {
2875                 return false;
2876             }
2877             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2878             if ( t3.getNumberOfExternalNodes() != 4 ) {
2879                 return false;
2880             }
2881             t3.deleteSubtree( t3.getNode( "B" ), true );
2882             if ( t3.getNumberOfExternalNodes() != 3 ) {
2883                 return false;
2884             }
2885             n = t3.getNode( "A" );
2886             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2887                 return false;
2888             }
2889             n = n.getNextExternalNode();
2890             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2891                 return false;
2892             }
2893             t3.deleteSubtree( t3.getNode( "A" ), true );
2894             if ( t3.getNumberOfExternalNodes() != 2 ) {
2895                 return false;
2896             }
2897             n = t3.getNode( "C" );
2898             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2899                 return false;
2900             }
2901             t3.deleteSubtree( t3.getNode( "C" ), true );
2902             if ( t3.getNumberOfExternalNodes() != 1 ) {
2903                 return false;
2904             }
2905             t3.deleteSubtree( t3.getNode( "D" ), true );
2906             if ( t3.getNumberOfExternalNodes() != 0 ) {
2907                 return false;
2908             }
2909             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2910             if ( t4.getNumberOfExternalNodes() != 6 ) {
2911                 return false;
2912             }
2913             t4.deleteSubtree( t4.getNode( "B2" ), true );
2914             if ( t4.getNumberOfExternalNodes() != 5 ) {
2915                 return false;
2916             }
2917             String s = w.toNewHampshire( t4, false, true ).toString();
2918             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2919                 return false;
2920             }
2921             t4.deleteSubtree( t4.getNode( "B11" ), true );
2922             if ( t4.getNumberOfExternalNodes() != 4 ) {
2923                 return false;
2924             }
2925             t4.deleteSubtree( t4.getNode( "C" ), true );
2926             if ( t4.getNumberOfExternalNodes() != 3 ) {
2927                 return false;
2928             }
2929             n = t4.getNode( "A" );
2930             n = n.getNextExternalNode();
2931             if ( !n.getName().equals( "B12" ) ) {
2932                 return false;
2933             }
2934             n = n.getNextExternalNode();
2935             if ( !n.getName().equals( "D" ) ) {
2936                 return false;
2937             }
2938             s = w.toNewHampshire( t4, false, true ).toString();
2939             if ( !s.equals( "((A,B12),D);" ) ) {
2940                 return false;
2941             }
2942             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2943             t5.deleteSubtree( t5.getNode( "A" ), true );
2944             if ( t5.getNumberOfExternalNodes() != 5 ) {
2945                 return false;
2946             }
2947             s = w.toNewHampshire( t5, false, true ).toString();
2948             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2949                 return false;
2950             }
2951             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2952             t6.deleteSubtree( t6.getNode( "B11" ), true );
2953             if ( t6.getNumberOfExternalNodes() != 5 ) {
2954                 return false;
2955             }
2956             s = w.toNewHampshire( t6, false, false ).toString();
2957             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2958                 return false;
2959             }
2960             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2961             t7.deleteSubtree( t7.getNode( "B12" ), true );
2962             if ( t7.getNumberOfExternalNodes() != 5 ) {
2963                 return false;
2964             }
2965             s = w.toNewHampshire( t7, false, true ).toString();
2966             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2967                 return false;
2968             }
2969             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2970             t8.deleteSubtree( t8.getNode( "B2" ), true );
2971             if ( t8.getNumberOfExternalNodes() != 5 ) {
2972                 return false;
2973             }
2974             s = w.toNewHampshire( t8, false, false ).toString();
2975             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2976                 return false;
2977             }
2978             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2979             t9.deleteSubtree( t9.getNode( "C" ), true );
2980             if ( t9.getNumberOfExternalNodes() != 5 ) {
2981                 return false;
2982             }
2983             s = w.toNewHampshire( t9, false, true ).toString();
2984             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2985                 return false;
2986             }
2987             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2988             t10.deleteSubtree( t10.getNode( "D" ), true );
2989             if ( t10.getNumberOfExternalNodes() != 5 ) {
2990                 return false;
2991             }
2992             s = w.toNewHampshire( t10, false, true ).toString();
2993             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2994                 return false;
2995             }
2996             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2997             t11.deleteSubtree( t11.getNode( "A" ), true );
2998             if ( t11.getNumberOfExternalNodes() != 2 ) {
2999                 return false;
3000             }
3001             s = w.toNewHampshire( t11, false, true ).toString();
3002             if ( !s.equals( "(B,C);" ) ) {
3003                 return false;
3004             }
3005             t11.deleteSubtree( t11.getNode( "C" ), true );
3006             if ( t11.getNumberOfExternalNodes() != 1 ) {
3007                 return false;
3008             }
3009             s = w.toNewHampshire( t11, false, false ).toString();
3010             if ( !s.equals( "B;" ) ) {
3011                 return false;
3012             }
3013             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3014             t12.deleteSubtree( t12.getNode( "B2" ), true );
3015             if ( t12.getNumberOfExternalNodes() != 8 ) {
3016                 return false;
3017             }
3018             s = w.toNewHampshire( t12, false, true ).toString();
3019             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3020                 return false;
3021             }
3022             t12.deleteSubtree( t12.getNode( "B3" ), true );
3023             if ( t12.getNumberOfExternalNodes() != 7 ) {
3024                 return false;
3025             }
3026             s = w.toNewHampshire( t12, false, true ).toString();
3027             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3028                 return false;
3029             }
3030             t12.deleteSubtree( t12.getNode( "C3" ), true );
3031             if ( t12.getNumberOfExternalNodes() != 6 ) {
3032                 return false;
3033             }
3034             s = w.toNewHampshire( t12, false, true ).toString();
3035             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3036                 return false;
3037             }
3038             t12.deleteSubtree( t12.getNode( "A1" ), true );
3039             if ( t12.getNumberOfExternalNodes() != 5 ) {
3040                 return false;
3041             }
3042             s = w.toNewHampshire( t12, false, true ).toString();
3043             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3044                 return false;
3045             }
3046             t12.deleteSubtree( t12.getNode( "B1" ), true );
3047             if ( t12.getNumberOfExternalNodes() != 4 ) {
3048                 return false;
3049             }
3050             s = w.toNewHampshire( t12, false, true ).toString();
3051             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3052                 return false;
3053             }
3054             t12.deleteSubtree( t12.getNode( "A3" ), true );
3055             if ( t12.getNumberOfExternalNodes() != 3 ) {
3056                 return false;
3057             }
3058             s = w.toNewHampshire( t12, false, true ).toString();
3059             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3060                 return false;
3061             }
3062             t12.deleteSubtree( t12.getNode( "A2" ), true );
3063             if ( t12.getNumberOfExternalNodes() != 2 ) {
3064                 return false;
3065             }
3066             s = w.toNewHampshire( t12, false, true ).toString();
3067             if ( !s.equals( "(C1,C2);" ) ) {
3068                 return false;
3069             }
3070             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3071             t13.deleteSubtree( t13.getNode( "D" ), true );
3072             if ( t13.getNumberOfExternalNodes() != 4 ) {
3073                 return false;
3074             }
3075             s = w.toNewHampshire( t13, false, true ).toString();
3076             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3077                 return false;
3078             }
3079             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3080             t14.deleteSubtree( t14.getNode( "E" ), true );
3081             if ( t14.getNumberOfExternalNodes() != 5 ) {
3082                 return false;
3083             }
3084             s = w.toNewHampshire( t14, false, true ).toString();
3085             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3086                 return false;
3087             }
3088             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3089             t15.deleteSubtree( t15.getNode( "B2" ), true );
3090             if ( t15.getNumberOfExternalNodes() != 11 ) {
3091                 return false;
3092             }
3093             t15.deleteSubtree( t15.getNode( "B1" ), true );
3094             if ( t15.getNumberOfExternalNodes() != 10 ) {
3095                 return false;
3096             }
3097             t15.deleteSubtree( t15.getNode( "B3" ), true );
3098             if ( t15.getNumberOfExternalNodes() != 9 ) {
3099                 return false;
3100             }
3101             t15.deleteSubtree( t15.getNode( "B4" ), true );
3102             if ( t15.getNumberOfExternalNodes() != 8 ) {
3103                 return false;
3104             }
3105             t15.deleteSubtree( t15.getNode( "A1" ), true );
3106             if ( t15.getNumberOfExternalNodes() != 7 ) {
3107                 return false;
3108             }
3109             t15.deleteSubtree( t15.getNode( "C4" ), true );
3110             if ( t15.getNumberOfExternalNodes() != 6 ) {
3111                 return false;
3112             }
3113         }
3114         catch ( final Exception e ) {
3115             e.printStackTrace( System.out );
3116             return false;
3117         }
3118         return true;
3119     }
3120
3121     private static boolean testDescriptiveStatistics() {
3122         try {
3123             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3124             dss1.addValue( 82 );
3125             dss1.addValue( 78 );
3126             dss1.addValue( 70 );
3127             dss1.addValue( 58 );
3128             dss1.addValue( 42 );
3129             if ( dss1.getN() != 5 ) {
3130                 return false;
3131             }
3132             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3133                 return false;
3134             }
3135             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3136                 return false;
3137             }
3138             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3139                 return false;
3140             }
3141             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3142                 return false;
3143             }
3144             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3145                 return false;
3146             }
3147             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3148                 return false;
3149             }
3150             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3151                 return false;
3152             }
3153             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3154                 return false;
3155             }
3156             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3157                 return false;
3158             }
3159             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3160                 return false;
3161             }
3162             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3163                 return false;
3164             }
3165             dss1.addValue( 123 );
3166             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3167                 return false;
3168             }
3169             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3170                 return false;
3171             }
3172             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3173                 return false;
3174             }
3175             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3176             dss2.addValue( -1.85 );
3177             dss2.addValue( 57.5 );
3178             dss2.addValue( 92.78 );
3179             dss2.addValue( 57.78 );
3180             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3181                 return false;
3182             }
3183             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3184                 return false;
3185             }
3186             final double[] a = dss2.getDataAsDoubleArray();
3187             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3188                 return false;
3189             }
3190             dss2.addValue( -100 );
3191             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3192                 return false;
3193             }
3194             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3195                 return false;
3196             }
3197             final double[] ds = new double[ 14 ];
3198             ds[ 0 ] = 34;
3199             ds[ 1 ] = 23;
3200             ds[ 2 ] = 1;
3201             ds[ 3 ] = 32;
3202             ds[ 4 ] = 11;
3203             ds[ 5 ] = 2;
3204             ds[ 6 ] = 12;
3205             ds[ 7 ] = 33;
3206             ds[ 8 ] = 13;
3207             ds[ 9 ] = 22;
3208             ds[ 10 ] = 21;
3209             ds[ 11 ] = 35;
3210             ds[ 12 ] = 24;
3211             ds[ 13 ] = 31;
3212             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3213             if ( bins.length != 4 ) {
3214                 return false;
3215             }
3216             if ( bins[ 0 ] != 2 ) {
3217                 return false;
3218             }
3219             if ( bins[ 1 ] != 3 ) {
3220                 return false;
3221             }
3222             if ( bins[ 2 ] != 4 ) {
3223                 return false;
3224             }
3225             if ( bins[ 3 ] != 5 ) {
3226                 return false;
3227             }
3228             final double[] ds1 = new double[ 9 ];
3229             ds1[ 0 ] = 10.0;
3230             ds1[ 1 ] = 19.0;
3231             ds1[ 2 ] = 9.999;
3232             ds1[ 3 ] = 0.0;
3233             ds1[ 4 ] = 39.9;
3234             ds1[ 5 ] = 39.999;
3235             ds1[ 6 ] = 30.0;
3236             ds1[ 7 ] = 19.999;
3237             ds1[ 8 ] = 30.1;
3238             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3239             if ( bins1.length != 4 ) {
3240                 return false;
3241             }
3242             if ( bins1[ 0 ] != 2 ) {
3243                 return false;
3244             }
3245             if ( bins1[ 1 ] != 3 ) {
3246                 return false;
3247             }
3248             if ( bins1[ 2 ] != 0 ) {
3249                 return false;
3250             }
3251             if ( bins1[ 3 ] != 4 ) {
3252                 return false;
3253             }
3254             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3255             if ( bins1_1.length != 3 ) {
3256                 return false;
3257             }
3258             if ( bins1_1[ 0 ] != 3 ) {
3259                 return false;
3260             }
3261             if ( bins1_1[ 1 ] != 2 ) {
3262                 return false;
3263             }
3264             if ( bins1_1[ 2 ] != 4 ) {
3265                 return false;
3266             }
3267             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3268             if ( bins1_2.length != 3 ) {
3269                 return false;
3270             }
3271             if ( bins1_2[ 0 ] != 2 ) {
3272                 return false;
3273             }
3274             if ( bins1_2[ 1 ] != 2 ) {
3275                 return false;
3276             }
3277             if ( bins1_2[ 2 ] != 2 ) {
3278                 return false;
3279             }
3280             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3281             dss3.addValue( 1 );
3282             dss3.addValue( 1 );
3283             dss3.addValue( 1 );
3284             dss3.addValue( 2 );
3285             dss3.addValue( 3 );
3286             dss3.addValue( 4 );
3287             dss3.addValue( 5 );
3288             dss3.addValue( 5 );
3289             dss3.addValue( 5 );
3290             dss3.addValue( 6 );
3291             dss3.addValue( 7 );
3292             dss3.addValue( 8 );
3293             dss3.addValue( 9 );
3294             dss3.addValue( 10 );
3295             dss3.addValue( 10 );
3296             dss3.addValue( 10 );
3297             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3298             histo.toStringBuffer( 10, '=', 40, 5 );
3299             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3300         }
3301         catch ( final Exception e ) {
3302             e.printStackTrace( System.out );
3303             return false;
3304         }
3305         return true;
3306     }
3307
3308     private static boolean testDir( final String file ) {
3309         try {
3310             final File f = new File( file );
3311             if ( !f.exists() ) {
3312                 return false;
3313             }
3314             if ( !f.isDirectory() ) {
3315                 return false;
3316             }
3317             if ( !f.canRead() ) {
3318                 return false;
3319             }
3320         }
3321         catch ( final Exception e ) {
3322             return false;
3323         }
3324         return true;
3325     }
3326
3327     private static boolean testEmblEntryRetrieval() {
3328         //The format for GenBank Accession numbers are:
3329         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
3330         //Protein:    3 letters + 5 numerals
3331         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
3332         if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
3333             return false;
3334         }
3335         if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861.2" ).equals( "AY423861.2" ) ) {
3336             return false;
3337         }
3338         if ( !SequenceIdParser.parseGenbankAccessor( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
3339             return false;
3340         }
3341         if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
3342             return false;
3343         }
3344         if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
3345             return false;
3346         }
3347         if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
3348             return false;
3349         }
3350         if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
3351             return false;
3352         }
3353         if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
3354             return false;
3355         }
3356         if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
3357             return false;
3358         }
3359         if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
3360             return false;
3361         }
3362         if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
3363             return false;
3364         }
3365         if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
3366             return false;
3367         }
3368         if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
3369             return false;
3370         }
3371         if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
3372             return false;
3373         }
3374         return true;
3375     }
3376
3377     private static boolean testExternalNodeRelatedMethods() {
3378         try {
3379             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3380             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3381             PhylogenyNode n = t1.getNode( "A" );
3382             n = n.getNextExternalNode();
3383             if ( !n.getName().equals( "B" ) ) {
3384                 return false;
3385             }
3386             n = n.getNextExternalNode();
3387             if ( !n.getName().equals( "C" ) ) {
3388                 return false;
3389             }
3390             n = n.getNextExternalNode();
3391             if ( !n.getName().equals( "D" ) ) {
3392                 return false;
3393             }
3394             n = t1.getNode( "B" );
3395             while ( !n.isLastExternalNode() ) {
3396                 n = n.getNextExternalNode();
3397             }
3398             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3399             n = t2.getNode( "A" );
3400             n = n.getNextExternalNode();
3401             if ( !n.getName().equals( "B" ) ) {
3402                 return false;
3403             }
3404             n = n.getNextExternalNode();
3405             if ( !n.getName().equals( "C" ) ) {
3406                 return false;
3407             }
3408             n = n.getNextExternalNode();
3409             if ( !n.getName().equals( "D" ) ) {
3410                 return false;
3411             }
3412             n = t2.getNode( "B" );
3413             while ( !n.isLastExternalNode() ) {
3414                 n = n.getNextExternalNode();
3415             }
3416             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3417             n = t3.getNode( "A" );
3418             n = n.getNextExternalNode();
3419             if ( !n.getName().equals( "B" ) ) {
3420                 return false;
3421             }
3422             n = n.getNextExternalNode();
3423             if ( !n.getName().equals( "C" ) ) {
3424                 return false;
3425             }
3426             n = n.getNextExternalNode();
3427             if ( !n.getName().equals( "D" ) ) {
3428                 return false;
3429             }
3430             n = n.getNextExternalNode();
3431             if ( !n.getName().equals( "E" ) ) {
3432                 return false;
3433             }
3434             n = n.getNextExternalNode();
3435             if ( !n.getName().equals( "F" ) ) {
3436                 return false;
3437             }
3438             n = n.getNextExternalNode();
3439             if ( !n.getName().equals( "G" ) ) {
3440                 return false;
3441             }
3442             n = n.getNextExternalNode();
3443             if ( !n.getName().equals( "H" ) ) {
3444                 return false;
3445             }
3446             n = t3.getNode( "B" );
3447             while ( !n.isLastExternalNode() ) {
3448                 n = n.getNextExternalNode();
3449             }
3450             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3451             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3452                 final PhylogenyNode node = iter.next();
3453             }
3454             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3455             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3456                 final PhylogenyNode node = iter.next();
3457             }
3458             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3459             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3460             if ( !iter.next().getName().equals( "A" ) ) {
3461                 return false;
3462             }
3463             if ( !iter.next().getName().equals( "B" ) ) {
3464                 return false;
3465             }
3466             if ( !iter.next().getName().equals( "C" ) ) {
3467                 return false;
3468             }
3469             if ( !iter.next().getName().equals( "D" ) ) {
3470                 return false;
3471             }
3472             if ( !iter.next().getName().equals( "E" ) ) {
3473                 return false;
3474             }
3475             if ( !iter.next().getName().equals( "F" ) ) {
3476                 return false;
3477             }
3478             if ( iter.hasNext() ) {
3479                 return false;
3480             }
3481         }
3482         catch ( final Exception e ) {
3483             e.printStackTrace( System.out );
3484             return false;
3485         }
3486         return true;
3487     }
3488
3489     private static boolean testExtractSNFromNodeName() {
3490         try {
3491             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
3492                 return false;
3493             }
3494             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
3495                     .equals( "Mus musculus musculus" ) ) {
3496                 return false;
3497             }
3498             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
3499                     .equals( "Mus musculus musculus" ) ) {
3500                 return false;
3501             }
3502             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
3503                 return false;
3504             }
3505             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
3506                     .equals( "Mus musculus" ) ) {
3507                 return false;
3508             }
3509         }
3510         catch ( final Exception e ) {
3511             e.printStackTrace( System.out );
3512             return false;
3513         }
3514         return true;
3515     }
3516
3517     private static boolean testExtractTaxonomyCodeFromNodeName() {
3518         try {
3519             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3520                 return false;
3521             }
3522             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3523                     .equals( "SOYBN" ) ) {
3524                 return false;
3525             }
3526             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3527                     .equals( "ARATH" ) ) {
3528                 return false;
3529             }
3530             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3531                     .equals( "ARATH" ) ) {
3532                 return false;
3533             }
3534             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3535                 return false;
3536             }
3537             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3538                 return false;
3539             }
3540             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3541                 return false;
3542             }
3543             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3544                     .equals( "SOYBN" ) ) {
3545                 return false;
3546             }
3547             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3548                     .equals( "SOYBN" ) ) {
3549                 return false;
3550             }
3551             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3552                     .equals( "SOYBN" ) ) {
3553                 return false;
3554             }
3555             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3556                     .equals( "SOYBN" ) ) {
3557                 return false;
3558             }
3559             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3560                     .equals( "SOYBN" ) ) {
3561                 return false;
3562             }
3563             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3564                     .equals( "SOYBN" ) ) {
3565                 return false;
3566             }
3567             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
3568                     .equals( "SOYBN" ) ) {
3569                 return false;
3570             }
3571             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
3572                     .equals( "SOYBN" ) ) {
3573                 return false;
3574             }
3575             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
3576                 return false;
3577             }
3578             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
3579                     .equals( "SOYBN" ) ) {
3580                 return false;
3581             }
3582             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
3583                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
3584                 return false;
3585             }
3586             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
3587                     .equals( "9YX45" ) ) {
3588                 return false;
3589             }
3590             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
3591                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3592                     .equals( "MOUSE" ) ) {
3593                 return false;
3594             }
3595             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
3596                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3597                     .equals( "MOUSE" ) ) {
3598                 return false;
3599             }
3600             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
3601                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3602                     .equals( "MOUSE" ) ) {
3603                 return false;
3604             }
3605             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
3606                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3607                 return false;
3608             }
3609             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
3610                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3611                 return false;
3612             }
3613             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3614                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3615                 return false;
3616             }
3617             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3618                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3619                 return false;
3620             }
3621             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
3622                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3623                 return false;
3624             }
3625             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
3626                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3627                 return false;
3628             }
3629             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
3630                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3631                 return false;
3632             }
3633             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3634                     .equals( "RAT" ) ) {
3635                 return false;
3636             }
3637             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3638                     .equals( "PIG" ) ) {
3639                 return false;
3640             }
3641             if ( !ParserUtils
3642                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3643                     .equals( "MOUSE" ) ) {
3644                 return false;
3645             }
3646             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3647                     .equals( "MOUSE" ) ) {
3648                 return false;
3649             }
3650             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3651                 return false;
3652             }
3653         }
3654         catch ( final Exception e ) {
3655             e.printStackTrace( System.out );
3656             return false;
3657         }
3658         return true;
3659     }
3660
3661     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
3662         try {
3663             PhylogenyNode n = new PhylogenyNode();
3664             n.setName( "tr|B3RJ64" );
3665             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3666                 return false;
3667             }
3668             n.setName( "tr.B3RJ64" );
3669             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3670                 return false;
3671             }
3672             n.setName( "tr=B3RJ64" );
3673             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3674                 return false;
3675             }
3676             n.setName( "tr-B3RJ64" );
3677             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3678                 return false;
3679             }
3680             n.setName( "tr/B3RJ64" );
3681             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3682                 return false;
3683             }
3684             n.setName( "tr\\B3RJ64" );
3685             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3686                 return false;
3687             }
3688             n.setName( "tr_B3RJ64" );
3689             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3690                 return false;
3691             }
3692             n.setName( " tr|B3RJ64 " );
3693             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3694                 return false;
3695             }
3696             n.setName( "-tr|B3RJ64-" );
3697             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3698                 return false;
3699             }
3700             n.setName( "-tr=B3RJ64-" );
3701             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3702                 return false;
3703             }
3704             n.setName( "_tr=B3RJ64_" );
3705             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3706                 return false;
3707             }
3708             n.setName( " tr_tr|B3RJ64_sp|123 " );
3709             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3710                 return false;
3711             }
3712             n.setName( "sp|B3RJ64" );
3713             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3714                 return false;
3715             }
3716             n.setName( "ssp|B3RJ64" );
3717             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3718                 return false;
3719             }
3720             n.setName( "sp|B3RJ64C" );
3721             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3722                 return false;
3723             }
3724             n.setName( "sp B3RJ64" );
3725             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3726                 return false;
3727             }
3728             n.setName( "sp|B3RJ6X" );
3729             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3730                 return false;
3731             }
3732             n.setName( "sp|B3RJ6" );
3733             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3734                 return false;
3735             }
3736             n.setName( "K1PYK7_CRAGI" );
3737             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3738                 return false;
3739             }
3740             n.setName( "K1PYK7_PEA" );
3741             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) {
3742                 return false;
3743             }
3744             n.setName( "K1PYK7_RAT" );
3745             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) {
3746                 return false;
3747             }
3748             n.setName( "K1PYK7_PIG" );
3749             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
3750                 return false;
3751             }
3752             n.setName( "~K1PYK7_PIG~" );
3753             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
3754                 return false;
3755             }
3756             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
3757             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3758                 return false;
3759             }
3760             n.setName( "K1PYKX_CRAGI" );
3761             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3762                 return false;
3763             }
3764             n.setName( "XXXXX_CRAGI" );
3765             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) {
3766                 return false;
3767             }
3768             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
3769             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) {
3770                 return false;
3771             }
3772             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
3773             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3774                 return false;
3775             }
3776             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
3777             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) {
3778                 return false;
3779             }
3780             n = new PhylogenyNode();
3781             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
3782             seq.setSymbol( "K1PYK7_CRAGI" );
3783             n.getNodeData().addSequence( seq );
3784             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3785                 return false;
3786             }
3787             seq.setSymbol( "tr|B3RJ64" );
3788             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3789                 return false;
3790             }
3791             n = new PhylogenyNode();
3792             seq = new org.forester.phylogeny.data.Sequence();
3793             seq.setName( "K1PYK7_CRAGI" );
3794             n.getNodeData().addSequence( seq );
3795             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3796                 return false;
3797             }
3798             seq.setName( "tr|B3RJ64" );
3799             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3800                 return false;
3801             }
3802             n = new PhylogenyNode();
3803             seq = new org.forester.phylogeny.data.Sequence();
3804             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
3805             n.getNodeData().addSequence( seq );
3806             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) {
3807                 return false;
3808             }
3809             n = new PhylogenyNode();
3810             seq = new org.forester.phylogeny.data.Sequence();
3811             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
3812             n.getNodeData().addSequence( seq );
3813             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3814                 return false;
3815             }
3816             //
3817             n = new PhylogenyNode();
3818             n.setName( "ACP19736" );
3819             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
3820                 return false;
3821             }
3822             n = new PhylogenyNode();
3823             n.setName( "_ACP19736_" );
3824             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
3825                 return false;
3826             }
3827         }
3828         catch ( final Exception e ) {
3829             e.printStackTrace( System.out );
3830             return false;
3831         }
3832         return true;
3833     }
3834
3835     private static boolean testFastaParser() {
3836         try {
3837             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
3838                 return false;
3839             }
3840             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
3841                 return false;
3842             }
3843             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
3844             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
3845                 return false;
3846             }
3847             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
3848                 return false;
3849             }
3850             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
3851                 return false;
3852             }
3853             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
3854                 return false;
3855             }
3856             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
3857                 return false;
3858             }
3859             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
3860                 return false;
3861             }
3862         }
3863         catch ( final Exception e ) {
3864             e.printStackTrace();
3865             return false;
3866         }
3867         return true;
3868     }
3869
3870     private static boolean testGeneralMsaParser() {
3871         try {
3872             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
3873             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
3874             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
3875             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
3876             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
3877             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
3878             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
3879             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
3880             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3881                 return false;
3882             }
3883             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3884                 return false;
3885             }
3886             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3887                 return false;
3888             }
3889             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3890                 return false;
3891             }
3892             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3893                 return false;
3894             }
3895             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3896                 return false;
3897             }
3898             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3899                 return false;
3900             }
3901             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3902                 return false;
3903             }
3904             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3905                 return false;
3906             }
3907             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3908                 return false;
3909             }
3910             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3911                 return false;
3912             }
3913             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3914                 return false;
3915             }
3916             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
3917             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
3918                 return false;
3919             }
3920             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
3921                 return false;
3922             }
3923             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
3924                 return false;
3925             }
3926             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
3927             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
3928                 return false;
3929             }
3930             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
3931                 return false;
3932             }
3933             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
3934                 return false;
3935             }
3936             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
3937             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
3938                 return false;
3939             }
3940             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
3941                 return false;
3942             }
3943             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
3944                 return false;
3945             }
3946         }
3947         catch ( final Exception e ) {
3948             e.printStackTrace();
3949             return false;
3950         }
3951         return true;
3952     }
3953
3954     private static boolean testGeneralTable() {
3955         try {
3956             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3957             t0.setValue( 3, 2, "23" );
3958             t0.setValue( 10, 1, "error" );
3959             t0.setValue( 10, 1, "110" );
3960             t0.setValue( 9, 1, "19" );
3961             t0.setValue( 1, 10, "101" );
3962             t0.setValue( 10, 10, "1010" );
3963             t0.setValue( 100, 10, "10100" );
3964             t0.setValue( 0, 0, "00" );
3965             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3966                 return false;
3967             }
3968             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3969                 return false;
3970             }
3971             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3972                 return false;
3973             }
3974             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3975                 return false;
3976             }
3977             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3978                 return false;
3979             }
3980             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3981                 return false;
3982             }
3983             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3984                 return false;
3985             }
3986             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3987                 return false;
3988             }
3989             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3990                 return false;
3991             }
3992             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3993             t1.setValue( "3", "2", "23" );
3994             t1.setValue( "10", "1", "error" );
3995             t1.setValue( "10", "1", "110" );
3996             t1.setValue( "9", "1", "19" );
3997             t1.setValue( "1", "10", "101" );
3998             t1.setValue( "10", "10", "1010" );
3999             t1.setValue( "100", "10", "10100" );
4000             t1.setValue( "0", "0", "00" );
4001             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4002             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4003                 return false;
4004             }
4005             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4006                 return false;
4007             }
4008             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4009                 return false;
4010             }
4011             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4012                 return false;
4013             }
4014             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4015                 return false;
4016             }
4017             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4018                 return false;
4019             }
4020             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4021                 return false;
4022             }
4023             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4024                 return false;
4025             }
4026             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4027                 return false;
4028             }
4029             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4030                 return false;
4031             }
4032         }
4033         catch ( final Exception e ) {
4034             e.printStackTrace( System.out );
4035             return false;
4036         }
4037         return true;
4038     }
4039
4040     private static boolean testGetDistance() {
4041         try {
4042             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4043             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",
4044                                                  new NHXParser() )[ 0 ];
4045             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4046                 return false;
4047             }
4048             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4049                 return false;
4050             }
4051             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4052                 return false;
4053             }
4054             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4055                 return false;
4056             }
4057             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4058                 return false;
4059             }
4060             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4061                 return false;
4062             }
4063             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4064                 return false;
4065             }
4066             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4067                 return false;
4068             }
4069             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4070                 return false;
4071             }
4072             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4073                 return false;
4074             }
4075             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4076                 return false;
4077             }
4078             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4079                 return false;
4080             }
4081             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4082                 return false;
4083             }
4084             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4085                 return false;
4086             }
4087             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4088                 return false;
4089             }
4090             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4091                 return false;
4092             }
4093             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4094                 return false;
4095             }
4096             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4097                 return false;
4098             }
4099             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4100                 return false;
4101             }
4102             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4103                 return false;
4104             }
4105             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4106                 return false;
4107             }
4108             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4109                 return false;
4110             }
4111             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4112                 return false;
4113             }
4114             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4115                 return false;
4116             }
4117             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4118                 return false;
4119             }
4120             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4121                 return false;
4122             }
4123             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4124                 return false;
4125             }
4126             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4127                 return false;
4128             }
4129             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4130                 return false;
4131             }
4132             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4133                 return false;
4134             }
4135             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4136                 return false;
4137             }
4138             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",
4139                                                  new NHXParser() )[ 0 ];
4140             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4141                 return false;
4142             }
4143             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4144                 return false;
4145             }
4146             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4147                 return false;
4148             }
4149             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4150                 return false;
4151             }
4152             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4153                 return false;
4154             }
4155             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4156                 return false;
4157             }
4158             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4159                 return false;
4160             }
4161             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4162                 return false;
4163             }
4164             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4165                 return false;
4166             }
4167             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4168                 return false;
4169             }
4170             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4171                 return false;
4172             }
4173         }
4174         catch ( final Exception e ) {
4175             e.printStackTrace( System.out );
4176             return false;
4177         }
4178         return true;
4179     }
4180
4181     private static boolean testGetLCA() {
4182         try {
4183             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4184             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4185                                                  new NHXParser() )[ 0 ];
4186             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4187             if ( !A.getName().equals( "A" ) ) {
4188                 return false;
4189             }
4190             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4191             if ( !gh.getName().equals( "gh" ) ) {
4192                 return false;
4193             }
4194             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4195             if ( !ab.getName().equals( "ab" ) ) {
4196                 return false;
4197             }
4198             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4199             if ( !ab2.getName().equals( "ab" ) ) {
4200                 return false;
4201             }
4202             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4203             if ( !gh2.getName().equals( "gh" ) ) {
4204                 return false;
4205             }
4206             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4207             if ( !gh3.getName().equals( "gh" ) ) {
4208                 return false;
4209             }
4210             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4211             if ( !abc.getName().equals( "abc" ) ) {
4212                 return false;
4213             }
4214             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4215             if ( !abc2.getName().equals( "abc" ) ) {
4216                 return false;
4217             }
4218             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4219             if ( !abcd.getName().equals( "abcd" ) ) {
4220                 return false;
4221             }
4222             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4223             if ( !abcd2.getName().equals( "abcd" ) ) {
4224                 return false;
4225             }
4226             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4227             if ( !abcdef.getName().equals( "abcdef" ) ) {
4228                 return false;
4229             }
4230             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4231             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4232                 return false;
4233             }
4234             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4235             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4236                 return false;
4237             }
4238             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4239             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4240                 return false;
4241             }
4242             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4243             if ( !abcde.getName().equals( "abcde" ) ) {
4244                 return false;
4245             }
4246             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4247             if ( !abcde2.getName().equals( "abcde" ) ) {
4248                 return false;
4249             }
4250             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4251             if ( !r.getName().equals( "abcdefgh" ) ) {
4252                 return false;
4253             }
4254             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4255             if ( !r2.getName().equals( "abcdefgh" ) ) {
4256                 return false;
4257             }
4258             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4259             if ( !r3.getName().equals( "abcdefgh" ) ) {
4260                 return false;
4261             }
4262             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4263             if ( !abcde3.getName().equals( "abcde" ) ) {
4264                 return false;
4265             }
4266             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4267             if ( !abcde4.getName().equals( "abcde" ) ) {
4268                 return false;
4269             }
4270             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4271             if ( !ab3.getName().equals( "ab" ) ) {
4272                 return false;
4273             }
4274             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4275             if ( !ab4.getName().equals( "ab" ) ) {
4276                 return false;
4277             }
4278             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4279             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4280             if ( !cd.getName().equals( "cd" ) ) {
4281                 return false;
4282             }
4283             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4284             if ( !cd2.getName().equals( "cd" ) ) {
4285                 return false;
4286             }
4287             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4288             if ( !cde.getName().equals( "cde" ) ) {
4289                 return false;
4290             }
4291             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4292             if ( !cde2.getName().equals( "cde" ) ) {
4293                 return false;
4294             }
4295             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4296             if ( !cdef.getName().equals( "cdef" ) ) {
4297                 return false;
4298             }
4299             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4300             if ( !cdef2.getName().equals( "cdef" ) ) {
4301                 return false;
4302             }
4303             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4304             if ( !cdef3.getName().equals( "cdef" ) ) {
4305                 return false;
4306             }
4307             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4308             if ( !rt.getName().equals( "r" ) ) {
4309                 return false;
4310             }
4311             final Phylogeny p3 = factory
4312                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4313                              new NHXParser() )[ 0 ];
4314             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4315             if ( !bc_3.getName().equals( "bc" ) ) {
4316                 return false;
4317             }
4318             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4319             if ( !ac_3.getName().equals( "abc" ) ) {
4320                 return false;
4321             }
4322             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4323             if ( !ad_3.getName().equals( "abcde" ) ) {
4324                 return false;
4325             }
4326             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4327             if ( !af_3.getName().equals( "abcdef" ) ) {
4328                 return false;
4329             }
4330             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4331             if ( !ag_3.getName().equals( "" ) ) {
4332                 return false;
4333             }
4334             if ( !ag_3.isRoot() ) {
4335                 return false;
4336             }
4337             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4338             if ( !al_3.getName().equals( "" ) ) {
4339                 return false;
4340             }
4341             if ( !al_3.isRoot() ) {
4342                 return false;
4343             }
4344             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4345             if ( !kl_3.getName().equals( "" ) ) {
4346                 return false;
4347             }
4348             if ( !kl_3.isRoot() ) {
4349                 return false;
4350             }
4351             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4352             if ( !fl_3.getName().equals( "" ) ) {
4353                 return false;
4354             }
4355             if ( !fl_3.isRoot() ) {
4356                 return false;
4357             }
4358             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4359             if ( !gk_3.getName().equals( "ghijk" ) ) {
4360                 return false;
4361             }
4362             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4363             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4364             if ( !r_4.getName().equals( "r" ) ) {
4365                 return false;
4366             }
4367             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4368             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4369             if ( !r_5.getName().equals( "root" ) ) {
4370                 return false;
4371             }
4372             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4373             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4374             if ( !r_6.getName().equals( "rot" ) ) {
4375                 return false;
4376             }
4377             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4378             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4379             if ( !r_7.getName().equals( "rott" ) ) {
4380                 return false;
4381             }
4382         }
4383         catch ( final Exception e ) {
4384             e.printStackTrace( System.out );
4385             return false;
4386         }
4387         return true;
4388     }
4389
4390     private static boolean testGetLCA2() {
4391         try {
4392             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4393             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
4394             PhylogenyMethods.preOrderReId( p_a );
4395             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
4396                                                                                               p_a.getNode( "a" ) );
4397             if ( !p_a_1.getName().equals( "a" ) ) {
4398                 return false;
4399             }
4400             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4401             PhylogenyMethods.preOrderReId( p_b );
4402             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
4403                                                                                               p_b.getNode( "a" ) );
4404             if ( !p_b_1.getName().equals( "b" ) ) {
4405                 return false;
4406             }
4407             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
4408                                                                                               p_b.getNode( "b" ) );
4409             if ( !p_b_2.getName().equals( "b" ) ) {
4410                 return false;
4411             }
4412             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
4413             PhylogenyMethods.preOrderReId( p_c );
4414             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
4415                                                                                               p_c.getNode( "a" ) );
4416             if ( !p_c_1.getName().equals( "b" ) ) {
4417                 return false;
4418             }
4419             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4420                                                                                               p_c.getNode( "c" ) );
4421             if ( !p_c_2.getName().equals( "c" ) ) {
4422                 System.out.println( p_c_2.getName() );
4423                 System.exit( -1 );
4424                 return false;
4425             }
4426             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4427                                                                                               p_c.getNode( "b" ) );
4428             if ( !p_c_3.getName().equals( "b" ) ) {
4429                 return false;
4430             }
4431             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
4432                                                                                               p_c.getNode( "a" ) );
4433             if ( !p_c_4.getName().equals( "c" ) ) {
4434                 return false;
4435             }
4436             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4437                                                  new NHXParser() )[ 0 ];
4438             PhylogenyMethods.preOrderReId( p1 );
4439             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4440                                                                                           p1.getNode( "A" ) );
4441             if ( !A.getName().equals( "A" ) ) {
4442                 return false;
4443             }
4444             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
4445                                                                                            p1.getNode( "gh" ) );
4446             if ( !gh.getName().equals( "gh" ) ) {
4447                 return false;
4448             }
4449             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4450                                                                                            p1.getNode( "B" ) );
4451             if ( !ab.getName().equals( "ab" ) ) {
4452                 return false;
4453             }
4454             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4455                                                                                             p1.getNode( "A" ) );
4456             if ( !ab2.getName().equals( "ab" ) ) {
4457                 return false;
4458             }
4459             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4460                                                                                             p1.getNode( "G" ) );
4461             if ( !gh2.getName().equals( "gh" ) ) {
4462                 return false;
4463             }
4464             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
4465                                                                                             p1.getNode( "H" ) );
4466             if ( !gh3.getName().equals( "gh" ) ) {
4467                 return false;
4468             }
4469             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
4470                                                                                             p1.getNode( "A" ) );
4471             if ( !abc.getName().equals( "abc" ) ) {
4472                 return false;
4473             }
4474             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4475                                                                                              p1.getNode( "C" ) );
4476             if ( !abc2.getName().equals( "abc" ) ) {
4477                 return false;
4478             }
4479             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4480                                                                                              p1.getNode( "D" ) );
4481             if ( !abcd.getName().equals( "abcd" ) ) {
4482                 return false;
4483             }
4484             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
4485                                                                                               p1.getNode( "A" ) );
4486             if ( !abcd2.getName().equals( "abcd" ) ) {
4487                 return false;
4488             }
4489             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4490                                                                                                p1.getNode( "F" ) );
4491             if ( !abcdef.getName().equals( "abcdef" ) ) {
4492                 return false;
4493             }
4494             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4495                                                                                                 p1.getNode( "A" ) );
4496             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4497                 return false;
4498             }
4499             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4500                                                                                                 p1.getNode( "F" ) );
4501             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4502                 return false;
4503             }
4504             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4505                                                                                                 p1.getNode( "ab" ) );
4506             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4507                 return false;
4508             }
4509             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4510                                                                                               p1.getNode( "E" ) );
4511             if ( !abcde.getName().equals( "abcde" ) ) {
4512                 return false;
4513             }
4514             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4515                                                                                                p1.getNode( "A" ) );
4516             if ( !abcde2.getName().equals( "abcde" ) ) {
4517                 return false;
4518             }
4519             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
4520                                                                                           p1.getNode( "abcdefgh" ) );
4521             if ( !r.getName().equals( "abcdefgh" ) ) {
4522                 return false;
4523             }
4524             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4525                                                                                            p1.getNode( "H" ) );
4526             if ( !r2.getName().equals( "abcdefgh" ) ) {
4527                 return false;
4528             }
4529             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4530                                                                                            p1.getNode( "A" ) );
4531             if ( !r3.getName().equals( "abcdefgh" ) ) {
4532                 return false;
4533             }
4534             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4535                                                                                                p1.getNode( "abcde" ) );
4536             if ( !abcde3.getName().equals( "abcde" ) ) {
4537                 return false;
4538             }
4539             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
4540                                                                                                p1.getNode( "E" ) );
4541             if ( !abcde4.getName().equals( "abcde" ) ) {
4542                 return false;
4543             }
4544             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4545                                                                                             p1.getNode( "B" ) );
4546             if ( !ab3.getName().equals( "ab" ) ) {
4547                 return false;
4548             }
4549             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4550                                                                                             p1.getNode( "ab" ) );
4551             if ( !ab4.getName().equals( "ab" ) ) {
4552                 return false;
4553             }
4554             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4555             PhylogenyMethods.preOrderReId( p2 );
4556             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4557                                                                                            p2.getNode( "d" ) );
4558             if ( !cd.getName().equals( "cd" ) ) {
4559                 return false;
4560             }
4561             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4562                                                                                             p2.getNode( "c" ) );
4563             if ( !cd2.getName().equals( "cd" ) ) {
4564                 return false;
4565             }
4566             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4567                                                                                             p2.getNode( "e" ) );
4568             if ( !cde.getName().equals( "cde" ) ) {
4569                 return false;
4570             }
4571             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
4572                                                                                              p2.getNode( "c" ) );
4573             if ( !cde2.getName().equals( "cde" ) ) {
4574                 return false;
4575             }
4576             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4577                                                                                              p2.getNode( "f" ) );
4578             if ( !cdef.getName().equals( "cdef" ) ) {
4579                 return false;
4580             }
4581             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4582                                                                                               p2.getNode( "f" ) );
4583             if ( !cdef2.getName().equals( "cdef" ) ) {
4584                 return false;
4585             }
4586             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
4587                                                                                               p2.getNode( "d" ) );
4588             if ( !cdef3.getName().equals( "cdef" ) ) {
4589                 return false;
4590             }
4591             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4592                                                                                            p2.getNode( "a" ) );
4593             if ( !rt.getName().equals( "r" ) ) {
4594                 return false;
4595             }
4596             final Phylogeny p3 = factory
4597                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4598                              new NHXParser() )[ 0 ];
4599             PhylogenyMethods.preOrderReId( p3 );
4600             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
4601                                                                                              p3.getNode( "c" ) );
4602             if ( !bc_3.getName().equals( "bc" ) ) {
4603                 return false;
4604             }
4605             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4606                                                                                              p3.getNode( "c" ) );
4607             if ( !ac_3.getName().equals( "abc" ) ) {
4608                 return false;
4609             }
4610             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4611                                                                                              p3.getNode( "d" ) );
4612             if ( !ad_3.getName().equals( "abcde" ) ) {
4613                 return false;
4614             }
4615             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4616                                                                                              p3.getNode( "f" ) );
4617             if ( !af_3.getName().equals( "abcdef" ) ) {
4618                 return false;
4619             }
4620             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4621                                                                                              p3.getNode( "g" ) );
4622             if ( !ag_3.getName().equals( "" ) ) {
4623                 return false;
4624             }
4625             if ( !ag_3.isRoot() ) {
4626                 return false;
4627             }
4628             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4629                                                                                              p3.getNode( "l" ) );
4630             if ( !al_3.getName().equals( "" ) ) {
4631                 return false;
4632             }
4633             if ( !al_3.isRoot() ) {
4634                 return false;
4635             }
4636             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
4637                                                                                              p3.getNode( "l" ) );
4638             if ( !kl_3.getName().equals( "" ) ) {
4639                 return false;
4640             }
4641             if ( !kl_3.isRoot() ) {
4642                 return false;
4643             }
4644             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
4645                                                                                              p3.getNode( "l" ) );
4646             if ( !fl_3.getName().equals( "" ) ) {
4647                 return false;
4648             }
4649             if ( !fl_3.isRoot() ) {
4650                 return false;
4651             }
4652             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
4653                                                                                              p3.getNode( "k" ) );
4654             if ( !gk_3.getName().equals( "ghijk" ) ) {
4655                 return false;
4656             }
4657             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4658             PhylogenyMethods.preOrderReId( p4 );
4659             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
4660                                                                                             p4.getNode( "c" ) );
4661             if ( !r_4.getName().equals( "r" ) ) {
4662                 return false;
4663             }
4664             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4665             PhylogenyMethods.preOrderReId( p5 );
4666             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
4667                                                                                             p5.getNode( "c" ) );
4668             if ( !r_5.getName().equals( "root" ) ) {
4669                 return false;
4670             }
4671             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4672             PhylogenyMethods.preOrderReId( p6 );
4673             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
4674                                                                                             p6.getNode( "a" ) );
4675             if ( !r_6.getName().equals( "rot" ) ) {
4676                 return false;
4677             }
4678             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4679             PhylogenyMethods.preOrderReId( p7 );
4680             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4681                                                                                             p7.getNode( "e" ) );
4682             if ( !r_7.getName().equals( "rott" ) ) {
4683                 return false;
4684             }
4685             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4686                                                                                              p7.getNode( "a" ) );
4687             if ( !r_71.getName().equals( "rott" ) ) {
4688                 return false;
4689             }
4690             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4691                                                                                              p7.getNode( "rott" ) );
4692             if ( !r_72.getName().equals( "rott" ) ) {
4693                 return false;
4694             }
4695             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4696                                                                                              p7.getNode( "a" ) );
4697             if ( !r_73.getName().equals( "rott" ) ) {
4698                 return false;
4699             }
4700             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4701                                                                                              p7.getNode( "rott" ) );
4702             if ( !r_74.getName().equals( "rott" ) ) {
4703                 return false;
4704             }
4705             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4706                                                                                              p7.getNode( "e" ) );
4707             if ( !r_75.getName().equals( "e" ) ) {
4708                 return false;
4709             }
4710         }
4711         catch ( final Exception e ) {
4712             e.printStackTrace( System.out );
4713             return false;
4714         }
4715         return true;
4716     }
4717
4718     private static boolean testHmmscanOutputParser() {
4719         final String test_dir = Test.PATH_TO_TEST_DATA;
4720         try {
4721             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4722                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4723             parser1.parse();
4724             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4725                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4726             final List<Protein> proteins = parser2.parse();
4727             if ( parser2.getProteinsEncountered() != 4 ) {
4728                 return false;
4729             }
4730             if ( proteins.size() != 4 ) {
4731                 return false;
4732             }
4733             if ( parser2.getDomainsEncountered() != 69 ) {
4734                 return false;
4735             }
4736             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4737                 return false;
4738             }
4739             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4740                 return false;
4741             }
4742             final Protein p1 = proteins.get( 0 );
4743             if ( p1.getNumberOfProteinDomains() != 15 ) {
4744                 return false;
4745             }
4746             if ( p1.getLength() != 850 ) {
4747                 return false;
4748             }
4749             final Protein p2 = proteins.get( 1 );
4750             if ( p2.getNumberOfProteinDomains() != 51 ) {
4751                 return false;
4752             }
4753             if ( p2.getLength() != 1291 ) {
4754                 return false;
4755             }
4756             final Protein p3 = proteins.get( 2 );
4757             if ( p3.getNumberOfProteinDomains() != 2 ) {
4758                 return false;
4759             }
4760             final Protein p4 = proteins.get( 3 );
4761             if ( p4.getNumberOfProteinDomains() != 1 ) {
4762                 return false;
4763             }
4764             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4765                 return false;
4766             }
4767             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4768                 return false;
4769             }
4770             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4771                 return false;
4772             }
4773             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4774                 return false;
4775             }
4776             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4777                 return false;
4778             }
4779             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4780                 return false;
4781             }
4782             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4783                 return false;
4784             }
4785             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4786                 return false;
4787             }
4788             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4789                 return false;
4790             }
4791         }
4792         catch ( final Exception e ) {
4793             e.printStackTrace( System.out );
4794             return false;
4795         }
4796         return true;
4797     }
4798
4799     private static boolean testLastExternalNodeMethods() {
4800         try {
4801             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4802             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4803             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4804             final PhylogenyNode n1 = t0.getNode( "A" );
4805             if ( n1.isLastExternalNode() ) {
4806                 return false;
4807             }
4808             final PhylogenyNode n2 = t0.getNode( "B" );
4809             if ( n2.isLastExternalNode() ) {
4810                 return false;
4811             }
4812             final PhylogenyNode n3 = t0.getNode( "C" );
4813             if ( n3.isLastExternalNode() ) {
4814                 return false;
4815             }
4816             final PhylogenyNode n4 = t0.getNode( "D" );
4817             if ( !n4.isLastExternalNode() ) {
4818                 return false;
4819             }
4820         }
4821         catch ( final Exception e ) {
4822             e.printStackTrace( System.out );
4823             return false;
4824         }
4825         return true;
4826     }
4827
4828     private static boolean testLevelOrderIterator() {
4829         try {
4830             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4831             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4832             PhylogenyNodeIterator it0;
4833             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4834                 it0.next();
4835             }
4836             for( it0.reset(); it0.hasNext(); ) {
4837                 it0.next();
4838             }
4839             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4840             if ( !it.next().getName().equals( "r" ) ) {
4841                 return false;
4842             }
4843             if ( !it.next().getName().equals( "ab" ) ) {
4844                 return false;
4845             }
4846             if ( !it.next().getName().equals( "cd" ) ) {
4847                 return false;
4848             }
4849             if ( !it.next().getName().equals( "A" ) ) {
4850                 return false;
4851             }
4852             if ( !it.next().getName().equals( "B" ) ) {
4853                 return false;
4854             }
4855             if ( !it.next().getName().equals( "C" ) ) {
4856                 return false;
4857             }
4858             if ( !it.next().getName().equals( "D" ) ) {
4859                 return false;
4860             }
4861             if ( it.hasNext() ) {
4862                 return false;
4863             }
4864             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",
4865                                                  new NHXParser() )[ 0 ];
4866             PhylogenyNodeIterator it2;
4867             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4868                 it2.next();
4869             }
4870             for( it2.reset(); it2.hasNext(); ) {
4871                 it2.next();
4872             }
4873             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4874             if ( !it3.next().getName().equals( "r" ) ) {
4875                 return false;
4876             }
4877             if ( !it3.next().getName().equals( "abc" ) ) {
4878                 return false;
4879             }
4880             if ( !it3.next().getName().equals( "defg" ) ) {
4881                 return false;
4882             }
4883             if ( !it3.next().getName().equals( "A" ) ) {
4884                 return false;
4885             }
4886             if ( !it3.next().getName().equals( "B" ) ) {
4887                 return false;
4888             }
4889             if ( !it3.next().getName().equals( "C" ) ) {
4890                 return false;
4891             }
4892             if ( !it3.next().getName().equals( "D" ) ) {
4893                 return false;
4894             }
4895             if ( !it3.next().getName().equals( "E" ) ) {
4896                 return false;
4897             }
4898             if ( !it3.next().getName().equals( "F" ) ) {
4899                 return false;
4900             }
4901             if ( !it3.next().getName().equals( "G" ) ) {
4902                 return false;
4903             }
4904             if ( !it3.next().getName().equals( "1" ) ) {
4905                 return false;
4906             }
4907             if ( !it3.next().getName().equals( "2" ) ) {
4908                 return false;
4909             }
4910             if ( !it3.next().getName().equals( "3" ) ) {
4911                 return false;
4912             }
4913             if ( !it3.next().getName().equals( "4" ) ) {
4914                 return false;
4915             }
4916             if ( !it3.next().getName().equals( "5" ) ) {
4917                 return false;
4918             }
4919             if ( !it3.next().getName().equals( "6" ) ) {
4920                 return false;
4921             }
4922             if ( !it3.next().getName().equals( "f1" ) ) {
4923                 return false;
4924             }
4925             if ( !it3.next().getName().equals( "f2" ) ) {
4926                 return false;
4927             }
4928             if ( !it3.next().getName().equals( "f3" ) ) {
4929                 return false;
4930             }
4931             if ( !it3.next().getName().equals( "a" ) ) {
4932                 return false;
4933             }
4934             if ( !it3.next().getName().equals( "b" ) ) {
4935                 return false;
4936             }
4937             if ( !it3.next().getName().equals( "f21" ) ) {
4938                 return false;
4939             }
4940             if ( !it3.next().getName().equals( "X" ) ) {
4941                 return false;
4942             }
4943             if ( !it3.next().getName().equals( "Y" ) ) {
4944                 return false;
4945             }
4946             if ( !it3.next().getName().equals( "Z" ) ) {
4947                 return false;
4948             }
4949             if ( it3.hasNext() ) {
4950                 return false;
4951             }
4952             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4953             PhylogenyNodeIterator it4;
4954             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4955                 it4.next();
4956             }
4957             for( it4.reset(); it4.hasNext(); ) {
4958                 it4.next();
4959             }
4960             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4961             if ( !it5.next().getName().equals( "r" ) ) {
4962                 return false;
4963             }
4964             if ( !it5.next().getName().equals( "A" ) ) {
4965                 return false;
4966             }
4967             if ( !it5.next().getName().equals( "B" ) ) {
4968                 return false;
4969             }
4970             if ( !it5.next().getName().equals( "C" ) ) {
4971                 return false;
4972             }
4973             if ( !it5.next().getName().equals( "D" ) ) {
4974                 return false;
4975             }
4976             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4977             PhylogenyNodeIterator it6;
4978             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4979                 it6.next();
4980             }
4981             for( it6.reset(); it6.hasNext(); ) {
4982                 it6.next();
4983             }
4984             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4985             if ( !it7.next().getName().equals( "A" ) ) {
4986                 return false;
4987             }
4988             if ( it.hasNext() ) {
4989                 return false;
4990             }
4991         }
4992         catch ( final Exception e ) {
4993             e.printStackTrace( System.out );
4994             return false;
4995         }
4996         return true;
4997     }
4998
4999     private static boolean testMafft( final String path ) {
5000         try {
5001             final List<String> opts = new ArrayList<String>();
5002             opts.add( "--maxiterate" );
5003             opts.add( "1000" );
5004             opts.add( "--localpair" );
5005             opts.add( "--quiet" );
5006             Msa msa = null;
5007             final MsaInferrer mafft = Mafft.createInstance( path );
5008             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5009             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5010                 return false;
5011             }
5012             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5013                 return false;
5014             }
5015         }
5016         catch ( final Exception e ) {
5017             e.printStackTrace( System.out );
5018             return false;
5019         }
5020         return true;
5021     }
5022
5023     private static boolean testMidpointrooting() {
5024         try {
5025             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5026             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5027             PhylogenyMethods.midpointRoot( t0 );
5028             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5029                 return false;
5030             }
5031             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5032                 return false;
5033             }
5034             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5035                            1 ) ) {
5036                 return false;
5037             }
5038             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",
5039                                                  new NHXParser() )[ 0 ];
5040             if ( !t1.isRooted() ) {
5041                 return false;
5042             }
5043             PhylogenyMethods.midpointRoot( t1 );
5044             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5045                 return false;
5046             }
5047             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5048                 return false;
5049             }
5050             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5051                 return false;
5052             }
5053             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5054                 return false;
5055             }
5056             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5057                 return false;
5058             }
5059             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5060                 return false;
5061             }
5062             t1.reRoot( t1.getNode( "A" ) );
5063             PhylogenyMethods.midpointRoot( t1 );
5064             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5065                 return false;
5066             }
5067             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5068                 return false;
5069             }
5070             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5071                 return false;
5072             }
5073             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5074                 return false;
5075             }
5076             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5077                 System.exit( -1 );
5078                 return false;
5079             }
5080             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5081                 return false;
5082             }
5083         }
5084         catch ( final Exception e ) {
5085             e.printStackTrace( System.out );
5086             return false;
5087         }
5088         return true;
5089     }
5090
5091     private static boolean testMsaQualityMethod() {
5092         try {
5093             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5094             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5095             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5096             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5097             final List<Sequence> l = new ArrayList<Sequence>();
5098             l.add( s0 );
5099             l.add( s1 );
5100             l.add( s2 );
5101             l.add( s3 );
5102             final Msa msa = BasicMsa.createInstance( l );
5103             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5104                 return false;
5105             }
5106             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5107                 return false;
5108             }
5109             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5110                 return false;
5111             }
5112             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5113                 return false;
5114             }
5115         }
5116         catch ( final Exception e ) {
5117             e.printStackTrace( System.out );
5118             return false;
5119         }
5120         return true;
5121     }
5122
5123     private static boolean testNextNodeWithCollapsing() {
5124         try {
5125             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5126             PhylogenyNode n;
5127             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5128             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5129             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5130             t0.getNode( "cd" ).setCollapse( true );
5131             t0.getNode( "cde" ).setCollapse( true );
5132             n = t0.getFirstExternalNode();
5133             while ( n != null ) {
5134                 ext.add( n );
5135                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5136             }
5137             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5138                 return false;
5139             }
5140             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5141                 return false;
5142             }
5143             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5144                 return false;
5145             }
5146             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5147                 return false;
5148             }
5149             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5150                 return false;
5151             }
5152             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5153                 return false;
5154             }
5155             ext.clear();
5156             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5157             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5158             t1.getNode( "ab" ).setCollapse( true );
5159             t1.getNode( "cd" ).setCollapse( true );
5160             t1.getNode( "cde" ).setCollapse( true );
5161             n = t1.getNode( "ab" );
5162             ext = new ArrayList<PhylogenyNode>();
5163             while ( n != null ) {
5164                 ext.add( n );
5165                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5166             }
5167             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5168                 return false;
5169             }
5170             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5171                 return false;
5172             }
5173             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5174                 return false;
5175             }
5176             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5177                 return false;
5178             }
5179             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5180                 return false;
5181             }
5182             //
5183             //
5184             ext.clear();
5185             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5186             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5187             t2.getNode( "ab" ).setCollapse( true );
5188             t2.getNode( "cd" ).setCollapse( true );
5189             t2.getNode( "cde" ).setCollapse( true );
5190             t2.getNode( "c" ).setCollapse( true );
5191             t2.getNode( "d" ).setCollapse( true );
5192             t2.getNode( "e" ).setCollapse( true );
5193             t2.getNode( "gh" ).setCollapse( true );
5194             n = t2.getNode( "ab" );
5195             ext = new ArrayList<PhylogenyNode>();
5196             while ( n != null ) {
5197                 ext.add( n );
5198                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5199             }
5200             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5201                 return false;
5202             }
5203             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5204                 return false;
5205             }
5206             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5207                 return false;
5208             }
5209             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5210                 return false;
5211             }
5212             //
5213             //
5214             ext.clear();
5215             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5216             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5217             t3.getNode( "ab" ).setCollapse( true );
5218             t3.getNode( "cd" ).setCollapse( true );
5219             t3.getNode( "cde" ).setCollapse( true );
5220             t3.getNode( "c" ).setCollapse( true );
5221             t3.getNode( "d" ).setCollapse( true );
5222             t3.getNode( "e" ).setCollapse( true );
5223             t3.getNode( "gh" ).setCollapse( true );
5224             t3.getNode( "fgh" ).setCollapse( true );
5225             n = t3.getNode( "ab" );
5226             ext = new ArrayList<PhylogenyNode>();
5227             while ( n != null ) {
5228                 ext.add( n );
5229                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5230             }
5231             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5232                 return false;
5233             }
5234             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5235                 return false;
5236             }
5237             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5238                 return false;
5239             }
5240             //
5241             //
5242             ext.clear();
5243             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5244             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5245             t4.getNode( "ab" ).setCollapse( true );
5246             t4.getNode( "cd" ).setCollapse( true );
5247             t4.getNode( "cde" ).setCollapse( true );
5248             t4.getNode( "c" ).setCollapse( true );
5249             t4.getNode( "d" ).setCollapse( true );
5250             t4.getNode( "e" ).setCollapse( true );
5251             t4.getNode( "gh" ).setCollapse( true );
5252             t4.getNode( "fgh" ).setCollapse( true );
5253             t4.getNode( "abcdefgh" ).setCollapse( true );
5254             n = t4.getNode( "abcdefgh" );
5255             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5256                 return false;
5257             }
5258             //
5259             //
5260             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5261             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5262             ext.clear();
5263             n = t5.getFirstExternalNode();
5264             while ( n != null ) {
5265                 ext.add( n );
5266                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5267             }
5268             if ( ext.size() != 8 ) {
5269                 return false;
5270             }
5271             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5272                 return false;
5273             }
5274             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5275                 return false;
5276             }
5277             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5278                 return false;
5279             }
5280             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5281                 return false;
5282             }
5283             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5284                 return false;
5285             }
5286             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5287                 return false;
5288             }
5289             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5290                 return false;
5291             }
5292             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5293                 return false;
5294             }
5295             //
5296             //
5297             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5298             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5299             ext.clear();
5300             t6.getNode( "ab" ).setCollapse( true );
5301             n = t6.getNode( "ab" );
5302             while ( n != null ) {
5303                 ext.add( n );
5304                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5305             }
5306             if ( ext.size() != 7 ) {
5307                 return false;
5308             }
5309             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5310                 return false;
5311             }
5312             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5313                 return false;
5314             }
5315             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5316                 return false;
5317             }
5318             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5319                 return false;
5320             }
5321             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5322                 return false;
5323             }
5324             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5325                 return false;
5326             }
5327             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5328                 return false;
5329             }
5330             //
5331             //
5332             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5333             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5334             ext.clear();
5335             t7.getNode( "cd" ).setCollapse( true );
5336             n = t7.getNode( "a" );
5337             while ( n != null ) {
5338                 ext.add( n );
5339                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5340             }
5341             if ( ext.size() != 7 ) {
5342                 return false;
5343             }
5344             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5345                 return false;
5346             }
5347             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5348                 return false;
5349             }
5350             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5351                 return false;
5352             }
5353             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5354                 return false;
5355             }
5356             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5357                 return false;
5358             }
5359             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5360                 return false;
5361             }
5362             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5363                 return false;
5364             }
5365             //
5366             //
5367             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5368             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5369             ext.clear();
5370             t8.getNode( "cd" ).setCollapse( true );
5371             t8.getNode( "c" ).setCollapse( true );
5372             t8.getNode( "d" ).setCollapse( true );
5373             n = t8.getNode( "a" );
5374             while ( n != null ) {
5375                 ext.add( n );
5376                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5377             }
5378             if ( ext.size() != 7 ) {
5379                 return false;
5380             }
5381             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5382                 return false;
5383             }
5384             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5385                 return false;
5386             }
5387             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5388                 System.out.println( "2 fail" );
5389                 return false;
5390             }
5391             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5392                 return false;
5393             }
5394             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5395                 return false;
5396             }
5397             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5398                 return false;
5399             }
5400             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5401                 return false;
5402             }
5403             //
5404             //
5405             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5406             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
5407             ext.clear();
5408             t9.getNode( "gh" ).setCollapse( true );
5409             n = t9.getNode( "a" );
5410             while ( n != null ) {
5411                 ext.add( n );
5412                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5413             }
5414             if ( ext.size() != 7 ) {
5415                 return false;
5416             }
5417             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5418                 return false;
5419             }
5420             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5421                 return false;
5422             }
5423             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5424                 return false;
5425             }
5426             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5427                 return false;
5428             }
5429             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5430                 return false;
5431             }
5432             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5433                 return false;
5434             }
5435             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5436                 return false;
5437             }
5438             //
5439             //
5440             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5441             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
5442             ext.clear();
5443             t10.getNode( "gh" ).setCollapse( true );
5444             t10.getNode( "g" ).setCollapse( true );
5445             t10.getNode( "h" ).setCollapse( true );
5446             n = t10.getNode( "a" );
5447             while ( n != null ) {
5448                 ext.add( n );
5449                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5450             }
5451             if ( ext.size() != 7 ) {
5452                 return false;
5453             }
5454             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5455                 return false;
5456             }
5457             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5458                 return false;
5459             }
5460             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5461                 return false;
5462             }
5463             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5464                 return false;
5465             }
5466             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5467                 return false;
5468             }
5469             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5470                 return false;
5471             }
5472             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5473                 return false;
5474             }
5475             //
5476             //
5477             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5478             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
5479             ext.clear();
5480             t11.getNode( "gh" ).setCollapse( true );
5481             t11.getNode( "fgh" ).setCollapse( true );
5482             n = t11.getNode( "a" );
5483             while ( n != null ) {
5484                 ext.add( n );
5485                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5486             }
5487             if ( ext.size() != 6 ) {
5488                 return false;
5489             }
5490             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5491                 return false;
5492             }
5493             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5494                 return false;
5495             }
5496             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5497                 return false;
5498             }
5499             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5500                 return false;
5501             }
5502             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5503                 return false;
5504             }
5505             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5506                 return false;
5507             }
5508             //
5509             //
5510             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5511             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
5512             ext.clear();
5513             t12.getNode( "gh" ).setCollapse( true );
5514             t12.getNode( "fgh" ).setCollapse( true );
5515             t12.getNode( "g" ).setCollapse( true );
5516             t12.getNode( "h" ).setCollapse( true );
5517             t12.getNode( "f" ).setCollapse( true );
5518             n = t12.getNode( "a" );
5519             while ( n != null ) {
5520                 ext.add( n );
5521                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5522             }
5523             if ( ext.size() != 6 ) {
5524                 return false;
5525             }
5526             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5527                 return false;
5528             }
5529             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5530                 return false;
5531             }
5532             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5533                 return false;
5534             }
5535             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5536                 return false;
5537             }
5538             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5539                 return false;
5540             }
5541             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5542                 return false;
5543             }
5544             //
5545             //
5546             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5547             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
5548             ext.clear();
5549             t13.getNode( "ab" ).setCollapse( true );
5550             t13.getNode( "b" ).setCollapse( true );
5551             t13.getNode( "fgh" ).setCollapse( true );
5552             t13.getNode( "gh" ).setCollapse( true );
5553             n = t13.getNode( "ab" );
5554             while ( n != null ) {
5555                 ext.add( n );
5556                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5557             }
5558             if ( ext.size() != 5 ) {
5559                 return false;
5560             }
5561             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5562                 return false;
5563             }
5564             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5565                 return false;
5566             }
5567             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5568                 return false;
5569             }
5570             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5571                 return false;
5572             }
5573             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5574                 return false;
5575             }
5576             //
5577             //
5578             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
5579             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
5580             ext.clear();
5581             t14.getNode( "ab" ).setCollapse( true );
5582             t14.getNode( "a" ).setCollapse( true );
5583             t14.getNode( "fgh" ).setCollapse( true );
5584             t14.getNode( "gh" ).setCollapse( true );
5585             n = t14.getNode( "ab" );
5586             while ( n != null ) {
5587                 ext.add( n );
5588                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5589             }
5590             if ( ext.size() != 5 ) {
5591                 return false;
5592             }
5593             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5594                 return false;
5595             }
5596             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5597                 return false;
5598             }
5599             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5600                 return false;
5601             }
5602             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5603                 return false;
5604             }
5605             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5606                 return false;
5607             }
5608             //
5609             //
5610             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" );
5611             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
5612             ext.clear();
5613             t15.getNode( "ab" ).setCollapse( true );
5614             t15.getNode( "a" ).setCollapse( true );
5615             t15.getNode( "fgh" ).setCollapse( true );
5616             t15.getNode( "gh" ).setCollapse( true );
5617             n = t15.getNode( "ab" );
5618             while ( n != null ) {
5619                 ext.add( n );
5620                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5621             }
5622             if ( ext.size() != 6 ) {
5623                 return false;
5624             }
5625             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5626                 return false;
5627             }
5628             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5629                 return false;
5630             }
5631             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5632                 return false;
5633             }
5634             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5635                 return false;
5636             }
5637             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
5638                 return false;
5639             }
5640             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5641                 return false;
5642             }
5643             //
5644             //
5645             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" );
5646             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
5647             ext.clear();
5648             t16.getNode( "ab" ).setCollapse( true );
5649             t16.getNode( "a" ).setCollapse( true );
5650             t16.getNode( "fgh" ).setCollapse( true );
5651             t16.getNode( "gh" ).setCollapse( true );
5652             t16.getNode( "cd" ).setCollapse( true );
5653             t16.getNode( "cde" ).setCollapse( true );
5654             t16.getNode( "d" ).setCollapse( true );
5655             t16.getNode( "x" ).setCollapse( true );
5656             n = t16.getNode( "ab" );
5657             while ( n != null ) {
5658                 ext.add( n );
5659                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5660             }
5661             if ( ext.size() != 4 ) {
5662                 return false;
5663             }
5664             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5665                 return false;
5666             }
5667             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5668                 return false;
5669             }
5670             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
5671                 return false;
5672             }
5673             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
5674                 return false;
5675             }
5676         }
5677         catch ( final Exception e ) {
5678             e.printStackTrace( System.out );
5679             return false;
5680         }
5681         return true;
5682     }
5683
5684     private static boolean testNexusCharactersParsing() {
5685         try {
5686             final NexusCharactersParser parser = new NexusCharactersParser();
5687             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
5688             parser.parse();
5689             String[] labels = parser.getCharStateLabels();
5690             if ( labels.length != 7 ) {
5691                 return false;
5692             }
5693             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5694                 return false;
5695             }
5696             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5697                 return false;
5698             }
5699             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5700                 return false;
5701             }
5702             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5703                 return false;
5704             }
5705             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5706                 return false;
5707             }
5708             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5709                 return false;
5710             }
5711             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5712                 return false;
5713             }
5714             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5715             parser.parse();
5716             labels = parser.getCharStateLabels();
5717             if ( labels.length != 7 ) {
5718                 return false;
5719             }
5720             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5721                 return false;
5722             }
5723             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5724                 return false;
5725             }
5726             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5727                 return false;
5728             }
5729             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5730                 return false;
5731             }
5732             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5733                 return false;
5734             }
5735             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5736                 return false;
5737             }
5738             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5739                 return false;
5740             }
5741         }
5742         catch ( final Exception e ) {
5743             e.printStackTrace( System.out );
5744             return false;
5745         }
5746         return true;
5747     }
5748
5749     private static boolean testNexusMatrixParsing() {
5750         try {
5751             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
5752             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
5753             parser.parse();
5754             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
5755             if ( m.getNumberOfCharacters() != 9 ) {
5756                 return false;
5757             }
5758             if ( m.getNumberOfIdentifiers() != 5 ) {
5759                 return false;
5760             }
5761             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
5762                 return false;
5763             }
5764             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
5765                 return false;
5766             }
5767             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
5768                 return false;
5769             }
5770             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
5771                 return false;
5772             }
5773             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
5774                 return false;
5775             }
5776             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
5777                 return false;
5778             }
5779             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
5780                 return false;
5781             }
5782             //            if ( labels.length != 7 ) {
5783             //                return false;
5784             //            }
5785             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5786             //                return false;
5787             //            }
5788             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5789             //                return false;
5790             //            }
5791             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5792             //                return false;
5793             //            }
5794             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5795             //                return false;
5796             //            }
5797             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5798             //                return false;
5799             //            }
5800             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5801             //                return false;
5802             //            }
5803             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5804             //                return false;
5805             //            }
5806             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5807             //            parser.parse();
5808             //            labels = parser.getCharStateLabels();
5809             //            if ( labels.length != 7 ) {
5810             //                return false;
5811             //            }
5812             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5813             //                return false;
5814             //            }
5815             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5816             //                return false;
5817             //            }
5818             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5819             //                return false;
5820             //            }
5821             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5822             //                return false;
5823             //            }
5824             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5825             //                return false;
5826             //            }
5827             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5828             //                return false;
5829             //            }
5830             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5831             //                return false;
5832             //            }
5833         }
5834         catch ( final Exception e ) {
5835             e.printStackTrace( System.out );
5836             return false;
5837         }
5838         return true;
5839     }
5840
5841     private static boolean testNexusTreeParsing() {
5842         try {
5843             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5844             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5845             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
5846             if ( phylogenies.length != 1 ) {
5847                 return false;
5848             }
5849             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
5850                 return false;
5851             }
5852             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
5853                 return false;
5854             }
5855             phylogenies = null;
5856             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
5857             if ( phylogenies.length != 1 ) {
5858                 return false;
5859             }
5860             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
5861                 return false;
5862             }
5863             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
5864                 return false;
5865             }
5866             phylogenies = null;
5867             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
5868             if ( phylogenies.length != 1 ) {
5869                 return false;
5870             }
5871             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5872                 return false;
5873             }
5874             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
5875                 return false;
5876             }
5877             if ( phylogenies[ 0 ].isRooted() ) {
5878                 return false;
5879             }
5880             phylogenies = null;
5881             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
5882             if ( phylogenies.length != 18 ) {
5883                 return false;
5884             }
5885             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
5886                 return false;
5887             }
5888             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
5889                 return false;
5890             }
5891             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
5892                 return false;
5893             }
5894             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
5895                 return false;
5896             }
5897             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5898                 return false;
5899             }
5900             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
5901                 return false;
5902             }
5903             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
5904                 return false;
5905             }
5906             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
5907                 return false;
5908             }
5909             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
5910                 return false;
5911             }
5912             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
5913                 return false;
5914             }
5915             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
5916                 return false;
5917             }
5918             if ( phylogenies[ 8 ].isRooted() ) {
5919                 return false;
5920             }
5921             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
5922                 return false;
5923             }
5924             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
5925                 return false;
5926             }
5927             if ( !phylogenies[ 9 ].isRooted() ) {
5928                 return false;
5929             }
5930             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
5931                 return false;
5932             }
5933             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
5934                 return false;
5935             }
5936             if ( !phylogenies[ 10 ].isRooted() ) {
5937                 return false;
5938             }
5939             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
5940                 return false;
5941             }
5942             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
5943                 return false;
5944             }
5945             if ( phylogenies[ 11 ].isRooted() ) {
5946                 return false;
5947             }
5948             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
5949                 return false;
5950             }
5951             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
5952                 return false;
5953             }
5954             if ( !phylogenies[ 12 ].isRooted() ) {
5955                 return false;
5956             }
5957             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
5958                 return false;
5959             }
5960             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
5961                 return false;
5962             }
5963             if ( !phylogenies[ 13 ].isRooted() ) {
5964                 return false;
5965             }
5966             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
5967                 return false;
5968             }
5969             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
5970                 return false;
5971             }
5972             if ( !phylogenies[ 14 ].isRooted() ) {
5973                 return false;
5974             }
5975             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
5976                 return false;
5977             }
5978             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
5979                 return false;
5980             }
5981             if ( phylogenies[ 15 ].isRooted() ) {
5982                 return false;
5983             }
5984             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
5985                 return false;
5986             }
5987             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
5988                 return false;
5989             }
5990             if ( !phylogenies[ 16 ].isRooted() ) {
5991                 return false;
5992             }
5993             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
5994                 return false;
5995             }
5996             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
5997                 return false;
5998             }
5999             if ( phylogenies[ 17 ].isRooted() ) {
6000                 return false;
6001             }
6002             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6003                 return false;
6004             }
6005         }
6006         catch ( final Exception e ) {
6007             e.printStackTrace( System.out );
6008             return false;
6009         }
6010         return true;
6011     }
6012
6013     private static boolean testNexusTreeParsingIterating() {
6014         try {
6015             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6016             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6017             if ( !p.hasNext() ) {
6018                 return false;
6019             }
6020             Phylogeny phy = p.next();
6021             if ( phy == null ) {
6022                 return false;
6023             }
6024             if ( phy.getNumberOfExternalNodes() != 25 ) {
6025                 return false;
6026             }
6027             if ( !phy.getName().equals( "" ) ) {
6028                 return false;
6029             }
6030             if ( p.hasNext() ) {
6031                 return false;
6032             }
6033             phy = p.next();
6034             if ( phy != null ) {
6035                 return false;
6036             }
6037             //
6038             p.reset();
6039             if ( !p.hasNext() ) {
6040                 return false;
6041             }
6042             phy = p.next();
6043             if ( phy == null ) {
6044                 return false;
6045             }
6046             if ( phy.getNumberOfExternalNodes() != 25 ) {
6047                 return false;
6048             }
6049             if ( !phy.getName().equals( "" ) ) {
6050                 return false;
6051             }
6052             if ( p.hasNext() ) {
6053                 return false;
6054             }
6055             phy = p.next();
6056             if ( phy != null ) {
6057                 return false;
6058             }
6059             ////
6060             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6061             if ( !p.hasNext() ) {
6062                 return false;
6063             }
6064             phy = p.next();
6065             if ( phy == null ) {
6066                 return false;
6067             }
6068             if ( phy.getNumberOfExternalNodes() != 10 ) {
6069                 return false;
6070             }
6071             if ( !phy.getName().equals( "name" ) ) {
6072                 return false;
6073             }
6074             if ( p.hasNext() ) {
6075                 return false;
6076             }
6077             phy = p.next();
6078             if ( phy != null ) {
6079                 return false;
6080             }
6081             //
6082             p.reset();
6083             if ( !p.hasNext() ) {
6084                 return false;
6085             }
6086             phy = p.next();
6087             if ( phy == null ) {
6088                 return false;
6089             }
6090             if ( phy.getNumberOfExternalNodes() != 10 ) {
6091                 return false;
6092             }
6093             if ( !phy.getName().equals( "name" ) ) {
6094                 return false;
6095             }
6096             if ( p.hasNext() ) {
6097                 return false;
6098             }
6099             phy = p.next();
6100             if ( phy != null ) {
6101                 return false;
6102             }
6103             ////
6104             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6105             if ( !p.hasNext() ) {
6106                 return false;
6107             }
6108             phy = p.next();
6109             if ( phy == null ) {
6110                 return false;
6111             }
6112             if ( phy.getNumberOfExternalNodes() != 3 ) {
6113                 return false;
6114             }
6115             if ( !phy.getName().equals( "" ) ) {
6116                 return false;
6117             }
6118             if ( phy.isRooted() ) {
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.reset();
6130             if ( !p.hasNext() ) {
6131                 return false;
6132             }
6133             phy = p.next();
6134             if ( phy == null ) {
6135                 return false;
6136             }
6137             if ( phy.getNumberOfExternalNodes() != 3 ) {
6138                 return false;
6139             }
6140             if ( !phy.getName().equals( "" ) ) {
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.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6152             //            if ( phylogenies.length != 18 ) {
6153             //                return false;
6154             //            }
6155             //0
6156             if ( !p.hasNext() ) {
6157                 return false;
6158             }
6159             phy = p.next();
6160             if ( phy == null ) {
6161                 return false;
6162             }
6163             if ( phy.getNumberOfExternalNodes() != 10 ) {
6164                 return false;
6165             }
6166             if ( !phy.getName().equals( "tree 0" ) ) {
6167                 return false;
6168             }
6169             //1
6170             if ( !p.hasNext() ) {
6171                 return false;
6172             }
6173             phy = p.next();
6174             if ( phy == null ) {
6175                 return false;
6176             }
6177             if ( phy.getNumberOfExternalNodes() != 10 ) {
6178                 return false;
6179             }
6180             if ( !phy.getName().equals( "tree 1" ) ) {
6181                 return false;
6182             }
6183             //2
6184             if ( !p.hasNext() ) {
6185                 return false;
6186             }
6187             phy = p.next();
6188             if ( phy == null ) {
6189                 return false;
6190             }
6191             if ( phy.getNumberOfExternalNodes() != 3 ) {
6192                 return false;
6193             }
6194             if ( !phy.getName().equals( "" ) ) {
6195                 return false;
6196             }
6197             if ( phy.isRooted() ) {
6198                 return false;
6199             }
6200             //3
6201             if ( !p.hasNext() ) {
6202                 return false;
6203             }
6204             phy = p.next();
6205             if ( phy == null ) {
6206                 return false;
6207             }
6208             if ( phy.getNumberOfExternalNodes() != 4 ) {
6209                 return false;
6210             }
6211             if ( !phy.getName().equals( "" ) ) {
6212                 return false;
6213             }
6214             if ( !phy.isRooted() ) {
6215                 return false;
6216             }
6217             //4
6218             if ( !p.hasNext() ) {
6219                 return false;
6220             }
6221             phy = p.next();
6222             if ( phy == null ) {
6223                 return false;
6224             }
6225             if ( phy.getNumberOfExternalNodes() != 5 ) {
6226                 System.out.println( phy.getNumberOfExternalNodes() );
6227                 return false;
6228             }
6229             if ( !phy.getName().equals( "" ) ) {
6230                 return false;
6231             }
6232             if ( !phy.isRooted() ) {
6233                 return false;
6234             }
6235             //5
6236             if ( !p.hasNext() ) {
6237                 return false;
6238             }
6239             phy = p.next();
6240             if ( phy == null ) {
6241                 return false;
6242             }
6243             if ( phy.getNumberOfExternalNodes() != 3 ) {
6244                 return false;
6245             }
6246             if ( !phy.getName().equals( "" ) ) {
6247                 return false;
6248             }
6249             if ( phy.isRooted() ) {
6250                 return false;
6251             }
6252             //6
6253             if ( !p.hasNext() ) {
6254                 return false;
6255             }
6256             phy = p.next();
6257             if ( phy == null ) {
6258                 return false;
6259             }
6260             if ( phy.getNumberOfExternalNodes() != 2 ) {
6261                 return false;
6262             }
6263             if ( !phy.getName().equals( "" ) ) {
6264                 return false;
6265             }
6266             if ( !phy.isRooted() ) {
6267                 return false;
6268             }
6269             //7
6270             if ( !p.hasNext() ) {
6271                 return false;
6272             }
6273             phy = p.next();
6274             if ( phy.getNumberOfExternalNodes() != 3 ) {
6275                 return false;
6276             }
6277             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6278                 return false;
6279             }
6280             if ( !phy.isRooted() ) {
6281                 return false;
6282             }
6283             //8
6284             if ( !p.hasNext() ) {
6285                 return false;
6286             }
6287             phy = p.next();
6288             if ( phy.getNumberOfExternalNodes() != 3 ) {
6289                 return false;
6290             }
6291             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6292                 return false;
6293             }
6294             if ( !phy.getName().equals( "tree 8" ) ) {
6295                 return false;
6296             }
6297             //9
6298             if ( !p.hasNext() ) {
6299                 return false;
6300             }
6301             phy = p.next();
6302             if ( phy.getNumberOfExternalNodes() != 3 ) {
6303                 return false;
6304             }
6305             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6306                 return false;
6307             }
6308             if ( !phy.getName().equals( "tree 9" ) ) {
6309                 return false;
6310             }
6311             //10
6312             if ( !p.hasNext() ) {
6313                 return false;
6314             }
6315             phy = p.next();
6316             if ( phy.getNumberOfExternalNodes() != 3 ) {
6317                 return false;
6318             }
6319             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6320                 return false;
6321             }
6322             if ( !phy.getName().equals( "tree 10" ) ) {
6323                 return false;
6324             }
6325             if ( !phy.isRooted() ) {
6326                 return false;
6327             }
6328             //11
6329             if ( !p.hasNext() ) {
6330                 return false;
6331             }
6332             phy = p.next();
6333             if ( phy.getNumberOfExternalNodes() != 3 ) {
6334                 return false;
6335             }
6336             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6337                 return false;
6338             }
6339             if ( !phy.getName().equals( "tree 11" ) ) {
6340                 return false;
6341             }
6342             if ( phy.isRooted() ) {
6343                 return false;
6344             }
6345             //12
6346             if ( !p.hasNext() ) {
6347                 return false;
6348             }
6349             phy = p.next();
6350             if ( phy.getNumberOfExternalNodes() != 3 ) {
6351                 return false;
6352             }
6353             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6354                 return false;
6355             }
6356             if ( !phy.getName().equals( "tree 12" ) ) {
6357                 return false;
6358             }
6359             if ( !phy.isRooted() ) {
6360                 return false;
6361             }
6362             //13
6363             if ( !p.hasNext() ) {
6364                 return false;
6365             }
6366             phy = p.next();
6367             if ( phy.getNumberOfExternalNodes() != 3 ) {
6368                 return false;
6369             }
6370             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6371                 return false;
6372             }
6373             if ( !phy.getName().equals( "tree 13" ) ) {
6374                 return false;
6375             }
6376             if ( !phy.isRooted() ) {
6377                 return false;
6378             }
6379             //14
6380             if ( !p.hasNext() ) {
6381                 return false;
6382             }
6383             phy = p.next();
6384             if ( phy.getNumberOfExternalNodes() != 10 ) {
6385                 System.out.println( phy.getNumberOfExternalNodes() );
6386                 return false;
6387             }
6388             if ( !phy
6389                     .toNewHampshire()
6390                     .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;" ) ) {
6391                 System.out.println( phy.toNewHampshire() );
6392                 return false;
6393             }
6394             if ( !phy.getName().equals( "tree 14" ) ) {
6395                 return false;
6396             }
6397             if ( !phy.isRooted() ) {
6398                 return false;
6399             }
6400             //15
6401             if ( !p.hasNext() ) {
6402                 return false;
6403             }
6404             phy = p.next();
6405             if ( phy.getNumberOfExternalNodes() != 10 ) {
6406                 System.out.println( phy.getNumberOfExternalNodes() );
6407                 return false;
6408             }
6409             if ( !phy
6410                     .toNewHampshire()
6411                     .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;" ) ) {
6412                 System.out.println( phy.toNewHampshire() );
6413                 return false;
6414             }
6415             if ( !phy.getName().equals( "tree 15" ) ) {
6416                 return false;
6417             }
6418             if ( phy.isRooted() ) {
6419                 return false;
6420             }
6421             //16
6422             if ( !p.hasNext() ) {
6423                 return false;
6424             }
6425             phy = p.next();
6426             if ( phy.getNumberOfExternalNodes() != 10 ) {
6427                 System.out.println( phy.getNumberOfExternalNodes() );
6428                 return false;
6429             }
6430             if ( !phy
6431                     .toNewHampshire()
6432                     .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;" ) ) {
6433                 System.out.println( phy.toNewHampshire() );
6434                 return false;
6435             }
6436             if ( !phy.getName().equals( "tree 16" ) ) {
6437                 return false;
6438             }
6439             if ( !phy.isRooted() ) {
6440                 return false;
6441             }
6442             //17
6443             if ( !p.hasNext() ) {
6444                 return false;
6445             }
6446             phy = p.next();
6447             if ( phy.getNumberOfExternalNodes() != 10 ) {
6448                 System.out.println( phy.getNumberOfExternalNodes() );
6449                 return false;
6450             }
6451             if ( !phy
6452                     .toNewHampshire()
6453                     .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;" ) ) {
6454                 System.out.println( phy.toNewHampshire() );
6455                 return false;
6456             }
6457             if ( !phy.getName().equals( "tree 17" ) ) {
6458                 return false;
6459             }
6460             if ( phy.isRooted() ) {
6461                 return false;
6462             }
6463             //
6464             if ( p.hasNext() ) {
6465                 return false;
6466             }
6467             phy = p.next();
6468             if ( phy != null ) {
6469                 return false;
6470             }
6471             p.reset();
6472             //0
6473             if ( !p.hasNext() ) {
6474                 return false;
6475             }
6476             phy = p.next();
6477             if ( phy == null ) {
6478                 return false;
6479             }
6480             if ( phy.getNumberOfExternalNodes() != 10 ) {
6481                 return false;
6482             }
6483             if ( !phy.getName().equals( "tree 0" ) ) {
6484                 return false;
6485             }
6486             //1
6487             if ( !p.hasNext() ) {
6488                 return false;
6489             }
6490             phy = p.next();
6491             if ( phy == null ) {
6492                 return false;
6493             }
6494             if ( phy.getNumberOfExternalNodes() != 10 ) {
6495                 return false;
6496             }
6497             if ( !phy.getName().equals( "tree 1" ) ) {
6498                 return false;
6499             }
6500             //2
6501             if ( !p.hasNext() ) {
6502                 return false;
6503             }
6504             phy = p.next();
6505             if ( phy == null ) {
6506                 return false;
6507             }
6508             if ( phy.getNumberOfExternalNodes() != 3 ) {
6509                 return false;
6510             }
6511             if ( !phy.getName().equals( "" ) ) {
6512                 return false;
6513             }
6514             if ( phy.isRooted() ) {
6515                 return false;
6516             }
6517             //3
6518             if ( !p.hasNext() ) {
6519                 return false;
6520             }
6521             phy = p.next();
6522             if ( phy == null ) {
6523                 return false;
6524             }
6525             if ( phy.getNumberOfExternalNodes() != 4 ) {
6526                 return false;
6527             }
6528             if ( !phy.getName().equals( "" ) ) {
6529                 return false;
6530             }
6531             if ( !phy.isRooted() ) {
6532                 return false;
6533             }
6534             //4
6535             if ( !p.hasNext() ) {
6536                 return false;
6537             }
6538             phy = p.next();
6539             if ( phy == null ) {
6540                 return false;
6541             }
6542             if ( phy.getNumberOfExternalNodes() != 5 ) {
6543                 System.out.println( phy.getNumberOfExternalNodes() );
6544                 return false;
6545             }
6546             if ( !phy.getName().equals( "" ) ) {
6547                 return false;
6548             }
6549             if ( !phy.isRooted() ) {
6550                 return false;
6551             }
6552             //5
6553             if ( !p.hasNext() ) {
6554                 return false;
6555             }
6556             phy = p.next();
6557             if ( phy == null ) {
6558                 return false;
6559             }
6560             if ( phy.getNumberOfExternalNodes() != 3 ) {
6561                 return false;
6562             }
6563             if ( !phy.getName().equals( "" ) ) {
6564                 return false;
6565             }
6566             if ( phy.isRooted() ) {
6567                 return false;
6568             }
6569         }
6570         catch ( final Exception e ) {
6571             e.printStackTrace( System.out );
6572             return false;
6573         }
6574         return true;
6575     }
6576
6577     private static boolean testNexusTreeParsingTranslating() {
6578         try {
6579             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6580             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6581             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
6582             if ( phylogenies.length != 1 ) {
6583                 return false;
6584             }
6585             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6586                 return false;
6587             }
6588             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6589                 return false;
6590             }
6591             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6592                 return false;
6593             }
6594             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6595                 return false;
6596             }
6597             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6598                     .equals( "Aranaeus" ) ) {
6599                 return false;
6600             }
6601             phylogenies = null;
6602             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
6603             if ( phylogenies.length != 3 ) {
6604                 return false;
6605             }
6606             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6607                 return false;
6608             }
6609             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6610                 return false;
6611             }
6612             if ( phylogenies[ 0 ].isRooted() ) {
6613                 return false;
6614             }
6615             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6616                 return false;
6617             }
6618             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6619                 return false;
6620             }
6621             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6622                     .equals( "Aranaeus" ) ) {
6623                 return false;
6624             }
6625             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6626                 return false;
6627             }
6628             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6629                 return false;
6630             }
6631             if ( phylogenies[ 1 ].isRooted() ) {
6632                 return false;
6633             }
6634             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6635                 return false;
6636             }
6637             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6638                 return false;
6639             }
6640             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6641                     .equals( "Aranaeus" ) ) {
6642                 return false;
6643             }
6644             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6645                 return false;
6646             }
6647             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6648                 return false;
6649             }
6650             if ( !phylogenies[ 2 ].isRooted() ) {
6651                 return false;
6652             }
6653             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6654                 return false;
6655             }
6656             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6657                 return false;
6658             }
6659             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6660                     .equals( "Aranaeus" ) ) {
6661                 return false;
6662             }
6663             phylogenies = null;
6664             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
6665             if ( phylogenies.length != 3 ) {
6666                 return false;
6667             }
6668             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6669                 return false;
6670             }
6671             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6672                 return false;
6673             }
6674             if ( phylogenies[ 0 ].isRooted() ) {
6675                 return false;
6676             }
6677             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6678                 return false;
6679             }
6680             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6681                 return false;
6682             }
6683             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6684                     .equals( "Aranaeus" ) ) {
6685                 return false;
6686             }
6687             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6688                 return false;
6689             }
6690             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6691                 return false;
6692             }
6693             if ( phylogenies[ 1 ].isRooted() ) {
6694                 return false;
6695             }
6696             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6697                 return false;
6698             }
6699             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6700                 return false;
6701             }
6702             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6703                     .equals( "Aranaeus" ) ) {
6704                 return false;
6705             }
6706             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6707                 return false;
6708             }
6709             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6710                 return false;
6711             }
6712             if ( !phylogenies[ 2 ].isRooted() ) {
6713                 return false;
6714             }
6715             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6716                 return false;
6717             }
6718             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6719                 return false;
6720             }
6721             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6722                     .equals( "Aranaeus" ) ) {
6723                 return false;
6724             }
6725         }
6726         catch ( final Exception e ) {
6727             e.printStackTrace( System.out );
6728             return false;
6729         }
6730         return true;
6731     }
6732
6733     private static boolean testNHParsing() {
6734         try {
6735             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6736             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
6737             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
6738                 return false;
6739             }
6740             final NHXParser nhxp = new NHXParser();
6741             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
6742             nhxp.setReplaceUnderscores( true );
6743             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
6744             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
6745                 return false;
6746             }
6747             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
6748                 return false;
6749             }
6750             final Phylogeny p1b = factory
6751                     .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 ",
6752                              new NHXParser() )[ 0 ];
6753             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
6754                 return false;
6755             }
6756             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
6757                 return false;
6758             }
6759             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
6760             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
6761             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
6762             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
6763             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
6764             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
6765             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
6766             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
6767             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
6768             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
6769             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
6770                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
6771                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
6772                                                     new NHXParser() );
6773             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
6774                 return false;
6775             }
6776             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
6777                 return false;
6778             }
6779             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
6780                 return false;
6781             }
6782             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
6783                 return false;
6784             }
6785             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
6786             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
6787             final String p16_S = "((A,B),C)";
6788             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
6789             if ( p16.length != 1 ) {
6790                 return false;
6791             }
6792             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
6793                 return false;
6794             }
6795             final String p17_S = "(C,(A,B))";
6796             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
6797             if ( p17.length != 1 ) {
6798                 return false;
6799             }
6800             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
6801                 return false;
6802             }
6803             final String p18_S = "((A,B),(C,D))";
6804             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
6805             if ( p18.length != 1 ) {
6806                 return false;
6807             }
6808             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
6809                 return false;
6810             }
6811             final String p19_S = "(((A,B),C),D)";
6812             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
6813             if ( p19.length != 1 ) {
6814                 return false;
6815             }
6816             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
6817                 return false;
6818             }
6819             final String p20_S = "(A,(B,(C,D)))";
6820             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
6821             if ( p20.length != 1 ) {
6822                 return false;
6823             }
6824             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
6825                 return false;
6826             }
6827             final String p21_S = "(A,(B,(C,(D,E))))";
6828             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
6829             if ( p21.length != 1 ) {
6830                 return false;
6831             }
6832             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
6833                 return false;
6834             }
6835             final String p22_S = "((((A,B),C),D),E)";
6836             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
6837             if ( p22.length != 1 ) {
6838                 return false;
6839             }
6840             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
6841                 return false;
6842             }
6843             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6844             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
6845             if ( p23.length != 1 ) {
6846                 System.out.println( "xl=" + p23.length );
6847                 System.exit( -1 );
6848                 return false;
6849             }
6850             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
6851                 return false;
6852             }
6853             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6854             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
6855             if ( p24.length != 1 ) {
6856                 return false;
6857             }
6858             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
6859                 return false;
6860             }
6861             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6862             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6863             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
6864             if ( p241.length != 2 ) {
6865                 return false;
6866             }
6867             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
6868                 return false;
6869             }
6870             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
6871                 return false;
6872             }
6873             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
6874                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
6875                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
6876                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
6877                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
6878                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
6879                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
6880                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
6881             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
6882             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
6883                 return false;
6884             }
6885             final String p26_S = "(A,B)ab";
6886             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
6887             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
6888                 return false;
6889             }
6890             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6891             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
6892             if ( p27s.length != 1 ) {
6893                 System.out.println( "xxl=" + p27s.length );
6894                 System.exit( -1 );
6895                 return false;
6896             }
6897             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
6898                 System.out.println( p27s[ 0 ].toNewHampshireX() );
6899                 System.exit( -1 );
6900                 return false;
6901             }
6902             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
6903                                                     new NHXParser() );
6904             if ( p27.length != 1 ) {
6905                 System.out.println( "yl=" + p27.length );
6906                 System.exit( -1 );
6907                 return false;
6908             }
6909             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
6910                 System.out.println( p27[ 0 ].toNewHampshireX() );
6911                 System.exit( -1 );
6912                 return false;
6913             }
6914             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6915             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6916             final String p28_S3 = "(A,B)ab";
6917             final String p28_S4 = "((((A,B),C),D),;E;)";
6918             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
6919                                                     new NHXParser() );
6920             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
6921                 return false;
6922             }
6923             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
6924                 return false;
6925             }
6926             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
6927                 return false;
6928             }
6929             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
6930                 return false;
6931             }
6932             if ( p28.length != 4 ) {
6933                 return false;
6934             }
6935             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";
6936             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
6937             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
6938                 return false;
6939             }
6940             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";
6941             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
6942             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
6943                 return false;
6944             }
6945             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
6946             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
6947             if ( ( p32.length != 0 ) ) {
6948                 return false;
6949             }
6950             final String p33_S = "A";
6951             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
6952             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
6953                 return false;
6954             }
6955             final String p34_S = "B;";
6956             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
6957             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
6958                 return false;
6959             }
6960             final String p35_S = "B:0.2";
6961             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
6962             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
6963                 return false;
6964             }
6965             final String p36_S = "(A)";
6966             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
6967             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
6968                 return false;
6969             }
6970             final String p37_S = "((A))";
6971             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
6972             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
6973                 return false;
6974             }
6975             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
6976             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
6977             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
6978                 return false;
6979             }
6980             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
6981             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
6982             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
6983                 return false;
6984             }
6985             final String p40_S = "(A,B,C)";
6986             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
6987             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
6988                 return false;
6989             }
6990             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
6991             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
6992             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
6993                 return false;
6994             }
6995             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
6996             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
6997             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
6998                 return false;
6999             }
7000             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)";
7001             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7002             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7003                 return false;
7004             }
7005             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)))";
7006             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7007             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7008                 return false;
7009             }
7010             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7011             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7012             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7013                 return false;
7014             }
7015             final String p46_S = "";
7016             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7017             if ( p46.length != 0 ) {
7018                 return false;
7019             }
7020             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7021             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7022                 return false;
7023             }
7024             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7025             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7026                 return false;
7027             }
7028             final Phylogeny p49 = factory
7029                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7030                              new NHXParser() )[ 0 ];
7031             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7032                 return false;
7033             }
7034             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7035             if ( p50.getNode( "A" ) == null ) {
7036                 return false;
7037             }
7038             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7039                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7040                 return false;
7041             }
7042             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7043                 return false;
7044             }
7045             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7046                     .equals( "((A,B)88:2.0,C);" ) ) {
7047                 return false;
7048             }
7049             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7050             if ( p51.getNode( "A(A" ) == null ) {
7051                 return false;
7052             }
7053             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7054             if ( p52.getNode( "A(A" ) == null ) {
7055                 return false;
7056             }
7057             final Phylogeny p53 = factory
7058                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7059                              new NHXParser() )[ 0 ];
7060             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7061                 return false;
7062             }
7063             // 
7064             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7065             if ( p54.getNode( "A" ) == null ) {
7066                 return false;
7067             }
7068             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7069                     .equals( "((A,B)[88],C);" ) ) {
7070                 return false;
7071             }
7072         }
7073         catch ( final Exception e ) {
7074             e.printStackTrace( System.out );
7075             return false;
7076         }
7077         return true;
7078     }
7079
7080     private static boolean testNHParsingIter() {
7081         try {
7082             final String p0_str = "(A,B);";
7083             final NHXParser p = new NHXParser();
7084             p.setSource( p0_str );
7085             if ( !p.hasNext() ) {
7086                 return false;
7087             }
7088             final Phylogeny p0 = p.next();
7089             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7090                 System.out.println( p0.toNewHampshire() );
7091                 return false;
7092             }
7093             if ( p.hasNext() ) {
7094                 return false;
7095             }
7096             if ( p.next() != null ) {
7097                 return false;
7098             }
7099             //
7100             final String p00_str = "(A,B)root;";
7101             p.setSource( p00_str );
7102             final Phylogeny p00 = p.next();
7103             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7104                 System.out.println( p00.toNewHampshire() );
7105                 return false;
7106             }
7107             //
7108             final String p000_str = "A;";
7109             p.setSource( p000_str );
7110             final Phylogeny p000 = p.next();
7111             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7112                 System.out.println( p000.toNewHampshire() );
7113                 return false;
7114             }
7115             //
7116             final String p0000_str = "A";
7117             p.setSource( p0000_str );
7118             final Phylogeny p0000 = p.next();
7119             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7120                 System.out.println( p0000.toNewHampshire() );
7121                 return false;
7122             }
7123             //
7124             p.setSource( "(A)" );
7125             final Phylogeny p00000 = p.next();
7126             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7127                 System.out.println( p00000.toNewHampshire() );
7128                 return false;
7129             }
7130             //
7131             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7132             p.setSource( p1_str );
7133             if ( !p.hasNext() ) {
7134                 return false;
7135             }
7136             final Phylogeny p1_0 = p.next();
7137             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7138                 System.out.println( p1_0.toNewHampshire() );
7139                 return false;
7140             }
7141             if ( !p.hasNext() ) {
7142                 return false;
7143             }
7144             final Phylogeny p1_1 = p.next();
7145             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7146                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7147                 return false;
7148             }
7149             if ( !p.hasNext() ) {
7150                 return false;
7151             }
7152             final Phylogeny p1_2 = p.next();
7153             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7154                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7155                 return false;
7156             }
7157             if ( !p.hasNext() ) {
7158                 return false;
7159             }
7160             final Phylogeny p1_3 = p.next();
7161             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7162                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7163                 return false;
7164             }
7165             if ( p.hasNext() ) {
7166                 return false;
7167             }
7168             if ( p.next() != null ) {
7169                 return false;
7170             }
7171             //
7172             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7173             p.setSource( p2_str );
7174             if ( !p.hasNext() ) {
7175                 return false;
7176             }
7177             Phylogeny p2_0 = p.next();
7178             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7179                 System.out.println( p2_0.toNewHampshire() );
7180                 return false;
7181             }
7182             if ( !p.hasNext() ) {
7183                 return false;
7184             }
7185             Phylogeny p2_1 = p.next();
7186             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7187                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7188                 return false;
7189             }
7190             if ( !p.hasNext() ) {
7191                 return false;
7192             }
7193             Phylogeny p2_2 = p.next();
7194             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7195                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7196                 return false;
7197             }
7198             if ( !p.hasNext() ) {
7199                 return false;
7200             }
7201             Phylogeny p2_3 = p.next();
7202             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7203                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7204                 return false;
7205             }
7206             if ( !p.hasNext() ) {
7207                 return false;
7208             }
7209             Phylogeny p2_4 = p.next();
7210             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7211                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7212                 return false;
7213             }
7214             if ( p.hasNext() ) {
7215                 return false;
7216             }
7217             if ( p.next() != null ) {
7218                 return false;
7219             }
7220             ////
7221             p.reset();
7222             if ( !p.hasNext() ) {
7223                 return false;
7224             }
7225             p2_0 = p.next();
7226             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7227                 System.out.println( p2_0.toNewHampshire() );
7228                 return false;
7229             }
7230             if ( !p.hasNext() ) {
7231                 return false;
7232             }
7233             p2_1 = p.next();
7234             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7235                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7236                 return false;
7237             }
7238             if ( !p.hasNext() ) {
7239                 return false;
7240             }
7241             p2_2 = p.next();
7242             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7243                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7244                 return false;
7245             }
7246             if ( !p.hasNext() ) {
7247                 return false;
7248             }
7249             p2_3 = p.next();
7250             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7251                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7252                 return false;
7253             }
7254             if ( !p.hasNext() ) {
7255                 return false;
7256             }
7257             p2_4 = p.next();
7258             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7259                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7260                 return false;
7261             }
7262             if ( p.hasNext() ) {
7263                 return false;
7264             }
7265             if ( p.next() != null ) {
7266                 return false;
7267             }
7268             //
7269             final String p3_str = "((A,B),C)abc";
7270             p.setSource( p3_str );
7271             if ( !p.hasNext() ) {
7272                 return false;
7273             }
7274             final Phylogeny p3_0 = p.next();
7275             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7276                 return false;
7277             }
7278             if ( p.hasNext() ) {
7279                 return false;
7280             }
7281             if ( p.next() != null ) {
7282                 return false;
7283             }
7284             //
7285             final String p4_str = "((A,B)ab,C)abc";
7286             p.setSource( p4_str );
7287             if ( !p.hasNext() ) {
7288                 return false;
7289             }
7290             final Phylogeny p4_0 = p.next();
7291             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7292                 return false;
7293             }
7294             if ( p.hasNext() ) {
7295                 return false;
7296             }
7297             if ( p.next() != null ) {
7298                 return false;
7299             }
7300             //
7301             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7302             p.setSource( p5_str );
7303             if ( !p.hasNext() ) {
7304                 return false;
7305             }
7306             final Phylogeny p5_0 = p.next();
7307             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7308                 return false;
7309             }
7310             if ( p.hasNext() ) {
7311                 return false;
7312             }
7313             if ( p.next() != null ) {
7314                 return false;
7315             }
7316             //
7317             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7318             p.setSource( p6_str );
7319             if ( !p.hasNext() ) {
7320                 return false;
7321             }
7322             Phylogeny p6_0 = p.next();
7323             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7324                 return false;
7325             }
7326             if ( p.hasNext() ) {
7327                 return false;
7328             }
7329             if ( p.next() != null ) {
7330                 return false;
7331             }
7332             p.reset();
7333             if ( !p.hasNext() ) {
7334                 return false;
7335             }
7336             p6_0 = p.next();
7337             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7338                 return false;
7339             }
7340             if ( p.hasNext() ) {
7341                 return false;
7342             }
7343             if ( p.next() != null ) {
7344                 return false;
7345             }
7346             //
7347             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7348             p.setSource( p7_str );
7349             if ( !p.hasNext() ) {
7350                 return false;
7351             }
7352             Phylogeny p7_0 = p.next();
7353             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7354                 return false;
7355             }
7356             if ( p.hasNext() ) {
7357                 return false;
7358             }
7359             if ( p.next() != null ) {
7360                 return false;
7361             }
7362             p.reset();
7363             if ( !p.hasNext() ) {
7364                 return false;
7365             }
7366             p7_0 = p.next();
7367             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7368                 return false;
7369             }
7370             if ( p.hasNext() ) {
7371                 return false;
7372             }
7373             if ( p.next() != null ) {
7374                 return false;
7375             }
7376             //
7377             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7378             p.setSource( p8_str );
7379             if ( !p.hasNext() ) {
7380                 return false;
7381             }
7382             Phylogeny p8_0 = p.next();
7383             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7384                 return false;
7385             }
7386             if ( !p.hasNext() ) {
7387                 return false;
7388             }
7389             if ( !p.hasNext() ) {
7390                 return false;
7391             }
7392             Phylogeny p8_1 = p.next();
7393             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7394                 return false;
7395             }
7396             if ( p.hasNext() ) {
7397                 return false;
7398             }
7399             if ( p.next() != null ) {
7400                 return false;
7401             }
7402             p.reset();
7403             if ( !p.hasNext() ) {
7404                 return false;
7405             }
7406             p8_0 = p.next();
7407             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7408                 return false;
7409             }
7410             if ( !p.hasNext() ) {
7411                 return false;
7412             }
7413             p8_1 = p.next();
7414             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7415                 return false;
7416             }
7417             if ( p.hasNext() ) {
7418                 return false;
7419             }
7420             if ( p.next() != null ) {
7421                 return false;
7422             }
7423             p.reset();
7424             //
7425             p.setSource( "" );
7426             if ( p.hasNext() ) {
7427                 return false;
7428             }
7429             //
7430             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
7431             if ( !p.hasNext() ) {
7432                 return false;
7433             }
7434             Phylogeny p_27 = p.next();
7435             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7436                 System.out.println( p_27.toNewHampshireX() );
7437                 System.exit( -1 );
7438                 return false;
7439             }
7440             if ( p.hasNext() ) {
7441                 return false;
7442             }
7443             if ( p.next() != null ) {
7444                 return false;
7445             }
7446             p.reset();
7447             if ( !p.hasNext() ) {
7448                 return false;
7449             }
7450             p_27 = p.next();
7451             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7452                 System.out.println( p_27.toNewHampshireX() );
7453                 System.exit( -1 );
7454                 return false;
7455             }
7456             if ( p.hasNext() ) {
7457                 return false;
7458             }
7459             if ( p.next() != null ) {
7460                 return false;
7461             }
7462         }
7463         catch ( final Exception e ) {
7464             e.printStackTrace( System.out );
7465             return false;
7466         }
7467         return true;
7468     }
7469
7470     private static boolean testNHXconversion() {
7471         try {
7472             final PhylogenyNode n1 = new PhylogenyNode();
7473             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7474             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7475             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7476             final PhylogenyNode n5 = PhylogenyNode
7477                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
7478             final PhylogenyNode n6 = PhylogenyNode
7479                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
7480             if ( !n1.toNewHampshireX().equals( "" ) ) {
7481                 return false;
7482             }
7483             if ( !n2.toNewHampshireX().equals( "" ) ) {
7484                 return false;
7485             }
7486             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
7487                 return false;
7488             }
7489             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
7490                 return false;
7491             }
7492             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
7493                 return false;
7494             }
7495             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
7496                 System.out.println( n6.toNewHampshireX() );
7497                 return false;
7498             }
7499         }
7500         catch ( final Exception e ) {
7501             e.printStackTrace( System.out );
7502             return false;
7503         }
7504         return true;
7505     }
7506
7507     private static boolean testNHXNodeParsing() {
7508         try {
7509             final PhylogenyNode n1 = new PhylogenyNode();
7510             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7511             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7512             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7513             final PhylogenyNode n5 = PhylogenyNode
7514                     .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]" );
7515             if ( !n3.getName().equals( "n3" ) ) {
7516                 return false;
7517             }
7518             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7519                 return false;
7520             }
7521             if ( n3.isDuplication() ) {
7522                 return false;
7523             }
7524             if ( n3.isHasAssignedEvent() ) {
7525                 return false;
7526             }
7527             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
7528                 return false;
7529             }
7530             if ( !n4.getName().equals( "n4" ) ) {
7531                 return false;
7532             }
7533             if ( n4.getDistanceToParent() != 0.01 ) {
7534                 return false;
7535             }
7536             if ( !n5.getName().equals( "n5" ) ) {
7537                 return false;
7538             }
7539             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
7540                 return false;
7541             }
7542             if ( n5.getDistanceToParent() != 0.1 ) {
7543                 return false;
7544             }
7545             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
7546                 return false;
7547             }
7548             if ( !n5.isDuplication() ) {
7549                 return false;
7550             }
7551             if ( !n5.isHasAssignedEvent() ) {
7552                 return false;
7553             }
7554             final PhylogenyNode n8 = PhylogenyNode
7555                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
7556                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7557             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7558                 return false;
7559             }
7560             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
7561                 return false;
7562             }
7563             final PhylogenyNode n9 = PhylogenyNode
7564                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
7565                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7566             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
7567                 return false;
7568             }
7569             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
7570                 return false;
7571             }
7572             final PhylogenyNode n10 = PhylogenyNode
7573                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7574             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
7575                 return false;
7576             }
7577             final PhylogenyNode n20 = PhylogenyNode
7578                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7579             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7580                 return false;
7581             }
7582             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
7583                 return false;
7584             }
7585             final PhylogenyNode n20x = PhylogenyNode
7586                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7587             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
7588                 return false;
7589             }
7590             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
7591                 return false;
7592             }
7593             final PhylogenyNode n20xx = PhylogenyNode
7594                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7595             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
7596                 return false;
7597             }
7598             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
7599                 return false;
7600             }
7601             final PhylogenyNode n20xxx = PhylogenyNode
7602                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7603             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
7604                 return false;
7605             }
7606             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
7607                 return false;
7608             }
7609             final PhylogenyNode n20xxxx = PhylogenyNode
7610                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7611             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
7612                 return false;
7613             }
7614             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
7615                 return false;
7616             }
7617             final PhylogenyNode n21 = PhylogenyNode
7618                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7619             if ( !n21.getName().equals( "N21_PIG" ) ) {
7620                 return false;
7621             }
7622             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
7623                 return false;
7624             }
7625             final PhylogenyNode n21x = PhylogenyNode
7626                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7627             if ( !n21x.getName().equals( "n21_PIG" ) ) {
7628                 return false;
7629             }
7630             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
7631                 return false;
7632             }
7633             final PhylogenyNode n22 = PhylogenyNode
7634                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7635             if ( !n22.getName().equals( "n22/PIG" ) ) {
7636                 return false;
7637             }
7638             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
7639                 return false;
7640             }
7641             final PhylogenyNode n23 = PhylogenyNode
7642                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7643             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
7644                 return false;
7645             }
7646             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
7647                 return false;
7648             }
7649             final PhylogenyNode a = PhylogenyNode
7650                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7651             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7652                 return false;
7653             }
7654             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
7655                 return false;
7656             }
7657             final PhylogenyNode c1 = PhylogenyNode
7658                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
7659                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7660             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
7661                 return false;
7662             }
7663             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
7664                 return false;
7665             }
7666             final PhylogenyNode c2 = PhylogenyNode
7667                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
7668                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7669             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
7670                 return false;
7671             }
7672             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
7673                 return false;
7674             }
7675             final PhylogenyNode e3 = PhylogenyNode
7676                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7677             if ( !e3.getName().equals( "n10_RAT~" ) ) {
7678                 return false;
7679             }
7680             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
7681                 return false;
7682             }
7683             final PhylogenyNode n11 = PhylogenyNode
7684                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
7685                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7686             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
7687                 return false;
7688             }
7689             if ( n11.getDistanceToParent() != 0.4 ) {
7690                 return false;
7691             }
7692             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
7693                 return false;
7694             }
7695             final PhylogenyNode n12 = PhylogenyNode
7696                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
7697                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7698             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
7699                 return false;
7700             }
7701             if ( n12.getDistanceToParent() != 0.4 ) {
7702                 return false;
7703             }
7704             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
7705                 return false;
7706             }
7707             final PhylogenyNode o = PhylogenyNode
7708                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7709             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
7710                 return false;
7711             }
7712             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
7713                 return false;
7714             }
7715             if ( n1.getName().compareTo( "" ) != 0 ) {
7716                 return false;
7717             }
7718             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7719                 return false;
7720             }
7721             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7722                 return false;
7723             }
7724             if ( n2.getName().compareTo( "" ) != 0 ) {
7725                 return false;
7726             }
7727             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7728                 return false;
7729             }
7730             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7731                 return false;
7732             }
7733             final PhylogenyNode n00 = PhylogenyNode
7734                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
7735             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
7736                 return false;
7737             }
7738             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
7739                 return false;
7740             }
7741             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
7742             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
7743                 return false;
7744             }
7745             final PhylogenyNode n13 = PhylogenyNode
7746                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7747             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
7748                 return false;
7749             }
7750             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
7751                 return false;
7752             }
7753             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7754                 return false;
7755             }
7756             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7757                 return false;
7758             }
7759             final PhylogenyNode n14 = PhylogenyNode
7760                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7761             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
7762                 return false;
7763             }
7764             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
7765                 return false;
7766             }
7767             final PhylogenyNode n15 = PhylogenyNode
7768                     .createInstanceFromNhxString( "something_wicked[123]",
7769                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7770             if ( !n15.getName().equals( "something_wicked" ) ) {
7771                 return false;
7772             }
7773             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
7774                 return false;
7775             }
7776             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
7777                 return false;
7778             }
7779             final PhylogenyNode n16 = PhylogenyNode
7780                     .createInstanceFromNhxString( "something_wicked2[9]",
7781                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7782             if ( !n16.getName().equals( "something_wicked2" ) ) {
7783                 return false;
7784             }
7785             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
7786                 return false;
7787             }
7788             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
7789                 return false;
7790             }
7791             final PhylogenyNode n17 = PhylogenyNode
7792                     .createInstanceFromNhxString( "something_wicked3[a]",
7793                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7794             if ( !n17.getName().equals( "something_wicked3" ) ) {
7795                 return false;
7796             }
7797             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
7798                 return false;
7799             }
7800             final PhylogenyNode n18 = PhylogenyNode
7801                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7802             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
7803                 return false;
7804             }
7805             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
7806                 return false;
7807             }
7808             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
7809                 return false;
7810             }
7811             final PhylogenyNode n19 = PhylogenyNode
7812                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7813             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
7814                 return false;
7815             }
7816             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7817                 return false;
7818             }
7819             final PhylogenyNode n30 = PhylogenyNode
7820                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
7821                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7822             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
7823                 return false;
7824             }
7825             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7826                 return false;
7827             }
7828             final PhylogenyNode n31 = PhylogenyNode
7829                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
7830                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7831             if ( n31.getNodeData().isHasTaxonomy() ) {
7832                 return false;
7833             }
7834             final PhylogenyNode n32 = PhylogenyNode
7835                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7836             if ( n32.getNodeData().isHasTaxonomy() ) {
7837                 return false;
7838             }
7839             final PhylogenyNode n40 = PhylogenyNode
7840                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7841             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7842                 return false;
7843             }
7844             final PhylogenyNode n41 = PhylogenyNode
7845                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7846             if ( n41.getNodeData().isHasTaxonomy() ) {
7847                 return false;
7848             }
7849             final PhylogenyNode n42 = PhylogenyNode
7850                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7851             if ( n42.getNodeData().isHasTaxonomy() ) {
7852                 return false;
7853             }
7854             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
7855                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
7856             if ( n43.getNodeData().isHasTaxonomy() ) {
7857                 return false;
7858             }
7859             final PhylogenyNode n44 = PhylogenyNode
7860                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7861             if ( n44.getNodeData().isHasTaxonomy() ) {
7862                 return false;
7863             }
7864         }
7865         catch ( final Exception e ) {
7866             e.printStackTrace( System.out );
7867             return false;
7868         }
7869         return true;
7870     }
7871
7872     private static boolean testNHXParsing() {
7873         try {
7874             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7875             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
7876             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
7877                 return false;
7878             }
7879             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]";
7880             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
7881             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7882                 return false;
7883             }
7884             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]";
7885             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
7886             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
7887                 return false;
7888             }
7889             final Phylogeny[] p3 = factory
7890                     .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]",
7891                              new NHXParser() );
7892             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7893                 return false;
7894             }
7895             final Phylogeny[] p4 = factory
7896                     .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(]",
7897                              new NHXParser() );
7898             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7899                 return false;
7900             }
7901             final Phylogeny[] p5 = factory
7902                     .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(((]",
7903                              new NHXParser() );
7904             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7905                 return false;
7906             }
7907             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)";
7908             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)";
7909             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
7910             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
7911                 return false;
7912             }
7913             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)))";
7914             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)))";
7915             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
7916             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
7917                 return false;
7918             }
7919             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])   ))[,,, ])))))))";
7920             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
7921             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
7922             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
7923                 return false;
7924             }
7925             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
7926             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
7927                 return false;
7928             }
7929             final Phylogeny p10 = factory
7930                     .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]",
7931                              new NHXParser() )[ 0 ];
7932             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
7933                 return false;
7934             }
7935         }
7936         catch ( final Exception e ) {
7937             e.printStackTrace( System.out );
7938             return false;
7939         }
7940         return true;
7941     }
7942
7943     private static boolean testNHXParsingMB() {
7944         try {
7945             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7946             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
7947                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7948                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
7949                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
7950                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
7951                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7952                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
7953                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
7954                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
7955             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
7956                 return false;
7957             }
7958             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
7959                 return false;
7960             }
7961             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
7962                            0.1100000000000000e+00 ) ) {
7963                 return false;
7964             }
7965             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
7966                 return false;
7967             }
7968             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
7969                 return false;
7970             }
7971             final Phylogeny p2 = factory
7972                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
7973                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7974                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
7975                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
7976                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
7977                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7978                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
7979                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
7980                                      + "7.369400000000000e-02}])",
7981                              new NHXParser() )[ 0 ];
7982             if ( p2.getNode( "1" ) == null ) {
7983                 return false;
7984             }
7985             if ( p2.getNode( "2" ) == null ) {
7986                 return false;
7987             }
7988         }
7989         catch ( final Exception e ) {
7990             e.printStackTrace( System.out );
7991             System.exit( -1 );
7992             return false;
7993         }
7994         return true;
7995     }
7996
7997     private static boolean testNHXParsingQuotes() {
7998         try {
7999             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8000             final NHXParser p = new NHXParser();
8001             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8002             if ( phylogenies_0.length != 5 ) {
8003                 return false;
8004             }
8005             final Phylogeny phy = phylogenies_0[ 4 ];
8006             if ( phy.getNumberOfExternalNodes() != 7 ) {
8007                 return false;
8008             }
8009             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8010                 return false;
8011             }
8012             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8013                 return false;
8014             }
8015             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8016                     .getScientificName().equals( "hsapiens" ) ) {
8017                 return false;
8018             }
8019             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8020                 return false;
8021             }
8022             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8023                 return false;
8024             }
8025             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8026                 return false;
8027             }
8028             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8029                 return false;
8030             }
8031             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8032                 return false;
8033             }
8034             final NHXParser p1p = new NHXParser();
8035             p1p.setIgnoreQuotes( true );
8036             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8037             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8038                 return false;
8039             }
8040             final NHXParser p2p = new NHXParser();
8041             p1p.setIgnoreQuotes( false );
8042             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8043             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8044                 return false;
8045             }
8046             final NHXParser p3p = new NHXParser();
8047             p3p.setIgnoreQuotes( false );
8048             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8049             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8050                 return false;
8051             }
8052             final NHXParser p4p = new NHXParser();
8053             p4p.setIgnoreQuotes( false );
8054             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8055             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8056                 return false;
8057             }
8058             final Phylogeny p10 = factory
8059                     .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]",
8060                              new NHXParser() )[ 0 ];
8061             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]";
8062             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8063                 return false;
8064             }
8065             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8066             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8067                 return false;
8068             }
8069             //
8070             final Phylogeny p12 = factory
8071                     .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]",
8072                              new NHXParser() )[ 0 ];
8073             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]";
8074             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8075                 return false;
8076             }
8077             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8078             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8079                 return false;
8080             }
8081             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;";
8082             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8083                 return false;
8084             }
8085             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8086             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8087                 return false;
8088             }
8089         }
8090         catch ( final Exception e ) {
8091             e.printStackTrace( System.out );
8092             return false;
8093         }
8094         return true;
8095     }
8096
8097     private static boolean testNodeRemoval() {
8098         try {
8099             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8100             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8101             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8102             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8103                 return false;
8104             }
8105             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8106             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8107             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8108                 return false;
8109             }
8110             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8111             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8112             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8113                 return false;
8114             }
8115         }
8116         catch ( final Exception e ) {
8117             e.printStackTrace( System.out );
8118             return false;
8119         }
8120         return true;
8121     }
8122
8123     private static boolean testPhylogenyBranch() {
8124         try {
8125             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8126             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8127             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8128             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8129             if ( !a1b1.equals( a1b1 ) ) {
8130                 return false;
8131             }
8132             if ( !a1b1.equals( b1a1 ) ) {
8133                 return false;
8134             }
8135             if ( !b1a1.equals( a1b1 ) ) {
8136                 return false;
8137             }
8138             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8139             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8140             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8141             if ( a1_b1.equals( b1_a1 ) ) {
8142                 return false;
8143             }
8144             if ( a1_b1.equals( a1_b1_ ) ) {
8145                 return false;
8146             }
8147             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8148             if ( !a1_b1.equals( b1_a1_ ) ) {
8149                 return false;
8150             }
8151             if ( a1_b1_.equals( b1_a1_ ) ) {
8152                 return false;
8153             }
8154             if ( !a1_b1_.equals( b1_a1 ) ) {
8155                 return false;
8156             }
8157         }
8158         catch ( final Exception e ) {
8159             e.printStackTrace( System.out );
8160             return false;
8161         }
8162         return true;
8163     }
8164
8165     private static boolean testPhyloXMLparsingOfDistributionElement() {
8166         try {
8167             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8168             PhyloXmlParser xml_parser = null;
8169             try {
8170                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8171             }
8172             catch ( final Exception e ) {
8173                 // Do nothing -- means were not running from jar.
8174             }
8175             if ( xml_parser == null ) {
8176                 xml_parser = new PhyloXmlParser();
8177                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8178                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8179                 }
8180                 else {
8181                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8182                 }
8183             }
8184             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8185                                                               xml_parser );
8186             if ( xml_parser.getErrorCount() > 0 ) {
8187                 System.out.println( xml_parser.getErrorMessages().toString() );
8188                 return false;
8189             }
8190             if ( phylogenies_0.length != 1 ) {
8191                 return false;
8192             }
8193             final Phylogeny t1 = phylogenies_0[ 0 ];
8194             PhylogenyNode n = null;
8195             Distribution d = null;
8196             n = t1.getNode( "root node" );
8197             if ( !n.getNodeData().isHasDistribution() ) {
8198                 return false;
8199             }
8200             if ( n.getNodeData().getDistributions().size() != 1 ) {
8201                 return false;
8202             }
8203             d = n.getNodeData().getDistribution();
8204             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8205                 return false;
8206             }
8207             if ( d.getPoints().size() != 1 ) {
8208                 return false;
8209             }
8210             if ( d.getPolygons() != null ) {
8211                 return false;
8212             }
8213             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8214                 return false;
8215             }
8216             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8217                 return false;
8218             }
8219             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8220                 return false;
8221             }
8222             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8223                 return false;
8224             }
8225             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8226                 return false;
8227             }
8228             n = t1.getNode( "node a" );
8229             if ( !n.getNodeData().isHasDistribution() ) {
8230                 return false;
8231             }
8232             if ( n.getNodeData().getDistributions().size() != 2 ) {
8233                 return false;
8234             }
8235             d = n.getNodeData().getDistribution( 1 );
8236             if ( !d.getDesc().equals( "San Diego" ) ) {
8237                 return false;
8238             }
8239             if ( d.getPoints().size() != 1 ) {
8240                 return false;
8241             }
8242             if ( d.getPolygons() != null ) {
8243                 return false;
8244             }
8245             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8246                 return false;
8247             }
8248             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8249                 return false;
8250             }
8251             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8252                 return false;
8253             }
8254             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8255                 return false;
8256             }
8257             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8258                 return false;
8259             }
8260             n = t1.getNode( "node bb" );
8261             if ( !n.getNodeData().isHasDistribution() ) {
8262                 return false;
8263             }
8264             if ( n.getNodeData().getDistributions().size() != 1 ) {
8265                 return false;
8266             }
8267             d = n.getNodeData().getDistribution( 0 );
8268             if ( d.getPoints().size() != 3 ) {
8269                 return false;
8270             }
8271             if ( d.getPolygons().size() != 2 ) {
8272                 return false;
8273             }
8274             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8275                 return false;
8276             }
8277             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8278                 return false;
8279             }
8280             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8281                 return false;
8282             }
8283             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8284                 return false;
8285             }
8286             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8287                 return false;
8288             }
8289             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8290                 return false;
8291             }
8292             Polygon p = d.getPolygons().get( 0 );
8293             if ( p.getPoints().size() != 3 ) {
8294                 return false;
8295             }
8296             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8297                 return false;
8298             }
8299             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8300                 return false;
8301             }
8302             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8303                 return false;
8304             }
8305             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8306                 return false;
8307             }
8308             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8309                 return false;
8310             }
8311             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8312                 return false;
8313             }
8314             p = d.getPolygons().get( 1 );
8315             if ( p.getPoints().size() != 3 ) {
8316                 return false;
8317             }
8318             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8319                 return false;
8320             }
8321             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8322                 return false;
8323             }
8324             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8325                 return false;
8326             }
8327             // Roundtrip:
8328             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
8329             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
8330             if ( rt.length != 1 ) {
8331                 return false;
8332             }
8333             final Phylogeny t1_rt = rt[ 0 ];
8334             n = t1_rt.getNode( "root node" );
8335             if ( !n.getNodeData().isHasDistribution() ) {
8336                 return false;
8337             }
8338             if ( n.getNodeData().getDistributions().size() != 1 ) {
8339                 return false;
8340             }
8341             d = n.getNodeData().getDistribution();
8342             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8343                 return false;
8344             }
8345             if ( d.getPoints().size() != 1 ) {
8346                 return false;
8347             }
8348             if ( d.getPolygons() != null ) {
8349                 return false;
8350             }
8351             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8352                 return false;
8353             }
8354             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8355                 return false;
8356             }
8357             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8358                 return false;
8359             }
8360             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8361                 return false;
8362             }
8363             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8364                 return false;
8365             }
8366             n = t1_rt.getNode( "node a" );
8367             if ( !n.getNodeData().isHasDistribution() ) {
8368                 return false;
8369             }
8370             if ( n.getNodeData().getDistributions().size() != 2 ) {
8371                 return false;
8372             }
8373             d = n.getNodeData().getDistribution( 1 );
8374             if ( !d.getDesc().equals( "San Diego" ) ) {
8375                 return false;
8376             }
8377             if ( d.getPoints().size() != 1 ) {
8378                 return false;
8379             }
8380             if ( d.getPolygons() != null ) {
8381                 return false;
8382             }
8383             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8384                 return false;
8385             }
8386             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8387                 return false;
8388             }
8389             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8390                 return false;
8391             }
8392             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8393                 return false;
8394             }
8395             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8396                 return false;
8397             }
8398             n = t1_rt.getNode( "node bb" );
8399             if ( !n.getNodeData().isHasDistribution() ) {
8400                 return false;
8401             }
8402             if ( n.getNodeData().getDistributions().size() != 1 ) {
8403                 return false;
8404             }
8405             d = n.getNodeData().getDistribution( 0 );
8406             if ( d.getPoints().size() != 3 ) {
8407                 return false;
8408             }
8409             if ( d.getPolygons().size() != 2 ) {
8410                 return false;
8411             }
8412             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8413                 return false;
8414             }
8415             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8416                 return false;
8417             }
8418             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8419                 return false;
8420             }
8421             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8422                 return false;
8423             }
8424             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8425                 return false;
8426             }
8427             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8428                 return false;
8429             }
8430             p = d.getPolygons().get( 0 );
8431             if ( p.getPoints().size() != 3 ) {
8432                 return false;
8433             }
8434             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8435                 return false;
8436             }
8437             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8438                 return false;
8439             }
8440             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8441                 return false;
8442             }
8443             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8444                 return false;
8445             }
8446             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8447                 return false;
8448             }
8449             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8450                 return false;
8451             }
8452             p = d.getPolygons().get( 1 );
8453             if ( p.getPoints().size() != 3 ) {
8454                 return false;
8455             }
8456             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8457                 return false;
8458             }
8459             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8460                 return false;
8461             }
8462             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8463                 return false;
8464             }
8465         }
8466         catch ( final Exception e ) {
8467             e.printStackTrace( System.out );
8468             return false;
8469         }
8470         return true;
8471     }
8472
8473     private static boolean testPostOrderIterator() {
8474         try {
8475             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8476             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8477             PhylogenyNodeIterator it0;
8478             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
8479                 it0.next();
8480             }
8481             for( it0.reset(); it0.hasNext(); ) {
8482                 it0.next();
8483             }
8484             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8485             final PhylogenyNodeIterator it = t1.iteratorPostorder();
8486             if ( !it.next().getName().equals( "A" ) ) {
8487                 return false;
8488             }
8489             if ( !it.next().getName().equals( "B" ) ) {
8490                 return false;
8491             }
8492             if ( !it.next().getName().equals( "ab" ) ) {
8493                 return false;
8494             }
8495             if ( !it.next().getName().equals( "C" ) ) {
8496                 return false;
8497             }
8498             if ( !it.next().getName().equals( "D" ) ) {
8499                 return false;
8500             }
8501             if ( !it.next().getName().equals( "cd" ) ) {
8502                 return false;
8503             }
8504             if ( !it.next().getName().equals( "abcd" ) ) {
8505                 return false;
8506             }
8507             if ( !it.next().getName().equals( "E" ) ) {
8508                 return false;
8509             }
8510             if ( !it.next().getName().equals( "F" ) ) {
8511                 return false;
8512             }
8513             if ( !it.next().getName().equals( "ef" ) ) {
8514                 return false;
8515             }
8516             if ( !it.next().getName().equals( "G" ) ) {
8517                 return false;
8518             }
8519             if ( !it.next().getName().equals( "H" ) ) {
8520                 return false;
8521             }
8522             if ( !it.next().getName().equals( "gh" ) ) {
8523                 return false;
8524             }
8525             if ( !it.next().getName().equals( "efgh" ) ) {
8526                 return false;
8527             }
8528             if ( !it.next().getName().equals( "r" ) ) {
8529                 return false;
8530             }
8531             if ( it.hasNext() ) {
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 testPreOrderIterator() {
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.iteratorPreorder(); it0.hasNext(); ) {
8548                 it0.next();
8549             }
8550             for( it0.reset(); it0.hasNext(); ) {
8551                 it0.next();
8552             }
8553             PhylogenyNodeIterator it = t0.iteratorPreorder();
8554             if ( !it.next().getName().equals( "r" ) ) {
8555                 return false;
8556             }
8557             if ( !it.next().getName().equals( "ab" ) ) {
8558                 return false;
8559             }
8560             if ( !it.next().getName().equals( "A" ) ) {
8561                 return false;
8562             }
8563             if ( !it.next().getName().equals( "B" ) ) {
8564                 return false;
8565             }
8566             if ( !it.next().getName().equals( "cd" ) ) {
8567                 return false;
8568             }
8569             if ( !it.next().getName().equals( "C" ) ) {
8570                 return false;
8571             }
8572             if ( !it.next().getName().equals( "D" ) ) {
8573                 return false;
8574             }
8575             if ( it.hasNext() ) {
8576                 return false;
8577             }
8578             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8579             it = t1.iteratorPreorder();
8580             if ( !it.next().getName().equals( "r" ) ) {
8581                 return false;
8582             }
8583             if ( !it.next().getName().equals( "abcd" ) ) {
8584                 return false;
8585             }
8586             if ( !it.next().getName().equals( "ab" ) ) {
8587                 return false;
8588             }
8589             if ( !it.next().getName().equals( "A" ) ) {
8590                 return false;
8591             }
8592             if ( !it.next().getName().equals( "B" ) ) {
8593                 return false;
8594             }
8595             if ( !it.next().getName().equals( "cd" ) ) {
8596                 return false;
8597             }
8598             if ( !it.next().getName().equals( "C" ) ) {
8599                 return false;
8600             }
8601             if ( !it.next().getName().equals( "D" ) ) {
8602                 return false;
8603             }
8604             if ( !it.next().getName().equals( "efgh" ) ) {
8605                 return false;
8606             }
8607             if ( !it.next().getName().equals( "ef" ) ) {
8608                 return false;
8609             }
8610             if ( !it.next().getName().equals( "E" ) ) {
8611                 return false;
8612             }
8613             if ( !it.next().getName().equals( "F" ) ) {
8614                 return false;
8615             }
8616             if ( !it.next().getName().equals( "gh" ) ) {
8617                 return false;
8618             }
8619             if ( !it.next().getName().equals( "G" ) ) {
8620                 return false;
8621             }
8622             if ( !it.next().getName().equals( "H" ) ) {
8623                 return false;
8624             }
8625             if ( it.hasNext() ) {
8626                 return false;
8627             }
8628         }
8629         catch ( final Exception e ) {
8630             e.printStackTrace( System.out );
8631             return false;
8632         }
8633         return true;
8634     }
8635
8636     private static boolean testPropertiesMap() {
8637         try {
8638             final PropertiesMap pm = new PropertiesMap();
8639             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8640             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8641             final Property p2 = new Property( "something:else",
8642                                               "?",
8643                                               "improbable:research",
8644                                               "xsd:decimal",
8645                                               AppliesTo.NODE );
8646             pm.addProperty( p0 );
8647             pm.addProperty( p1 );
8648             pm.addProperty( p2 );
8649             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
8650                 return false;
8651             }
8652             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
8653                 return false;
8654             }
8655             if ( pm.getProperties().size() != 3 ) {
8656                 return false;
8657             }
8658             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
8659                 return false;
8660             }
8661             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8662                 return false;
8663             }
8664             if ( pm.getProperties().size() != 3 ) {
8665                 return false;
8666             }
8667             pm.removeProperty( "dimensions:diameter" );
8668             if ( pm.getProperties().size() != 2 ) {
8669                 return false;
8670             }
8671             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
8672                 return false;
8673             }
8674             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8675                 return false;
8676             }
8677         }
8678         catch ( final Exception e ) {
8679             e.printStackTrace( System.out );
8680             return false;
8681         }
8682         return true;
8683     }
8684
8685     private static boolean testProteinId() {
8686         try {
8687             final ProteinId id1 = new ProteinId( "a" );
8688             final ProteinId id2 = new ProteinId( "a" );
8689             final ProteinId id3 = new ProteinId( "A" );
8690             final ProteinId id4 = new ProteinId( "b" );
8691             if ( !id1.equals( id1 ) ) {
8692                 return false;
8693             }
8694             if ( id1.getId().equals( "x" ) ) {
8695                 return false;
8696             }
8697             if ( id1.getId().equals( null ) ) {
8698                 return false;
8699             }
8700             if ( !id1.equals( id2 ) ) {
8701                 return false;
8702             }
8703             if ( id1.equals( id3 ) ) {
8704                 return false;
8705             }
8706             if ( id1.hashCode() != id1.hashCode() ) {
8707                 return false;
8708             }
8709             if ( id1.hashCode() != id2.hashCode() ) {
8710                 return false;
8711             }
8712             if ( id1.hashCode() == id3.hashCode() ) {
8713                 return false;
8714             }
8715             if ( id1.compareTo( id1 ) != 0 ) {
8716                 return false;
8717             }
8718             if ( id1.compareTo( id2 ) != 0 ) {
8719                 return false;
8720             }
8721             if ( id1.compareTo( id3 ) != 0 ) {
8722                 return false;
8723             }
8724             if ( id1.compareTo( id4 ) >= 0 ) {
8725                 return false;
8726             }
8727             if ( id4.compareTo( id1 ) <= 0 ) {
8728                 return false;
8729             }
8730             if ( !id4.getId().equals( "b" ) ) {
8731                 return false;
8732             }
8733             final ProteinId id5 = new ProteinId( " C " );
8734             if ( !id5.getId().equals( "C" ) ) {
8735                 return false;
8736             }
8737             if ( id5.equals( id1 ) ) {
8738                 return false;
8739             }
8740         }
8741         catch ( final Exception e ) {
8742             e.printStackTrace( System.out );
8743             return false;
8744         }
8745         return true;
8746     }
8747
8748     private static boolean testReIdMethods() {
8749         try {
8750             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8751             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
8752             final long count = PhylogenyNode.getNodeCount();
8753             p.levelOrderReID();
8754             if ( p.getNode( "r" ).getId() != count ) {
8755                 return false;
8756             }
8757             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
8758                 return false;
8759             }
8760             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
8761                 return false;
8762             }
8763             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
8764                 return false;
8765             }
8766             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
8767                 return false;
8768             }
8769             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
8770                 return false;
8771             }
8772             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
8773                 return false;
8774             }
8775             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
8776                 return false;
8777             }
8778             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
8779                 return false;
8780             }
8781             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
8782                 return false;
8783             }
8784             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
8785                 return false;
8786             }
8787             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
8788                 return false;
8789             }
8790             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
8791                 return false;
8792             }
8793             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
8794                 return false;
8795             }
8796             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
8797                 return false;
8798             }
8799         }
8800         catch ( final Exception e ) {
8801             e.printStackTrace( System.out );
8802             return false;
8803         }
8804         return true;
8805     }
8806
8807     private static boolean testRerooting() {
8808         try {
8809             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8810             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",
8811                                                  new NHXParser() )[ 0 ];
8812             if ( !t1.isRooted() ) {
8813                 return false;
8814             }
8815             t1.reRoot( t1.getNode( "D" ) );
8816             t1.reRoot( t1.getNode( "CD" ) );
8817             t1.reRoot( t1.getNode( "A" ) );
8818             t1.reRoot( t1.getNode( "B" ) );
8819             t1.reRoot( t1.getNode( "AB" ) );
8820             t1.reRoot( t1.getNode( "D" ) );
8821             t1.reRoot( t1.getNode( "C" ) );
8822             t1.reRoot( t1.getNode( "CD" ) );
8823             t1.reRoot( t1.getNode( "A" ) );
8824             t1.reRoot( t1.getNode( "B" ) );
8825             t1.reRoot( t1.getNode( "AB" ) );
8826             t1.reRoot( t1.getNode( "D" ) );
8827             t1.reRoot( t1.getNode( "D" ) );
8828             t1.reRoot( t1.getNode( "C" ) );
8829             t1.reRoot( t1.getNode( "A" ) );
8830             t1.reRoot( t1.getNode( "B" ) );
8831             t1.reRoot( t1.getNode( "AB" ) );
8832             t1.reRoot( t1.getNode( "C" ) );
8833             t1.reRoot( t1.getNode( "D" ) );
8834             t1.reRoot( t1.getNode( "CD" ) );
8835             t1.reRoot( t1.getNode( "D" ) );
8836             t1.reRoot( t1.getNode( "A" ) );
8837             t1.reRoot( t1.getNode( "B" ) );
8838             t1.reRoot( t1.getNode( "AB" ) );
8839             t1.reRoot( t1.getNode( "C" ) );
8840             t1.reRoot( t1.getNode( "D" ) );
8841             t1.reRoot( t1.getNode( "CD" ) );
8842             t1.reRoot( t1.getNode( "D" ) );
8843             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
8844                 return false;
8845             }
8846             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
8847                 return false;
8848             }
8849             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
8850                 return false;
8851             }
8852             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
8853                 return false;
8854             }
8855             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
8856                 return false;
8857             }
8858             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
8859                 return false;
8860             }
8861             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",
8862                                                  new NHXParser() )[ 0 ];
8863             t2.reRoot( t2.getNode( "A" ) );
8864             t2.reRoot( t2.getNode( "D" ) );
8865             t2.reRoot( t2.getNode( "ABC" ) );
8866             t2.reRoot( t2.getNode( "A" ) );
8867             t2.reRoot( t2.getNode( "B" ) );
8868             t2.reRoot( t2.getNode( "D" ) );
8869             t2.reRoot( t2.getNode( "C" ) );
8870             t2.reRoot( t2.getNode( "ABC" ) );
8871             t2.reRoot( t2.getNode( "A" ) );
8872             t2.reRoot( t2.getNode( "B" ) );
8873             t2.reRoot( t2.getNode( "AB" ) );
8874             t2.reRoot( t2.getNode( "AB" ) );
8875             t2.reRoot( t2.getNode( "D" ) );
8876             t2.reRoot( t2.getNode( "C" ) );
8877             t2.reRoot( t2.getNode( "B" ) );
8878             t2.reRoot( t2.getNode( "AB" ) );
8879             t2.reRoot( t2.getNode( "D" ) );
8880             t2.reRoot( t2.getNode( "D" ) );
8881             t2.reRoot( t2.getNode( "ABC" ) );
8882             t2.reRoot( t2.getNode( "A" ) );
8883             t2.reRoot( t2.getNode( "B" ) );
8884             t2.reRoot( t2.getNode( "AB" ) );
8885             t2.reRoot( t2.getNode( "D" ) );
8886             t2.reRoot( t2.getNode( "C" ) );
8887             t2.reRoot( t2.getNode( "ABC" ) );
8888             t2.reRoot( t2.getNode( "A" ) );
8889             t2.reRoot( t2.getNode( "B" ) );
8890             t2.reRoot( t2.getNode( "AB" ) );
8891             t2.reRoot( t2.getNode( "D" ) );
8892             t2.reRoot( t2.getNode( "D" ) );
8893             t2.reRoot( t2.getNode( "C" ) );
8894             t2.reRoot( t2.getNode( "A" ) );
8895             t2.reRoot( t2.getNode( "B" ) );
8896             t2.reRoot( t2.getNode( "AB" ) );
8897             t2.reRoot( t2.getNode( "C" ) );
8898             t2.reRoot( t2.getNode( "D" ) );
8899             t2.reRoot( t2.getNode( "ABC" ) );
8900             t2.reRoot( t2.getNode( "D" ) );
8901             t2.reRoot( t2.getNode( "A" ) );
8902             t2.reRoot( t2.getNode( "B" ) );
8903             t2.reRoot( t2.getNode( "AB" ) );
8904             t2.reRoot( t2.getNode( "C" ) );
8905             t2.reRoot( t2.getNode( "D" ) );
8906             t2.reRoot( t2.getNode( "ABC" ) );
8907             t2.reRoot( t2.getNode( "D" ) );
8908             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8909                 return false;
8910             }
8911             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8912                 return false;
8913             }
8914             t2.reRoot( t2.getNode( "ABC" ) );
8915             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8916                 return false;
8917             }
8918             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8919                 return false;
8920             }
8921             t2.reRoot( t2.getNode( "AB" ) );
8922             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8923                 return false;
8924             }
8925             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8926                 return false;
8927             }
8928             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8929                 return false;
8930             }
8931             t2.reRoot( t2.getNode( "AB" ) );
8932             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8933                 return false;
8934             }
8935             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8936                 return false;
8937             }
8938             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8939                 return false;
8940             }
8941             t2.reRoot( t2.getNode( "D" ) );
8942             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8943                 return false;
8944             }
8945             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8946                 return false;
8947             }
8948             t2.reRoot( t2.getNode( "ABC" ) );
8949             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8950                 return false;
8951             }
8952             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8953                 return false;
8954             }
8955             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
8956                                                  new NHXParser() )[ 0 ];
8957             t3.reRoot( t3.getNode( "B" ) );
8958             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8959                 return false;
8960             }
8961             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8962                 return false;
8963             }
8964             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
8965                 return false;
8966             }
8967             t3.reRoot( t3.getNode( "B" ) );
8968             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8969                 return false;
8970             }
8971             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8972                 return false;
8973             }
8974             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
8975                 return false;
8976             }
8977             t3.reRoot( t3.getRoot() );
8978             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8979                 return false;
8980             }
8981             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8982                 return false;
8983             }
8984             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
8985                 return false;
8986             }
8987         }
8988         catch ( final Exception e ) {
8989             e.printStackTrace( System.out );
8990             return false;
8991         }
8992         return true;
8993     }
8994
8995     private static boolean testSDIse() {
8996         try {
8997             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8998             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
8999             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9000             gene1.setRooted( true );
9001             species1.setRooted( true );
9002             final SDI sdi = new SDI( gene1, species1 );
9003             if ( !gene1.getRoot().isDuplication() ) {
9004                 return false;
9005             }
9006             final Phylogeny species2 = factory
9007                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9008                              new NHXParser() )[ 0 ];
9009             final Phylogeny gene2 = factory
9010                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9011                              new NHXParser() )[ 0 ];
9012             species2.setRooted( true );
9013             gene2.setRooted( true );
9014             final SDI sdi2 = new SDI( gene2, species2 );
9015             if ( sdi2.getDuplicationsSum() != 0 ) {
9016                 return false;
9017             }
9018             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9019                 return false;
9020             }
9021             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9022                 return false;
9023             }
9024             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9025                 return false;
9026             }
9027             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9028                 return false;
9029             }
9030             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9031                 return false;
9032             }
9033             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9034                 return false;
9035             }
9036             final Phylogeny species3 = factory
9037                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9038                              new NHXParser() )[ 0 ];
9039             final Phylogeny gene3 = factory
9040                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9041                              new NHXParser() )[ 0 ];
9042             species3.setRooted( true );
9043             gene3.setRooted( true );
9044             final SDI sdi3 = new SDI( gene3, species3 );
9045             if ( sdi3.getDuplicationsSum() != 1 ) {
9046                 return false;
9047             }
9048             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9049                 return false;
9050             }
9051             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9052                 return false;
9053             }
9054             final Phylogeny species4 = factory
9055                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9056                              new NHXParser() )[ 0 ];
9057             final Phylogeny gene4 = factory
9058                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9059                              new NHXParser() )[ 0 ];
9060             species4.setRooted( true );
9061             gene4.setRooted( true );
9062             final SDI sdi4 = new SDI( gene4, species4 );
9063             if ( sdi4.getDuplicationsSum() != 1 ) {
9064                 return false;
9065             }
9066             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9067                 return false;
9068             }
9069             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9070                 return false;
9071             }
9072             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9073                 return false;
9074             }
9075             if ( species4.getNumberOfExternalNodes() != 6 ) {
9076                 return false;
9077             }
9078             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9079                 return false;
9080             }
9081             final Phylogeny species5 = factory
9082                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9083                              new NHXParser() )[ 0 ];
9084             final Phylogeny gene5 = factory
9085                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9086                              new NHXParser() )[ 0 ];
9087             species5.setRooted( true );
9088             gene5.setRooted( true );
9089             final SDI sdi5 = new SDI( gene5, species5 );
9090             if ( sdi5.getDuplicationsSum() != 2 ) {
9091                 return false;
9092             }
9093             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9094                 return false;
9095             }
9096             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9097                 return false;
9098             }
9099             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9100                 return false;
9101             }
9102             if ( species5.getNumberOfExternalNodes() != 6 ) {
9103                 return false;
9104             }
9105             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9106                 return false;
9107             }
9108             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9109             // Conjecture for Comparing Molecular Phylogenies"
9110             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9111             final Phylogeny species6 = factory
9112                     .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,"
9113                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9114                              new NHXParser() )[ 0 ];
9115             final Phylogeny gene6 = factory
9116                     .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,"
9117                                      + "((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,"
9118                                      + "(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;",
9119                              new NHXParser() )[ 0 ];
9120             species6.setRooted( true );
9121             gene6.setRooted( true );
9122             final SDI sdi6 = new SDI( gene6, species6 );
9123             if ( sdi6.getDuplicationsSum() != 3 ) {
9124                 return false;
9125             }
9126             if ( !gene6.getNode( "r" ).isDuplication() ) {
9127                 return false;
9128             }
9129             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9130                 return false;
9131             }
9132             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9133                 return false;
9134             }
9135             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9136                 return false;
9137             }
9138             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9139                 return false;
9140             }
9141             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9142                 return false;
9143             }
9144             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9145                 return false;
9146             }
9147             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9148                 return false;
9149             }
9150             sdi6.computeMappingCostL();
9151             if ( sdi6.computeMappingCostL() != 17 ) {
9152                 return false;
9153             }
9154             if ( species6.getNumberOfExternalNodes() != 9 ) {
9155                 return false;
9156             }
9157             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9158                 return false;
9159             }
9160             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9161                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9162                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9163                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9164                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9165             species7.setRooted( true );
9166             final Phylogeny gene7_1 = Test
9167                     .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])" );
9168             gene7_1.setRooted( true );
9169             final SDI sdi7 = new SDI( gene7_1, species7 );
9170             if ( sdi7.getDuplicationsSum() != 0 ) {
9171                 return false;
9172             }
9173             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9174                 return false;
9175             }
9176             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9177                 return false;
9178             }
9179             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9180                 return false;
9181             }
9182             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9183                 return false;
9184             }
9185             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9186                 return false;
9187             }
9188             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9189                 return false;
9190             }
9191             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9192                 return false;
9193             }
9194             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9195                 return false;
9196             }
9197             final Phylogeny gene7_2 = Test
9198                     .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])" );
9199             gene7_2.setRooted( true );
9200             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9201             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9202                 return false;
9203             }
9204             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9205                 return false;
9206             }
9207             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9208                 return false;
9209             }
9210             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9211                 return false;
9212             }
9213             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9214                 return false;
9215             }
9216             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9217                 return false;
9218             }
9219             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9220                 return false;
9221             }
9222             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9223                 return false;
9224             }
9225             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9226                 return false;
9227             }
9228             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9229                 return false;
9230             }
9231         }
9232         catch ( final Exception e ) {
9233             return false;
9234         }
9235         return true;
9236     }
9237
9238     private static boolean testSDIunrooted() {
9239         try {
9240             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9241             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9242             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9243             final Iterator<PhylogenyBranch> iter = l.iterator();
9244             PhylogenyBranch br = iter.next();
9245             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9246                 return false;
9247             }
9248             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9249                 return false;
9250             }
9251             br = iter.next();
9252             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9253                 return false;
9254             }
9255             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9256                 return false;
9257             }
9258             br = iter.next();
9259             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9260                 return false;
9261             }
9262             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9263                 return false;
9264             }
9265             br = iter.next();
9266             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9267                 return false;
9268             }
9269             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9270                 return false;
9271             }
9272             br = iter.next();
9273             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9274                 return false;
9275             }
9276             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9277                 return false;
9278             }
9279             br = iter.next();
9280             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9281                 return false;
9282             }
9283             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9284                 return false;
9285             }
9286             br = iter.next();
9287             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9288                 return false;
9289             }
9290             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9291                 return false;
9292             }
9293             br = iter.next();
9294             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9295                 return false;
9296             }
9297             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9298                 return false;
9299             }
9300             br = iter.next();
9301             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9302                 return false;
9303             }
9304             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9305                 return false;
9306             }
9307             br = iter.next();
9308             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9309                 return false;
9310             }
9311             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9312                 return false;
9313             }
9314             br = iter.next();
9315             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9316                 return false;
9317             }
9318             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9319                 return false;
9320             }
9321             br = iter.next();
9322             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
9323                 return false;
9324             }
9325             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
9326                 return false;
9327             }
9328             br = iter.next();
9329             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9330                 return false;
9331             }
9332             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9333                 return false;
9334             }
9335             br = iter.next();
9336             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
9337                 return false;
9338             }
9339             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
9340                 return false;
9341             }
9342             br = iter.next();
9343             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
9344                 return false;
9345             }
9346             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
9347                 return false;
9348             }
9349             if ( iter.hasNext() ) {
9350                 return false;
9351             }
9352             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
9353             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
9354             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
9355             br = iter1.next();
9356             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9357                 return false;
9358             }
9359             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9360                 return false;
9361             }
9362             br = iter1.next();
9363             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9364                 return false;
9365             }
9366             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9367                 return false;
9368             }
9369             br = iter1.next();
9370             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9371                 return false;
9372             }
9373             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9374                 return false;
9375             }
9376             if ( iter1.hasNext() ) {
9377                 return false;
9378             }
9379             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
9380             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
9381             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
9382             br = iter2.next();
9383             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9384                 return false;
9385             }
9386             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9387                 return false;
9388             }
9389             br = iter2.next();
9390             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9391                 return false;
9392             }
9393             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9394                 return false;
9395             }
9396             br = iter2.next();
9397             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9398                 return false;
9399             }
9400             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9401                 return false;
9402             }
9403             if ( iter2.hasNext() ) {
9404                 return false;
9405             }
9406             final Phylogeny species0 = factory
9407                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9408                              new NHXParser() )[ 0 ];
9409             final Phylogeny gene1 = factory
9410                     .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])",
9411                              new NHXParser() )[ 0 ];
9412             species0.setRooted( true );
9413             gene1.setRooted( true );
9414             final SDIR sdi_unrooted = new SDIR();
9415             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
9416             if ( sdi_unrooted.getCount() != 1 ) {
9417                 return false;
9418             }
9419             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
9420                 return false;
9421             }
9422             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
9423                 return false;
9424             }
9425             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
9426                 return false;
9427             }
9428             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9429                 return false;
9430             }
9431             final Phylogeny gene2 = factory
9432                     .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])",
9433                              new NHXParser() )[ 0 ];
9434             gene2.setRooted( true );
9435             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
9436             if ( sdi_unrooted.getCount() != 1 ) {
9437                 return false;
9438             }
9439             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9440                 return false;
9441             }
9442             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9443                 return false;
9444             }
9445             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
9446                 return false;
9447             }
9448             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9449                 return false;
9450             }
9451             final Phylogeny species6 = factory
9452                     .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,"
9453                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9454                              new NHXParser() )[ 0 ];
9455             final Phylogeny gene6 = factory
9456                     .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],"
9457                                      + "(((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],"
9458                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9459                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9460                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9461                              new NHXParser() )[ 0 ];
9462             species6.setRooted( true );
9463             gene6.setRooted( true );
9464             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
9465             if ( sdi_unrooted.getCount() != 1 ) {
9466                 return false;
9467             }
9468             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9469                 return false;
9470             }
9471             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9472                 return false;
9473             }
9474             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9475                 return false;
9476             }
9477             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9478                 return false;
9479             }
9480             if ( !p6[ 0 ].getRoot().isDuplication() ) {
9481                 return false;
9482             }
9483             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9484                 return false;
9485             }
9486             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9487                 return false;
9488             }
9489             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
9490                 return false;
9491             }
9492             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9493                 return false;
9494             }
9495             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
9496                 return false;
9497             }
9498             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
9499                 return false;
9500             }
9501             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9502                 return false;
9503             }
9504             p6 = null;
9505             final Phylogeny species7 = factory
9506                     .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,"
9507                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9508                              new NHXParser() )[ 0 ];
9509             final Phylogeny gene7 = factory
9510                     .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],"
9511                                      + "(((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],"
9512                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9513                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9514                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9515                              new NHXParser() )[ 0 ];
9516             species7.setRooted( true );
9517             gene7.setRooted( true );
9518             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
9519             if ( sdi_unrooted.getCount() != 1 ) {
9520                 return false;
9521             }
9522             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9523                 return false;
9524             }
9525             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9526                 return false;
9527             }
9528             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9529                 return false;
9530             }
9531             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
9532                 return false;
9533             }
9534             if ( !p7[ 0 ].getRoot().isDuplication() ) {
9535                 return false;
9536             }
9537             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9538                 return false;
9539             }
9540             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9541                 return false;
9542             }
9543             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
9544                 return false;
9545             }
9546             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9547                 return false;
9548             }
9549             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
9550                 return false;
9551             }
9552             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
9553                 return false;
9554             }
9555             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9556                 return false;
9557             }
9558             p7 = null;
9559             final Phylogeny species8 = factory
9560                     .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,"
9561                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9562                              new NHXParser() )[ 0 ];
9563             final Phylogeny gene8 = factory
9564                     .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],"
9565                                      + "(((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],"
9566                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9567                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9568                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9569                              new NHXParser() )[ 0 ];
9570             species8.setRooted( true );
9571             gene8.setRooted( true );
9572             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
9573             if ( sdi_unrooted.getCount() != 1 ) {
9574                 return false;
9575             }
9576             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9577                 return false;
9578             }
9579             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9580                 return false;
9581             }
9582             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9583                 return false;
9584             }
9585             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9586                 return false;
9587             }
9588             if ( !p8[ 0 ].getRoot().isDuplication() ) {
9589                 return false;
9590             }
9591             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9592                 return false;
9593             }
9594             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9595                 return false;
9596             }
9597             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
9598                 return false;
9599             }
9600             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9601                 return false;
9602             }
9603             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
9604                 return false;
9605             }
9606             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
9607                 return false;
9608             }
9609             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9610                 return false;
9611             }
9612             p8 = null;
9613         }
9614         catch ( final Exception e ) {
9615             e.printStackTrace( System.out );
9616             return false;
9617         }
9618         return true;
9619     }
9620
9621     private static boolean testSequenceIdParsing() {
9622         try {
9623             Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
9624             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9625                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9626                 if ( id != null ) {
9627                     System.out.println( "value   =" + id.getValue() );
9628                     System.out.println( "provider=" + id.getProvider() );
9629                 }
9630                 return false;
9631             }
9632             //
9633             id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
9634             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9635                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9636                 if ( id != null ) {
9637                     System.out.println( "value   =" + id.getValue() );
9638                     System.out.println( "provider=" + id.getProvider() );
9639                 }
9640                 return false;
9641             }
9642             //
9643             id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
9644             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9645                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9646                 if ( id != null ) {
9647                     System.out.println( "value   =" + id.getValue() );
9648                     System.out.println( "provider=" + id.getProvider() );
9649                 }
9650                 return false;
9651             }
9652             // 
9653             id = SequenceIdParser.parse( "gb_AAA96518_1" );
9654             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9655                     || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
9656                 if ( id != null ) {
9657                     System.out.println( "value   =" + id.getValue() );
9658                     System.out.println( "provider=" + id.getProvider() );
9659                 }
9660                 return false;
9661             }
9662             // 
9663             id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
9664             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9665                     || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
9666                 if ( id != null ) {
9667                     System.out.println( "value   =" + id.getValue() );
9668                     System.out.println( "provider=" + id.getProvider() );
9669                 }
9670                 return false;
9671             }
9672             // 
9673             id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
9674             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9675                     || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
9676                 if ( id != null ) {
9677                     System.out.println( "value   =" + id.getValue() );
9678                     System.out.println( "provider=" + id.getProvider() );
9679                 }
9680                 return false;
9681             }
9682             // 
9683             id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
9684             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9685                     || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
9686                 if ( id != null ) {
9687                     System.out.println( "value   =" + id.getValue() );
9688                     System.out.println( "provider=" + id.getProvider() );
9689                 }
9690                 return false;
9691             }
9692             // 
9693             id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
9694             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9695                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
9696                 if ( id != null ) {
9697                     System.out.println( "value   =" + id.getValue() );
9698                     System.out.println( "provider=" + id.getProvider() );
9699                 }
9700                 return false;
9701             }
9702             // 
9703             id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
9704             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9705                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
9706                 if ( id != null ) {
9707                     System.out.println( "value   =" + id.getValue() );
9708                     System.out.println( "provider=" + id.getProvider() );
9709                 }
9710                 return false;
9711             }
9712             // 
9713             id = SequenceIdParser.parse( "P4A123" );
9714             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9715                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9716                 if ( id != null ) {
9717                     System.out.println( "value   =" + id.getValue() );
9718                     System.out.println( "provider=" + id.getProvider() );
9719                 }
9720                 return false;
9721             }
9722             // 
9723             id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
9724             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9725                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9726                 if ( id != null ) {
9727                     System.out.println( "value   =" + id.getValue() );
9728                     System.out.println( "provider=" + id.getProvider() );
9729                 }
9730                 return false;
9731             }
9732             // 
9733             id = SequenceIdParser.parse( "XP_12345" );
9734             if ( id != null ) {
9735                 System.out.println( "value   =" + id.getValue() );
9736                 System.out.println( "provider=" + id.getProvider() );
9737                 return false;
9738             }
9739             // lcl_91970_unknown_
9740         }
9741         catch ( final Exception e ) {
9742             e.printStackTrace( System.out );
9743             return false;
9744         }
9745         return true;
9746     }
9747
9748     private static boolean testSequenceWriter() {
9749         try {
9750             final String n = ForesterUtil.LINE_SEPARATOR;
9751             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9752                 return false;
9753             }
9754             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9755                 return false;
9756             }
9757             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9758                 return false;
9759             }
9760             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9761                 return false;
9762             }
9763             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9764                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9765                 return false;
9766             }
9767             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9768                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9769                 return false;
9770             }
9771         }
9772         catch ( final Exception e ) {
9773             e.printStackTrace();
9774             return false;
9775         }
9776         return true;
9777     }
9778
9779     private static boolean testSpecies() {
9780         try {
9781             final Species s1 = new BasicSpecies( "a" );
9782             final Species s2 = new BasicSpecies( "a" );
9783             final Species s3 = new BasicSpecies( "A" );
9784             final Species s4 = new BasicSpecies( "b" );
9785             if ( !s1.equals( s1 ) ) {
9786                 return false;
9787             }
9788             if ( s1.getSpeciesId().equals( "x" ) ) {
9789                 return false;
9790             }
9791             if ( s1.getSpeciesId().equals( null ) ) {
9792                 return false;
9793             }
9794             if ( !s1.equals( s2 ) ) {
9795                 return false;
9796             }
9797             if ( s1.equals( s3 ) ) {
9798                 return false;
9799             }
9800             if ( s1.hashCode() != s1.hashCode() ) {
9801                 return false;
9802             }
9803             if ( s1.hashCode() != s2.hashCode() ) {
9804                 return false;
9805             }
9806             if ( s1.hashCode() == s3.hashCode() ) {
9807                 return false;
9808             }
9809             if ( s1.compareTo( s1 ) != 0 ) {
9810                 return false;
9811             }
9812             if ( s1.compareTo( s2 ) != 0 ) {
9813                 return false;
9814             }
9815             if ( s1.compareTo( s3 ) != 0 ) {
9816                 return false;
9817             }
9818             if ( s1.compareTo( s4 ) >= 0 ) {
9819                 return false;
9820             }
9821             if ( s4.compareTo( s1 ) <= 0 ) {
9822                 return false;
9823             }
9824             if ( !s4.getSpeciesId().equals( "b" ) ) {
9825                 return false;
9826             }
9827             final Species s5 = new BasicSpecies( " C " );
9828             if ( !s5.getSpeciesId().equals( "C" ) ) {
9829                 return false;
9830             }
9831             if ( s5.equals( s1 ) ) {
9832                 return false;
9833             }
9834         }
9835         catch ( final Exception e ) {
9836             e.printStackTrace( System.out );
9837             return false;
9838         }
9839         return true;
9840     }
9841
9842     private static boolean testSplit() {
9843         try {
9844             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9845             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
9846             //Archaeopteryx.createApplication( p0 );
9847             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
9848             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9849             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9850             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9851             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9852             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9853             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9854             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9855             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
9856             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
9857             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
9858             // System.out.println( s0.toString() );
9859             //
9860             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
9861             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9863             if ( s0.match( query_nodes ) ) {
9864                 return false;
9865             }
9866             query_nodes = new HashSet<PhylogenyNode>();
9867             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9874             if ( !s0.match( query_nodes ) ) {
9875                 return false;
9876             }
9877             //
9878             query_nodes = new HashSet<PhylogenyNode>();
9879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9882             if ( !s0.match( query_nodes ) ) {
9883                 return false;
9884             }
9885             //
9886             query_nodes = new HashSet<PhylogenyNode>();
9887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9891             if ( !s0.match( query_nodes ) ) {
9892                 return false;
9893             }
9894             //
9895             query_nodes = new HashSet<PhylogenyNode>();
9896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9900             if ( !s0.match( query_nodes ) ) {
9901                 return false;
9902             }
9903             //
9904             query_nodes = new HashSet<PhylogenyNode>();
9905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9908             if ( !s0.match( query_nodes ) ) {
9909                 return false;
9910             }
9911             //
9912             query_nodes = new HashSet<PhylogenyNode>();
9913             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9915             if ( !s0.match( query_nodes ) ) {
9916                 return false;
9917             }
9918             //
9919             query_nodes = new HashSet<PhylogenyNode>();
9920             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9921             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9925             if ( !s0.match( query_nodes ) ) {
9926                 return false;
9927             }
9928             //
9929             query_nodes = new HashSet<PhylogenyNode>();
9930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9931             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9932             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9933             if ( !s0.match( query_nodes ) ) {
9934                 return false;
9935             }
9936             //
9937             query_nodes = new HashSet<PhylogenyNode>();
9938             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9940             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9941             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9942             if ( !s0.match( query_nodes ) ) {
9943                 return false;
9944             }
9945             //
9946             query_nodes = new HashSet<PhylogenyNode>();
9947             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9949             if ( s0.match( query_nodes ) ) {
9950                 return false;
9951             }
9952             //
9953             query_nodes = new HashSet<PhylogenyNode>();
9954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9958             if ( s0.match( query_nodes ) ) {
9959                 return false;
9960             }
9961             //
9962             query_nodes = new HashSet<PhylogenyNode>();
9963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9968             if ( s0.match( query_nodes ) ) {
9969                 return false;
9970             }
9971             //
9972             query_nodes = new HashSet<PhylogenyNode>();
9973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9974             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9976             if ( s0.match( query_nodes ) ) {
9977                 return false;
9978             }
9979             //
9980             query_nodes = new HashSet<PhylogenyNode>();
9981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9983             if ( s0.match( query_nodes ) ) {
9984                 return false;
9985             }
9986             //
9987             query_nodes = new HashSet<PhylogenyNode>();
9988             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9990             if ( s0.match( query_nodes ) ) {
9991                 return false;
9992             }
9993             //
9994             query_nodes = new HashSet<PhylogenyNode>();
9995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9996             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9997             if ( s0.match( query_nodes ) ) {
9998                 return false;
9999             }
10000             //
10001             query_nodes = new HashSet<PhylogenyNode>();
10002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10004             if ( s0.match( query_nodes ) ) {
10005                 return false;
10006             }
10007             //
10008             query_nodes = new HashSet<PhylogenyNode>();
10009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10011             if ( s0.match( query_nodes ) ) {
10012                 return false;
10013             }
10014             //
10015             query_nodes = new HashSet<PhylogenyNode>();
10016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "F" ) );
10025             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10026             if ( s0.match( query_nodes ) ) {
10027                 return false;
10028             }
10029             //
10030             query_nodes = new HashSet<PhylogenyNode>();
10031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10032             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10033             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10034             if ( s0.match( query_nodes ) ) {
10035                 return false;
10036             }
10037             //
10038             query_nodes = new HashSet<PhylogenyNode>();
10039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10041             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10042             if ( s0.match( query_nodes ) ) {
10043                 return false;
10044             }
10045             //
10046             query_nodes = new HashSet<PhylogenyNode>();
10047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10050             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10051             if ( s0.match( query_nodes ) ) {
10052                 return false;
10053             }
10054             /////////
10055             //            query_nodes = new HashSet<PhylogenyNode>();
10056             //            query_nodes.add( new PhylogenyNode( "X" ) );
10057             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10058             //            query_nodes.add( new PhylogenyNode( "A" ) );
10059             //            query_nodes.add( new PhylogenyNode( "B" ) );
10060             //            query_nodes.add( new PhylogenyNode( "C" ) );
10061             //            query_nodes.add( new PhylogenyNode( "D" ) );
10062             //            query_nodes.add( new PhylogenyNode( "E" ) );
10063             //            query_nodes.add( new PhylogenyNode( "F" ) );
10064             //            query_nodes.add( new PhylogenyNode( "G" ) );
10065             //            if ( !s0.match( query_nodes ) ) {
10066             //                return false;
10067             //            }
10068             //            query_nodes = new HashSet<PhylogenyNode>();
10069             //            query_nodes.add( new PhylogenyNode( "X" ) );
10070             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10071             //            query_nodes.add( new PhylogenyNode( "A" ) );
10072             //            query_nodes.add( new PhylogenyNode( "B" ) );
10073             //            query_nodes.add( new PhylogenyNode( "C" ) );
10074             //            if ( !s0.match( query_nodes ) ) {
10075             //                return false;
10076             //            }
10077             //            //
10078             //            query_nodes = new HashSet<PhylogenyNode>();
10079             //            query_nodes.add( new PhylogenyNode( "X" ) );
10080             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10081             //            query_nodes.add( new PhylogenyNode( "D" ) );
10082             //            query_nodes.add( new PhylogenyNode( "E" ) );
10083             //            query_nodes.add( new PhylogenyNode( "F" ) );
10084             //            query_nodes.add( new PhylogenyNode( "G" ) );
10085             //            if ( !s0.match( query_nodes ) ) {
10086             //                return false;
10087             //            }
10088             //            //
10089             //            query_nodes = new HashSet<PhylogenyNode>();
10090             //            query_nodes.add( new PhylogenyNode( "X" ) );
10091             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10092             //            query_nodes.add( new PhylogenyNode( "A" ) );
10093             //            query_nodes.add( new PhylogenyNode( "B" ) );
10094             //            query_nodes.add( new PhylogenyNode( "C" ) );
10095             //            query_nodes.add( new PhylogenyNode( "D" ) );
10096             //            if ( !s0.match( query_nodes ) ) {
10097             //                return false;
10098             //            }
10099             //            //
10100             //            query_nodes = new HashSet<PhylogenyNode>();
10101             //            query_nodes.add( new PhylogenyNode( "X" ) );
10102             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10103             //            query_nodes.add( new PhylogenyNode( "E" ) );
10104             //            query_nodes.add( new PhylogenyNode( "F" ) );
10105             //            query_nodes.add( new PhylogenyNode( "G" ) );
10106             //            if ( !s0.match( query_nodes ) ) {
10107             //                return false;
10108             //            }
10109             //            //
10110             //            query_nodes = new HashSet<PhylogenyNode>();
10111             //            query_nodes.add( new PhylogenyNode( "X" ) );
10112             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10113             //            query_nodes.add( new PhylogenyNode( "F" ) );
10114             //            query_nodes.add( new PhylogenyNode( "G" ) );
10115             //            if ( !s0.match( query_nodes ) ) {
10116             //                return false;
10117             //            }
10118             //
10119             query_nodes = new HashSet<PhylogenyNode>();
10120             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10121             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10122             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10123             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10124             if ( s0.match( query_nodes ) ) {
10125                 return false;
10126             }
10127             //
10128             query_nodes = new HashSet<PhylogenyNode>();
10129             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10130             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10131             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10133             if ( s0.match( query_nodes ) ) {
10134                 return false;
10135             }
10136             ///////////////////////////
10137             //
10138             query_nodes = new HashSet<PhylogenyNode>();
10139             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10143             if ( s0.match( query_nodes ) ) {
10144                 return false;
10145             }
10146             //
10147             query_nodes = new HashSet<PhylogenyNode>();
10148             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10149             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10150             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10151             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10152             if ( s0.match( query_nodes ) ) {
10153                 return false;
10154             }
10155             //
10156             query_nodes = new HashSet<PhylogenyNode>();
10157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10159             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10160             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10161             if ( s0.match( query_nodes ) ) {
10162                 return false;
10163             }
10164             //
10165             query_nodes = new HashSet<PhylogenyNode>();
10166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10167             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10168             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10169             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10170             if ( s0.match( query_nodes ) ) {
10171                 return false;
10172             }
10173             //
10174             query_nodes = new HashSet<PhylogenyNode>();
10175             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10176             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10177             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10178             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10179             if ( s0.match( query_nodes ) ) {
10180                 return false;
10181             }
10182             //
10183             query_nodes = new HashSet<PhylogenyNode>();
10184             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10185             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10186             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10187             if ( s0.match( query_nodes ) ) {
10188                 return false;
10189             }
10190             //
10191             query_nodes = new HashSet<PhylogenyNode>();
10192             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10193             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10194             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10195             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10196             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10197             if ( s0.match( query_nodes ) ) {
10198                 return false;
10199             }
10200             //
10201             query_nodes = new HashSet<PhylogenyNode>();
10202             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10203             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10204             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10205             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10206             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10207             if ( s0.match( query_nodes ) ) {
10208                 return false;
10209             }
10210             //
10211             query_nodes = new HashSet<PhylogenyNode>();
10212             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10213             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10214             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10215             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10216             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10217             if ( s0.match( query_nodes ) ) {
10218                 return false;
10219             }
10220             //
10221             query_nodes = new HashSet<PhylogenyNode>();
10222             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10223             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10224             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10225             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10226             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10227             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10228             if ( s0.match( query_nodes ) ) {
10229                 return false;
10230             }
10231         }
10232         catch ( final Exception e ) {
10233             e.printStackTrace();
10234             return false;
10235         }
10236         return true;
10237     }
10238
10239     private static boolean testSplitStrict() {
10240         try {
10241             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10242             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10243             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10244             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10245             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10246             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10247             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10248             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10249             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10250             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10251             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
10252             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10254             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10255             if ( s0.match( query_nodes ) ) {
10256                 return false;
10257             }
10258             query_nodes = new HashSet<PhylogenyNode>();
10259             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10260             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10261             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10262             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10263             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
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( "A" ) );
10272             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10273             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10274             if ( !s0.match( query_nodes ) ) {
10275                 return false;
10276             }
10277             //
10278             query_nodes = new HashSet<PhylogenyNode>();
10279             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10280             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10282             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10283             if ( !s0.match( query_nodes ) ) {
10284                 return false;
10285             }
10286             //
10287             query_nodes = new HashSet<PhylogenyNode>();
10288             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10289             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10292             if ( !s0.match( query_nodes ) ) {
10293                 return false;
10294             }
10295             //
10296             query_nodes = new HashSet<PhylogenyNode>();
10297             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10298             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10299             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10300             if ( !s0.match( query_nodes ) ) {
10301                 return false;
10302             }
10303             //
10304             query_nodes = new HashSet<PhylogenyNode>();
10305             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10306             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10307             if ( !s0.match( query_nodes ) ) {
10308                 return false;
10309             }
10310             //
10311             query_nodes = new HashSet<PhylogenyNode>();
10312             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10313             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10314             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10315             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10316             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10317             if ( !s0.match( query_nodes ) ) {
10318                 return false;
10319             }
10320             //
10321             query_nodes = new HashSet<PhylogenyNode>();
10322             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10323             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10324             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10325             if ( !s0.match( query_nodes ) ) {
10326                 return false;
10327             }
10328             //
10329             query_nodes = new HashSet<PhylogenyNode>();
10330             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10331             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10332             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10333             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10334             if ( !s0.match( query_nodes ) ) {
10335                 return false;
10336             }
10337             //
10338             query_nodes = new HashSet<PhylogenyNode>();
10339             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10340             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10341             if ( s0.match( query_nodes ) ) {
10342                 return false;
10343             }
10344             //
10345             query_nodes = new HashSet<PhylogenyNode>();
10346             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10347             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10348             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10349             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10350             if ( s0.match( query_nodes ) ) {
10351                 return false;
10352             }
10353             //
10354             query_nodes = new HashSet<PhylogenyNode>();
10355             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10356             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10357             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10358             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10360             if ( s0.match( query_nodes ) ) {
10361                 return false;
10362             }
10363             //
10364             query_nodes = new HashSet<PhylogenyNode>();
10365             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10366             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10367             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10368             if ( s0.match( query_nodes ) ) {
10369                 return false;
10370             }
10371             //
10372             query_nodes = new HashSet<PhylogenyNode>();
10373             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10374             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10375             if ( s0.match( query_nodes ) ) {
10376                 return false;
10377             }
10378             //
10379             query_nodes = new HashSet<PhylogenyNode>();
10380             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10381             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10382             if ( s0.match( query_nodes ) ) {
10383                 return false;
10384             }
10385             //
10386             query_nodes = new HashSet<PhylogenyNode>();
10387             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10388             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10389             if ( s0.match( query_nodes ) ) {
10390                 return false;
10391             }
10392             //
10393             query_nodes = new HashSet<PhylogenyNode>();
10394             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10396             if ( s0.match( query_nodes ) ) {
10397                 return false;
10398             }
10399             //
10400             query_nodes = new HashSet<PhylogenyNode>();
10401             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10402             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10403             if ( s0.match( query_nodes ) ) {
10404                 return false;
10405             }
10406             //
10407             query_nodes = new HashSet<PhylogenyNode>();
10408             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10409             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "F" ) );
10417             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10418             if ( s0.match( query_nodes ) ) {
10419                 return false;
10420             }
10421             //
10422             query_nodes = new HashSet<PhylogenyNode>();
10423             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10424             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10425             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10426             if ( s0.match( query_nodes ) ) {
10427                 return false;
10428             }
10429             //
10430             query_nodes = new HashSet<PhylogenyNode>();
10431             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10432             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10433             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10434             if ( s0.match( query_nodes ) ) {
10435                 return false;
10436             }
10437             //
10438             query_nodes = new HashSet<PhylogenyNode>();
10439             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10440             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10441             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10442             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10443             if ( s0.match( query_nodes ) ) {
10444                 return false;
10445             }
10446         }
10447         catch ( final Exception e ) {
10448             e.printStackTrace();
10449             return false;
10450         }
10451         return true;
10452     }
10453
10454     private static boolean testSubtreeDeletion() {
10455         try {
10456             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10457             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10458             t1.deleteSubtree( t1.getNode( "A" ), false );
10459             if ( t1.getNumberOfExternalNodes() != 5 ) {
10460                 return false;
10461             }
10462             t1.toNewHampshireX();
10463             t1.deleteSubtree( t1.getNode( "E" ), false );
10464             if ( t1.getNumberOfExternalNodes() != 4 ) {
10465                 return false;
10466             }
10467             t1.toNewHampshireX();
10468             t1.deleteSubtree( t1.getNode( "F" ), false );
10469             if ( t1.getNumberOfExternalNodes() != 3 ) {
10470                 return false;
10471             }
10472             t1.toNewHampshireX();
10473             t1.deleteSubtree( t1.getNode( "D" ), false );
10474             t1.toNewHampshireX();
10475             if ( t1.getNumberOfExternalNodes() != 3 ) {
10476                 return false;
10477             }
10478             t1.deleteSubtree( t1.getNode( "def" ), false );
10479             t1.toNewHampshireX();
10480             if ( t1.getNumberOfExternalNodes() != 2 ) {
10481                 return false;
10482             }
10483             t1.deleteSubtree( t1.getNode( "B" ), false );
10484             t1.toNewHampshireX();
10485             if ( t1.getNumberOfExternalNodes() != 1 ) {
10486                 return false;
10487             }
10488             t1.deleteSubtree( t1.getNode( "C" ), false );
10489             t1.toNewHampshireX();
10490             if ( t1.getNumberOfExternalNodes() != 1 ) {
10491                 return false;
10492             }
10493             t1.deleteSubtree( t1.getNode( "abc" ), false );
10494             t1.toNewHampshireX();
10495             if ( t1.getNumberOfExternalNodes() != 1 ) {
10496                 return false;
10497             }
10498             t1.deleteSubtree( t1.getNode( "r" ), false );
10499             if ( t1.getNumberOfExternalNodes() != 0 ) {
10500                 return false;
10501             }
10502             if ( !t1.isEmpty() ) {
10503                 return false;
10504             }
10505             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10506             t2.deleteSubtree( t2.getNode( "A" ), false );
10507             t2.toNewHampshireX();
10508             if ( t2.getNumberOfExternalNodes() != 5 ) {
10509                 return false;
10510             }
10511             t2.deleteSubtree( t2.getNode( "abc" ), false );
10512             t2.toNewHampshireX();
10513             if ( t2.getNumberOfExternalNodes() != 3 ) {
10514                 return false;
10515             }
10516             t2.deleteSubtree( t2.getNode( "def" ), false );
10517             t2.toNewHampshireX();
10518             if ( t2.getNumberOfExternalNodes() != 1 ) {
10519                 return false;
10520             }
10521         }
10522         catch ( final Exception e ) {
10523             e.printStackTrace( System.out );
10524             return false;
10525         }
10526         return true;
10527     }
10528
10529     private static boolean testSupportCount() {
10530         try {
10531             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10532             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
10533             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
10534                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
10535                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
10536                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
10537                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
10538                                                               new NHXParser() );
10539             SupportCount.count( t0_1, phylogenies_1, true, false );
10540             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
10541             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
10542                                                                       + "(((((A,B),C),D),E),((F,G),X))"
10543                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
10544                                                                       + "(((((A,B),C),D),E),(F,G))"
10545                                                                       + "(((((A,B),C),D),E),(F,G))"
10546                                                                       + "(((((A,B),C),D),E),(F,G))"
10547                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
10548                                                                       + "(((((A,B),C),D),E),(F,G))"
10549                                                                       + "((((((A,B),C),D),E),F),G)"
10550                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
10551                                                               new NHXParser() );
10552             SupportCount.count( t0_2, phylogenies_2, true, false );
10553             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
10554             while ( it.hasNext() ) {
10555                 final PhylogenyNode n = it.next();
10556                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
10557                     return false;
10558                 }
10559             }
10560             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
10561             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
10562                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
10563             SupportCount.count( t0_3, phylogenies_3, true, false );
10564             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
10565             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
10566                 return false;
10567             }
10568             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
10569                 return false;
10570             }
10571             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
10572                 return false;
10573             }
10574             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
10575                 return false;
10576             }
10577             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
10578                 return false;
10579             }
10580             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
10581                 return false;
10582             }
10583             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
10584                 return false;
10585             }
10586             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
10587                 return false;
10588             }
10589             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
10590                 return false;
10591             }
10592             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
10593                 return false;
10594             }
10595             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10596             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
10597                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
10598             SupportCount.count( t0_4, phylogenies_4, true, false );
10599             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
10600             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
10601                 return false;
10602             }
10603             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
10604                 return false;
10605             }
10606             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
10607                 return false;
10608             }
10609             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
10610                 return false;
10611             }
10612             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
10613                 return false;
10614             }
10615             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
10616                 return false;
10617             }
10618             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
10619                 return false;
10620             }
10621             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
10622                 return false;
10623             }
10624             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
10625                 return false;
10626             }
10627             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
10628                 return false;
10629             }
10630             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10631             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10632             double d = SupportCount.compare( b1, a, true, true, true );
10633             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
10634                 return false;
10635             }
10636             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10637             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10638             d = SupportCount.compare( b2, a, true, true, true );
10639             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
10640                 return false;
10641             }
10642             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10643             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
10644             d = SupportCount.compare( b3, a, true, true, true );
10645             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
10646                 return false;
10647             }
10648             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
10649             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
10650             d = SupportCount.compare( b4, a, true, true, false );
10651             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
10652                 return false;
10653             }
10654         }
10655         catch ( final Exception e ) {
10656             e.printStackTrace( System.out );
10657             return false;
10658         }
10659         return true;
10660     }
10661
10662     private static boolean testSupportTransfer() {
10663         try {
10664             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10665             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)",
10666                                                  new NHXParser() )[ 0 ];
10667             final Phylogeny p2 = factory
10668                     .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 ];
10669             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
10670                 return false;
10671             }
10672             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
10673                 return false;
10674             }
10675             support_transfer.moveBranchLengthsToBootstrap( p1 );
10676             support_transfer.transferSupportValues( p1, p2 );
10677             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
10678                 return false;
10679             }
10680             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
10681                 return false;
10682             }
10683             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
10684                 return false;
10685             }
10686             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
10687                 return false;
10688             }
10689             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
10690                 return false;
10691             }
10692             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
10693                 return false;
10694             }
10695             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
10696                 return false;
10697             }
10698             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
10699                 return false;
10700             }
10701         }
10702         catch ( final Exception e ) {
10703             e.printStackTrace( System.out );
10704             return false;
10705         }
10706         return true;
10707     }
10708
10709     private static boolean testTaxonomyExtraction() {
10710         try {
10711             final PhylogenyNode n0 = PhylogenyNode
10712                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10713             if ( n0.getNodeData().isHasTaxonomy() ) {
10714                 return false;
10715             }
10716             final PhylogenyNode n1 = PhylogenyNode
10717                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10718             if ( n1.getNodeData().isHasTaxonomy() ) {
10719                 System.out.println( n1.toString() );
10720                 return false;
10721             }
10722             final PhylogenyNode n2x = PhylogenyNode
10723                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10724             if ( n2x.getNodeData().isHasTaxonomy() ) {
10725                 return false;
10726             }
10727             final PhylogenyNode n3 = PhylogenyNode
10728                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10729             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10730                 System.out.println( n3.toString() );
10731                 return false;
10732             }
10733             final PhylogenyNode n4 = PhylogenyNode
10734                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10735             if ( n4.getNodeData().isHasTaxonomy() ) {
10736                 System.out.println( n4.toString() );
10737                 return false;
10738             }
10739             final PhylogenyNode n5 = PhylogenyNode
10740                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10741             if ( n5.getNodeData().isHasTaxonomy() ) {
10742                 System.out.println( n5.toString() );
10743                 return false;
10744             }
10745             final PhylogenyNode n6 = PhylogenyNode
10746                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10747             if ( n6.getNodeData().isHasTaxonomy() ) {
10748                 System.out.println( n6.toString() );
10749                 return false;
10750             }
10751             final PhylogenyNode n7 = PhylogenyNode
10752                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10753             if ( n7.getNodeData().isHasTaxonomy() ) {
10754                 System.out.println( n7.toString() );
10755                 return false;
10756             }
10757             final PhylogenyNode n8 = PhylogenyNode
10758                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10759             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10760                 System.out.println( n8.toString() );
10761                 return false;
10762             }
10763             final PhylogenyNode n9 = PhylogenyNode
10764                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10765             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10766                 System.out.println( n9.toString() );
10767                 return false;
10768             }
10769             final PhylogenyNode n10x = PhylogenyNode
10770                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10771             if ( n10x.getNodeData().isHasTaxonomy() ) {
10772                 System.out.println( n10x.toString() );
10773                 return false;
10774             }
10775             final PhylogenyNode n10xx = PhylogenyNode
10776                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10777             if ( n10xx.getNodeData().isHasTaxonomy() ) {
10778                 System.out.println( n10xx.toString() );
10779                 return false;
10780             }
10781             final PhylogenyNode n10 = PhylogenyNode
10782                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10783             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
10784                 System.out.println( n10.toString() );
10785                 return false;
10786             }
10787             final PhylogenyNode n11 = PhylogenyNode
10788                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10789             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
10790                 System.out.println( n11.toString() );
10791                 return false;
10792             }
10793             final PhylogenyNode n12 = PhylogenyNode
10794                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
10795                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10796             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
10797                 System.out.println( n12.toString() );
10798                 return false;
10799             }
10800             final PhylogenyNode n13 = PhylogenyNode
10801                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10802             if ( n13.getNodeData().isHasTaxonomy() ) {
10803                 System.out.println( n13.toString() );
10804                 return false;
10805             }
10806         }
10807         catch ( final Exception e ) {
10808             e.printStackTrace( System.out );
10809             return false;
10810         }
10811         return true;
10812     }
10813
10814     private static boolean testTreeMethods() {
10815         try {
10816             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10817             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
10818             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
10819             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
10820                 System.out.println( t0.toNewHampshireX() );
10821                 return false;
10822             }
10823             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
10824             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
10825             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
10826                 return false;
10827             }
10828             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
10829                 return false;
10830             }
10831             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
10832                 return false;
10833             }
10834         }
10835         catch ( final Exception e ) {
10836             e.printStackTrace( System.out );
10837             return false;
10838         }
10839         return true;
10840     }
10841
10842     private static boolean testUniprotEntryRetrieval() {
10843         try {
10844             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
10845             if ( !entry.getAccession().equals( "P12345" ) ) {
10846                 return false;
10847             }
10848             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
10849                 return false;
10850             }
10851             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
10852                 return false;
10853             }
10854             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
10855                 return false;
10856             }
10857             if ( !entry.getGeneName().equals( "GOT2" ) ) {
10858                 return false;
10859             }
10860             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
10861                 return false;
10862             }
10863         }
10864         catch ( final IOException e ) {
10865             System.out.println();
10866             System.out.println( "the following might be due to absence internet connection:" );
10867             e.printStackTrace( System.out );
10868             return true;
10869         }
10870         catch ( final Exception e ) {
10871             return false;
10872         }
10873         return true;
10874     }
10875
10876     private static boolean testUniprotTaxonomySearch() {
10877         try {
10878             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
10879                                                                                                  10 );
10880             if ( results.size() != 1 ) {
10881                 return false;
10882             }
10883             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
10884                 return false;
10885             }
10886             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
10887                 return false;
10888             }
10889             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
10890                 return false;
10891             }
10892             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10893                 return false;
10894             }
10895             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
10896                 return false;
10897             }
10898             results = null;
10899             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
10900             if ( results.size() != 1 ) {
10901                 return false;
10902             }
10903             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
10904                 return false;
10905             }
10906             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
10907                 return false;
10908             }
10909             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
10910                 return false;
10911             }
10912             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10913                 return false;
10914             }
10915             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
10916                 return false;
10917             }
10918             results = null;
10919             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
10920             if ( results.size() != 1 ) {
10921                 return false;
10922             }
10923             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
10924                 return false;
10925             }
10926             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
10927                 return false;
10928             }
10929             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
10930                 return false;
10931             }
10932             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10933                 return false;
10934             }
10935             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
10936                 return false;
10937             }
10938             results = null;
10939             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
10940             if ( results.size() != 1 ) {
10941                 return false;
10942             }
10943             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
10944                 return false;
10945             }
10946             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
10947                 return false;
10948             }
10949             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
10950                 return false;
10951             }
10952             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10953                 return false;
10954             }
10955             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
10956                 return false;
10957             }
10958             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
10959                 return false;
10960             }
10961             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
10962                 return false;
10963             }
10964             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
10965                     .equals( "Nematostella vectensis" ) ) {
10966                 System.out.println( results.get( 0 ).getLineage() );
10967                 return false;
10968             }
10969             //
10970             results = null;
10971             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
10972             if ( results.size() != 1 ) {
10973                 return false;
10974             }
10975             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
10976                 return false;
10977             }
10978             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
10979                 return false;
10980             }
10981             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
10982                 return false;
10983             }
10984             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10985                 return false;
10986             }
10987             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
10988                 return false;
10989             }
10990             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
10991                     .equals( "Xenopus tropicalis" ) ) {
10992                 System.out.println( results.get( 0 ).getLineage() );
10993                 return false;
10994             }
10995             //
10996             results = null;
10997             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
10998             if ( results.size() != 1 ) {
10999                 return false;
11000             }
11001             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11002                 return false;
11003             }
11004             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11005                 return false;
11006             }
11007             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11008                 return false;
11009             }
11010             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11011                 return false;
11012             }
11013             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11014                 return false;
11015             }
11016             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11017                     .equals( "Xenopus tropicalis" ) ) {
11018                 System.out.println( results.get( 0 ).getLineage() );
11019                 return false;
11020             }
11021             //
11022             results = null;
11023             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
11024             if ( results.size() != 1 ) {
11025                 return false;
11026             }
11027             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11028                 return false;
11029             }
11030             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11031                 return false;
11032             }
11033             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11034                 return false;
11035             }
11036             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11037                 return false;
11038             }
11039             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11040                 return false;
11041             }
11042             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11043                     .equals( "Xenopus tropicalis" ) ) {
11044                 System.out.println( results.get( 0 ).getLineage() );
11045                 return false;
11046             }
11047         }
11048         catch ( final IOException e ) {
11049             System.out.println();
11050             System.out.println( "the following might be due to absence internet connection:" );
11051             e.printStackTrace( System.out );
11052             return true;
11053         }
11054         catch ( final Exception e ) {
11055             return false;
11056         }
11057         return true;
11058     }
11059
11060     private static boolean testWabiTxSearch() {
11061         try {
11062             String result = "";
11063             result = TxSearch.searchSimple( "nematostella" );
11064             result = TxSearch.getTxId( "nematostella" );
11065             if ( !result.equals( "45350" ) ) {
11066                 return false;
11067             }
11068             result = TxSearch.getTxName( "45350" );
11069             if ( !result.equals( "Nematostella" ) ) {
11070                 return false;
11071             }
11072             result = TxSearch.getTxId( "nematostella vectensis" );
11073             if ( !result.equals( "45351" ) ) {
11074                 return false;
11075             }
11076             result = TxSearch.getTxName( "45351" );
11077             if ( !result.equals( "Nematostella vectensis" ) ) {
11078                 return false;
11079             }
11080             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11081             if ( !result.equals( "536089" ) ) {
11082                 return false;
11083             }
11084             result = TxSearch.getTxName( "536089" );
11085             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11086                 return false;
11087             }
11088             final List<String> queries = new ArrayList<String>();
11089             queries.add( "Campylobacter coli" );
11090             queries.add( "Escherichia coli" );
11091             queries.add( "Arabidopsis" );
11092             queries.add( "Trichoplax" );
11093             queries.add( "Samanea saman" );
11094             queries.add( "Kluyveromyces marxianus" );
11095             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11096             queries.add( "Bornavirus parrot/PDD/2008" );
11097             final List<RANKS> ranks = new ArrayList<RANKS>();
11098             ranks.add( RANKS.SUPERKINGDOM );
11099             ranks.add( RANKS.KINGDOM );
11100             ranks.add( RANKS.FAMILY );
11101             ranks.add( RANKS.GENUS );
11102             ranks.add( RANKS.TRIBE );
11103             result = TxSearch.searchLineage( queries, ranks );
11104             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11105             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11106         }
11107         catch ( final Exception e ) {
11108             System.out.println();
11109             System.out.println( "the following might be due to absence internet connection:" );
11110             e.printStackTrace( System.out );
11111             return false;
11112         }
11113         return true;
11114     }
11115 }