inprogress
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.test;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Set;
39 import java.util.SortedSet;
40
41 import org.forester.application.support_transfer;
42 import org.forester.archaeopteryx.TreePanelUtil;
43 import org.forester.development.DevelopmentTools;
44 import org.forester.evoinference.TestPhylogenyReconstruction;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
46 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
47 import org.forester.go.TestGo;
48 import org.forester.io.parsers.FastaParser;
49 import org.forester.io.parsers.GeneralMsaParser;
50 import org.forester.io.parsers.HmmscanPerDomainTableParser;
51 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
52 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
53 import org.forester.io.parsers.nexus.NexusCharactersParser;
54 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
55 import org.forester.io.parsers.nhx.NHXParser;
56 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
57 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
58 import org.forester.io.parsers.tol.TolParser;
59 import org.forester.io.parsers.util.ParserUtils;
60 import org.forester.io.writers.PhylogenyWriter;
61 import org.forester.io.writers.SequenceWriter;
62 import org.forester.msa.BasicMsa;
63 import org.forester.msa.Mafft;
64 import org.forester.msa.Msa;
65 import org.forester.msa.MsaInferrer;
66 import org.forester.msa.MsaMethods;
67 import org.forester.pccx.TestPccx;
68 import org.forester.phylogeny.Phylogeny;
69 import org.forester.phylogeny.PhylogenyBranch;
70 import org.forester.phylogeny.PhylogenyMethods;
71 import org.forester.phylogeny.PhylogenyNode;
72 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
73 import org.forester.phylogeny.data.Accession;
74 import org.forester.phylogeny.data.Accession.Source;
75 import org.forester.phylogeny.data.BinaryCharacters;
76 import org.forester.phylogeny.data.BranchWidth;
77 import org.forester.phylogeny.data.Confidence;
78 import org.forester.phylogeny.data.Distribution;
79 import org.forester.phylogeny.data.DomainArchitecture;
80 import org.forester.phylogeny.data.Event;
81 import org.forester.phylogeny.data.Identifier;
82 import org.forester.phylogeny.data.PhylogenyData;
83 import org.forester.phylogeny.data.PhylogenyDataUtil;
84 import org.forester.phylogeny.data.Polygon;
85 import org.forester.phylogeny.data.PropertiesMap;
86 import org.forester.phylogeny.data.Property;
87 import org.forester.phylogeny.data.Property.AppliesTo;
88 import org.forester.phylogeny.data.ProteinDomain;
89 import org.forester.phylogeny.data.Taxonomy;
90 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
91 import org.forester.phylogeny.factories.PhylogenyFactory;
92 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
93 import org.forester.protein.BasicDomain;
94 import org.forester.protein.BasicProtein;
95 import org.forester.protein.Domain;
96 import org.forester.protein.Protein;
97 import org.forester.protein.ProteinId;
98 import org.forester.rio.TestRIO;
99 import org.forester.sdi.SDI;
100 import org.forester.sdi.SDIR;
101 import org.forester.sdi.TestGSDI;
102 import org.forester.sequence.BasicSequence;
103 import org.forester.sequence.Sequence;
104 import org.forester.species.BasicSpecies;
105 import org.forester.species.Species;
106 import org.forester.surfacing.TestSurfacing;
107 import org.forester.tools.ConfidenceAssessor;
108 import org.forester.tools.SupportCount;
109 import org.forester.tools.TreeSplitMatrix;
110 import org.forester.util.AsciiHistogram;
111 import org.forester.util.BasicDescriptiveStatistics;
112 import org.forester.util.BasicTable;
113 import org.forester.util.BasicTableParser;
114 import org.forester.util.DescriptiveStatistics;
115 import org.forester.util.ForesterConstants;
116 import org.forester.util.ForesterUtil;
117 import org.forester.util.GeneralTable;
118 import org.forester.util.SequenceAccessionTools;
119 import org.forester.ws.seqdb.SequenceDatabaseEntry;
120 import org.forester.ws.seqdb.SequenceDbWsTools;
121 import org.forester.ws.seqdb.UniProtTaxonomy;
122 import org.forester.ws.wabi.TxSearch;
123 import org.forester.ws.wabi.TxSearch.RANKS;
124 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
125 import org.forester.ws.wabi.TxSearch.TAX_RANK;
126
127 @SuppressWarnings( "unused")
128 public final class Test {
129
130     private final static boolean PERFORM_DB_TESTS          = true;
131     private final static double  ZERO_DIFF                 = 1.0E-9;
132     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
133                                                                    + ForesterUtil.getFileSeparator() + "test_data"
134                                                                    + ForesterUtil.getFileSeparator();
135     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
136                                                                    + ForesterUtil.getFileSeparator() + "resources"
137                                                                    + ForesterUtil.getFileSeparator();
138     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
139     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
140                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
141                                                                    + ForesterConstants.PHYLO_XML_XSD;
142     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
143                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
144                                                                    + ForesterConstants.PHYLO_XML_XSD;
145
146     public static boolean isEqual( final double a, final double b ) {
147         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
148     }
149
150     public static void main( final String[] args ) {
151         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
152         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
153                 + "]" );
154         Locale.setDefault( Locale.US );
155         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
156         int failed = 0;
157         int succeeded = 0;
158         System.out.print( "[Test if directory with files for testing exists/is readable: " );
159         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
160             System.out.println( "OK.]" );
161         }
162         else {
163             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
164             System.out.println( "Testing aborted." );
165             System.exit( -1 );
166         }
167         System.out.print( "[Test if resources directory exists/is readable: " );
168         if ( testDir( PATH_TO_RESOURCES ) ) {
169             System.out.println( "OK.]" );
170         }
171         else {
172             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
173             System.out.println( "Testing aborted." );
174             System.exit( -1 );
175         }
176         final long start_time = new Date().getTime();
177         System.out.print( "Basic node methods: " );
178         if ( Test.testBasicNodeMethods() ) {
179             System.out.println( "OK." );
180             succeeded++;
181         }
182         else {
183             System.out.println( "failed." );
184             failed++;
185         }
186         System.out.print( "Protein id: " );
187         if ( !testProteinId() ) {
188             System.out.println( "failed." );
189             failed++;
190         }
191         else {
192             succeeded++;
193         }
194         System.out.println( "OK." );
195         System.out.print( "Species: " );
196         if ( !testSpecies() ) {
197             System.out.println( "failed." );
198             failed++;
199         }
200         else {
201             succeeded++;
202         }
203         System.out.println( "OK." );
204         System.out.print( "Basic domain: " );
205         if ( !testBasicDomain() ) {
206             System.out.println( "failed." );
207             failed++;
208         }
209         else {
210             succeeded++;
211         }
212         System.out.println( "OK." );
213         System.out.print( "Basic protein: " );
214         if ( !testBasicProtein() ) {
215             System.out.println( "failed." );
216             failed++;
217         }
218         else {
219             succeeded++;
220         }
221         System.out.println( "OK." );
222         System.out.print( "Sequence writer: " );
223         if ( testSequenceWriter() ) {
224             System.out.println( "OK." );
225             succeeded++;
226         }
227         else {
228             System.out.println( "failed." );
229             failed++;
230         }
231         System.out.print( "Sequence id parsing: " );
232         if ( testSequenceIdParsing() ) {
233             System.out.println( "OK." );
234             succeeded++;
235         }
236         else {
237             System.out.println( "failed." );
238             failed++;
239         }
240         System.out.print( "UniProtKB id extraction: " );
241         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
242             System.out.println( "OK." );
243             succeeded++;
244         }
245         else {
246             System.out.println( "failed." );
247             failed++;
248         }
249         System.out.print( "Sequence DB tools 1: " );
250         if ( testSequenceDbWsTools1() ) {
251             System.out.println( "OK." );
252             succeeded++;
253         }
254         else {
255             System.out.println( "failed." );
256             failed++;
257         }
258         if ( PERFORM_DB_TESTS ) {
259             System.out.print( "Sequence DB tools 2: " );
260             if ( testSequenceDbWsTools2() ) {
261                 System.out.println( "OK." );
262                 succeeded++;
263             }
264             else {
265                 System.out.println( "failed." );
266                 failed++;
267                 System.exit( -1 );
268             }
269         }
270         System.exit( 0 );
271         System.out.print( "Hmmscan output parser: " );
272         if ( testHmmscanOutputParser() ) {
273             System.out.println( "OK." );
274             succeeded++;
275         }
276         else {
277             System.out.println( "failed." );
278             failed++;
279         }
280         System.out.print( "Taxonomy code extraction: " );
281         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
282             System.out.println( "OK." );
283             succeeded++;
284         }
285         else {
286             System.out.println( "failed." );
287             failed++;
288         }
289         System.out.print( "SN extraction: " );
290         if ( Test.testExtractSNFromNodeName() ) {
291             System.out.println( "OK." );
292             succeeded++;
293         }
294         else {
295             System.out.println( "failed." );
296             failed++;
297         }
298         System.out.print( "Taxonomy extraction (general): " );
299         if ( Test.testTaxonomyExtraction() ) {
300             System.out.println( "OK." );
301             succeeded++;
302         }
303         else {
304             System.out.println( "failed." );
305             failed++;
306         }
307         System.out.print( "Uri for Aptx web sequence accession: " );
308         if ( Test.testCreateUriForSeqWeb() ) {
309             System.out.println( "OK." );
310             succeeded++;
311         }
312         else {
313             System.out.println( "failed." );
314             failed++;
315         }
316         System.out.print( "Basic node construction and parsing of NHX (node level): " );
317         if ( Test.testNHXNodeParsing() ) {
318             System.out.println( "OK." );
319             succeeded++;
320         }
321         else {
322             System.out.println( "failed." );
323             failed++;
324         }
325         System.out.print( "NHX parsing iterating: " );
326         if ( Test.testNHParsingIter() ) {
327             System.out.println( "OK." );
328             succeeded++;
329         }
330         else {
331             System.out.println( "failed." );
332             failed++;
333         }
334         System.out.print( "NH parsing: " );
335         if ( Test.testNHParsing() ) {
336             System.out.println( "OK." );
337             succeeded++;
338         }
339         else {
340             System.out.println( "failed." );
341             failed++;
342         }
343         System.out.print( "Conversion to NHX (node level): " );
344         if ( Test.testNHXconversion() ) {
345             System.out.println( "OK." );
346             succeeded++;
347         }
348         else {
349             System.out.println( "failed." );
350             failed++;
351         }
352         System.out.print( "NHX parsing: " );
353         if ( Test.testNHXParsing() ) {
354             System.out.println( "OK." );
355             succeeded++;
356         }
357         else {
358             System.out.println( "failed." );
359             failed++;
360         }
361         System.out.print( "NHX parsing with quotes: " );
362         if ( Test.testNHXParsingQuotes() ) {
363             System.out.println( "OK." );
364             succeeded++;
365         }
366         else {
367             System.out.println( "failed." );
368             failed++;
369         }
370         System.out.print( "NHX parsing (MrBayes): " );
371         if ( Test.testNHXParsingMB() ) {
372             System.out.println( "OK." );
373             succeeded++;
374         }
375         else {
376             System.out.println( "failed." );
377             failed++;
378         }
379         System.out.print( "Nexus characters parsing: " );
380         if ( Test.testNexusCharactersParsing() ) {
381             System.out.println( "OK." );
382             succeeded++;
383         }
384         else {
385             System.out.println( "failed." );
386             failed++;
387         }
388         System.out.print( "Nexus tree parsing iterating: " );
389         if ( Test.testNexusTreeParsingIterating() ) {
390             System.out.println( "OK." );
391             succeeded++;
392         }
393         else {
394             System.out.println( "failed." );
395             failed++;
396         }
397         System.out.print( "Nexus tree parsing: " );
398         if ( Test.testNexusTreeParsing() ) {
399             System.out.println( "OK." );
400             succeeded++;
401         }
402         else {
403             System.out.println( "failed." );
404             failed++;
405         }
406         System.out.print( "Nexus tree parsing (translating): " );
407         if ( Test.testNexusTreeParsingTranslating() ) {
408             System.out.println( "OK." );
409             succeeded++;
410         }
411         else {
412             System.out.println( "failed." );
413             failed++;
414         }
415         System.out.print( "Nexus matrix parsing: " );
416         if ( Test.testNexusMatrixParsing() ) {
417             System.out.println( "OK." );
418             succeeded++;
419         }
420         else {
421             System.out.println( "failed." );
422             failed++;
423         }
424         System.out.print( "Basic phyloXML parsing: " );
425         if ( Test.testBasicPhyloXMLparsing() ) {
426             System.out.println( "OK." );
427             succeeded++;
428         }
429         else {
430             System.out.println( "failed." );
431             failed++;
432         }
433         System.out.print( "Basic phyloXML parsing (validating against schema): " );
434         if ( testBasicPhyloXMLparsingValidating() ) {
435             System.out.println( "OK." );
436             succeeded++;
437         }
438         else {
439             System.out.println( "failed." );
440             failed++;
441         }
442         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
443         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
444             System.out.println( "OK." );
445             succeeded++;
446         }
447         else {
448             System.out.println( "failed." );
449             failed++;
450         }
451         System.out.print( "phyloXML Distribution Element: " );
452         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
453             System.out.println( "OK." );
454             succeeded++;
455         }
456         else {
457             System.out.println( "failed." );
458             failed++;
459         }
460         System.out.print( "Tol XML parsing: " );
461         if ( Test.testBasicTolXMLparsing() ) {
462             System.out.println( "OK." );
463             succeeded++;
464         }
465         else {
466             System.out.println( "failed." );
467             failed++;
468         }
469         System.out.print( "Copying of node data: " );
470         if ( Test.testCopyOfNodeData() ) {
471             System.out.println( "OK." );
472             succeeded++;
473         }
474         else {
475             System.out.println( "failed." );
476             failed++;
477         }
478         System.out.print( "Basic tree methods: " );
479         if ( Test.testBasicTreeMethods() ) {
480             System.out.println( "OK." );
481             succeeded++;
482         }
483         else {
484             System.out.println( "failed." );
485             failed++;
486         }
487         System.out.print( "Tree methods: " );
488         if ( Test.testTreeMethods() ) {
489             System.out.println( "OK." );
490             succeeded++;
491         }
492         else {
493             System.out.println( "failed." );
494             failed++;
495         }
496         System.out.print( "Postorder Iterator: " );
497         if ( Test.testPostOrderIterator() ) {
498             System.out.println( "OK." );
499             succeeded++;
500         }
501         else {
502             System.out.println( "failed." );
503             failed++;
504         }
505         System.out.print( "Preorder Iterator: " );
506         if ( Test.testPreOrderIterator() ) {
507             System.out.println( "OK." );
508             succeeded++;
509         }
510         else {
511             System.out.println( "failed." );
512             failed++;
513         }
514         System.out.print( "Levelorder Iterator: " );
515         if ( Test.testLevelOrderIterator() ) {
516             System.out.println( "OK." );
517             succeeded++;
518         }
519         else {
520             System.out.println( "failed." );
521             failed++;
522         }
523         System.out.print( "Re-id methods: " );
524         if ( Test.testReIdMethods() ) {
525             System.out.println( "OK." );
526             succeeded++;
527         }
528         else {
529             System.out.println( "failed." );
530             failed++;
531         }
532         System.out.print( "Methods on last external nodes: " );
533         if ( Test.testLastExternalNodeMethods() ) {
534             System.out.println( "OK." );
535             succeeded++;
536         }
537         else {
538             System.out.println( "failed." );
539             failed++;
540         }
541         System.out.print( "Methods on external nodes: " );
542         if ( Test.testExternalNodeRelatedMethods() ) {
543             System.out.println( "OK." );
544             succeeded++;
545         }
546         else {
547             System.out.println( "failed." );
548             failed++;
549         }
550         System.out.print( "Deletion of external nodes: " );
551         if ( Test.testDeletionOfExternalNodes() ) {
552             System.out.println( "OK." );
553             succeeded++;
554         }
555         else {
556             System.out.println( "failed." );
557             failed++;
558         }
559         System.out.print( "Subtree deletion: " );
560         if ( Test.testSubtreeDeletion() ) {
561             System.out.println( "OK." );
562             succeeded++;
563         }
564         else {
565             System.out.println( "failed." );
566             failed++;
567         }
568         System.out.print( "Phylogeny branch: " );
569         if ( Test.testPhylogenyBranch() ) {
570             System.out.println( "OK." );
571             succeeded++;
572         }
573         else {
574             System.out.println( "failed." );
575             failed++;
576         }
577         System.out.print( "Rerooting: " );
578         if ( Test.testRerooting() ) {
579             System.out.println( "OK." );
580             succeeded++;
581         }
582         else {
583             System.out.println( "failed." );
584             failed++;
585         }
586         System.out.print( "Mipoint rooting: " );
587         if ( Test.testMidpointrooting() ) {
588             System.out.println( "OK." );
589             succeeded++;
590         }
591         else {
592             System.out.println( "failed." );
593             failed++;
594         }
595         System.out.print( "Node removal: " );
596         if ( Test.testNodeRemoval() ) {
597             System.out.println( "OK." );
598             succeeded++;
599         }
600         else {
601             System.out.println( "failed." );
602             failed++;
603         }
604         System.out.print( "Support count: " );
605         if ( Test.testSupportCount() ) {
606             System.out.println( "OK." );
607             succeeded++;
608         }
609         else {
610             System.out.println( "failed." );
611             failed++;
612         }
613         System.out.print( "Support transfer: " );
614         if ( Test.testSupportTransfer() ) {
615             System.out.println( "OK." );
616             succeeded++;
617         }
618         else {
619             System.out.println( "failed." );
620             failed++;
621         }
622         System.out.print( "Finding of LCA: " );
623         if ( Test.testGetLCA() ) {
624             System.out.println( "OK." );
625             succeeded++;
626         }
627         else {
628             System.out.println( "failed." );
629             failed++;
630         }
631         System.out.print( "Finding of LCA 2: " );
632         if ( Test.testGetLCA2() ) {
633             System.out.println( "OK." );
634             succeeded++;
635         }
636         else {
637             System.out.println( "failed." );
638             failed++;
639         }
640         System.out.print( "Calculation of distance between nodes: " );
641         if ( Test.testGetDistance() ) {
642             System.out.println( "OK." );
643             succeeded++;
644         }
645         else {
646             System.out.println( "failed." );
647             failed++;
648         }
649         System.out.print( "Descriptive statistics: " );
650         if ( Test.testDescriptiveStatistics() ) {
651             System.out.println( "OK." );
652             succeeded++;
653         }
654         else {
655             System.out.println( "failed." );
656             failed++;
657         }
658         System.out.print( "Data objects and methods: " );
659         if ( Test.testDataObjects() ) {
660             System.out.println( "OK." );
661             succeeded++;
662         }
663         else {
664             System.out.println( "failed." );
665             failed++;
666         }
667         System.out.print( "Properties map: " );
668         if ( Test.testPropertiesMap() ) {
669             System.out.println( "OK." );
670             succeeded++;
671         }
672         else {
673             System.out.println( "failed." );
674             failed++;
675         }
676         System.out.print( "SDIse: " );
677         if ( Test.testSDIse() ) {
678             System.out.println( "OK." );
679             succeeded++;
680         }
681         else {
682             System.out.println( "failed." );
683             failed++;
684         }
685         System.out.print( "SDIunrooted: " );
686         if ( Test.testSDIunrooted() ) {
687             System.out.println( "OK." );
688             succeeded++;
689         }
690         else {
691             System.out.println( "failed." );
692             failed++;
693         }
694         System.out.print( "GSDI: " );
695         if ( TestGSDI.test() ) {
696             System.out.println( "OK." );
697             succeeded++;
698         }
699         else {
700             System.out.println( "failed." );
701             failed++;
702         }
703         System.out.print( "RIO: " );
704         if ( TestRIO.test() ) {
705             System.out.println( "OK." );
706             succeeded++;
707         }
708         else {
709             System.out.println( "failed." );
710             failed++;
711         }
712         System.out.print( "Phylogeny reconstruction:" );
713         System.out.println();
714         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
715             System.out.println( "OK." );
716             succeeded++;
717         }
718         else {
719             System.out.println( "failed." );
720             failed++;
721         }
722         System.out.print( "Analysis of domain architectures: " );
723         System.out.println();
724         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
725             System.out.println( "OK." );
726             succeeded++;
727         }
728         else {
729             System.out.println( "failed." );
730             failed++;
731         }
732         System.out.print( "GO: " );
733         System.out.println();
734         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "Modeling tools: " );
743         if ( TestPccx.test() ) {
744             System.out.println( "OK." );
745             succeeded++;
746         }
747         else {
748             System.out.println( "failed." );
749             failed++;
750         }
751         System.out.print( "Split Matrix strict: " );
752         if ( Test.testSplitStrict() ) {
753             System.out.println( "OK." );
754             succeeded++;
755         }
756         else {
757             System.out.println( "failed." );
758             failed++;
759         }
760         System.out.print( "Split Matrix: " );
761         if ( Test.testSplit() ) {
762             System.out.println( "OK." );
763             succeeded++;
764         }
765         else {
766             System.out.println( "failed." );
767             failed++;
768         }
769         System.out.print( "Confidence Assessor: " );
770         if ( Test.testConfidenceAssessor() ) {
771             System.out.println( "OK." );
772             succeeded++;
773         }
774         else {
775             System.out.println( "failed." );
776             failed++;
777         }
778         System.out.print( "Basic table: " );
779         if ( Test.testBasicTable() ) {
780             System.out.println( "OK." );
781             succeeded++;
782         }
783         else {
784             System.out.println( "failed." );
785             failed++;
786         }
787         System.out.print( "General table: " );
788         if ( Test.testGeneralTable() ) {
789             System.out.println( "OK." );
790             succeeded++;
791         }
792         else {
793             System.out.println( "failed." );
794             failed++;
795         }
796         System.out.print( "Amino acid sequence: " );
797         if ( Test.testAminoAcidSequence() ) {
798             System.out.println( "OK." );
799             succeeded++;
800         }
801         else {
802             System.out.println( "failed." );
803             failed++;
804         }
805         System.out.print( "General MSA parser: " );
806         if ( Test.testGeneralMsaParser() ) {
807             System.out.println( "OK." );
808             succeeded++;
809         }
810         else {
811             System.out.println( "failed." );
812             failed++;
813         }
814         System.out.print( "Fasta parser for msa: " );
815         if ( Test.testFastaParser() ) {
816             System.out.println( "OK." );
817             succeeded++;
818         }
819         else {
820             System.out.println( "failed." );
821             failed++;
822         }
823         System.out.print( "Creation of balanced phylogeny: " );
824         if ( Test.testCreateBalancedPhylogeny() ) {
825             System.out.println( "OK." );
826             succeeded++;
827         }
828         else {
829             System.out.println( "failed." );
830             failed++;
831         }
832         System.out.print( "EMBL Entry Retrieval: " );
833         if ( Test.testEmblEntryRetrieval() ) {
834             System.out.println( "OK." );
835             succeeded++;
836         }
837         else {
838             System.out.println( "failed." );
839             failed++;
840         }
841         if ( PERFORM_DB_TESTS ) {
842             System.out.print( "Uniprot Entry Retrieval: " );
843             if ( Test.testUniprotEntryRetrieval() ) {
844                 System.out.println( "OK." );
845                 succeeded++;
846             }
847             else {
848                 System.out.println( "failed." );
849                 failed++;
850             }
851         }
852         if ( PERFORM_DB_TESTS ) {
853             System.out.print( "Uniprot Taxonomy Search: " );
854             if ( Test.testUniprotTaxonomySearch() ) {
855                 System.out.println( "OK." );
856                 succeeded++;
857             }
858             else {
859                 System.out.println( "failed." );
860                 failed++;
861             }
862         }
863         //----
864         String path = "";
865         final String os = ForesterUtil.OS_NAME.toLowerCase();
866         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
867             path = "/usr/local/bin/mafft";
868         }
869         else if ( os.indexOf( "win" ) >= 0 ) {
870             path = "C:\\Program Files\\mafft-win\\mafft.bat";
871         }
872         else {
873             path = "/home/czmasek/bin/mafft";
874         }
875         if ( !MsaInferrer.isInstalled( path ) ) {
876             path = "mafft";
877         }
878         if ( !MsaInferrer.isInstalled( path ) ) {
879             path = "/usr/local/bin/mafft";
880         }
881         if ( MsaInferrer.isInstalled( path ) ) {
882             System.out.print( "MAFFT (external program): " );
883             if ( Test.testMafft( path ) ) {
884                 System.out.println( "OK." );
885                 succeeded++;
886             }
887             else {
888                 System.out.println( "failed [will not count towards failed tests]" );
889             }
890         }
891         //----
892         System.out.print( "Next nodes with collapsed: " );
893         if ( Test.testNextNodeWithCollapsing() ) {
894             System.out.println( "OK." );
895             succeeded++;
896         }
897         else {
898             System.out.println( "failed." );
899             failed++;
900         }
901         System.out.print( "Simple MSA quality: " );
902         if ( Test.testMsaQualityMethod() ) {
903             System.out.println( "OK." );
904             succeeded++;
905         }
906         else {
907             System.out.println( "failed." );
908             failed++;
909         }
910         System.out.println();
911         final Runtime rt = java.lang.Runtime.getRuntime();
912         final long free_memory = rt.freeMemory() / 1000000;
913         final long total_memory = rt.totalMemory() / 1000000;
914         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
915                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
916         System.out.println();
917         System.out.println( "Successful tests: " + succeeded );
918         System.out.println( "Failed     tests: " + failed );
919         System.out.println();
920         if ( failed < 1 ) {
921             System.out.println( "OK." );
922         }
923         else {
924             System.out.println( "Not OK." );
925         }
926     }
927
928     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
929         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
930         return p;
931     }
932
933     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
934         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
935     }
936
937     private static boolean testAminoAcidSequence() {
938         try {
939             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
940             if ( aa1.getLength() != 13 ) {
941                 return false;
942             }
943             if ( aa1.getResidueAt( 0 ) != 'A' ) {
944                 return false;
945             }
946             if ( aa1.getResidueAt( 2 ) != 'K' ) {
947                 return false;
948             }
949             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
950                 return false;
951             }
952             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
953             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
954                 return false;
955             }
956             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
957             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
958                 return false;
959             }
960             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
961             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
962                 return false;
963             }
964         }
965         catch ( final Exception e ) {
966             e.printStackTrace();
967             return false;
968         }
969         return true;
970     }
971
972     private static boolean testBasicDomain() {
973         try {
974             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
975             if ( !pd.getDomainId().equals( "id" ) ) {
976                 return false;
977             }
978             if ( pd.getNumber() != 1 ) {
979                 return false;
980             }
981             if ( pd.getTotalCount() != 4 ) {
982                 return false;
983             }
984             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
985                 return false;
986             }
987             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
988             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
989             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
990             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
991             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
992             if ( !a1.equals( a1 ) ) {
993                 return false;
994             }
995             if ( !a1.equals( a1_copy ) ) {
996                 return false;
997             }
998             if ( !a1.equals( a1_equal ) ) {
999                 return false;
1000             }
1001             if ( !a1.equals( a2 ) ) {
1002                 return false;
1003             }
1004             if ( a1.equals( a3 ) ) {
1005                 return false;
1006             }
1007             if ( a1.compareTo( a1 ) != 0 ) {
1008                 return false;
1009             }
1010             if ( a1.compareTo( a1_copy ) != 0 ) {
1011                 return false;
1012             }
1013             if ( a1.compareTo( a1_equal ) != 0 ) {
1014                 return false;
1015             }
1016             if ( a1.compareTo( a2 ) != 0 ) {
1017                 return false;
1018             }
1019             if ( a1.compareTo( a3 ) == 0 ) {
1020                 return false;
1021             }
1022         }
1023         catch ( final Exception e ) {
1024             e.printStackTrace( System.out );
1025             return false;
1026         }
1027         return true;
1028     }
1029
1030     private static boolean testBasicNodeMethods() {
1031         try {
1032             if ( PhylogenyNode.getNodeCount() != 0 ) {
1033                 return false;
1034             }
1035             final PhylogenyNode n1 = new PhylogenyNode();
1036             final PhylogenyNode n2 = PhylogenyNode
1037                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1038             final PhylogenyNode n3 = PhylogenyNode
1039                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1040             final PhylogenyNode n4 = PhylogenyNode
1041                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1042             if ( n1.isHasAssignedEvent() ) {
1043                 return false;
1044             }
1045             if ( PhylogenyNode.getNodeCount() != 4 ) {
1046                 return false;
1047             }
1048             if ( n3.getIndicator() != 0 ) {
1049                 return false;
1050             }
1051             if ( n3.getNumberOfExternalNodes() != 1 ) {
1052                 return false;
1053             }
1054             if ( !n3.isExternal() ) {
1055                 return false;
1056             }
1057             if ( !n3.isRoot() ) {
1058                 return false;
1059             }
1060             if ( !n4.getName().equals( "n4" ) ) {
1061                 return false;
1062             }
1063         }
1064         catch ( final Exception e ) {
1065             e.printStackTrace( System.out );
1066             return false;
1067         }
1068         return true;
1069     }
1070
1071     private static boolean testBasicPhyloXMLparsing() {
1072         try {
1073             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1074             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1075             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1076                                                               xml_parser );
1077             if ( xml_parser.getErrorCount() > 0 ) {
1078                 System.out.println( xml_parser.getErrorMessages().toString() );
1079                 return false;
1080             }
1081             if ( phylogenies_0.length != 4 ) {
1082                 return false;
1083             }
1084             final Phylogeny t1 = phylogenies_0[ 0 ];
1085             final Phylogeny t2 = phylogenies_0[ 1 ];
1086             final Phylogeny t3 = phylogenies_0[ 2 ];
1087             final Phylogeny t4 = phylogenies_0[ 3 ];
1088             if ( t1.getNumberOfExternalNodes() != 1 ) {
1089                 return false;
1090             }
1091             if ( !t1.isRooted() ) {
1092                 return false;
1093             }
1094             if ( t1.isRerootable() ) {
1095                 return false;
1096             }
1097             if ( !t1.getType().equals( "gene_tree" ) ) {
1098                 return false;
1099             }
1100             if ( t2.getNumberOfExternalNodes() != 2 ) {
1101                 return false;
1102             }
1103             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1104                 return false;
1105             }
1106             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1107                 return false;
1108             }
1109             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1110                 return false;
1111             }
1112             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1113                 return false;
1114             }
1115             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1116                 return false;
1117             }
1118             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1119                 return false;
1120             }
1121             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1122                     .startsWith( "actgtgggggt" ) ) {
1123                 return false;
1124             }
1125             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1126                     .startsWith( "ctgtgatgcat" ) ) {
1127                 return false;
1128             }
1129             if ( t3.getNumberOfExternalNodes() != 4 ) {
1130                 return false;
1131             }
1132             if ( !t1.getName().equals( "t1" ) ) {
1133                 return false;
1134             }
1135             if ( !t2.getName().equals( "t2" ) ) {
1136                 return false;
1137             }
1138             if ( !t3.getName().equals( "t3" ) ) {
1139                 return false;
1140             }
1141             if ( !t4.getName().equals( "t4" ) ) {
1142                 return false;
1143             }
1144             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1145                 return false;
1146             }
1147             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1148                 return false;
1149             }
1150             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1151                 return false;
1152             }
1153             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1154                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1155                 return false;
1156             }
1157             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1158                 return false;
1159             }
1160             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1161                 return false;
1162             }
1163             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
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 ) ).getRef()
1171                     .equals( "GO:0006915" ) ) {
1172                 return false;
1173             }
1174             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1175                     .equals( "UniProtKB" ) ) {
1176                 return false;
1177             }
1178             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1179                     .equals( "experimental" ) ) {
1180                 return false;
1181             }
1182             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1183                     .equals( "function" ) ) {
1184                 return false;
1185             }
1186             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1187                     .getValue() != 1 ) {
1188                 return false;
1189             }
1190             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1191                     .getType().equals( "ml" ) ) {
1192                 return false;
1193             }
1194             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1195                     .equals( "apoptosis" ) ) {
1196                 return false;
1197             }
1198             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1199                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1200                 return false;
1201             }
1202             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1203                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1204                 return false;
1205             }
1206             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1207                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1208                 return false;
1209             }
1210             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1211                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1212                 return false;
1213             }
1214             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1215                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1216                 return false;
1217             }
1218             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1219                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1220                 return false;
1221             }
1222             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1223                     .equals( "GO:0005829" ) ) {
1224                 return false;
1225             }
1226             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1227                     .equals( "intracellular organelle" ) ) {
1228                 return false;
1229             }
1230             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1231                 return false;
1232             }
1233             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1234                     .equals( "UniProt link" ) ) ) {
1235                 return false;
1236             }
1237             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1238                 return false;
1239             }
1240             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1241             if ( x.size() != 4 ) {
1242                 return false;
1243             }
1244             int c = 0;
1245             for( final Accession acc : x ) {
1246                 if ( c == 0 ) {
1247                     if ( !acc.getSource().equals( "KEGG" ) ) {
1248                         return false;
1249                     }
1250                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1251                         return false;
1252                     }
1253                 }
1254                 c++;
1255             }
1256         }
1257         catch ( final Exception e ) {
1258             e.printStackTrace( System.out );
1259             return false;
1260         }
1261         return true;
1262     }
1263
1264     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1265         try {
1266             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1267             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1268             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1269                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1270             }
1271             else {
1272                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1273             }
1274             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1275                                                               xml_parser );
1276             if ( xml_parser.getErrorCount() > 0 ) {
1277                 System.out.println( xml_parser.getErrorMessages().toString() );
1278                 return false;
1279             }
1280             if ( phylogenies_0.length != 4 ) {
1281                 return false;
1282             }
1283             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1284             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1285             if ( phylogenies_t1.length != 1 ) {
1286                 return false;
1287             }
1288             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1289             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1290                 return false;
1291             }
1292             if ( !t1_rt.isRooted() ) {
1293                 return false;
1294             }
1295             if ( t1_rt.isRerootable() ) {
1296                 return false;
1297             }
1298             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1299                 return false;
1300             }
1301             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1302             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1303             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1304             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1305                 return false;
1306             }
1307             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1308                 return false;
1309             }
1310             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1311                 return false;
1312             }
1313             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1314                 return false;
1315             }
1316             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1317                     .startsWith( "actgtgggggt" ) ) {
1318                 return false;
1319             }
1320             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1321                     .startsWith( "ctgtgatgcat" ) ) {
1322                 return false;
1323             }
1324             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1325             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1326             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1327             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1328             if ( phylogenies_1.length != 1 ) {
1329                 return false;
1330             }
1331             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1332             if ( !t3_rt.getName().equals( "t3" ) ) {
1333                 return false;
1334             }
1335             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1336                 return false;
1337             }
1338             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1339                 return false;
1340             }
1341             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1342                 return false;
1343             }
1344             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1345                 return false;
1346             }
1347             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1348                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1349                 return false;
1350             }
1351             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1352                 return false;
1353             }
1354             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1355                 return false;
1356             }
1357             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1358                     .equals( "UniProtKB" ) ) {
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 ) ).getRef()
1366                     .equals( "GO:0006915" ) ) {
1367                 return false;
1368             }
1369             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1370                     .equals( "UniProtKB" ) ) {
1371                 return false;
1372             }
1373             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1374                     .equals( "experimental" ) ) {
1375                 return false;
1376             }
1377             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1378                     .equals( "function" ) ) {
1379                 return false;
1380             }
1381             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1382                     .getValue() != 1 ) {
1383                 return false;
1384             }
1385             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1386                     .getType().equals( "ml" ) ) {
1387                 return false;
1388             }
1389             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1390                     .equals( "apoptosis" ) ) {
1391                 return false;
1392             }
1393             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1394                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1395                 return false;
1396             }
1397             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1398                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1399                 return false;
1400             }
1401             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1402                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1403                 return false;
1404             }
1405             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1406                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1407                 return false;
1408             }
1409             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1410                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1411                 return false;
1412             }
1413             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1414                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1415                 return false;
1416             }
1417             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1418                     .equals( "GO:0005829" ) ) {
1419                 return false;
1420             }
1421             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1422                     .equals( "intracellular organelle" ) ) {
1423                 return false;
1424             }
1425             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1426                 return false;
1427             }
1428             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1429                     .equals( "UniProt link" ) ) ) {
1430                 return false;
1431             }
1432             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1433                 return false;
1434             }
1435             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1436                 return false;
1437             }
1438             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1439                     .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." ) ) ) {
1440                 return false;
1441             }
1442             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1443                 return false;
1444             }
1445             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1446                 return false;
1447             }
1448             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1449                 return false;
1450             }
1451             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1452                 return false;
1453             }
1454             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1455                     .equals( "ncbi" ) ) {
1456                 return false;
1457             }
1458             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1459                 return false;
1460             }
1461             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1462                     .getName().equals( "B" ) ) {
1463                 return false;
1464             }
1465             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1466                     .getFrom() != 21 ) {
1467                 return false;
1468             }
1469             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1470                 return false;
1471             }
1472             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1473                     .getLength() != 24 ) {
1474                 return false;
1475             }
1476             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1477                     .getConfidence() != 2144 ) {
1478                 return false;
1479             }
1480             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1481                     .equals( "pfam" ) ) {
1482                 return false;
1483             }
1484             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1485                 return false;
1486             }
1487             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1488                 return false;
1489             }
1490             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1491                 return false;
1492             }
1493             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1494                 return false;
1495             }
1496             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1497             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1498                 return false;
1499             }
1500             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1501                 return false;
1502             }
1503             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1504                 return false;
1505             }
1506             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1507                 return false;
1508             }
1509             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1510                 return false;
1511             }
1512             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1513                 return false;
1514             }
1515             if ( taxbb.getSynonyms().size() != 2 ) {
1516                 return false;
1517             }
1518             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1519                 return false;
1520             }
1521             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1522                 return false;
1523             }
1524             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1525                 return false;
1526             }
1527             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1528                 return false;
1529             }
1530             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1531                 return false;
1532             }
1533             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1534                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1535                 return false;
1536             }
1537             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1538                 return false;
1539             }
1540             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1541                 return false;
1542             }
1543             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1544                 return false;
1545             }
1546             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1547                 return false;
1548             }
1549             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1550                 return false;
1551             }
1552             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1553                 return false;
1554             }
1555             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1556                 return false;
1557             }
1558             //
1559             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1560                 return false;
1561             }
1562             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1563                     .equalsIgnoreCase( "435" ) ) {
1564                 return false;
1565             }
1566             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1567                 return false;
1568             }
1569             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1570                     .equalsIgnoreCase( "443.7" ) ) {
1571                 return false;
1572             }
1573             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1574                 return false;
1575             }
1576             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1577                 return false;
1578             }
1579             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1580                     .equalsIgnoreCase( "433" ) ) {
1581                 return false;
1582             }
1583             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
1584                     .getCrossReferences();
1585             if ( x.size() != 4 ) {
1586                 return false;
1587             }
1588             int c = 0;
1589             for( final Accession acc : x ) {
1590                 if ( c == 0 ) {
1591                     if ( !acc.getSource().equals( "KEGG" ) ) {
1592                         return false;
1593                     }
1594                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1595                         return false;
1596                     }
1597                 }
1598                 c++;
1599             }
1600         }
1601         catch ( final Exception e ) {
1602             e.printStackTrace( System.out );
1603             return false;
1604         }
1605         return true;
1606     }
1607
1608     private static boolean testBasicPhyloXMLparsingValidating() {
1609         try {
1610             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1611             PhyloXmlParser xml_parser = null;
1612             try {
1613                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1614             }
1615             catch ( final Exception e ) {
1616                 // Do nothing -- means were not running from jar.
1617             }
1618             if ( xml_parser == null ) {
1619                 xml_parser = new PhyloXmlParser();
1620                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1621                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1622                 }
1623                 else {
1624                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1625                 }
1626             }
1627             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1628                                                               xml_parser );
1629             if ( xml_parser.getErrorCount() > 0 ) {
1630                 System.out.println( xml_parser.getErrorMessages().toString() );
1631                 return false;
1632             }
1633             if ( phylogenies_0.length != 4 ) {
1634                 return false;
1635             }
1636             final Phylogeny t1 = phylogenies_0[ 0 ];
1637             final Phylogeny t2 = phylogenies_0[ 1 ];
1638             final Phylogeny t3 = phylogenies_0[ 2 ];
1639             final Phylogeny t4 = phylogenies_0[ 3 ];
1640             if ( !t1.getName().equals( "t1" ) ) {
1641                 return false;
1642             }
1643             if ( !t2.getName().equals( "t2" ) ) {
1644                 return false;
1645             }
1646             if ( !t3.getName().equals( "t3" ) ) {
1647                 return false;
1648             }
1649             if ( !t4.getName().equals( "t4" ) ) {
1650                 return false;
1651             }
1652             if ( t1.getNumberOfExternalNodes() != 1 ) {
1653                 return false;
1654             }
1655             if ( t2.getNumberOfExternalNodes() != 2 ) {
1656                 return false;
1657             }
1658             if ( t3.getNumberOfExternalNodes() != 4 ) {
1659                 return false;
1660             }
1661             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1662             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1663             if ( xml_parser.getErrorCount() > 0 ) {
1664                 System.out.println( "errors:" );
1665                 System.out.println( xml_parser.getErrorMessages().toString() );
1666                 return false;
1667             }
1668             if ( phylogenies_1.length != 4 ) {
1669                 return false;
1670             }
1671             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1672                                                               xml_parser );
1673             if ( xml_parser.getErrorCount() > 0 ) {
1674                 System.out.println( "errors:" );
1675                 System.out.println( xml_parser.getErrorMessages().toString() );
1676                 return false;
1677             }
1678             if ( phylogenies_2.length != 1 ) {
1679                 return false;
1680             }
1681             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1682                 return false;
1683             }
1684             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1685                                                               xml_parser );
1686             if ( xml_parser.getErrorCount() > 0 ) {
1687                 System.out.println( xml_parser.getErrorMessages().toString() );
1688                 return false;
1689             }
1690             if ( phylogenies_3.length != 2 ) {
1691                 return false;
1692             }
1693             final Phylogeny a = phylogenies_3[ 0 ];
1694             if ( !a.getName().equals( "tree 4" ) ) {
1695                 return false;
1696             }
1697             if ( a.getNumberOfExternalNodes() != 3 ) {
1698                 return false;
1699             }
1700             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1701                 return false;
1702             }
1703             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1704                 return false;
1705             }
1706             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1707                                                               xml_parser );
1708             if ( xml_parser.getErrorCount() > 0 ) {
1709                 System.out.println( xml_parser.getErrorMessages().toString() );
1710                 return false;
1711             }
1712             if ( phylogenies_4.length != 1 ) {
1713                 return false;
1714             }
1715             final Phylogeny s = phylogenies_4[ 0 ];
1716             if ( s.getNumberOfExternalNodes() != 6 ) {
1717                 return false;
1718             }
1719             s.getNode( "first" );
1720             s.getNode( "<>" );
1721             s.getNode( "\"<a'b&c'd\">\"" );
1722             s.getNode( "'''\"" );
1723             s.getNode( "\"\"\"" );
1724             s.getNode( "dick & doof" );
1725         }
1726         catch ( final Exception e ) {
1727             e.printStackTrace( System.out );
1728             return false;
1729         }
1730         return true;
1731     }
1732
1733     private static boolean testBasicProtein() {
1734         try {
1735             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
1736             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1737             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1738             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1739             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1740             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1741             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1742             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1743             p0.addProteinDomain( y );
1744             p0.addProteinDomain( e );
1745             p0.addProteinDomain( b );
1746             p0.addProteinDomain( c );
1747             p0.addProteinDomain( d );
1748             p0.addProteinDomain( a );
1749             p0.addProteinDomain( x );
1750             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
1751                 return false;
1752             }
1753             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
1754                 return false;
1755             }
1756             //
1757             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
1758             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1759             aa0.addProteinDomain( a1 );
1760             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
1761                 return false;
1762             }
1763             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
1764                 return false;
1765             }
1766             //
1767             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
1768             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1769             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1770             aa1.addProteinDomain( a11 );
1771             aa1.addProteinDomain( a12 );
1772             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
1773                 return false;
1774             }
1775             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
1776                 return false;
1777             }
1778             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1779             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
1780                 return false;
1781             }
1782             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1783                 return false;
1784             }
1785             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
1786                 return false;
1787             }
1788             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1789             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
1790                 return false;
1791             }
1792             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1793                 return false;
1794             }
1795             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
1796                 return false;
1797             }
1798             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
1799                 return false;
1800             }
1801             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1802             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
1803                 return false;
1804             }
1805             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
1806                 return false;
1807             }
1808             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
1809                 return false;
1810             }
1811             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
1812                 return false;
1813             }
1814             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1815             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
1816                 return false;
1817             }
1818             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
1819                 return false;
1820             }
1821             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
1822                 return false;
1823             }
1824             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
1825                 return false;
1826             }
1827             //
1828             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
1829             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1830             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1831             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1832             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1833             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1834             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
1835             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
1836             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
1837             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
1838             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
1839             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1840             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1841             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
1842             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
1843             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
1844             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
1845             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
1846             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
1847             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
1848             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
1849             p00.addProteinDomain( y0 );
1850             p00.addProteinDomain( e0 );
1851             p00.addProteinDomain( b0 );
1852             p00.addProteinDomain( c0 );
1853             p00.addProteinDomain( d0 );
1854             p00.addProteinDomain( a0 );
1855             p00.addProteinDomain( x0 );
1856             p00.addProteinDomain( y1 );
1857             p00.addProteinDomain( y2 );
1858             p00.addProteinDomain( y3 );
1859             p00.addProteinDomain( e1 );
1860             p00.addProteinDomain( e2 );
1861             p00.addProteinDomain( e3 );
1862             p00.addProteinDomain( e4 );
1863             p00.addProteinDomain( e5 );
1864             p00.addProteinDomain( z0 );
1865             p00.addProteinDomain( z1 );
1866             p00.addProteinDomain( z2 );
1867             p00.addProteinDomain( zz0 );
1868             p00.addProteinDomain( zz1 );
1869             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
1870                 return false;
1871             }
1872             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
1873                 return false;
1874             }
1875             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1876                 return false;
1877             }
1878             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1879                 return false;
1880             }
1881             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" ) ) {
1882                 return false;
1883             }
1884             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
1885             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1886             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
1887             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
1888             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
1889             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
1890             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
1891             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
1892             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
1893             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
1894             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
1895             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
1896             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
1897             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
1898             p.addProteinDomain( B15 );
1899             p.addProteinDomain( C50 );
1900             p.addProteinDomain( A60 );
1901             p.addProteinDomain( A30 );
1902             p.addProteinDomain( C70 );
1903             p.addProteinDomain( B35 );
1904             p.addProteinDomain( B40 );
1905             p.addProteinDomain( A0 );
1906             p.addProteinDomain( A10 );
1907             p.addProteinDomain( A20 );
1908             p.addProteinDomain( B25 );
1909             p.addProteinDomain( D80 );
1910             List<String> domains_ids = new ArrayList<String>();
1911             domains_ids.add( "A" );
1912             domains_ids.add( "B" );
1913             domains_ids.add( "C" );
1914             if ( !p.contains( domains_ids, false ) ) {
1915                 return false;
1916             }
1917             if ( !p.contains( domains_ids, true ) ) {
1918                 return false;
1919             }
1920             domains_ids.add( "X" );
1921             if ( p.contains( domains_ids, false ) ) {
1922                 return false;
1923             }
1924             if ( p.contains( domains_ids, true ) ) {
1925                 return false;
1926             }
1927             domains_ids = new ArrayList<String>();
1928             domains_ids.add( "A" );
1929             domains_ids.add( "C" );
1930             domains_ids.add( "D" );
1931             if ( !p.contains( domains_ids, false ) ) {
1932                 return false;
1933             }
1934             if ( !p.contains( domains_ids, true ) ) {
1935                 return false;
1936             }
1937             domains_ids = new ArrayList<String>();
1938             domains_ids.add( "A" );
1939             domains_ids.add( "D" );
1940             domains_ids.add( "C" );
1941             if ( !p.contains( domains_ids, false ) ) {
1942                 return false;
1943             }
1944             if ( p.contains( domains_ids, true ) ) {
1945                 return false;
1946             }
1947             domains_ids = new ArrayList<String>();
1948             domains_ids.add( "A" );
1949             domains_ids.add( "A" );
1950             domains_ids.add( "B" );
1951             if ( !p.contains( domains_ids, false ) ) {
1952                 return false;
1953             }
1954             if ( !p.contains( domains_ids, true ) ) {
1955                 return false;
1956             }
1957             domains_ids = new ArrayList<String>();
1958             domains_ids.add( "A" );
1959             domains_ids.add( "A" );
1960             domains_ids.add( "A" );
1961             domains_ids.add( "B" );
1962             domains_ids.add( "B" );
1963             if ( !p.contains( domains_ids, false ) ) {
1964                 return false;
1965             }
1966             if ( !p.contains( domains_ids, true ) ) {
1967                 return false;
1968             }
1969             domains_ids = new ArrayList<String>();
1970             domains_ids.add( "A" );
1971             domains_ids.add( "A" );
1972             domains_ids.add( "B" );
1973             domains_ids.add( "A" );
1974             domains_ids.add( "B" );
1975             domains_ids.add( "B" );
1976             domains_ids.add( "A" );
1977             domains_ids.add( "B" );
1978             domains_ids.add( "C" );
1979             domains_ids.add( "A" );
1980             domains_ids.add( "C" );
1981             domains_ids.add( "D" );
1982             if ( !p.contains( domains_ids, false ) ) {
1983                 return false;
1984             }
1985             if ( p.contains( domains_ids, true ) ) {
1986                 return false;
1987             }
1988         }
1989         catch ( final Exception e ) {
1990             e.printStackTrace( System.out );
1991             return false;
1992         }
1993         return true;
1994     }
1995
1996     private static boolean testBasicTable() {
1997         try {
1998             final BasicTable<String> t0 = new BasicTable<String>();
1999             if ( t0.getNumberOfColumns() != 0 ) {
2000                 return false;
2001             }
2002             if ( t0.getNumberOfRows() != 0 ) {
2003                 return false;
2004             }
2005             t0.setValue( 3, 2, "23" );
2006             t0.setValue( 10, 1, "error" );
2007             t0.setValue( 10, 1, "110" );
2008             t0.setValue( 9, 1, "19" );
2009             t0.setValue( 1, 10, "101" );
2010             t0.setValue( 10, 10, "1010" );
2011             t0.setValue( 100, 10, "10100" );
2012             t0.setValue( 0, 0, "00" );
2013             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2014                 return false;
2015             }
2016             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2017                 return false;
2018             }
2019             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2020                 return false;
2021             }
2022             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2023                 return false;
2024             }
2025             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2026                 return false;
2027             }
2028             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2029                 return false;
2030             }
2031             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2032                 return false;
2033             }
2034             if ( t0.getNumberOfColumns() != 101 ) {
2035                 return false;
2036             }
2037             if ( t0.getNumberOfRows() != 11 ) {
2038                 return false;
2039             }
2040             if ( t0.getValueAsString( 49, 4 ) != null ) {
2041                 return false;
2042             }
2043             final String l = ForesterUtil.getLineSeparator();
2044             final StringBuffer source = new StringBuffer();
2045             source.append( "" + l );
2046             source.append( "# 1 1 1 1 1 1 1 1" + l );
2047             source.append( " 00 01 02 03" + l );
2048             source.append( "   10 11 12 13  " + l );
2049             source.append( "20 21 22 23 " + l );
2050             source.append( "    30  31    32 33" + l );
2051             source.append( "40 41 42 43" + l );
2052             source.append( "  # 1 1 1 1 1 " + l );
2053             source.append( "50 51 52 53 54" + l );
2054             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2055             if ( t1.getNumberOfColumns() != 5 ) {
2056                 return false;
2057             }
2058             if ( t1.getNumberOfRows() != 6 ) {
2059                 return false;
2060             }
2061             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2062                 return false;
2063             }
2064             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2065                 return false;
2066             }
2067             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2068                 return false;
2069             }
2070             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2071                 return false;
2072             }
2073             final StringBuffer source1 = new StringBuffer();
2074             source1.append( "" + l );
2075             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2076             source1.append( " 00; 01 ;02;03" + l );
2077             source1.append( "   10; 11; 12; 13  " + l );
2078             source1.append( "20; 21; 22; 23 " + l );
2079             source1.append( "    30;  31;    32; 33" + l );
2080             source1.append( "40;41;42;43" + l );
2081             source1.append( "  # 1 1 1 1 1 " + l );
2082             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2083             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2084             if ( t2.getNumberOfColumns() != 5 ) {
2085                 return false;
2086             }
2087             if ( t2.getNumberOfRows() != 6 ) {
2088                 return false;
2089             }
2090             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2091                 return false;
2092             }
2093             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2094                 return false;
2095             }
2096             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2097                 return false;
2098             }
2099             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2100                 return false;
2101             }
2102             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2103                 return false;
2104             }
2105             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2106                 return false;
2107             }
2108             final StringBuffer source2 = new StringBuffer();
2109             source2.append( "" + l );
2110             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2111             source2.append( " 00; 01 ;02;03" + l );
2112             source2.append( "   10; 11; 12; 13  " + l );
2113             source2.append( "20; 21; 22; 23 " + l );
2114             source2.append( "                     " + l );
2115             source2.append( "    30;  31;    32; 33" + l );
2116             source2.append( "40;41;42;43" + l );
2117             source2.append( "  comment: 1 1 1 1 1 " + l );
2118             source2.append( ";;;50  ;   52; 53;;54   " + l );
2119             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2120                                                                         ';',
2121                                                                         false,
2122                                                                         false,
2123                                                                         "comment:",
2124                                                                         false );
2125             if ( tl.size() != 2 ) {
2126                 return false;
2127             }
2128             final BasicTable<String> t3 = tl.get( 0 );
2129             final BasicTable<String> t4 = tl.get( 1 );
2130             if ( t3.getNumberOfColumns() != 4 ) {
2131                 return false;
2132             }
2133             if ( t3.getNumberOfRows() != 3 ) {
2134                 return false;
2135             }
2136             if ( t4.getNumberOfColumns() != 4 ) {
2137                 return false;
2138             }
2139             if ( t4.getNumberOfRows() != 3 ) {
2140                 return false;
2141             }
2142             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2143                 return false;
2144             }
2145             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2146                 return false;
2147             }
2148         }
2149         catch ( final Exception e ) {
2150             e.printStackTrace( System.out );
2151             return false;
2152         }
2153         return true;
2154     }
2155
2156     private static boolean testBasicTolXMLparsing() {
2157         try {
2158             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2159             final TolParser parser = new TolParser();
2160             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2161             if ( parser.getErrorCount() > 0 ) {
2162                 System.out.println( parser.getErrorMessages().toString() );
2163                 return false;
2164             }
2165             if ( phylogenies_0.length != 1 ) {
2166                 return false;
2167             }
2168             final Phylogeny t1 = phylogenies_0[ 0 ];
2169             if ( t1.getNumberOfExternalNodes() != 5 ) {
2170                 return false;
2171             }
2172             if ( !t1.isRooted() ) {
2173                 return false;
2174             }
2175             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2176                 return false;
2177             }
2178             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2179                 return false;
2180             }
2181             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2182                 return false;
2183             }
2184             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2185                 return false;
2186             }
2187             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2188             if ( parser.getErrorCount() > 0 ) {
2189                 System.out.println( parser.getErrorMessages().toString() );
2190                 return false;
2191             }
2192             if ( phylogenies_1.length != 1 ) {
2193                 return false;
2194             }
2195             final Phylogeny t2 = phylogenies_1[ 0 ];
2196             if ( t2.getNumberOfExternalNodes() != 664 ) {
2197                 return false;
2198             }
2199             if ( !t2.isRooted() ) {
2200                 return false;
2201             }
2202             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2203                 return false;
2204             }
2205             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2206                 return false;
2207             }
2208             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2209                 return false;
2210             }
2211             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2212                 return false;
2213             }
2214             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2215                 return false;
2216             }
2217             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2218                     .equals( "Aquifex" ) ) {
2219                 return false;
2220             }
2221             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2222             if ( parser.getErrorCount() > 0 ) {
2223                 System.out.println( parser.getErrorMessages().toString() );
2224                 return false;
2225             }
2226             if ( phylogenies_2.length != 1 ) {
2227                 return false;
2228             }
2229             final Phylogeny t3 = phylogenies_2[ 0 ];
2230             if ( t3.getNumberOfExternalNodes() != 184 ) {
2231                 return false;
2232             }
2233             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2234                 return false;
2235             }
2236             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2237                 return false;
2238             }
2239             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2240                 return false;
2241             }
2242             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2243             if ( parser.getErrorCount() > 0 ) {
2244                 System.out.println( parser.getErrorMessages().toString() );
2245                 return false;
2246             }
2247             if ( phylogenies_3.length != 1 ) {
2248                 return false;
2249             }
2250             final Phylogeny t4 = phylogenies_3[ 0 ];
2251             if ( t4.getNumberOfExternalNodes() != 1 ) {
2252                 return false;
2253             }
2254             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2255                 return false;
2256             }
2257             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2258                 return false;
2259             }
2260             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2261                 return false;
2262             }
2263             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2264             if ( parser.getErrorCount() > 0 ) {
2265                 System.out.println( parser.getErrorMessages().toString() );
2266                 return false;
2267             }
2268             if ( phylogenies_4.length != 1 ) {
2269                 return false;
2270             }
2271             final Phylogeny t5 = phylogenies_4[ 0 ];
2272             if ( t5.getNumberOfExternalNodes() != 13 ) {
2273                 return false;
2274             }
2275             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2276                 return false;
2277             }
2278             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2279                 return false;
2280             }
2281             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2282                 return false;
2283             }
2284         }
2285         catch ( final Exception e ) {
2286             e.printStackTrace( System.out );
2287             return false;
2288         }
2289         return true;
2290     }
2291
2292     private static boolean testBasicTreeMethods() {
2293         try {
2294             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2295             final Phylogeny t1 = factory.create();
2296             if ( !t1.isEmpty() ) {
2297                 return false;
2298             }
2299             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2300             if ( t2.getNumberOfExternalNodes() != 4 ) {
2301                 return false;
2302             }
2303             if ( t2.getHeight() != 8.5 ) {
2304                 return false;
2305             }
2306             if ( !t2.isCompletelyBinary() ) {
2307                 return false;
2308             }
2309             if ( t2.isEmpty() ) {
2310                 return false;
2311             }
2312             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2313             if ( t3.getNumberOfExternalNodes() != 5 ) {
2314                 return false;
2315             }
2316             if ( t3.getHeight() != 11 ) {
2317                 return false;
2318             }
2319             if ( t3.isCompletelyBinary() ) {
2320                 return false;
2321             }
2322             final PhylogenyNode n = t3.getNode( "ABC" );
2323             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 ];
2324             if ( t4.getNumberOfExternalNodes() != 9 ) {
2325                 return false;
2326             }
2327             if ( t4.getHeight() != 11 ) {
2328                 return false;
2329             }
2330             if ( t4.isCompletelyBinary() ) {
2331                 return false;
2332             }
2333             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)" );
2334             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2335             if ( t5.getNumberOfExternalNodes() != 8 ) {
2336                 return false;
2337             }
2338             if ( t5.getHeight() != 15 ) {
2339                 return false;
2340             }
2341             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)" );
2342             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2343             if ( t6.getHeight() != 15 ) {
2344                 return false;
2345             }
2346             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)" );
2347             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2348             if ( t7.getHeight() != 15 ) {
2349                 return false;
2350             }
2351             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)" );
2352             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2353             if ( t8.getNumberOfExternalNodes() != 10 ) {
2354                 return false;
2355             }
2356             if ( t8.getHeight() != 15 ) {
2357                 return false;
2358             }
2359             final char[] a9 = new char[] { 'a' };
2360             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2361             if ( t9.getHeight() != 0 ) {
2362                 return false;
2363             }
2364             final char[] a10 = new char[] { 'a', ':', '6' };
2365             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2366             if ( t10.getHeight() != 6 ) {
2367                 return false;
2368             }
2369         }
2370         catch ( final Exception e ) {
2371             e.printStackTrace( System.out );
2372             return false;
2373         }
2374         return true;
2375     }
2376
2377     private static boolean testConfidenceAssessor() {
2378         try {
2379             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2380             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2381             final Phylogeny[] ev0 = factory
2382                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2383                              new NHXParser() );
2384             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2385             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2386                 return false;
2387             }
2388             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2389                 return false;
2390             }
2391             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2392             final Phylogeny[] ev1 = factory
2393                     .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)));",
2394                              new NHXParser() );
2395             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2396             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2397                 return false;
2398             }
2399             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2400                 return false;
2401             }
2402             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2403             final Phylogeny[] ev_b = factory
2404                     .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",
2405                              new NHXParser() );
2406             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2407             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2408                 return false;
2409             }
2410             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2411                 return false;
2412             }
2413             //
2414             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2415             final Phylogeny[] ev1x = factory
2416                     .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)));",
2417                              new NHXParser() );
2418             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2419             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2420                 return false;
2421             }
2422             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2423                 return false;
2424             }
2425             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2426             final Phylogeny[] ev_bx = factory
2427                     .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",
2428                              new NHXParser() );
2429             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2430             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2431                 return false;
2432             }
2433             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2434                 return false;
2435             }
2436             //
2437             final Phylogeny[] t2 = factory
2438                     .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);",
2439                              new NHXParser() );
2440             final Phylogeny[] ev2 = factory
2441                     .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);",
2442                              new NHXParser() );
2443             for( final Phylogeny target : t2 ) {
2444                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2445             }
2446             //
2447             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2448                                                  new NHXParser() )[ 0 ];
2449             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2450             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2451             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2452                 return false;
2453             }
2454             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2455                 return false;
2456             }
2457             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2458                 return false;
2459             }
2460         }
2461         catch ( final Exception e ) {
2462             e.printStackTrace();
2463             return false;
2464         }
2465         return true;
2466     }
2467
2468     private static boolean testCopyOfNodeData() {
2469         try {
2470             final PhylogenyNode n1 = PhylogenyNode
2471                     .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]" );
2472             final PhylogenyNode n2 = n1.copyNodeData();
2473             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2474                 return false;
2475             }
2476         }
2477         catch ( final Exception e ) {
2478             e.printStackTrace();
2479             return false;
2480         }
2481         return true;
2482     }
2483
2484     private static boolean testCreateBalancedPhylogeny() {
2485         try {
2486             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2487             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2488                 return false;
2489             }
2490             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2491                 return false;
2492             }
2493             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2494             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2495                 return false;
2496             }
2497             if ( p1.getNumberOfExternalNodes() != 100 ) {
2498                 return false;
2499             }
2500         }
2501         catch ( final Exception e ) {
2502             e.printStackTrace();
2503             return false;
2504         }
2505         return true;
2506     }
2507
2508     private static boolean testCreateUriForSeqWeb() {
2509         try {
2510             final PhylogenyNode n = new PhylogenyNode();
2511             n.setName( "tr|B3RJ64" );
2512             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2513                 return false;
2514             }
2515             n.setName( "B0LM41_HUMAN" );
2516             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2517                 return false;
2518             }
2519             n.setName( "NP_001025424" );
2520             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2521                 return false;
2522             }
2523             n.setName( "_NM_001030253-" );
2524             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2525                 return false;
2526             }
2527             n.setName( "XM_002122186" );
2528             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2529                 return false;
2530             }
2531             n.setName( "dgh_AAA34956_gdg" );
2532             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2533                 return false;
2534             }
2535             n.setName( "AAA34956" );
2536             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2537                 return false;
2538             }
2539             n.setName( "GI:394892" );
2540             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2541                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2542                 return false;
2543             }
2544             n.setName( "gi_394892" );
2545             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2546                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2547                 return false;
2548             }
2549             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2550             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2551                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2552                 return false;
2553             }
2554             n.setName( "P12345" );
2555             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2556                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2557                 return false;
2558             }
2559             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
2560             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2561                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2562                 return false;
2563             }
2564         }
2565         catch ( final Exception e ) {
2566             e.printStackTrace( System.out );
2567             return false;
2568         }
2569         return true;
2570     }
2571
2572     private static boolean testDataObjects() {
2573         try {
2574             final Confidence s0 = new Confidence();
2575             final Confidence s1 = new Confidence();
2576             if ( !s0.isEqual( s1 ) ) {
2577                 return false;
2578             }
2579             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2580             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2581             if ( s2.isEqual( s1 ) ) {
2582                 return false;
2583             }
2584             if ( !s2.isEqual( s3 ) ) {
2585                 return false;
2586             }
2587             final Confidence s4 = ( Confidence ) s3.copy();
2588             if ( !s4.isEqual( s3 ) ) {
2589                 return false;
2590             }
2591             s3.asSimpleText();
2592             s3.asText();
2593             // Taxonomy
2594             // ----------
2595             final Taxonomy t1 = new Taxonomy();
2596             final Taxonomy t2 = new Taxonomy();
2597             final Taxonomy t3 = new Taxonomy();
2598             final Taxonomy t4 = new Taxonomy();
2599             final Taxonomy t5 = new Taxonomy();
2600             t1.setIdentifier( new Identifier( "ecoli" ) );
2601             t1.setTaxonomyCode( "ECOLI" );
2602             t1.setScientificName( "E. coli" );
2603             t1.setCommonName( "coli" );
2604             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2605             if ( !t1.isEqual( t0 ) ) {
2606                 return false;
2607             }
2608             t2.setIdentifier( new Identifier( "ecoli" ) );
2609             t2.setTaxonomyCode( "OTHER" );
2610             t2.setScientificName( "what" );
2611             t2.setCommonName( "something" );
2612             if ( !t1.isEqual( t2 ) ) {
2613                 return false;
2614             }
2615             t2.setIdentifier( new Identifier( "nemve" ) );
2616             if ( t1.isEqual( t2 ) ) {
2617                 return false;
2618             }
2619             t1.setIdentifier( null );
2620             t3.setTaxonomyCode( "ECOLI" );
2621             t3.setScientificName( "what" );
2622             t3.setCommonName( "something" );
2623             if ( !t1.isEqual( t3 ) ) {
2624                 return false;
2625             }
2626             t1.setIdentifier( null );
2627             t1.setTaxonomyCode( "" );
2628             t4.setScientificName( "E. ColI" );
2629             t4.setCommonName( "something" );
2630             if ( !t1.isEqual( t4 ) ) {
2631                 return false;
2632             }
2633             t4.setScientificName( "B. subtilis" );
2634             t4.setCommonName( "something" );
2635             if ( t1.isEqual( t4 ) ) {
2636                 return false;
2637             }
2638             t1.setIdentifier( null );
2639             t1.setTaxonomyCode( "" );
2640             t1.setScientificName( "" );
2641             t5.setCommonName( "COLI" );
2642             if ( !t1.isEqual( t5 ) ) {
2643                 return false;
2644             }
2645             t5.setCommonName( "vibrio" );
2646             if ( t1.isEqual( t5 ) ) {
2647                 return false;
2648             }
2649             // Identifier
2650             // ----------
2651             final Identifier id0 = new Identifier( "123", "pfam" );
2652             final Identifier id1 = ( Identifier ) id0.copy();
2653             if ( !id1.isEqual( id1 ) ) {
2654                 return false;
2655             }
2656             if ( !id1.isEqual( id0 ) ) {
2657                 return false;
2658             }
2659             if ( !id0.isEqual( id1 ) ) {
2660                 return false;
2661             }
2662             id1.asSimpleText();
2663             id1.asText();
2664             // ProteinDomain
2665             // ---------------
2666             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2667             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2668             if ( !pd1.isEqual( pd1 ) ) {
2669                 return false;
2670             }
2671             if ( !pd1.isEqual( pd0 ) ) {
2672                 return false;
2673             }
2674             pd1.asSimpleText();
2675             pd1.asText();
2676             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2677             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2678             if ( !pd3.isEqual( pd3 ) ) {
2679                 return false;
2680             }
2681             if ( !pd2.isEqual( pd3 ) ) {
2682                 return false;
2683             }
2684             if ( !pd0.isEqual( pd3 ) ) {
2685                 return false;
2686             }
2687             pd3.asSimpleText();
2688             pd3.asText();
2689             // DomainArchitecture
2690             // ------------------
2691             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2692             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2693             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2694             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2695             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2696             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2697             domains0.add( d2 );
2698             domains0.add( d0 );
2699             domains0.add( d3 );
2700             domains0.add( d1 );
2701             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2702             if ( ds0.getNumberOfDomains() != 4 ) {
2703                 return false;
2704             }
2705             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2706             if ( !ds0.isEqual( ds0 ) ) {
2707                 return false;
2708             }
2709             if ( !ds0.isEqual( ds1 ) ) {
2710                 return false;
2711             }
2712             if ( ds1.getNumberOfDomains() != 4 ) {
2713                 return false;
2714             }
2715             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2716             domains1.add( d1 );
2717             domains1.add( d2 );
2718             domains1.add( d4 );
2719             domains1.add( d0 );
2720             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2721             if ( ds0.isEqual( ds2 ) ) {
2722                 return false;
2723             }
2724             ds1.asSimpleText();
2725             ds1.asText();
2726             ds1.toNHX();
2727             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2728             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2729                 System.out.println( ds3.toNHX() );
2730                 return false;
2731             }
2732             if ( ds3.getNumberOfDomains() != 3 ) {
2733                 return false;
2734             }
2735             // Event
2736             // -----
2737             final Event e1 = new Event( Event.EventType.fusion );
2738             if ( e1.isDuplication() ) {
2739                 return false;
2740             }
2741             if ( !e1.isFusion() ) {
2742                 return false;
2743             }
2744             if ( !e1.asText().toString().equals( "fusion" ) ) {
2745                 return false;
2746             }
2747             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2748                 return false;
2749             }
2750             final Event e11 = new Event( Event.EventType.fusion );
2751             if ( !e11.isEqual( e1 ) ) {
2752                 return false;
2753             }
2754             if ( !e11.toNHX().toString().equals( "" ) ) {
2755                 return false;
2756             }
2757             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2758             if ( e2.isDuplication() ) {
2759                 return false;
2760             }
2761             if ( !e2.isSpeciationOrDuplication() ) {
2762                 return false;
2763             }
2764             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2765                 return false;
2766             }
2767             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2768                 return false;
2769             }
2770             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2771                 return false;
2772             }
2773             if ( e11.isEqual( e2 ) ) {
2774                 return false;
2775             }
2776             final Event e2c = ( Event ) e2.copy();
2777             if ( !e2c.isEqual( e2 ) ) {
2778                 return false;
2779             }
2780             Event e3 = new Event( 1, 2, 3 );
2781             if ( e3.isDuplication() ) {
2782                 return false;
2783             }
2784             if ( e3.isSpeciation() ) {
2785                 return false;
2786             }
2787             if ( e3.isGeneLoss() ) {
2788                 return false;
2789             }
2790             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2791                 return false;
2792             }
2793             final Event e3c = ( Event ) e3.copy();
2794             final Event e3cc = ( Event ) e3c.copy();
2795             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2796                 return false;
2797             }
2798             e3 = null;
2799             if ( !e3c.isEqual( e3cc ) ) {
2800                 return false;
2801             }
2802             Event e4 = new Event( 1, 2, 3 );
2803             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2804                 return false;
2805             }
2806             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2807                 return false;
2808             }
2809             final Event e4c = ( Event ) e4.copy();
2810             e4 = null;
2811             final Event e4cc = ( Event ) e4c.copy();
2812             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2813                 return false;
2814             }
2815             if ( !e4c.isEqual( e4cc ) ) {
2816                 return false;
2817             }
2818             final Event e5 = new Event();
2819             if ( !e5.isUnassigned() ) {
2820                 return false;
2821             }
2822             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2823                 return false;
2824             }
2825             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2826                 return false;
2827             }
2828             final Event e6 = new Event( 1, 0, 0 );
2829             if ( !e6.asText().toString().equals( "duplication" ) ) {
2830                 return false;
2831             }
2832             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2833                 return false;
2834             }
2835             final Event e7 = new Event( 0, 1, 0 );
2836             if ( !e7.asText().toString().equals( "speciation" ) ) {
2837                 return false;
2838             }
2839             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2840                 return false;
2841             }
2842             final Event e8 = new Event( 0, 0, 1 );
2843             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2844                 return false;
2845             }
2846             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2847                 return false;
2848             }
2849         }
2850         catch ( final Exception e ) {
2851             e.printStackTrace( System.out );
2852             return false;
2853         }
2854         return true;
2855     }
2856
2857     private static boolean testDeletionOfExternalNodes() {
2858         try {
2859             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2860             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2861             final PhylogenyWriter w = new PhylogenyWriter();
2862             if ( t0.isEmpty() ) {
2863                 return false;
2864             }
2865             if ( t0.getNumberOfExternalNodes() != 1 ) {
2866                 return false;
2867             }
2868             t0.deleteSubtree( t0.getNode( "A" ), false );
2869             if ( t0.getNumberOfExternalNodes() != 0 ) {
2870                 return false;
2871             }
2872             if ( !t0.isEmpty() ) {
2873                 return false;
2874             }
2875             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2876             if ( t1.getNumberOfExternalNodes() != 2 ) {
2877                 return false;
2878             }
2879             t1.deleteSubtree( t1.getNode( "A" ), false );
2880             if ( t1.getNumberOfExternalNodes() != 1 ) {
2881                 return false;
2882             }
2883             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2884                 return false;
2885             }
2886             t1.deleteSubtree( t1.getNode( "B" ), false );
2887             if ( t1.getNumberOfExternalNodes() != 1 ) {
2888                 return false;
2889             }
2890             t1.deleteSubtree( t1.getNode( "r" ), false );
2891             if ( !t1.isEmpty() ) {
2892                 return false;
2893             }
2894             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2895             if ( t2.getNumberOfExternalNodes() != 3 ) {
2896                 return false;
2897             }
2898             t2.deleteSubtree( t2.getNode( "B" ), false );
2899             if ( t2.getNumberOfExternalNodes() != 2 ) {
2900                 return false;
2901             }
2902             t2.toNewHampshireX();
2903             PhylogenyNode n = t2.getNode( "A" );
2904             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2905                 return false;
2906             }
2907             t2.deleteSubtree( t2.getNode( "A" ), false );
2908             if ( t2.getNumberOfExternalNodes() != 2 ) {
2909                 return false;
2910             }
2911             t2.deleteSubtree( t2.getNode( "C" ), true );
2912             if ( t2.getNumberOfExternalNodes() != 1 ) {
2913                 return false;
2914             }
2915             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2916             if ( t3.getNumberOfExternalNodes() != 4 ) {
2917                 return false;
2918             }
2919             t3.deleteSubtree( t3.getNode( "B" ), true );
2920             if ( t3.getNumberOfExternalNodes() != 3 ) {
2921                 return false;
2922             }
2923             n = t3.getNode( "A" );
2924             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2925                 return false;
2926             }
2927             n = n.getNextExternalNode();
2928             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2929                 return false;
2930             }
2931             t3.deleteSubtree( t3.getNode( "A" ), true );
2932             if ( t3.getNumberOfExternalNodes() != 2 ) {
2933                 return false;
2934             }
2935             n = t3.getNode( "C" );
2936             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2937                 return false;
2938             }
2939             t3.deleteSubtree( t3.getNode( "C" ), true );
2940             if ( t3.getNumberOfExternalNodes() != 1 ) {
2941                 return false;
2942             }
2943             t3.deleteSubtree( t3.getNode( "D" ), true );
2944             if ( t3.getNumberOfExternalNodes() != 0 ) {
2945                 return false;
2946             }
2947             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2948             if ( t4.getNumberOfExternalNodes() != 6 ) {
2949                 return false;
2950             }
2951             t4.deleteSubtree( t4.getNode( "B2" ), true );
2952             if ( t4.getNumberOfExternalNodes() != 5 ) {
2953                 return false;
2954             }
2955             String s = w.toNewHampshire( t4, false, true ).toString();
2956             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2957                 return false;
2958             }
2959             t4.deleteSubtree( t4.getNode( "B11" ), true );
2960             if ( t4.getNumberOfExternalNodes() != 4 ) {
2961                 return false;
2962             }
2963             t4.deleteSubtree( t4.getNode( "C" ), true );
2964             if ( t4.getNumberOfExternalNodes() != 3 ) {
2965                 return false;
2966             }
2967             n = t4.getNode( "A" );
2968             n = n.getNextExternalNode();
2969             if ( !n.getName().equals( "B12" ) ) {
2970                 return false;
2971             }
2972             n = n.getNextExternalNode();
2973             if ( !n.getName().equals( "D" ) ) {
2974                 return false;
2975             }
2976             s = w.toNewHampshire( t4, false, true ).toString();
2977             if ( !s.equals( "((A,B12),D);" ) ) {
2978                 return false;
2979             }
2980             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2981             t5.deleteSubtree( t5.getNode( "A" ), true );
2982             if ( t5.getNumberOfExternalNodes() != 5 ) {
2983                 return false;
2984             }
2985             s = w.toNewHampshire( t5, false, true ).toString();
2986             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2987                 return false;
2988             }
2989             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2990             t6.deleteSubtree( t6.getNode( "B11" ), true );
2991             if ( t6.getNumberOfExternalNodes() != 5 ) {
2992                 return false;
2993             }
2994             s = w.toNewHampshire( t6, false, false ).toString();
2995             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2996                 return false;
2997             }
2998             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2999             t7.deleteSubtree( t7.getNode( "B12" ), true );
3000             if ( t7.getNumberOfExternalNodes() != 5 ) {
3001                 return false;
3002             }
3003             s = w.toNewHampshire( t7, false, true ).toString();
3004             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3005                 return false;
3006             }
3007             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3008             t8.deleteSubtree( t8.getNode( "B2" ), true );
3009             if ( t8.getNumberOfExternalNodes() != 5 ) {
3010                 return false;
3011             }
3012             s = w.toNewHampshire( t8, false, false ).toString();
3013             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3014                 return false;
3015             }
3016             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3017             t9.deleteSubtree( t9.getNode( "C" ), true );
3018             if ( t9.getNumberOfExternalNodes() != 5 ) {
3019                 return false;
3020             }
3021             s = w.toNewHampshire( t9, false, true ).toString();
3022             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3023                 return false;
3024             }
3025             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3026             t10.deleteSubtree( t10.getNode( "D" ), true );
3027             if ( t10.getNumberOfExternalNodes() != 5 ) {
3028                 return false;
3029             }
3030             s = w.toNewHampshire( t10, false, true ).toString();
3031             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3032                 return false;
3033             }
3034             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3035             t11.deleteSubtree( t11.getNode( "A" ), true );
3036             if ( t11.getNumberOfExternalNodes() != 2 ) {
3037                 return false;
3038             }
3039             s = w.toNewHampshire( t11, false, true ).toString();
3040             if ( !s.equals( "(B,C);" ) ) {
3041                 return false;
3042             }
3043             t11.deleteSubtree( t11.getNode( "C" ), true );
3044             if ( t11.getNumberOfExternalNodes() != 1 ) {
3045                 return false;
3046             }
3047             s = w.toNewHampshire( t11, false, false ).toString();
3048             if ( !s.equals( "B;" ) ) {
3049                 return false;
3050             }
3051             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3052             t12.deleteSubtree( t12.getNode( "B2" ), true );
3053             if ( t12.getNumberOfExternalNodes() != 8 ) {
3054                 return false;
3055             }
3056             s = w.toNewHampshire( t12, false, true ).toString();
3057             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3058                 return false;
3059             }
3060             t12.deleteSubtree( t12.getNode( "B3" ), true );
3061             if ( t12.getNumberOfExternalNodes() != 7 ) {
3062                 return false;
3063             }
3064             s = w.toNewHampshire( t12, false, true ).toString();
3065             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3066                 return false;
3067             }
3068             t12.deleteSubtree( t12.getNode( "C3" ), true );
3069             if ( t12.getNumberOfExternalNodes() != 6 ) {
3070                 return false;
3071             }
3072             s = w.toNewHampshire( t12, false, true ).toString();
3073             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3074                 return false;
3075             }
3076             t12.deleteSubtree( t12.getNode( "A1" ), true );
3077             if ( t12.getNumberOfExternalNodes() != 5 ) {
3078                 return false;
3079             }
3080             s = w.toNewHampshire( t12, false, true ).toString();
3081             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3082                 return false;
3083             }
3084             t12.deleteSubtree( t12.getNode( "B1" ), true );
3085             if ( t12.getNumberOfExternalNodes() != 4 ) {
3086                 return false;
3087             }
3088             s = w.toNewHampshire( t12, false, true ).toString();
3089             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3090                 return false;
3091             }
3092             t12.deleteSubtree( t12.getNode( "A3" ), true );
3093             if ( t12.getNumberOfExternalNodes() != 3 ) {
3094                 return false;
3095             }
3096             s = w.toNewHampshire( t12, false, true ).toString();
3097             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3098                 return false;
3099             }
3100             t12.deleteSubtree( t12.getNode( "A2" ), true );
3101             if ( t12.getNumberOfExternalNodes() != 2 ) {
3102                 return false;
3103             }
3104             s = w.toNewHampshire( t12, false, true ).toString();
3105             if ( !s.equals( "(C1,C2);" ) ) {
3106                 return false;
3107             }
3108             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3109             t13.deleteSubtree( t13.getNode( "D" ), true );
3110             if ( t13.getNumberOfExternalNodes() != 4 ) {
3111                 return false;
3112             }
3113             s = w.toNewHampshire( t13, false, true ).toString();
3114             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3115                 return false;
3116             }
3117             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3118             t14.deleteSubtree( t14.getNode( "E" ), true );
3119             if ( t14.getNumberOfExternalNodes() != 5 ) {
3120                 return false;
3121             }
3122             s = w.toNewHampshire( t14, false, true ).toString();
3123             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3124                 return false;
3125             }
3126             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3127             t15.deleteSubtree( t15.getNode( "B2" ), true );
3128             if ( t15.getNumberOfExternalNodes() != 11 ) {
3129                 return false;
3130             }
3131             t15.deleteSubtree( t15.getNode( "B1" ), true );
3132             if ( t15.getNumberOfExternalNodes() != 10 ) {
3133                 return false;
3134             }
3135             t15.deleteSubtree( t15.getNode( "B3" ), true );
3136             if ( t15.getNumberOfExternalNodes() != 9 ) {
3137                 return false;
3138             }
3139             t15.deleteSubtree( t15.getNode( "B4" ), true );
3140             if ( t15.getNumberOfExternalNodes() != 8 ) {
3141                 return false;
3142             }
3143             t15.deleteSubtree( t15.getNode( "A1" ), true );
3144             if ( t15.getNumberOfExternalNodes() != 7 ) {
3145                 return false;
3146             }
3147             t15.deleteSubtree( t15.getNode( "C4" ), true );
3148             if ( t15.getNumberOfExternalNodes() != 6 ) {
3149                 return false;
3150             }
3151         }
3152         catch ( final Exception e ) {
3153             e.printStackTrace( System.out );
3154             return false;
3155         }
3156         return true;
3157     }
3158
3159     private static boolean testDescriptiveStatistics() {
3160         try {
3161             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3162             dss1.addValue( 82 );
3163             dss1.addValue( 78 );
3164             dss1.addValue( 70 );
3165             dss1.addValue( 58 );
3166             dss1.addValue( 42 );
3167             if ( dss1.getN() != 5 ) {
3168                 return false;
3169             }
3170             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3171                 return false;
3172             }
3173             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3174                 return false;
3175             }
3176             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3177                 return false;
3178             }
3179             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3180                 return false;
3181             }
3182             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3183                 return false;
3184             }
3185             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3186                 return false;
3187             }
3188             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3189                 return false;
3190             }
3191             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3192                 return false;
3193             }
3194             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3195                 return false;
3196             }
3197             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3198                 return false;
3199             }
3200             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3201                 return false;
3202             }
3203             dss1.addValue( 123 );
3204             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3205                 return false;
3206             }
3207             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3208                 return false;
3209             }
3210             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3211                 return false;
3212             }
3213             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3214             dss2.addValue( -1.85 );
3215             dss2.addValue( 57.5 );
3216             dss2.addValue( 92.78 );
3217             dss2.addValue( 57.78 );
3218             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3219                 return false;
3220             }
3221             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3222                 return false;
3223             }
3224             final double[] a = dss2.getDataAsDoubleArray();
3225             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3226                 return false;
3227             }
3228             dss2.addValue( -100 );
3229             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3230                 return false;
3231             }
3232             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3233                 return false;
3234             }
3235             final double[] ds = new double[ 14 ];
3236             ds[ 0 ] = 34;
3237             ds[ 1 ] = 23;
3238             ds[ 2 ] = 1;
3239             ds[ 3 ] = 32;
3240             ds[ 4 ] = 11;
3241             ds[ 5 ] = 2;
3242             ds[ 6 ] = 12;
3243             ds[ 7 ] = 33;
3244             ds[ 8 ] = 13;
3245             ds[ 9 ] = 22;
3246             ds[ 10 ] = 21;
3247             ds[ 11 ] = 35;
3248             ds[ 12 ] = 24;
3249             ds[ 13 ] = 31;
3250             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3251             if ( bins.length != 4 ) {
3252                 return false;
3253             }
3254             if ( bins[ 0 ] != 2 ) {
3255                 return false;
3256             }
3257             if ( bins[ 1 ] != 3 ) {
3258                 return false;
3259             }
3260             if ( bins[ 2 ] != 4 ) {
3261                 return false;
3262             }
3263             if ( bins[ 3 ] != 5 ) {
3264                 return false;
3265             }
3266             final double[] ds1 = new double[ 9 ];
3267             ds1[ 0 ] = 10.0;
3268             ds1[ 1 ] = 19.0;
3269             ds1[ 2 ] = 9.999;
3270             ds1[ 3 ] = 0.0;
3271             ds1[ 4 ] = 39.9;
3272             ds1[ 5 ] = 39.999;
3273             ds1[ 6 ] = 30.0;
3274             ds1[ 7 ] = 19.999;
3275             ds1[ 8 ] = 30.1;
3276             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3277             if ( bins1.length != 4 ) {
3278                 return false;
3279             }
3280             if ( bins1[ 0 ] != 2 ) {
3281                 return false;
3282             }
3283             if ( bins1[ 1 ] != 3 ) {
3284                 return false;
3285             }
3286             if ( bins1[ 2 ] != 0 ) {
3287                 return false;
3288             }
3289             if ( bins1[ 3 ] != 4 ) {
3290                 return false;
3291             }
3292             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3293             if ( bins1_1.length != 3 ) {
3294                 return false;
3295             }
3296             if ( bins1_1[ 0 ] != 3 ) {
3297                 return false;
3298             }
3299             if ( bins1_1[ 1 ] != 2 ) {
3300                 return false;
3301             }
3302             if ( bins1_1[ 2 ] != 4 ) {
3303                 return false;
3304             }
3305             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3306             if ( bins1_2.length != 3 ) {
3307                 return false;
3308             }
3309             if ( bins1_2[ 0 ] != 2 ) {
3310                 return false;
3311             }
3312             if ( bins1_2[ 1 ] != 2 ) {
3313                 return false;
3314             }
3315             if ( bins1_2[ 2 ] != 2 ) {
3316                 return false;
3317             }
3318             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3319             dss3.addValue( 1 );
3320             dss3.addValue( 1 );
3321             dss3.addValue( 1 );
3322             dss3.addValue( 2 );
3323             dss3.addValue( 3 );
3324             dss3.addValue( 4 );
3325             dss3.addValue( 5 );
3326             dss3.addValue( 5 );
3327             dss3.addValue( 5 );
3328             dss3.addValue( 6 );
3329             dss3.addValue( 7 );
3330             dss3.addValue( 8 );
3331             dss3.addValue( 9 );
3332             dss3.addValue( 10 );
3333             dss3.addValue( 10 );
3334             dss3.addValue( 10 );
3335             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3336             histo.toStringBuffer( 10, '=', 40, 5 );
3337             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3338         }
3339         catch ( final Exception e ) {
3340             e.printStackTrace( System.out );
3341             return false;
3342         }
3343         return true;
3344     }
3345
3346     private static boolean testDir( final String file ) {
3347         try {
3348             final File f = new File( file );
3349             if ( !f.exists() ) {
3350                 return false;
3351             }
3352             if ( !f.isDirectory() ) {
3353                 return false;
3354             }
3355             if ( !f.canRead() ) {
3356                 return false;
3357             }
3358         }
3359         catch ( final Exception e ) {
3360             return false;
3361         }
3362         return true;
3363     }
3364
3365     private static boolean testEmblEntryRetrieval() {
3366         //The format for GenBank Accession numbers are:
3367         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
3368         //Protein:    3 letters + 5 numerals
3369         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
3370         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
3371             return false;
3372         }
3373         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
3374             return false;
3375         }
3376         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
3377             return false;
3378         }
3379         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
3380             return false;
3381         }
3382         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
3383             return false;
3384         }
3385         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
3386             return false;
3387         }
3388         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
3389             return false;
3390         }
3391         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
3392             return false;
3393         }
3394         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
3395             return false;
3396         }
3397         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
3398             return false;
3399         }
3400         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
3401             return false;
3402         }
3403         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
3404             return false;
3405         }
3406         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
3407             return false;
3408         }
3409         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
3410             return false;
3411         }
3412         return true;
3413     }
3414
3415     private static boolean testExternalNodeRelatedMethods() {
3416         try {
3417             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3418             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3419             PhylogenyNode n = t1.getNode( "A" );
3420             n = n.getNextExternalNode();
3421             if ( !n.getName().equals( "B" ) ) {
3422                 return false;
3423             }
3424             n = n.getNextExternalNode();
3425             if ( !n.getName().equals( "C" ) ) {
3426                 return false;
3427             }
3428             n = n.getNextExternalNode();
3429             if ( !n.getName().equals( "D" ) ) {
3430                 return false;
3431             }
3432             n = t1.getNode( "B" );
3433             while ( !n.isLastExternalNode() ) {
3434                 n = n.getNextExternalNode();
3435             }
3436             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3437             n = t2.getNode( "A" );
3438             n = n.getNextExternalNode();
3439             if ( !n.getName().equals( "B" ) ) {
3440                 return false;
3441             }
3442             n = n.getNextExternalNode();
3443             if ( !n.getName().equals( "C" ) ) {
3444                 return false;
3445             }
3446             n = n.getNextExternalNode();
3447             if ( !n.getName().equals( "D" ) ) {
3448                 return false;
3449             }
3450             n = t2.getNode( "B" );
3451             while ( !n.isLastExternalNode() ) {
3452                 n = n.getNextExternalNode();
3453             }
3454             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3455             n = t3.getNode( "A" );
3456             n = n.getNextExternalNode();
3457             if ( !n.getName().equals( "B" ) ) {
3458                 return false;
3459             }
3460             n = n.getNextExternalNode();
3461             if ( !n.getName().equals( "C" ) ) {
3462                 return false;
3463             }
3464             n = n.getNextExternalNode();
3465             if ( !n.getName().equals( "D" ) ) {
3466                 return false;
3467             }
3468             n = n.getNextExternalNode();
3469             if ( !n.getName().equals( "E" ) ) {
3470                 return false;
3471             }
3472             n = n.getNextExternalNode();
3473             if ( !n.getName().equals( "F" ) ) {
3474                 return false;
3475             }
3476             n = n.getNextExternalNode();
3477             if ( !n.getName().equals( "G" ) ) {
3478                 return false;
3479             }
3480             n = n.getNextExternalNode();
3481             if ( !n.getName().equals( "H" ) ) {
3482                 return false;
3483             }
3484             n = t3.getNode( "B" );
3485             while ( !n.isLastExternalNode() ) {
3486                 n = n.getNextExternalNode();
3487             }
3488             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3489             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3490                 final PhylogenyNode node = iter.next();
3491             }
3492             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3493             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3494                 final PhylogenyNode node = iter.next();
3495             }
3496             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3497             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3498             if ( !iter.next().getName().equals( "A" ) ) {
3499                 return false;
3500             }
3501             if ( !iter.next().getName().equals( "B" ) ) {
3502                 return false;
3503             }
3504             if ( !iter.next().getName().equals( "C" ) ) {
3505                 return false;
3506             }
3507             if ( !iter.next().getName().equals( "D" ) ) {
3508                 return false;
3509             }
3510             if ( !iter.next().getName().equals( "E" ) ) {
3511                 return false;
3512             }
3513             if ( !iter.next().getName().equals( "F" ) ) {
3514                 return false;
3515             }
3516             if ( iter.hasNext() ) {
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 testExtractSNFromNodeName() {
3528         try {
3529             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
3530                 return false;
3531             }
3532             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
3533                     .equals( "Mus musculus musculus" ) ) {
3534                 return false;
3535             }
3536             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
3537                     .equals( "Mus musculus musculus" ) ) {
3538                 return false;
3539             }
3540             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
3541                 return false;
3542             }
3543             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
3544                     .equals( "Mus musculus" ) ) {
3545                 return false;
3546             }
3547         }
3548         catch ( final Exception e ) {
3549             e.printStackTrace( System.out );
3550             return false;
3551         }
3552         return true;
3553     }
3554
3555     private static boolean testExtractTaxonomyCodeFromNodeName() {
3556         try {
3557             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3558                 return false;
3559             }
3560             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3561                     .equals( "SOYBN" ) ) {
3562                 return false;
3563             }
3564             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3565                     .equals( "ARATH" ) ) {
3566                 return false;
3567             }
3568             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3569                     .equals( "ARATH" ) ) {
3570                 return false;
3571             }
3572             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3573                 return false;
3574             }
3575             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3576                 return false;
3577             }
3578             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3579                 return false;
3580             }
3581             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3582                     .equals( "SOYBN" ) ) {
3583                 return false;
3584             }
3585             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3586                     .equals( "SOYBN" ) ) {
3587                 return false;
3588             }
3589             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3590                     .equals( "SOYBN" ) ) {
3591                 return false;
3592             }
3593             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3594                     .equals( "SOYBN" ) ) {
3595                 return false;
3596             }
3597             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3598                     .equals( "SOYBN" ) ) {
3599                 return false;
3600             }
3601             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3602                     .equals( "SOYBN" ) ) {
3603                 return false;
3604             }
3605             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
3606                     .equals( "SOYBN" ) ) {
3607                 return false;
3608             }
3609             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
3610                     .equals( "SOYBN" ) ) {
3611                 return false;
3612             }
3613             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
3614                 return false;
3615             }
3616             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
3617                     .equals( "SOYBN" ) ) {
3618                 return false;
3619             }
3620             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
3621                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
3622                 return false;
3623             }
3624             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
3625                     .equals( "9YX45" ) ) {
3626                 return false;
3627             }
3628             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
3629                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3630                     .equals( "MOUSE" ) ) {
3631                 return false;
3632             }
3633             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
3634                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3635                     .equals( "MOUSE" ) ) {
3636                 return false;
3637             }
3638             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
3639                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3640                     .equals( "MOUSE" ) ) {
3641                 return false;
3642             }
3643             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
3644                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3645                 return false;
3646             }
3647             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
3648                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3649                 return false;
3650             }
3651             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3652                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3653                 return false;
3654             }
3655             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3656                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3657                 return false;
3658             }
3659             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
3660                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3661                 return false;
3662             }
3663             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
3664                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3665                 return false;
3666             }
3667             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
3668                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3669                 return false;
3670             }
3671             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3672                     .equals( "RAT" ) ) {
3673                 return false;
3674             }
3675             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3676                     .equals( "PIG" ) ) {
3677                 return false;
3678             }
3679             if ( !ParserUtils
3680                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3681                     .equals( "MOUSE" ) ) {
3682                 return false;
3683             }
3684             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3685                     .equals( "MOUSE" ) ) {
3686                 return false;
3687             }
3688             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3689                 return false;
3690             }
3691         }
3692         catch ( final Exception e ) {
3693             e.printStackTrace( System.out );
3694             return false;
3695         }
3696         return true;
3697     }
3698
3699     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
3700         try {
3701             PhylogenyNode n = new PhylogenyNode();
3702             n.setName( "tr|B3RJ64" );
3703             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3704                 return false;
3705             }
3706             n.setName( "tr.B3RJ64" );
3707             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3708                 return false;
3709             }
3710             n.setName( "tr=B3RJ64" );
3711             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3712                 return false;
3713             }
3714             n.setName( "tr-B3RJ64" );
3715             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3716                 return false;
3717             }
3718             n.setName( "tr/B3RJ64" );
3719             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3720                 return false;
3721             }
3722             n.setName( "tr\\B3RJ64" );
3723             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3724                 return false;
3725             }
3726             n.setName( "tr_B3RJ64" );
3727             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3728                 return false;
3729             }
3730             n.setName( " tr|B3RJ64 " );
3731             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3732                 return false;
3733             }
3734             n.setName( "-tr|B3RJ64-" );
3735             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3736                 return false;
3737             }
3738             n.setName( "-tr=B3RJ64-" );
3739             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3740                 return false;
3741             }
3742             n.setName( "_tr=B3RJ64_" );
3743             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3744                 return false;
3745             }
3746             n.setName( " tr_tr|B3RJ64_sp|123 " );
3747             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3748                 return false;
3749             }
3750             n.setName( "B3RJ64" );
3751             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3752                 return false;
3753             }
3754             n.setName( "sp|B3RJ64" );
3755             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3756                 return false;
3757             }
3758             n.setName( "sp|B3RJ64C" );
3759             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3760                 return false;
3761             }
3762             n.setName( "sp B3RJ64" );
3763             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3764                 return false;
3765             }
3766             n.setName( "sp|B3RJ6X" );
3767             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3768                 return false;
3769             }
3770             n.setName( "sp|B3RJ6" );
3771             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3772                 return false;
3773             }
3774             n.setName( "K1PYK7_CRAGI" );
3775             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3776                 return false;
3777             }
3778             n.setName( "K1PYK7_PEA" );
3779             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
3780                 return false;
3781             }
3782             n.setName( "K1PYK7_RAT" );
3783             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
3784                 return false;
3785             }
3786             n.setName( "K1PYK7_PIG" );
3787             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
3788                 return false;
3789             }
3790             n.setName( "~K1PYK7_PIG~" );
3791             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
3792                 return false;
3793             }
3794             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
3795             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3796                 return false;
3797             }
3798             n.setName( "K1PYKX_CRAGI" );
3799             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3800                 return false;
3801             }
3802             n.setName( "XXXXX_CRAGI" );
3803             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
3804                 return false;
3805             }
3806             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
3807             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
3808                 return false;
3809             }
3810             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
3811             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
3812                 return false;
3813             }
3814             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
3815             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
3816                 return false;
3817             }
3818             n = new PhylogenyNode();
3819             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
3820             seq.setSymbol( "K1PYK7_CRAGI" );
3821             n.getNodeData().addSequence( seq );
3822             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3823                 return false;
3824             }
3825             seq.setSymbol( "tr|B3RJ64" );
3826             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3827                 return false;
3828             }
3829             n = new PhylogenyNode();
3830             seq = new org.forester.phylogeny.data.Sequence();
3831             seq.setName( "K1PYK7_CRAGI" );
3832             n.getNodeData().addSequence( seq );
3833             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
3834                 return false;
3835             }
3836             seq.setName( "tr|B3RJ64" );
3837             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3838                 return false;
3839             }
3840             n = new PhylogenyNode();
3841             seq = new org.forester.phylogeny.data.Sequence();
3842             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
3843             n.getNodeData().addSequence( seq );
3844             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
3845                 return false;
3846             }
3847             n = new PhylogenyNode();
3848             seq = new org.forester.phylogeny.data.Sequence();
3849             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
3850             n.getNodeData().addSequence( seq );
3851             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
3852                 return false;
3853             }
3854             //
3855             n = new PhylogenyNode();
3856             n.setName( "ACP19736" );
3857             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
3858                 return false;
3859             }
3860             n = new PhylogenyNode();
3861             n.setName( "|ACP19736|" );
3862             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
3863                 return false;
3864             }
3865         }
3866         catch ( final Exception e ) {
3867             e.printStackTrace( System.out );
3868             return false;
3869         }
3870         return true;
3871     }
3872
3873     private static boolean testFastaParser() {
3874         try {
3875             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
3876                 return false;
3877             }
3878             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
3879                 return false;
3880             }
3881             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
3882             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
3883                 return false;
3884             }
3885             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
3886                 return false;
3887             }
3888             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
3889                 return false;
3890             }
3891             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
3892                 return false;
3893             }
3894             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
3895                 return false;
3896             }
3897             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
3898                 return false;
3899             }
3900         }
3901         catch ( final Exception e ) {
3902             e.printStackTrace();
3903             return false;
3904         }
3905         return true;
3906     }
3907
3908     private static boolean testGeneralMsaParser() {
3909         try {
3910             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
3911             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
3912             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
3913             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
3914             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
3915             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
3916             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
3917             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
3918             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3919                 return false;
3920             }
3921             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3922                 return false;
3923             }
3924             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3925                 return false;
3926             }
3927             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3928                 return false;
3929             }
3930             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3931                 return false;
3932             }
3933             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3934                 return false;
3935             }
3936             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3937                 return false;
3938             }
3939             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3940                 return false;
3941             }
3942             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3943                 return false;
3944             }
3945             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3946                 return false;
3947             }
3948             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3949                 return false;
3950             }
3951             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3952                 return false;
3953             }
3954             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
3955             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
3956                 return false;
3957             }
3958             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
3959                 return false;
3960             }
3961             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
3962                 return false;
3963             }
3964             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
3965             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
3966                 return false;
3967             }
3968             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
3969                 return false;
3970             }
3971             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
3972                 return false;
3973             }
3974             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
3975             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
3976                 return false;
3977             }
3978             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
3979                 return false;
3980             }
3981             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
3982                 return false;
3983             }
3984         }
3985         catch ( final Exception e ) {
3986             e.printStackTrace();
3987             return false;
3988         }
3989         return true;
3990     }
3991
3992     private static boolean testGeneralTable() {
3993         try {
3994             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3995             t0.setValue( 3, 2, "23" );
3996             t0.setValue( 10, 1, "error" );
3997             t0.setValue( 10, 1, "110" );
3998             t0.setValue( 9, 1, "19" );
3999             t0.setValue( 1, 10, "101" );
4000             t0.setValue( 10, 10, "1010" );
4001             t0.setValue( 100, 10, "10100" );
4002             t0.setValue( 0, 0, "00" );
4003             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4004                 return false;
4005             }
4006             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4007                 return false;
4008             }
4009             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4010                 return false;
4011             }
4012             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4013                 return false;
4014             }
4015             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4016                 return false;
4017             }
4018             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4019                 return false;
4020             }
4021             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4022                 return false;
4023             }
4024             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4025                 return false;
4026             }
4027             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4028                 return false;
4029             }
4030             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4031             t1.setValue( "3", "2", "23" );
4032             t1.setValue( "10", "1", "error" );
4033             t1.setValue( "10", "1", "110" );
4034             t1.setValue( "9", "1", "19" );
4035             t1.setValue( "1", "10", "101" );
4036             t1.setValue( "10", "10", "1010" );
4037             t1.setValue( "100", "10", "10100" );
4038             t1.setValue( "0", "0", "00" );
4039             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4040             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4041                 return false;
4042             }
4043             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4044                 return false;
4045             }
4046             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4047                 return false;
4048             }
4049             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4050                 return false;
4051             }
4052             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4053                 return false;
4054             }
4055             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4056                 return false;
4057             }
4058             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4059                 return false;
4060             }
4061             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4062                 return false;
4063             }
4064             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4065                 return false;
4066             }
4067             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4068                 return false;
4069             }
4070         }
4071         catch ( final Exception e ) {
4072             e.printStackTrace( System.out );
4073             return false;
4074         }
4075         return true;
4076     }
4077
4078     private static boolean testGetDistance() {
4079         try {
4080             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4081             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",
4082                                                  new NHXParser() )[ 0 ];
4083             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4084                 return false;
4085             }
4086             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4087                 return false;
4088             }
4089             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4090                 return false;
4091             }
4092             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4093                 return false;
4094             }
4095             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4096                 return false;
4097             }
4098             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4099                 return false;
4100             }
4101             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4102                 return false;
4103             }
4104             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4105                 return false;
4106             }
4107             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4108                 return false;
4109             }
4110             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4111                 return false;
4112             }
4113             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4114                 return false;
4115             }
4116             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4117                 return false;
4118             }
4119             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4120                 return false;
4121             }
4122             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4123                 return false;
4124             }
4125             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4126                 return false;
4127             }
4128             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4129                 return false;
4130             }
4131             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4132                 return false;
4133             }
4134             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4135                 return false;
4136             }
4137             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4138                 return false;
4139             }
4140             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4141                 return false;
4142             }
4143             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4144                 return false;
4145             }
4146             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4147                 return false;
4148             }
4149             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4150                 return false;
4151             }
4152             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4153                 return false;
4154             }
4155             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4156                 return false;
4157             }
4158             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4159                 return false;
4160             }
4161             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4162                 return false;
4163             }
4164             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4165                 return false;
4166             }
4167             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4168                 return false;
4169             }
4170             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4171                 return false;
4172             }
4173             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4174                 return false;
4175             }
4176             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",
4177                                                  new NHXParser() )[ 0 ];
4178             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4179                 return false;
4180             }
4181             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4182                 return false;
4183             }
4184             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4185                 return false;
4186             }
4187             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4188                 return false;
4189             }
4190             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4191                 return false;
4192             }
4193             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4194                 return false;
4195             }
4196             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4197                 return false;
4198             }
4199             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4200                 return false;
4201             }
4202             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4203                 return false;
4204             }
4205             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4206                 return false;
4207             }
4208             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4209                 return false;
4210             }
4211         }
4212         catch ( final Exception e ) {
4213             e.printStackTrace( System.out );
4214             return false;
4215         }
4216         return true;
4217     }
4218
4219     private static boolean testGetLCA() {
4220         try {
4221             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4222             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4223                                                  new NHXParser() )[ 0 ];
4224             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4225             if ( !A.getName().equals( "A" ) ) {
4226                 return false;
4227             }
4228             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4229             if ( !gh.getName().equals( "gh" ) ) {
4230                 return false;
4231             }
4232             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4233             if ( !ab.getName().equals( "ab" ) ) {
4234                 return false;
4235             }
4236             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4237             if ( !ab2.getName().equals( "ab" ) ) {
4238                 return false;
4239             }
4240             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4241             if ( !gh2.getName().equals( "gh" ) ) {
4242                 return false;
4243             }
4244             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4245             if ( !gh3.getName().equals( "gh" ) ) {
4246                 return false;
4247             }
4248             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4249             if ( !abc.getName().equals( "abc" ) ) {
4250                 return false;
4251             }
4252             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4253             if ( !abc2.getName().equals( "abc" ) ) {
4254                 return false;
4255             }
4256             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4257             if ( !abcd.getName().equals( "abcd" ) ) {
4258                 return false;
4259             }
4260             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4261             if ( !abcd2.getName().equals( "abcd" ) ) {
4262                 return false;
4263             }
4264             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4265             if ( !abcdef.getName().equals( "abcdef" ) ) {
4266                 return false;
4267             }
4268             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4269             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4270                 return false;
4271             }
4272             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4273             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4274                 return false;
4275             }
4276             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4277             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4278                 return false;
4279             }
4280             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4281             if ( !abcde.getName().equals( "abcde" ) ) {
4282                 return false;
4283             }
4284             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4285             if ( !abcde2.getName().equals( "abcde" ) ) {
4286                 return false;
4287             }
4288             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4289             if ( !r.getName().equals( "abcdefgh" ) ) {
4290                 return false;
4291             }
4292             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4293             if ( !r2.getName().equals( "abcdefgh" ) ) {
4294                 return false;
4295             }
4296             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4297             if ( !r3.getName().equals( "abcdefgh" ) ) {
4298                 return false;
4299             }
4300             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4301             if ( !abcde3.getName().equals( "abcde" ) ) {
4302                 return false;
4303             }
4304             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4305             if ( !abcde4.getName().equals( "abcde" ) ) {
4306                 return false;
4307             }
4308             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4309             if ( !ab3.getName().equals( "ab" ) ) {
4310                 return false;
4311             }
4312             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4313             if ( !ab4.getName().equals( "ab" ) ) {
4314                 return false;
4315             }
4316             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4317             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4318             if ( !cd.getName().equals( "cd" ) ) {
4319                 return false;
4320             }
4321             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4322             if ( !cd2.getName().equals( "cd" ) ) {
4323                 return false;
4324             }
4325             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4326             if ( !cde.getName().equals( "cde" ) ) {
4327                 return false;
4328             }
4329             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4330             if ( !cde2.getName().equals( "cde" ) ) {
4331                 return false;
4332             }
4333             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4334             if ( !cdef.getName().equals( "cdef" ) ) {
4335                 return false;
4336             }
4337             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4338             if ( !cdef2.getName().equals( "cdef" ) ) {
4339                 return false;
4340             }
4341             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4342             if ( !cdef3.getName().equals( "cdef" ) ) {
4343                 return false;
4344             }
4345             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4346             if ( !rt.getName().equals( "r" ) ) {
4347                 return false;
4348             }
4349             final Phylogeny p3 = factory
4350                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4351                              new NHXParser() )[ 0 ];
4352             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4353             if ( !bc_3.getName().equals( "bc" ) ) {
4354                 return false;
4355             }
4356             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4357             if ( !ac_3.getName().equals( "abc" ) ) {
4358                 return false;
4359             }
4360             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4361             if ( !ad_3.getName().equals( "abcde" ) ) {
4362                 return false;
4363             }
4364             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4365             if ( !af_3.getName().equals( "abcdef" ) ) {
4366                 return false;
4367             }
4368             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4369             if ( !ag_3.getName().equals( "" ) ) {
4370                 return false;
4371             }
4372             if ( !ag_3.isRoot() ) {
4373                 return false;
4374             }
4375             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4376             if ( !al_3.getName().equals( "" ) ) {
4377                 return false;
4378             }
4379             if ( !al_3.isRoot() ) {
4380                 return false;
4381             }
4382             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4383             if ( !kl_3.getName().equals( "" ) ) {
4384                 return false;
4385             }
4386             if ( !kl_3.isRoot() ) {
4387                 return false;
4388             }
4389             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4390             if ( !fl_3.getName().equals( "" ) ) {
4391                 return false;
4392             }
4393             if ( !fl_3.isRoot() ) {
4394                 return false;
4395             }
4396             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4397             if ( !gk_3.getName().equals( "ghijk" ) ) {
4398                 return false;
4399             }
4400             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4401             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4402             if ( !r_4.getName().equals( "r" ) ) {
4403                 return false;
4404             }
4405             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4406             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4407             if ( !r_5.getName().equals( "root" ) ) {
4408                 return false;
4409             }
4410             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4411             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4412             if ( !r_6.getName().equals( "rot" ) ) {
4413                 return false;
4414             }
4415             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4416             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4417             if ( !r_7.getName().equals( "rott" ) ) {
4418                 return false;
4419             }
4420         }
4421         catch ( final Exception e ) {
4422             e.printStackTrace( System.out );
4423             return false;
4424         }
4425         return true;
4426     }
4427
4428     private static boolean testGetLCA2() {
4429         try {
4430             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4431             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
4432             PhylogenyMethods.preOrderReId( p_a );
4433             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
4434                                                                                               p_a.getNode( "a" ) );
4435             if ( !p_a_1.getName().equals( "a" ) ) {
4436                 return false;
4437             }
4438             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4439             PhylogenyMethods.preOrderReId( p_b );
4440             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
4441                                                                                               p_b.getNode( "a" ) );
4442             if ( !p_b_1.getName().equals( "b" ) ) {
4443                 return false;
4444             }
4445             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
4446                                                                                               p_b.getNode( "b" ) );
4447             if ( !p_b_2.getName().equals( "b" ) ) {
4448                 return false;
4449             }
4450             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
4451             PhylogenyMethods.preOrderReId( p_c );
4452             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
4453                                                                                               p_c.getNode( "a" ) );
4454             if ( !p_c_1.getName().equals( "b" ) ) {
4455                 return false;
4456             }
4457             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4458                                                                                               p_c.getNode( "c" ) );
4459             if ( !p_c_2.getName().equals( "c" ) ) {
4460                 System.out.println( p_c_2.getName() );
4461                 System.exit( -1 );
4462                 return false;
4463             }
4464             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4465                                                                                               p_c.getNode( "b" ) );
4466             if ( !p_c_3.getName().equals( "b" ) ) {
4467                 return false;
4468             }
4469             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
4470                                                                                               p_c.getNode( "a" ) );
4471             if ( !p_c_4.getName().equals( "c" ) ) {
4472                 return false;
4473             }
4474             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4475                                                  new NHXParser() )[ 0 ];
4476             PhylogenyMethods.preOrderReId( p1 );
4477             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4478                                                                                           p1.getNode( "A" ) );
4479             if ( !A.getName().equals( "A" ) ) {
4480                 return false;
4481             }
4482             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
4483                                                                                            p1.getNode( "gh" ) );
4484             if ( !gh.getName().equals( "gh" ) ) {
4485                 return false;
4486             }
4487             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4488                                                                                            p1.getNode( "B" ) );
4489             if ( !ab.getName().equals( "ab" ) ) {
4490                 return false;
4491             }
4492             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4493                                                                                             p1.getNode( "A" ) );
4494             if ( !ab2.getName().equals( "ab" ) ) {
4495                 return false;
4496             }
4497             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4498                                                                                             p1.getNode( "G" ) );
4499             if ( !gh2.getName().equals( "gh" ) ) {
4500                 return false;
4501             }
4502             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
4503                                                                                             p1.getNode( "H" ) );
4504             if ( !gh3.getName().equals( "gh" ) ) {
4505                 return false;
4506             }
4507             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
4508                                                                                             p1.getNode( "A" ) );
4509             if ( !abc.getName().equals( "abc" ) ) {
4510                 return false;
4511             }
4512             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4513                                                                                              p1.getNode( "C" ) );
4514             if ( !abc2.getName().equals( "abc" ) ) {
4515                 return false;
4516             }
4517             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4518                                                                                              p1.getNode( "D" ) );
4519             if ( !abcd.getName().equals( "abcd" ) ) {
4520                 return false;
4521             }
4522             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
4523                                                                                               p1.getNode( "A" ) );
4524             if ( !abcd2.getName().equals( "abcd" ) ) {
4525                 return false;
4526             }
4527             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4528                                                                                                p1.getNode( "F" ) );
4529             if ( !abcdef.getName().equals( "abcdef" ) ) {
4530                 return false;
4531             }
4532             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4533                                                                                                 p1.getNode( "A" ) );
4534             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4535                 return false;
4536             }
4537             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4538                                                                                                 p1.getNode( "F" ) );
4539             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4540                 return false;
4541             }
4542             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4543                                                                                                 p1.getNode( "ab" ) );
4544             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4545                 return false;
4546             }
4547             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4548                                                                                               p1.getNode( "E" ) );
4549             if ( !abcde.getName().equals( "abcde" ) ) {
4550                 return false;
4551             }
4552             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4553                                                                                                p1.getNode( "A" ) );
4554             if ( !abcde2.getName().equals( "abcde" ) ) {
4555                 return false;
4556             }
4557             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
4558                                                                                           p1.getNode( "abcdefgh" ) );
4559             if ( !r.getName().equals( "abcdefgh" ) ) {
4560                 return false;
4561             }
4562             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4563                                                                                            p1.getNode( "H" ) );
4564             if ( !r2.getName().equals( "abcdefgh" ) ) {
4565                 return false;
4566             }
4567             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4568                                                                                            p1.getNode( "A" ) );
4569             if ( !r3.getName().equals( "abcdefgh" ) ) {
4570                 return false;
4571             }
4572             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4573                                                                                                p1.getNode( "abcde" ) );
4574             if ( !abcde3.getName().equals( "abcde" ) ) {
4575                 return false;
4576             }
4577             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
4578                                                                                                p1.getNode( "E" ) );
4579             if ( !abcde4.getName().equals( "abcde" ) ) {
4580                 return false;
4581             }
4582             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4583                                                                                             p1.getNode( "B" ) );
4584             if ( !ab3.getName().equals( "ab" ) ) {
4585                 return false;
4586             }
4587             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4588                                                                                             p1.getNode( "ab" ) );
4589             if ( !ab4.getName().equals( "ab" ) ) {
4590                 return false;
4591             }
4592             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4593             PhylogenyMethods.preOrderReId( p2 );
4594             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4595                                                                                            p2.getNode( "d" ) );
4596             if ( !cd.getName().equals( "cd" ) ) {
4597                 return false;
4598             }
4599             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4600                                                                                             p2.getNode( "c" ) );
4601             if ( !cd2.getName().equals( "cd" ) ) {
4602                 return false;
4603             }
4604             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4605                                                                                             p2.getNode( "e" ) );
4606             if ( !cde.getName().equals( "cde" ) ) {
4607                 return false;
4608             }
4609             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
4610                                                                                              p2.getNode( "c" ) );
4611             if ( !cde2.getName().equals( "cde" ) ) {
4612                 return false;
4613             }
4614             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4615                                                                                              p2.getNode( "f" ) );
4616             if ( !cdef.getName().equals( "cdef" ) ) {
4617                 return false;
4618             }
4619             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4620                                                                                               p2.getNode( "f" ) );
4621             if ( !cdef2.getName().equals( "cdef" ) ) {
4622                 return false;
4623             }
4624             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
4625                                                                                               p2.getNode( "d" ) );
4626             if ( !cdef3.getName().equals( "cdef" ) ) {
4627                 return false;
4628             }
4629             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4630                                                                                            p2.getNode( "a" ) );
4631             if ( !rt.getName().equals( "r" ) ) {
4632                 return false;
4633             }
4634             final Phylogeny p3 = factory
4635                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4636                              new NHXParser() )[ 0 ];
4637             PhylogenyMethods.preOrderReId( p3 );
4638             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
4639                                                                                              p3.getNode( "c" ) );
4640             if ( !bc_3.getName().equals( "bc" ) ) {
4641                 return false;
4642             }
4643             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4644                                                                                              p3.getNode( "c" ) );
4645             if ( !ac_3.getName().equals( "abc" ) ) {
4646                 return false;
4647             }
4648             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4649                                                                                              p3.getNode( "d" ) );
4650             if ( !ad_3.getName().equals( "abcde" ) ) {
4651                 return false;
4652             }
4653             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4654                                                                                              p3.getNode( "f" ) );
4655             if ( !af_3.getName().equals( "abcdef" ) ) {
4656                 return false;
4657             }
4658             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4659                                                                                              p3.getNode( "g" ) );
4660             if ( !ag_3.getName().equals( "" ) ) {
4661                 return false;
4662             }
4663             if ( !ag_3.isRoot() ) {
4664                 return false;
4665             }
4666             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4667                                                                                              p3.getNode( "l" ) );
4668             if ( !al_3.getName().equals( "" ) ) {
4669                 return false;
4670             }
4671             if ( !al_3.isRoot() ) {
4672                 return false;
4673             }
4674             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
4675                                                                                              p3.getNode( "l" ) );
4676             if ( !kl_3.getName().equals( "" ) ) {
4677                 return false;
4678             }
4679             if ( !kl_3.isRoot() ) {
4680                 return false;
4681             }
4682             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
4683                                                                                              p3.getNode( "l" ) );
4684             if ( !fl_3.getName().equals( "" ) ) {
4685                 return false;
4686             }
4687             if ( !fl_3.isRoot() ) {
4688                 return false;
4689             }
4690             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
4691                                                                                              p3.getNode( "k" ) );
4692             if ( !gk_3.getName().equals( "ghijk" ) ) {
4693                 return false;
4694             }
4695             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4696             PhylogenyMethods.preOrderReId( p4 );
4697             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
4698                                                                                             p4.getNode( "c" ) );
4699             if ( !r_4.getName().equals( "r" ) ) {
4700                 return false;
4701             }
4702             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4703             PhylogenyMethods.preOrderReId( p5 );
4704             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
4705                                                                                             p5.getNode( "c" ) );
4706             if ( !r_5.getName().equals( "root" ) ) {
4707                 return false;
4708             }
4709             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4710             PhylogenyMethods.preOrderReId( p6 );
4711             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
4712                                                                                             p6.getNode( "a" ) );
4713             if ( !r_6.getName().equals( "rot" ) ) {
4714                 return false;
4715             }
4716             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4717             PhylogenyMethods.preOrderReId( p7 );
4718             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4719                                                                                             p7.getNode( "e" ) );
4720             if ( !r_7.getName().equals( "rott" ) ) {
4721                 return false;
4722             }
4723             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4724                                                                                              p7.getNode( "a" ) );
4725             if ( !r_71.getName().equals( "rott" ) ) {
4726                 return false;
4727             }
4728             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4729                                                                                              p7.getNode( "rott" ) );
4730             if ( !r_72.getName().equals( "rott" ) ) {
4731                 return false;
4732             }
4733             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4734                                                                                              p7.getNode( "a" ) );
4735             if ( !r_73.getName().equals( "rott" ) ) {
4736                 return false;
4737             }
4738             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4739                                                                                              p7.getNode( "rott" ) );
4740             if ( !r_74.getName().equals( "rott" ) ) {
4741                 return false;
4742             }
4743             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4744                                                                                              p7.getNode( "e" ) );
4745             if ( !r_75.getName().equals( "e" ) ) {
4746                 return false;
4747             }
4748         }
4749         catch ( final Exception e ) {
4750             e.printStackTrace( System.out );
4751             return false;
4752         }
4753         return true;
4754     }
4755
4756     private static boolean testHmmscanOutputParser() {
4757         final String test_dir = Test.PATH_TO_TEST_DATA;
4758         try {
4759             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4760                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4761             parser1.parse();
4762             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4763                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4764             final List<Protein> proteins = parser2.parse();
4765             if ( parser2.getProteinsEncountered() != 4 ) {
4766                 return false;
4767             }
4768             if ( proteins.size() != 4 ) {
4769                 return false;
4770             }
4771             if ( parser2.getDomainsEncountered() != 69 ) {
4772                 return false;
4773             }
4774             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4775                 return false;
4776             }
4777             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4778                 return false;
4779             }
4780             final Protein p1 = proteins.get( 0 );
4781             if ( p1.getNumberOfProteinDomains() != 15 ) {
4782                 return false;
4783             }
4784             if ( p1.getLength() != 850 ) {
4785                 return false;
4786             }
4787             final Protein p2 = proteins.get( 1 );
4788             if ( p2.getNumberOfProteinDomains() != 51 ) {
4789                 return false;
4790             }
4791             if ( p2.getLength() != 1291 ) {
4792                 return false;
4793             }
4794             final Protein p3 = proteins.get( 2 );
4795             if ( p3.getNumberOfProteinDomains() != 2 ) {
4796                 return false;
4797             }
4798             final Protein p4 = proteins.get( 3 );
4799             if ( p4.getNumberOfProteinDomains() != 1 ) {
4800                 return false;
4801             }
4802             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4803                 return false;
4804             }
4805             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4806                 return false;
4807             }
4808             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4809                 return false;
4810             }
4811             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4812                 return false;
4813             }
4814             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4815                 return false;
4816             }
4817             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4818                 return false;
4819             }
4820             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4821                 return false;
4822             }
4823             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4824                 return false;
4825             }
4826             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4827                 return false;
4828             }
4829         }
4830         catch ( final Exception e ) {
4831             e.printStackTrace( System.out );
4832             return false;
4833         }
4834         return true;
4835     }
4836
4837     private static boolean testLastExternalNodeMethods() {
4838         try {
4839             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4840             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4841             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4842             final PhylogenyNode n1 = t0.getNode( "A" );
4843             if ( n1.isLastExternalNode() ) {
4844                 return false;
4845             }
4846             final PhylogenyNode n2 = t0.getNode( "B" );
4847             if ( n2.isLastExternalNode() ) {
4848                 return false;
4849             }
4850             final PhylogenyNode n3 = t0.getNode( "C" );
4851             if ( n3.isLastExternalNode() ) {
4852                 return false;
4853             }
4854             final PhylogenyNode n4 = t0.getNode( "D" );
4855             if ( !n4.isLastExternalNode() ) {
4856                 return false;
4857             }
4858         }
4859         catch ( final Exception e ) {
4860             e.printStackTrace( System.out );
4861             return false;
4862         }
4863         return true;
4864     }
4865
4866     private static boolean testLevelOrderIterator() {
4867         try {
4868             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4869             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4870             PhylogenyNodeIterator it0;
4871             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4872                 it0.next();
4873             }
4874             for( it0.reset(); it0.hasNext(); ) {
4875                 it0.next();
4876             }
4877             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4878             if ( !it.next().getName().equals( "r" ) ) {
4879                 return false;
4880             }
4881             if ( !it.next().getName().equals( "ab" ) ) {
4882                 return false;
4883             }
4884             if ( !it.next().getName().equals( "cd" ) ) {
4885                 return false;
4886             }
4887             if ( !it.next().getName().equals( "A" ) ) {
4888                 return false;
4889             }
4890             if ( !it.next().getName().equals( "B" ) ) {
4891                 return false;
4892             }
4893             if ( !it.next().getName().equals( "C" ) ) {
4894                 return false;
4895             }
4896             if ( !it.next().getName().equals( "D" ) ) {
4897                 return false;
4898             }
4899             if ( it.hasNext() ) {
4900                 return false;
4901             }
4902             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",
4903                                                  new NHXParser() )[ 0 ];
4904             PhylogenyNodeIterator it2;
4905             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4906                 it2.next();
4907             }
4908             for( it2.reset(); it2.hasNext(); ) {
4909                 it2.next();
4910             }
4911             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4912             if ( !it3.next().getName().equals( "r" ) ) {
4913                 return false;
4914             }
4915             if ( !it3.next().getName().equals( "abc" ) ) {
4916                 return false;
4917             }
4918             if ( !it3.next().getName().equals( "defg" ) ) {
4919                 return false;
4920             }
4921             if ( !it3.next().getName().equals( "A" ) ) {
4922                 return false;
4923             }
4924             if ( !it3.next().getName().equals( "B" ) ) {
4925                 return false;
4926             }
4927             if ( !it3.next().getName().equals( "C" ) ) {
4928                 return false;
4929             }
4930             if ( !it3.next().getName().equals( "D" ) ) {
4931                 return false;
4932             }
4933             if ( !it3.next().getName().equals( "E" ) ) {
4934                 return false;
4935             }
4936             if ( !it3.next().getName().equals( "F" ) ) {
4937                 return false;
4938             }
4939             if ( !it3.next().getName().equals( "G" ) ) {
4940                 return false;
4941             }
4942             if ( !it3.next().getName().equals( "1" ) ) {
4943                 return false;
4944             }
4945             if ( !it3.next().getName().equals( "2" ) ) {
4946                 return false;
4947             }
4948             if ( !it3.next().getName().equals( "3" ) ) {
4949                 return false;
4950             }
4951             if ( !it3.next().getName().equals( "4" ) ) {
4952                 return false;
4953             }
4954             if ( !it3.next().getName().equals( "5" ) ) {
4955                 return false;
4956             }
4957             if ( !it3.next().getName().equals( "6" ) ) {
4958                 return false;
4959             }
4960             if ( !it3.next().getName().equals( "f1" ) ) {
4961                 return false;
4962             }
4963             if ( !it3.next().getName().equals( "f2" ) ) {
4964                 return false;
4965             }
4966             if ( !it3.next().getName().equals( "f3" ) ) {
4967                 return false;
4968             }
4969             if ( !it3.next().getName().equals( "a" ) ) {
4970                 return false;
4971             }
4972             if ( !it3.next().getName().equals( "b" ) ) {
4973                 return false;
4974             }
4975             if ( !it3.next().getName().equals( "f21" ) ) {
4976                 return false;
4977             }
4978             if ( !it3.next().getName().equals( "X" ) ) {
4979                 return false;
4980             }
4981             if ( !it3.next().getName().equals( "Y" ) ) {
4982                 return false;
4983             }
4984             if ( !it3.next().getName().equals( "Z" ) ) {
4985                 return false;
4986             }
4987             if ( it3.hasNext() ) {
4988                 return false;
4989             }
4990             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4991             PhylogenyNodeIterator it4;
4992             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4993                 it4.next();
4994             }
4995             for( it4.reset(); it4.hasNext(); ) {
4996                 it4.next();
4997             }
4998             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4999             if ( !it5.next().getName().equals( "r" ) ) {
5000                 return false;
5001             }
5002             if ( !it5.next().getName().equals( "A" ) ) {
5003                 return false;
5004             }
5005             if ( !it5.next().getName().equals( "B" ) ) {
5006                 return false;
5007             }
5008             if ( !it5.next().getName().equals( "C" ) ) {
5009                 return false;
5010             }
5011             if ( !it5.next().getName().equals( "D" ) ) {
5012                 return false;
5013             }
5014             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5015             PhylogenyNodeIterator it6;
5016             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5017                 it6.next();
5018             }
5019             for( it6.reset(); it6.hasNext(); ) {
5020                 it6.next();
5021             }
5022             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5023             if ( !it7.next().getName().equals( "A" ) ) {
5024                 return false;
5025             }
5026             if ( it.hasNext() ) {
5027                 return false;
5028             }
5029         }
5030         catch ( final Exception e ) {
5031             e.printStackTrace( System.out );
5032             return false;
5033         }
5034         return true;
5035     }
5036
5037     private static boolean testMafft( final String path ) {
5038         try {
5039             final List<String> opts = new ArrayList<String>();
5040             opts.add( "--maxiterate" );
5041             opts.add( "1000" );
5042             opts.add( "--localpair" );
5043             opts.add( "--quiet" );
5044             Msa msa = null;
5045             final MsaInferrer mafft = Mafft.createInstance( path );
5046             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5047             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5048                 return false;
5049             }
5050             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5051                 return false;
5052             }
5053         }
5054         catch ( final Exception e ) {
5055             e.printStackTrace( System.out );
5056             return false;
5057         }
5058         return true;
5059     }
5060
5061     private static boolean testMidpointrooting() {
5062         try {
5063             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5064             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5065             PhylogenyMethods.midpointRoot( t0 );
5066             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5067                 return false;
5068             }
5069             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5070                 return false;
5071             }
5072             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5073                            1 ) ) {
5074                 return false;
5075             }
5076             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",
5077                                                  new NHXParser() )[ 0 ];
5078             if ( !t1.isRooted() ) {
5079                 return false;
5080             }
5081             PhylogenyMethods.midpointRoot( t1 );
5082             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5083                 return false;
5084             }
5085             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5086                 return false;
5087             }
5088             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5089                 return false;
5090             }
5091             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5092                 return false;
5093             }
5094             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5095                 return false;
5096             }
5097             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5098                 return false;
5099             }
5100             t1.reRoot( t1.getNode( "A" ) );
5101             PhylogenyMethods.midpointRoot( t1 );
5102             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5103                 return false;
5104             }
5105             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5106                 return false;
5107             }
5108             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5109                 return false;
5110             }
5111             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5112                 return false;
5113             }
5114             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5115                 System.exit( -1 );
5116                 return false;
5117             }
5118             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5119                 return false;
5120             }
5121         }
5122         catch ( final Exception e ) {
5123             e.printStackTrace( System.out );
5124             return false;
5125         }
5126         return true;
5127     }
5128
5129     private static boolean testMsaQualityMethod() {
5130         try {
5131             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5132             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5133             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5134             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5135             final List<Sequence> l = new ArrayList<Sequence>();
5136             l.add( s0 );
5137             l.add( s1 );
5138             l.add( s2 );
5139             l.add( s3 );
5140             final Msa msa = BasicMsa.createInstance( l );
5141             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5142                 return false;
5143             }
5144             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5145                 return false;
5146             }
5147             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5148                 return false;
5149             }
5150             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5151                 return false;
5152             }
5153         }
5154         catch ( final Exception e ) {
5155             e.printStackTrace( System.out );
5156             return false;
5157         }
5158         return true;
5159     }
5160
5161     private static boolean testNextNodeWithCollapsing() {
5162         try {
5163             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5164             PhylogenyNode n;
5165             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5166             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5167             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5168             t0.getNode( "cd" ).setCollapse( true );
5169             t0.getNode( "cde" ).setCollapse( true );
5170             n = t0.getFirstExternalNode();
5171             while ( n != null ) {
5172                 ext.add( n );
5173                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5174             }
5175             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5176                 return false;
5177             }
5178             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5179                 return false;
5180             }
5181             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5182                 return false;
5183             }
5184             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5185                 return false;
5186             }
5187             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5188                 return false;
5189             }
5190             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5191                 return false;
5192             }
5193             ext.clear();
5194             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5195             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5196             t1.getNode( "ab" ).setCollapse( true );
5197             t1.getNode( "cd" ).setCollapse( true );
5198             t1.getNode( "cde" ).setCollapse( true );
5199             n = t1.getNode( "ab" );
5200             ext = new ArrayList<PhylogenyNode>();
5201             while ( n != null ) {
5202                 ext.add( n );
5203                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5204             }
5205             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5206                 return false;
5207             }
5208             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5209                 return false;
5210             }
5211             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5212                 return false;
5213             }
5214             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5215                 return false;
5216             }
5217             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5218                 return false;
5219             }
5220             //
5221             //
5222             ext.clear();
5223             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5224             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5225             t2.getNode( "ab" ).setCollapse( true );
5226             t2.getNode( "cd" ).setCollapse( true );
5227             t2.getNode( "cde" ).setCollapse( true );
5228             t2.getNode( "c" ).setCollapse( true );
5229             t2.getNode( "d" ).setCollapse( true );
5230             t2.getNode( "e" ).setCollapse( true );
5231             t2.getNode( "gh" ).setCollapse( true );
5232             n = t2.getNode( "ab" );
5233             ext = new ArrayList<PhylogenyNode>();
5234             while ( n != null ) {
5235                 ext.add( n );
5236                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5237             }
5238             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5239                 return false;
5240             }
5241             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5242                 return false;
5243             }
5244             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5245                 return false;
5246             }
5247             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5248                 return false;
5249             }
5250             //
5251             //
5252             ext.clear();
5253             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5254             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5255             t3.getNode( "ab" ).setCollapse( true );
5256             t3.getNode( "cd" ).setCollapse( true );
5257             t3.getNode( "cde" ).setCollapse( true );
5258             t3.getNode( "c" ).setCollapse( true );
5259             t3.getNode( "d" ).setCollapse( true );
5260             t3.getNode( "e" ).setCollapse( true );
5261             t3.getNode( "gh" ).setCollapse( true );
5262             t3.getNode( "fgh" ).setCollapse( true );
5263             n = t3.getNode( "ab" );
5264             ext = new ArrayList<PhylogenyNode>();
5265             while ( n != null ) {
5266                 ext.add( n );
5267                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5268             }
5269             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5270                 return false;
5271             }
5272             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5273                 return false;
5274             }
5275             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5276                 return false;
5277             }
5278             //
5279             //
5280             ext.clear();
5281             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5282             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5283             t4.getNode( "ab" ).setCollapse( true );
5284             t4.getNode( "cd" ).setCollapse( true );
5285             t4.getNode( "cde" ).setCollapse( true );
5286             t4.getNode( "c" ).setCollapse( true );
5287             t4.getNode( "d" ).setCollapse( true );
5288             t4.getNode( "e" ).setCollapse( true );
5289             t4.getNode( "gh" ).setCollapse( true );
5290             t4.getNode( "fgh" ).setCollapse( true );
5291             t4.getNode( "abcdefgh" ).setCollapse( true );
5292             n = t4.getNode( "abcdefgh" );
5293             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5294                 return false;
5295             }
5296             //
5297             //
5298             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5299             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5300             ext.clear();
5301             n = t5.getFirstExternalNode();
5302             while ( n != null ) {
5303                 ext.add( n );
5304                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5305             }
5306             if ( ext.size() != 8 ) {
5307                 return false;
5308             }
5309             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5310                 return false;
5311             }
5312             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5313                 return false;
5314             }
5315             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5316                 return false;
5317             }
5318             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5319                 return false;
5320             }
5321             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5322                 return false;
5323             }
5324             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5325                 return false;
5326             }
5327             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5328                 return false;
5329             }
5330             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5331                 return false;
5332             }
5333             //
5334             //
5335             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5336             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5337             ext.clear();
5338             t6.getNode( "ab" ).setCollapse( true );
5339             n = t6.getNode( "ab" );
5340             while ( n != null ) {
5341                 ext.add( n );
5342                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5343             }
5344             if ( ext.size() != 7 ) {
5345                 return false;
5346             }
5347             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5348                 return false;
5349             }
5350             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5351                 return false;
5352             }
5353             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5354                 return false;
5355             }
5356             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5357                 return false;
5358             }
5359             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5360                 return false;
5361             }
5362             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5363                 return false;
5364             }
5365             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5366                 return false;
5367             }
5368             //
5369             //
5370             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5371             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5372             ext.clear();
5373             t7.getNode( "cd" ).setCollapse( true );
5374             n = t7.getNode( "a" );
5375             while ( n != null ) {
5376                 ext.add( n );
5377                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5378             }
5379             if ( ext.size() != 7 ) {
5380                 return false;
5381             }
5382             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5383                 return false;
5384             }
5385             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5386                 return false;
5387             }
5388             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5389                 return false;
5390             }
5391             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5392                 return false;
5393             }
5394             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5395                 return false;
5396             }
5397             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5398                 return false;
5399             }
5400             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5401                 return false;
5402             }
5403             //
5404             //
5405             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5406             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5407             ext.clear();
5408             t8.getNode( "cd" ).setCollapse( true );
5409             t8.getNode( "c" ).setCollapse( true );
5410             t8.getNode( "d" ).setCollapse( true );
5411             n = t8.getNode( "a" );
5412             while ( n != null ) {
5413                 ext.add( n );
5414                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5415             }
5416             if ( ext.size() != 7 ) {
5417                 return false;
5418             }
5419             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5420                 return false;
5421             }
5422             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5423                 return false;
5424             }
5425             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5426                 System.out.println( "2 fail" );
5427                 return false;
5428             }
5429             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5430                 return false;
5431             }
5432             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5433                 return false;
5434             }
5435             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5436                 return false;
5437             }
5438             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5439                 return false;
5440             }
5441             //
5442             //
5443             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5444             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
5445             ext.clear();
5446             t9.getNode( "gh" ).setCollapse( true );
5447             n = t9.getNode( "a" );
5448             while ( n != null ) {
5449                 ext.add( n );
5450                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5451             }
5452             if ( ext.size() != 7 ) {
5453                 return false;
5454             }
5455             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5456                 return false;
5457             }
5458             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5459                 return false;
5460             }
5461             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5462                 return false;
5463             }
5464             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5465                 return false;
5466             }
5467             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5468                 return false;
5469             }
5470             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5471                 return false;
5472             }
5473             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5474                 return false;
5475             }
5476             //
5477             //
5478             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5479             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
5480             ext.clear();
5481             t10.getNode( "gh" ).setCollapse( true );
5482             t10.getNode( "g" ).setCollapse( true );
5483             t10.getNode( "h" ).setCollapse( true );
5484             n = t10.getNode( "a" );
5485             while ( n != null ) {
5486                 ext.add( n );
5487                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5488             }
5489             if ( ext.size() != 7 ) {
5490                 return false;
5491             }
5492             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5493                 return false;
5494             }
5495             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5496                 return false;
5497             }
5498             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5499                 return false;
5500             }
5501             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5502                 return false;
5503             }
5504             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5505                 return false;
5506             }
5507             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5508                 return false;
5509             }
5510             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5511                 return false;
5512             }
5513             //
5514             //
5515             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5516             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
5517             ext.clear();
5518             t11.getNode( "gh" ).setCollapse( true );
5519             t11.getNode( "fgh" ).setCollapse( true );
5520             n = t11.getNode( "a" );
5521             while ( n != null ) {
5522                 ext.add( n );
5523                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5524             }
5525             if ( ext.size() != 6 ) {
5526                 return false;
5527             }
5528             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5529                 return false;
5530             }
5531             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5532                 return false;
5533             }
5534             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5535                 return false;
5536             }
5537             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5538                 return false;
5539             }
5540             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5541                 return false;
5542             }
5543             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5544                 return false;
5545             }
5546             //
5547             //
5548             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5549             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
5550             ext.clear();
5551             t12.getNode( "gh" ).setCollapse( true );
5552             t12.getNode( "fgh" ).setCollapse( true );
5553             t12.getNode( "g" ).setCollapse( true );
5554             t12.getNode( "h" ).setCollapse( true );
5555             t12.getNode( "f" ).setCollapse( true );
5556             n = t12.getNode( "a" );
5557             while ( n != null ) {
5558                 ext.add( n );
5559                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5560             }
5561             if ( ext.size() != 6 ) {
5562                 return false;
5563             }
5564             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5565                 return false;
5566             }
5567             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5568                 return false;
5569             }
5570             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5571                 return false;
5572             }
5573             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5574                 return false;
5575             }
5576             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5577                 return false;
5578             }
5579             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5580                 return false;
5581             }
5582             //
5583             //
5584             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5585             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
5586             ext.clear();
5587             t13.getNode( "ab" ).setCollapse( true );
5588             t13.getNode( "b" ).setCollapse( true );
5589             t13.getNode( "fgh" ).setCollapse( true );
5590             t13.getNode( "gh" ).setCollapse( true );
5591             n = t13.getNode( "ab" );
5592             while ( n != null ) {
5593                 ext.add( n );
5594                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5595             }
5596             if ( ext.size() != 5 ) {
5597                 return false;
5598             }
5599             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5600                 return false;
5601             }
5602             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5603                 return false;
5604             }
5605             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5606                 return false;
5607             }
5608             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5609                 return false;
5610             }
5611             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5612                 return false;
5613             }
5614             //
5615             //
5616             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
5617             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
5618             ext.clear();
5619             t14.getNode( "ab" ).setCollapse( true );
5620             t14.getNode( "a" ).setCollapse( true );
5621             t14.getNode( "fgh" ).setCollapse( true );
5622             t14.getNode( "gh" ).setCollapse( true );
5623             n = t14.getNode( "ab" );
5624             while ( n != null ) {
5625                 ext.add( n );
5626                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5627             }
5628             if ( ext.size() != 5 ) {
5629                 return false;
5630             }
5631             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5632                 return false;
5633             }
5634             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5635                 return false;
5636             }
5637             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5638                 return false;
5639             }
5640             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5641                 return false;
5642             }
5643             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5644                 return false;
5645             }
5646             //
5647             //
5648             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" );
5649             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
5650             ext.clear();
5651             t15.getNode( "ab" ).setCollapse( true );
5652             t15.getNode( "a" ).setCollapse( true );
5653             t15.getNode( "fgh" ).setCollapse( true );
5654             t15.getNode( "gh" ).setCollapse( true );
5655             n = t15.getNode( "ab" );
5656             while ( n != null ) {
5657                 ext.add( n );
5658                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5659             }
5660             if ( ext.size() != 6 ) {
5661                 return false;
5662             }
5663             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5664                 return false;
5665             }
5666             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5667                 return false;
5668             }
5669             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5670                 return false;
5671             }
5672             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5673                 return false;
5674             }
5675             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
5676                 return false;
5677             }
5678             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5679                 return false;
5680             }
5681             //
5682             //
5683             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" );
5684             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
5685             ext.clear();
5686             t16.getNode( "ab" ).setCollapse( true );
5687             t16.getNode( "a" ).setCollapse( true );
5688             t16.getNode( "fgh" ).setCollapse( true );
5689             t16.getNode( "gh" ).setCollapse( true );
5690             t16.getNode( "cd" ).setCollapse( true );
5691             t16.getNode( "cde" ).setCollapse( true );
5692             t16.getNode( "d" ).setCollapse( true );
5693             t16.getNode( "x" ).setCollapse( true );
5694             n = t16.getNode( "ab" );
5695             while ( n != null ) {
5696                 ext.add( n );
5697                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5698             }
5699             if ( ext.size() != 4 ) {
5700                 return false;
5701             }
5702             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5703                 return false;
5704             }
5705             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5706                 return false;
5707             }
5708             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
5709                 return false;
5710             }
5711             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
5712                 return false;
5713             }
5714         }
5715         catch ( final Exception e ) {
5716             e.printStackTrace( System.out );
5717             return false;
5718         }
5719         return true;
5720     }
5721
5722     private static boolean testNexusCharactersParsing() {
5723         try {
5724             final NexusCharactersParser parser = new NexusCharactersParser();
5725             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
5726             parser.parse();
5727             String[] labels = parser.getCharStateLabels();
5728             if ( labels.length != 7 ) {
5729                 return false;
5730             }
5731             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5732                 return false;
5733             }
5734             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5735                 return false;
5736             }
5737             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5738                 return false;
5739             }
5740             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5741                 return false;
5742             }
5743             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5744                 return false;
5745             }
5746             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5747                 return false;
5748             }
5749             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5750                 return false;
5751             }
5752             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5753             parser.parse();
5754             labels = parser.getCharStateLabels();
5755             if ( labels.length != 7 ) {
5756                 return false;
5757             }
5758             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5759                 return false;
5760             }
5761             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5762                 return false;
5763             }
5764             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5765                 return false;
5766             }
5767             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5768                 return false;
5769             }
5770             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5771                 return false;
5772             }
5773             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5774                 return false;
5775             }
5776             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5777                 return false;
5778             }
5779         }
5780         catch ( final Exception e ) {
5781             e.printStackTrace( System.out );
5782             return false;
5783         }
5784         return true;
5785     }
5786
5787     private static boolean testNexusMatrixParsing() {
5788         try {
5789             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
5790             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
5791             parser.parse();
5792             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
5793             if ( m.getNumberOfCharacters() != 9 ) {
5794                 return false;
5795             }
5796             if ( m.getNumberOfIdentifiers() != 5 ) {
5797                 return false;
5798             }
5799             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
5800                 return false;
5801             }
5802             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
5803                 return false;
5804             }
5805             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
5806                 return false;
5807             }
5808             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
5809                 return false;
5810             }
5811             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
5812                 return false;
5813             }
5814             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
5815                 return false;
5816             }
5817             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
5818                 return false;
5819             }
5820             //            if ( labels.length != 7 ) {
5821             //                return false;
5822             //            }
5823             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5824             //                return false;
5825             //            }
5826             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5827             //                return false;
5828             //            }
5829             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5830             //                return false;
5831             //            }
5832             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5833             //                return false;
5834             //            }
5835             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5836             //                return false;
5837             //            }
5838             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5839             //                return false;
5840             //            }
5841             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5842             //                return false;
5843             //            }
5844             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5845             //            parser.parse();
5846             //            labels = parser.getCharStateLabels();
5847             //            if ( labels.length != 7 ) {
5848             //                return false;
5849             //            }
5850             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5851             //                return false;
5852             //            }
5853             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5854             //                return false;
5855             //            }
5856             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5857             //                return false;
5858             //            }
5859             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5860             //                return false;
5861             //            }
5862             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5863             //                return false;
5864             //            }
5865             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5866             //                return false;
5867             //            }
5868             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5869             //                return false;
5870             //            }
5871         }
5872         catch ( final Exception e ) {
5873             e.printStackTrace( System.out );
5874             return false;
5875         }
5876         return true;
5877     }
5878
5879     private static boolean testNexusTreeParsing() {
5880         try {
5881             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5882             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5883             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
5884             if ( phylogenies.length != 1 ) {
5885                 return false;
5886             }
5887             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
5888                 return false;
5889             }
5890             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
5891                 return false;
5892             }
5893             phylogenies = null;
5894             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
5895             if ( phylogenies.length != 1 ) {
5896                 return false;
5897             }
5898             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
5899                 return false;
5900             }
5901             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
5902                 return false;
5903             }
5904             phylogenies = null;
5905             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
5906             if ( phylogenies.length != 1 ) {
5907                 return false;
5908             }
5909             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5910                 return false;
5911             }
5912             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
5913                 return false;
5914             }
5915             if ( phylogenies[ 0 ].isRooted() ) {
5916                 return false;
5917             }
5918             phylogenies = null;
5919             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
5920             if ( phylogenies.length != 18 ) {
5921                 return false;
5922             }
5923             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
5924                 return false;
5925             }
5926             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
5927                 return false;
5928             }
5929             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
5930                 return false;
5931             }
5932             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
5933                 return false;
5934             }
5935             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5936                 return false;
5937             }
5938             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
5939                 return false;
5940             }
5941             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
5942                 return false;
5943             }
5944             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
5945                 return false;
5946             }
5947             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
5948                 return false;
5949             }
5950             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
5951                 return false;
5952             }
5953             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
5954                 return false;
5955             }
5956             if ( phylogenies[ 8 ].isRooted() ) {
5957                 return false;
5958             }
5959             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
5960                 return false;
5961             }
5962             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
5963                 return false;
5964             }
5965             if ( !phylogenies[ 9 ].isRooted() ) {
5966                 return false;
5967             }
5968             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
5969                 return false;
5970             }
5971             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
5972                 return false;
5973             }
5974             if ( !phylogenies[ 10 ].isRooted() ) {
5975                 return false;
5976             }
5977             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
5978                 return false;
5979             }
5980             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
5981                 return false;
5982             }
5983             if ( phylogenies[ 11 ].isRooted() ) {
5984                 return false;
5985             }
5986             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
5987                 return false;
5988             }
5989             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
5990                 return false;
5991             }
5992             if ( !phylogenies[ 12 ].isRooted() ) {
5993                 return false;
5994             }
5995             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
5996                 return false;
5997             }
5998             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
5999                 return false;
6000             }
6001             if ( !phylogenies[ 13 ].isRooted() ) {
6002                 return false;
6003             }
6004             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6005                 return false;
6006             }
6007             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6008                 return false;
6009             }
6010             if ( !phylogenies[ 14 ].isRooted() ) {
6011                 return false;
6012             }
6013             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6014                 return false;
6015             }
6016             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6017                 return false;
6018             }
6019             if ( phylogenies[ 15 ].isRooted() ) {
6020                 return false;
6021             }
6022             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6023                 return false;
6024             }
6025             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6026                 return false;
6027             }
6028             if ( !phylogenies[ 16 ].isRooted() ) {
6029                 return false;
6030             }
6031             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6032                 return false;
6033             }
6034             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6035                 return false;
6036             }
6037             if ( phylogenies[ 17 ].isRooted() ) {
6038                 return false;
6039             }
6040             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6041                 return false;
6042             }
6043         }
6044         catch ( final Exception e ) {
6045             e.printStackTrace( System.out );
6046             return false;
6047         }
6048         return true;
6049     }
6050
6051     private static boolean testNexusTreeParsingIterating() {
6052         try {
6053             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6054             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6055             if ( !p.hasNext() ) {
6056                 return false;
6057             }
6058             Phylogeny phy = p.next();
6059             if ( phy == null ) {
6060                 return false;
6061             }
6062             if ( phy.getNumberOfExternalNodes() != 25 ) {
6063                 return false;
6064             }
6065             if ( !phy.getName().equals( "" ) ) {
6066                 return false;
6067             }
6068             if ( p.hasNext() ) {
6069                 return false;
6070             }
6071             phy = p.next();
6072             if ( phy != null ) {
6073                 return false;
6074             }
6075             //
6076             p.reset();
6077             if ( !p.hasNext() ) {
6078                 return false;
6079             }
6080             phy = p.next();
6081             if ( phy == null ) {
6082                 return false;
6083             }
6084             if ( phy.getNumberOfExternalNodes() != 25 ) {
6085                 return false;
6086             }
6087             if ( !phy.getName().equals( "" ) ) {
6088                 return false;
6089             }
6090             if ( p.hasNext() ) {
6091                 return false;
6092             }
6093             phy = p.next();
6094             if ( phy != null ) {
6095                 return false;
6096             }
6097             ////
6098             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6099             if ( !p.hasNext() ) {
6100                 return false;
6101             }
6102             phy = p.next();
6103             if ( phy == null ) {
6104                 return false;
6105             }
6106             if ( phy.getNumberOfExternalNodes() != 10 ) {
6107                 return false;
6108             }
6109             if ( !phy.getName().equals( "name" ) ) {
6110                 return false;
6111             }
6112             if ( p.hasNext() ) {
6113                 return false;
6114             }
6115             phy = p.next();
6116             if ( phy != null ) {
6117                 return false;
6118             }
6119             //
6120             p.reset();
6121             if ( !p.hasNext() ) {
6122                 return false;
6123             }
6124             phy = p.next();
6125             if ( phy == null ) {
6126                 return false;
6127             }
6128             if ( phy.getNumberOfExternalNodes() != 10 ) {
6129                 return false;
6130             }
6131             if ( !phy.getName().equals( "name" ) ) {
6132                 return false;
6133             }
6134             if ( p.hasNext() ) {
6135                 return false;
6136             }
6137             phy = p.next();
6138             if ( phy != null ) {
6139                 return false;
6140             }
6141             ////
6142             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6143             if ( !p.hasNext() ) {
6144                 return false;
6145             }
6146             phy = p.next();
6147             if ( phy == null ) {
6148                 return false;
6149             }
6150             if ( phy.getNumberOfExternalNodes() != 3 ) {
6151                 return false;
6152             }
6153             if ( !phy.getName().equals( "" ) ) {
6154                 return false;
6155             }
6156             if ( phy.isRooted() ) {
6157                 return false;
6158             }
6159             if ( p.hasNext() ) {
6160                 return false;
6161             }
6162             phy = p.next();
6163             if ( phy != null ) {
6164                 return false;
6165             }
6166             //
6167             p.reset();
6168             if ( !p.hasNext() ) {
6169                 return false;
6170             }
6171             phy = p.next();
6172             if ( phy == null ) {
6173                 return false;
6174             }
6175             if ( phy.getNumberOfExternalNodes() != 3 ) {
6176                 return false;
6177             }
6178             if ( !phy.getName().equals( "" ) ) {
6179                 return false;
6180             }
6181             if ( p.hasNext() ) {
6182                 return false;
6183             }
6184             phy = p.next();
6185             if ( phy != null ) {
6186                 return false;
6187             }
6188             ////
6189             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6190             //            if ( phylogenies.length != 18 ) {
6191             //                return false;
6192             //            }
6193             //0
6194             if ( !p.hasNext() ) {
6195                 return false;
6196             }
6197             phy = p.next();
6198             if ( phy == null ) {
6199                 return false;
6200             }
6201             if ( phy.getNumberOfExternalNodes() != 10 ) {
6202                 return false;
6203             }
6204             if ( !phy.getName().equals( "tree 0" ) ) {
6205                 return false;
6206             }
6207             //1
6208             if ( !p.hasNext() ) {
6209                 return false;
6210             }
6211             phy = p.next();
6212             if ( phy == null ) {
6213                 return false;
6214             }
6215             if ( phy.getNumberOfExternalNodes() != 10 ) {
6216                 return false;
6217             }
6218             if ( !phy.getName().equals( "tree 1" ) ) {
6219                 return false;
6220             }
6221             //2
6222             if ( !p.hasNext() ) {
6223                 return false;
6224             }
6225             phy = p.next();
6226             if ( phy == null ) {
6227                 return false;
6228             }
6229             if ( phy.getNumberOfExternalNodes() != 3 ) {
6230                 return false;
6231             }
6232             if ( !phy.getName().equals( "" ) ) {
6233                 return false;
6234             }
6235             if ( phy.isRooted() ) {
6236                 return false;
6237             }
6238             //3
6239             if ( !p.hasNext() ) {
6240                 return false;
6241             }
6242             phy = p.next();
6243             if ( phy == null ) {
6244                 return false;
6245             }
6246             if ( phy.getNumberOfExternalNodes() != 4 ) {
6247                 return false;
6248             }
6249             if ( !phy.getName().equals( "" ) ) {
6250                 return false;
6251             }
6252             if ( !phy.isRooted() ) {
6253                 return false;
6254             }
6255             //4
6256             if ( !p.hasNext() ) {
6257                 return false;
6258             }
6259             phy = p.next();
6260             if ( phy == null ) {
6261                 return false;
6262             }
6263             if ( phy.getNumberOfExternalNodes() != 5 ) {
6264                 System.out.println( phy.getNumberOfExternalNodes() );
6265                 return false;
6266             }
6267             if ( !phy.getName().equals( "" ) ) {
6268                 return false;
6269             }
6270             if ( !phy.isRooted() ) {
6271                 return false;
6272             }
6273             //5
6274             if ( !p.hasNext() ) {
6275                 return false;
6276             }
6277             phy = p.next();
6278             if ( phy == null ) {
6279                 return false;
6280             }
6281             if ( phy.getNumberOfExternalNodes() != 3 ) {
6282                 return false;
6283             }
6284             if ( !phy.getName().equals( "" ) ) {
6285                 return false;
6286             }
6287             if ( phy.isRooted() ) {
6288                 return false;
6289             }
6290             //6
6291             if ( !p.hasNext() ) {
6292                 return false;
6293             }
6294             phy = p.next();
6295             if ( phy == null ) {
6296                 return false;
6297             }
6298             if ( phy.getNumberOfExternalNodes() != 2 ) {
6299                 return false;
6300             }
6301             if ( !phy.getName().equals( "" ) ) {
6302                 return false;
6303             }
6304             if ( !phy.isRooted() ) {
6305                 return false;
6306             }
6307             //7
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),c);" ) ) {
6316                 return false;
6317             }
6318             if ( !phy.isRooted() ) {
6319                 return false;
6320             }
6321             //8
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( "((AA,BB),CC);" ) ) {
6330                 return false;
6331             }
6332             if ( !phy.getName().equals( "tree 8" ) ) {
6333                 return false;
6334             }
6335             //9
6336             if ( !p.hasNext() ) {
6337                 return false;
6338             }
6339             phy = p.next();
6340             if ( phy.getNumberOfExternalNodes() != 3 ) {
6341                 return false;
6342             }
6343             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6344                 return false;
6345             }
6346             if ( !phy.getName().equals( "tree 9" ) ) {
6347                 return false;
6348             }
6349             //10
6350             if ( !p.hasNext() ) {
6351                 return false;
6352             }
6353             phy = p.next();
6354             if ( phy.getNumberOfExternalNodes() != 3 ) {
6355                 return false;
6356             }
6357             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6358                 return false;
6359             }
6360             if ( !phy.getName().equals( "tree 10" ) ) {
6361                 return false;
6362             }
6363             if ( !phy.isRooted() ) {
6364                 return false;
6365             }
6366             //11
6367             if ( !p.hasNext() ) {
6368                 return false;
6369             }
6370             phy = p.next();
6371             if ( phy.getNumberOfExternalNodes() != 3 ) {
6372                 return false;
6373             }
6374             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6375                 return false;
6376             }
6377             if ( !phy.getName().equals( "tree 11" ) ) {
6378                 return false;
6379             }
6380             if ( phy.isRooted() ) {
6381                 return false;
6382             }
6383             //12
6384             if ( !p.hasNext() ) {
6385                 return false;
6386             }
6387             phy = p.next();
6388             if ( phy.getNumberOfExternalNodes() != 3 ) {
6389                 return false;
6390             }
6391             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6392                 return false;
6393             }
6394             if ( !phy.getName().equals( "tree 12" ) ) {
6395                 return false;
6396             }
6397             if ( !phy.isRooted() ) {
6398                 return false;
6399             }
6400             //13
6401             if ( !p.hasNext() ) {
6402                 return false;
6403             }
6404             phy = p.next();
6405             if ( phy.getNumberOfExternalNodes() != 3 ) {
6406                 return false;
6407             }
6408             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6409                 return false;
6410             }
6411             if ( !phy.getName().equals( "tree 13" ) ) {
6412                 return false;
6413             }
6414             if ( !phy.isRooted() ) {
6415                 return false;
6416             }
6417             //14
6418             if ( !p.hasNext() ) {
6419                 return false;
6420             }
6421             phy = p.next();
6422             if ( phy.getNumberOfExternalNodes() != 10 ) {
6423                 System.out.println( phy.getNumberOfExternalNodes() );
6424                 return false;
6425             }
6426             if ( !phy
6427                     .toNewHampshire()
6428                     .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;" ) ) {
6429                 System.out.println( phy.toNewHampshire() );
6430                 return false;
6431             }
6432             if ( !phy.getName().equals( "tree 14" ) ) {
6433                 return false;
6434             }
6435             if ( !phy.isRooted() ) {
6436                 return false;
6437             }
6438             //15
6439             if ( !p.hasNext() ) {
6440                 return false;
6441             }
6442             phy = p.next();
6443             if ( phy.getNumberOfExternalNodes() != 10 ) {
6444                 System.out.println( phy.getNumberOfExternalNodes() );
6445                 return false;
6446             }
6447             if ( !phy
6448                     .toNewHampshire()
6449                     .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;" ) ) {
6450                 System.out.println( phy.toNewHampshire() );
6451                 return false;
6452             }
6453             if ( !phy.getName().equals( "tree 15" ) ) {
6454                 return false;
6455             }
6456             if ( phy.isRooted() ) {
6457                 return false;
6458             }
6459             //16
6460             if ( !p.hasNext() ) {
6461                 return false;
6462             }
6463             phy = p.next();
6464             if ( phy.getNumberOfExternalNodes() != 10 ) {
6465                 System.out.println( phy.getNumberOfExternalNodes() );
6466                 return false;
6467             }
6468             if ( !phy
6469                     .toNewHampshire()
6470                     .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;" ) ) {
6471                 System.out.println( phy.toNewHampshire() );
6472                 return false;
6473             }
6474             if ( !phy.getName().equals( "tree 16" ) ) {
6475                 return false;
6476             }
6477             if ( !phy.isRooted() ) {
6478                 return false;
6479             }
6480             //17
6481             if ( !p.hasNext() ) {
6482                 return false;
6483             }
6484             phy = p.next();
6485             if ( phy.getNumberOfExternalNodes() != 10 ) {
6486                 System.out.println( phy.getNumberOfExternalNodes() );
6487                 return false;
6488             }
6489             if ( !phy
6490                     .toNewHampshire()
6491                     .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;" ) ) {
6492                 System.out.println( phy.toNewHampshire() );
6493                 return false;
6494             }
6495             if ( !phy.getName().equals( "tree 17" ) ) {
6496                 return false;
6497             }
6498             if ( phy.isRooted() ) {
6499                 return false;
6500             }
6501             //
6502             if ( p.hasNext() ) {
6503                 return false;
6504             }
6505             phy = p.next();
6506             if ( phy != null ) {
6507                 return false;
6508             }
6509             p.reset();
6510             //0
6511             if ( !p.hasNext() ) {
6512                 return false;
6513             }
6514             phy = p.next();
6515             if ( phy == null ) {
6516                 return false;
6517             }
6518             if ( phy.getNumberOfExternalNodes() != 10 ) {
6519                 return false;
6520             }
6521             if ( !phy.getName().equals( "tree 0" ) ) {
6522                 return false;
6523             }
6524             //1
6525             if ( !p.hasNext() ) {
6526                 return false;
6527             }
6528             phy = p.next();
6529             if ( phy == null ) {
6530                 return false;
6531             }
6532             if ( phy.getNumberOfExternalNodes() != 10 ) {
6533                 return false;
6534             }
6535             if ( !phy.getName().equals( "tree 1" ) ) {
6536                 return false;
6537             }
6538             //2
6539             if ( !p.hasNext() ) {
6540                 return false;
6541             }
6542             phy = p.next();
6543             if ( phy == null ) {
6544                 return false;
6545             }
6546             if ( phy.getNumberOfExternalNodes() != 3 ) {
6547                 return false;
6548             }
6549             if ( !phy.getName().equals( "" ) ) {
6550                 return false;
6551             }
6552             if ( phy.isRooted() ) {
6553                 return false;
6554             }
6555             //3
6556             if ( !p.hasNext() ) {
6557                 return false;
6558             }
6559             phy = p.next();
6560             if ( phy == null ) {
6561                 return false;
6562             }
6563             if ( phy.getNumberOfExternalNodes() != 4 ) {
6564                 return false;
6565             }
6566             if ( !phy.getName().equals( "" ) ) {
6567                 return false;
6568             }
6569             if ( !phy.isRooted() ) {
6570                 return false;
6571             }
6572             //4
6573             if ( !p.hasNext() ) {
6574                 return false;
6575             }
6576             phy = p.next();
6577             if ( phy == null ) {
6578                 return false;
6579             }
6580             if ( phy.getNumberOfExternalNodes() != 5 ) {
6581                 System.out.println( phy.getNumberOfExternalNodes() );
6582                 return false;
6583             }
6584             if ( !phy.getName().equals( "" ) ) {
6585                 return false;
6586             }
6587             if ( !phy.isRooted() ) {
6588                 return false;
6589             }
6590             //5
6591             if ( !p.hasNext() ) {
6592                 return false;
6593             }
6594             phy = p.next();
6595             if ( phy == null ) {
6596                 return false;
6597             }
6598             if ( phy.getNumberOfExternalNodes() != 3 ) {
6599                 return false;
6600             }
6601             if ( !phy.getName().equals( "" ) ) {
6602                 return false;
6603             }
6604             if ( phy.isRooted() ) {
6605                 return false;
6606             }
6607         }
6608         catch ( final Exception e ) {
6609             e.printStackTrace( System.out );
6610             return false;
6611         }
6612         return true;
6613     }
6614
6615     private static boolean testNexusTreeParsingTranslating() {
6616         try {
6617             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6618             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6619             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
6620             if ( phylogenies.length != 1 ) {
6621                 return false;
6622             }
6623             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6624                 return false;
6625             }
6626             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6627                 return false;
6628             }
6629             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6630                 return false;
6631             }
6632             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6633                 return false;
6634             }
6635             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6636                     .equals( "Aranaeus" ) ) {
6637                 return false;
6638             }
6639             phylogenies = null;
6640             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
6641             if ( phylogenies.length != 3 ) {
6642                 return false;
6643             }
6644             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6645                 return false;
6646             }
6647             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6648                 return false;
6649             }
6650             if ( phylogenies[ 0 ].isRooted() ) {
6651                 return false;
6652             }
6653             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6654                 return false;
6655             }
6656             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6657                 return false;
6658             }
6659             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6660                     .equals( "Aranaeus" ) ) {
6661                 return false;
6662             }
6663             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6664                 return false;
6665             }
6666             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6667                 return false;
6668             }
6669             if ( phylogenies[ 1 ].isRooted() ) {
6670                 return false;
6671             }
6672             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6673                 return false;
6674             }
6675             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6676                 return false;
6677             }
6678             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6679                     .equals( "Aranaeus" ) ) {
6680                 return false;
6681             }
6682             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6683                 return false;
6684             }
6685             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6686                 return false;
6687             }
6688             if ( !phylogenies[ 2 ].isRooted() ) {
6689                 return false;
6690             }
6691             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6692                 return false;
6693             }
6694             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6695                 return false;
6696             }
6697             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6698                     .equals( "Aranaeus" ) ) {
6699                 return false;
6700             }
6701             phylogenies = null;
6702             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
6703             if ( phylogenies.length != 3 ) {
6704                 return false;
6705             }
6706             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6707                 return false;
6708             }
6709             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6710                 return false;
6711             }
6712             if ( phylogenies[ 0 ].isRooted() ) {
6713                 return false;
6714             }
6715             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6716                 return false;
6717             }
6718             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6719                 return false;
6720             }
6721             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6722                     .equals( "Aranaeus" ) ) {
6723                 return false;
6724             }
6725             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6726                 return false;
6727             }
6728             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6729                 return false;
6730             }
6731             if ( phylogenies[ 1 ].isRooted() ) {
6732                 return false;
6733             }
6734             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6735                 return false;
6736             }
6737             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6738                 return false;
6739             }
6740             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6741                     .equals( "Aranaeus" ) ) {
6742                 return false;
6743             }
6744             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6745                 return false;
6746             }
6747             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6748                 return false;
6749             }
6750             if ( !phylogenies[ 2 ].isRooted() ) {
6751                 return false;
6752             }
6753             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6754                 return false;
6755             }
6756             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6757                 return false;
6758             }
6759             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6760                     .equals( "Aranaeus" ) ) {
6761                 return false;
6762             }
6763         }
6764         catch ( final Exception e ) {
6765             e.printStackTrace( System.out );
6766             return false;
6767         }
6768         return true;
6769     }
6770
6771     private static boolean testNHParsing() {
6772         try {
6773             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6774             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
6775             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
6776                 return false;
6777             }
6778             final NHXParser nhxp = new NHXParser();
6779             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
6780             nhxp.setReplaceUnderscores( true );
6781             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
6782             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
6783                 return false;
6784             }
6785             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
6786                 return false;
6787             }
6788             final Phylogeny p1b = factory
6789                     .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 ",
6790                              new NHXParser() )[ 0 ];
6791             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
6792                 return false;
6793             }
6794             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
6795                 return false;
6796             }
6797             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
6798             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
6799             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
6800             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
6801             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
6802             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
6803             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
6804             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
6805             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
6806             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
6807             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
6808                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
6809                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
6810                                                     new NHXParser() );
6811             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
6812                 return false;
6813             }
6814             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
6815                 return false;
6816             }
6817             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
6818                 return false;
6819             }
6820             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
6821                 return false;
6822             }
6823             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
6824             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
6825             final String p16_S = "((A,B),C)";
6826             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
6827             if ( p16.length != 1 ) {
6828                 return false;
6829             }
6830             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
6831                 return false;
6832             }
6833             final String p17_S = "(C,(A,B))";
6834             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
6835             if ( p17.length != 1 ) {
6836                 return false;
6837             }
6838             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
6839                 return false;
6840             }
6841             final String p18_S = "((A,B),(C,D))";
6842             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
6843             if ( p18.length != 1 ) {
6844                 return false;
6845             }
6846             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
6847                 return false;
6848             }
6849             final String p19_S = "(((A,B),C),D)";
6850             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
6851             if ( p19.length != 1 ) {
6852                 return false;
6853             }
6854             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
6855                 return false;
6856             }
6857             final String p20_S = "(A,(B,(C,D)))";
6858             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
6859             if ( p20.length != 1 ) {
6860                 return false;
6861             }
6862             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
6863                 return false;
6864             }
6865             final String p21_S = "(A,(B,(C,(D,E))))";
6866             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
6867             if ( p21.length != 1 ) {
6868                 return false;
6869             }
6870             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
6871                 return false;
6872             }
6873             final String p22_S = "((((A,B),C),D),E)";
6874             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
6875             if ( p22.length != 1 ) {
6876                 return false;
6877             }
6878             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
6879                 return false;
6880             }
6881             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6882             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
6883             if ( p23.length != 1 ) {
6884                 System.out.println( "xl=" + p23.length );
6885                 System.exit( -1 );
6886                 return false;
6887             }
6888             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
6889                 return false;
6890             }
6891             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6892             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
6893             if ( p24.length != 1 ) {
6894                 return false;
6895             }
6896             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
6897                 return false;
6898             }
6899             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6900             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6901             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
6902             if ( p241.length != 2 ) {
6903                 return false;
6904             }
6905             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
6906                 return false;
6907             }
6908             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
6909                 return false;
6910             }
6911             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
6912                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
6913                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
6914                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
6915                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
6916                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
6917                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
6918                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
6919             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
6920             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
6921                 return false;
6922             }
6923             final String p26_S = "(A,B)ab";
6924             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
6925             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
6926                 return false;
6927             }
6928             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6929             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
6930             if ( p27s.length != 1 ) {
6931                 System.out.println( "xxl=" + p27s.length );
6932                 System.exit( -1 );
6933                 return false;
6934             }
6935             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
6936                 System.out.println( p27s[ 0 ].toNewHampshireX() );
6937                 System.exit( -1 );
6938                 return false;
6939             }
6940             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
6941                                                     new NHXParser() );
6942             if ( p27.length != 1 ) {
6943                 System.out.println( "yl=" + p27.length );
6944                 System.exit( -1 );
6945                 return false;
6946             }
6947             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
6948                 System.out.println( p27[ 0 ].toNewHampshireX() );
6949                 System.exit( -1 );
6950                 return false;
6951             }
6952             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6953             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6954             final String p28_S3 = "(A,B)ab";
6955             final String p28_S4 = "((((A,B),C),D),;E;)";
6956             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
6957                                                     new NHXParser() );
6958             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
6959                 return false;
6960             }
6961             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
6962                 return false;
6963             }
6964             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
6965                 return false;
6966             }
6967             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
6968                 return false;
6969             }
6970             if ( p28.length != 4 ) {
6971                 return false;
6972             }
6973             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";
6974             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
6975             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
6976                 return false;
6977             }
6978             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";
6979             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
6980             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
6981                 return false;
6982             }
6983             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
6984             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
6985             if ( ( p32.length != 0 ) ) {
6986                 return false;
6987             }
6988             final String p33_S = "A";
6989             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
6990             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
6991                 return false;
6992             }
6993             final String p34_S = "B;";
6994             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
6995             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
6996                 return false;
6997             }
6998             final String p35_S = "B:0.2";
6999             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7000             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7001                 return false;
7002             }
7003             final String p36_S = "(A)";
7004             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7005             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7006                 return false;
7007             }
7008             final String p37_S = "((A))";
7009             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7010             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7011                 return false;
7012             }
7013             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7014             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7015             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7016                 return false;
7017             }
7018             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7019             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7020             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7021                 return false;
7022             }
7023             final String p40_S = "(A,B,C)";
7024             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7025             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7026                 return false;
7027             }
7028             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7029             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7030             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7031                 return false;
7032             }
7033             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7034             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7035             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7036                 return false;
7037             }
7038             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)";
7039             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7040             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7041                 return false;
7042             }
7043             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)))";
7044             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7045             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7046                 return false;
7047             }
7048             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7049             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7050             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7051                 return false;
7052             }
7053             final String p46_S = "";
7054             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7055             if ( p46.length != 0 ) {
7056                 return false;
7057             }
7058             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7059             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7060                 return false;
7061             }
7062             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7063             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7064                 return false;
7065             }
7066             final Phylogeny p49 = factory
7067                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7068                              new NHXParser() )[ 0 ];
7069             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7070                 return false;
7071             }
7072             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7073             if ( p50.getNode( "A" ) == null ) {
7074                 return false;
7075             }
7076             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7077                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7078                 return false;
7079             }
7080             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7081                 return false;
7082             }
7083             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7084                     .equals( "((A,B)88:2.0,C);" ) ) {
7085                 return false;
7086             }
7087             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7088             if ( p51.getNode( "A(A" ) == null ) {
7089                 return false;
7090             }
7091             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7092             if ( p52.getNode( "A(A" ) == null ) {
7093                 return false;
7094             }
7095             final Phylogeny p53 = factory
7096                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7097                              new NHXParser() )[ 0 ];
7098             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7099                 return false;
7100             }
7101             // 
7102             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7103             if ( p54.getNode( "A" ) == null ) {
7104                 return false;
7105             }
7106             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7107                     .equals( "((A,B)[88],C);" ) ) {
7108                 return false;
7109             }
7110         }
7111         catch ( final Exception e ) {
7112             e.printStackTrace( System.out );
7113             return false;
7114         }
7115         return true;
7116     }
7117
7118     private static boolean testNHParsingIter() {
7119         try {
7120             final String p0_str = "(A,B);";
7121             final NHXParser p = new NHXParser();
7122             p.setSource( p0_str );
7123             if ( !p.hasNext() ) {
7124                 return false;
7125             }
7126             final Phylogeny p0 = p.next();
7127             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7128                 System.out.println( p0.toNewHampshire() );
7129                 return false;
7130             }
7131             if ( p.hasNext() ) {
7132                 return false;
7133             }
7134             if ( p.next() != null ) {
7135                 return false;
7136             }
7137             //
7138             final String p00_str = "(A,B)root;";
7139             p.setSource( p00_str );
7140             final Phylogeny p00 = p.next();
7141             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7142                 System.out.println( p00.toNewHampshire() );
7143                 return false;
7144             }
7145             //
7146             final String p000_str = "A;";
7147             p.setSource( p000_str );
7148             final Phylogeny p000 = p.next();
7149             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7150                 System.out.println( p000.toNewHampshire() );
7151                 return false;
7152             }
7153             //
7154             final String p0000_str = "A";
7155             p.setSource( p0000_str );
7156             final Phylogeny p0000 = p.next();
7157             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7158                 System.out.println( p0000.toNewHampshire() );
7159                 return false;
7160             }
7161             //
7162             p.setSource( "(A)" );
7163             final Phylogeny p00000 = p.next();
7164             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7165                 System.out.println( p00000.toNewHampshire() );
7166                 return false;
7167             }
7168             //
7169             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7170             p.setSource( p1_str );
7171             if ( !p.hasNext() ) {
7172                 return false;
7173             }
7174             final Phylogeny p1_0 = p.next();
7175             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7176                 System.out.println( p1_0.toNewHampshire() );
7177                 return false;
7178             }
7179             if ( !p.hasNext() ) {
7180                 return false;
7181             }
7182             final Phylogeny p1_1 = p.next();
7183             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7184                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7185                 return false;
7186             }
7187             if ( !p.hasNext() ) {
7188                 return false;
7189             }
7190             final Phylogeny p1_2 = p.next();
7191             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7192                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7193                 return false;
7194             }
7195             if ( !p.hasNext() ) {
7196                 return false;
7197             }
7198             final Phylogeny p1_3 = p.next();
7199             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7200                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7201                 return false;
7202             }
7203             if ( p.hasNext() ) {
7204                 return false;
7205             }
7206             if ( p.next() != null ) {
7207                 return false;
7208             }
7209             //
7210             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7211             p.setSource( p2_str );
7212             if ( !p.hasNext() ) {
7213                 return false;
7214             }
7215             Phylogeny p2_0 = p.next();
7216             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7217                 System.out.println( p2_0.toNewHampshire() );
7218                 return false;
7219             }
7220             if ( !p.hasNext() ) {
7221                 return false;
7222             }
7223             Phylogeny p2_1 = p.next();
7224             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7225                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7226                 return false;
7227             }
7228             if ( !p.hasNext() ) {
7229                 return false;
7230             }
7231             Phylogeny p2_2 = p.next();
7232             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7233                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7234                 return false;
7235             }
7236             if ( !p.hasNext() ) {
7237                 return false;
7238             }
7239             Phylogeny p2_3 = p.next();
7240             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7241                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7242                 return false;
7243             }
7244             if ( !p.hasNext() ) {
7245                 return false;
7246             }
7247             Phylogeny p2_4 = p.next();
7248             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7249                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7250                 return false;
7251             }
7252             if ( p.hasNext() ) {
7253                 return false;
7254             }
7255             if ( p.next() != null ) {
7256                 return false;
7257             }
7258             ////
7259             p.reset();
7260             if ( !p.hasNext() ) {
7261                 return false;
7262             }
7263             p2_0 = p.next();
7264             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7265                 System.out.println( p2_0.toNewHampshire() );
7266                 return false;
7267             }
7268             if ( !p.hasNext() ) {
7269                 return false;
7270             }
7271             p2_1 = p.next();
7272             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7273                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7274                 return false;
7275             }
7276             if ( !p.hasNext() ) {
7277                 return false;
7278             }
7279             p2_2 = p.next();
7280             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7281                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7282                 return false;
7283             }
7284             if ( !p.hasNext() ) {
7285                 return false;
7286             }
7287             p2_3 = p.next();
7288             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7289                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7290                 return false;
7291             }
7292             if ( !p.hasNext() ) {
7293                 return false;
7294             }
7295             p2_4 = p.next();
7296             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7297                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7298                 return false;
7299             }
7300             if ( p.hasNext() ) {
7301                 return false;
7302             }
7303             if ( p.next() != null ) {
7304                 return false;
7305             }
7306             //
7307             final String p3_str = "((A,B),C)abc";
7308             p.setSource( p3_str );
7309             if ( !p.hasNext() ) {
7310                 return false;
7311             }
7312             final Phylogeny p3_0 = p.next();
7313             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7314                 return false;
7315             }
7316             if ( p.hasNext() ) {
7317                 return false;
7318             }
7319             if ( p.next() != null ) {
7320                 return false;
7321             }
7322             //
7323             final String p4_str = "((A,B)ab,C)abc";
7324             p.setSource( p4_str );
7325             if ( !p.hasNext() ) {
7326                 return false;
7327             }
7328             final Phylogeny p4_0 = p.next();
7329             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7330                 return false;
7331             }
7332             if ( p.hasNext() ) {
7333                 return false;
7334             }
7335             if ( p.next() != null ) {
7336                 return false;
7337             }
7338             //
7339             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7340             p.setSource( p5_str );
7341             if ( !p.hasNext() ) {
7342                 return false;
7343             }
7344             final Phylogeny p5_0 = p.next();
7345             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7346                 return false;
7347             }
7348             if ( p.hasNext() ) {
7349                 return false;
7350             }
7351             if ( p.next() != null ) {
7352                 return false;
7353             }
7354             //
7355             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7356             p.setSource( p6_str );
7357             if ( !p.hasNext() ) {
7358                 return false;
7359             }
7360             Phylogeny p6_0 = p.next();
7361             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7362                 return false;
7363             }
7364             if ( p.hasNext() ) {
7365                 return false;
7366             }
7367             if ( p.next() != null ) {
7368                 return false;
7369             }
7370             p.reset();
7371             if ( !p.hasNext() ) {
7372                 return false;
7373             }
7374             p6_0 = p.next();
7375             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7376                 return false;
7377             }
7378             if ( p.hasNext() ) {
7379                 return false;
7380             }
7381             if ( p.next() != null ) {
7382                 return false;
7383             }
7384             //
7385             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7386             p.setSource( p7_str );
7387             if ( !p.hasNext() ) {
7388                 return false;
7389             }
7390             Phylogeny p7_0 = p.next();
7391             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7392                 return false;
7393             }
7394             if ( p.hasNext() ) {
7395                 return false;
7396             }
7397             if ( p.next() != null ) {
7398                 return false;
7399             }
7400             p.reset();
7401             if ( !p.hasNext() ) {
7402                 return false;
7403             }
7404             p7_0 = p.next();
7405             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7406                 return false;
7407             }
7408             if ( p.hasNext() ) {
7409                 return false;
7410             }
7411             if ( p.next() != null ) {
7412                 return false;
7413             }
7414             //
7415             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7416             p.setSource( p8_str );
7417             if ( !p.hasNext() ) {
7418                 return false;
7419             }
7420             Phylogeny p8_0 = p.next();
7421             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7422                 return false;
7423             }
7424             if ( !p.hasNext() ) {
7425                 return false;
7426             }
7427             if ( !p.hasNext() ) {
7428                 return false;
7429             }
7430             Phylogeny p8_1 = p.next();
7431             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7432                 return false;
7433             }
7434             if ( p.hasNext() ) {
7435                 return false;
7436             }
7437             if ( p.next() != null ) {
7438                 return false;
7439             }
7440             p.reset();
7441             if ( !p.hasNext() ) {
7442                 return false;
7443             }
7444             p8_0 = p.next();
7445             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7446                 return false;
7447             }
7448             if ( !p.hasNext() ) {
7449                 return false;
7450             }
7451             p8_1 = p.next();
7452             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7453                 return false;
7454             }
7455             if ( p.hasNext() ) {
7456                 return false;
7457             }
7458             if ( p.next() != null ) {
7459                 return false;
7460             }
7461             p.reset();
7462             //
7463             p.setSource( "" );
7464             if ( p.hasNext() ) {
7465                 return false;
7466             }
7467             //
7468             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
7469             if ( !p.hasNext() ) {
7470                 return false;
7471             }
7472             Phylogeny p_27 = p.next();
7473             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7474                 System.out.println( p_27.toNewHampshireX() );
7475                 System.exit( -1 );
7476                 return false;
7477             }
7478             if ( p.hasNext() ) {
7479                 return false;
7480             }
7481             if ( p.next() != null ) {
7482                 return false;
7483             }
7484             p.reset();
7485             if ( !p.hasNext() ) {
7486                 return false;
7487             }
7488             p_27 = p.next();
7489             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7490                 System.out.println( p_27.toNewHampshireX() );
7491                 System.exit( -1 );
7492                 return false;
7493             }
7494             if ( p.hasNext() ) {
7495                 return false;
7496             }
7497             if ( p.next() != null ) {
7498                 return false;
7499             }
7500         }
7501         catch ( final Exception e ) {
7502             e.printStackTrace( System.out );
7503             return false;
7504         }
7505         return true;
7506     }
7507
7508     private static boolean testNHXconversion() {
7509         try {
7510             final PhylogenyNode n1 = new PhylogenyNode();
7511             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7512             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7513             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7514             final PhylogenyNode n5 = PhylogenyNode
7515                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
7516             final PhylogenyNode n6 = PhylogenyNode
7517                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
7518             if ( !n1.toNewHampshireX().equals( "" ) ) {
7519                 return false;
7520             }
7521             if ( !n2.toNewHampshireX().equals( "" ) ) {
7522                 return false;
7523             }
7524             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
7525                 return false;
7526             }
7527             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
7528                 return false;
7529             }
7530             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
7531                 return false;
7532             }
7533             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
7534                 System.out.println( n6.toNewHampshireX() );
7535                 return false;
7536             }
7537         }
7538         catch ( final Exception e ) {
7539             e.printStackTrace( System.out );
7540             return false;
7541         }
7542         return true;
7543     }
7544
7545     private static boolean testNHXNodeParsing() {
7546         try {
7547             final PhylogenyNode n1 = new PhylogenyNode();
7548             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7549             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7550             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7551             final PhylogenyNode n5 = PhylogenyNode
7552                     .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]" );
7553             if ( !n3.getName().equals( "n3" ) ) {
7554                 return false;
7555             }
7556             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7557                 return false;
7558             }
7559             if ( n3.isDuplication() ) {
7560                 return false;
7561             }
7562             if ( n3.isHasAssignedEvent() ) {
7563                 return false;
7564             }
7565             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
7566                 return false;
7567             }
7568             if ( !n4.getName().equals( "n4" ) ) {
7569                 return false;
7570             }
7571             if ( n4.getDistanceToParent() != 0.01 ) {
7572                 return false;
7573             }
7574             if ( !n5.getName().equals( "n5" ) ) {
7575                 return false;
7576             }
7577             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
7578                 return false;
7579             }
7580             if ( n5.getDistanceToParent() != 0.1 ) {
7581                 return false;
7582             }
7583             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
7584                 return false;
7585             }
7586             if ( !n5.isDuplication() ) {
7587                 return false;
7588             }
7589             if ( !n5.isHasAssignedEvent() ) {
7590                 return false;
7591             }
7592             final PhylogenyNode n8 = PhylogenyNode
7593                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
7594                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7595             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7596                 return false;
7597             }
7598             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
7599                 return false;
7600             }
7601             final PhylogenyNode n9 = PhylogenyNode
7602                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
7603                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7604             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
7605                 return false;
7606             }
7607             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
7608                 return false;
7609             }
7610             final PhylogenyNode n10 = PhylogenyNode
7611                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7612             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
7613                 return false;
7614             }
7615             final PhylogenyNode n20 = PhylogenyNode
7616                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7617             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7618                 return false;
7619             }
7620             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
7621                 return false;
7622             }
7623             final PhylogenyNode n20x = PhylogenyNode
7624                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7625             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
7626                 return false;
7627             }
7628             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
7629                 return false;
7630             }
7631             final PhylogenyNode n20xx = PhylogenyNode
7632                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7633             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
7634                 return false;
7635             }
7636             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
7637                 return false;
7638             }
7639             final PhylogenyNode n20xxx = PhylogenyNode
7640                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7641             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
7642                 return false;
7643             }
7644             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
7645                 return false;
7646             }
7647             final PhylogenyNode n20xxxx = PhylogenyNode
7648                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7649             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
7650                 return false;
7651             }
7652             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
7653                 return false;
7654             }
7655             final PhylogenyNode n21 = PhylogenyNode
7656                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7657             if ( !n21.getName().equals( "N21_PIG" ) ) {
7658                 return false;
7659             }
7660             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
7661                 return false;
7662             }
7663             final PhylogenyNode n21x = PhylogenyNode
7664                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7665             if ( !n21x.getName().equals( "n21_PIG" ) ) {
7666                 return false;
7667             }
7668             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
7669                 return false;
7670             }
7671             final PhylogenyNode n22 = PhylogenyNode
7672                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7673             if ( !n22.getName().equals( "n22/PIG" ) ) {
7674                 return false;
7675             }
7676             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
7677                 return false;
7678             }
7679             final PhylogenyNode n23 = PhylogenyNode
7680                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7681             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
7682                 return false;
7683             }
7684             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
7685                 return false;
7686             }
7687             final PhylogenyNode a = PhylogenyNode
7688                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7689             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7690                 return false;
7691             }
7692             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
7693                 return false;
7694             }
7695             final PhylogenyNode c1 = PhylogenyNode
7696                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
7697                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7698             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
7699                 return false;
7700             }
7701             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
7702                 return false;
7703             }
7704             final PhylogenyNode c2 = PhylogenyNode
7705                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
7706                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7707             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
7708                 return false;
7709             }
7710             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
7711                 return false;
7712             }
7713             final PhylogenyNode e3 = PhylogenyNode
7714                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7715             if ( !e3.getName().equals( "n10_RAT~" ) ) {
7716                 return false;
7717             }
7718             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
7719                 return false;
7720             }
7721             final PhylogenyNode n11 = PhylogenyNode
7722                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
7723                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7724             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
7725                 return false;
7726             }
7727             if ( n11.getDistanceToParent() != 0.4 ) {
7728                 return false;
7729             }
7730             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
7731                 return false;
7732             }
7733             final PhylogenyNode n12 = PhylogenyNode
7734                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
7735                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7736             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
7737                 return false;
7738             }
7739             if ( n12.getDistanceToParent() != 0.4 ) {
7740                 return false;
7741             }
7742             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
7743                 return false;
7744             }
7745             final PhylogenyNode o = PhylogenyNode
7746                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7747             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
7748                 return false;
7749             }
7750             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
7751                 return false;
7752             }
7753             if ( n1.getName().compareTo( "" ) != 0 ) {
7754                 return false;
7755             }
7756             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7757                 return false;
7758             }
7759             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7760                 return false;
7761             }
7762             if ( n2.getName().compareTo( "" ) != 0 ) {
7763                 return false;
7764             }
7765             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7766                 return false;
7767             }
7768             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7769                 return false;
7770             }
7771             final PhylogenyNode n00 = PhylogenyNode
7772                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
7773             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
7774                 return false;
7775             }
7776             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
7777                 return false;
7778             }
7779             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
7780             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
7781                 return false;
7782             }
7783             final PhylogenyNode n13 = PhylogenyNode
7784                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7785             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
7786                 return false;
7787             }
7788             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
7789                 return false;
7790             }
7791             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7792                 return false;
7793             }
7794             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7795                 return false;
7796             }
7797             final PhylogenyNode n14 = PhylogenyNode
7798                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7799             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
7800                 return false;
7801             }
7802             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
7803                 return false;
7804             }
7805             final PhylogenyNode n15 = PhylogenyNode
7806                     .createInstanceFromNhxString( "something_wicked[123]",
7807                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7808             if ( !n15.getName().equals( "something_wicked" ) ) {
7809                 return false;
7810             }
7811             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
7812                 return false;
7813             }
7814             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
7815                 return false;
7816             }
7817             final PhylogenyNode n16 = PhylogenyNode
7818                     .createInstanceFromNhxString( "something_wicked2[9]",
7819                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7820             if ( !n16.getName().equals( "something_wicked2" ) ) {
7821                 return false;
7822             }
7823             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
7824                 return false;
7825             }
7826             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
7827                 return false;
7828             }
7829             final PhylogenyNode n17 = PhylogenyNode
7830                     .createInstanceFromNhxString( "something_wicked3[a]",
7831                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7832             if ( !n17.getName().equals( "something_wicked3" ) ) {
7833                 return false;
7834             }
7835             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
7836                 return false;
7837             }
7838             final PhylogenyNode n18 = PhylogenyNode
7839                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7840             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
7841                 return false;
7842             }
7843             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
7844                 return false;
7845             }
7846             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
7847                 return false;
7848             }
7849             final PhylogenyNode n19 = PhylogenyNode
7850                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7851             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
7852                 return false;
7853             }
7854             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7855                 return false;
7856             }
7857             final PhylogenyNode n30 = PhylogenyNode
7858                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
7859                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7860             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
7861                 return false;
7862             }
7863             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7864                 return false;
7865             }
7866             final PhylogenyNode n31 = PhylogenyNode
7867                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
7868                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7869             if ( n31.getNodeData().isHasTaxonomy() ) {
7870                 return false;
7871             }
7872             final PhylogenyNode n32 = PhylogenyNode
7873                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7874             if ( n32.getNodeData().isHasTaxonomy() ) {
7875                 return false;
7876             }
7877             final PhylogenyNode n40 = PhylogenyNode
7878                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7879             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7880                 return false;
7881             }
7882             final PhylogenyNode n41 = PhylogenyNode
7883                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7884             if ( n41.getNodeData().isHasTaxonomy() ) {
7885                 return false;
7886             }
7887             final PhylogenyNode n42 = PhylogenyNode
7888                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7889             if ( n42.getNodeData().isHasTaxonomy() ) {
7890                 return false;
7891             }
7892             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
7893                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
7894             if ( n43.getNodeData().isHasTaxonomy() ) {
7895                 return false;
7896             }
7897             final PhylogenyNode n44 = PhylogenyNode
7898                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7899             if ( n44.getNodeData().isHasTaxonomy() ) {
7900                 return false;
7901             }
7902         }
7903         catch ( final Exception e ) {
7904             e.printStackTrace( System.out );
7905             return false;
7906         }
7907         return true;
7908     }
7909
7910     private static boolean testNHXParsing() {
7911         try {
7912             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7913             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
7914             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
7915                 return false;
7916             }
7917             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]";
7918             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
7919             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7920                 return false;
7921             }
7922             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]";
7923             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
7924             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
7925                 return false;
7926             }
7927             final Phylogeny[] p3 = factory
7928                     .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]",
7929                              new NHXParser() );
7930             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7931                 return false;
7932             }
7933             final Phylogeny[] p4 = factory
7934                     .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(]",
7935                              new NHXParser() );
7936             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7937                 return false;
7938             }
7939             final Phylogeny[] p5 = factory
7940                     .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(((]",
7941                              new NHXParser() );
7942             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7943                 return false;
7944             }
7945             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)";
7946             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)";
7947             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
7948             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
7949                 return false;
7950             }
7951             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)))";
7952             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)))";
7953             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
7954             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
7955                 return false;
7956             }
7957             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])   ))[,,, ])))))))";
7958             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
7959             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
7960             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
7961                 return false;
7962             }
7963             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
7964             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
7965                 return false;
7966             }
7967             final Phylogeny p10 = factory
7968                     .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]",
7969                              new NHXParser() )[ 0 ];
7970             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
7971                 return false;
7972             }
7973         }
7974         catch ( final Exception e ) {
7975             e.printStackTrace( System.out );
7976             return false;
7977         }
7978         return true;
7979     }
7980
7981     private static boolean testNHXParsingMB() {
7982         try {
7983             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7984             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
7985                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7986                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
7987                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
7988                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
7989                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7990                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
7991                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
7992                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
7993             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
7994                 return false;
7995             }
7996             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
7997                 return false;
7998             }
7999             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8000                            0.1100000000000000e+00 ) ) {
8001                 return false;
8002             }
8003             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8004                 return false;
8005             }
8006             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8007                 return false;
8008             }
8009             final Phylogeny p2 = factory
8010                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8011                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8012                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8013                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8014                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8015                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8016                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8017                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8018                                      + "7.369400000000000e-02}])",
8019                              new NHXParser() )[ 0 ];
8020             if ( p2.getNode( "1" ) == null ) {
8021                 return false;
8022             }
8023             if ( p2.getNode( "2" ) == null ) {
8024                 return false;
8025             }
8026         }
8027         catch ( final Exception e ) {
8028             e.printStackTrace( System.out );
8029             System.exit( -1 );
8030             return false;
8031         }
8032         return true;
8033     }
8034
8035     private static boolean testNHXParsingQuotes() {
8036         try {
8037             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8038             final NHXParser p = new NHXParser();
8039             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8040             if ( phylogenies_0.length != 5 ) {
8041                 return false;
8042             }
8043             final Phylogeny phy = phylogenies_0[ 4 ];
8044             if ( phy.getNumberOfExternalNodes() != 7 ) {
8045                 return false;
8046             }
8047             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8048                 return false;
8049             }
8050             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8051                 return false;
8052             }
8053             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8054                     .getScientificName().equals( "hsapiens" ) ) {
8055                 return false;
8056             }
8057             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8058                 return false;
8059             }
8060             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8061                 return false;
8062             }
8063             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8064                 return false;
8065             }
8066             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8067                 return false;
8068             }
8069             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8070                 return false;
8071             }
8072             final NHXParser p1p = new NHXParser();
8073             p1p.setIgnoreQuotes( true );
8074             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8075             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8076                 return false;
8077             }
8078             final NHXParser p2p = new NHXParser();
8079             p1p.setIgnoreQuotes( false );
8080             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8081             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8082                 return false;
8083             }
8084             final NHXParser p3p = new NHXParser();
8085             p3p.setIgnoreQuotes( false );
8086             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8087             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8088                 return false;
8089             }
8090             final NHXParser p4p = new NHXParser();
8091             p4p.setIgnoreQuotes( false );
8092             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8093             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8094                 return false;
8095             }
8096             final Phylogeny p10 = factory
8097                     .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]",
8098                              new NHXParser() )[ 0 ];
8099             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]";
8100             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8101                 return false;
8102             }
8103             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8104             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8105                 return false;
8106             }
8107             //
8108             final Phylogeny p12 = factory
8109                     .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]",
8110                              new NHXParser() )[ 0 ];
8111             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]";
8112             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8113                 return false;
8114             }
8115             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8116             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8117                 return false;
8118             }
8119             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;";
8120             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8121                 return false;
8122             }
8123             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8124             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8125                 return false;
8126             }
8127         }
8128         catch ( final Exception e ) {
8129             e.printStackTrace( System.out );
8130             return false;
8131         }
8132         return true;
8133     }
8134
8135     private static boolean testNodeRemoval() {
8136         try {
8137             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8138             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8139             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8140             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8141                 return false;
8142             }
8143             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8144             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8145             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8146                 return false;
8147             }
8148             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8149             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8150             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8151                 return false;
8152             }
8153         }
8154         catch ( final Exception e ) {
8155             e.printStackTrace( System.out );
8156             return false;
8157         }
8158         return true;
8159     }
8160
8161     private static boolean testPhylogenyBranch() {
8162         try {
8163             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8164             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8165             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8166             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8167             if ( !a1b1.equals( a1b1 ) ) {
8168                 return false;
8169             }
8170             if ( !a1b1.equals( b1a1 ) ) {
8171                 return false;
8172             }
8173             if ( !b1a1.equals( a1b1 ) ) {
8174                 return false;
8175             }
8176             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8177             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8178             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8179             if ( a1_b1.equals( b1_a1 ) ) {
8180                 return false;
8181             }
8182             if ( a1_b1.equals( a1_b1_ ) ) {
8183                 return false;
8184             }
8185             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8186             if ( !a1_b1.equals( b1_a1_ ) ) {
8187                 return false;
8188             }
8189             if ( a1_b1_.equals( b1_a1_ ) ) {
8190                 return false;
8191             }
8192             if ( !a1_b1_.equals( b1_a1 ) ) {
8193                 return false;
8194             }
8195         }
8196         catch ( final Exception e ) {
8197             e.printStackTrace( System.out );
8198             return false;
8199         }
8200         return true;
8201     }
8202
8203     private static boolean testPhyloXMLparsingOfDistributionElement() {
8204         try {
8205             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8206             PhyloXmlParser xml_parser = null;
8207             try {
8208                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8209             }
8210             catch ( final Exception e ) {
8211                 // Do nothing -- means were not running from jar.
8212             }
8213             if ( xml_parser == null ) {
8214                 xml_parser = new PhyloXmlParser();
8215                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8216                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8217                 }
8218                 else {
8219                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8220                 }
8221             }
8222             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8223                                                               xml_parser );
8224             if ( xml_parser.getErrorCount() > 0 ) {
8225                 System.out.println( xml_parser.getErrorMessages().toString() );
8226                 return false;
8227             }
8228             if ( phylogenies_0.length != 1 ) {
8229                 return false;
8230             }
8231             final Phylogeny t1 = phylogenies_0[ 0 ];
8232             PhylogenyNode n = null;
8233             Distribution d = null;
8234             n = t1.getNode( "root node" );
8235             if ( !n.getNodeData().isHasDistribution() ) {
8236                 return false;
8237             }
8238             if ( n.getNodeData().getDistributions().size() != 1 ) {
8239                 return false;
8240             }
8241             d = n.getNodeData().getDistribution();
8242             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8243                 return false;
8244             }
8245             if ( d.getPoints().size() != 1 ) {
8246                 return false;
8247             }
8248             if ( d.getPolygons() != null ) {
8249                 return false;
8250             }
8251             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8252                 return false;
8253             }
8254             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8255                 return false;
8256             }
8257             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8258                 return false;
8259             }
8260             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8261                 return false;
8262             }
8263             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8264                 return false;
8265             }
8266             n = t1.getNode( "node a" );
8267             if ( !n.getNodeData().isHasDistribution() ) {
8268                 return false;
8269             }
8270             if ( n.getNodeData().getDistributions().size() != 2 ) {
8271                 return false;
8272             }
8273             d = n.getNodeData().getDistribution( 1 );
8274             if ( !d.getDesc().equals( "San Diego" ) ) {
8275                 return false;
8276             }
8277             if ( d.getPoints().size() != 1 ) {
8278                 return false;
8279             }
8280             if ( d.getPolygons() != null ) {
8281                 return false;
8282             }
8283             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8284                 return false;
8285             }
8286             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8287                 return false;
8288             }
8289             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8290                 return false;
8291             }
8292             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8293                 return false;
8294             }
8295             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8296                 return false;
8297             }
8298             n = t1.getNode( "node bb" );
8299             if ( !n.getNodeData().isHasDistribution() ) {
8300                 return false;
8301             }
8302             if ( n.getNodeData().getDistributions().size() != 1 ) {
8303                 return false;
8304             }
8305             d = n.getNodeData().getDistribution( 0 );
8306             if ( d.getPoints().size() != 3 ) {
8307                 return false;
8308             }
8309             if ( d.getPolygons().size() != 2 ) {
8310                 return false;
8311             }
8312             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8313                 return false;
8314             }
8315             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8316                 return false;
8317             }
8318             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8319                 return false;
8320             }
8321             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8322                 return false;
8323             }
8324             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8325                 return false;
8326             }
8327             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8328                 return false;
8329             }
8330             Polygon p = d.getPolygons().get( 0 );
8331             if ( p.getPoints().size() != 3 ) {
8332                 return false;
8333             }
8334             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8335                 return false;
8336             }
8337             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8338                 return false;
8339             }
8340             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8341                 return false;
8342             }
8343             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8344                 return false;
8345             }
8346             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8347                 return false;
8348             }
8349             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8350                 return false;
8351             }
8352             p = d.getPolygons().get( 1 );
8353             if ( p.getPoints().size() != 3 ) {
8354                 return false;
8355             }
8356             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8357                 return false;
8358             }
8359             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8360                 return false;
8361             }
8362             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8363                 return false;
8364             }
8365             // Roundtrip:
8366             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
8367             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
8368             if ( rt.length != 1 ) {
8369                 return false;
8370             }
8371             final Phylogeny t1_rt = rt[ 0 ];
8372             n = t1_rt.getNode( "root node" );
8373             if ( !n.getNodeData().isHasDistribution() ) {
8374                 return false;
8375             }
8376             if ( n.getNodeData().getDistributions().size() != 1 ) {
8377                 return false;
8378             }
8379             d = n.getNodeData().getDistribution();
8380             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8381                 return false;
8382             }
8383             if ( d.getPoints().size() != 1 ) {
8384                 return false;
8385             }
8386             if ( d.getPolygons() != null ) {
8387                 return false;
8388             }
8389             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8390                 return false;
8391             }
8392             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8393                 return false;
8394             }
8395             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8396                 return false;
8397             }
8398             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8399                 return false;
8400             }
8401             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8402                 return false;
8403             }
8404             n = t1_rt.getNode( "node a" );
8405             if ( !n.getNodeData().isHasDistribution() ) {
8406                 return false;
8407             }
8408             if ( n.getNodeData().getDistributions().size() != 2 ) {
8409                 return false;
8410             }
8411             d = n.getNodeData().getDistribution( 1 );
8412             if ( !d.getDesc().equals( "San Diego" ) ) {
8413                 return false;
8414             }
8415             if ( d.getPoints().size() != 1 ) {
8416                 return false;
8417             }
8418             if ( d.getPolygons() != null ) {
8419                 return false;
8420             }
8421             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8422                 return false;
8423             }
8424             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8425                 return false;
8426             }
8427             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8428                 return false;
8429             }
8430             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8431                 return false;
8432             }
8433             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8434                 return false;
8435             }
8436             n = t1_rt.getNode( "node bb" );
8437             if ( !n.getNodeData().isHasDistribution() ) {
8438                 return false;
8439             }
8440             if ( n.getNodeData().getDistributions().size() != 1 ) {
8441                 return false;
8442             }
8443             d = n.getNodeData().getDistribution( 0 );
8444             if ( d.getPoints().size() != 3 ) {
8445                 return false;
8446             }
8447             if ( d.getPolygons().size() != 2 ) {
8448                 return false;
8449             }
8450             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8451                 return false;
8452             }
8453             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8454                 return false;
8455             }
8456             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8457                 return false;
8458             }
8459             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8460                 return false;
8461             }
8462             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8463                 return false;
8464             }
8465             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8466                 return false;
8467             }
8468             p = d.getPolygons().get( 0 );
8469             if ( p.getPoints().size() != 3 ) {
8470                 return false;
8471             }
8472             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8473                 return false;
8474             }
8475             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8476                 return false;
8477             }
8478             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8479                 return false;
8480             }
8481             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8482                 return false;
8483             }
8484             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8485                 return false;
8486             }
8487             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8488                 return false;
8489             }
8490             p = d.getPolygons().get( 1 );
8491             if ( p.getPoints().size() != 3 ) {
8492                 return false;
8493             }
8494             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8495                 return false;
8496             }
8497             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8498                 return false;
8499             }
8500             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8501                 return false;
8502             }
8503         }
8504         catch ( final Exception e ) {
8505             e.printStackTrace( System.out );
8506             return false;
8507         }
8508         return true;
8509     }
8510
8511     private static boolean testPostOrderIterator() {
8512         try {
8513             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8514             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8515             PhylogenyNodeIterator it0;
8516             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
8517                 it0.next();
8518             }
8519             for( it0.reset(); it0.hasNext(); ) {
8520                 it0.next();
8521             }
8522             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8523             final PhylogenyNodeIterator it = t1.iteratorPostorder();
8524             if ( !it.next().getName().equals( "A" ) ) {
8525                 return false;
8526             }
8527             if ( !it.next().getName().equals( "B" ) ) {
8528                 return false;
8529             }
8530             if ( !it.next().getName().equals( "ab" ) ) {
8531                 return false;
8532             }
8533             if ( !it.next().getName().equals( "C" ) ) {
8534                 return false;
8535             }
8536             if ( !it.next().getName().equals( "D" ) ) {
8537                 return false;
8538             }
8539             if ( !it.next().getName().equals( "cd" ) ) {
8540                 return false;
8541             }
8542             if ( !it.next().getName().equals( "abcd" ) ) {
8543                 return false;
8544             }
8545             if ( !it.next().getName().equals( "E" ) ) {
8546                 return false;
8547             }
8548             if ( !it.next().getName().equals( "F" ) ) {
8549                 return false;
8550             }
8551             if ( !it.next().getName().equals( "ef" ) ) {
8552                 return false;
8553             }
8554             if ( !it.next().getName().equals( "G" ) ) {
8555                 return false;
8556             }
8557             if ( !it.next().getName().equals( "H" ) ) {
8558                 return false;
8559             }
8560             if ( !it.next().getName().equals( "gh" ) ) {
8561                 return false;
8562             }
8563             if ( !it.next().getName().equals( "efgh" ) ) {
8564                 return false;
8565             }
8566             if ( !it.next().getName().equals( "r" ) ) {
8567                 return false;
8568             }
8569             if ( it.hasNext() ) {
8570                 return false;
8571             }
8572         }
8573         catch ( final Exception e ) {
8574             e.printStackTrace( System.out );
8575             return false;
8576         }
8577         return true;
8578     }
8579
8580     private static boolean testPreOrderIterator() {
8581         try {
8582             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8583             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8584             PhylogenyNodeIterator it0;
8585             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
8586                 it0.next();
8587             }
8588             for( it0.reset(); it0.hasNext(); ) {
8589                 it0.next();
8590             }
8591             PhylogenyNodeIterator it = t0.iteratorPreorder();
8592             if ( !it.next().getName().equals( "r" ) ) {
8593                 return false;
8594             }
8595             if ( !it.next().getName().equals( "ab" ) ) {
8596                 return false;
8597             }
8598             if ( !it.next().getName().equals( "A" ) ) {
8599                 return false;
8600             }
8601             if ( !it.next().getName().equals( "B" ) ) {
8602                 return false;
8603             }
8604             if ( !it.next().getName().equals( "cd" ) ) {
8605                 return false;
8606             }
8607             if ( !it.next().getName().equals( "C" ) ) {
8608                 return false;
8609             }
8610             if ( !it.next().getName().equals( "D" ) ) {
8611                 return false;
8612             }
8613             if ( it.hasNext() ) {
8614                 return false;
8615             }
8616             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8617             it = t1.iteratorPreorder();
8618             if ( !it.next().getName().equals( "r" ) ) {
8619                 return false;
8620             }
8621             if ( !it.next().getName().equals( "abcd" ) ) {
8622                 return false;
8623             }
8624             if ( !it.next().getName().equals( "ab" ) ) {
8625                 return false;
8626             }
8627             if ( !it.next().getName().equals( "A" ) ) {
8628                 return false;
8629             }
8630             if ( !it.next().getName().equals( "B" ) ) {
8631                 return false;
8632             }
8633             if ( !it.next().getName().equals( "cd" ) ) {
8634                 return false;
8635             }
8636             if ( !it.next().getName().equals( "C" ) ) {
8637                 return false;
8638             }
8639             if ( !it.next().getName().equals( "D" ) ) {
8640                 return false;
8641             }
8642             if ( !it.next().getName().equals( "efgh" ) ) {
8643                 return false;
8644             }
8645             if ( !it.next().getName().equals( "ef" ) ) {
8646                 return false;
8647             }
8648             if ( !it.next().getName().equals( "E" ) ) {
8649                 return false;
8650             }
8651             if ( !it.next().getName().equals( "F" ) ) {
8652                 return false;
8653             }
8654             if ( !it.next().getName().equals( "gh" ) ) {
8655                 return false;
8656             }
8657             if ( !it.next().getName().equals( "G" ) ) {
8658                 return false;
8659             }
8660             if ( !it.next().getName().equals( "H" ) ) {
8661                 return false;
8662             }
8663             if ( it.hasNext() ) {
8664                 return false;
8665             }
8666         }
8667         catch ( final Exception e ) {
8668             e.printStackTrace( System.out );
8669             return false;
8670         }
8671         return true;
8672     }
8673
8674     private static boolean testPropertiesMap() {
8675         try {
8676             final PropertiesMap pm = new PropertiesMap();
8677             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8678             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8679             final Property p2 = new Property( "something:else",
8680                                               "?",
8681                                               "improbable:research",
8682                                               "xsd:decimal",
8683                                               AppliesTo.NODE );
8684             pm.addProperty( p0 );
8685             pm.addProperty( p1 );
8686             pm.addProperty( p2 );
8687             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
8688                 return false;
8689             }
8690             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
8691                 return false;
8692             }
8693             if ( pm.getProperties().size() != 3 ) {
8694                 return false;
8695             }
8696             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
8697                 return false;
8698             }
8699             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8700                 return false;
8701             }
8702             if ( pm.getProperties().size() != 3 ) {
8703                 return false;
8704             }
8705             pm.removeProperty( "dimensions:diameter" );
8706             if ( pm.getProperties().size() != 2 ) {
8707                 return false;
8708             }
8709             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
8710                 return false;
8711             }
8712             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8713                 return false;
8714             }
8715         }
8716         catch ( final Exception e ) {
8717             e.printStackTrace( System.out );
8718             return false;
8719         }
8720         return true;
8721     }
8722
8723     private static boolean testProteinId() {
8724         try {
8725             final ProteinId id1 = new ProteinId( "a" );
8726             final ProteinId id2 = new ProteinId( "a" );
8727             final ProteinId id3 = new ProteinId( "A" );
8728             final ProteinId id4 = new ProteinId( "b" );
8729             if ( !id1.equals( id1 ) ) {
8730                 return false;
8731             }
8732             if ( id1.getId().equals( "x" ) ) {
8733                 return false;
8734             }
8735             if ( id1.getId().equals( null ) ) {
8736                 return false;
8737             }
8738             if ( !id1.equals( id2 ) ) {
8739                 return false;
8740             }
8741             if ( id1.equals( id3 ) ) {
8742                 return false;
8743             }
8744             if ( id1.hashCode() != id1.hashCode() ) {
8745                 return false;
8746             }
8747             if ( id1.hashCode() != id2.hashCode() ) {
8748                 return false;
8749             }
8750             if ( id1.hashCode() == id3.hashCode() ) {
8751                 return false;
8752             }
8753             if ( id1.compareTo( id1 ) != 0 ) {
8754                 return false;
8755             }
8756             if ( id1.compareTo( id2 ) != 0 ) {
8757                 return false;
8758             }
8759             if ( id1.compareTo( id3 ) != 0 ) {
8760                 return false;
8761             }
8762             if ( id1.compareTo( id4 ) >= 0 ) {
8763                 return false;
8764             }
8765             if ( id4.compareTo( id1 ) <= 0 ) {
8766                 return false;
8767             }
8768             if ( !id4.getId().equals( "b" ) ) {
8769                 return false;
8770             }
8771             final ProteinId id5 = new ProteinId( " C " );
8772             if ( !id5.getId().equals( "C" ) ) {
8773                 return false;
8774             }
8775             if ( id5.equals( id1 ) ) {
8776                 return false;
8777             }
8778         }
8779         catch ( final Exception e ) {
8780             e.printStackTrace( System.out );
8781             return false;
8782         }
8783         return true;
8784     }
8785
8786     private static boolean testReIdMethods() {
8787         try {
8788             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8789             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
8790             final long count = PhylogenyNode.getNodeCount();
8791             p.levelOrderReID();
8792             if ( p.getNode( "r" ).getId() != count ) {
8793                 return false;
8794             }
8795             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
8796                 return false;
8797             }
8798             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
8799                 return false;
8800             }
8801             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
8802                 return false;
8803             }
8804             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
8805                 return false;
8806             }
8807             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
8808                 return false;
8809             }
8810             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
8811                 return false;
8812             }
8813             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
8814                 return false;
8815             }
8816             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
8817                 return false;
8818             }
8819             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
8820                 return false;
8821             }
8822             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
8823                 return false;
8824             }
8825             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
8826                 return false;
8827             }
8828             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
8829                 return false;
8830             }
8831             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
8832                 return false;
8833             }
8834             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
8835                 return false;
8836             }
8837         }
8838         catch ( final Exception e ) {
8839             e.printStackTrace( System.out );
8840             return false;
8841         }
8842         return true;
8843     }
8844
8845     private static boolean testRerooting() {
8846         try {
8847             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8848             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",
8849                                                  new NHXParser() )[ 0 ];
8850             if ( !t1.isRooted() ) {
8851                 return false;
8852             }
8853             t1.reRoot( t1.getNode( "D" ) );
8854             t1.reRoot( t1.getNode( "CD" ) );
8855             t1.reRoot( t1.getNode( "A" ) );
8856             t1.reRoot( t1.getNode( "B" ) );
8857             t1.reRoot( t1.getNode( "AB" ) );
8858             t1.reRoot( t1.getNode( "D" ) );
8859             t1.reRoot( t1.getNode( "C" ) );
8860             t1.reRoot( t1.getNode( "CD" ) );
8861             t1.reRoot( t1.getNode( "A" ) );
8862             t1.reRoot( t1.getNode( "B" ) );
8863             t1.reRoot( t1.getNode( "AB" ) );
8864             t1.reRoot( t1.getNode( "D" ) );
8865             t1.reRoot( t1.getNode( "D" ) );
8866             t1.reRoot( t1.getNode( "C" ) );
8867             t1.reRoot( t1.getNode( "A" ) );
8868             t1.reRoot( t1.getNode( "B" ) );
8869             t1.reRoot( t1.getNode( "AB" ) );
8870             t1.reRoot( t1.getNode( "C" ) );
8871             t1.reRoot( t1.getNode( "D" ) );
8872             t1.reRoot( t1.getNode( "CD" ) );
8873             t1.reRoot( t1.getNode( "D" ) );
8874             t1.reRoot( t1.getNode( "A" ) );
8875             t1.reRoot( t1.getNode( "B" ) );
8876             t1.reRoot( t1.getNode( "AB" ) );
8877             t1.reRoot( t1.getNode( "C" ) );
8878             t1.reRoot( t1.getNode( "D" ) );
8879             t1.reRoot( t1.getNode( "CD" ) );
8880             t1.reRoot( t1.getNode( "D" ) );
8881             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
8882                 return false;
8883             }
8884             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
8885                 return false;
8886             }
8887             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
8888                 return false;
8889             }
8890             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
8891                 return false;
8892             }
8893             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
8894                 return false;
8895             }
8896             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
8897                 return false;
8898             }
8899             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",
8900                                                  new NHXParser() )[ 0 ];
8901             t2.reRoot( t2.getNode( "A" ) );
8902             t2.reRoot( t2.getNode( "D" ) );
8903             t2.reRoot( t2.getNode( "ABC" ) );
8904             t2.reRoot( t2.getNode( "A" ) );
8905             t2.reRoot( t2.getNode( "B" ) );
8906             t2.reRoot( t2.getNode( "D" ) );
8907             t2.reRoot( t2.getNode( "C" ) );
8908             t2.reRoot( t2.getNode( "ABC" ) );
8909             t2.reRoot( t2.getNode( "A" ) );
8910             t2.reRoot( t2.getNode( "B" ) );
8911             t2.reRoot( t2.getNode( "AB" ) );
8912             t2.reRoot( t2.getNode( "AB" ) );
8913             t2.reRoot( t2.getNode( "D" ) );
8914             t2.reRoot( t2.getNode( "C" ) );
8915             t2.reRoot( t2.getNode( "B" ) );
8916             t2.reRoot( t2.getNode( "AB" ) );
8917             t2.reRoot( t2.getNode( "D" ) );
8918             t2.reRoot( t2.getNode( "D" ) );
8919             t2.reRoot( t2.getNode( "ABC" ) );
8920             t2.reRoot( t2.getNode( "A" ) );
8921             t2.reRoot( t2.getNode( "B" ) );
8922             t2.reRoot( t2.getNode( "AB" ) );
8923             t2.reRoot( t2.getNode( "D" ) );
8924             t2.reRoot( t2.getNode( "C" ) );
8925             t2.reRoot( t2.getNode( "ABC" ) );
8926             t2.reRoot( t2.getNode( "A" ) );
8927             t2.reRoot( t2.getNode( "B" ) );
8928             t2.reRoot( t2.getNode( "AB" ) );
8929             t2.reRoot( t2.getNode( "D" ) );
8930             t2.reRoot( t2.getNode( "D" ) );
8931             t2.reRoot( t2.getNode( "C" ) );
8932             t2.reRoot( t2.getNode( "A" ) );
8933             t2.reRoot( t2.getNode( "B" ) );
8934             t2.reRoot( t2.getNode( "AB" ) );
8935             t2.reRoot( t2.getNode( "C" ) );
8936             t2.reRoot( t2.getNode( "D" ) );
8937             t2.reRoot( t2.getNode( "ABC" ) );
8938             t2.reRoot( t2.getNode( "D" ) );
8939             t2.reRoot( t2.getNode( "A" ) );
8940             t2.reRoot( t2.getNode( "B" ) );
8941             t2.reRoot( t2.getNode( "AB" ) );
8942             t2.reRoot( t2.getNode( "C" ) );
8943             t2.reRoot( t2.getNode( "D" ) );
8944             t2.reRoot( t2.getNode( "ABC" ) );
8945             t2.reRoot( t2.getNode( "D" ) );
8946             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8947                 return false;
8948             }
8949             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8950                 return false;
8951             }
8952             t2.reRoot( t2.getNode( "ABC" ) );
8953             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8954                 return false;
8955             }
8956             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8957                 return false;
8958             }
8959             t2.reRoot( t2.getNode( "AB" ) );
8960             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8961                 return false;
8962             }
8963             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8964                 return false;
8965             }
8966             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8967                 return false;
8968             }
8969             t2.reRoot( t2.getNode( "AB" ) );
8970             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8971                 return false;
8972             }
8973             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8974                 return false;
8975             }
8976             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8977                 return false;
8978             }
8979             t2.reRoot( t2.getNode( "D" ) );
8980             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8981                 return false;
8982             }
8983             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8984                 return false;
8985             }
8986             t2.reRoot( t2.getNode( "ABC" ) );
8987             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8988                 return false;
8989             }
8990             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8991                 return false;
8992             }
8993             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
8994                                                  new NHXParser() )[ 0 ];
8995             t3.reRoot( t3.getNode( "B" ) );
8996             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8997                 return false;
8998             }
8999             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9000                 return false;
9001             }
9002             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9003                 return false;
9004             }
9005             t3.reRoot( t3.getNode( "B" ) );
9006             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9007                 return false;
9008             }
9009             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9010                 return false;
9011             }
9012             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9013                 return false;
9014             }
9015             t3.reRoot( t3.getRoot() );
9016             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9017                 return false;
9018             }
9019             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9020                 return false;
9021             }
9022             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9023                 return false;
9024             }
9025         }
9026         catch ( final Exception e ) {
9027             e.printStackTrace( System.out );
9028             return false;
9029         }
9030         return true;
9031     }
9032
9033     private static boolean testSDIse() {
9034         try {
9035             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9036             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9037             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9038             gene1.setRooted( true );
9039             species1.setRooted( true );
9040             final SDI sdi = new SDI( gene1, species1 );
9041             if ( !gene1.getRoot().isDuplication() ) {
9042                 return false;
9043             }
9044             final Phylogeny species2 = factory
9045                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9046                              new NHXParser() )[ 0 ];
9047             final Phylogeny gene2 = factory
9048                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9049                              new NHXParser() )[ 0 ];
9050             species2.setRooted( true );
9051             gene2.setRooted( true );
9052             final SDI sdi2 = new SDI( gene2, species2 );
9053             if ( sdi2.getDuplicationsSum() != 0 ) {
9054                 return false;
9055             }
9056             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9057                 return false;
9058             }
9059             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9060                 return false;
9061             }
9062             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9063                 return false;
9064             }
9065             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9066                 return false;
9067             }
9068             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9069                 return false;
9070             }
9071             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9072                 return false;
9073             }
9074             final Phylogeny species3 = factory
9075                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9076                              new NHXParser() )[ 0 ];
9077             final Phylogeny gene3 = factory
9078                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9079                              new NHXParser() )[ 0 ];
9080             species3.setRooted( true );
9081             gene3.setRooted( true );
9082             final SDI sdi3 = new SDI( gene3, species3 );
9083             if ( sdi3.getDuplicationsSum() != 1 ) {
9084                 return false;
9085             }
9086             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9087                 return false;
9088             }
9089             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9090                 return false;
9091             }
9092             final Phylogeny species4 = factory
9093                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9094                              new NHXParser() )[ 0 ];
9095             final Phylogeny gene4 = factory
9096                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9097                              new NHXParser() )[ 0 ];
9098             species4.setRooted( true );
9099             gene4.setRooted( true );
9100             final SDI sdi4 = new SDI( gene4, species4 );
9101             if ( sdi4.getDuplicationsSum() != 1 ) {
9102                 return false;
9103             }
9104             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9105                 return false;
9106             }
9107             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9108                 return false;
9109             }
9110             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9111                 return false;
9112             }
9113             if ( species4.getNumberOfExternalNodes() != 6 ) {
9114                 return false;
9115             }
9116             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9117                 return false;
9118             }
9119             final Phylogeny species5 = factory
9120                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9121                              new NHXParser() )[ 0 ];
9122             final Phylogeny gene5 = factory
9123                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9124                              new NHXParser() )[ 0 ];
9125             species5.setRooted( true );
9126             gene5.setRooted( true );
9127             final SDI sdi5 = new SDI( gene5, species5 );
9128             if ( sdi5.getDuplicationsSum() != 2 ) {
9129                 return false;
9130             }
9131             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9132                 return false;
9133             }
9134             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9135                 return false;
9136             }
9137             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9138                 return false;
9139             }
9140             if ( species5.getNumberOfExternalNodes() != 6 ) {
9141                 return false;
9142             }
9143             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9144                 return false;
9145             }
9146             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9147             // Conjecture for Comparing Molecular Phylogenies"
9148             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9149             final Phylogeny species6 = factory
9150                     .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,"
9151                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9152                              new NHXParser() )[ 0 ];
9153             final Phylogeny gene6 = factory
9154                     .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,"
9155                                      + "((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,"
9156                                      + "(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;",
9157                              new NHXParser() )[ 0 ];
9158             species6.setRooted( true );
9159             gene6.setRooted( true );
9160             final SDI sdi6 = new SDI( gene6, species6 );
9161             if ( sdi6.getDuplicationsSum() != 3 ) {
9162                 return false;
9163             }
9164             if ( !gene6.getNode( "r" ).isDuplication() ) {
9165                 return false;
9166             }
9167             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9168                 return false;
9169             }
9170             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9171                 return false;
9172             }
9173             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9174                 return false;
9175             }
9176             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9177                 return false;
9178             }
9179             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9180                 return false;
9181             }
9182             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9183                 return false;
9184             }
9185             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9186                 return false;
9187             }
9188             sdi6.computeMappingCostL();
9189             if ( sdi6.computeMappingCostL() != 17 ) {
9190                 return false;
9191             }
9192             if ( species6.getNumberOfExternalNodes() != 9 ) {
9193                 return false;
9194             }
9195             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9196                 return false;
9197             }
9198             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9199                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9200                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9201                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9202                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9203             species7.setRooted( true );
9204             final Phylogeny gene7_1 = Test
9205                     .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])" );
9206             gene7_1.setRooted( true );
9207             final SDI sdi7 = new SDI( gene7_1, species7 );
9208             if ( sdi7.getDuplicationsSum() != 0 ) {
9209                 return false;
9210             }
9211             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9212                 return false;
9213             }
9214             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9215                 return false;
9216             }
9217             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9218                 return false;
9219             }
9220             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9221                 return false;
9222             }
9223             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9224                 return false;
9225             }
9226             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9227                 return false;
9228             }
9229             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9230                 return false;
9231             }
9232             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9233                 return false;
9234             }
9235             final Phylogeny gene7_2 = Test
9236                     .createPhylogeny( "(((((((((a1[&&NHX:S=a1],a2[&&NHX:S=a2]),b1[&&NHX:S=b1]),x[&&NHX:S=x]),m1[&&NHX:S=m1]),i1[&&NHX:S=i1]),j2[&&NHX:S=j2]),e1[&&NHX:S=e1]),y[&&NHX:S=y]),z[&&NHX:S=z])" );
9237             gene7_2.setRooted( true );
9238             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9239             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9240                 return false;
9241             }
9242             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9243                 return false;
9244             }
9245             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9246                 return false;
9247             }
9248             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9249                 return false;
9250             }
9251             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9252                 return false;
9253             }
9254             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9255                 return false;
9256             }
9257             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9258                 return false;
9259             }
9260             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9261                 return false;
9262             }
9263             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9264                 return false;
9265             }
9266             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9267                 return false;
9268             }
9269         }
9270         catch ( final Exception e ) {
9271             return false;
9272         }
9273         return true;
9274     }
9275
9276     private static boolean testSDIunrooted() {
9277         try {
9278             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9279             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9280             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9281             final Iterator<PhylogenyBranch> iter = l.iterator();
9282             PhylogenyBranch br = iter.next();
9283             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9284                 return false;
9285             }
9286             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9287                 return false;
9288             }
9289             br = iter.next();
9290             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9291                 return false;
9292             }
9293             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9294                 return false;
9295             }
9296             br = iter.next();
9297             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9298                 return false;
9299             }
9300             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9301                 return false;
9302             }
9303             br = iter.next();
9304             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9305                 return false;
9306             }
9307             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9308                 return false;
9309             }
9310             br = iter.next();
9311             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9312                 return false;
9313             }
9314             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9315                 return false;
9316             }
9317             br = iter.next();
9318             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9319                 return false;
9320             }
9321             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9322                 return false;
9323             }
9324             br = iter.next();
9325             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9326                 return false;
9327             }
9328             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9329                 return false;
9330             }
9331             br = iter.next();
9332             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9333                 return false;
9334             }
9335             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9336                 return false;
9337             }
9338             br = iter.next();
9339             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9340                 return false;
9341             }
9342             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9343                 return false;
9344             }
9345             br = iter.next();
9346             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9347                 return false;
9348             }
9349             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9350                 return false;
9351             }
9352             br = iter.next();
9353             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9354                 return false;
9355             }
9356             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9357                 return false;
9358             }
9359             br = iter.next();
9360             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
9361                 return false;
9362             }
9363             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
9364                 return false;
9365             }
9366             br = iter.next();
9367             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9368                 return false;
9369             }
9370             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9371                 return false;
9372             }
9373             br = iter.next();
9374             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
9375                 return false;
9376             }
9377             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
9378                 return false;
9379             }
9380             br = iter.next();
9381             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
9382                 return false;
9383             }
9384             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
9385                 return false;
9386             }
9387             if ( iter.hasNext() ) {
9388                 return false;
9389             }
9390             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
9391             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
9392             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
9393             br = iter1.next();
9394             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9395                 return false;
9396             }
9397             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9398                 return false;
9399             }
9400             br = iter1.next();
9401             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9402                 return false;
9403             }
9404             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9405                 return false;
9406             }
9407             br = iter1.next();
9408             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9409                 return false;
9410             }
9411             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9412                 return false;
9413             }
9414             if ( iter1.hasNext() ) {
9415                 return false;
9416             }
9417             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
9418             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
9419             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
9420             br = iter2.next();
9421             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9422                 return false;
9423             }
9424             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9425                 return false;
9426             }
9427             br = iter2.next();
9428             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9429                 return false;
9430             }
9431             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9432                 return false;
9433             }
9434             br = iter2.next();
9435             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9436                 return false;
9437             }
9438             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9439                 return false;
9440             }
9441             if ( iter2.hasNext() ) {
9442                 return false;
9443             }
9444             final Phylogeny species0 = factory
9445                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9446                              new NHXParser() )[ 0 ];
9447             final Phylogeny gene1 = factory
9448                     .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])",
9449                              new NHXParser() )[ 0 ];
9450             species0.setRooted( true );
9451             gene1.setRooted( true );
9452             final SDIR sdi_unrooted = new SDIR();
9453             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
9454             if ( sdi_unrooted.getCount() != 1 ) {
9455                 return false;
9456             }
9457             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
9458                 return false;
9459             }
9460             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
9461                 return false;
9462             }
9463             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
9464                 return false;
9465             }
9466             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9467                 return false;
9468             }
9469             final Phylogeny gene2 = factory
9470                     .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])",
9471                              new NHXParser() )[ 0 ];
9472             gene2.setRooted( true );
9473             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
9474             if ( sdi_unrooted.getCount() != 1 ) {
9475                 return false;
9476             }
9477             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9478                 return false;
9479             }
9480             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9481                 return false;
9482             }
9483             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
9484                 return false;
9485             }
9486             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9487                 return false;
9488             }
9489             final Phylogeny species6 = factory
9490                     .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,"
9491                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9492                              new NHXParser() )[ 0 ];
9493             final Phylogeny gene6 = factory
9494                     .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],"
9495                                      + "(((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],"
9496                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9497                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9498                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9499                              new NHXParser() )[ 0 ];
9500             species6.setRooted( true );
9501             gene6.setRooted( true );
9502             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
9503             if ( sdi_unrooted.getCount() != 1 ) {
9504                 return false;
9505             }
9506             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9507                 return false;
9508             }
9509             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9510                 return false;
9511             }
9512             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9513                 return false;
9514             }
9515             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9516                 return false;
9517             }
9518             if ( !p6[ 0 ].getRoot().isDuplication() ) {
9519                 return false;
9520             }
9521             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9522                 return false;
9523             }
9524             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9525                 return false;
9526             }
9527             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
9528                 return false;
9529             }
9530             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9531                 return false;
9532             }
9533             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
9534                 return false;
9535             }
9536             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
9537                 return false;
9538             }
9539             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9540                 return false;
9541             }
9542             p6 = null;
9543             final Phylogeny species7 = factory
9544                     .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,"
9545                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9546                              new NHXParser() )[ 0 ];
9547             final Phylogeny gene7 = factory
9548                     .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],"
9549                                      + "(((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],"
9550                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9551                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9552                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9553                              new NHXParser() )[ 0 ];
9554             species7.setRooted( true );
9555             gene7.setRooted( true );
9556             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
9557             if ( sdi_unrooted.getCount() != 1 ) {
9558                 return false;
9559             }
9560             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9561                 return false;
9562             }
9563             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9564                 return false;
9565             }
9566             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9567                 return false;
9568             }
9569             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
9570                 return false;
9571             }
9572             if ( !p7[ 0 ].getRoot().isDuplication() ) {
9573                 return false;
9574             }
9575             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9576                 return false;
9577             }
9578             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9579                 return false;
9580             }
9581             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
9582                 return false;
9583             }
9584             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9585                 return false;
9586             }
9587             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
9588                 return false;
9589             }
9590             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
9591                 return false;
9592             }
9593             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9594                 return false;
9595             }
9596             p7 = null;
9597             final Phylogeny species8 = factory
9598                     .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,"
9599                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9600                              new NHXParser() )[ 0 ];
9601             final Phylogeny gene8 = factory
9602                     .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],"
9603                                      + "(((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],"
9604                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9605                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9606                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9607                              new NHXParser() )[ 0 ];
9608             species8.setRooted( true );
9609             gene8.setRooted( true );
9610             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
9611             if ( sdi_unrooted.getCount() != 1 ) {
9612                 return false;
9613             }
9614             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9615                 return false;
9616             }
9617             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9618                 return false;
9619             }
9620             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9621                 return false;
9622             }
9623             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9624                 return false;
9625             }
9626             if ( !p8[ 0 ].getRoot().isDuplication() ) {
9627                 return false;
9628             }
9629             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9630                 return false;
9631             }
9632             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9633                 return false;
9634             }
9635             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
9636                 return false;
9637             }
9638             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9639                 return false;
9640             }
9641             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
9642                 return false;
9643             }
9644             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
9645                 return false;
9646             }
9647             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9648                 return false;
9649             }
9650             p8 = null;
9651         }
9652         catch ( final Exception e ) {
9653             e.printStackTrace( System.out );
9654             return false;
9655         }
9656         return true;
9657     }
9658
9659     private static boolean testSequenceIdParsing() {
9660         try {
9661             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
9662             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9663                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
9664                 if ( id != null ) {
9665                     System.out.println( "value   =" + id.getValue() );
9666                     System.out.println( "provider=" + id.getSource() );
9667                 }
9668                 return false;
9669             }
9670             //
9671             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
9672             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9673                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
9674                 if ( id != null ) {
9675                     System.out.println( "value   =" + id.getValue() );
9676                     System.out.println( "provider=" + id.getSource() );
9677                 }
9678                 return false;
9679             }
9680             //
9681             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
9682             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9683                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
9684                 if ( id != null ) {
9685                     System.out.println( "value   =" + id.getValue() );
9686                     System.out.println( "provider=" + id.getSource() );
9687                 }
9688                 return false;
9689             }
9690             // 
9691             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
9692             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9693                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
9694                 if ( id != null ) {
9695                     System.out.println( "value   =" + id.getValue() );
9696                     System.out.println( "provider=" + id.getSource() );
9697                 }
9698                 return false;
9699             }
9700             // 
9701             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
9702             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9703                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
9704                 if ( id != null ) {
9705                     System.out.println( "value   =" + id.getValue() );
9706                     System.out.println( "provider=" + id.getSource() );
9707                 }
9708                 return false;
9709             }
9710             // 
9711             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
9712             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9713                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
9714                 if ( id != null ) {
9715                     System.out.println( "value   =" + id.getValue() );
9716                     System.out.println( "provider=" + id.getSource() );
9717                 }
9718                 return false;
9719             }
9720             // 
9721             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
9722             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9723                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
9724                 if ( id != null ) {
9725                     System.out.println( "value   =" + id.getValue() );
9726                     System.out.println( "provider=" + id.getSource() );
9727                 }
9728                 return false;
9729             }
9730             // 
9731             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
9732             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9733                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
9734                 if ( id != null ) {
9735                     System.out.println( "value   =" + id.getValue() );
9736                     System.out.println( "provider=" + id.getSource() );
9737                 }
9738                 return false;
9739             }
9740             // 
9741             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
9742             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9743                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
9744                 if ( id != null ) {
9745                     System.out.println( "value   =" + id.getValue() );
9746                     System.out.println( "provider=" + id.getSource() );
9747                 }
9748                 return false;
9749             }
9750             // 
9751             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
9752             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
9753                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
9754                 if ( id != null ) {
9755                     System.out.println( "value   =" + id.getValue() );
9756                     System.out.println( "provider=" + id.getSource() );
9757                 }
9758                 return false;
9759             }
9760             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
9761             if ( id != null ) {
9762                 System.out.println( "value   =" + id.getValue() );
9763                 System.out.println( "provider=" + id.getSource() );
9764                 return false;
9765             }
9766         }
9767         catch ( final Exception e ) {
9768             e.printStackTrace( System.out );
9769             return false;
9770         }
9771         return true;
9772     }
9773
9774     private static boolean testSequenceWriter() {
9775         try {
9776             final String n = ForesterUtil.LINE_SEPARATOR;
9777             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9778                 return false;
9779             }
9780             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9781                 return false;
9782             }
9783             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9784                 return false;
9785             }
9786             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9787                 return false;
9788             }
9789             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9790                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9791                 return false;
9792             }
9793             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9794                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9795                 return false;
9796             }
9797         }
9798         catch ( final Exception e ) {
9799             e.printStackTrace();
9800             return false;
9801         }
9802         return true;
9803     }
9804
9805     private static boolean testSpecies() {
9806         try {
9807             final Species s1 = new BasicSpecies( "a" );
9808             final Species s2 = new BasicSpecies( "a" );
9809             final Species s3 = new BasicSpecies( "A" );
9810             final Species s4 = new BasicSpecies( "b" );
9811             if ( !s1.equals( s1 ) ) {
9812                 return false;
9813             }
9814             if ( s1.getSpeciesId().equals( "x" ) ) {
9815                 return false;
9816             }
9817             if ( s1.getSpeciesId().equals( null ) ) {
9818                 return false;
9819             }
9820             if ( !s1.equals( s2 ) ) {
9821                 return false;
9822             }
9823             if ( s1.equals( s3 ) ) {
9824                 return false;
9825             }
9826             if ( s1.hashCode() != s1.hashCode() ) {
9827                 return false;
9828             }
9829             if ( s1.hashCode() != s2.hashCode() ) {
9830                 return false;
9831             }
9832             if ( s1.hashCode() == s3.hashCode() ) {
9833                 return false;
9834             }
9835             if ( s1.compareTo( s1 ) != 0 ) {
9836                 return false;
9837             }
9838             if ( s1.compareTo( s2 ) != 0 ) {
9839                 return false;
9840             }
9841             if ( s1.compareTo( s3 ) != 0 ) {
9842                 return false;
9843             }
9844             if ( s1.compareTo( s4 ) >= 0 ) {
9845                 return false;
9846             }
9847             if ( s4.compareTo( s1 ) <= 0 ) {
9848                 return false;
9849             }
9850             if ( !s4.getSpeciesId().equals( "b" ) ) {
9851                 return false;
9852             }
9853             final Species s5 = new BasicSpecies( " C " );
9854             if ( !s5.getSpeciesId().equals( "C" ) ) {
9855                 return false;
9856             }
9857             if ( s5.equals( s1 ) ) {
9858                 return false;
9859             }
9860         }
9861         catch ( final Exception e ) {
9862             e.printStackTrace( System.out );
9863             return false;
9864         }
9865         return true;
9866     }
9867
9868     private static boolean testSplit() {
9869         try {
9870             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9871             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
9872             //Archaeopteryx.createApplication( p0 );
9873             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
9874             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9875             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9876             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9877             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9878             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9879             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9880             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9881             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
9882             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
9883             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
9884             // System.out.println( s0.toString() );
9885             //
9886             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
9887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9889             if ( s0.match( query_nodes ) ) {
9890                 return false;
9891             }
9892             query_nodes = new HashSet<PhylogenyNode>();
9893             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9900             if ( !s0.match( query_nodes ) ) {
9901                 return false;
9902             }
9903             //
9904             query_nodes = new HashSet<PhylogenyNode>();
9905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9908             if ( !s0.match( query_nodes ) ) {
9909                 return false;
9910             }
9911             //
9912             query_nodes = new HashSet<PhylogenyNode>();
9913             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9917             if ( !s0.match( query_nodes ) ) {
9918                 return false;
9919             }
9920             //
9921             query_nodes = new HashSet<PhylogenyNode>();
9922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9926             if ( !s0.match( query_nodes ) ) {
9927                 return false;
9928             }
9929             //
9930             query_nodes = new HashSet<PhylogenyNode>();
9931             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9932             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9933             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9934             if ( !s0.match( query_nodes ) ) {
9935                 return false;
9936             }
9937             //
9938             query_nodes = new HashSet<PhylogenyNode>();
9939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9940             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9941             if ( !s0.match( query_nodes ) ) {
9942                 return false;
9943             }
9944             //
9945             query_nodes = new HashSet<PhylogenyNode>();
9946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9947             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9949             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9950             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9951             if ( !s0.match( query_nodes ) ) {
9952                 return false;
9953             }
9954             //
9955             query_nodes = new HashSet<PhylogenyNode>();
9956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9958             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9959             if ( !s0.match( query_nodes ) ) {
9960                 return false;
9961             }
9962             //
9963             query_nodes = new HashSet<PhylogenyNode>();
9964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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( "A" ) );
9975             if ( s0.match( query_nodes ) ) {
9976                 return false;
9977             }
9978             //
9979             query_nodes = new HashSet<PhylogenyNode>();
9980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9983             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9984             if ( s0.match( query_nodes ) ) {
9985                 return false;
9986             }
9987             //
9988             query_nodes = new HashSet<PhylogenyNode>();
9989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9992             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9994             if ( s0.match( query_nodes ) ) {
9995                 return false;
9996             }
9997             //
9998             query_nodes = new HashSet<PhylogenyNode>();
9999             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10002             if ( s0.match( query_nodes ) ) {
10003                 return false;
10004             }
10005             //
10006             query_nodes = new HashSet<PhylogenyNode>();
10007             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10009             if ( s0.match( query_nodes ) ) {
10010                 return false;
10011             }
10012             //
10013             query_nodes = new HashSet<PhylogenyNode>();
10014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10016             if ( s0.match( query_nodes ) ) {
10017                 return false;
10018             }
10019             //
10020             query_nodes = new HashSet<PhylogenyNode>();
10021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10023             if ( s0.match( query_nodes ) ) {
10024                 return false;
10025             }
10026             //
10027             query_nodes = new HashSet<PhylogenyNode>();
10028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10030             if ( s0.match( query_nodes ) ) {
10031                 return false;
10032             }
10033             //
10034             query_nodes = new HashSet<PhylogenyNode>();
10035             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10036             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10037             if ( s0.match( query_nodes ) ) {
10038                 return false;
10039             }
10040             //
10041             query_nodes = new HashSet<PhylogenyNode>();
10042             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10043             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10044             if ( s0.match( query_nodes ) ) {
10045                 return false;
10046             }
10047             //
10048             query_nodes = new HashSet<PhylogenyNode>();
10049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10050             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10051             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10052             if ( s0.match( query_nodes ) ) {
10053                 return false;
10054             }
10055             //
10056             query_nodes = new HashSet<PhylogenyNode>();
10057             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10058             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10059             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10060             if ( s0.match( query_nodes ) ) {
10061                 return false;
10062             }
10063             //
10064             query_nodes = new HashSet<PhylogenyNode>();
10065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10066             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10067             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10068             if ( s0.match( query_nodes ) ) {
10069                 return false;
10070             }
10071             //
10072             query_nodes = new HashSet<PhylogenyNode>();
10073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10074             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10075             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10076             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10077             if ( s0.match( query_nodes ) ) {
10078                 return false;
10079             }
10080             /////////
10081             //            query_nodes = new HashSet<PhylogenyNode>();
10082             //            query_nodes.add( new PhylogenyNode( "X" ) );
10083             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10084             //            query_nodes.add( new PhylogenyNode( "A" ) );
10085             //            query_nodes.add( new PhylogenyNode( "B" ) );
10086             //            query_nodes.add( new PhylogenyNode( "C" ) );
10087             //            query_nodes.add( new PhylogenyNode( "D" ) );
10088             //            query_nodes.add( new PhylogenyNode( "E" ) );
10089             //            query_nodes.add( new PhylogenyNode( "F" ) );
10090             //            query_nodes.add( new PhylogenyNode( "G" ) );
10091             //            if ( !s0.match( query_nodes ) ) {
10092             //                return false;
10093             //            }
10094             //            query_nodes = new HashSet<PhylogenyNode>();
10095             //            query_nodes.add( new PhylogenyNode( "X" ) );
10096             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10097             //            query_nodes.add( new PhylogenyNode( "A" ) );
10098             //            query_nodes.add( new PhylogenyNode( "B" ) );
10099             //            query_nodes.add( new PhylogenyNode( "C" ) );
10100             //            if ( !s0.match( query_nodes ) ) {
10101             //                return false;
10102             //            }
10103             //            //
10104             //            query_nodes = new HashSet<PhylogenyNode>();
10105             //            query_nodes.add( new PhylogenyNode( "X" ) );
10106             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10107             //            query_nodes.add( new PhylogenyNode( "D" ) );
10108             //            query_nodes.add( new PhylogenyNode( "E" ) );
10109             //            query_nodes.add( new PhylogenyNode( "F" ) );
10110             //            query_nodes.add( new PhylogenyNode( "G" ) );
10111             //            if ( !s0.match( query_nodes ) ) {
10112             //                return false;
10113             //            }
10114             //            //
10115             //            query_nodes = new HashSet<PhylogenyNode>();
10116             //            query_nodes.add( new PhylogenyNode( "X" ) );
10117             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10118             //            query_nodes.add( new PhylogenyNode( "A" ) );
10119             //            query_nodes.add( new PhylogenyNode( "B" ) );
10120             //            query_nodes.add( new PhylogenyNode( "C" ) );
10121             //            query_nodes.add( new PhylogenyNode( "D" ) );
10122             //            if ( !s0.match( query_nodes ) ) {
10123             //                return false;
10124             //            }
10125             //            //
10126             //            query_nodes = new HashSet<PhylogenyNode>();
10127             //            query_nodes.add( new PhylogenyNode( "X" ) );
10128             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10129             //            query_nodes.add( new PhylogenyNode( "E" ) );
10130             //            query_nodes.add( new PhylogenyNode( "F" ) );
10131             //            query_nodes.add( new PhylogenyNode( "G" ) );
10132             //            if ( !s0.match( query_nodes ) ) {
10133             //                return false;
10134             //            }
10135             //            //
10136             //            query_nodes = new HashSet<PhylogenyNode>();
10137             //            query_nodes.add( new PhylogenyNode( "X" ) );
10138             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10139             //            query_nodes.add( new PhylogenyNode( "F" ) );
10140             //            query_nodes.add( new PhylogenyNode( "G" ) );
10141             //            if ( !s0.match( query_nodes ) ) {
10142             //                return false;
10143             //            }
10144             //
10145             query_nodes = new HashSet<PhylogenyNode>();
10146             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10147             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10148             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10149             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10150             if ( s0.match( query_nodes ) ) {
10151                 return false;
10152             }
10153             //
10154             query_nodes = new HashSet<PhylogenyNode>();
10155             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10156             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10159             if ( s0.match( query_nodes ) ) {
10160                 return false;
10161             }
10162             ///////////////////////////
10163             //
10164             query_nodes = new HashSet<PhylogenyNode>();
10165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10167             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10168             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10169             if ( s0.match( query_nodes ) ) {
10170                 return false;
10171             }
10172             //
10173             query_nodes = new HashSet<PhylogenyNode>();
10174             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10175             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10176             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10177             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10178             if ( s0.match( query_nodes ) ) {
10179                 return false;
10180             }
10181             //
10182             query_nodes = new HashSet<PhylogenyNode>();
10183             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10184             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10185             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10186             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10187             if ( s0.match( query_nodes ) ) {
10188                 return false;
10189             }
10190             //
10191             query_nodes = new HashSet<PhylogenyNode>();
10192             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10193             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10194             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10195             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10196             if ( s0.match( query_nodes ) ) {
10197                 return false;
10198             }
10199             //
10200             query_nodes = new HashSet<PhylogenyNode>();
10201             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10202             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10203             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10204             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10205             if ( s0.match( query_nodes ) ) {
10206                 return false;
10207             }
10208             //
10209             query_nodes = new HashSet<PhylogenyNode>();
10210             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10211             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10212             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10213             if ( s0.match( query_nodes ) ) {
10214                 return false;
10215             }
10216             //
10217             query_nodes = new HashSet<PhylogenyNode>();
10218             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10219             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10220             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10221             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10222             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10223             if ( s0.match( query_nodes ) ) {
10224                 return false;
10225             }
10226             //
10227             query_nodes = new HashSet<PhylogenyNode>();
10228             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10229             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10230             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10232             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10233             if ( s0.match( query_nodes ) ) {
10234                 return false;
10235             }
10236             //
10237             query_nodes = new HashSet<PhylogenyNode>();
10238             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10239             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10240             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10241             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10242             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10243             if ( s0.match( query_nodes ) ) {
10244                 return false;
10245             }
10246             //
10247             query_nodes = new HashSet<PhylogenyNode>();
10248             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10249             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10250             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10251             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10252             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10254             if ( s0.match( query_nodes ) ) {
10255                 return false;
10256             }
10257         }
10258         catch ( final Exception e ) {
10259             e.printStackTrace();
10260             return false;
10261         }
10262         return true;
10263     }
10264
10265     private static boolean testSplitStrict() {
10266         try {
10267             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10268             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10269             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10270             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10271             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10272             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10273             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10274             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10275             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10276             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10277             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
10278             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10279             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10280             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10281             if ( s0.match( query_nodes ) ) {
10282                 return false;
10283             }
10284             query_nodes = new HashSet<PhylogenyNode>();
10285             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10286             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10287             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10288             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10289             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10292             if ( !s0.match( query_nodes ) ) {
10293                 return false;
10294             }
10295             //
10296             query_nodes = new HashSet<PhylogenyNode>();
10297             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10298             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10299             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10300             if ( !s0.match( query_nodes ) ) {
10301                 return false;
10302             }
10303             //
10304             query_nodes = new HashSet<PhylogenyNode>();
10305             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10306             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10307             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10308             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10309             if ( !s0.match( query_nodes ) ) {
10310                 return false;
10311             }
10312             //
10313             query_nodes = new HashSet<PhylogenyNode>();
10314             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10315             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10316             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10317             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10318             if ( !s0.match( query_nodes ) ) {
10319                 return false;
10320             }
10321             //
10322             query_nodes = new HashSet<PhylogenyNode>();
10323             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10324             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10325             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10326             if ( !s0.match( query_nodes ) ) {
10327                 return false;
10328             }
10329             //
10330             query_nodes = new HashSet<PhylogenyNode>();
10331             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10332             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10333             if ( !s0.match( query_nodes ) ) {
10334                 return false;
10335             }
10336             //
10337             query_nodes = new HashSet<PhylogenyNode>();
10338             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10339             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10340             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10341             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10342             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10343             if ( !s0.match( query_nodes ) ) {
10344                 return false;
10345             }
10346             //
10347             query_nodes = new HashSet<PhylogenyNode>();
10348             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10349             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10350             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10351             if ( !s0.match( query_nodes ) ) {
10352                 return false;
10353             }
10354             //
10355             query_nodes = new HashSet<PhylogenyNode>();
10356             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10357             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10358             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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( "A" ) );
10367             if ( s0.match( query_nodes ) ) {
10368                 return false;
10369             }
10370             //
10371             query_nodes = new HashSet<PhylogenyNode>();
10372             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10373             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10374             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10375             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10376             if ( s0.match( query_nodes ) ) {
10377                 return false;
10378             }
10379             //
10380             query_nodes = new HashSet<PhylogenyNode>();
10381             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10382             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10383             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10384             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10385             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10386             if ( s0.match( query_nodes ) ) {
10387                 return false;
10388             }
10389             //
10390             query_nodes = new HashSet<PhylogenyNode>();
10391             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10392             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10393             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10394             if ( s0.match( query_nodes ) ) {
10395                 return false;
10396             }
10397             //
10398             query_nodes = new HashSet<PhylogenyNode>();
10399             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10401             if ( s0.match( query_nodes ) ) {
10402                 return false;
10403             }
10404             //
10405             query_nodes = new HashSet<PhylogenyNode>();
10406             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10407             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10408             if ( s0.match( query_nodes ) ) {
10409                 return false;
10410             }
10411             //
10412             query_nodes = new HashSet<PhylogenyNode>();
10413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10415             if ( s0.match( query_nodes ) ) {
10416                 return false;
10417             }
10418             //
10419             query_nodes = new HashSet<PhylogenyNode>();
10420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10422             if ( s0.match( query_nodes ) ) {
10423                 return false;
10424             }
10425             //
10426             query_nodes = new HashSet<PhylogenyNode>();
10427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10429             if ( s0.match( query_nodes ) ) {
10430                 return false;
10431             }
10432             //
10433             query_nodes = new HashSet<PhylogenyNode>();
10434             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10436             if ( s0.match( query_nodes ) ) {
10437                 return false;
10438             }
10439             //
10440             query_nodes = new HashSet<PhylogenyNode>();
10441             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10442             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10443             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10444             if ( s0.match( query_nodes ) ) {
10445                 return false;
10446             }
10447             //
10448             query_nodes = new HashSet<PhylogenyNode>();
10449             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10450             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10451             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10452             if ( s0.match( query_nodes ) ) {
10453                 return false;
10454             }
10455             //
10456             query_nodes = new HashSet<PhylogenyNode>();
10457             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10458             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10459             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10460             if ( s0.match( query_nodes ) ) {
10461                 return false;
10462             }
10463             //
10464             query_nodes = new HashSet<PhylogenyNode>();
10465             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10466             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10467             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10468             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10469             if ( s0.match( query_nodes ) ) {
10470                 return false;
10471             }
10472         }
10473         catch ( final Exception e ) {
10474             e.printStackTrace();
10475             return false;
10476         }
10477         return true;
10478     }
10479
10480     private static boolean testSubtreeDeletion() {
10481         try {
10482             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10483             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10484             t1.deleteSubtree( t1.getNode( "A" ), false );
10485             if ( t1.getNumberOfExternalNodes() != 5 ) {
10486                 return false;
10487             }
10488             t1.toNewHampshireX();
10489             t1.deleteSubtree( t1.getNode( "E" ), false );
10490             if ( t1.getNumberOfExternalNodes() != 4 ) {
10491                 return false;
10492             }
10493             t1.toNewHampshireX();
10494             t1.deleteSubtree( t1.getNode( "F" ), false );
10495             if ( t1.getNumberOfExternalNodes() != 3 ) {
10496                 return false;
10497             }
10498             t1.toNewHampshireX();
10499             t1.deleteSubtree( t1.getNode( "D" ), false );
10500             t1.toNewHampshireX();
10501             if ( t1.getNumberOfExternalNodes() != 3 ) {
10502                 return false;
10503             }
10504             t1.deleteSubtree( t1.getNode( "def" ), false );
10505             t1.toNewHampshireX();
10506             if ( t1.getNumberOfExternalNodes() != 2 ) {
10507                 return false;
10508             }
10509             t1.deleteSubtree( t1.getNode( "B" ), false );
10510             t1.toNewHampshireX();
10511             if ( t1.getNumberOfExternalNodes() != 1 ) {
10512                 return false;
10513             }
10514             t1.deleteSubtree( t1.getNode( "C" ), false );
10515             t1.toNewHampshireX();
10516             if ( t1.getNumberOfExternalNodes() != 1 ) {
10517                 return false;
10518             }
10519             t1.deleteSubtree( t1.getNode( "abc" ), false );
10520             t1.toNewHampshireX();
10521             if ( t1.getNumberOfExternalNodes() != 1 ) {
10522                 return false;
10523             }
10524             t1.deleteSubtree( t1.getNode( "r" ), false );
10525             if ( t1.getNumberOfExternalNodes() != 0 ) {
10526                 return false;
10527             }
10528             if ( !t1.isEmpty() ) {
10529                 return false;
10530             }
10531             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10532             t2.deleteSubtree( t2.getNode( "A" ), false );
10533             t2.toNewHampshireX();
10534             if ( t2.getNumberOfExternalNodes() != 5 ) {
10535                 return false;
10536             }
10537             t2.deleteSubtree( t2.getNode( "abc" ), false );
10538             t2.toNewHampshireX();
10539             if ( t2.getNumberOfExternalNodes() != 3 ) {
10540                 return false;
10541             }
10542             t2.deleteSubtree( t2.getNode( "def" ), false );
10543             t2.toNewHampshireX();
10544             if ( t2.getNumberOfExternalNodes() != 1 ) {
10545                 return false;
10546             }
10547         }
10548         catch ( final Exception e ) {
10549             e.printStackTrace( System.out );
10550             return false;
10551         }
10552         return true;
10553     }
10554
10555     private static boolean testSupportCount() {
10556         try {
10557             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10558             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
10559             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
10560                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
10561                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
10562                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
10563                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
10564                                                               new NHXParser() );
10565             SupportCount.count( t0_1, phylogenies_1, true, false );
10566             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
10567             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
10568                                                                       + "(((((A,B),C),D),E),((F,G),X))"
10569                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
10570                                                                       + "(((((A,B),C),D),E),(F,G))"
10571                                                                       + "(((((A,B),C),D),E),(F,G))"
10572                                                                       + "(((((A,B),C),D),E),(F,G))"
10573                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
10574                                                                       + "(((((A,B),C),D),E),(F,G))"
10575                                                                       + "((((((A,B),C),D),E),F),G)"
10576                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
10577                                                               new NHXParser() );
10578             SupportCount.count( t0_2, phylogenies_2, true, false );
10579             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
10580             while ( it.hasNext() ) {
10581                 final PhylogenyNode n = it.next();
10582                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
10583                     return false;
10584                 }
10585             }
10586             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
10587             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
10588                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
10589             SupportCount.count( t0_3, phylogenies_3, true, false );
10590             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
10591             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
10592                 return false;
10593             }
10594             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
10595                 return false;
10596             }
10597             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
10598                 return false;
10599             }
10600             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
10601                 return false;
10602             }
10603             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
10604                 return false;
10605             }
10606             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
10607                 return false;
10608             }
10609             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
10610                 return false;
10611             }
10612             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
10613                 return false;
10614             }
10615             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
10616                 return false;
10617             }
10618             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
10619                 return false;
10620             }
10621             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10622             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
10623                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
10624             SupportCount.count( t0_4, phylogenies_4, true, false );
10625             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
10626             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
10627                 return false;
10628             }
10629             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
10630                 return false;
10631             }
10632             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
10633                 return false;
10634             }
10635             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
10636                 return false;
10637             }
10638             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
10639                 return false;
10640             }
10641             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
10642                 return false;
10643             }
10644             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
10645                 return false;
10646             }
10647             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
10648                 return false;
10649             }
10650             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
10651                 return false;
10652             }
10653             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
10654                 return false;
10655             }
10656             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10657             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10658             double d = SupportCount.compare( b1, a, true, true, true );
10659             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
10660                 return false;
10661             }
10662             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10663             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10664             d = SupportCount.compare( b2, a, true, true, true );
10665             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
10666                 return false;
10667             }
10668             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10669             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
10670             d = SupportCount.compare( b3, a, true, true, true );
10671             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
10672                 return false;
10673             }
10674             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
10675             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
10676             d = SupportCount.compare( b4, a, true, true, false );
10677             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
10678                 return false;
10679             }
10680         }
10681         catch ( final Exception e ) {
10682             e.printStackTrace( System.out );
10683             return false;
10684         }
10685         return true;
10686     }
10687
10688     private static boolean testSupportTransfer() {
10689         try {
10690             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10691             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)",
10692                                                  new NHXParser() )[ 0 ];
10693             final Phylogeny p2 = factory
10694                     .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 ];
10695             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
10696                 return false;
10697             }
10698             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
10699                 return false;
10700             }
10701             support_transfer.moveBranchLengthsToBootstrap( p1 );
10702             support_transfer.transferSupportValues( p1, p2 );
10703             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
10704                 return false;
10705             }
10706             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
10707                 return false;
10708             }
10709             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
10710                 return false;
10711             }
10712             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
10713                 return false;
10714             }
10715             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
10716                 return false;
10717             }
10718             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
10719                 return false;
10720             }
10721             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
10722                 return false;
10723             }
10724             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
10725                 return false;
10726             }
10727         }
10728         catch ( final Exception e ) {
10729             e.printStackTrace( System.out );
10730             return false;
10731         }
10732         return true;
10733     }
10734
10735     private static boolean testTaxonomyExtraction() {
10736         try {
10737             final PhylogenyNode n0 = PhylogenyNode
10738                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10739             if ( n0.getNodeData().isHasTaxonomy() ) {
10740                 return false;
10741             }
10742             final PhylogenyNode n1 = PhylogenyNode
10743                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10744             if ( n1.getNodeData().isHasTaxonomy() ) {
10745                 System.out.println( n1.toString() );
10746                 return false;
10747             }
10748             final PhylogenyNode n2x = PhylogenyNode
10749                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10750             if ( n2x.getNodeData().isHasTaxonomy() ) {
10751                 return false;
10752             }
10753             final PhylogenyNode n3 = PhylogenyNode
10754                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10755             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10756                 System.out.println( n3.toString() );
10757                 return false;
10758             }
10759             final PhylogenyNode n4 = PhylogenyNode
10760                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10761             if ( n4.getNodeData().isHasTaxonomy() ) {
10762                 System.out.println( n4.toString() );
10763                 return false;
10764             }
10765             final PhylogenyNode n5 = PhylogenyNode
10766                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10767             if ( n5.getNodeData().isHasTaxonomy() ) {
10768                 System.out.println( n5.toString() );
10769                 return false;
10770             }
10771             final PhylogenyNode n6 = PhylogenyNode
10772                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10773             if ( n6.getNodeData().isHasTaxonomy() ) {
10774                 System.out.println( n6.toString() );
10775                 return false;
10776             }
10777             final PhylogenyNode n7 = PhylogenyNode
10778                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10779             if ( n7.getNodeData().isHasTaxonomy() ) {
10780                 System.out.println( n7.toString() );
10781                 return false;
10782             }
10783             final PhylogenyNode n8 = PhylogenyNode
10784                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10785             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10786                 System.out.println( n8.toString() );
10787                 return false;
10788             }
10789             final PhylogenyNode n9 = PhylogenyNode
10790                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10791             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10792                 System.out.println( n9.toString() );
10793                 return false;
10794             }
10795             final PhylogenyNode n10x = PhylogenyNode
10796                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10797             if ( n10x.getNodeData().isHasTaxonomy() ) {
10798                 System.out.println( n10x.toString() );
10799                 return false;
10800             }
10801             final PhylogenyNode n10xx = PhylogenyNode
10802                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10803             if ( n10xx.getNodeData().isHasTaxonomy() ) {
10804                 System.out.println( n10xx.toString() );
10805                 return false;
10806             }
10807             final PhylogenyNode n10 = PhylogenyNode
10808                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10809             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
10810                 System.out.println( n10.toString() );
10811                 return false;
10812             }
10813             final PhylogenyNode n11 = PhylogenyNode
10814                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10815             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
10816                 System.out.println( n11.toString() );
10817                 return false;
10818             }
10819             final PhylogenyNode n12 = PhylogenyNode
10820                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
10821                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10822             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
10823                 System.out.println( n12.toString() );
10824                 return false;
10825             }
10826             final PhylogenyNode n13 = PhylogenyNode
10827                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10828             if ( n13.getNodeData().isHasTaxonomy() ) {
10829                 System.out.println( n13.toString() );
10830                 return false;
10831             }
10832         }
10833         catch ( final Exception e ) {
10834             e.printStackTrace( System.out );
10835             return false;
10836         }
10837         return true;
10838     }
10839
10840     private static boolean testTreeMethods() {
10841         try {
10842             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10843             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
10844             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
10845             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
10846                 System.out.println( t0.toNewHampshireX() );
10847                 return false;
10848             }
10849             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
10850             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
10851             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
10852                 return false;
10853             }
10854             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
10855                 return false;
10856             }
10857             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
10858                 return false;
10859             }
10860         }
10861         catch ( final Exception e ) {
10862             e.printStackTrace( System.out );
10863             return false;
10864         }
10865         return true;
10866     }
10867
10868     private static boolean testSequenceDbWsTools1() {
10869         try {
10870             final PhylogenyNode n = new PhylogenyNode();
10871             n.setName( "NP_001025424" );
10872             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10873             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10874                     || !acc.getValue().equals( "NP_001025424" ) ) {
10875                 return false;
10876             }
10877             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10878             acc = SequenceDbWsTools.obtainSeqAccession( n );
10879             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10880                     || !acc.getValue().equals( "NP_001025424" ) ) {
10881                 return false;
10882             }
10883             n.setName( "NP_001025424.1" );
10884             acc = SequenceDbWsTools.obtainSeqAccession( n );
10885             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10886                     || !acc.getValue().equals( "NP_001025424" ) ) {
10887                 return false;
10888             }
10889             n.setName( "NM_001030253" );
10890             acc = SequenceDbWsTools.obtainSeqAccession( n );
10891             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10892                     || !acc.getValue().equals( "NM_001030253" ) ) {
10893                 return false;
10894             }
10895             n.setName( "BCL2_HUMAN" );
10896             acc = SequenceDbWsTools.obtainSeqAccession( n );
10897             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10898                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10899                 System.out.println( acc.toString() );
10900                 return false;
10901             }
10902             n.setName( "P10415" );
10903             acc = SequenceDbWsTools.obtainSeqAccession( n );
10904             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10905                     || !acc.getValue().equals( "P10415" ) ) {
10906                 System.out.println( acc.toString() );
10907                 return false;
10908             }
10909             n.setName( " P10415 " );
10910             acc = SequenceDbWsTools.obtainSeqAccession( n );
10911             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10912                     || !acc.getValue().equals( "P10415" ) ) {
10913                 System.out.println( acc.toString() );
10914                 return false;
10915             }
10916             n.setName( "_P10415|" );
10917             acc = SequenceDbWsTools.obtainSeqAccession( n );
10918             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10919                     || !acc.getValue().equals( "P10415" ) ) {
10920                 System.out.println( acc.toString() );
10921                 return false;
10922             }
10923             n.setName( "AY695820" );
10924             acc = SequenceDbWsTools.obtainSeqAccession( n );
10925             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10926                     || !acc.getValue().equals( "AY695820" ) ) {
10927                 System.out.println( acc.toString() );
10928                 return false;
10929             }
10930             n.setName( "_AY695820_" );
10931             acc = SequenceDbWsTools.obtainSeqAccession( n );
10932             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10933                     || !acc.getValue().equals( "AY695820" ) ) {
10934                 System.out.println( acc.toString() );
10935                 return false;
10936             }
10937             n.setName( "AAA59452" );
10938             acc = SequenceDbWsTools.obtainSeqAccession( n );
10939             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10940                     || !acc.getValue().equals( "AAA59452" ) ) {
10941                 System.out.println( acc.toString() );
10942                 return false;
10943             }
10944             n.setName( "_AAA59452_" );
10945             acc = SequenceDbWsTools.obtainSeqAccession( n );
10946             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10947                     || !acc.getValue().equals( "AAA59452" ) ) {
10948                 System.out.println( acc.toString() );
10949                 return false;
10950             }
10951             n.setName( "AAA59452.1" );
10952             acc = SequenceDbWsTools.obtainSeqAccession( n );
10953             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10954                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10955                 System.out.println( acc.toString() );
10956                 return false;
10957             }
10958             n.setName( "_AAA59452.1_" );
10959             acc = SequenceDbWsTools.obtainSeqAccession( n );
10960             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10961                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10962                 System.out.println( acc.toString() );
10963                 return false;
10964             }
10965             n.setName( "GI:94894583" );
10966             acc = SequenceDbWsTools.obtainSeqAccession( n );
10967             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10968                     || !acc.getValue().equals( "94894583" ) ) {
10969                 System.out.println( acc.toString() );
10970                 return false;
10971             }
10972         }
10973         catch ( final Exception e ) {
10974             return false;
10975         }
10976         return true;
10977     }
10978
10979     private static boolean testSequenceDbWsTools2() {
10980         try {
10981             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
10982             SequenceDbWsTools.obtainSeqInformation( n1 );
10983             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10984                 return false;
10985             }
10986             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10987                 return false;
10988             }
10989             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10990                 return false;
10991             }
10992             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
10993                 return false;
10994             }
10995             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
10996             SequenceDbWsTools.obtainSeqInformation( n2 );
10997             System.out.println( n2.toString() );
10998             if ( !n2.getNodeData().getSequence().getName()
10999                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
11000                 return false;
11001             }
11002             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11003                 return false;
11004             }
11005             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11006                 return false;
11007             }
11008             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11009                 return false;
11010             }
11011             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11012             SequenceDbWsTools.obtainSeqInformation( n3 );
11013             System.out.println( "n=" + n3.toString() );
11014             if ( !n3.getNodeData().getSequence().getName()
11015                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11016                 return false;
11017             }
11018             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11019                 return false;
11020             }
11021             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11022                 return false;
11023             }
11024             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11025                 return false;
11026             }
11027         }
11028         catch ( final IOException e ) {
11029             System.out.println();
11030             System.out.println( "the following might be due to absence internet connection:" );
11031             e.printStackTrace( System.out );
11032             return true;
11033         }
11034         catch ( final Exception e ) {
11035             e.printStackTrace();
11036             return false;
11037         }
11038         return true;
11039     }
11040
11041     private static boolean testUniprotEntryRetrieval() {
11042         try {
11043             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
11044             if ( !entry.getAccession().equals( "P12345" ) ) {
11045                 return false;
11046             }
11047             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
11048                 return false;
11049             }
11050             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
11051                 return false;
11052             }
11053             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
11054                 return false;
11055             }
11056             if ( !entry.getGeneName().equals( "GOT2" ) ) {
11057                 return false;
11058             }
11059             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
11060                 return false;
11061             }
11062         }
11063         catch ( final IOException e ) {
11064             System.out.println();
11065             System.out.println( "the following might be due to absence internet connection:" );
11066             e.printStackTrace( System.out );
11067             return true;
11068         }
11069         catch ( final Exception e ) {
11070             return false;
11071         }
11072         return true;
11073     }
11074
11075     private static boolean testUniprotTaxonomySearch() {
11076         try {
11077             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
11078                                                                                                  10 );
11079             if ( results.size() != 1 ) {
11080                 return false;
11081             }
11082             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11083                 return false;
11084             }
11085             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11086                 return false;
11087             }
11088             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11089                 return false;
11090             }
11091             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11092                 return false;
11093             }
11094             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11095                 return false;
11096             }
11097             results = null;
11098             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
11099             if ( results.size() != 1 ) {
11100                 return false;
11101             }
11102             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11103                 return false;
11104             }
11105             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11106                 return false;
11107             }
11108             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11109                 return false;
11110             }
11111             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11112                 return false;
11113             }
11114             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11115                 return false;
11116             }
11117             results = null;
11118             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
11119             if ( results.size() != 1 ) {
11120                 return false;
11121             }
11122             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11123                 return false;
11124             }
11125             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11126                 return false;
11127             }
11128             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11129                 return false;
11130             }
11131             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11132                 return false;
11133             }
11134             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11135                 return false;
11136             }
11137             results = null;
11138             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
11139             if ( results.size() != 1 ) {
11140                 return false;
11141             }
11142             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11143                 return false;
11144             }
11145             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11146                 return false;
11147             }
11148             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11149                 return false;
11150             }
11151             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11152                 return false;
11153             }
11154             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11155                 return false;
11156             }
11157             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
11158                 return false;
11159             }
11160             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
11161                 return false;
11162             }
11163             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11164                     .equals( "Nematostella vectensis" ) ) {
11165                 System.out.println( results.get( 0 ).getLineage() );
11166                 return false;
11167             }
11168             //
11169             results = null;
11170             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
11171             if ( results.size() != 1 ) {
11172                 return false;
11173             }
11174             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11175                 return false;
11176             }
11177             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11178                 return false;
11179             }
11180             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11181                 return false;
11182             }
11183             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11184                 return false;
11185             }
11186             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11187                 return false;
11188             }
11189             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11190                     .equals( "Xenopus tropicalis" ) ) {
11191                 System.out.println( results.get( 0 ).getLineage() );
11192                 return false;
11193             }
11194             //
11195             results = null;
11196             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
11197             if ( results.size() != 1 ) {
11198                 return false;
11199             }
11200             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11201                 return false;
11202             }
11203             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11204                 return false;
11205             }
11206             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11207                 return false;
11208             }
11209             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11210                 return false;
11211             }
11212             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11213                 return false;
11214             }
11215             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11216                     .equals( "Xenopus tropicalis" ) ) {
11217                 System.out.println( results.get( 0 ).getLineage() );
11218                 return false;
11219             }
11220             //
11221             results = null;
11222             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
11223             if ( results.size() != 1 ) {
11224                 return false;
11225             }
11226             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11227                 return false;
11228             }
11229             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11230                 return false;
11231             }
11232             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11233                 return false;
11234             }
11235             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11236                 return false;
11237             }
11238             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11239                 return false;
11240             }
11241             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11242                     .equals( "Xenopus tropicalis" ) ) {
11243                 System.out.println( results.get( 0 ).getLineage() );
11244                 return false;
11245             }
11246         }
11247         catch ( final IOException e ) {
11248             System.out.println();
11249             System.out.println( "the following might be due to absence internet connection:" );
11250             e.printStackTrace( System.out );
11251             return true;
11252         }
11253         catch ( final Exception e ) {
11254             return false;
11255         }
11256         return true;
11257     }
11258
11259     private static boolean testWabiTxSearch() {
11260         try {
11261             String result = "";
11262             result = TxSearch.searchSimple( "nematostella" );
11263             result = TxSearch.getTxId( "nematostella" );
11264             if ( !result.equals( "45350" ) ) {
11265                 return false;
11266             }
11267             result = TxSearch.getTxName( "45350" );
11268             if ( !result.equals( "Nematostella" ) ) {
11269                 return false;
11270             }
11271             result = TxSearch.getTxId( "nematostella vectensis" );
11272             if ( !result.equals( "45351" ) ) {
11273                 return false;
11274             }
11275             result = TxSearch.getTxName( "45351" );
11276             if ( !result.equals( "Nematostella vectensis" ) ) {
11277                 return false;
11278             }
11279             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11280             if ( !result.equals( "536089" ) ) {
11281                 return false;
11282             }
11283             result = TxSearch.getTxName( "536089" );
11284             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11285                 return false;
11286             }
11287             final List<String> queries = new ArrayList<String>();
11288             queries.add( "Campylobacter coli" );
11289             queries.add( "Escherichia coli" );
11290             queries.add( "Arabidopsis" );
11291             queries.add( "Trichoplax" );
11292             queries.add( "Samanea saman" );
11293             queries.add( "Kluyveromyces marxianus" );
11294             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11295             queries.add( "Bornavirus parrot/PDD/2008" );
11296             final List<RANKS> ranks = new ArrayList<RANKS>();
11297             ranks.add( RANKS.SUPERKINGDOM );
11298             ranks.add( RANKS.KINGDOM );
11299             ranks.add( RANKS.FAMILY );
11300             ranks.add( RANKS.GENUS );
11301             ranks.add( RANKS.TRIBE );
11302             result = TxSearch.searchLineage( queries, ranks );
11303             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11304             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11305         }
11306         catch ( final Exception e ) {
11307             System.out.println();
11308             System.out.println( "the following might be due to absence internet connection:" );
11309             e.printStackTrace( System.out );
11310             return false;
11311         }
11312         return true;
11313     }
11314 }