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