ac070ff599fb1081b35c198e19aca436fba384ff
[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.net.URL;
33 import java.util.ArrayList;
34 import java.util.Date;
35 import java.util.HashSet;
36 import java.util.Iterator;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Set;
40 import java.util.SortedSet;
41
42 import org.forester.application.support_transfer;
43 import org.forester.archaeopteryx.TreePanelUtil;
44 import org.forester.development.DevelopmentTools;
45 import org.forester.evoinference.TestPhylogenyReconstruction;
46 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
47 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
48 import org.forester.go.TestGo;
49 import org.forester.io.parsers.FastaParser;
50 import org.forester.io.parsers.GeneralMsaParser;
51 import org.forester.io.parsers.HmmscanPerDomainTableParser;
52 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
53 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
54 import org.forester.io.parsers.nexus.NexusCharactersParser;
55 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
56 import org.forester.io.parsers.nhx.NHXParser;
57 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
58 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
59 import org.forester.io.parsers.tol.TolParser;
60 import org.forester.io.parsers.util.ParserUtils;
61 import org.forester.io.writers.PhylogenyWriter;
62 import org.forester.io.writers.SequenceWriter;
63 import org.forester.msa.BasicMsa;
64 import org.forester.msa.Mafft;
65 import org.forester.msa.Msa;
66 import org.forester.msa.MsaInferrer;
67 import org.forester.msa.MsaMethods;
68 import org.forester.pccx.TestPccx;
69 import org.forester.phylogeny.Phylogeny;
70 import org.forester.phylogeny.PhylogenyBranch;
71 import org.forester.phylogeny.PhylogenyMethods;
72 import org.forester.phylogeny.PhylogenyNode;
73 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
74 import org.forester.phylogeny.data.Accession;
75 import org.forester.phylogeny.data.Accession.Source;
76 import org.forester.phylogeny.data.BinaryCharacters;
77 import org.forester.phylogeny.data.BranchWidth;
78 import org.forester.phylogeny.data.Confidence;
79 import org.forester.phylogeny.data.Distribution;
80 import org.forester.phylogeny.data.DomainArchitecture;
81 import org.forester.phylogeny.data.Event;
82 import org.forester.phylogeny.data.Identifier;
83 import org.forester.phylogeny.data.PhylogenyData;
84 import org.forester.phylogeny.data.PhylogenyDataUtil;
85 import org.forester.phylogeny.data.Polygon;
86 import org.forester.phylogeny.data.PropertiesMap;
87 import org.forester.phylogeny.data.Property;
88 import org.forester.phylogeny.data.Property.AppliesTo;
89 import org.forester.phylogeny.data.ProteinDomain;
90 import org.forester.phylogeny.data.Taxonomy;
91 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
92 import org.forester.phylogeny.factories.PhylogenyFactory;
93 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
94 import org.forester.protein.BasicDomain;
95 import org.forester.protein.BasicProtein;
96 import org.forester.protein.Domain;
97 import org.forester.protein.Protein;
98 import org.forester.protein.ProteinId;
99 import org.forester.rio.TestRIO;
100 import org.forester.sdi.SDI;
101 import org.forester.sdi.SDIR;
102 import org.forester.sdi.TestGSDI;
103 import org.forester.sequence.BasicSequence;
104 import org.forester.sequence.Sequence;
105 import org.forester.species.BasicSpecies;
106 import org.forester.species.Species;
107 import org.forester.surfacing.TestSurfacing;
108 import org.forester.tools.ConfidenceAssessor;
109 import org.forester.tools.SupportCount;
110 import org.forester.tools.TreeSplitMatrix;
111 import org.forester.util.AsciiHistogram;
112 import org.forester.util.BasicDescriptiveStatistics;
113 import org.forester.util.BasicTable;
114 import org.forester.util.BasicTableParser;
115 import org.forester.util.DescriptiveStatistics;
116 import org.forester.util.ForesterConstants;
117 import org.forester.util.ForesterUtil;
118 import org.forester.util.GeneralTable;
119 import org.forester.util.SequenceAccessionTools;
120 import org.forester.ws.seqdb.SequenceDatabaseEntry;
121 import org.forester.ws.seqdb.SequenceDbWsTools;
122 import org.forester.ws.seqdb.UniProtTaxonomy;
123 import org.forester.ws.wabi.TxSearch;
124 import org.forester.ws.wabi.TxSearch.RANKS;
125 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
126 import org.forester.ws.wabi.TxSearch.TAX_RANK;
127
128 @SuppressWarnings( "unused")
129 public final class Test {
130
131     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
132                                                                    + ForesterUtil.getFileSeparator() + "resources"
133                                                                    + ForesterUtil.getFileSeparator();
134     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
135                                                                    + ForesterUtil.getFileSeparator() + "test_data"
136                                                                    + ForesterUtil.getFileSeparator();
137     private final static boolean PERFORM_DB_TESTS          = false;
138     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
139                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
140                                                                    + ForesterConstants.PHYLO_XML_XSD;
141     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
142                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
143                                                                    + ForesterConstants.PHYLO_XML_XSD;
144     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
145     private final static double  ZERO_DIFF                 = 1.0E-9;
146
147     public static boolean isEqual( final double a, final double b ) {
148         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
149     }
150
151     public static void main( final String[] args ) {
152         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
153         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
154                 + "]" );
155         Locale.setDefault( Locale.US );
156         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
157         int failed = 0;
158         int succeeded = 0;
159         System.out.print( "[Test if directory with files for testing exists/is readable: " );
160         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
161             System.out.println( "OK.]" );
162         }
163         else {
164             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
165             System.out.println( "Testing aborted." );
166             System.exit( -1 );
167         }
168         System.out.print( "[Test if resources directory exists/is readable: " );
169         if ( testDir( PATH_TO_RESOURCES ) ) {
170             System.out.println( "OK.]" );
171         }
172         else {
173             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
174             System.out.println( "Testing aborted." );
175             System.exit( -1 );
176         }
177         final long start_time = new Date().getTime();
178         System.out.print( "Basic node methods: " );
179         if ( Test.testBasicNodeMethods() ) {
180             System.out.println( "OK." );
181             succeeded++;
182         }
183         else {
184             System.out.println( "failed." );
185             failed++;
186         }
187         System.out.print( "Protein id: " );
188         if ( !testProteinId() ) {
189             System.out.println( "failed." );
190             failed++;
191         }
192         else {
193             succeeded++;
194         }
195         System.out.println( "OK." );
196         System.out.print( "Species: " );
197         if ( !testSpecies() ) {
198             System.out.println( "failed." );
199             failed++;
200         }
201         else {
202             succeeded++;
203         }
204         System.out.println( "OK." );
205         System.out.print( "Basic domain: " );
206         if ( !testBasicDomain() ) {
207             System.out.println( "failed." );
208             failed++;
209         }
210         else {
211             succeeded++;
212         }
213         System.out.println( "OK." );
214         System.out.print( "Basic protein: " );
215         if ( !testBasicProtein() ) {
216             System.out.println( "failed." );
217             failed++;
218         }
219         else {
220             succeeded++;
221         }
222         System.out.println( "OK." );
223         System.out.print( "Sequence writer: " );
224         if ( testSequenceWriter() ) {
225             System.out.println( "OK." );
226             succeeded++;
227         }
228         else {
229             System.out.println( "failed." );
230             failed++;
231         }
232         System.out.print( "Sequence id parsing: " );
233         if ( testSequenceIdParsing() ) {
234             System.out.println( "OK." );
235             succeeded++;
236         }
237         else {
238             System.out.println( "failed." );
239             failed++;
240         }
241         System.out.print( "UniProtKB id extraction: " );
242         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
243             System.out.println( "OK." );
244             succeeded++;
245         }
246         else {
247             System.out.println( "failed." );
248             failed++;
249         }
250         System.out.print( "Sequence DB tools 1: " );
251         if ( testSequenceDbWsTools1() ) {
252             System.out.println( "OK." );
253             succeeded++;
254         }
255         else {
256             System.out.println( "failed." );
257             failed++;
258         }
259         if ( PERFORM_DB_TESTS ) {
260             System.out.print( "Ebi Entry Retrieval: " );
261             if ( Test.testEbiEntryRetrieval() ) {
262                 System.out.println( "OK." );
263                 succeeded++;
264             }
265             else {
266                 System.out.println( "failed." );
267                 failed++;
268             }
269         }
270         // System.exit( 0 );
271         if ( PERFORM_DB_TESTS ) {
272             System.out.print( "Sequence DB tools 2: " );
273             if ( testSequenceDbWsTools2() ) {
274                 System.out.println( "OK." );
275                 succeeded++;
276             }
277             else {
278                 System.out.println( "failed." );
279                 failed++;
280                 System.exit( -1 );
281             }
282         }
283         // System.exit( 0 );
284         System.out.print( "Hmmscan output parser: " );
285         if ( testHmmscanOutputParser() ) {
286             System.out.println( "OK." );
287             succeeded++;
288         }
289         else {
290             System.out.println( "failed." );
291             failed++;
292         }
293         //
294         System.out.print( "Overlap removal: " );
295         if ( !org.forester.test.Test.testOverlapRemoval() ) {
296             System.out.println( "failed." );
297             failed++;
298         }
299         else {
300             succeeded++;
301         }
302         System.out.println( "OK." );
303         System.out.print( "Engulfing overlap removal: " );
304         if ( !Test.testEngulfingOverlapRemoval() ) {
305             System.out.println( "failed." );
306             failed++;
307         }
308         else {
309             succeeded++;
310         }
311         System.out.println( "OK." );
312         //
313         System.out.print( "Taxonomy code extraction: " );
314         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
315             System.out.println( "OK." );
316             succeeded++;
317         }
318         else {
319             System.out.println( "failed." );
320             failed++;
321         }
322         System.out.print( "SN extraction: " );
323         if ( Test.testExtractSNFromNodeName() ) {
324             System.out.println( "OK." );
325             succeeded++;
326         }
327         else {
328             System.out.println( "failed." );
329             failed++;
330         }
331         System.out.print( "Taxonomy extraction (general): " );
332         if ( Test.testTaxonomyExtraction() ) {
333             System.out.println( "OK." );
334             succeeded++;
335         }
336         else {
337             System.out.println( "failed." );
338             failed++;
339         }
340         System.out.print( "Uri for Aptx web sequence accession: " );
341         if ( Test.testCreateUriForSeqWeb() ) {
342             System.out.println( "OK." );
343             succeeded++;
344         }
345         else {
346             System.out.println( "failed." );
347             failed++;
348         }
349         System.out.print( "Basic node construction and parsing of NHX (node level): " );
350         if ( Test.testNHXNodeParsing() ) {
351             System.out.println( "OK." );
352             succeeded++;
353         }
354         else {
355             System.out.println( "failed." );
356             failed++;
357         }
358         System.out.print( "NHX parsing iterating: " );
359         if ( Test.testNHParsingIter() ) {
360             System.out.println( "OK." );
361             succeeded++;
362         }
363         else {
364             System.out.println( "failed." );
365             failed++;
366         }
367         System.out.print( "NH parsing: " );
368         if ( Test.testNHParsing() ) {
369             System.out.println( "OK." );
370             succeeded++;
371         }
372         else {
373             System.out.println( "failed." );
374             failed++;
375         }
376         System.out.print( "Conversion to NHX (node level): " );
377         if ( Test.testNHXconversion() ) {
378             System.out.println( "OK." );
379             succeeded++;
380         }
381         else {
382             System.out.println( "failed." );
383             failed++;
384         }
385         System.out.print( "NHX parsing: " );
386         if ( Test.testNHXParsing() ) {
387             System.out.println( "OK." );
388             succeeded++;
389         }
390         else {
391             System.out.println( "failed." );
392             failed++;
393         }
394         System.out.print( "NHX parsing with quotes: " );
395         if ( Test.testNHXParsingQuotes() ) {
396             System.out.println( "OK." );
397             succeeded++;
398         }
399         else {
400             System.out.println( "failed." );
401             failed++;
402         }
403         System.out.print( "NHX parsing (MrBayes): " );
404         if ( Test.testNHXParsingMB() ) {
405             System.out.println( "OK." );
406             succeeded++;
407         }
408         else {
409             System.out.println( "failed." );
410             failed++;
411         }
412         System.out.print( "Nexus characters parsing: " );
413         if ( Test.testNexusCharactersParsing() ) {
414             System.out.println( "OK." );
415             succeeded++;
416         }
417         else {
418             System.out.println( "failed." );
419             failed++;
420         }
421         System.out.print( "Nexus tree parsing iterating: " );
422         if ( Test.testNexusTreeParsingIterating() ) {
423             System.out.println( "OK." );
424             succeeded++;
425         }
426         else {
427             System.out.println( "failed." );
428             failed++;
429         }
430         System.out.print( "Nexus tree parsing: " );
431         if ( Test.testNexusTreeParsing() ) {
432             System.out.println( "OK." );
433             succeeded++;
434         }
435         else {
436             System.out.println( "failed." );
437             failed++;
438         }
439         System.out.print( "Nexus tree parsing (translating): " );
440         if ( Test.testNexusTreeParsingTranslating() ) {
441             System.out.println( "OK." );
442             succeeded++;
443         }
444         else {
445             System.out.println( "failed." );
446             failed++;
447         }
448         System.out.print( "Nexus matrix parsing: " );
449         if ( Test.testNexusMatrixParsing() ) {
450             System.out.println( "OK." );
451             succeeded++;
452         }
453         else {
454             System.out.println( "failed." );
455             failed++;
456         }
457         System.out.print( "Basic phyloXML parsing: " );
458         if ( Test.testBasicPhyloXMLparsing() ) {
459             System.out.println( "OK." );
460             succeeded++;
461         }
462         else {
463             System.out.println( "failed." );
464             failed++;
465         }
466         System.out.print( "Basic phyloXML parsing (validating against schema): " );
467         if ( testBasicPhyloXMLparsingValidating() ) {
468             System.out.println( "OK." );
469             succeeded++;
470         }
471         else {
472             System.out.println( "failed." );
473             failed++;
474         }
475         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
476         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
477             System.out.println( "OK." );
478             succeeded++;
479         }
480         else {
481             System.out.println( "failed." );
482             failed++;
483         }
484         System.out.print( "phyloXML Distribution Element: " );
485         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
486             System.out.println( "OK." );
487             succeeded++;
488         }
489         else {
490             System.out.println( "failed." );
491             failed++;
492         }
493         System.out.print( "Tol XML parsing: " );
494         if ( Test.testBasicTolXMLparsing() ) {
495             System.out.println( "OK." );
496             succeeded++;
497         }
498         else {
499             System.out.println( "failed." );
500             failed++;
501         }
502         System.out.print( "Copying of node data: " );
503         if ( Test.testCopyOfNodeData() ) {
504             System.out.println( "OK." );
505             succeeded++;
506         }
507         else {
508             System.out.println( "failed." );
509             failed++;
510         }
511         System.out.print( "Tree copy: " );
512         if ( Test.testTreeCopy() ) {
513             System.out.println( "OK." );
514             succeeded++;
515         }
516         else {
517             System.out.println( "failed." );
518             failed++;
519         }
520         System.out.print( "Basic tree methods: " );
521         if ( Test.testBasicTreeMethods() ) {
522             System.out.println( "OK." );
523             succeeded++;
524         }
525         else {
526             System.out.println( "failed." );
527             failed++;
528         }
529         System.out.print( "Tree methods: " );
530         if ( Test.testTreeMethods() ) {
531             System.out.println( "OK." );
532             succeeded++;
533         }
534         else {
535             System.out.println( "failed." );
536             failed++;
537         }
538         System.out.print( "Postorder Iterator: " );
539         if ( Test.testPostOrderIterator() ) {
540             System.out.println( "OK." );
541             succeeded++;
542         }
543         else {
544             System.out.println( "failed." );
545             failed++;
546         }
547         System.out.print( "Preorder Iterator: " );
548         if ( Test.testPreOrderIterator() ) {
549             System.out.println( "OK." );
550             succeeded++;
551         }
552         else {
553             System.out.println( "failed." );
554             failed++;
555         }
556         System.out.print( "Levelorder Iterator: " );
557         if ( Test.testLevelOrderIterator() ) {
558             System.out.println( "OK." );
559             succeeded++;
560         }
561         else {
562             System.out.println( "failed." );
563             failed++;
564         }
565         System.out.print( "Re-id methods: " );
566         if ( Test.testReIdMethods() ) {
567             System.out.println( "OK." );
568             succeeded++;
569         }
570         else {
571             System.out.println( "failed." );
572             failed++;
573         }
574         System.out.print( "Methods on last external nodes: " );
575         if ( Test.testLastExternalNodeMethods() ) {
576             System.out.println( "OK." );
577             succeeded++;
578         }
579         else {
580             System.out.println( "failed." );
581             failed++;
582         }
583         System.out.print( "Methods on external nodes: " );
584         if ( Test.testExternalNodeRelatedMethods() ) {
585             System.out.println( "OK." );
586             succeeded++;
587         }
588         else {
589             System.out.println( "failed." );
590             failed++;
591         }
592         System.out.print( "Deletion of external nodes: " );
593         if ( Test.testDeletionOfExternalNodes() ) {
594             System.out.println( "OK." );
595             succeeded++;
596         }
597         else {
598             System.out.println( "failed." );
599             failed++;
600         }
601         System.out.print( "Subtree deletion: " );
602         if ( Test.testSubtreeDeletion() ) {
603             System.out.println( "OK." );
604             succeeded++;
605         }
606         else {
607             System.out.println( "failed." );
608             failed++;
609         }
610         System.out.print( "Phylogeny branch: " );
611         if ( Test.testPhylogenyBranch() ) {
612             System.out.println( "OK." );
613             succeeded++;
614         }
615         else {
616             System.out.println( "failed." );
617             failed++;
618         }
619         System.out.print( "Rerooting: " );
620         if ( Test.testRerooting() ) {
621             System.out.println( "OK." );
622             succeeded++;
623         }
624         else {
625             System.out.println( "failed." );
626             failed++;
627         }
628         System.out.print( "Mipoint rooting: " );
629         if ( Test.testMidpointrooting() ) {
630             System.out.println( "OK." );
631             succeeded++;
632         }
633         else {
634             System.out.println( "failed." );
635             failed++;
636         }
637         System.out.print( "Node removal: " );
638         if ( Test.testNodeRemoval() ) {
639             System.out.println( "OK." );
640             succeeded++;
641         }
642         else {
643             System.out.println( "failed." );
644             failed++;
645         }
646         System.out.print( "Support count: " );
647         if ( Test.testSupportCount() ) {
648             System.out.println( "OK." );
649             succeeded++;
650         }
651         else {
652             System.out.println( "failed." );
653             failed++;
654         }
655         System.out.print( "Support transfer: " );
656         if ( Test.testSupportTransfer() ) {
657             System.out.println( "OK." );
658             succeeded++;
659         }
660         else {
661             System.out.println( "failed." );
662             failed++;
663         }
664         System.out.print( "Finding of LCA: " );
665         if ( Test.testGetLCA() ) {
666             System.out.println( "OK." );
667             succeeded++;
668         }
669         else {
670             System.out.println( "failed." );
671             failed++;
672         }
673         System.out.print( "Finding of LCA 2: " );
674         if ( Test.testGetLCA2() ) {
675             System.out.println( "OK." );
676             succeeded++;
677         }
678         else {
679             System.out.println( "failed." );
680             failed++;
681         }
682         System.out.print( "Calculation of distance between nodes: " );
683         if ( Test.testGetDistance() ) {
684             System.out.println( "OK." );
685             succeeded++;
686         }
687         else {
688             System.out.println( "failed." );
689             failed++;
690         }
691         System.out.print( "Descriptive statistics: " );
692         if ( Test.testDescriptiveStatistics() ) {
693             System.out.println( "OK." );
694             succeeded++;
695         }
696         else {
697             System.out.println( "failed." );
698             failed++;
699         }
700         System.out.print( "Data objects and methods: " );
701         if ( Test.testDataObjects() ) {
702             System.out.println( "OK." );
703             succeeded++;
704         }
705         else {
706             System.out.println( "failed." );
707             failed++;
708         }
709         System.out.print( "Properties map: " );
710         if ( Test.testPropertiesMap() ) {
711             System.out.println( "OK." );
712             succeeded++;
713         }
714         else {
715             System.out.println( "failed." );
716             failed++;
717         }
718         System.out.print( "SDIse: " );
719         if ( Test.testSDIse() ) {
720             System.out.println( "OK." );
721             succeeded++;
722         }
723         else {
724             System.out.println( "failed." );
725             failed++;
726         }
727         System.out.print( "SDIunrooted: " );
728         if ( Test.testSDIunrooted() ) {
729             System.out.println( "OK." );
730             succeeded++;
731         }
732         else {
733             System.out.println( "failed." );
734             failed++;
735         }
736         System.out.print( "GSDI: " );
737         if ( TestGSDI.test() ) {
738             System.out.println( "OK." );
739             succeeded++;
740         }
741         else {
742             System.out.println( "failed." );
743             failed++;
744         }
745         System.out.print( "RIO: " );
746         if ( TestRIO.test() ) {
747             System.out.println( "OK." );
748             succeeded++;
749         }
750         else {
751             System.out.println( "failed." );
752             failed++;
753         }
754         System.out.print( "Phylogeny reconstruction:" );
755         System.out.println();
756         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
757             System.out.println( "OK." );
758             succeeded++;
759         }
760         else {
761             System.out.println( "failed." );
762             failed++;
763         }
764         System.out.print( "Analysis of domain architectures: " );
765         System.out.println();
766         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
767             System.out.println( "OK." );
768             succeeded++;
769         }
770         else {
771             System.out.println( "failed." );
772             failed++;
773         }
774         System.out.print( "GO: " );
775         System.out.println();
776         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
777             System.out.println( "OK." );
778             succeeded++;
779         }
780         else {
781             System.out.println( "failed." );
782             failed++;
783         }
784         System.out.print( "Modeling tools: " );
785         if ( TestPccx.test() ) {
786             System.out.println( "OK." );
787             succeeded++;
788         }
789         else {
790             System.out.println( "failed." );
791             failed++;
792         }
793         System.out.print( "Split Matrix strict: " );
794         if ( Test.testSplitStrict() ) {
795             System.out.println( "OK." );
796             succeeded++;
797         }
798         else {
799             System.out.println( "failed." );
800             failed++;
801         }
802         System.out.print( "Split Matrix: " );
803         if ( Test.testSplit() ) {
804             System.out.println( "OK." );
805             succeeded++;
806         }
807         else {
808             System.out.println( "failed." );
809             failed++;
810         }
811         System.out.print( "Confidence Assessor: " );
812         if ( Test.testConfidenceAssessor() ) {
813             System.out.println( "OK." );
814             succeeded++;
815         }
816         else {
817             System.out.println( "failed." );
818             failed++;
819         }
820         System.out.print( "Basic table: " );
821         if ( Test.testBasicTable() ) {
822             System.out.println( "OK." );
823             succeeded++;
824         }
825         else {
826             System.out.println( "failed." );
827             failed++;
828         }
829         System.out.print( "General table: " );
830         if ( Test.testGeneralTable() ) {
831             System.out.println( "OK." );
832             succeeded++;
833         }
834         else {
835             System.out.println( "failed." );
836             failed++;
837         }
838         System.out.print( "Amino acid sequence: " );
839         if ( Test.testAminoAcidSequence() ) {
840             System.out.println( "OK." );
841             succeeded++;
842         }
843         else {
844             System.out.println( "failed." );
845             failed++;
846         }
847         System.out.print( "General MSA parser: " );
848         if ( Test.testGeneralMsaParser() ) {
849             System.out.println( "OK." );
850             succeeded++;
851         }
852         else {
853             System.out.println( "failed." );
854             failed++;
855         }
856         System.out.print( "Fasta parser for msa: " );
857         if ( Test.testFastaParser() ) {
858             System.out.println( "OK." );
859             succeeded++;
860         }
861         else {
862             System.out.println( "failed." );
863             failed++;
864         }
865         System.out.print( "Creation of balanced phylogeny: " );
866         if ( Test.testCreateBalancedPhylogeny() ) {
867             System.out.println( "OK." );
868             succeeded++;
869         }
870         else {
871             System.out.println( "failed." );
872             failed++;
873         }
874         System.out.print( "Genbank accessor parsing: " );
875         if ( Test.testGenbankAccessorParsing() ) {
876             System.out.println( "OK." );
877             succeeded++;
878         }
879         else {
880             System.out.println( "failed." );
881             failed++;
882         }
883         if ( PERFORM_DB_TESTS ) {
884             System.out.print( "Uniprot Entry Retrieval: " );
885             if ( Test.testUniprotEntryRetrieval() ) {
886                 System.out.println( "OK." );
887                 succeeded++;
888             }
889             else {
890                 System.out.println( "failed." );
891                 failed++;
892             }
893         }
894         if ( PERFORM_DB_TESTS ) {
895             System.out.print( "Uniprot Taxonomy Search: " );
896             if ( Test.testUniprotTaxonomySearch() ) {
897                 System.out.println( "OK." );
898                 succeeded++;
899             }
900             else {
901                 System.out.println( "failed." );
902                 failed++;
903             }
904         }
905         //----
906         String path = "";
907         final String os = ForesterUtil.OS_NAME.toLowerCase();
908         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
909             path = "/usr/local/bin/mafft";
910         }
911         else if ( os.indexOf( "win" ) >= 0 ) {
912             path = "C:\\Program Files\\mafft-win\\mafft.bat";
913         }
914         else {
915             path = "/home/czmasek/bin/mafft";
916         }
917         if ( !MsaInferrer.isInstalled( path ) ) {
918             path = "mafft";
919         }
920         if ( !MsaInferrer.isInstalled( path ) ) {
921             path = "/usr/local/bin/mafft";
922         }
923         if ( !MsaInferrer.isInstalled( path ) ) {
924             path = "/home/czmasek/SOFTWARE/MSA/MAFFT/mafft-7.130-without-extensions/scripts/mafft";
925         }
926         if ( MsaInferrer.isInstalled( path ) ) {
927             System.out.print( "MAFFT (external program): " );
928             if ( Test.testMafft( path ) ) {
929                 System.out.println( "OK." );
930                 succeeded++;
931             }
932             else {
933                 System.out.println( "failed [will not count towards failed tests]" );
934             }
935         }
936         //----
937         System.out.print( "Next nodes with collapsed: " );
938         if ( Test.testNextNodeWithCollapsing() ) {
939             System.out.println( "OK." );
940             succeeded++;
941         }
942         else {
943             System.out.println( "failed." );
944             failed++;
945         }
946         System.out.print( "Simple MSA quality: " );
947         if ( Test.testMsaQualityMethod() ) {
948             System.out.println( "OK." );
949             succeeded++;
950         }
951         else {
952             System.out.println( "failed." );
953             failed++;
954         }
955         System.out.print( "NHX parsing from URL: " );
956         if ( Test.testNHXparsingFromURL() ) {
957             System.out.println( "OK." );
958             succeeded++;
959         }
960         else {
961             System.out.println( "failed." );
962             failed++;
963         }
964         System.out.print( "phyloXML parsing from URL: " );
965         if ( Test.testPhyloXMLparsingFromURL() ) {
966             System.out.println( "OK." );
967             succeeded++;
968         }
969         else {
970             System.out.println( "failed." );
971             failed++;
972         }
973         System.out.println();
974         final Runtime rt = java.lang.Runtime.getRuntime();
975         final long free_memory = rt.freeMemory() / 1000000;
976         final long total_memory = rt.totalMemory() / 1000000;
977         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
978                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
979         System.out.println();
980         System.out.println( "Successful tests: " + succeeded );
981         System.out.println( "Failed     tests: " + failed );
982         System.out.println();
983         if ( failed < 1 ) {
984             System.out.println( "OK." );
985         }
986         else {
987             System.out.println( "Not OK." );
988         }
989     }
990
991     public static boolean testEngulfingOverlapRemoval() {
992         try {
993             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
994             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
995             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
996             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
997             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
998             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
999             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1000             final List<Boolean> covered = new ArrayList<Boolean>();
1001             covered.add( true ); // 0
1002             covered.add( false ); // 1
1003             covered.add( true ); // 2
1004             covered.add( false ); // 3
1005             covered.add( true ); // 4
1006             covered.add( true ); // 5
1007             covered.add( false ); // 6
1008             covered.add( true ); // 7
1009             covered.add( true ); // 8
1010             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1011                 return false;
1012             }
1013             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1014                 return false;
1015             }
1016             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1017                 return false;
1018             }
1019             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1020                 return false;
1021             }
1022             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1023                 return false;
1024             }
1025             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1026                 return false;
1027             }
1028             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1029                 return false;
1030             }
1031             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1032             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1033             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1034             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1035             abc.addProteinDomain( a );
1036             abc.addProteinDomain( b );
1037             abc.addProteinDomain( c );
1038             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1039             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1040             if ( abc.getNumberOfProteinDomains() != 3 ) {
1041                 return false;
1042             }
1043             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1044                 return false;
1045             }
1046             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1047                 return false;
1048             }
1049             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1050                 return false;
1051             }
1052             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1053                 return false;
1054             }
1055             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1056             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1057             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1058             final Protein def = new BasicProtein( "def", "nemve", 0 );
1059             def.addProteinDomain( d );
1060             def.addProteinDomain( e );
1061             def.addProteinDomain( f );
1062             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1063             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1064             if ( def.getNumberOfProteinDomains() != 3 ) {
1065                 return false;
1066             }
1067             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1068                 return false;
1069             }
1070             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1071                 return false;
1072             }
1073             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1074                 return false;
1075             }
1076             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1077                 return false;
1078             }
1079             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1080                 return false;
1081             }
1082         }
1083         catch ( final Exception e ) {
1084             e.printStackTrace( System.out );
1085             return false;
1086         }
1087         return true;
1088     }
1089
1090     public static final boolean testPhyloXMLparsingFromURL() {
1091         try {
1092             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1093             final URL u = new URL( s );
1094             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1095             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1096             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1097                 return false;
1098             }
1099         }
1100         catch ( final Exception e ) {
1101             e.printStackTrace();
1102         }
1103         return true;
1104     }
1105
1106     public static final boolean testNHXparsingFromURL() {
1107         try {
1108             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1109             final URL u = new URL( s );
1110             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1111             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1112             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1113                 return false;
1114             }
1115             if ( !phys[ 0 ].toNewHampshire().equals( "((a,b),c);" ) ) {
1116                 System.out.println( phys[ 0 ].toNewHampshire() );
1117                 return false;
1118             }
1119             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1120             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1121                 return false;
1122             }
1123             if ( !phys2[ 0 ].toNewHampshire().equals( "((a,b),c);" ) ) {
1124                 System.out.println( phys2[ 0 ].toNewHampshire() );
1125                 return false;
1126             }
1127             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1128             final NHXParser p = new NHXParser();
1129             final URL u2 = new URL( s );
1130             p.setSource( u2 );
1131             if ( !p.hasNext() ) {
1132                 return false;
1133             }
1134             if ( !p.next().toNewHampshire().equals( "((a,b),c);" ) ) {
1135                 return false;
1136             }
1137             if ( p.hasNext() ) {
1138                 return false;
1139             }
1140             if ( p.next() != null ) {
1141                 return false;
1142             }
1143             if ( p.hasNext() ) {
1144                 return false;
1145             }
1146             if ( p.next() != null ) {
1147                 return false;
1148             }
1149             p.reset();
1150             if ( !p.hasNext() ) {
1151                 return false;
1152             }
1153             if ( !p.next().toNewHampshire().equals( "((a,b),c);" ) ) {
1154                 return false;
1155             }
1156             if ( p.hasNext() ) {
1157                 return false;
1158             }
1159             if ( p.next() != null ) {
1160                 return false;
1161             }
1162             if ( p.hasNext() ) {
1163                 return false;
1164             }
1165             if ( p.next() != null ) {
1166                 return false;
1167             }
1168             p.reset();
1169             if ( !p.hasNext() ) {
1170                 return false;
1171             }
1172         }
1173         catch ( final Exception e ) {
1174             e.printStackTrace();
1175         }
1176         return true;
1177     }
1178
1179     public static boolean testOverlapRemoval() {
1180         try {
1181             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1182             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1183             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1184             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1185             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1186             final List<Boolean> covered = new ArrayList<Boolean>();
1187             covered.add( true ); // 0
1188             covered.add( false ); // 1
1189             covered.add( true ); // 2
1190             covered.add( false ); // 3
1191             covered.add( true ); // 4
1192             covered.add( true ); // 5
1193             covered.add( false ); // 6
1194             covered.add( true ); // 7
1195             covered.add( true ); // 8
1196             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1197                 return false;
1198             }
1199             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1200                 return false;
1201             }
1202             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1203                 return false;
1204             }
1205             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1206                 return false;
1207             }
1208             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1209                 return false;
1210             }
1211             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1212             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1213             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1214             ab.addProteinDomain( a );
1215             ab.addProteinDomain( b );
1216             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1217             if ( ab.getNumberOfProteinDomains() != 2 ) {
1218                 return false;
1219             }
1220             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1221                 return false;
1222             }
1223             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1224                 return false;
1225             }
1226             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1227             if ( ab.getNumberOfProteinDomains() != 2 ) {
1228                 return false;
1229             }
1230             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1231                 return false;
1232             }
1233             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1234             final Domain d = new BasicDomain( "d",
1235                                               ( short ) 10000,
1236                                               ( short ) 10500,
1237                                               ( short ) 1,
1238                                               ( short ) 1,
1239                                               0.0000001,
1240                                               1 );
1241             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1242             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1243             cde.addProteinDomain( c );
1244             cde.addProteinDomain( d );
1245             cde.addProteinDomain( e );
1246             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1247             if ( cde.getNumberOfProteinDomains() != 3 ) {
1248                 return false;
1249             }
1250             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1251                 return false;
1252             }
1253             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1254             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1255             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1256             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1257             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1258             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1259             fghi.addProteinDomain( f );
1260             fghi.addProteinDomain( g );
1261             fghi.addProteinDomain( h );
1262             fghi.addProteinDomain( i );
1263             fghi.addProteinDomain( i );
1264             fghi.addProteinDomain( i );
1265             fghi.addProteinDomain( i2 );
1266             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1267             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1268                 return false;
1269             }
1270             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1271                 return false;
1272             }
1273             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1274                 return false;
1275             }
1276             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1277             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1278                 return false;
1279             }
1280             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1281                 return false;
1282             }
1283             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1284             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1285             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1286             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1287             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1288             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1289             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1290             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1291             jklm.addProteinDomain( j );
1292             jklm.addProteinDomain( k );
1293             jklm.addProteinDomain( l );
1294             jklm.addProteinDomain( m );
1295             jklm.addProteinDomain( m0 );
1296             jklm.addProteinDomain( m1 );
1297             jklm.addProteinDomain( m2 );
1298             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1299             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1300                 return false;
1301             }
1302             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1303                 return false;
1304             }
1305             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1306                 return false;
1307             }
1308             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1309             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1310                 return false;
1311             }
1312             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1313                 return false;
1314             }
1315             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1316             final Protein od = new BasicProtein( "od", "varanus", 0 );
1317             od.addProteinDomain( only );
1318             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1319             if ( od.getNumberOfProteinDomains() != 1 ) {
1320                 return false;
1321             }
1322             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1323                 return false;
1324             }
1325         }
1326         catch ( final Exception e ) {
1327             e.printStackTrace( System.out );
1328             return false;
1329         }
1330         return true;
1331     }
1332
1333     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1334         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1335         return p;
1336     }
1337
1338     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1339         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1340     }
1341
1342     private static boolean testAminoAcidSequence() {
1343         try {
1344             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1345             if ( aa1.getLength() != 13 ) {
1346                 return false;
1347             }
1348             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1349                 return false;
1350             }
1351             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1352                 return false;
1353             }
1354             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1355                 return false;
1356             }
1357             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1358             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1359                 return false;
1360             }
1361             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1362             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1363                 return false;
1364             }
1365             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1366             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1367                 return false;
1368             }
1369         }
1370         catch ( final Exception e ) {
1371             e.printStackTrace();
1372             return false;
1373         }
1374         return true;
1375     }
1376
1377     private static boolean testBasicDomain() {
1378         try {
1379             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1380             if ( !pd.getDomainId().equals( "id" ) ) {
1381                 return false;
1382             }
1383             if ( pd.getNumber() != 1 ) {
1384                 return false;
1385             }
1386             if ( pd.getTotalCount() != 4 ) {
1387                 return false;
1388             }
1389             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1390                 return false;
1391             }
1392             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1393             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1394             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1395             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1396             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1397             if ( !a1.equals( a1 ) ) {
1398                 return false;
1399             }
1400             if ( !a1.equals( a1_copy ) ) {
1401                 return false;
1402             }
1403             if ( !a1.equals( a1_equal ) ) {
1404                 return false;
1405             }
1406             if ( !a1.equals( a2 ) ) {
1407                 return false;
1408             }
1409             if ( a1.equals( a3 ) ) {
1410                 return false;
1411             }
1412             if ( a1.compareTo( a1 ) != 0 ) {
1413                 return false;
1414             }
1415             if ( a1.compareTo( a1_copy ) != 0 ) {
1416                 return false;
1417             }
1418             if ( a1.compareTo( a1_equal ) != 0 ) {
1419                 return false;
1420             }
1421             if ( a1.compareTo( a2 ) != 0 ) {
1422                 return false;
1423             }
1424             if ( a1.compareTo( a3 ) == 0 ) {
1425                 return false;
1426             }
1427         }
1428         catch ( final Exception e ) {
1429             e.printStackTrace( System.out );
1430             return false;
1431         }
1432         return true;
1433     }
1434
1435     private static boolean testBasicNodeMethods() {
1436         try {
1437             if ( PhylogenyNode.getNodeCount() != 0 ) {
1438                 return false;
1439             }
1440             final PhylogenyNode n1 = new PhylogenyNode();
1441             final PhylogenyNode n2 = PhylogenyNode
1442                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1443             final PhylogenyNode n3 = PhylogenyNode
1444                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1445             final PhylogenyNode n4 = PhylogenyNode
1446                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1447             if ( n1.isHasAssignedEvent() ) {
1448                 return false;
1449             }
1450             if ( PhylogenyNode.getNodeCount() != 4 ) {
1451                 return false;
1452             }
1453             if ( n3.getIndicator() != 0 ) {
1454                 return false;
1455             }
1456             if ( n3.getNumberOfExternalNodes() != 1 ) {
1457                 return false;
1458             }
1459             if ( !n3.isExternal() ) {
1460                 return false;
1461             }
1462             if ( !n3.isRoot() ) {
1463                 return false;
1464             }
1465             if ( !n4.getName().equals( "n4" ) ) {
1466                 return false;
1467             }
1468         }
1469         catch ( final Exception e ) {
1470             e.printStackTrace( System.out );
1471             return false;
1472         }
1473         return true;
1474     }
1475
1476     private static boolean testBasicPhyloXMLparsing() {
1477         try {
1478             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1479             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1480             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1481                                                               xml_parser );
1482             if ( xml_parser.getErrorCount() > 0 ) {
1483                 System.out.println( xml_parser.getErrorMessages().toString() );
1484                 return false;
1485             }
1486             if ( phylogenies_0.length != 4 ) {
1487                 return false;
1488             }
1489             final Phylogeny t1 = phylogenies_0[ 0 ];
1490             final Phylogeny t2 = phylogenies_0[ 1 ];
1491             final Phylogeny t3 = phylogenies_0[ 2 ];
1492             final Phylogeny t4 = phylogenies_0[ 3 ];
1493             if ( t1.getNumberOfExternalNodes() != 1 ) {
1494                 return false;
1495             }
1496             if ( !t1.isRooted() ) {
1497                 return false;
1498             }
1499             if ( t1.isRerootable() ) {
1500                 return false;
1501             }
1502             if ( !t1.getType().equals( "gene_tree" ) ) {
1503                 return false;
1504             }
1505             if ( t2.getNumberOfExternalNodes() != 2 ) {
1506                 return false;
1507             }
1508             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1509                 return false;
1510             }
1511             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1512                 return false;
1513             }
1514             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1515                 return false;
1516             }
1517             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1518                 return false;
1519             }
1520             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1521                 return false;
1522             }
1523             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1524                 return false;
1525             }
1526             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1527                     .startsWith( "actgtgggggt" ) ) {
1528                 return false;
1529             }
1530             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1531                     .startsWith( "ctgtgatgcat" ) ) {
1532                 return false;
1533             }
1534             if ( t3.getNumberOfExternalNodes() != 4 ) {
1535                 return false;
1536             }
1537             if ( !t1.getName().equals( "t1" ) ) {
1538                 return false;
1539             }
1540             if ( !t2.getName().equals( "t2" ) ) {
1541                 return false;
1542             }
1543             if ( !t3.getName().equals( "t3" ) ) {
1544                 return false;
1545             }
1546             if ( !t4.getName().equals( "t4" ) ) {
1547                 return false;
1548             }
1549             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1550                 return false;
1551             }
1552             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1553                 return false;
1554             }
1555             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1556                 return false;
1557             }
1558             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1559                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1560                 return false;
1561             }
1562             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1563                 return false;
1564             }
1565             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1566                 return false;
1567             }
1568             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1569                 return false;
1570             }
1571             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1572                     .equals( "apoptosis" ) ) {
1573                 return false;
1574             }
1575             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1576                     .equals( "GO:0006915" ) ) {
1577                 return false;
1578             }
1579             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1580                     .equals( "UniProtKB" ) ) {
1581                 return false;
1582             }
1583             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1584                     .equals( "experimental" ) ) {
1585                 return false;
1586             }
1587             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1588                     .equals( "function" ) ) {
1589                 return false;
1590             }
1591             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1592                     .getValue() != 1 ) {
1593                 return false;
1594             }
1595             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1596                     .getType().equals( "ml" ) ) {
1597                 return false;
1598             }
1599             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1600                     .equals( "apoptosis" ) ) {
1601                 return false;
1602             }
1603             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1604                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1605                 return false;
1606             }
1607             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1608                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1609                 return false;
1610             }
1611             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1612                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1613                 return false;
1614             }
1615             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1616                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1617                 return false;
1618             }
1619             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1620                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1621                 return false;
1622             }
1623             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1624                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1625                 return false;
1626             }
1627             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1628                     .equals( "GO:0005829" ) ) {
1629                 return false;
1630             }
1631             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1632                     .equals( "intracellular organelle" ) ) {
1633                 return false;
1634             }
1635             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1636                 return false;
1637             }
1638             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1639                     .equals( "UniProt link" ) ) ) {
1640                 return false;
1641             }
1642             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1643                 return false;
1644             }
1645             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1646             if ( x.size() != 4 ) {
1647                 return false;
1648             }
1649             int c = 0;
1650             for( final Accession acc : x ) {
1651                 if ( c == 0 ) {
1652                     if ( !acc.getSource().equals( "KEGG" ) ) {
1653                         return false;
1654                     }
1655                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1656                         return false;
1657                     }
1658                 }
1659                 c++;
1660             }
1661         }
1662         catch ( final Exception e ) {
1663             e.printStackTrace( System.out );
1664             return false;
1665         }
1666         return true;
1667     }
1668
1669     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1670         try {
1671             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1672             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1673             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1674                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1675             }
1676             else {
1677                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1678             }
1679             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1680                                                               xml_parser );
1681             if ( xml_parser.getErrorCount() > 0 ) {
1682                 System.out.println( xml_parser.getErrorMessages().toString() );
1683                 return false;
1684             }
1685             if ( phylogenies_0.length != 4 ) {
1686                 return false;
1687             }
1688             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1689             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1690             if ( phylogenies_t1.length != 1 ) {
1691                 return false;
1692             }
1693             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1694             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1695                 return false;
1696             }
1697             if ( !t1_rt.isRooted() ) {
1698                 return false;
1699             }
1700             if ( t1_rt.isRerootable() ) {
1701                 return false;
1702             }
1703             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1704                 return false;
1705             }
1706             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1707             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1708             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1709             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1710                 return false;
1711             }
1712             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1713                 return false;
1714             }
1715             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1716                 return false;
1717             }
1718             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1719                 return false;
1720             }
1721             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1722                     .startsWith( "actgtgggggt" ) ) {
1723                 return false;
1724             }
1725             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1726                     .startsWith( "ctgtgatgcat" ) ) {
1727                 return false;
1728             }
1729             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1730             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1731             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1732             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1733             if ( phylogenies_1.length != 1 ) {
1734                 return false;
1735             }
1736             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1737             if ( !t3_rt.getName().equals( "t3" ) ) {
1738                 return false;
1739             }
1740             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1741                 return false;
1742             }
1743             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1744                 return false;
1745             }
1746             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1747                 return false;
1748             }
1749             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1750                 return false;
1751             }
1752             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1753                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1754                 return false;
1755             }
1756             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1757                 return false;
1758             }
1759             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1760                 return false;
1761             }
1762             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1763                     .equals( "UniProtKB" ) ) {
1764                 return false;
1765             }
1766             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1767                     .equals( "apoptosis" ) ) {
1768                 return false;
1769             }
1770             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1771                     .equals( "GO:0006915" ) ) {
1772                 return false;
1773             }
1774             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1775                     .equals( "UniProtKB" ) ) {
1776                 return false;
1777             }
1778             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1779                     .equals( "experimental" ) ) {
1780                 return false;
1781             }
1782             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1783                     .equals( "function" ) ) {
1784                 return false;
1785             }
1786             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1787                     .getValue() != 1 ) {
1788                 return false;
1789             }
1790             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1791                     .getType().equals( "ml" ) ) {
1792                 return false;
1793             }
1794             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1795                     .equals( "apoptosis" ) ) {
1796                 return false;
1797             }
1798             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1799                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1800                 return false;
1801             }
1802             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1803                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1804                 return false;
1805             }
1806             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1807                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1808                 return false;
1809             }
1810             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1811                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1812                 return false;
1813             }
1814             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1815                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1816                 return false;
1817             }
1818             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1819                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1820                 return false;
1821             }
1822             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1823                     .equals( "GO:0005829" ) ) {
1824                 return false;
1825             }
1826             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1827                     .equals( "intracellular organelle" ) ) {
1828                 return false;
1829             }
1830             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1831                 return false;
1832             }
1833             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1834                     .equals( "UniProt link" ) ) ) {
1835                 return false;
1836             }
1837             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1838                 return false;
1839             }
1840             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1841                 return false;
1842             }
1843             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1844                     .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." ) ) ) {
1845                 return false;
1846             }
1847             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1848                 return false;
1849             }
1850             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1851                 return false;
1852             }
1853             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1854                 return false;
1855             }
1856             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1857                 return false;
1858             }
1859             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1860                     .equals( "ncbi" ) ) {
1861                 return false;
1862             }
1863             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1864                 return false;
1865             }
1866             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1867                     .getName().equals( "B" ) ) {
1868                 return false;
1869             }
1870             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1871                     .getFrom() != 21 ) {
1872                 return false;
1873             }
1874             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1875                 return false;
1876             }
1877             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1878                     .getLength() != 24 ) {
1879                 return false;
1880             }
1881             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1882                     .getConfidence() != 2144 ) {
1883                 return false;
1884             }
1885             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1886                     .equals( "pfam" ) ) {
1887                 return false;
1888             }
1889             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1890                 return false;
1891             }
1892             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1893                 return false;
1894             }
1895             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1896                 return false;
1897             }
1898             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1899                 return false;
1900             }
1901             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1902             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1903                 return false;
1904             }
1905             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1906                 return false;
1907             }
1908             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1909                 return false;
1910             }
1911             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1912                 return false;
1913             }
1914             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1915                 return false;
1916             }
1917             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1918                 return false;
1919             }
1920             if ( taxbb.getSynonyms().size() != 2 ) {
1921                 return false;
1922             }
1923             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1924                 return false;
1925             }
1926             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1927                 return false;
1928             }
1929             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1930                 return false;
1931             }
1932             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1933                 return false;
1934             }
1935             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1936                 return false;
1937             }
1938             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1939                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1940                 return false;
1941             }
1942             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1943                 return false;
1944             }
1945             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1946                 return false;
1947             }
1948             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1949                 return false;
1950             }
1951             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1952                 return false;
1953             }
1954             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1955                 return false;
1956             }
1957             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1958                 return false;
1959             }
1960             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1961                 return false;
1962             }
1963             //
1964             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1965                 return false;
1966             }
1967             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1968                     .equalsIgnoreCase( "435" ) ) {
1969                 return false;
1970             }
1971             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1972                 return false;
1973             }
1974             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1975                     .equalsIgnoreCase( "443.7" ) ) {
1976                 return false;
1977             }
1978             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1979                 return false;
1980             }
1981             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1982                 return false;
1983             }
1984             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1985                     .equalsIgnoreCase( "433" ) ) {
1986                 return false;
1987             }
1988             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
1989                     .getCrossReferences();
1990             if ( x.size() != 4 ) {
1991                 return false;
1992             }
1993             int c = 0;
1994             for( final Accession acc : x ) {
1995                 if ( c == 0 ) {
1996                     if ( !acc.getSource().equals( "KEGG" ) ) {
1997                         return false;
1998                     }
1999                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2000                         return false;
2001                     }
2002                 }
2003                 c++;
2004             }
2005         }
2006         catch ( final Exception e ) {
2007             e.printStackTrace( System.out );
2008             return false;
2009         }
2010         return true;
2011     }
2012
2013     private static boolean testBasicPhyloXMLparsingValidating() {
2014         try {
2015             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2016             PhyloXmlParser xml_parser = null;
2017             try {
2018                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2019             }
2020             catch ( final Exception e ) {
2021                 // Do nothing -- means were not running from jar.
2022             }
2023             if ( xml_parser == null ) {
2024                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2025                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2026                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2027                 }
2028                 else {
2029                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2030                 }
2031             }
2032             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2033                                                               xml_parser );
2034             if ( xml_parser.getErrorCount() > 0 ) {
2035                 System.out.println( xml_parser.getErrorMessages().toString() );
2036                 return false;
2037             }
2038             if ( phylogenies_0.length != 4 ) {
2039                 return false;
2040             }
2041             final Phylogeny t1 = phylogenies_0[ 0 ];
2042             final Phylogeny t2 = phylogenies_0[ 1 ];
2043             final Phylogeny t3 = phylogenies_0[ 2 ];
2044             final Phylogeny t4 = phylogenies_0[ 3 ];
2045             if ( !t1.getName().equals( "t1" ) ) {
2046                 return false;
2047             }
2048             if ( !t2.getName().equals( "t2" ) ) {
2049                 return false;
2050             }
2051             if ( !t3.getName().equals( "t3" ) ) {
2052                 return false;
2053             }
2054             if ( !t4.getName().equals( "t4" ) ) {
2055                 return false;
2056             }
2057             if ( t1.getNumberOfExternalNodes() != 1 ) {
2058                 return false;
2059             }
2060             if ( t2.getNumberOfExternalNodes() != 2 ) {
2061                 return false;
2062             }
2063             if ( t3.getNumberOfExternalNodes() != 4 ) {
2064                 return false;
2065             }
2066             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2067             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2068             if ( xml_parser.getErrorCount() > 0 ) {
2069                 System.out.println( "errors:" );
2070                 System.out.println( xml_parser.getErrorMessages().toString() );
2071                 return false;
2072             }
2073             if ( phylogenies_1.length != 4 ) {
2074                 return false;
2075             }
2076             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2077                                                               xml_parser );
2078             if ( xml_parser.getErrorCount() > 0 ) {
2079                 System.out.println( "errors:" );
2080                 System.out.println( xml_parser.getErrorMessages().toString() );
2081                 return false;
2082             }
2083             if ( phylogenies_2.length != 1 ) {
2084                 return false;
2085             }
2086             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2087                 return false;
2088             }
2089             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2090                                                               xml_parser );
2091             if ( xml_parser.getErrorCount() > 0 ) {
2092                 System.out.println( xml_parser.getErrorMessages().toString() );
2093                 return false;
2094             }
2095             if ( phylogenies_3.length != 2 ) {
2096                 return false;
2097             }
2098             final Phylogeny a = phylogenies_3[ 0 ];
2099             if ( !a.getName().equals( "tree 4" ) ) {
2100                 return false;
2101             }
2102             if ( a.getNumberOfExternalNodes() != 3 ) {
2103                 return false;
2104             }
2105             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2106                 return false;
2107             }
2108             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2109                 return false;
2110             }
2111             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2112                                                               xml_parser );
2113             if ( xml_parser.getErrorCount() > 0 ) {
2114                 System.out.println( xml_parser.getErrorMessages().toString() );
2115                 return false;
2116             }
2117             if ( phylogenies_4.length != 1 ) {
2118                 return false;
2119             }
2120             final Phylogeny s = phylogenies_4[ 0 ];
2121             if ( s.getNumberOfExternalNodes() != 6 ) {
2122                 return false;
2123             }
2124             s.getNode( "first" );
2125             s.getNode( "<>" );
2126             s.getNode( "\"<a'b&c'd\">\"" );
2127             s.getNode( "'''\"" );
2128             s.getNode( "\"\"\"" );
2129             s.getNode( "dick & doof" );
2130         }
2131         catch ( final Exception e ) {
2132             e.printStackTrace( System.out );
2133             return false;
2134         }
2135         return true;
2136     }
2137
2138     private static boolean testBasicProtein() {
2139         try {
2140             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2141             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2142             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2143             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2144             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2145             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2146             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2147             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2148             p0.addProteinDomain( y );
2149             p0.addProteinDomain( e );
2150             p0.addProteinDomain( b );
2151             p0.addProteinDomain( c );
2152             p0.addProteinDomain( d );
2153             p0.addProteinDomain( a );
2154             p0.addProteinDomain( x );
2155             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2156                 return false;
2157             }
2158             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2159                 return false;
2160             }
2161             //
2162             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2163             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2164             aa0.addProteinDomain( a1 );
2165             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2166                 return false;
2167             }
2168             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2169                 return false;
2170             }
2171             //
2172             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2173             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2174             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2175             aa1.addProteinDomain( a11 );
2176             aa1.addProteinDomain( a12 );
2177             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2178                 return false;
2179             }
2180             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2181                 return false;
2182             }
2183             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2184             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2185                 return false;
2186             }
2187             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2188                 return false;
2189             }
2190             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2191                 return false;
2192             }
2193             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2194             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2195                 return false;
2196             }
2197             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2198                 return false;
2199             }
2200             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2201                 return false;
2202             }
2203             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2204                 return false;
2205             }
2206             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2207             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2208                 return false;
2209             }
2210             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2211                 return false;
2212             }
2213             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2214                 return false;
2215             }
2216             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2217                 return false;
2218             }
2219             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2220             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2221                 return false;
2222             }
2223             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2224                 return false;
2225             }
2226             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2227                 return false;
2228             }
2229             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2230                 return false;
2231             }
2232             //
2233             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2234             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2235             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2236             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2237             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2238             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2239             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2240             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2241             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2242             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2243             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2244             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2245             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2246             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2247             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2248             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2249             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2250             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2251             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2252             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2253             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2254             p00.addProteinDomain( y0 );
2255             p00.addProteinDomain( e0 );
2256             p00.addProteinDomain( b0 );
2257             p00.addProteinDomain( c0 );
2258             p00.addProteinDomain( d0 );
2259             p00.addProteinDomain( a0 );
2260             p00.addProteinDomain( x0 );
2261             p00.addProteinDomain( y1 );
2262             p00.addProteinDomain( y2 );
2263             p00.addProteinDomain( y3 );
2264             p00.addProteinDomain( e1 );
2265             p00.addProteinDomain( e2 );
2266             p00.addProteinDomain( e3 );
2267             p00.addProteinDomain( e4 );
2268             p00.addProteinDomain( e5 );
2269             p00.addProteinDomain( z0 );
2270             p00.addProteinDomain( z1 );
2271             p00.addProteinDomain( z2 );
2272             p00.addProteinDomain( zz0 );
2273             p00.addProteinDomain( zz1 );
2274             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2275                 return false;
2276             }
2277             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2278                 return false;
2279             }
2280             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2281                 return false;
2282             }
2283             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2284                 return false;
2285             }
2286             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" ) ) {
2287                 return false;
2288             }
2289             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2290             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2291             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2292             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2293             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2294             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2295             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2296             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2297             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2298             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2299             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2300             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2301             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2302             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2303             p.addProteinDomain( B15 );
2304             p.addProteinDomain( C50 );
2305             p.addProteinDomain( A60 );
2306             p.addProteinDomain( A30 );
2307             p.addProteinDomain( C70 );
2308             p.addProteinDomain( B35 );
2309             p.addProteinDomain( B40 );
2310             p.addProteinDomain( A0 );
2311             p.addProteinDomain( A10 );
2312             p.addProteinDomain( A20 );
2313             p.addProteinDomain( B25 );
2314             p.addProteinDomain( D80 );
2315             List<String> domains_ids = new ArrayList<String>();
2316             domains_ids.add( "A" );
2317             domains_ids.add( "B" );
2318             domains_ids.add( "C" );
2319             if ( !p.contains( domains_ids, false ) ) {
2320                 return false;
2321             }
2322             if ( !p.contains( domains_ids, true ) ) {
2323                 return false;
2324             }
2325             domains_ids.add( "X" );
2326             if ( p.contains( domains_ids, false ) ) {
2327                 return false;
2328             }
2329             if ( p.contains( domains_ids, true ) ) {
2330                 return false;
2331             }
2332             domains_ids = new ArrayList<String>();
2333             domains_ids.add( "A" );
2334             domains_ids.add( "C" );
2335             domains_ids.add( "D" );
2336             if ( !p.contains( domains_ids, false ) ) {
2337                 return false;
2338             }
2339             if ( !p.contains( domains_ids, true ) ) {
2340                 return false;
2341             }
2342             domains_ids = new ArrayList<String>();
2343             domains_ids.add( "A" );
2344             domains_ids.add( "D" );
2345             domains_ids.add( "C" );
2346             if ( !p.contains( domains_ids, false ) ) {
2347                 return false;
2348             }
2349             if ( p.contains( domains_ids, true ) ) {
2350                 return false;
2351             }
2352             domains_ids = new ArrayList<String>();
2353             domains_ids.add( "A" );
2354             domains_ids.add( "A" );
2355             domains_ids.add( "B" );
2356             if ( !p.contains( domains_ids, false ) ) {
2357                 return false;
2358             }
2359             if ( !p.contains( domains_ids, true ) ) {
2360                 return false;
2361             }
2362             domains_ids = new ArrayList<String>();
2363             domains_ids.add( "A" );
2364             domains_ids.add( "A" );
2365             domains_ids.add( "A" );
2366             domains_ids.add( "B" );
2367             domains_ids.add( "B" );
2368             if ( !p.contains( domains_ids, false ) ) {
2369                 return false;
2370             }
2371             if ( !p.contains( domains_ids, true ) ) {
2372                 return false;
2373             }
2374             domains_ids = new ArrayList<String>();
2375             domains_ids.add( "A" );
2376             domains_ids.add( "A" );
2377             domains_ids.add( "B" );
2378             domains_ids.add( "A" );
2379             domains_ids.add( "B" );
2380             domains_ids.add( "B" );
2381             domains_ids.add( "A" );
2382             domains_ids.add( "B" );
2383             domains_ids.add( "C" );
2384             domains_ids.add( "A" );
2385             domains_ids.add( "C" );
2386             domains_ids.add( "D" );
2387             if ( !p.contains( domains_ids, false ) ) {
2388                 return false;
2389             }
2390             if ( p.contains( domains_ids, true ) ) {
2391                 return false;
2392             }
2393         }
2394         catch ( final Exception e ) {
2395             e.printStackTrace( System.out );
2396             return false;
2397         }
2398         return true;
2399     }
2400
2401     private static boolean testBasicTable() {
2402         try {
2403             final BasicTable<String> t0 = new BasicTable<String>();
2404             if ( t0.getNumberOfColumns() != 0 ) {
2405                 return false;
2406             }
2407             if ( t0.getNumberOfRows() != 0 ) {
2408                 return false;
2409             }
2410             t0.setValue( 3, 2, "23" );
2411             t0.setValue( 10, 1, "error" );
2412             t0.setValue( 10, 1, "110" );
2413             t0.setValue( 9, 1, "19" );
2414             t0.setValue( 1, 10, "101" );
2415             t0.setValue( 10, 10, "1010" );
2416             t0.setValue( 100, 10, "10100" );
2417             t0.setValue( 0, 0, "00" );
2418             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2419                 return false;
2420             }
2421             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2422                 return false;
2423             }
2424             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2425                 return false;
2426             }
2427             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2428                 return false;
2429             }
2430             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2431                 return false;
2432             }
2433             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2434                 return false;
2435             }
2436             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2437                 return false;
2438             }
2439             if ( t0.getNumberOfColumns() != 101 ) {
2440                 return false;
2441             }
2442             if ( t0.getNumberOfRows() != 11 ) {
2443                 return false;
2444             }
2445             if ( t0.getValueAsString( 49, 4 ) != null ) {
2446                 return false;
2447             }
2448             final String l = ForesterUtil.getLineSeparator();
2449             final StringBuffer source = new StringBuffer();
2450             source.append( "" + l );
2451             source.append( "# 1 1 1 1 1 1 1 1" + l );
2452             source.append( " 00 01 02 03" + l );
2453             source.append( "   10 11 12 13  " + l );
2454             source.append( "20 21 22 23 " + l );
2455             source.append( "    30  31    32 33" + l );
2456             source.append( "40 41 42 43" + l );
2457             source.append( "  # 1 1 1 1 1 " + l );
2458             source.append( "50 51 52 53 54" + l );
2459             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2460             if ( t1.getNumberOfColumns() != 5 ) {
2461                 return false;
2462             }
2463             if ( t1.getNumberOfRows() != 6 ) {
2464                 return false;
2465             }
2466             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2467                 return false;
2468             }
2469             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2470                 return false;
2471             }
2472             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2473                 return false;
2474             }
2475             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2476                 return false;
2477             }
2478             final StringBuffer source1 = new StringBuffer();
2479             source1.append( "" + l );
2480             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2481             source1.append( " 00; 01 ;02;03" + l );
2482             source1.append( "   10; 11; 12; 13  " + l );
2483             source1.append( "20; 21; 22; 23 " + l );
2484             source1.append( "    30;  31;    32; 33" + l );
2485             source1.append( "40;41;42;43" + l );
2486             source1.append( "  # 1 1 1 1 1 " + l );
2487             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2488             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2489             if ( t2.getNumberOfColumns() != 5 ) {
2490                 return false;
2491             }
2492             if ( t2.getNumberOfRows() != 6 ) {
2493                 return false;
2494             }
2495             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2496                 return false;
2497             }
2498             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2499                 return false;
2500             }
2501             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2502                 return false;
2503             }
2504             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2505                 return false;
2506             }
2507             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2508                 return false;
2509             }
2510             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2511                 return false;
2512             }
2513             final StringBuffer source2 = new StringBuffer();
2514             source2.append( "" + l );
2515             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2516             source2.append( " 00; 01 ;02;03" + l );
2517             source2.append( "   10; 11; 12; 13  " + l );
2518             source2.append( "20; 21; 22; 23 " + l );
2519             source2.append( "                     " + l );
2520             source2.append( "    30;  31;    32; 33" + l );
2521             source2.append( "40;41;42;43" + l );
2522             source2.append( "  comment: 1 1 1 1 1 " + l );
2523             source2.append( ";;;50  ;   52; 53;;54   " + l );
2524             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2525                                                                         ';',
2526                                                                         false,
2527                                                                         false,
2528                                                                         "comment:",
2529                                                                         false );
2530             if ( tl.size() != 2 ) {
2531                 return false;
2532             }
2533             final BasicTable<String> t3 = tl.get( 0 );
2534             final BasicTable<String> t4 = tl.get( 1 );
2535             if ( t3.getNumberOfColumns() != 4 ) {
2536                 return false;
2537             }
2538             if ( t3.getNumberOfRows() != 3 ) {
2539                 return false;
2540             }
2541             if ( t4.getNumberOfColumns() != 4 ) {
2542                 return false;
2543             }
2544             if ( t4.getNumberOfRows() != 3 ) {
2545                 return false;
2546             }
2547             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2548                 return false;
2549             }
2550             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2551                 return false;
2552             }
2553         }
2554         catch ( final Exception e ) {
2555             e.printStackTrace( System.out );
2556             return false;
2557         }
2558         return true;
2559     }
2560
2561     private static boolean testBasicTolXMLparsing() {
2562         try {
2563             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2564             final TolParser parser = new TolParser();
2565             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2566             if ( parser.getErrorCount() > 0 ) {
2567                 System.out.println( parser.getErrorMessages().toString() );
2568                 return false;
2569             }
2570             if ( phylogenies_0.length != 1 ) {
2571                 return false;
2572             }
2573             final Phylogeny t1 = phylogenies_0[ 0 ];
2574             if ( t1.getNumberOfExternalNodes() != 5 ) {
2575                 return false;
2576             }
2577             if ( !t1.isRooted() ) {
2578                 return false;
2579             }
2580             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2581                 return false;
2582             }
2583             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2584                 return false;
2585             }
2586             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2587                 return false;
2588             }
2589             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2590                 return false;
2591             }
2592             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2593             if ( parser.getErrorCount() > 0 ) {
2594                 System.out.println( parser.getErrorMessages().toString() );
2595                 return false;
2596             }
2597             if ( phylogenies_1.length != 1 ) {
2598                 return false;
2599             }
2600             final Phylogeny t2 = phylogenies_1[ 0 ];
2601             if ( t2.getNumberOfExternalNodes() != 664 ) {
2602                 return false;
2603             }
2604             if ( !t2.isRooted() ) {
2605                 return false;
2606             }
2607             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2608                 return false;
2609             }
2610             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2611                 return false;
2612             }
2613             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2614                 return false;
2615             }
2616             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2617                 return false;
2618             }
2619             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2620                 return false;
2621             }
2622             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2623                     .equals( "Aquifex" ) ) {
2624                 return false;
2625             }
2626             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2627             if ( parser.getErrorCount() > 0 ) {
2628                 System.out.println( parser.getErrorMessages().toString() );
2629                 return false;
2630             }
2631             if ( phylogenies_2.length != 1 ) {
2632                 return false;
2633             }
2634             final Phylogeny t3 = phylogenies_2[ 0 ];
2635             if ( t3.getNumberOfExternalNodes() != 184 ) {
2636                 return false;
2637             }
2638             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2639                 return false;
2640             }
2641             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2642                 return false;
2643             }
2644             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2645                 return false;
2646             }
2647             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2648             if ( parser.getErrorCount() > 0 ) {
2649                 System.out.println( parser.getErrorMessages().toString() );
2650                 return false;
2651             }
2652             if ( phylogenies_3.length != 1 ) {
2653                 return false;
2654             }
2655             final Phylogeny t4 = phylogenies_3[ 0 ];
2656             if ( t4.getNumberOfExternalNodes() != 1 ) {
2657                 return false;
2658             }
2659             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2660                 return false;
2661             }
2662             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2663                 return false;
2664             }
2665             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2666                 return false;
2667             }
2668             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2669             if ( parser.getErrorCount() > 0 ) {
2670                 System.out.println( parser.getErrorMessages().toString() );
2671                 return false;
2672             }
2673             if ( phylogenies_4.length != 1 ) {
2674                 return false;
2675             }
2676             final Phylogeny t5 = phylogenies_4[ 0 ];
2677             if ( t5.getNumberOfExternalNodes() != 13 ) {
2678                 return false;
2679             }
2680             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2681                 return false;
2682             }
2683             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2684                 return false;
2685             }
2686             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2687                 return false;
2688             }
2689         }
2690         catch ( final Exception e ) {
2691             e.printStackTrace( System.out );
2692             return false;
2693         }
2694         return true;
2695     }
2696
2697     private static boolean testBasicTreeMethods() {
2698         try {
2699             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2700             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2701             if ( t2.getNumberOfExternalNodes() != 4 ) {
2702                 return false;
2703             }
2704             if ( t2.getHeight() != 8.5 ) {
2705                 return false;
2706             }
2707             if ( !t2.isCompletelyBinary() ) {
2708                 return false;
2709             }
2710             if ( t2.isEmpty() ) {
2711                 return false;
2712             }
2713             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2714             if ( t3.getNumberOfExternalNodes() != 5 ) {
2715                 return false;
2716             }
2717             if ( t3.getHeight() != 11 ) {
2718                 return false;
2719             }
2720             if ( t3.isCompletelyBinary() ) {
2721                 return false;
2722             }
2723             final PhylogenyNode n = t3.getNode( "ABC" );
2724             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 ];
2725             if ( t4.getNumberOfExternalNodes() != 9 ) {
2726                 return false;
2727             }
2728             if ( t4.getHeight() != 11 ) {
2729                 return false;
2730             }
2731             if ( t4.isCompletelyBinary() ) {
2732                 return false;
2733             }
2734             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)" );
2735             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2736             if ( t5.getNumberOfExternalNodes() != 8 ) {
2737                 return false;
2738             }
2739             if ( t5.getHeight() != 15 ) {
2740                 return false;
2741             }
2742             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)" );
2743             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2744             if ( t6.getHeight() != 15 ) {
2745                 return false;
2746             }
2747             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)" );
2748             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2749             if ( t7.getHeight() != 15 ) {
2750                 return false;
2751             }
2752             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)" );
2753             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2754             if ( t8.getNumberOfExternalNodes() != 10 ) {
2755                 return false;
2756             }
2757             if ( t8.getHeight() != 15 ) {
2758                 return false;
2759             }
2760             final char[] a9 = new char[] { 'a' };
2761             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2762             if ( t9.getHeight() != 0 ) {
2763                 return false;
2764             }
2765             final char[] a10 = new char[] { 'a', ':', '6' };
2766             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2767             if ( t10.getHeight() != 6 ) {
2768                 return false;
2769             }
2770         }
2771         catch ( final Exception e ) {
2772             e.printStackTrace( System.out );
2773             return false;
2774         }
2775         return true;
2776     }
2777
2778     private static boolean testConfidenceAssessor() {
2779         try {
2780             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2781             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2782             final Phylogeny[] ev0 = factory
2783                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2784                              new NHXParser() );
2785             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2786             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2787                 return false;
2788             }
2789             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2790                 return false;
2791             }
2792             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2793             final Phylogeny[] ev1 = factory
2794                     .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)));",
2795                              new NHXParser() );
2796             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2797             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2798                 return false;
2799             }
2800             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2801                 return false;
2802             }
2803             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2804             final Phylogeny[] ev_b = factory
2805                     .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",
2806                              new NHXParser() );
2807             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2808             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2809                 return false;
2810             }
2811             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2812                 return false;
2813             }
2814             //
2815             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2816             final Phylogeny[] ev1x = factory
2817                     .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)));",
2818                              new NHXParser() );
2819             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2820             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2821                 return false;
2822             }
2823             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2824                 return false;
2825             }
2826             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2827             final Phylogeny[] ev_bx = factory
2828                     .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",
2829                              new NHXParser() );
2830             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2831             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2832                 return false;
2833             }
2834             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2835                 return false;
2836             }
2837             //
2838             final Phylogeny[] t2 = factory
2839                     .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);",
2840                              new NHXParser() );
2841             final Phylogeny[] ev2 = factory
2842                     .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);",
2843                              new NHXParser() );
2844             for( final Phylogeny target : t2 ) {
2845                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2846             }
2847             //
2848             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2849                                                  new NHXParser() )[ 0 ];
2850             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2851             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2852             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2853                 return false;
2854             }
2855             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2856                 return false;
2857             }
2858             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2859                 return false;
2860             }
2861         }
2862         catch ( final Exception e ) {
2863             e.printStackTrace();
2864             return false;
2865         }
2866         return true;
2867     }
2868
2869     private static boolean testCopyOfNodeData() {
2870         try {
2871             final PhylogenyNode n1 = PhylogenyNode
2872                     .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]" );
2873             final PhylogenyNode n2 = n1.copyNodeData();
2874             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2875                 return false;
2876             }
2877         }
2878         catch ( final Exception e ) {
2879             e.printStackTrace();
2880             return false;
2881         }
2882         return true;
2883     }
2884
2885     private static boolean testCreateBalancedPhylogeny() {
2886         try {
2887             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2888             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2889                 return false;
2890             }
2891             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2892                 return false;
2893             }
2894             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2895             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2896                 return false;
2897             }
2898             if ( p1.getNumberOfExternalNodes() != 100 ) {
2899                 return false;
2900             }
2901         }
2902         catch ( final Exception e ) {
2903             e.printStackTrace();
2904             return false;
2905         }
2906         return true;
2907     }
2908
2909     private static boolean testCreateUriForSeqWeb() {
2910         try {
2911             final PhylogenyNode n = new PhylogenyNode();
2912             n.setName( "tr|B3RJ64" );
2913             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2914                 return false;
2915             }
2916             n.setName( "B0LM41_HUMAN" );
2917             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2918                 return false;
2919             }
2920             n.setName( "NP_001025424" );
2921             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2922                 return false;
2923             }
2924             n.setName( "_NM_001030253-" );
2925             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2926                 return false;
2927             }
2928             n.setName( "XM_002122186" );
2929             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2930                 return false;
2931             }
2932             n.setName( "dgh_AAA34956_gdg" );
2933             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2934                 return false;
2935             }
2936             n.setName( "AAA34956" );
2937             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2938                 return false;
2939             }
2940             n.setName( "GI:394892" );
2941             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2942                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2943                 return false;
2944             }
2945             n.setName( "gi_394892" );
2946             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2947                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2948                 return false;
2949             }
2950             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2951             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2952                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2953                 return false;
2954             }
2955             n.setName( "P12345" );
2956             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2957                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2958                 return false;
2959             }
2960             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
2961             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2962                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2963                 return false;
2964             }
2965         }
2966         catch ( final Exception e ) {
2967             e.printStackTrace( System.out );
2968             return false;
2969         }
2970         return true;
2971     }
2972
2973     private static boolean testDataObjects() {
2974         try {
2975             final Confidence s0 = new Confidence();
2976             final Confidence s1 = new Confidence();
2977             if ( !s0.isEqual( s1 ) ) {
2978                 return false;
2979             }
2980             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2981             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2982             if ( s2.isEqual( s1 ) ) {
2983                 return false;
2984             }
2985             if ( !s2.isEqual( s3 ) ) {
2986                 return false;
2987             }
2988             final Confidence s4 = ( Confidence ) s3.copy();
2989             if ( !s4.isEqual( s3 ) ) {
2990                 return false;
2991             }
2992             s3.asSimpleText();
2993             s3.asText();
2994             // Taxonomy
2995             // ----------
2996             final Taxonomy t1 = new Taxonomy();
2997             final Taxonomy t2 = new Taxonomy();
2998             final Taxonomy t3 = new Taxonomy();
2999             final Taxonomy t4 = new Taxonomy();
3000             final Taxonomy t5 = new Taxonomy();
3001             t1.setIdentifier( new Identifier( "ecoli" ) );
3002             t1.setTaxonomyCode( "ECOLI" );
3003             t1.setScientificName( "E. coli" );
3004             t1.setCommonName( "coli" );
3005             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3006             if ( !t1.isEqual( t0 ) ) {
3007                 return false;
3008             }
3009             t2.setIdentifier( new Identifier( "ecoli" ) );
3010             t2.setTaxonomyCode( "OTHER" );
3011             t2.setScientificName( "what" );
3012             t2.setCommonName( "something" );
3013             if ( !t1.isEqual( t2 ) ) {
3014                 return false;
3015             }
3016             t2.setIdentifier( new Identifier( "nemve" ) );
3017             if ( t1.isEqual( t2 ) ) {
3018                 return false;
3019             }
3020             t1.setIdentifier( null );
3021             t3.setTaxonomyCode( "ECOLI" );
3022             t3.setScientificName( "what" );
3023             t3.setCommonName( "something" );
3024             if ( !t1.isEqual( t3 ) ) {
3025                 return false;
3026             }
3027             t1.setIdentifier( null );
3028             t1.setTaxonomyCode( "" );
3029             t4.setScientificName( "E. ColI" );
3030             t4.setCommonName( "something" );
3031             if ( !t1.isEqual( t4 ) ) {
3032                 return false;
3033             }
3034             t4.setScientificName( "B. subtilis" );
3035             t4.setCommonName( "something" );
3036             if ( t1.isEqual( t4 ) ) {
3037                 return false;
3038             }
3039             t1.setIdentifier( null );
3040             t1.setTaxonomyCode( "" );
3041             t1.setScientificName( "" );
3042             t5.setCommonName( "COLI" );
3043             if ( !t1.isEqual( t5 ) ) {
3044                 return false;
3045             }
3046             t5.setCommonName( "vibrio" );
3047             if ( t1.isEqual( t5 ) ) {
3048                 return false;
3049             }
3050             // Identifier
3051             // ----------
3052             final Identifier id0 = new Identifier( "123", "pfam" );
3053             final Identifier id1 = ( Identifier ) id0.copy();
3054             if ( !id1.isEqual( id1 ) ) {
3055                 return false;
3056             }
3057             if ( !id1.isEqual( id0 ) ) {
3058                 return false;
3059             }
3060             if ( !id0.isEqual( id1 ) ) {
3061                 return false;
3062             }
3063             id1.asSimpleText();
3064             id1.asText();
3065             // ProteinDomain
3066             // ---------------
3067             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3068             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3069             if ( !pd1.isEqual( pd1 ) ) {
3070                 return false;
3071             }
3072             if ( !pd1.isEqual( pd0 ) ) {
3073                 return false;
3074             }
3075             pd1.asSimpleText();
3076             pd1.asText();
3077             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3078             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3079             if ( !pd3.isEqual( pd3 ) ) {
3080                 return false;
3081             }
3082             if ( !pd2.isEqual( pd3 ) ) {
3083                 return false;
3084             }
3085             if ( !pd0.isEqual( pd3 ) ) {
3086                 return false;
3087             }
3088             pd3.asSimpleText();
3089             pd3.asText();
3090             // DomainArchitecture
3091             // ------------------
3092             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3093             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3094             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3095             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3096             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3097             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3098             domains0.add( d2 );
3099             domains0.add( d0 );
3100             domains0.add( d3 );
3101             domains0.add( d1 );
3102             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3103             if ( ds0.getNumberOfDomains() != 4 ) {
3104                 return false;
3105             }
3106             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3107             if ( !ds0.isEqual( ds0 ) ) {
3108                 return false;
3109             }
3110             if ( !ds0.isEqual( ds1 ) ) {
3111                 return false;
3112             }
3113             if ( ds1.getNumberOfDomains() != 4 ) {
3114                 return false;
3115             }
3116             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3117             domains1.add( d1 );
3118             domains1.add( d2 );
3119             domains1.add( d4 );
3120             domains1.add( d0 );
3121             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3122             if ( ds0.isEqual( ds2 ) ) {
3123                 return false;
3124             }
3125             ds1.asSimpleText();
3126             ds1.asText();
3127             ds1.toNHX();
3128             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3129             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3130                 System.out.println( ds3.toNHX() );
3131                 return false;
3132             }
3133             if ( ds3.getNumberOfDomains() != 3 ) {
3134                 return false;
3135             }
3136             // Event
3137             // -----
3138             final Event e1 = new Event( Event.EventType.fusion );
3139             if ( e1.isDuplication() ) {
3140                 return false;
3141             }
3142             if ( !e1.isFusion() ) {
3143                 return false;
3144             }
3145             if ( !e1.asText().toString().equals( "fusion" ) ) {
3146                 return false;
3147             }
3148             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3149                 return false;
3150             }
3151             final Event e11 = new Event( Event.EventType.fusion );
3152             if ( !e11.isEqual( e1 ) ) {
3153                 return false;
3154             }
3155             if ( !e11.toNHX().toString().equals( "" ) ) {
3156                 return false;
3157             }
3158             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3159             if ( e2.isDuplication() ) {
3160                 return false;
3161             }
3162             if ( !e2.isSpeciationOrDuplication() ) {
3163                 return false;
3164             }
3165             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3166                 return false;
3167             }
3168             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3169                 return false;
3170             }
3171             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3172                 return false;
3173             }
3174             if ( e11.isEqual( e2 ) ) {
3175                 return false;
3176             }
3177             final Event e2c = ( Event ) e2.copy();
3178             if ( !e2c.isEqual( e2 ) ) {
3179                 return false;
3180             }
3181             Event e3 = new Event( 1, 2, 3 );
3182             if ( e3.isDuplication() ) {
3183                 return false;
3184             }
3185             if ( e3.isSpeciation() ) {
3186                 return false;
3187             }
3188             if ( e3.isGeneLoss() ) {
3189                 return false;
3190             }
3191             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3192                 return false;
3193             }
3194             final Event e3c = ( Event ) e3.copy();
3195             final Event e3cc = ( Event ) e3c.copy();
3196             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3197                 return false;
3198             }
3199             e3 = null;
3200             if ( !e3c.isEqual( e3cc ) ) {
3201                 return false;
3202             }
3203             Event e4 = new Event( 1, 2, 3 );
3204             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3205                 return false;
3206             }
3207             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3208                 return false;
3209             }
3210             final Event e4c = ( Event ) e4.copy();
3211             e4 = null;
3212             final Event e4cc = ( Event ) e4c.copy();
3213             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3214                 return false;
3215             }
3216             if ( !e4c.isEqual( e4cc ) ) {
3217                 return false;
3218             }
3219             final Event e5 = new Event();
3220             if ( !e5.isUnassigned() ) {
3221                 return false;
3222             }
3223             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3224                 return false;
3225             }
3226             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3227                 return false;
3228             }
3229             final Event e6 = new Event( 1, 0, 0 );
3230             if ( !e6.asText().toString().equals( "duplication" ) ) {
3231                 return false;
3232             }
3233             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3234                 return false;
3235             }
3236             final Event e7 = new Event( 0, 1, 0 );
3237             if ( !e7.asText().toString().equals( "speciation" ) ) {
3238                 return false;
3239             }
3240             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3241                 return false;
3242             }
3243             final Event e8 = new Event( 0, 0, 1 );
3244             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3245                 return false;
3246             }
3247             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3248                 return false;
3249             }
3250         }
3251         catch ( final Exception e ) {
3252             e.printStackTrace( System.out );
3253             return false;
3254         }
3255         return true;
3256     }
3257
3258     private static boolean testDeletionOfExternalNodes() {
3259         try {
3260             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3261             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3262             final PhylogenyWriter w = new PhylogenyWriter();
3263             if ( t0.isEmpty() ) {
3264                 return false;
3265             }
3266             if ( t0.getNumberOfExternalNodes() != 1 ) {
3267                 return false;
3268             }
3269             t0.deleteSubtree( t0.getNode( "A" ), false );
3270             if ( t0.getNumberOfExternalNodes() != 0 ) {
3271                 return false;
3272             }
3273             if ( !t0.isEmpty() ) {
3274                 return false;
3275             }
3276             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3277             if ( t1.getNumberOfExternalNodes() != 2 ) {
3278                 return false;
3279             }
3280             t1.deleteSubtree( t1.getNode( "A" ), false );
3281             if ( t1.getNumberOfExternalNodes() != 1 ) {
3282                 return false;
3283             }
3284             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3285                 return false;
3286             }
3287             t1.deleteSubtree( t1.getNode( "B" ), false );
3288             if ( t1.getNumberOfExternalNodes() != 1 ) {
3289                 return false;
3290             }
3291             t1.deleteSubtree( t1.getNode( "r" ), false );
3292             if ( !t1.isEmpty() ) {
3293                 return false;
3294             }
3295             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3296             if ( t2.getNumberOfExternalNodes() != 3 ) {
3297                 return false;
3298             }
3299             t2.deleteSubtree( t2.getNode( "B" ), false );
3300             if ( t2.getNumberOfExternalNodes() != 2 ) {
3301                 return false;
3302             }
3303             t2.toNewHampshireX();
3304             PhylogenyNode n = t2.getNode( "A" );
3305             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3306                 return false;
3307             }
3308             t2.deleteSubtree( t2.getNode( "A" ), false );
3309             if ( t2.getNumberOfExternalNodes() != 2 ) {
3310                 return false;
3311             }
3312             t2.deleteSubtree( t2.getNode( "C" ), true );
3313             if ( t2.getNumberOfExternalNodes() != 1 ) {
3314                 return false;
3315             }
3316             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3317             if ( t3.getNumberOfExternalNodes() != 4 ) {
3318                 return false;
3319             }
3320             t3.deleteSubtree( t3.getNode( "B" ), true );
3321             if ( t3.getNumberOfExternalNodes() != 3 ) {
3322                 return false;
3323             }
3324             n = t3.getNode( "A" );
3325             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3326                 return false;
3327             }
3328             n = n.getNextExternalNode();
3329             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3330                 return false;
3331             }
3332             t3.deleteSubtree( t3.getNode( "A" ), true );
3333             if ( t3.getNumberOfExternalNodes() != 2 ) {
3334                 return false;
3335             }
3336             n = t3.getNode( "C" );
3337             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3338                 return false;
3339             }
3340             t3.deleteSubtree( t3.getNode( "C" ), true );
3341             if ( t3.getNumberOfExternalNodes() != 1 ) {
3342                 return false;
3343             }
3344             t3.deleteSubtree( t3.getNode( "D" ), true );
3345             if ( t3.getNumberOfExternalNodes() != 0 ) {
3346                 return false;
3347             }
3348             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3349             if ( t4.getNumberOfExternalNodes() != 6 ) {
3350                 return false;
3351             }
3352             t4.deleteSubtree( t4.getNode( "B2" ), true );
3353             if ( t4.getNumberOfExternalNodes() != 5 ) {
3354                 return false;
3355             }
3356             String s = w.toNewHampshire( t4, false, true ).toString();
3357             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3358                 return false;
3359             }
3360             t4.deleteSubtree( t4.getNode( "B11" ), true );
3361             if ( t4.getNumberOfExternalNodes() != 4 ) {
3362                 return false;
3363             }
3364             t4.deleteSubtree( t4.getNode( "C" ), true );
3365             if ( t4.getNumberOfExternalNodes() != 3 ) {
3366                 return false;
3367             }
3368             n = t4.getNode( "A" );
3369             n = n.getNextExternalNode();
3370             if ( !n.getName().equals( "B12" ) ) {
3371                 return false;
3372             }
3373             n = n.getNextExternalNode();
3374             if ( !n.getName().equals( "D" ) ) {
3375                 return false;
3376             }
3377             s = w.toNewHampshire( t4, false, true ).toString();
3378             if ( !s.equals( "((A,B12),D);" ) ) {
3379                 return false;
3380             }
3381             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3382             t5.deleteSubtree( t5.getNode( "A" ), true );
3383             if ( t5.getNumberOfExternalNodes() != 5 ) {
3384                 return false;
3385             }
3386             s = w.toNewHampshire( t5, false, true ).toString();
3387             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3388                 return false;
3389             }
3390             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3391             t6.deleteSubtree( t6.getNode( "B11" ), true );
3392             if ( t6.getNumberOfExternalNodes() != 5 ) {
3393                 return false;
3394             }
3395             s = w.toNewHampshire( t6, false, false ).toString();
3396             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3397                 return false;
3398             }
3399             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3400             t7.deleteSubtree( t7.getNode( "B12" ), true );
3401             if ( t7.getNumberOfExternalNodes() != 5 ) {
3402                 return false;
3403             }
3404             s = w.toNewHampshire( t7, false, true ).toString();
3405             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3406                 return false;
3407             }
3408             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3409             t8.deleteSubtree( t8.getNode( "B2" ), true );
3410             if ( t8.getNumberOfExternalNodes() != 5 ) {
3411                 return false;
3412             }
3413             s = w.toNewHampshire( t8, false, false ).toString();
3414             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3415                 return false;
3416             }
3417             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3418             t9.deleteSubtree( t9.getNode( "C" ), true );
3419             if ( t9.getNumberOfExternalNodes() != 5 ) {
3420                 return false;
3421             }
3422             s = w.toNewHampshire( t9, false, true ).toString();
3423             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3424                 return false;
3425             }
3426             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3427             t10.deleteSubtree( t10.getNode( "D" ), true );
3428             if ( t10.getNumberOfExternalNodes() != 5 ) {
3429                 return false;
3430             }
3431             s = w.toNewHampshire( t10, false, true ).toString();
3432             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3433                 return false;
3434             }
3435             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3436             t11.deleteSubtree( t11.getNode( "A" ), true );
3437             if ( t11.getNumberOfExternalNodes() != 2 ) {
3438                 return false;
3439             }
3440             s = w.toNewHampshire( t11, false, true ).toString();
3441             if ( !s.equals( "(B,C);" ) ) {
3442                 return false;
3443             }
3444             t11.deleteSubtree( t11.getNode( "C" ), true );
3445             if ( t11.getNumberOfExternalNodes() != 1 ) {
3446                 return false;
3447             }
3448             s = w.toNewHampshire( t11, false, false ).toString();
3449             if ( !s.equals( "B;" ) ) {
3450                 return false;
3451             }
3452             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3453             t12.deleteSubtree( t12.getNode( "B2" ), true );
3454             if ( t12.getNumberOfExternalNodes() != 8 ) {
3455                 return false;
3456             }
3457             s = w.toNewHampshire( t12, false, true ).toString();
3458             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3459                 return false;
3460             }
3461             t12.deleteSubtree( t12.getNode( "B3" ), true );
3462             if ( t12.getNumberOfExternalNodes() != 7 ) {
3463                 return false;
3464             }
3465             s = w.toNewHampshire( t12, false, true ).toString();
3466             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3467                 return false;
3468             }
3469             t12.deleteSubtree( t12.getNode( "C3" ), true );
3470             if ( t12.getNumberOfExternalNodes() != 6 ) {
3471                 return false;
3472             }
3473             s = w.toNewHampshire( t12, false, true ).toString();
3474             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3475                 return false;
3476             }
3477             t12.deleteSubtree( t12.getNode( "A1" ), true );
3478             if ( t12.getNumberOfExternalNodes() != 5 ) {
3479                 return false;
3480             }
3481             s = w.toNewHampshire( t12, false, true ).toString();
3482             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3483                 return false;
3484             }
3485             t12.deleteSubtree( t12.getNode( "B1" ), true );
3486             if ( t12.getNumberOfExternalNodes() != 4 ) {
3487                 return false;
3488             }
3489             s = w.toNewHampshire( t12, false, true ).toString();
3490             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3491                 return false;
3492             }
3493             t12.deleteSubtree( t12.getNode( "A3" ), true );
3494             if ( t12.getNumberOfExternalNodes() != 3 ) {
3495                 return false;
3496             }
3497             s = w.toNewHampshire( t12, false, true ).toString();
3498             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3499                 return false;
3500             }
3501             t12.deleteSubtree( t12.getNode( "A2" ), true );
3502             if ( t12.getNumberOfExternalNodes() != 2 ) {
3503                 return false;
3504             }
3505             s = w.toNewHampshire( t12, false, true ).toString();
3506             if ( !s.equals( "(C1,C2);" ) ) {
3507                 return false;
3508             }
3509             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3510             t13.deleteSubtree( t13.getNode( "D" ), true );
3511             if ( t13.getNumberOfExternalNodes() != 4 ) {
3512                 return false;
3513             }
3514             s = w.toNewHampshire( t13, false, true ).toString();
3515             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3516                 return false;
3517             }
3518             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3519             t14.deleteSubtree( t14.getNode( "E" ), true );
3520             if ( t14.getNumberOfExternalNodes() != 5 ) {
3521                 return false;
3522             }
3523             s = w.toNewHampshire( t14, false, true ).toString();
3524             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3525                 return false;
3526             }
3527             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3528             t15.deleteSubtree( t15.getNode( "B2" ), true );
3529             if ( t15.getNumberOfExternalNodes() != 11 ) {
3530                 return false;
3531             }
3532             t15.deleteSubtree( t15.getNode( "B1" ), true );
3533             if ( t15.getNumberOfExternalNodes() != 10 ) {
3534                 return false;
3535             }
3536             t15.deleteSubtree( t15.getNode( "B3" ), true );
3537             if ( t15.getNumberOfExternalNodes() != 9 ) {
3538                 return false;
3539             }
3540             t15.deleteSubtree( t15.getNode( "B4" ), true );
3541             if ( t15.getNumberOfExternalNodes() != 8 ) {
3542                 return false;
3543             }
3544             t15.deleteSubtree( t15.getNode( "A1" ), true );
3545             if ( t15.getNumberOfExternalNodes() != 7 ) {
3546                 return false;
3547             }
3548             t15.deleteSubtree( t15.getNode( "C4" ), true );
3549             if ( t15.getNumberOfExternalNodes() != 6 ) {
3550                 return false;
3551             }
3552         }
3553         catch ( final Exception e ) {
3554             e.printStackTrace( System.out );
3555             return false;
3556         }
3557         return true;
3558     }
3559
3560     private static boolean testDescriptiveStatistics() {
3561         try {
3562             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3563             dss1.addValue( 82 );
3564             dss1.addValue( 78 );
3565             dss1.addValue( 70 );
3566             dss1.addValue( 58 );
3567             dss1.addValue( 42 );
3568             if ( dss1.getN() != 5 ) {
3569                 return false;
3570             }
3571             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3572                 return false;
3573             }
3574             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3575                 return false;
3576             }
3577             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3578                 return false;
3579             }
3580             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3581                 return false;
3582             }
3583             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3584                 return false;
3585             }
3586             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3587                 return false;
3588             }
3589             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3590                 return false;
3591             }
3592             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3593                 return false;
3594             }
3595             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3596                 return false;
3597             }
3598             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3599                 return false;
3600             }
3601             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3602                 return false;
3603             }
3604             dss1.addValue( 123 );
3605             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3606                 return false;
3607             }
3608             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3609                 return false;
3610             }
3611             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3612                 return false;
3613             }
3614             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3615             dss2.addValue( -1.85 );
3616             dss2.addValue( 57.5 );
3617             dss2.addValue( 92.78 );
3618             dss2.addValue( 57.78 );
3619             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3620                 return false;
3621             }
3622             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3623                 return false;
3624             }
3625             final double[] a = dss2.getDataAsDoubleArray();
3626             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3627                 return false;
3628             }
3629             dss2.addValue( -100 );
3630             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3631                 return false;
3632             }
3633             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3634                 return false;
3635             }
3636             final double[] ds = new double[ 14 ];
3637             ds[ 0 ] = 34;
3638             ds[ 1 ] = 23;
3639             ds[ 2 ] = 1;
3640             ds[ 3 ] = 32;
3641             ds[ 4 ] = 11;
3642             ds[ 5 ] = 2;
3643             ds[ 6 ] = 12;
3644             ds[ 7 ] = 33;
3645             ds[ 8 ] = 13;
3646             ds[ 9 ] = 22;
3647             ds[ 10 ] = 21;
3648             ds[ 11 ] = 35;
3649             ds[ 12 ] = 24;
3650             ds[ 13 ] = 31;
3651             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3652             if ( bins.length != 4 ) {
3653                 return false;
3654             }
3655             if ( bins[ 0 ] != 2 ) {
3656                 return false;
3657             }
3658             if ( bins[ 1 ] != 3 ) {
3659                 return false;
3660             }
3661             if ( bins[ 2 ] != 4 ) {
3662                 return false;
3663             }
3664             if ( bins[ 3 ] != 5 ) {
3665                 return false;
3666             }
3667             final double[] ds1 = new double[ 9 ];
3668             ds1[ 0 ] = 10.0;
3669             ds1[ 1 ] = 19.0;
3670             ds1[ 2 ] = 9.999;
3671             ds1[ 3 ] = 0.0;
3672             ds1[ 4 ] = 39.9;
3673             ds1[ 5 ] = 39.999;
3674             ds1[ 6 ] = 30.0;
3675             ds1[ 7 ] = 19.999;
3676             ds1[ 8 ] = 30.1;
3677             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3678             if ( bins1.length != 4 ) {
3679                 return false;
3680             }
3681             if ( bins1[ 0 ] != 2 ) {
3682                 return false;
3683             }
3684             if ( bins1[ 1 ] != 3 ) {
3685                 return false;
3686             }
3687             if ( bins1[ 2 ] != 0 ) {
3688                 return false;
3689             }
3690             if ( bins1[ 3 ] != 4 ) {
3691                 return false;
3692             }
3693             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3694             if ( bins1_1.length != 3 ) {
3695                 return false;
3696             }
3697             if ( bins1_1[ 0 ] != 3 ) {
3698                 return false;
3699             }
3700             if ( bins1_1[ 1 ] != 2 ) {
3701                 return false;
3702             }
3703             if ( bins1_1[ 2 ] != 4 ) {
3704                 return false;
3705             }
3706             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3707             if ( bins1_2.length != 3 ) {
3708                 return false;
3709             }
3710             if ( bins1_2[ 0 ] != 2 ) {
3711                 return false;
3712             }
3713             if ( bins1_2[ 1 ] != 2 ) {
3714                 return false;
3715             }
3716             if ( bins1_2[ 2 ] != 2 ) {
3717                 return false;
3718             }
3719             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3720             dss3.addValue( 1 );
3721             dss3.addValue( 1 );
3722             dss3.addValue( 1 );
3723             dss3.addValue( 2 );
3724             dss3.addValue( 3 );
3725             dss3.addValue( 4 );
3726             dss3.addValue( 5 );
3727             dss3.addValue( 5 );
3728             dss3.addValue( 5 );
3729             dss3.addValue( 6 );
3730             dss3.addValue( 7 );
3731             dss3.addValue( 8 );
3732             dss3.addValue( 9 );
3733             dss3.addValue( 10 );
3734             dss3.addValue( 10 );
3735             dss3.addValue( 10 );
3736             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3737             histo.toStringBuffer( 10, '=', 40, 5 );
3738             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3739         }
3740         catch ( final Exception e ) {
3741             e.printStackTrace( System.out );
3742             return false;
3743         }
3744         return true;
3745     }
3746
3747     private static boolean testDir( final String file ) {
3748         try {
3749             final File f = new File( file );
3750             if ( !f.exists() ) {
3751                 return false;
3752             }
3753             if ( !f.isDirectory() ) {
3754                 return false;
3755             }
3756             if ( !f.canRead() ) {
3757                 return false;
3758             }
3759         }
3760         catch ( final Exception e ) {
3761             return false;
3762         }
3763         return true;
3764     }
3765
3766     private static boolean testEbiEntryRetrieval() {
3767         try {
3768             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3769             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3770                 System.out.println( entry.getAccession() );
3771                 return false;
3772             }
3773             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3774                 System.out.println( entry.getTaxonomyScientificName() );
3775                 return false;
3776             }
3777             if ( !entry.getSequenceName()
3778                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3779                 System.out.println( entry.getSequenceName() );
3780                 return false;
3781             }
3782             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3783             //     System.out.println( entry.getSequenceSymbol() );
3784             //     return false;
3785             // }
3786             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3787                 System.out.println( entry.getGeneName() );
3788                 return false;
3789             }
3790             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3791                 System.out.println( entry.getTaxonomyIdentifier() );
3792                 return false;
3793             }
3794             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3795                 System.out.println( entry.getAnnotations().first().getRefValue() );
3796                 return false;
3797             }
3798             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3799                 System.out.println( entry.getAnnotations().first().getRefSource() );
3800                 return false;
3801             }
3802             if ( entry.getCrossReferences().size() != 5 ) {
3803                 return false;
3804             }
3805             //
3806             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3807             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3808                 return false;
3809             }
3810             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3811                 System.out.println( entry1.getTaxonomyScientificName() );
3812                 return false;
3813             }
3814             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3815                 System.out.println( entry1.getSequenceName() );
3816                 return false;
3817             }
3818             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3819                 System.out.println( entry1.getTaxonomyIdentifier() );
3820                 return false;
3821             }
3822             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3823                 System.out.println( entry1.getGeneName() );
3824                 return false;
3825             }
3826             if ( entry1.getCrossReferences().size() != 6 ) {
3827                 return false;
3828             }
3829             //
3830             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3831             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3832                 return false;
3833             }
3834             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3835                 System.out.println( entry2.getTaxonomyScientificName() );
3836                 return false;
3837             }
3838             if ( !entry2.getSequenceName()
3839                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3840                 System.out.println( entry2.getSequenceName() );
3841                 return false;
3842             }
3843             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3844                 System.out.println( entry2.getTaxonomyIdentifier() );
3845                 return false;
3846             }
3847             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3848                 System.out.println( entry2.getGeneName() );
3849                 return false;
3850             }
3851             if ( entry2.getCrossReferences().size() != 3 ) {
3852                 return false;
3853             }
3854             //
3855             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3856             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3857                 return false;
3858             }
3859             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3860                 System.out.println( entry3.getTaxonomyScientificName() );
3861                 return false;
3862             }
3863             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3864                 System.out.println( entry3.getSequenceName() );
3865                 return false;
3866             }
3867             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3868                 System.out.println( entry3.getTaxonomyIdentifier() );
3869                 return false;
3870             }
3871             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3872                 System.out.println( entry3.getSequenceSymbol() );
3873                 return false;
3874             }
3875             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
3876                 return false;
3877             }
3878             if ( entry3.getCrossReferences().size() != 8 ) {
3879                 return false;
3880             }
3881             //
3882             //
3883             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
3884             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
3885                 return false;
3886             }
3887             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3888                 System.out.println( entry4.getTaxonomyScientificName() );
3889                 return false;
3890             }
3891             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
3892                 System.out.println( entry4.getSequenceName() );
3893                 return false;
3894             }
3895             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
3896                 System.out.println( entry4.getTaxonomyIdentifier() );
3897                 return false;
3898             }
3899             if ( !entry4.getGeneName().equals( "ras" ) ) {
3900                 System.out.println( entry4.getGeneName() );
3901                 return false;
3902             }
3903             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
3904             //     System.out.println( entry4.getChromosome() );
3905             //     return false;
3906             // }
3907             // if ( !entry4.getMap().equals( "ras" ) ) {
3908             //     System.out.println( entry4.getMap() );
3909             //     return false;
3910             // }
3911             //TODO FIXME gi...
3912             //
3913             //TODO fails:
3914             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
3915             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
3916             //                return false;
3917             //            }
3918             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
3919             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
3920                 return false;
3921             }
3922             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
3923                 System.out.println( entry5.getTaxonomyScientificName() );
3924                 return false;
3925             }
3926             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
3927                 System.out.println( entry5.getSequenceName() );
3928                 return false;
3929             }
3930             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
3931                 System.out.println( entry5.getTaxonomyIdentifier() );
3932                 return false;
3933             }
3934         }
3935         catch ( final IOException e ) {
3936             System.out.println();
3937             System.out.println( "the following might be due to absence internet connection:" );
3938             e.printStackTrace( System.out );
3939             return true;
3940         }
3941         catch ( final Exception e ) {
3942             e.printStackTrace();
3943             return false;
3944         }
3945         return true;
3946     }
3947
3948     private static boolean testExternalNodeRelatedMethods() {
3949         try {
3950             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3951             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3952             PhylogenyNode n = t1.getNode( "A" );
3953             n = n.getNextExternalNode();
3954             if ( !n.getName().equals( "B" ) ) {
3955                 return false;
3956             }
3957             n = n.getNextExternalNode();
3958             if ( !n.getName().equals( "C" ) ) {
3959                 return false;
3960             }
3961             n = n.getNextExternalNode();
3962             if ( !n.getName().equals( "D" ) ) {
3963                 return false;
3964             }
3965             n = t1.getNode( "B" );
3966             while ( !n.isLastExternalNode() ) {
3967                 n = n.getNextExternalNode();
3968             }
3969             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3970             n = t2.getNode( "A" );
3971             n = n.getNextExternalNode();
3972             if ( !n.getName().equals( "B" ) ) {
3973                 return false;
3974             }
3975             n = n.getNextExternalNode();
3976             if ( !n.getName().equals( "C" ) ) {
3977                 return false;
3978             }
3979             n = n.getNextExternalNode();
3980             if ( !n.getName().equals( "D" ) ) {
3981                 return false;
3982             }
3983             n = t2.getNode( "B" );
3984             while ( !n.isLastExternalNode() ) {
3985                 n = n.getNextExternalNode();
3986             }
3987             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3988             n = t3.getNode( "A" );
3989             n = n.getNextExternalNode();
3990             if ( !n.getName().equals( "B" ) ) {
3991                 return false;
3992             }
3993             n = n.getNextExternalNode();
3994             if ( !n.getName().equals( "C" ) ) {
3995                 return false;
3996             }
3997             n = n.getNextExternalNode();
3998             if ( !n.getName().equals( "D" ) ) {
3999                 return false;
4000             }
4001             n = n.getNextExternalNode();
4002             if ( !n.getName().equals( "E" ) ) {
4003                 return false;
4004             }
4005             n = n.getNextExternalNode();
4006             if ( !n.getName().equals( "F" ) ) {
4007                 return false;
4008             }
4009             n = n.getNextExternalNode();
4010             if ( !n.getName().equals( "G" ) ) {
4011                 return false;
4012             }
4013             n = n.getNextExternalNode();
4014             if ( !n.getName().equals( "H" ) ) {
4015                 return false;
4016             }
4017             n = t3.getNode( "B" );
4018             while ( !n.isLastExternalNode() ) {
4019                 n = n.getNextExternalNode();
4020             }
4021             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4022             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4023                 final PhylogenyNode node = iter.next();
4024             }
4025             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4026             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4027                 final PhylogenyNode node = iter.next();
4028             }
4029             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4030             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4031             if ( !iter.next().getName().equals( "A" ) ) {
4032                 return false;
4033             }
4034             if ( !iter.next().getName().equals( "B" ) ) {
4035                 return false;
4036             }
4037             if ( !iter.next().getName().equals( "C" ) ) {
4038                 return false;
4039             }
4040             if ( !iter.next().getName().equals( "D" ) ) {
4041                 return false;
4042             }
4043             if ( !iter.next().getName().equals( "E" ) ) {
4044                 return false;
4045             }
4046             if ( !iter.next().getName().equals( "F" ) ) {
4047                 return false;
4048             }
4049             if ( iter.hasNext() ) {
4050                 return false;
4051             }
4052         }
4053         catch ( final Exception e ) {
4054             e.printStackTrace( System.out );
4055             return false;
4056         }
4057         return true;
4058     }
4059
4060     private static boolean testExtractSNFromNodeName() {
4061         try {
4062             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4063                 return false;
4064             }
4065             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
4066                     .equals( "Mus musculus musculus" ) ) {
4067                 return false;
4068             }
4069             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
4070                     .equals( "Mus musculus musculus" ) ) {
4071                 return false;
4072             }
4073             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
4074                 return false;
4075             }
4076             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
4077                     .equals( "Mus musculus" ) ) {
4078                 return false;
4079             }
4080         }
4081         catch ( final Exception e ) {
4082             e.printStackTrace( System.out );
4083             return false;
4084         }
4085         return true;
4086     }
4087
4088     private static boolean testExtractTaxonomyCodeFromNodeName() {
4089         try {
4090             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4091                 return false;
4092             }
4093             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4094                     .equals( "SOYBN" ) ) {
4095                 return false;
4096             }
4097             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4098                     .equals( "ARATH" ) ) {
4099                 return false;
4100             }
4101             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4102                     .equals( "ARATH" ) ) {
4103                 return false;
4104             }
4105             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4106                 return false;
4107             }
4108             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4109                 return false;
4110             }
4111             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4112                 return false;
4113             }
4114             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4115                     .equals( "SOYBN" ) ) {
4116                 return false;
4117             }
4118             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4119                     .equals( "SOYBN" ) ) {
4120                 return false;
4121             }
4122             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4123                     .equals( "SOYBN" ) ) {
4124                 return false;
4125             }
4126             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4127                     .equals( "SOYBN" ) ) {
4128                 return false;
4129             }
4130             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4131                     .equals( "SOYBN" ) ) {
4132                 return false;
4133             }
4134             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4135                     .equals( "SOYBN" ) ) {
4136                 return false;
4137             }
4138             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4139                     .equals( "SOYBN" ) ) {
4140                 return false;
4141             }
4142             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4143                     .equals( "SOYBN" ) ) {
4144                 return false;
4145             }
4146             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4147                 return false;
4148             }
4149             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4150                     .equals( "SOYBN" ) ) {
4151                 return false;
4152             }
4153             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4154                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4155                 return false;
4156             }
4157             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4158                     .equals( "9YX45" ) ) {
4159                 return false;
4160             }
4161             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4162                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4163                     .equals( "MOUSE" ) ) {
4164                 return false;
4165             }
4166             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4167                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4168                     .equals( "MOUSE" ) ) {
4169                 return false;
4170             }
4171             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4172                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4173                     .equals( "MOUSE" ) ) {
4174                 return false;
4175             }
4176             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4177                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4178                 return false;
4179             }
4180             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4181                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4182                 return false;
4183             }
4184             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4185                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4186                 return false;
4187             }
4188             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4189                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4190                 return false;
4191             }
4192             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4193                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4194                 return false;
4195             }
4196             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4197                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4198                 return false;
4199             }
4200             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4201                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4202                 return false;
4203             }
4204             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4205                     .equals( "RAT" ) ) {
4206                 return false;
4207             }
4208             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4209                     .equals( "PIG" ) ) {
4210                 return false;
4211             }
4212             if ( !ParserUtils
4213                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4214                     .equals( "MOUSE" ) ) {
4215                 return false;
4216             }
4217             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4218                     .equals( "MOUSE" ) ) {
4219                 return false;
4220             }
4221             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4222                 return false;
4223             }
4224         }
4225         catch ( final Exception e ) {
4226             e.printStackTrace( System.out );
4227             return false;
4228         }
4229         return true;
4230     }
4231
4232     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4233         try {
4234             PhylogenyNode n = new PhylogenyNode();
4235             n.setName( "tr|B3RJ64" );
4236             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4237                 return false;
4238             }
4239             n.setName( "tr.B3RJ64" );
4240             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4241                 return false;
4242             }
4243             n.setName( "tr=B3RJ64" );
4244             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4245                 return false;
4246             }
4247             n.setName( "tr-B3RJ64" );
4248             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4249                 return false;
4250             }
4251             n.setName( "tr/B3RJ64" );
4252             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4253                 return false;
4254             }
4255             n.setName( "tr\\B3RJ64" );
4256             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4257                 return false;
4258             }
4259             n.setName( "tr_B3RJ64" );
4260             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4261                 return false;
4262             }
4263             n.setName( " tr|B3RJ64 " );
4264             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4265                 return false;
4266             }
4267             n.setName( "-tr|B3RJ64-" );
4268             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4269                 return false;
4270             }
4271             n.setName( "-tr=B3RJ64-" );
4272             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4273                 return false;
4274             }
4275             n.setName( "_tr=B3RJ64_" );
4276             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4277                 return false;
4278             }
4279             n.setName( " tr_tr|B3RJ64_sp|123 " );
4280             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4281                 return false;
4282             }
4283             n.setName( "B3RJ64" );
4284             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4285                 return false;
4286             }
4287             n.setName( "sp|B3RJ64" );
4288             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4289                 return false;
4290             }
4291             n.setName( "sp|B3RJ64C" );
4292             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4293                 return false;
4294             }
4295             n.setName( "sp B3RJ64" );
4296             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4297                 return false;
4298             }
4299             n.setName( "sp|B3RJ6X" );
4300             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4301                 return false;
4302             }
4303             n.setName( "sp|B3RJ6" );
4304             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4305                 return false;
4306             }
4307             n.setName( "K1PYK7_CRAGI" );
4308             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4309                 return false;
4310             }
4311             n.setName( "K1PYK7_PEA" );
4312             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4313                 return false;
4314             }
4315             n.setName( "K1PYK7_RAT" );
4316             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4317                 return false;
4318             }
4319             n.setName( "K1PYK7_PIG" );
4320             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4321                 return false;
4322             }
4323             n.setName( "~K1PYK7_PIG~" );
4324             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4325                 return false;
4326             }
4327             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4328             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4329                 return false;
4330             }
4331             n.setName( "K1PYKX_CRAGI" );
4332             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4333                 return false;
4334             }
4335             n.setName( "XXXXX_CRAGI" );
4336             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4337                 return false;
4338             }
4339             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4340             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4341                 return false;
4342             }
4343             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4344             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4345                 return false;
4346             }
4347             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4348             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4349                 return false;
4350             }
4351             n = new PhylogenyNode();
4352             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4353             seq.setSymbol( "K1PYK7_CRAGI" );
4354             n.getNodeData().addSequence( seq );
4355             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4356                 return false;
4357             }
4358             seq.setSymbol( "tr|B3RJ64" );
4359             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4360                 return false;
4361             }
4362             n = new PhylogenyNode();
4363             seq = new org.forester.phylogeny.data.Sequence();
4364             seq.setName( "K1PYK7_CRAGI" );
4365             n.getNodeData().addSequence( seq );
4366             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4367                 return false;
4368             }
4369             seq.setName( "tr|B3RJ64" );
4370             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4371                 return false;
4372             }
4373             n = new PhylogenyNode();
4374             seq = new org.forester.phylogeny.data.Sequence();
4375             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4376             n.getNodeData().addSequence( seq );
4377             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4378                 return false;
4379             }
4380             n = new PhylogenyNode();
4381             seq = new org.forester.phylogeny.data.Sequence();
4382             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4383             n.getNodeData().addSequence( seq );
4384             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4385                 return false;
4386             }
4387             //
4388             n = new PhylogenyNode();
4389             n.setName( "ACP19736" );
4390             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4391                 return false;
4392             }
4393             n = new PhylogenyNode();
4394             n.setName( "|ACP19736|" );
4395             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4396                 return false;
4397             }
4398         }
4399         catch ( final Exception e ) {
4400             e.printStackTrace( System.out );
4401             return false;
4402         }
4403         return true;
4404     }
4405
4406     private static boolean testFastaParser() {
4407         try {
4408             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4409                 return false;
4410             }
4411             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4412                 return false;
4413             }
4414             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4415             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4416                 return false;
4417             }
4418             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4419                 return false;
4420             }
4421             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4422                 return false;
4423             }
4424             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4425                 return false;
4426             }
4427             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4428                 return false;
4429             }
4430             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4431                 return false;
4432             }
4433         }
4434         catch ( final Exception e ) {
4435             e.printStackTrace();
4436             return false;
4437         }
4438         return true;
4439     }
4440
4441     private static boolean testGenbankAccessorParsing() {
4442         //The format for GenBank Accession numbers are:
4443         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4444         //Protein:    3 letters + 5 numerals
4445         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4446         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4447             return false;
4448         }
4449         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4450             return false;
4451         }
4452         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4453             return false;
4454         }
4455         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4456             return false;
4457         }
4458         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4459             return false;
4460         }
4461         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4462             return false;
4463         }
4464         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4465             return false;
4466         }
4467         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4468             return false;
4469         }
4470         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4471             return false;
4472         }
4473         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4474             return false;
4475         }
4476         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4477             return false;
4478         }
4479         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4480             return false;
4481         }
4482         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4483             return false;
4484         }
4485         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4486             return false;
4487         }
4488         return true;
4489     }
4490
4491     private static boolean testGeneralMsaParser() {
4492         try {
4493             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4494             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4495             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4496             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4497             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4498             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4499             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4500             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4501             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4502                 return false;
4503             }
4504             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4505                 return false;
4506             }
4507             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4508                 return false;
4509             }
4510             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4511                 return false;
4512             }
4513             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4514                 return false;
4515             }
4516             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4517                 return false;
4518             }
4519             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4520                 return false;
4521             }
4522             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4523                 return false;
4524             }
4525             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4526                 return false;
4527             }
4528             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4529                 return false;
4530             }
4531             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4532                 return false;
4533             }
4534             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4535                 return false;
4536             }
4537             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4538             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4539                 return false;
4540             }
4541             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4542                 return false;
4543             }
4544             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4545                 return false;
4546             }
4547             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4548             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4549                 return false;
4550             }
4551             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4552                 return false;
4553             }
4554             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4555                 return false;
4556             }
4557             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4558             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4559                 return false;
4560             }
4561             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4562                 return false;
4563             }
4564             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4565                 return false;
4566             }
4567         }
4568         catch ( final Exception e ) {
4569             e.printStackTrace();
4570             return false;
4571         }
4572         return true;
4573     }
4574
4575     private static boolean testGeneralTable() {
4576         try {
4577             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4578             t0.setValue( 3, 2, "23" );
4579             t0.setValue( 10, 1, "error" );
4580             t0.setValue( 10, 1, "110" );
4581             t0.setValue( 9, 1, "19" );
4582             t0.setValue( 1, 10, "101" );
4583             t0.setValue( 10, 10, "1010" );
4584             t0.setValue( 100, 10, "10100" );
4585             t0.setValue( 0, 0, "00" );
4586             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4587                 return false;
4588             }
4589             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4590                 return false;
4591             }
4592             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4593                 return false;
4594             }
4595             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4596                 return false;
4597             }
4598             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4599                 return false;
4600             }
4601             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4602                 return false;
4603             }
4604             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4605                 return false;
4606             }
4607             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4608                 return false;
4609             }
4610             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4611                 return false;
4612             }
4613             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4614             t1.setValue( "3", "2", "23" );
4615             t1.setValue( "10", "1", "error" );
4616             t1.setValue( "10", "1", "110" );
4617             t1.setValue( "9", "1", "19" );
4618             t1.setValue( "1", "10", "101" );
4619             t1.setValue( "10", "10", "1010" );
4620             t1.setValue( "100", "10", "10100" );
4621             t1.setValue( "0", "0", "00" );
4622             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4623             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4624                 return false;
4625             }
4626             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4627                 return false;
4628             }
4629             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4630                 return false;
4631             }
4632             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4633                 return false;
4634             }
4635             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4636                 return false;
4637             }
4638             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4639                 return false;
4640             }
4641             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4642                 return false;
4643             }
4644             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4645                 return false;
4646             }
4647             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4648                 return false;
4649             }
4650             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4651                 return false;
4652             }
4653         }
4654         catch ( final Exception e ) {
4655             e.printStackTrace( System.out );
4656             return false;
4657         }
4658         return true;
4659     }
4660
4661     private static boolean testGetDistance() {
4662         try {
4663             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4664             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",
4665                                                  new NHXParser() )[ 0 ];
4666             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4667                 return false;
4668             }
4669             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4670                 return false;
4671             }
4672             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4673                 return false;
4674             }
4675             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4676                 return false;
4677             }
4678             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4679                 return false;
4680             }
4681             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4682                 return false;
4683             }
4684             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4685                 return false;
4686             }
4687             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4688                 return false;
4689             }
4690             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4691                 return false;
4692             }
4693             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4694                 return false;
4695             }
4696             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4697                 return false;
4698             }
4699             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4700                 return false;
4701             }
4702             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4703                 return false;
4704             }
4705             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4706                 return false;
4707             }
4708             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4709                 return false;
4710             }
4711             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4712                 return false;
4713             }
4714             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4715                 return false;
4716             }
4717             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4718                 return false;
4719             }
4720             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4721                 return false;
4722             }
4723             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4724                 return false;
4725             }
4726             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4727                 return false;
4728             }
4729             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4730                 return false;
4731             }
4732             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4733                 return false;
4734             }
4735             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4736                 return false;
4737             }
4738             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4739                 return false;
4740             }
4741             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4742                 return false;
4743             }
4744             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4745                 return false;
4746             }
4747             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4748                 return false;
4749             }
4750             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4751                 return false;
4752             }
4753             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4754                 return false;
4755             }
4756             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4757                 return false;
4758             }
4759             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",
4760                                                  new NHXParser() )[ 0 ];
4761             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4762                 return false;
4763             }
4764             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4765                 return false;
4766             }
4767             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4768                 return false;
4769             }
4770             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4771                 return false;
4772             }
4773             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4774                 return false;
4775             }
4776             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4777                 return false;
4778             }
4779             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4780                 return false;
4781             }
4782             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4783                 return false;
4784             }
4785             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4786                 return false;
4787             }
4788             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4789                 return false;
4790             }
4791             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4792                 return false;
4793             }
4794         }
4795         catch ( final Exception e ) {
4796             e.printStackTrace( System.out );
4797             return false;
4798         }
4799         return true;
4800     }
4801
4802     private static boolean testGetLCA() {
4803         try {
4804             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4805             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4806                                                  new NHXParser() )[ 0 ];
4807             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4808             if ( !A.getName().equals( "A" ) ) {
4809                 return false;
4810             }
4811             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4812             if ( !gh.getName().equals( "gh" ) ) {
4813                 return false;
4814             }
4815             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4816             if ( !ab.getName().equals( "ab" ) ) {
4817                 return false;
4818             }
4819             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4820             if ( !ab2.getName().equals( "ab" ) ) {
4821                 return false;
4822             }
4823             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4824             if ( !gh2.getName().equals( "gh" ) ) {
4825                 return false;
4826             }
4827             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4828             if ( !gh3.getName().equals( "gh" ) ) {
4829                 return false;
4830             }
4831             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4832             if ( !abc.getName().equals( "abc" ) ) {
4833                 return false;
4834             }
4835             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4836             if ( !abc2.getName().equals( "abc" ) ) {
4837                 return false;
4838             }
4839             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4840             if ( !abcd.getName().equals( "abcd" ) ) {
4841                 return false;
4842             }
4843             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4844             if ( !abcd2.getName().equals( "abcd" ) ) {
4845                 return false;
4846             }
4847             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4848             if ( !abcdef.getName().equals( "abcdef" ) ) {
4849                 return false;
4850             }
4851             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4852             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4853                 return false;
4854             }
4855             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4856             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4857                 return false;
4858             }
4859             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4860             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4861                 return false;
4862             }
4863             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4864             if ( !abcde.getName().equals( "abcde" ) ) {
4865                 return false;
4866             }
4867             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4868             if ( !abcde2.getName().equals( "abcde" ) ) {
4869                 return false;
4870             }
4871             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4872             if ( !r.getName().equals( "abcdefgh" ) ) {
4873                 return false;
4874             }
4875             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4876             if ( !r2.getName().equals( "abcdefgh" ) ) {
4877                 return false;
4878             }
4879             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4880             if ( !r3.getName().equals( "abcdefgh" ) ) {
4881                 return false;
4882             }
4883             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4884             if ( !abcde3.getName().equals( "abcde" ) ) {
4885                 return false;
4886             }
4887             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4888             if ( !abcde4.getName().equals( "abcde" ) ) {
4889                 return false;
4890             }
4891             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4892             if ( !ab3.getName().equals( "ab" ) ) {
4893                 return false;
4894             }
4895             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4896             if ( !ab4.getName().equals( "ab" ) ) {
4897                 return false;
4898             }
4899             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4900             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4901             if ( !cd.getName().equals( "cd" ) ) {
4902                 return false;
4903             }
4904             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4905             if ( !cd2.getName().equals( "cd" ) ) {
4906                 return false;
4907             }
4908             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4909             if ( !cde.getName().equals( "cde" ) ) {
4910                 return false;
4911             }
4912             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4913             if ( !cde2.getName().equals( "cde" ) ) {
4914                 return false;
4915             }
4916             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4917             if ( !cdef.getName().equals( "cdef" ) ) {
4918                 return false;
4919             }
4920             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4921             if ( !cdef2.getName().equals( "cdef" ) ) {
4922                 return false;
4923             }
4924             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4925             if ( !cdef3.getName().equals( "cdef" ) ) {
4926                 return false;
4927             }
4928             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4929             if ( !rt.getName().equals( "r" ) ) {
4930                 return false;
4931             }
4932             final Phylogeny p3 = factory
4933                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4934                              new NHXParser() )[ 0 ];
4935             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4936             if ( !bc_3.getName().equals( "bc" ) ) {
4937                 return false;
4938             }
4939             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4940             if ( !ac_3.getName().equals( "abc" ) ) {
4941                 return false;
4942             }
4943             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4944             if ( !ad_3.getName().equals( "abcde" ) ) {
4945                 return false;
4946             }
4947             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4948             if ( !af_3.getName().equals( "abcdef" ) ) {
4949                 return false;
4950             }
4951             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4952             if ( !ag_3.getName().equals( "" ) ) {
4953                 return false;
4954             }
4955             if ( !ag_3.isRoot() ) {
4956                 return false;
4957             }
4958             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4959             if ( !al_3.getName().equals( "" ) ) {
4960                 return false;
4961             }
4962             if ( !al_3.isRoot() ) {
4963                 return false;
4964             }
4965             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4966             if ( !kl_3.getName().equals( "" ) ) {
4967                 return false;
4968             }
4969             if ( !kl_3.isRoot() ) {
4970                 return false;
4971             }
4972             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4973             if ( !fl_3.getName().equals( "" ) ) {
4974                 return false;
4975             }
4976             if ( !fl_3.isRoot() ) {
4977                 return false;
4978             }
4979             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4980             if ( !gk_3.getName().equals( "ghijk" ) ) {
4981                 return false;
4982             }
4983             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4984             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4985             if ( !r_4.getName().equals( "r" ) ) {
4986                 return false;
4987             }
4988             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4989             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4990             if ( !r_5.getName().equals( "root" ) ) {
4991                 return false;
4992             }
4993             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4994             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4995             if ( !r_6.getName().equals( "rot" ) ) {
4996                 return false;
4997             }
4998             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4999             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5000             if ( !r_7.getName().equals( "rott" ) ) {
5001                 return false;
5002             }
5003         }
5004         catch ( final Exception e ) {
5005             e.printStackTrace( System.out );
5006             return false;
5007         }
5008         return true;
5009     }
5010
5011     private static boolean testGetLCA2() {
5012         try {
5013             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5014             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5015             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5016             PhylogenyMethods.preOrderReId( p_a );
5017             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5018                                                                                               p_a.getNode( "a" ) );
5019             if ( !p_a_1.getName().equals( "a" ) ) {
5020                 return false;
5021             }
5022             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5023             PhylogenyMethods.preOrderReId( p_b );
5024             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5025                                                                                               p_b.getNode( "a" ) );
5026             if ( !p_b_1.getName().equals( "b" ) ) {
5027                 return false;
5028             }
5029             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5030                                                                                               p_b.getNode( "b" ) );
5031             if ( !p_b_2.getName().equals( "b" ) ) {
5032                 return false;
5033             }
5034             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5035             PhylogenyMethods.preOrderReId( p_c );
5036             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5037                                                                                               p_c.getNode( "a" ) );
5038             if ( !p_c_1.getName().equals( "b" ) ) {
5039                 return false;
5040             }
5041             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5042                                                                                               p_c.getNode( "c" ) );
5043             if ( !p_c_2.getName().equals( "c" ) ) {
5044                 System.out.println( p_c_2.getName() );
5045                 System.exit( -1 );
5046                 return false;
5047             }
5048             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5049                                                                                               p_c.getNode( "b" ) );
5050             if ( !p_c_3.getName().equals( "b" ) ) {
5051                 return false;
5052             }
5053             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5054                                                                                               p_c.getNode( "a" ) );
5055             if ( !p_c_4.getName().equals( "c" ) ) {
5056                 return false;
5057             }
5058             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5059                                                  new NHXParser() )[ 0 ];
5060             PhylogenyMethods.preOrderReId( p1 );
5061             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5062                                                                                           p1.getNode( "A" ) );
5063             if ( !A.getName().equals( "A" ) ) {
5064                 return false;
5065             }
5066             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5067                                                                                            p1.getNode( "gh" ) );
5068             if ( !gh.getName().equals( "gh" ) ) {
5069                 return false;
5070             }
5071             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5072                                                                                            p1.getNode( "B" ) );
5073             if ( !ab.getName().equals( "ab" ) ) {
5074                 return false;
5075             }
5076             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5077                                                                                             p1.getNode( "A" ) );
5078             if ( !ab2.getName().equals( "ab" ) ) {
5079                 return false;
5080             }
5081             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5082                                                                                             p1.getNode( "G" ) );
5083             if ( !gh2.getName().equals( "gh" ) ) {
5084                 return false;
5085             }
5086             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5087                                                                                             p1.getNode( "H" ) );
5088             if ( !gh3.getName().equals( "gh" ) ) {
5089                 return false;
5090             }
5091             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5092                                                                                             p1.getNode( "A" ) );
5093             if ( !abc.getName().equals( "abc" ) ) {
5094                 return false;
5095             }
5096             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5097                                                                                              p1.getNode( "C" ) );
5098             if ( !abc2.getName().equals( "abc" ) ) {
5099                 return false;
5100             }
5101             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5102                                                                                              p1.getNode( "D" ) );
5103             if ( !abcd.getName().equals( "abcd" ) ) {
5104                 return false;
5105             }
5106             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5107                                                                                               p1.getNode( "A" ) );
5108             if ( !abcd2.getName().equals( "abcd" ) ) {
5109                 return false;
5110             }
5111             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5112                                                                                                p1.getNode( "F" ) );
5113             if ( !abcdef.getName().equals( "abcdef" ) ) {
5114                 return false;
5115             }
5116             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5117                                                                                                 p1.getNode( "A" ) );
5118             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5119                 return false;
5120             }
5121             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5122                                                                                                 p1.getNode( "F" ) );
5123             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5124                 return false;
5125             }
5126             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5127                                                                                                 p1.getNode( "ab" ) );
5128             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5129                 return false;
5130             }
5131             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5132                                                                                               p1.getNode( "E" ) );
5133             if ( !abcde.getName().equals( "abcde" ) ) {
5134                 return false;
5135             }
5136             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5137                                                                                                p1.getNode( "A" ) );
5138             if ( !abcde2.getName().equals( "abcde" ) ) {
5139                 return false;
5140             }
5141             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5142                                                                                           p1.getNode( "abcdefgh" ) );
5143             if ( !r.getName().equals( "abcdefgh" ) ) {
5144                 return false;
5145             }
5146             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5147                                                                                            p1.getNode( "H" ) );
5148             if ( !r2.getName().equals( "abcdefgh" ) ) {
5149                 return false;
5150             }
5151             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5152                                                                                            p1.getNode( "A" ) );
5153             if ( !r3.getName().equals( "abcdefgh" ) ) {
5154                 return false;
5155             }
5156             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5157                                                                                                p1.getNode( "abcde" ) );
5158             if ( !abcde3.getName().equals( "abcde" ) ) {
5159                 return false;
5160             }
5161             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5162                                                                                                p1.getNode( "E" ) );
5163             if ( !abcde4.getName().equals( "abcde" ) ) {
5164                 return false;
5165             }
5166             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5167                                                                                             p1.getNode( "B" ) );
5168             if ( !ab3.getName().equals( "ab" ) ) {
5169                 return false;
5170             }
5171             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5172                                                                                             p1.getNode( "ab" ) );
5173             if ( !ab4.getName().equals( "ab" ) ) {
5174                 return false;
5175             }
5176             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5177             PhylogenyMethods.preOrderReId( p2 );
5178             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5179                                                                                            p2.getNode( "d" ) );
5180             if ( !cd.getName().equals( "cd" ) ) {
5181                 return false;
5182             }
5183             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5184                                                                                             p2.getNode( "c" ) );
5185             if ( !cd2.getName().equals( "cd" ) ) {
5186                 return false;
5187             }
5188             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5189                                                                                             p2.getNode( "e" ) );
5190             if ( !cde.getName().equals( "cde" ) ) {
5191                 return false;
5192             }
5193             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5194                                                                                              p2.getNode( "c" ) );
5195             if ( !cde2.getName().equals( "cde" ) ) {
5196                 return false;
5197             }
5198             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5199                                                                                              p2.getNode( "f" ) );
5200             if ( !cdef.getName().equals( "cdef" ) ) {
5201                 return false;
5202             }
5203             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5204                                                                                               p2.getNode( "f" ) );
5205             if ( !cdef2.getName().equals( "cdef" ) ) {
5206                 return false;
5207             }
5208             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5209                                                                                               p2.getNode( "d" ) );
5210             if ( !cdef3.getName().equals( "cdef" ) ) {
5211                 return false;
5212             }
5213             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5214                                                                                            p2.getNode( "a" ) );
5215             if ( !rt.getName().equals( "r" ) ) {
5216                 return false;
5217             }
5218             final Phylogeny p3 = factory
5219                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5220                              new NHXParser() )[ 0 ];
5221             PhylogenyMethods.preOrderReId( p3 );
5222             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5223                                                                                              p3.getNode( "c" ) );
5224             if ( !bc_3.getName().equals( "bc" ) ) {
5225                 return false;
5226             }
5227             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5228                                                                                              p3.getNode( "c" ) );
5229             if ( !ac_3.getName().equals( "abc" ) ) {
5230                 return false;
5231             }
5232             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5233                                                                                              p3.getNode( "d" ) );
5234             if ( !ad_3.getName().equals( "abcde" ) ) {
5235                 return false;
5236             }
5237             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5238                                                                                              p3.getNode( "f" ) );
5239             if ( !af_3.getName().equals( "abcdef" ) ) {
5240                 return false;
5241             }
5242             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5243                                                                                              p3.getNode( "g" ) );
5244             if ( !ag_3.getName().equals( "" ) ) {
5245                 return false;
5246             }
5247             if ( !ag_3.isRoot() ) {
5248                 return false;
5249             }
5250             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5251                                                                                              p3.getNode( "l" ) );
5252             if ( !al_3.getName().equals( "" ) ) {
5253                 return false;
5254             }
5255             if ( !al_3.isRoot() ) {
5256                 return false;
5257             }
5258             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5259                                                                                              p3.getNode( "l" ) );
5260             if ( !kl_3.getName().equals( "" ) ) {
5261                 return false;
5262             }
5263             if ( !kl_3.isRoot() ) {
5264                 return false;
5265             }
5266             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5267                                                                                              p3.getNode( "l" ) );
5268             if ( !fl_3.getName().equals( "" ) ) {
5269                 return false;
5270             }
5271             if ( !fl_3.isRoot() ) {
5272                 return false;
5273             }
5274             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5275                                                                                              p3.getNode( "k" ) );
5276             if ( !gk_3.getName().equals( "ghijk" ) ) {
5277                 return false;
5278             }
5279             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5280             PhylogenyMethods.preOrderReId( p4 );
5281             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5282                                                                                             p4.getNode( "c" ) );
5283             if ( !r_4.getName().equals( "r" ) ) {
5284                 return false;
5285             }
5286             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5287             PhylogenyMethods.preOrderReId( p5 );
5288             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5289                                                                                             p5.getNode( "c" ) );
5290             if ( !r_5.getName().equals( "root" ) ) {
5291                 return false;
5292             }
5293             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5294             PhylogenyMethods.preOrderReId( p6 );
5295             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5296                                                                                             p6.getNode( "a" ) );
5297             if ( !r_6.getName().equals( "rot" ) ) {
5298                 return false;
5299             }
5300             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5301             PhylogenyMethods.preOrderReId( p7 );
5302             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5303                                                                                             p7.getNode( "e" ) );
5304             if ( !r_7.getName().equals( "rott" ) ) {
5305                 return false;
5306             }
5307             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5308                                                                                              p7.getNode( "a" ) );
5309             if ( !r_71.getName().equals( "rott" ) ) {
5310                 return false;
5311             }
5312             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5313                                                                                              p7.getNode( "rott" ) );
5314             if ( !r_72.getName().equals( "rott" ) ) {
5315                 return false;
5316             }
5317             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5318                                                                                              p7.getNode( "a" ) );
5319             if ( !r_73.getName().equals( "rott" ) ) {
5320                 return false;
5321             }
5322             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5323                                                                                              p7.getNode( "rott" ) );
5324             if ( !r_74.getName().equals( "rott" ) ) {
5325                 return false;
5326             }
5327             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5328                                                                                              p7.getNode( "e" ) );
5329             if ( !r_75.getName().equals( "e" ) ) {
5330                 return false;
5331             }
5332         }
5333         catch ( final Exception e ) {
5334             e.printStackTrace( System.out );
5335             return false;
5336         }
5337         return true;
5338     }
5339
5340     private static boolean testHmmscanOutputParser() {
5341         final String test_dir = Test.PATH_TO_TEST_DATA;
5342         try {
5343             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5344                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5345             parser1.parse();
5346             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5347                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5348             final List<Protein> proteins = parser2.parse();
5349             if ( parser2.getProteinsEncountered() != 4 ) {
5350                 return false;
5351             }
5352             if ( proteins.size() != 4 ) {
5353                 return false;
5354             }
5355             if ( parser2.getDomainsEncountered() != 69 ) {
5356                 return false;
5357             }
5358             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5359                 return false;
5360             }
5361             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5362                 return false;
5363             }
5364             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5365                 return false;
5366             }
5367             final Protein p1 = proteins.get( 0 );
5368             if ( p1.getNumberOfProteinDomains() != 15 ) {
5369                 return false;
5370             }
5371             if ( p1.getLength() != 850 ) {
5372                 return false;
5373             }
5374             final Protein p2 = proteins.get( 1 );
5375             if ( p2.getNumberOfProteinDomains() != 51 ) {
5376                 return false;
5377             }
5378             if ( p2.getLength() != 1291 ) {
5379                 return false;
5380             }
5381             final Protein p3 = proteins.get( 2 );
5382             if ( p3.getNumberOfProteinDomains() != 2 ) {
5383                 return false;
5384             }
5385             final Protein p4 = proteins.get( 3 );
5386             if ( p4.getNumberOfProteinDomains() != 1 ) {
5387                 return false;
5388             }
5389             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5390                 return false;
5391             }
5392             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5393                 return false;
5394             }
5395             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5396                 return false;
5397             }
5398             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5399                 return false;
5400             }
5401             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5402                 return false;
5403             }
5404             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5405                 return false;
5406             }
5407             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5408                 return false;
5409             }
5410         }
5411         catch ( final Exception e ) {
5412             e.printStackTrace( System.out );
5413             return false;
5414         }
5415         return true;
5416     }
5417
5418     private static boolean testLastExternalNodeMethods() {
5419         try {
5420             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5421             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5422             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5423             final PhylogenyNode n1 = t0.getNode( "A" );
5424             if ( n1.isLastExternalNode() ) {
5425                 return false;
5426             }
5427             final PhylogenyNode n2 = t0.getNode( "B" );
5428             if ( n2.isLastExternalNode() ) {
5429                 return false;
5430             }
5431             final PhylogenyNode n3 = t0.getNode( "C" );
5432             if ( n3.isLastExternalNode() ) {
5433                 return false;
5434             }
5435             final PhylogenyNode n4 = t0.getNode( "D" );
5436             if ( !n4.isLastExternalNode() ) {
5437                 return false;
5438             }
5439         }
5440         catch ( final Exception e ) {
5441             e.printStackTrace( System.out );
5442             return false;
5443         }
5444         return true;
5445     }
5446
5447     private static boolean testLevelOrderIterator() {
5448         try {
5449             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5450             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5451             PhylogenyNodeIterator it0;
5452             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5453                 it0.next();
5454             }
5455             for( it0.reset(); it0.hasNext(); ) {
5456                 it0.next();
5457             }
5458             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5459             if ( !it.next().getName().equals( "r" ) ) {
5460                 return false;
5461             }
5462             if ( !it.next().getName().equals( "ab" ) ) {
5463                 return false;
5464             }
5465             if ( !it.next().getName().equals( "cd" ) ) {
5466                 return false;
5467             }
5468             if ( !it.next().getName().equals( "A" ) ) {
5469                 return false;
5470             }
5471             if ( !it.next().getName().equals( "B" ) ) {
5472                 return false;
5473             }
5474             if ( !it.next().getName().equals( "C" ) ) {
5475                 return false;
5476             }
5477             if ( !it.next().getName().equals( "D" ) ) {
5478                 return false;
5479             }
5480             if ( it.hasNext() ) {
5481                 return false;
5482             }
5483             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",
5484                                                  new NHXParser() )[ 0 ];
5485             PhylogenyNodeIterator it2;
5486             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5487                 it2.next();
5488             }
5489             for( it2.reset(); it2.hasNext(); ) {
5490                 it2.next();
5491             }
5492             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5493             if ( !it3.next().getName().equals( "r" ) ) {
5494                 return false;
5495             }
5496             if ( !it3.next().getName().equals( "abc" ) ) {
5497                 return false;
5498             }
5499             if ( !it3.next().getName().equals( "defg" ) ) {
5500                 return false;
5501             }
5502             if ( !it3.next().getName().equals( "A" ) ) {
5503                 return false;
5504             }
5505             if ( !it3.next().getName().equals( "B" ) ) {
5506                 return false;
5507             }
5508             if ( !it3.next().getName().equals( "C" ) ) {
5509                 return false;
5510             }
5511             if ( !it3.next().getName().equals( "D" ) ) {
5512                 return false;
5513             }
5514             if ( !it3.next().getName().equals( "E" ) ) {
5515                 return false;
5516             }
5517             if ( !it3.next().getName().equals( "F" ) ) {
5518                 return false;
5519             }
5520             if ( !it3.next().getName().equals( "G" ) ) {
5521                 return false;
5522             }
5523             if ( !it3.next().getName().equals( "1" ) ) {
5524                 return false;
5525             }
5526             if ( !it3.next().getName().equals( "2" ) ) {
5527                 return false;
5528             }
5529             if ( !it3.next().getName().equals( "3" ) ) {
5530                 return false;
5531             }
5532             if ( !it3.next().getName().equals( "4" ) ) {
5533                 return false;
5534             }
5535             if ( !it3.next().getName().equals( "5" ) ) {
5536                 return false;
5537             }
5538             if ( !it3.next().getName().equals( "6" ) ) {
5539                 return false;
5540             }
5541             if ( !it3.next().getName().equals( "f1" ) ) {
5542                 return false;
5543             }
5544             if ( !it3.next().getName().equals( "f2" ) ) {
5545                 return false;
5546             }
5547             if ( !it3.next().getName().equals( "f3" ) ) {
5548                 return false;
5549             }
5550             if ( !it3.next().getName().equals( "a" ) ) {
5551                 return false;
5552             }
5553             if ( !it3.next().getName().equals( "b" ) ) {
5554                 return false;
5555             }
5556             if ( !it3.next().getName().equals( "f21" ) ) {
5557                 return false;
5558             }
5559             if ( !it3.next().getName().equals( "X" ) ) {
5560                 return false;
5561             }
5562             if ( !it3.next().getName().equals( "Y" ) ) {
5563                 return false;
5564             }
5565             if ( !it3.next().getName().equals( "Z" ) ) {
5566                 return false;
5567             }
5568             if ( it3.hasNext() ) {
5569                 return false;
5570             }
5571             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5572             PhylogenyNodeIterator it4;
5573             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5574                 it4.next();
5575             }
5576             for( it4.reset(); it4.hasNext(); ) {
5577                 it4.next();
5578             }
5579             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5580             if ( !it5.next().getName().equals( "r" ) ) {
5581                 return false;
5582             }
5583             if ( !it5.next().getName().equals( "A" ) ) {
5584                 return false;
5585             }
5586             if ( !it5.next().getName().equals( "B" ) ) {
5587                 return false;
5588             }
5589             if ( !it5.next().getName().equals( "C" ) ) {
5590                 return false;
5591             }
5592             if ( !it5.next().getName().equals( "D" ) ) {
5593                 return false;
5594             }
5595             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5596             PhylogenyNodeIterator it6;
5597             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5598                 it6.next();
5599             }
5600             for( it6.reset(); it6.hasNext(); ) {
5601                 it6.next();
5602             }
5603             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5604             if ( !it7.next().getName().equals( "A" ) ) {
5605                 return false;
5606             }
5607             if ( it.hasNext() ) {
5608                 return false;
5609             }
5610         }
5611         catch ( final Exception e ) {
5612             e.printStackTrace( System.out );
5613             return false;
5614         }
5615         return true;
5616     }
5617
5618     private static boolean testMafft( final String path ) {
5619         try {
5620             final List<String> opts = new ArrayList<String>();
5621             opts.add( "--maxiterate" );
5622             opts.add( "1000" );
5623             opts.add( "--localpair" );
5624             opts.add( "--quiet" );
5625             Msa msa = null;
5626             final MsaInferrer mafft = Mafft.createInstance( path );
5627             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5628             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5629                 return false;
5630             }
5631             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5632                 return false;
5633             }
5634         }
5635         catch ( final Exception e ) {
5636             e.printStackTrace( System.out );
5637             return false;
5638         }
5639         return true;
5640     }
5641
5642     private static boolean testMidpointrooting() {
5643         try {
5644             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5645             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5646             PhylogenyMethods.midpointRoot( t0 );
5647             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5648                 return false;
5649             }
5650             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5651                 return false;
5652             }
5653             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5654                            1 ) ) {
5655                 return false;
5656             }
5657             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",
5658                                                  new NHXParser() )[ 0 ];
5659             if ( !t1.isRooted() ) {
5660                 return false;
5661             }
5662             PhylogenyMethods.midpointRoot( t1 );
5663             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5664                 return false;
5665             }
5666             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5667                 return false;
5668             }
5669             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5670                 return false;
5671             }
5672             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5673                 return false;
5674             }
5675             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5676                 return false;
5677             }
5678             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5679                 return false;
5680             }
5681             t1.reRoot( t1.getNode( "A" ) );
5682             PhylogenyMethods.midpointRoot( t1 );
5683             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5684                 return false;
5685             }
5686             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5687                 return false;
5688             }
5689             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5690                 return false;
5691             }
5692             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5693                 return false;
5694             }
5695             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5696                 System.exit( -1 );
5697                 return false;
5698             }
5699             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5700                 return false;
5701             }
5702         }
5703         catch ( final Exception e ) {
5704             e.printStackTrace( System.out );
5705             return false;
5706         }
5707         return true;
5708     }
5709
5710     private static boolean testMsaQualityMethod() {
5711         try {
5712             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5713             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5714             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5715             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5716             final List<Sequence> l = new ArrayList<Sequence>();
5717             l.add( s0 );
5718             l.add( s1 );
5719             l.add( s2 );
5720             l.add( s3 );
5721             final Msa msa = BasicMsa.createInstance( l );
5722             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5723                 return false;
5724             }
5725             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5726                 return false;
5727             }
5728             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5729                 return false;
5730             }
5731             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5732                 return false;
5733             }
5734         }
5735         catch ( final Exception e ) {
5736             e.printStackTrace( System.out );
5737             return false;
5738         }
5739         return true;
5740     }
5741
5742     private static boolean testNextNodeWithCollapsing() {
5743         try {
5744             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5745             PhylogenyNode n;
5746             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5747             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5748             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5749             t0.getNode( "cd" ).setCollapse( true );
5750             t0.getNode( "cde" ).setCollapse( true );
5751             n = t0.getFirstExternalNode();
5752             while ( n != null ) {
5753                 ext.add( n );
5754                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5755             }
5756             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5757                 return false;
5758             }
5759             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5760                 return false;
5761             }
5762             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5763                 return false;
5764             }
5765             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5766                 return false;
5767             }
5768             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5769                 return false;
5770             }
5771             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5772                 return false;
5773             }
5774             ext.clear();
5775             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5776             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5777             t1.getNode( "ab" ).setCollapse( true );
5778             t1.getNode( "cd" ).setCollapse( true );
5779             t1.getNode( "cde" ).setCollapse( true );
5780             n = t1.getNode( "ab" );
5781             ext = new ArrayList<PhylogenyNode>();
5782             while ( n != null ) {
5783                 ext.add( n );
5784                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5785             }
5786             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5787                 return false;
5788             }
5789             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5790                 return false;
5791             }
5792             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5793                 return false;
5794             }
5795             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5796                 return false;
5797             }
5798             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5799                 return false;
5800             }
5801             //
5802             //
5803             ext.clear();
5804             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5805             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5806             t2.getNode( "ab" ).setCollapse( true );
5807             t2.getNode( "cd" ).setCollapse( true );
5808             t2.getNode( "cde" ).setCollapse( true );
5809             t2.getNode( "c" ).setCollapse( true );
5810             t2.getNode( "d" ).setCollapse( true );
5811             t2.getNode( "e" ).setCollapse( true );
5812             t2.getNode( "gh" ).setCollapse( true );
5813             n = t2.getNode( "ab" );
5814             ext = new ArrayList<PhylogenyNode>();
5815             while ( n != null ) {
5816                 ext.add( n );
5817                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5818             }
5819             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5820                 return false;
5821             }
5822             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5823                 return false;
5824             }
5825             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5826                 return false;
5827             }
5828             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5829                 return false;
5830             }
5831             //
5832             //
5833             ext.clear();
5834             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5835             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5836             t3.getNode( "ab" ).setCollapse( true );
5837             t3.getNode( "cd" ).setCollapse( true );
5838             t3.getNode( "cde" ).setCollapse( true );
5839             t3.getNode( "c" ).setCollapse( true );
5840             t3.getNode( "d" ).setCollapse( true );
5841             t3.getNode( "e" ).setCollapse( true );
5842             t3.getNode( "gh" ).setCollapse( true );
5843             t3.getNode( "fgh" ).setCollapse( true );
5844             n = t3.getNode( "ab" );
5845             ext = new ArrayList<PhylogenyNode>();
5846             while ( n != null ) {
5847                 ext.add( n );
5848                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5849             }
5850             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5851                 return false;
5852             }
5853             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5854                 return false;
5855             }
5856             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5857                 return false;
5858             }
5859             //
5860             //
5861             ext.clear();
5862             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5863             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5864             t4.getNode( "ab" ).setCollapse( true );
5865             t4.getNode( "cd" ).setCollapse( true );
5866             t4.getNode( "cde" ).setCollapse( true );
5867             t4.getNode( "c" ).setCollapse( true );
5868             t4.getNode( "d" ).setCollapse( true );
5869             t4.getNode( "e" ).setCollapse( true );
5870             t4.getNode( "gh" ).setCollapse( true );
5871             t4.getNode( "fgh" ).setCollapse( true );
5872             t4.getNode( "abcdefgh" ).setCollapse( true );
5873             n = t4.getNode( "abcdefgh" );
5874             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5875                 return false;
5876             }
5877             //
5878             //
5879             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5880             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5881             ext.clear();
5882             n = t5.getFirstExternalNode();
5883             while ( n != null ) {
5884                 ext.add( n );
5885                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5886             }
5887             if ( ext.size() != 8 ) {
5888                 return false;
5889             }
5890             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5891                 return false;
5892             }
5893             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5894                 return false;
5895             }
5896             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5897                 return false;
5898             }
5899             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5900                 return false;
5901             }
5902             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5903                 return false;
5904             }
5905             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5906                 return false;
5907             }
5908             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5909                 return false;
5910             }
5911             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5912                 return false;
5913             }
5914             //
5915             //
5916             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5917             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5918             ext.clear();
5919             t6.getNode( "ab" ).setCollapse( true );
5920             n = t6.getNode( "ab" );
5921             while ( n != null ) {
5922                 ext.add( n );
5923                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5924             }
5925             if ( ext.size() != 7 ) {
5926                 return false;
5927             }
5928             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5929                 return false;
5930             }
5931             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5932                 return false;
5933             }
5934             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5935                 return false;
5936             }
5937             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5938                 return false;
5939             }
5940             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5941                 return false;
5942             }
5943             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5944                 return false;
5945             }
5946             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5947                 return false;
5948             }
5949             //
5950             //
5951             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5952             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5953             ext.clear();
5954             t7.getNode( "cd" ).setCollapse( true );
5955             n = t7.getNode( "a" );
5956             while ( n != null ) {
5957                 ext.add( n );
5958                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5959             }
5960             if ( ext.size() != 7 ) {
5961                 return false;
5962             }
5963             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5964                 return false;
5965             }
5966             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5967                 return false;
5968             }
5969             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5970                 return false;
5971             }
5972             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5973                 return false;
5974             }
5975             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5976                 return false;
5977             }
5978             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5979                 return false;
5980             }
5981             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5982                 return false;
5983             }
5984             //
5985             //
5986             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5987             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5988             ext.clear();
5989             t8.getNode( "cd" ).setCollapse( true );
5990             t8.getNode( "c" ).setCollapse( true );
5991             t8.getNode( "d" ).setCollapse( true );
5992             n = t8.getNode( "a" );
5993             while ( n != null ) {
5994                 ext.add( n );
5995                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5996             }
5997             if ( ext.size() != 7 ) {
5998                 return false;
5999             }
6000             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6001                 return false;
6002             }
6003             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6004                 return false;
6005             }
6006             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6007                 System.out.println( "2 fail" );
6008                 return false;
6009             }
6010             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6011                 return false;
6012             }
6013             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6014                 return false;
6015             }
6016             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6017                 return false;
6018             }
6019             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6020                 return false;
6021             }
6022             //
6023             //
6024             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6025             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6026             ext.clear();
6027             t9.getNode( "gh" ).setCollapse( true );
6028             n = t9.getNode( "a" );
6029             while ( n != null ) {
6030                 ext.add( n );
6031                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6032             }
6033             if ( ext.size() != 7 ) {
6034                 return false;
6035             }
6036             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6037                 return false;
6038             }
6039             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6040                 return false;
6041             }
6042             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6043                 return false;
6044             }
6045             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6046                 return false;
6047             }
6048             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6049                 return false;
6050             }
6051             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6052                 return false;
6053             }
6054             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6055                 return false;
6056             }
6057             //
6058             //
6059             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6060             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6061             ext.clear();
6062             t10.getNode( "gh" ).setCollapse( true );
6063             t10.getNode( "g" ).setCollapse( true );
6064             t10.getNode( "h" ).setCollapse( true );
6065             n = t10.getNode( "a" );
6066             while ( n != null ) {
6067                 ext.add( n );
6068                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6069             }
6070             if ( ext.size() != 7 ) {
6071                 return false;
6072             }
6073             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6074                 return false;
6075             }
6076             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6077                 return false;
6078             }
6079             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6080                 return false;
6081             }
6082             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6083                 return false;
6084             }
6085             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6086                 return false;
6087             }
6088             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6089                 return false;
6090             }
6091             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6092                 return false;
6093             }
6094             //
6095             //
6096             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6097             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6098             ext.clear();
6099             t11.getNode( "gh" ).setCollapse( true );
6100             t11.getNode( "fgh" ).setCollapse( true );
6101             n = t11.getNode( "a" );
6102             while ( n != null ) {
6103                 ext.add( n );
6104                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6105             }
6106             if ( ext.size() != 6 ) {
6107                 return false;
6108             }
6109             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6110                 return false;
6111             }
6112             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6113                 return false;
6114             }
6115             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6116                 return false;
6117             }
6118             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6119                 return false;
6120             }
6121             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6122                 return false;
6123             }
6124             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6125                 return false;
6126             }
6127             //
6128             //
6129             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6130             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6131             ext.clear();
6132             t12.getNode( "gh" ).setCollapse( true );
6133             t12.getNode( "fgh" ).setCollapse( true );
6134             t12.getNode( "g" ).setCollapse( true );
6135             t12.getNode( "h" ).setCollapse( true );
6136             t12.getNode( "f" ).setCollapse( true );
6137             n = t12.getNode( "a" );
6138             while ( n != null ) {
6139                 ext.add( n );
6140                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6141             }
6142             if ( ext.size() != 6 ) {
6143                 return false;
6144             }
6145             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6146                 return false;
6147             }
6148             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6149                 return false;
6150             }
6151             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6152                 return false;
6153             }
6154             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6155                 return false;
6156             }
6157             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6158                 return false;
6159             }
6160             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6161                 return false;
6162             }
6163             //
6164             //
6165             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6166             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6167             ext.clear();
6168             t13.getNode( "ab" ).setCollapse( true );
6169             t13.getNode( "b" ).setCollapse( true );
6170             t13.getNode( "fgh" ).setCollapse( true );
6171             t13.getNode( "gh" ).setCollapse( true );
6172             n = t13.getNode( "ab" );
6173             while ( n != null ) {
6174                 ext.add( n );
6175                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6176             }
6177             if ( ext.size() != 5 ) {
6178                 return false;
6179             }
6180             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6181                 return false;
6182             }
6183             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6184                 return false;
6185             }
6186             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6187                 return false;
6188             }
6189             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6190                 return false;
6191             }
6192             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6193                 return false;
6194             }
6195             //
6196             //
6197             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6198             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6199             ext.clear();
6200             t14.getNode( "ab" ).setCollapse( true );
6201             t14.getNode( "a" ).setCollapse( true );
6202             t14.getNode( "fgh" ).setCollapse( true );
6203             t14.getNode( "gh" ).setCollapse( true );
6204             n = t14.getNode( "ab" );
6205             while ( n != null ) {
6206                 ext.add( n );
6207                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6208             }
6209             if ( ext.size() != 5 ) {
6210                 return false;
6211             }
6212             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6213                 return false;
6214             }
6215             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6216                 return false;
6217             }
6218             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6219                 return false;
6220             }
6221             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6222                 return false;
6223             }
6224             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6225                 return false;
6226             }
6227             //
6228             //
6229             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" );
6230             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6231             ext.clear();
6232             t15.getNode( "ab" ).setCollapse( true );
6233             t15.getNode( "a" ).setCollapse( true );
6234             t15.getNode( "fgh" ).setCollapse( true );
6235             t15.getNode( "gh" ).setCollapse( true );
6236             n = t15.getNode( "ab" );
6237             while ( n != null ) {
6238                 ext.add( n );
6239                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6240             }
6241             if ( ext.size() != 6 ) {
6242                 return false;
6243             }
6244             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6245                 return false;
6246             }
6247             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6248                 return false;
6249             }
6250             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6251                 return false;
6252             }
6253             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6254                 return false;
6255             }
6256             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6257                 return false;
6258             }
6259             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6260                 return false;
6261             }
6262             //
6263             //
6264             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" );
6265             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6266             ext.clear();
6267             t16.getNode( "ab" ).setCollapse( true );
6268             t16.getNode( "a" ).setCollapse( true );
6269             t16.getNode( "fgh" ).setCollapse( true );
6270             t16.getNode( "gh" ).setCollapse( true );
6271             t16.getNode( "cd" ).setCollapse( true );
6272             t16.getNode( "cde" ).setCollapse( true );
6273             t16.getNode( "d" ).setCollapse( true );
6274             t16.getNode( "x" ).setCollapse( true );
6275             n = t16.getNode( "ab" );
6276             while ( n != null ) {
6277                 ext.add( n );
6278                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6279             }
6280             if ( ext.size() != 4 ) {
6281                 return false;
6282             }
6283             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6284                 return false;
6285             }
6286             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6287                 return false;
6288             }
6289             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6290                 return false;
6291             }
6292             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6293                 return false;
6294             }
6295         }
6296         catch ( final Exception e ) {
6297             e.printStackTrace( System.out );
6298             return false;
6299         }
6300         return true;
6301     }
6302
6303     private static boolean testNexusCharactersParsing() {
6304         try {
6305             final NexusCharactersParser parser = new NexusCharactersParser();
6306             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6307             parser.parse();
6308             String[] labels = parser.getCharStateLabels();
6309             if ( labels.length != 7 ) {
6310                 return false;
6311             }
6312             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6313                 return false;
6314             }
6315             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6316                 return false;
6317             }
6318             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6319                 return false;
6320             }
6321             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6322                 return false;
6323             }
6324             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6325                 return false;
6326             }
6327             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6328                 return false;
6329             }
6330             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6331                 return false;
6332             }
6333             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6334             parser.parse();
6335             labels = parser.getCharStateLabels();
6336             if ( labels.length != 7 ) {
6337                 return false;
6338             }
6339             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6340                 return false;
6341             }
6342             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6343                 return false;
6344             }
6345             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6346                 return false;
6347             }
6348             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6349                 return false;
6350             }
6351             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6352                 return false;
6353             }
6354             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6355                 return false;
6356             }
6357             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6358                 return false;
6359             }
6360         }
6361         catch ( final Exception e ) {
6362             e.printStackTrace( System.out );
6363             return false;
6364         }
6365         return true;
6366     }
6367
6368     private static boolean testNexusMatrixParsing() {
6369         try {
6370             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6371             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6372             parser.parse();
6373             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6374             if ( m.getNumberOfCharacters() != 9 ) {
6375                 return false;
6376             }
6377             if ( m.getNumberOfIdentifiers() != 5 ) {
6378                 return false;
6379             }
6380             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6381                 return false;
6382             }
6383             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6384                 return false;
6385             }
6386             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6387                 return false;
6388             }
6389             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6390                 return false;
6391             }
6392             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6393                 return false;
6394             }
6395             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6396                 return false;
6397             }
6398             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6399                 return false;
6400             }
6401             //            if ( labels.length != 7 ) {
6402             //                return false;
6403             //            }
6404             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6405             //                return false;
6406             //            }
6407             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6408             //                return false;
6409             //            }
6410             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6411             //                return false;
6412             //            }
6413             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6414             //                return false;
6415             //            }
6416             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6417             //                return false;
6418             //            }
6419             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6420             //                return false;
6421             //            }
6422             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6423             //                return false;
6424             //            }
6425             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6426             //            parser.parse();
6427             //            labels = parser.getCharStateLabels();
6428             //            if ( labels.length != 7 ) {
6429             //                return false;
6430             //            }
6431             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6432             //                return false;
6433             //            }
6434             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6435             //                return false;
6436             //            }
6437             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6438             //                return false;
6439             //            }
6440             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6441             //                return false;
6442             //            }
6443             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6444             //                return false;
6445             //            }
6446             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6447             //                return false;
6448             //            }
6449             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6450             //                return false;
6451             //            }
6452         }
6453         catch ( final Exception e ) {
6454             e.printStackTrace( System.out );
6455             return false;
6456         }
6457         return true;
6458     }
6459
6460     private static boolean testNexusTreeParsing() {
6461         try {
6462             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6463             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6464             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6465             if ( phylogenies.length != 1 ) {
6466                 return false;
6467             }
6468             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6469                 return false;
6470             }
6471             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6472                 return false;
6473             }
6474             phylogenies = null;
6475             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6476             if ( phylogenies.length != 1 ) {
6477                 return false;
6478             }
6479             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6480                 return false;
6481             }
6482             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6483                 return false;
6484             }
6485             phylogenies = null;
6486             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6487             if ( phylogenies.length != 1 ) {
6488                 return false;
6489             }
6490             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6491                 return false;
6492             }
6493             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6494                 return false;
6495             }
6496             if ( phylogenies[ 0 ].isRooted() ) {
6497                 return false;
6498             }
6499             phylogenies = null;
6500             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6501             if ( phylogenies.length != 18 ) {
6502                 return false;
6503             }
6504             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6505                 return false;
6506             }
6507             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6508                 return false;
6509             }
6510             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6511                 return false;
6512             }
6513             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6514                 return false;
6515             }
6516             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6517                 return false;
6518             }
6519             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6520                 return false;
6521             }
6522             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6523                 return false;
6524             }
6525             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6526                 return false;
6527             }
6528             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6529                 return false;
6530             }
6531             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6532                 return false;
6533             }
6534             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6535                 return false;
6536             }
6537             if ( phylogenies[ 8 ].isRooted() ) {
6538                 return false;
6539             }
6540             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6541                 return false;
6542             }
6543             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6544                 return false;
6545             }
6546             if ( !phylogenies[ 9 ].isRooted() ) {
6547                 return false;
6548             }
6549             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6550                 return false;
6551             }
6552             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6553                 return false;
6554             }
6555             if ( !phylogenies[ 10 ].isRooted() ) {
6556                 return false;
6557             }
6558             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6559                 return false;
6560             }
6561             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6562                 return false;
6563             }
6564             if ( phylogenies[ 11 ].isRooted() ) {
6565                 return false;
6566             }
6567             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6568                 return false;
6569             }
6570             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6571                 return false;
6572             }
6573             if ( !phylogenies[ 12 ].isRooted() ) {
6574                 return false;
6575             }
6576             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6577                 return false;
6578             }
6579             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6580                 return false;
6581             }
6582             if ( !phylogenies[ 13 ].isRooted() ) {
6583                 return false;
6584             }
6585             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6586                 return false;
6587             }
6588             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6589                 return false;
6590             }
6591             if ( !phylogenies[ 14 ].isRooted() ) {
6592                 return false;
6593             }
6594             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6595                 return false;
6596             }
6597             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6598                 return false;
6599             }
6600             if ( phylogenies[ 15 ].isRooted() ) {
6601                 return false;
6602             }
6603             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6604                 return false;
6605             }
6606             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6607                 return false;
6608             }
6609             if ( !phylogenies[ 16 ].isRooted() ) {
6610                 return false;
6611             }
6612             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6613                 return false;
6614             }
6615             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6616                 return false;
6617             }
6618             if ( phylogenies[ 17 ].isRooted() ) {
6619                 return false;
6620             }
6621             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6622                 return false;
6623             }
6624         }
6625         catch ( final Exception e ) {
6626             e.printStackTrace( System.out );
6627             return false;
6628         }
6629         return true;
6630     }
6631
6632     private static boolean testNexusTreeParsingIterating() {
6633         try {
6634             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6635             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6636             if ( !p.hasNext() ) {
6637                 return false;
6638             }
6639             Phylogeny phy = p.next();
6640             if ( phy == null ) {
6641                 return false;
6642             }
6643             if ( phy.getNumberOfExternalNodes() != 25 ) {
6644                 return false;
6645             }
6646             if ( !phy.getName().equals( "" ) ) {
6647                 return false;
6648             }
6649             if ( p.hasNext() ) {
6650                 return false;
6651             }
6652             phy = p.next();
6653             if ( phy != null ) {
6654                 return false;
6655             }
6656             //
6657             p.reset();
6658             if ( !p.hasNext() ) {
6659                 return false;
6660             }
6661             phy = p.next();
6662             if ( phy == null ) {
6663                 return false;
6664             }
6665             if ( phy.getNumberOfExternalNodes() != 25 ) {
6666                 return false;
6667             }
6668             if ( !phy.getName().equals( "" ) ) {
6669                 return false;
6670             }
6671             if ( p.hasNext() ) {
6672                 return false;
6673             }
6674             phy = p.next();
6675             if ( phy != null ) {
6676                 return false;
6677             }
6678             ////
6679             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6680             if ( !p.hasNext() ) {
6681                 return false;
6682             }
6683             phy = p.next();
6684             if ( phy == null ) {
6685                 return false;
6686             }
6687             if ( phy.getNumberOfExternalNodes() != 10 ) {
6688                 return false;
6689             }
6690             if ( !phy.getName().equals( "name" ) ) {
6691                 return false;
6692             }
6693             if ( p.hasNext() ) {
6694                 return false;
6695             }
6696             phy = p.next();
6697             if ( phy != null ) {
6698                 return false;
6699             }
6700             //
6701             p.reset();
6702             if ( !p.hasNext() ) {
6703                 return false;
6704             }
6705             phy = p.next();
6706             if ( phy == null ) {
6707                 return false;
6708             }
6709             if ( phy.getNumberOfExternalNodes() != 10 ) {
6710                 return false;
6711             }
6712             if ( !phy.getName().equals( "name" ) ) {
6713                 return false;
6714             }
6715             if ( p.hasNext() ) {
6716                 return false;
6717             }
6718             phy = p.next();
6719             if ( phy != null ) {
6720                 return false;
6721             }
6722             ////
6723             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6724             if ( !p.hasNext() ) {
6725                 return false;
6726             }
6727             phy = p.next();
6728             if ( phy == null ) {
6729                 return false;
6730             }
6731             if ( phy.getNumberOfExternalNodes() != 3 ) {
6732                 return false;
6733             }
6734             if ( !phy.getName().equals( "" ) ) {
6735                 return false;
6736             }
6737             if ( phy.isRooted() ) {
6738                 return false;
6739             }
6740             if ( p.hasNext() ) {
6741                 return false;
6742             }
6743             phy = p.next();
6744             if ( phy != null ) {
6745                 return false;
6746             }
6747             //
6748             p.reset();
6749             if ( !p.hasNext() ) {
6750                 return false;
6751             }
6752             phy = p.next();
6753             if ( phy == null ) {
6754                 return false;
6755             }
6756             if ( phy.getNumberOfExternalNodes() != 3 ) {
6757                 return false;
6758             }
6759             if ( !phy.getName().equals( "" ) ) {
6760                 return false;
6761             }
6762             if ( p.hasNext() ) {
6763                 return false;
6764             }
6765             phy = p.next();
6766             if ( phy != null ) {
6767                 return false;
6768             }
6769             ////
6770             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6771             //            if ( phylogenies.length != 18 ) {
6772             //                return false;
6773             //            }
6774             //0
6775             if ( !p.hasNext() ) {
6776                 return false;
6777             }
6778             phy = p.next();
6779             if ( phy == null ) {
6780                 return false;
6781             }
6782             if ( phy.getNumberOfExternalNodes() != 10 ) {
6783                 return false;
6784             }
6785             if ( !phy.getName().equals( "tree 0" ) ) {
6786                 return false;
6787             }
6788             //1
6789             if ( !p.hasNext() ) {
6790                 return false;
6791             }
6792             phy = p.next();
6793             if ( phy == null ) {
6794                 return false;
6795             }
6796             if ( phy.getNumberOfExternalNodes() != 10 ) {
6797                 return false;
6798             }
6799             if ( !phy.getName().equals( "tree 1" ) ) {
6800                 return false;
6801             }
6802             //2
6803             if ( !p.hasNext() ) {
6804                 return false;
6805             }
6806             phy = p.next();
6807             if ( phy == null ) {
6808                 return false;
6809             }
6810             if ( phy.getNumberOfExternalNodes() != 3 ) {
6811                 return false;
6812             }
6813             if ( !phy.getName().equals( "" ) ) {
6814                 return false;
6815             }
6816             if ( phy.isRooted() ) {
6817                 return false;
6818             }
6819             //3
6820             if ( !p.hasNext() ) {
6821                 return false;
6822             }
6823             phy = p.next();
6824             if ( phy == null ) {
6825                 return false;
6826             }
6827             if ( phy.getNumberOfExternalNodes() != 4 ) {
6828                 return false;
6829             }
6830             if ( !phy.getName().equals( "" ) ) {
6831                 return false;
6832             }
6833             if ( !phy.isRooted() ) {
6834                 return false;
6835             }
6836             //4
6837             if ( !p.hasNext() ) {
6838                 return false;
6839             }
6840             phy = p.next();
6841             if ( phy == null ) {
6842                 return false;
6843             }
6844             if ( phy.getNumberOfExternalNodes() != 5 ) {
6845                 System.out.println( phy.getNumberOfExternalNodes() );
6846                 return false;
6847             }
6848             if ( !phy.getName().equals( "" ) ) {
6849                 return false;
6850             }
6851             if ( !phy.isRooted() ) {
6852                 return false;
6853             }
6854             //5
6855             if ( !p.hasNext() ) {
6856                 return false;
6857             }
6858             phy = p.next();
6859             if ( phy == null ) {
6860                 return false;
6861             }
6862             if ( phy.getNumberOfExternalNodes() != 3 ) {
6863                 return false;
6864             }
6865             if ( !phy.getName().equals( "" ) ) {
6866                 return false;
6867             }
6868             if ( phy.isRooted() ) {
6869                 return false;
6870             }
6871             //6
6872             if ( !p.hasNext() ) {
6873                 return false;
6874             }
6875             phy = p.next();
6876             if ( phy == null ) {
6877                 return false;
6878             }
6879             if ( phy.getNumberOfExternalNodes() != 2 ) {
6880                 return false;
6881             }
6882             if ( !phy.getName().equals( "" ) ) {
6883                 return false;
6884             }
6885             if ( !phy.isRooted() ) {
6886                 return false;
6887             }
6888             //7
6889             if ( !p.hasNext() ) {
6890                 return false;
6891             }
6892             phy = p.next();
6893             if ( phy.getNumberOfExternalNodes() != 3 ) {
6894                 return false;
6895             }
6896             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6897                 return false;
6898             }
6899             if ( !phy.isRooted() ) {
6900                 return false;
6901             }
6902             //8
6903             if ( !p.hasNext() ) {
6904                 return false;
6905             }
6906             phy = p.next();
6907             if ( phy.getNumberOfExternalNodes() != 3 ) {
6908                 return false;
6909             }
6910             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6911                 return false;
6912             }
6913             if ( !phy.getName().equals( "tree 8" ) ) {
6914                 return false;
6915             }
6916             //9
6917             if ( !p.hasNext() ) {
6918                 return false;
6919             }
6920             phy = p.next();
6921             if ( phy.getNumberOfExternalNodes() != 3 ) {
6922                 return false;
6923             }
6924             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6925                 return false;
6926             }
6927             if ( !phy.getName().equals( "tree 9" ) ) {
6928                 return false;
6929             }
6930             //10
6931             if ( !p.hasNext() ) {
6932                 return false;
6933             }
6934             phy = p.next();
6935             if ( phy.getNumberOfExternalNodes() != 3 ) {
6936                 return false;
6937             }
6938             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6939                 return false;
6940             }
6941             if ( !phy.getName().equals( "tree 10" ) ) {
6942                 return false;
6943             }
6944             if ( !phy.isRooted() ) {
6945                 return false;
6946             }
6947             //11
6948             if ( !p.hasNext() ) {
6949                 return false;
6950             }
6951             phy = p.next();
6952             if ( phy.getNumberOfExternalNodes() != 3 ) {
6953                 return false;
6954             }
6955             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6956                 return false;
6957             }
6958             if ( !phy.getName().equals( "tree 11" ) ) {
6959                 return false;
6960             }
6961             if ( phy.isRooted() ) {
6962                 return false;
6963             }
6964             //12
6965             if ( !p.hasNext() ) {
6966                 return false;
6967             }
6968             phy = p.next();
6969             if ( phy.getNumberOfExternalNodes() != 3 ) {
6970                 return false;
6971             }
6972             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6973                 return false;
6974             }
6975             if ( !phy.getName().equals( "tree 12" ) ) {
6976                 return false;
6977             }
6978             if ( !phy.isRooted() ) {
6979                 return false;
6980             }
6981             //13
6982             if ( !p.hasNext() ) {
6983                 return false;
6984             }
6985             phy = p.next();
6986             if ( phy.getNumberOfExternalNodes() != 3 ) {
6987                 return false;
6988             }
6989             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6990                 return false;
6991             }
6992             if ( !phy.getName().equals( "tree 13" ) ) {
6993                 return false;
6994             }
6995             if ( !phy.isRooted() ) {
6996                 return false;
6997             }
6998             //14
6999             if ( !p.hasNext() ) {
7000                 return false;
7001             }
7002             phy = p.next();
7003             if ( phy.getNumberOfExternalNodes() != 10 ) {
7004                 System.out.println( phy.getNumberOfExternalNodes() );
7005                 return false;
7006             }
7007             if ( !phy
7008                     .toNewHampshire()
7009                     .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;" ) ) {
7010                 System.out.println( phy.toNewHampshire() );
7011                 return false;
7012             }
7013             if ( !phy.getName().equals( "tree 14" ) ) {
7014                 return false;
7015             }
7016             if ( !phy.isRooted() ) {
7017                 return false;
7018             }
7019             //15
7020             if ( !p.hasNext() ) {
7021                 return false;
7022             }
7023             phy = p.next();
7024             if ( phy.getNumberOfExternalNodes() != 10 ) {
7025                 System.out.println( phy.getNumberOfExternalNodes() );
7026                 return false;
7027             }
7028             if ( !phy
7029                     .toNewHampshire()
7030                     .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;" ) ) {
7031                 System.out.println( phy.toNewHampshire() );
7032                 return false;
7033             }
7034             if ( !phy.getName().equals( "tree 15" ) ) {
7035                 return false;
7036             }
7037             if ( phy.isRooted() ) {
7038                 return false;
7039             }
7040             //16
7041             if ( !p.hasNext() ) {
7042                 return false;
7043             }
7044             phy = p.next();
7045             if ( phy.getNumberOfExternalNodes() != 10 ) {
7046                 System.out.println( phy.getNumberOfExternalNodes() );
7047                 return false;
7048             }
7049             if ( !phy
7050                     .toNewHampshire()
7051                     .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;" ) ) {
7052                 System.out.println( phy.toNewHampshire() );
7053                 return false;
7054             }
7055             if ( !phy.getName().equals( "tree 16" ) ) {
7056                 return false;
7057             }
7058             if ( !phy.isRooted() ) {
7059                 return false;
7060             }
7061             //17
7062             if ( !p.hasNext() ) {
7063                 return false;
7064             }
7065             phy = p.next();
7066             if ( phy.getNumberOfExternalNodes() != 10 ) {
7067                 System.out.println( phy.getNumberOfExternalNodes() );
7068                 return false;
7069             }
7070             if ( !phy
7071                     .toNewHampshire()
7072                     .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;" ) ) {
7073                 System.out.println( phy.toNewHampshire() );
7074                 return false;
7075             }
7076             if ( !phy.getName().equals( "tree 17" ) ) {
7077                 return false;
7078             }
7079             if ( phy.isRooted() ) {
7080                 return false;
7081             }
7082             //
7083             if ( p.hasNext() ) {
7084                 return false;
7085             }
7086             phy = p.next();
7087             if ( phy != null ) {
7088                 return false;
7089             }
7090             p.reset();
7091             //0
7092             if ( !p.hasNext() ) {
7093                 return false;
7094             }
7095             phy = p.next();
7096             if ( phy == null ) {
7097                 return false;
7098             }
7099             if ( phy.getNumberOfExternalNodes() != 10 ) {
7100                 return false;
7101             }
7102             if ( !phy.getName().equals( "tree 0" ) ) {
7103                 return false;
7104             }
7105             //1
7106             if ( !p.hasNext() ) {
7107                 return false;
7108             }
7109             phy = p.next();
7110             if ( phy == null ) {
7111                 return false;
7112             }
7113             if ( phy.getNumberOfExternalNodes() != 10 ) {
7114                 return false;
7115             }
7116             if ( !phy.getName().equals( "tree 1" ) ) {
7117                 return false;
7118             }
7119             //2
7120             if ( !p.hasNext() ) {
7121                 return false;
7122             }
7123             phy = p.next();
7124             if ( phy == null ) {
7125                 return false;
7126             }
7127             if ( phy.getNumberOfExternalNodes() != 3 ) {
7128                 return false;
7129             }
7130             if ( !phy.getName().equals( "" ) ) {
7131                 return false;
7132             }
7133             if ( phy.isRooted() ) {
7134                 return false;
7135             }
7136             //3
7137             if ( !p.hasNext() ) {
7138                 return false;
7139             }
7140             phy = p.next();
7141             if ( phy == null ) {
7142                 return false;
7143             }
7144             if ( phy.getNumberOfExternalNodes() != 4 ) {
7145                 return false;
7146             }
7147             if ( !phy.getName().equals( "" ) ) {
7148                 return false;
7149             }
7150             if ( !phy.isRooted() ) {
7151                 return false;
7152             }
7153             //4
7154             if ( !p.hasNext() ) {
7155                 return false;
7156             }
7157             phy = p.next();
7158             if ( phy == null ) {
7159                 return false;
7160             }
7161             if ( phy.getNumberOfExternalNodes() != 5 ) {
7162                 System.out.println( phy.getNumberOfExternalNodes() );
7163                 return false;
7164             }
7165             if ( !phy.getName().equals( "" ) ) {
7166                 return false;
7167             }
7168             if ( !phy.isRooted() ) {
7169                 return false;
7170             }
7171             //5
7172             if ( !p.hasNext() ) {
7173                 return false;
7174             }
7175             phy = p.next();
7176             if ( phy == null ) {
7177                 return false;
7178             }
7179             if ( phy.getNumberOfExternalNodes() != 3 ) {
7180                 return false;
7181             }
7182             if ( !phy.getName().equals( "" ) ) {
7183                 return false;
7184             }
7185             if ( phy.isRooted() ) {
7186                 return false;
7187             }
7188         }
7189         catch ( final Exception e ) {
7190             e.printStackTrace( System.out );
7191             return false;
7192         }
7193         return true;
7194     }
7195
7196     private static boolean testNexusTreeParsingTranslating() {
7197         try {
7198             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7199             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7200             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7201             if ( phylogenies.length != 1 ) {
7202                 return false;
7203             }
7204             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7205                 return false;
7206             }
7207             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7208                 return false;
7209             }
7210             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7211                 return false;
7212             }
7213             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7214                 return false;
7215             }
7216             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7217                     .equals( "Aranaeus" ) ) {
7218                 return false;
7219             }
7220             phylogenies = null;
7221             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7222             if ( phylogenies.length != 3 ) {
7223                 return false;
7224             }
7225             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7226                 return false;
7227             }
7228             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7229                 return false;
7230             }
7231             if ( phylogenies[ 0 ].isRooted() ) {
7232                 return false;
7233             }
7234             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7235                 return false;
7236             }
7237             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7238                 return false;
7239             }
7240             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7241                     .equals( "Aranaeus" ) ) {
7242                 return false;
7243             }
7244             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7245                 return false;
7246             }
7247             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7248                 return false;
7249             }
7250             if ( phylogenies[ 1 ].isRooted() ) {
7251                 return false;
7252             }
7253             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7254                 return false;
7255             }
7256             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7257                 return false;
7258             }
7259             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7260                     .equals( "Aranaeus" ) ) {
7261                 return false;
7262             }
7263             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7264                 return false;
7265             }
7266             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7267                 return false;
7268             }
7269             if ( !phylogenies[ 2 ].isRooted() ) {
7270                 return false;
7271             }
7272             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7273                 return false;
7274             }
7275             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7276                 return false;
7277             }
7278             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7279                     .equals( "Aranaeus" ) ) {
7280                 return false;
7281             }
7282             phylogenies = null;
7283             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7284             if ( phylogenies.length != 3 ) {
7285                 return false;
7286             }
7287             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7288                 return false;
7289             }
7290             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7291                 return false;
7292             }
7293             if ( phylogenies[ 0 ].isRooted() ) {
7294                 return false;
7295             }
7296             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7297                 return false;
7298             }
7299             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7300                 return false;
7301             }
7302             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7303                     .equals( "Aranaeus" ) ) {
7304                 return false;
7305             }
7306             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7307                 return false;
7308             }
7309             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7310                 return false;
7311             }
7312             if ( phylogenies[ 1 ].isRooted() ) {
7313                 return false;
7314             }
7315             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7316                 return false;
7317             }
7318             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7319                 return false;
7320             }
7321             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7322                     .equals( "Aranaeus" ) ) {
7323                 return false;
7324             }
7325             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7326                 return false;
7327             }
7328             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7329                 return false;
7330             }
7331             if ( !phylogenies[ 2 ].isRooted() ) {
7332                 return false;
7333             }
7334             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7335                 return false;
7336             }
7337             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7338                 return false;
7339             }
7340             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7341                     .equals( "Aranaeus" ) ) {
7342                 return false;
7343             }
7344         }
7345         catch ( final Exception e ) {
7346             e.printStackTrace( System.out );
7347             return false;
7348         }
7349         return true;
7350     }
7351
7352     private static boolean testNHParsing() {
7353         try {
7354             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7355             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7356             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7357                 return false;
7358             }
7359             final NHXParser nhxp = new NHXParser();
7360             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7361             nhxp.setReplaceUnderscores( true );
7362             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7363             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
7364                 return false;
7365             }
7366             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
7367                 return false;
7368             }
7369             final Phylogeny p1b = factory
7370                     .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 ",
7371                              new NHXParser() )[ 0 ];
7372             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7373                 return false;
7374             }
7375             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7376                 return false;
7377             }
7378             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7379             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7380             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7381             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7382             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7383             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7384             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7385             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7386             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7387             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7388             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7389                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7390                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7391                                                     new NHXParser() );
7392             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7393                 return false;
7394             }
7395             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7396                 return false;
7397             }
7398             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7399                 return false;
7400             }
7401             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7402                 return false;
7403             }
7404             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7405             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7406             final String p16_S = "((A,B),C)";
7407             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7408             if ( p16.length != 1 ) {
7409                 return false;
7410             }
7411             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
7412                 return false;
7413             }
7414             final String p17_S = "(C,(A,B))";
7415             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
7416             if ( p17.length != 1 ) {
7417                 return false;
7418             }
7419             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7420                 return false;
7421             }
7422             final String p18_S = "((A,B),(C,D))";
7423             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7424             if ( p18.length != 1 ) {
7425                 return false;
7426             }
7427             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7428                 return false;
7429             }
7430             final String p19_S = "(((A,B),C),D)";
7431             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7432             if ( p19.length != 1 ) {
7433                 return false;
7434             }
7435             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7436                 return false;
7437             }
7438             final String p20_S = "(A,(B,(C,D)))";
7439             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7440             if ( p20.length != 1 ) {
7441                 return false;
7442             }
7443             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7444                 return false;
7445             }
7446             final String p21_S = "(A,(B,(C,(D,E))))";
7447             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7448             if ( p21.length != 1 ) {
7449                 return false;
7450             }
7451             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7452                 return false;
7453             }
7454             final String p22_S = "((((A,B),C),D),E)";
7455             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7456             if ( p22.length != 1 ) {
7457                 return false;
7458             }
7459             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7460                 return false;
7461             }
7462             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7463             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7464             if ( p23.length != 1 ) {
7465                 System.out.println( "xl=" + p23.length );
7466                 System.exit( -1 );
7467                 return false;
7468             }
7469             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7470                 return false;
7471             }
7472             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7473             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7474             if ( p24.length != 1 ) {
7475                 return false;
7476             }
7477             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7478                 return false;
7479             }
7480             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7481             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7482             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7483             if ( p241.length != 2 ) {
7484                 return false;
7485             }
7486             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7487                 return false;
7488             }
7489             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7490                 return false;
7491             }
7492             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7493                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7494                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7495                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7496                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7497                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7498                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7499                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7500             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7501             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7502                 return false;
7503             }
7504             final String p26_S = "(A,B)ab";
7505             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7506             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7507                 return false;
7508             }
7509             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7510             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7511             if ( p27s.length != 1 ) {
7512                 System.out.println( "xxl=" + p27s.length );
7513                 System.exit( -1 );
7514                 return false;
7515             }
7516             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7517                 System.out.println( p27s[ 0 ].toNewHampshireX() );
7518                 System.exit( -1 );
7519                 return false;
7520             }
7521             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7522                                                     new NHXParser() );
7523             if ( p27.length != 1 ) {
7524                 System.out.println( "yl=" + p27.length );
7525                 System.exit( -1 );
7526                 return false;
7527             }
7528             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7529                 System.out.println( p27[ 0 ].toNewHampshireX() );
7530                 System.exit( -1 );
7531                 return false;
7532             }
7533             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7534             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7535             final String p28_S3 = "(A,B)ab";
7536             final String p28_S4 = "((((A,B),C),D),;E;)";
7537             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7538                                                     new NHXParser() );
7539             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7540                 return false;
7541             }
7542             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7543                 return false;
7544             }
7545             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7546                 return false;
7547             }
7548             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7549                 return false;
7550             }
7551             if ( p28.length != 4 ) {
7552                 return false;
7553             }
7554             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";
7555             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
7556             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
7557                 return false;
7558             }
7559             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";
7560             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
7561             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
7562                 return false;
7563             }
7564             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
7565             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
7566             if ( ( p32.length != 0 ) ) {
7567                 return false;
7568             }
7569             final String p33_S = "A";
7570             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
7571             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
7572                 return false;
7573             }
7574             final String p34_S = "B;";
7575             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
7576             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
7577                 return false;
7578             }
7579             final String p35_S = "B:0.2";
7580             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7581             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7582                 return false;
7583             }
7584             final String p36_S = "(A)";
7585             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7586             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7587                 return false;
7588             }
7589             final String p37_S = "((A))";
7590             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7591             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7592                 return false;
7593             }
7594             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7595             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7596             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7597                 return false;
7598             }
7599             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7600             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7601             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7602                 return false;
7603             }
7604             final String p40_S = "(A,B,C)";
7605             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7606             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7607                 return false;
7608             }
7609             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7610             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7611             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7612                 return false;
7613             }
7614             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7615             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7616             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7617                 return false;
7618             }
7619             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)";
7620             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7621             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7622                 return false;
7623             }
7624             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)))";
7625             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7626             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7627                 return false;
7628             }
7629             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7630             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7631             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7632                 return false;
7633             }
7634             final String p46_S = "";
7635             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7636             if ( p46.length != 0 ) {
7637                 return false;
7638             }
7639             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7640             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7641                 return false;
7642             }
7643             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7644             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7645                 return false;
7646             }
7647             final Phylogeny p49 = factory
7648                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7649                              new NHXParser() )[ 0 ];
7650             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7651                 return false;
7652             }
7653             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7654             if ( p50.getNode( "A" ) == null ) {
7655                 return false;
7656             }
7657             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7658                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7659                 return false;
7660             }
7661             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7662                 return false;
7663             }
7664             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7665                     .equals( "((A,B)88:2.0,C);" ) ) {
7666                 return false;
7667             }
7668             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7669             if ( p51.getNode( "A(A" ) == null ) {
7670                 return false;
7671             }
7672             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7673             if ( p52.getNode( "A(A" ) == null ) {
7674                 return false;
7675             }
7676             final Phylogeny p53 = factory
7677                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7678                              new NHXParser() )[ 0 ];
7679             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7680                 return false;
7681             }
7682             // 
7683             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7684             if ( p54.getNode( "A" ) == null ) {
7685                 return false;
7686             }
7687             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7688                     .equals( "((A,B)[88],C);" ) ) {
7689                 return false;
7690             }
7691         }
7692         catch ( final Exception e ) {
7693             e.printStackTrace( System.out );
7694             return false;
7695         }
7696         return true;
7697     }
7698
7699     private static boolean testNHParsingIter() {
7700         try {
7701             final String p0_str = "(A,B);";
7702             final NHXParser p = new NHXParser();
7703             p.setSource( p0_str );
7704             if ( !p.hasNext() ) {
7705                 return false;
7706             }
7707             final Phylogeny p0 = p.next();
7708             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7709                 System.out.println( p0.toNewHampshire() );
7710                 return false;
7711             }
7712             if ( p.hasNext() ) {
7713                 return false;
7714             }
7715             if ( p.next() != null ) {
7716                 return false;
7717             }
7718             //
7719             final String p00_str = "(A,B)root;";
7720             p.setSource( p00_str );
7721             final Phylogeny p00 = p.next();
7722             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7723                 System.out.println( p00.toNewHampshire() );
7724                 return false;
7725             }
7726             //
7727             final String p000_str = "A;";
7728             p.setSource( p000_str );
7729             final Phylogeny p000 = p.next();
7730             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7731                 System.out.println( p000.toNewHampshire() );
7732                 return false;
7733             }
7734             //
7735             final String p0000_str = "A";
7736             p.setSource( p0000_str );
7737             final Phylogeny p0000 = p.next();
7738             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7739                 System.out.println( p0000.toNewHampshire() );
7740                 return false;
7741             }
7742             //
7743             p.setSource( "(A)" );
7744             final Phylogeny p00000 = p.next();
7745             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7746                 System.out.println( p00000.toNewHampshire() );
7747                 return false;
7748             }
7749             //
7750             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7751             p.setSource( p1_str );
7752             if ( !p.hasNext() ) {
7753                 return false;
7754             }
7755             final Phylogeny p1_0 = p.next();
7756             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7757                 System.out.println( p1_0.toNewHampshire() );
7758                 return false;
7759             }
7760             if ( !p.hasNext() ) {
7761                 return false;
7762             }
7763             final Phylogeny p1_1 = p.next();
7764             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7765                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7766                 return false;
7767             }
7768             if ( !p.hasNext() ) {
7769                 return false;
7770             }
7771             final Phylogeny p1_2 = p.next();
7772             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7773                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7774                 return false;
7775             }
7776             if ( !p.hasNext() ) {
7777                 return false;
7778             }
7779             final Phylogeny p1_3 = p.next();
7780             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7781                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7782                 return false;
7783             }
7784             if ( p.hasNext() ) {
7785                 return false;
7786             }
7787             if ( p.next() != null ) {
7788                 return false;
7789             }
7790             //
7791             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7792             p.setSource( p2_str );
7793             if ( !p.hasNext() ) {
7794                 return false;
7795             }
7796             Phylogeny p2_0 = p.next();
7797             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7798                 System.out.println( p2_0.toNewHampshire() );
7799                 return false;
7800             }
7801             if ( !p.hasNext() ) {
7802                 return false;
7803             }
7804             Phylogeny p2_1 = p.next();
7805             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7806                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7807                 return false;
7808             }
7809             if ( !p.hasNext() ) {
7810                 return false;
7811             }
7812             Phylogeny p2_2 = p.next();
7813             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7814                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7815                 return false;
7816             }
7817             if ( !p.hasNext() ) {
7818                 return false;
7819             }
7820             Phylogeny p2_3 = p.next();
7821             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7822                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7823                 return false;
7824             }
7825             if ( !p.hasNext() ) {
7826                 return false;
7827             }
7828             Phylogeny p2_4 = p.next();
7829             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7830                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7831                 return false;
7832             }
7833             if ( p.hasNext() ) {
7834                 return false;
7835             }
7836             if ( p.next() != null ) {
7837                 return false;
7838             }
7839             ////
7840             p.reset();
7841             if ( !p.hasNext() ) {
7842                 return false;
7843             }
7844             p2_0 = p.next();
7845             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7846                 System.out.println( p2_0.toNewHampshire() );
7847                 return false;
7848             }
7849             if ( !p.hasNext() ) {
7850                 return false;
7851             }
7852             p2_1 = p.next();
7853             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7854                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7855                 return false;
7856             }
7857             if ( !p.hasNext() ) {
7858                 return false;
7859             }
7860             p2_2 = p.next();
7861             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7862                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7863                 return false;
7864             }
7865             if ( !p.hasNext() ) {
7866                 return false;
7867             }
7868             p2_3 = p.next();
7869             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7870                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7871                 return false;
7872             }
7873             if ( !p.hasNext() ) {
7874                 return false;
7875             }
7876             p2_4 = p.next();
7877             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7878                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7879                 return false;
7880             }
7881             if ( p.hasNext() ) {
7882                 return false;
7883             }
7884             if ( p.next() != null ) {
7885                 return false;
7886             }
7887             //
7888             final String p3_str = "((A,B),C)abc";
7889             p.setSource( p3_str );
7890             if ( !p.hasNext() ) {
7891                 return false;
7892             }
7893             final Phylogeny p3_0 = p.next();
7894             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7895                 return false;
7896             }
7897             if ( p.hasNext() ) {
7898                 return false;
7899             }
7900             if ( p.next() != null ) {
7901                 return false;
7902             }
7903             //
7904             final String p4_str = "((A,B)ab,C)abc";
7905             p.setSource( p4_str );
7906             if ( !p.hasNext() ) {
7907                 return false;
7908             }
7909             final Phylogeny p4_0 = p.next();
7910             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7911                 return false;
7912             }
7913             if ( p.hasNext() ) {
7914                 return false;
7915             }
7916             if ( p.next() != null ) {
7917                 return false;
7918             }
7919             //
7920             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7921             p.setSource( p5_str );
7922             if ( !p.hasNext() ) {
7923                 return false;
7924             }
7925             final Phylogeny p5_0 = p.next();
7926             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7927                 return false;
7928             }
7929             if ( p.hasNext() ) {
7930                 return false;
7931             }
7932             if ( p.next() != null ) {
7933                 return false;
7934             }
7935             //
7936             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7937             p.setSource( p6_str );
7938             if ( !p.hasNext() ) {
7939                 return false;
7940             }
7941             Phylogeny p6_0 = p.next();
7942             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7943                 return false;
7944             }
7945             if ( p.hasNext() ) {
7946                 return false;
7947             }
7948             if ( p.next() != null ) {
7949                 return false;
7950             }
7951             p.reset();
7952             if ( !p.hasNext() ) {
7953                 return false;
7954             }
7955             p6_0 = p.next();
7956             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7957                 return false;
7958             }
7959             if ( p.hasNext() ) {
7960                 return false;
7961             }
7962             if ( p.next() != null ) {
7963                 return false;
7964             }
7965             //
7966             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7967             p.setSource( p7_str );
7968             if ( !p.hasNext() ) {
7969                 return false;
7970             }
7971             Phylogeny p7_0 = p.next();
7972             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7973                 return false;
7974             }
7975             if ( p.hasNext() ) {
7976                 return false;
7977             }
7978             if ( p.next() != null ) {
7979                 return false;
7980             }
7981             p.reset();
7982             if ( !p.hasNext() ) {
7983                 return false;
7984             }
7985             p7_0 = p.next();
7986             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7987                 return false;
7988             }
7989             if ( p.hasNext() ) {
7990                 return false;
7991             }
7992             if ( p.next() != null ) {
7993                 return false;
7994             }
7995             //
7996             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7997             p.setSource( p8_str );
7998             if ( !p.hasNext() ) {
7999                 return false;
8000             }
8001             Phylogeny p8_0 = p.next();
8002             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8003                 return false;
8004             }
8005             if ( !p.hasNext() ) {
8006                 return false;
8007             }
8008             if ( !p.hasNext() ) {
8009                 return false;
8010             }
8011             Phylogeny p8_1 = p.next();
8012             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8013                 return false;
8014             }
8015             if ( p.hasNext() ) {
8016                 return false;
8017             }
8018             if ( p.next() != null ) {
8019                 return false;
8020             }
8021             p.reset();
8022             if ( !p.hasNext() ) {
8023                 return false;
8024             }
8025             p8_0 = p.next();
8026             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8027                 return false;
8028             }
8029             if ( !p.hasNext() ) {
8030                 return false;
8031             }
8032             p8_1 = p.next();
8033             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8034                 return false;
8035             }
8036             if ( p.hasNext() ) {
8037                 return false;
8038             }
8039             if ( p.next() != null ) {
8040                 return false;
8041             }
8042             p.reset();
8043             //
8044             p.setSource( "" );
8045             if ( p.hasNext() ) {
8046                 return false;
8047             }
8048             //
8049             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8050             if ( !p.hasNext() ) {
8051                 return false;
8052             }
8053             Phylogeny p_27 = p.next();
8054             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8055                 System.out.println( p_27.toNewHampshireX() );
8056                 System.exit( -1 );
8057                 return false;
8058             }
8059             if ( p.hasNext() ) {
8060                 return false;
8061             }
8062             if ( p.next() != null ) {
8063                 return false;
8064             }
8065             p.reset();
8066             if ( !p.hasNext() ) {
8067                 return false;
8068             }
8069             p_27 = p.next();
8070             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8071                 System.out.println( p_27.toNewHampshireX() );
8072                 System.exit( -1 );
8073                 return false;
8074             }
8075             if ( p.hasNext() ) {
8076                 return false;
8077             }
8078             if ( p.next() != null ) {
8079                 return false;
8080             }
8081             //
8082             final String p30_str = "(A,B);(C,D)";
8083             final NHXParser p30 = new NHXParser();
8084             p30.setSource( p30_str );
8085             if ( !p30.hasNext() ) {
8086                 return false;
8087             }
8088             Phylogeny phy30 = p30.next();
8089             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8090                 System.out.println( phy30.toNewHampshire() );
8091                 return false;
8092             }
8093             if ( !p30.hasNext() ) {
8094                 return false;
8095             }
8096             Phylogeny phy301 = p30.next();
8097             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8098                 System.out.println( phy301.toNewHampshire() );
8099                 return false;
8100             }
8101             if ( p30.hasNext() ) {
8102                 return false;
8103             }
8104             if ( p30.hasNext() ) {
8105                 return false;
8106             }
8107             if ( p30.next() != null ) {
8108                 return false;
8109             }
8110             if ( p30.next() != null ) {
8111                 return false;
8112             }
8113             p30.reset();
8114             if ( !p30.hasNext() ) {
8115                 return false;
8116             }
8117             phy30 = p30.next();
8118             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8119                 System.out.println( phy30.toNewHampshire() );
8120                 return false;
8121             }
8122             if ( !p30.hasNext() ) {
8123                 return false;
8124             }
8125             phy301 = p30.next();
8126             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8127                 System.out.println( phy301.toNewHampshire() );
8128                 return false;
8129             }
8130             if ( p30.hasNext() ) {
8131                 return false;
8132             }
8133             if ( p30.hasNext() ) {
8134                 return false;
8135             }
8136             if ( p30.next() != null ) {
8137                 return false;
8138             }
8139             if ( p30.next() != null ) {
8140                 return false;
8141             }
8142         }
8143         catch ( final Exception e ) {
8144             e.printStackTrace( System.out );
8145             return false;
8146         }
8147         return true;
8148     }
8149
8150     private static boolean testNHXconversion() {
8151         try {
8152             final PhylogenyNode n1 = new PhylogenyNode();
8153             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8154             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8155             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8156             final PhylogenyNode n5 = PhylogenyNode
8157                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8158             final PhylogenyNode n6 = PhylogenyNode
8159                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8160             if ( !n1.toNewHampshireX().equals( "" ) ) {
8161                 return false;
8162             }
8163             if ( !n2.toNewHampshireX().equals( "" ) ) {
8164                 return false;
8165             }
8166             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8167                 return false;
8168             }
8169             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8170                 return false;
8171             }
8172             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8173                 return false;
8174             }
8175             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8176                 System.out.println( n6.toNewHampshireX() );
8177                 return false;
8178             }
8179         }
8180         catch ( final Exception e ) {
8181             e.printStackTrace( System.out );
8182             return false;
8183         }
8184         return true;
8185     }
8186
8187     private static boolean testNHXNodeParsing() {
8188         try {
8189             final PhylogenyNode n1 = new PhylogenyNode();
8190             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8191             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8192             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8193             final PhylogenyNode n5 = PhylogenyNode
8194                     .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]" );
8195             if ( !n3.getName().equals( "n3" ) ) {
8196                 return false;
8197             }
8198             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8199                 return false;
8200             }
8201             if ( n3.isDuplication() ) {
8202                 return false;
8203             }
8204             if ( n3.isHasAssignedEvent() ) {
8205                 return false;
8206             }
8207             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8208                 return false;
8209             }
8210             if ( !n4.getName().equals( "n4" ) ) {
8211                 return false;
8212             }
8213             if ( n4.getDistanceToParent() != 0.01 ) {
8214                 return false;
8215             }
8216             if ( !n5.getName().equals( "n5" ) ) {
8217                 return false;
8218             }
8219             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8220                 return false;
8221             }
8222             if ( n5.getDistanceToParent() != 0.1 ) {
8223                 return false;
8224             }
8225             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8226                 return false;
8227             }
8228             if ( !n5.isDuplication() ) {
8229                 return false;
8230             }
8231             if ( !n5.isHasAssignedEvent() ) {
8232                 return false;
8233             }
8234             final PhylogenyNode n8 = PhylogenyNode
8235                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8236                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8237             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8238                 return false;
8239             }
8240             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8241                 return false;
8242             }
8243             final PhylogenyNode n9 = PhylogenyNode
8244                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8245                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8246             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8247                 return false;
8248             }
8249             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8250                 return false;
8251             }
8252             final PhylogenyNode n10 = PhylogenyNode
8253                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8254             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8255                 return false;
8256             }
8257             final PhylogenyNode n20 = PhylogenyNode
8258                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8259             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8260                 return false;
8261             }
8262             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8263                 return false;
8264             }
8265             final PhylogenyNode n20x = PhylogenyNode
8266                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8267             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8268                 return false;
8269             }
8270             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8271                 return false;
8272             }
8273             final PhylogenyNode n20xx = PhylogenyNode
8274                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8275             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8276                 return false;
8277             }
8278             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8279                 return false;
8280             }
8281             final PhylogenyNode n20xxx = PhylogenyNode
8282                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8283             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8284                 return false;
8285             }
8286             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8287                 return false;
8288             }
8289             final PhylogenyNode n20xxxx = PhylogenyNode
8290                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8291             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8292                 return false;
8293             }
8294             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8295                 return false;
8296             }
8297             final PhylogenyNode n21 = PhylogenyNode
8298                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8299             if ( !n21.getName().equals( "N21_PIG" ) ) {
8300                 return false;
8301             }
8302             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8303                 return false;
8304             }
8305             final PhylogenyNode n21x = PhylogenyNode
8306                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8307             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8308                 return false;
8309             }
8310             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8311                 return false;
8312             }
8313             final PhylogenyNode n22 = PhylogenyNode
8314                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8315             if ( !n22.getName().equals( "n22/PIG" ) ) {
8316                 return false;
8317             }
8318             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8319                 return false;
8320             }
8321             final PhylogenyNode n23 = PhylogenyNode
8322                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8323             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8324                 return false;
8325             }
8326             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8327                 return false;
8328             }
8329             final PhylogenyNode a = PhylogenyNode
8330                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8331             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8332                 return false;
8333             }
8334             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8335                 return false;
8336             }
8337             final PhylogenyNode c1 = PhylogenyNode
8338                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8339                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8340             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8341                 return false;
8342             }
8343             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8344                 return false;
8345             }
8346             final PhylogenyNode c2 = PhylogenyNode
8347                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8348                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8349             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8350                 return false;
8351             }
8352             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
8353                 return false;
8354             }
8355             final PhylogenyNode e3 = PhylogenyNode
8356                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8357             if ( !e3.getName().equals( "n10_RAT~" ) ) {
8358                 return false;
8359             }
8360             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
8361                 return false;
8362             }
8363             final PhylogenyNode n11 = PhylogenyNode
8364                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
8365                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8366             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
8367                 return false;
8368             }
8369             if ( n11.getDistanceToParent() != 0.4 ) {
8370                 return false;
8371             }
8372             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
8373                 return false;
8374             }
8375             final PhylogenyNode n12 = PhylogenyNode
8376                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
8377                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8378             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
8379                 return false;
8380             }
8381             if ( n12.getDistanceToParent() != 0.4 ) {
8382                 return false;
8383             }
8384             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
8385                 return false;
8386             }
8387             final PhylogenyNode o = PhylogenyNode
8388                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8389             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
8390                 return false;
8391             }
8392             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
8393                 return false;
8394             }
8395             if ( n1.getName().compareTo( "" ) != 0 ) {
8396                 return false;
8397             }
8398             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8399                 return false;
8400             }
8401             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8402                 return false;
8403             }
8404             if ( n2.getName().compareTo( "" ) != 0 ) {
8405                 return false;
8406             }
8407             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8408                 return false;
8409             }
8410             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8411                 return false;
8412             }
8413             final PhylogenyNode n00 = PhylogenyNode
8414                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
8415             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
8416                 return false;
8417             }
8418             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
8419                 return false;
8420             }
8421             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
8422             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
8423                 return false;
8424             }
8425             final PhylogenyNode n13 = PhylogenyNode
8426                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8427             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
8428                 return false;
8429             }
8430             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
8431                 return false;
8432             }
8433             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8434                 return false;
8435             }
8436             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8437                 return false;
8438             }
8439             final PhylogenyNode n14 = PhylogenyNode
8440                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8441             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
8442                 return false;
8443             }
8444             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
8445                 return false;
8446             }
8447             final PhylogenyNode n15 = PhylogenyNode
8448                     .createInstanceFromNhxString( "something_wicked[123]",
8449                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8450             if ( !n15.getName().equals( "something_wicked" ) ) {
8451                 return false;
8452             }
8453             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
8454                 return false;
8455             }
8456             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
8457                 return false;
8458             }
8459             final PhylogenyNode n16 = PhylogenyNode
8460                     .createInstanceFromNhxString( "something_wicked2[9]",
8461                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8462             if ( !n16.getName().equals( "something_wicked2" ) ) {
8463                 return false;
8464             }
8465             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
8466                 return false;
8467             }
8468             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
8469                 return false;
8470             }
8471             final PhylogenyNode n17 = PhylogenyNode
8472                     .createInstanceFromNhxString( "something_wicked3[a]",
8473                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8474             if ( !n17.getName().equals( "something_wicked3" ) ) {
8475                 return false;
8476             }
8477             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
8478                 return false;
8479             }
8480             final PhylogenyNode n18 = PhylogenyNode
8481                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8482             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8483                 return false;
8484             }
8485             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8486                 return false;
8487             }
8488             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8489                 return false;
8490             }
8491             final PhylogenyNode n19 = PhylogenyNode
8492                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8493             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
8494                 return false;
8495             }
8496             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8497                 return false;
8498             }
8499             final PhylogenyNode n30 = PhylogenyNode
8500                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
8501                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8502             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
8503                 return false;
8504             }
8505             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8506                 return false;
8507             }
8508             final PhylogenyNode n31 = PhylogenyNode
8509                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
8510                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8511             if ( n31.getNodeData().isHasTaxonomy() ) {
8512                 return false;
8513             }
8514             final PhylogenyNode n32 = PhylogenyNode
8515                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8516             if ( n32.getNodeData().isHasTaxonomy() ) {
8517                 return false;
8518             }
8519             final PhylogenyNode n40 = PhylogenyNode
8520                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8521             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8522                 return false;
8523             }
8524             final PhylogenyNode n41 = PhylogenyNode
8525                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8526             if ( n41.getNodeData().isHasTaxonomy() ) {
8527                 return false;
8528             }
8529             final PhylogenyNode n42 = PhylogenyNode
8530                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8531             if ( n42.getNodeData().isHasTaxonomy() ) {
8532                 return false;
8533             }
8534             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
8535                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
8536             if ( n43.getNodeData().isHasTaxonomy() ) {
8537                 return false;
8538             }
8539             final PhylogenyNode n44 = PhylogenyNode
8540                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8541             if ( n44.getNodeData().isHasTaxonomy() ) {
8542                 return false;
8543             }
8544         }
8545         catch ( final Exception e ) {
8546             e.printStackTrace( System.out );
8547             return false;
8548         }
8549         return true;
8550     }
8551
8552     private static boolean testNHXParsing() {
8553         try {
8554             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8555             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
8556             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
8557                 return false;
8558             }
8559             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]";
8560             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
8561             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8562                 return false;
8563             }
8564             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]";
8565             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
8566             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
8567                 return false;
8568             }
8569             final Phylogeny[] p3 = factory
8570                     .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]",
8571                              new NHXParser() );
8572             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8573                 return false;
8574             }
8575             final Phylogeny[] p4 = factory
8576                     .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(]",
8577                              new NHXParser() );
8578             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8579                 return false;
8580             }
8581             final Phylogeny[] p5 = factory
8582                     .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(((]",
8583                              new NHXParser() );
8584             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8585                 return false;
8586             }
8587             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)";
8588             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)";
8589             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
8590             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
8591                 return false;
8592             }
8593             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)))";
8594             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)))";
8595             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
8596             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
8597                 return false;
8598             }
8599             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])   ))[,,, ])))))))";
8600             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
8601             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
8602             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
8603                 return false;
8604             }
8605             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
8606             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8607                 return false;
8608             }
8609             final Phylogeny p10 = factory
8610                     .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]",
8611                              new NHXParser() )[ 0 ];
8612             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8613                 return false;
8614             }
8615         }
8616         catch ( final Exception e ) {
8617             e.printStackTrace( System.out );
8618             return false;
8619         }
8620         return true;
8621     }
8622
8623     private static boolean testNHXParsingMB() {
8624         try {
8625             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8626             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
8627                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8628                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8629                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8630                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8631                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8632                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8633                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8634                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
8635             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
8636                 return false;
8637             }
8638             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
8639                 return false;
8640             }
8641             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8642                            0.1100000000000000e+00 ) ) {
8643                 return false;
8644             }
8645             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8646                 return false;
8647             }
8648             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8649                 return false;
8650             }
8651             final Phylogeny p2 = factory
8652                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8653                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8654                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8655                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8656                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8657                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8658                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8659                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8660                                      + "7.369400000000000e-02}])",
8661                              new NHXParser() )[ 0 ];
8662             if ( p2.getNode( "1" ) == null ) {
8663                 return false;
8664             }
8665             if ( p2.getNode( "2" ) == null ) {
8666                 return false;
8667             }
8668         }
8669         catch ( final Exception e ) {
8670             e.printStackTrace( System.out );
8671             System.exit( -1 );
8672             return false;
8673         }
8674         return true;
8675     }
8676
8677     private static boolean testNHXParsingQuotes() {
8678         try {
8679             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8680             final NHXParser p = new NHXParser();
8681             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8682             if ( phylogenies_0.length != 5 ) {
8683                 return false;
8684             }
8685             final Phylogeny phy = phylogenies_0[ 4 ];
8686             if ( phy.getNumberOfExternalNodes() != 7 ) {
8687                 return false;
8688             }
8689             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8690                 return false;
8691             }
8692             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8693                 return false;
8694             }
8695             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8696                     .getScientificName().equals( "hsapiens" ) ) {
8697                 return false;
8698             }
8699             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8700                 return false;
8701             }
8702             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8703                 return false;
8704             }
8705             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8706                 return false;
8707             }
8708             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8709                 return false;
8710             }
8711             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8712                 return false;
8713             }
8714             final NHXParser p1p = new NHXParser();
8715             p1p.setIgnoreQuotes( true );
8716             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8717             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8718                 return false;
8719             }
8720             final NHXParser p2p = new NHXParser();
8721             p1p.setIgnoreQuotes( false );
8722             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8723             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8724                 return false;
8725             }
8726             final NHXParser p3p = new NHXParser();
8727             p3p.setIgnoreQuotes( false );
8728             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8729             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8730                 return false;
8731             }
8732             final NHXParser p4p = new NHXParser();
8733             p4p.setIgnoreQuotes( false );
8734             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8735             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8736                 return false;
8737             }
8738             final Phylogeny p10 = factory
8739                     .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]",
8740                              new NHXParser() )[ 0 ];
8741             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]";
8742             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8743                 return false;
8744             }
8745             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8746             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8747                 return false;
8748             }
8749             //
8750             final Phylogeny p12 = factory
8751                     .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]",
8752                              new NHXParser() )[ 0 ];
8753             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]";
8754             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8755                 return false;
8756             }
8757             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8758             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8759                 return false;
8760             }
8761             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;";
8762             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8763                 return false;
8764             }
8765             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8766             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8767                 return false;
8768             }
8769         }
8770         catch ( final Exception e ) {
8771             e.printStackTrace( System.out );
8772             return false;
8773         }
8774         return true;
8775     }
8776
8777     private static boolean testNodeRemoval() {
8778         try {
8779             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8780             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8781             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8782             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8783                 return false;
8784             }
8785             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8786             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8787             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8788                 return false;
8789             }
8790             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8791             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8792             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8793                 return false;
8794             }
8795         }
8796         catch ( final Exception e ) {
8797             e.printStackTrace( System.out );
8798             return false;
8799         }
8800         return true;
8801     }
8802
8803     private static boolean testPhylogenyBranch() {
8804         try {
8805             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8806             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8807             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8808             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8809             if ( !a1b1.equals( a1b1 ) ) {
8810                 return false;
8811             }
8812             if ( !a1b1.equals( b1a1 ) ) {
8813                 return false;
8814             }
8815             if ( !b1a1.equals( a1b1 ) ) {
8816                 return false;
8817             }
8818             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8819             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8820             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8821             if ( a1_b1.equals( b1_a1 ) ) {
8822                 return false;
8823             }
8824             if ( a1_b1.equals( a1_b1_ ) ) {
8825                 return false;
8826             }
8827             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8828             if ( !a1_b1.equals( b1_a1_ ) ) {
8829                 return false;
8830             }
8831             if ( a1_b1_.equals( b1_a1_ ) ) {
8832                 return false;
8833             }
8834             if ( !a1_b1_.equals( b1_a1 ) ) {
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 testPhyloXMLparsingOfDistributionElement() {
8846         try {
8847             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8848             PhyloXmlParser xml_parser = null;
8849             try {
8850                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8851             }
8852             catch ( final Exception e ) {
8853                 // Do nothing -- means were not running from jar.
8854             }
8855             if ( xml_parser == null ) {
8856                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
8857                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8858                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8859                 }
8860                 else {
8861                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8862                 }
8863             }
8864             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8865                                                               xml_parser );
8866             if ( xml_parser.getErrorCount() > 0 ) {
8867                 System.out.println( xml_parser.getErrorMessages().toString() );
8868                 return false;
8869             }
8870             if ( phylogenies_0.length != 1 ) {
8871                 return false;
8872             }
8873             final Phylogeny t1 = phylogenies_0[ 0 ];
8874             PhylogenyNode n = null;
8875             Distribution d = null;
8876             n = t1.getNode( "root node" );
8877             if ( !n.getNodeData().isHasDistribution() ) {
8878                 return false;
8879             }
8880             if ( n.getNodeData().getDistributions().size() != 1 ) {
8881                 return false;
8882             }
8883             d = n.getNodeData().getDistribution();
8884             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8885                 return false;
8886             }
8887             if ( d.getPoints().size() != 1 ) {
8888                 return false;
8889             }
8890             if ( d.getPolygons() != null ) {
8891                 return false;
8892             }
8893             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8894                 return false;
8895             }
8896             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8897                 return false;
8898             }
8899             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8900                 return false;
8901             }
8902             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8903                 return false;
8904             }
8905             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8906                 return false;
8907             }
8908             n = t1.getNode( "node a" );
8909             if ( !n.getNodeData().isHasDistribution() ) {
8910                 return false;
8911             }
8912             if ( n.getNodeData().getDistributions().size() != 2 ) {
8913                 return false;
8914             }
8915             d = n.getNodeData().getDistribution( 1 );
8916             if ( !d.getDesc().equals( "San Diego" ) ) {
8917                 return false;
8918             }
8919             if ( d.getPoints().size() != 1 ) {
8920                 return false;
8921             }
8922             if ( d.getPolygons() != null ) {
8923                 return false;
8924             }
8925             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8926                 return false;
8927             }
8928             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8929                 return false;
8930             }
8931             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8932                 return false;
8933             }
8934             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8935                 return false;
8936             }
8937             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8938                 return false;
8939             }
8940             n = t1.getNode( "node bb" );
8941             if ( !n.getNodeData().isHasDistribution() ) {
8942                 return false;
8943             }
8944             if ( n.getNodeData().getDistributions().size() != 1 ) {
8945                 return false;
8946             }
8947             d = n.getNodeData().getDistribution( 0 );
8948             if ( d.getPoints().size() != 3 ) {
8949                 return false;
8950             }
8951             if ( d.getPolygons().size() != 2 ) {
8952                 return false;
8953             }
8954             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8955                 return false;
8956             }
8957             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8958                 return false;
8959             }
8960             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8961                 return false;
8962             }
8963             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8964                 return false;
8965             }
8966             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8967                 return false;
8968             }
8969             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8970                 return false;
8971             }
8972             Polygon p = d.getPolygons().get( 0 );
8973             if ( p.getPoints().size() != 3 ) {
8974                 return false;
8975             }
8976             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8977                 return false;
8978             }
8979             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8980                 return false;
8981             }
8982             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8983                 return false;
8984             }
8985             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8986                 return false;
8987             }
8988             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8989                 return false;
8990             }
8991             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8992                 return false;
8993             }
8994             p = d.getPolygons().get( 1 );
8995             if ( p.getPoints().size() != 3 ) {
8996                 return false;
8997             }
8998             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8999                 return false;
9000             }
9001             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9002                 return false;
9003             }
9004             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9005                 return false;
9006             }
9007             // Roundtrip:
9008             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9009             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9010             if ( rt.length != 1 ) {
9011                 return false;
9012             }
9013             final Phylogeny t1_rt = rt[ 0 ];
9014             n = t1_rt.getNode( "root node" );
9015             if ( !n.getNodeData().isHasDistribution() ) {
9016                 return false;
9017             }
9018             if ( n.getNodeData().getDistributions().size() != 1 ) {
9019                 return false;
9020             }
9021             d = n.getNodeData().getDistribution();
9022             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9023                 return false;
9024             }
9025             if ( d.getPoints().size() != 1 ) {
9026                 return false;
9027             }
9028             if ( d.getPolygons() != null ) {
9029                 return false;
9030             }
9031             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9032                 return false;
9033             }
9034             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9035                 return false;
9036             }
9037             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9038                 return false;
9039             }
9040             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9041                 return false;
9042             }
9043             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9044                 return false;
9045             }
9046             n = t1_rt.getNode( "node a" );
9047             if ( !n.getNodeData().isHasDistribution() ) {
9048                 return false;
9049             }
9050             if ( n.getNodeData().getDistributions().size() != 2 ) {
9051                 return false;
9052             }
9053             d = n.getNodeData().getDistribution( 1 );
9054             if ( !d.getDesc().equals( "San Diego" ) ) {
9055                 return false;
9056             }
9057             if ( d.getPoints().size() != 1 ) {
9058                 return false;
9059             }
9060             if ( d.getPolygons() != null ) {
9061                 return false;
9062             }
9063             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9064                 return false;
9065             }
9066             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9067                 return false;
9068             }
9069             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9070                 return false;
9071             }
9072             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9073                 return false;
9074             }
9075             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9076                 return false;
9077             }
9078             n = t1_rt.getNode( "node bb" );
9079             if ( !n.getNodeData().isHasDistribution() ) {
9080                 return false;
9081             }
9082             if ( n.getNodeData().getDistributions().size() != 1 ) {
9083                 return false;
9084             }
9085             d = n.getNodeData().getDistribution( 0 );
9086             if ( d.getPoints().size() != 3 ) {
9087                 return false;
9088             }
9089             if ( d.getPolygons().size() != 2 ) {
9090                 return false;
9091             }
9092             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9093                 return false;
9094             }
9095             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9096                 return false;
9097             }
9098             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9099                 return false;
9100             }
9101             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9102                 return false;
9103             }
9104             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9105                 return false;
9106             }
9107             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9108                 return false;
9109             }
9110             p = d.getPolygons().get( 0 );
9111             if ( p.getPoints().size() != 3 ) {
9112                 return false;
9113             }
9114             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9115                 return false;
9116             }
9117             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9118                 return false;
9119             }
9120             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9121                 return false;
9122             }
9123             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9124                 return false;
9125             }
9126             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9127                 return false;
9128             }
9129             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9130                 return false;
9131             }
9132             p = d.getPolygons().get( 1 );
9133             if ( p.getPoints().size() != 3 ) {
9134                 return false;
9135             }
9136             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9137                 return false;
9138             }
9139             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9140                 return false;
9141             }
9142             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9143                 return false;
9144             }
9145         }
9146         catch ( final Exception e ) {
9147             e.printStackTrace( System.out );
9148             return false;
9149         }
9150         return true;
9151     }
9152
9153     private static boolean testPostOrderIterator() {
9154         try {
9155             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9156             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9157             PhylogenyNodeIterator it0;
9158             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9159                 it0.next();
9160             }
9161             for( it0.reset(); it0.hasNext(); ) {
9162                 it0.next();
9163             }
9164             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9165             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9166             if ( !it.next().getName().equals( "A" ) ) {
9167                 return false;
9168             }
9169             if ( !it.next().getName().equals( "B" ) ) {
9170                 return false;
9171             }
9172             if ( !it.next().getName().equals( "ab" ) ) {
9173                 return false;
9174             }
9175             if ( !it.next().getName().equals( "C" ) ) {
9176                 return false;
9177             }
9178             if ( !it.next().getName().equals( "D" ) ) {
9179                 return false;
9180             }
9181             if ( !it.next().getName().equals( "cd" ) ) {
9182                 return false;
9183             }
9184             if ( !it.next().getName().equals( "abcd" ) ) {
9185                 return false;
9186             }
9187             if ( !it.next().getName().equals( "E" ) ) {
9188                 return false;
9189             }
9190             if ( !it.next().getName().equals( "F" ) ) {
9191                 return false;
9192             }
9193             if ( !it.next().getName().equals( "ef" ) ) {
9194                 return false;
9195             }
9196             if ( !it.next().getName().equals( "G" ) ) {
9197                 return false;
9198             }
9199             if ( !it.next().getName().equals( "H" ) ) {
9200                 return false;
9201             }
9202             if ( !it.next().getName().equals( "gh" ) ) {
9203                 return false;
9204             }
9205             if ( !it.next().getName().equals( "efgh" ) ) {
9206                 return false;
9207             }
9208             if ( !it.next().getName().equals( "r" ) ) {
9209                 return false;
9210             }
9211             if ( it.hasNext() ) {
9212                 return false;
9213             }
9214         }
9215         catch ( final Exception e ) {
9216             e.printStackTrace( System.out );
9217             return false;
9218         }
9219         return true;
9220     }
9221
9222     private static boolean testPreOrderIterator() {
9223         try {
9224             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9225             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9226             PhylogenyNodeIterator it0;
9227             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9228                 it0.next();
9229             }
9230             for( it0.reset(); it0.hasNext(); ) {
9231                 it0.next();
9232             }
9233             PhylogenyNodeIterator it = t0.iteratorPreorder();
9234             if ( !it.next().getName().equals( "r" ) ) {
9235                 return false;
9236             }
9237             if ( !it.next().getName().equals( "ab" ) ) {
9238                 return false;
9239             }
9240             if ( !it.next().getName().equals( "A" ) ) {
9241                 return false;
9242             }
9243             if ( !it.next().getName().equals( "B" ) ) {
9244                 return false;
9245             }
9246             if ( !it.next().getName().equals( "cd" ) ) {
9247                 return false;
9248             }
9249             if ( !it.next().getName().equals( "C" ) ) {
9250                 return false;
9251             }
9252             if ( !it.next().getName().equals( "D" ) ) {
9253                 return false;
9254             }
9255             if ( it.hasNext() ) {
9256                 return false;
9257             }
9258             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9259             it = t1.iteratorPreorder();
9260             if ( !it.next().getName().equals( "r" ) ) {
9261                 return false;
9262             }
9263             if ( !it.next().getName().equals( "abcd" ) ) {
9264                 return false;
9265             }
9266             if ( !it.next().getName().equals( "ab" ) ) {
9267                 return false;
9268             }
9269             if ( !it.next().getName().equals( "A" ) ) {
9270                 return false;
9271             }
9272             if ( !it.next().getName().equals( "B" ) ) {
9273                 return false;
9274             }
9275             if ( !it.next().getName().equals( "cd" ) ) {
9276                 return false;
9277             }
9278             if ( !it.next().getName().equals( "C" ) ) {
9279                 return false;
9280             }
9281             if ( !it.next().getName().equals( "D" ) ) {
9282                 return false;
9283             }
9284             if ( !it.next().getName().equals( "efgh" ) ) {
9285                 return false;
9286             }
9287             if ( !it.next().getName().equals( "ef" ) ) {
9288                 return false;
9289             }
9290             if ( !it.next().getName().equals( "E" ) ) {
9291                 return false;
9292             }
9293             if ( !it.next().getName().equals( "F" ) ) {
9294                 return false;
9295             }
9296             if ( !it.next().getName().equals( "gh" ) ) {
9297                 return false;
9298             }
9299             if ( !it.next().getName().equals( "G" ) ) {
9300                 return false;
9301             }
9302             if ( !it.next().getName().equals( "H" ) ) {
9303                 return false;
9304             }
9305             if ( it.hasNext() ) {
9306                 return false;
9307             }
9308         }
9309         catch ( final Exception e ) {
9310             e.printStackTrace( System.out );
9311             return false;
9312         }
9313         return true;
9314     }
9315
9316     private static boolean testPropertiesMap() {
9317         try {
9318             final PropertiesMap pm = new PropertiesMap();
9319             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9320             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9321             final Property p2 = new Property( "something:else",
9322                                               "?",
9323                                               "improbable:research",
9324                                               "xsd:decimal",
9325                                               AppliesTo.NODE );
9326             pm.addProperty( p0 );
9327             pm.addProperty( p1 );
9328             pm.addProperty( p2 );
9329             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9330                 return false;
9331             }
9332             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9333                 return false;
9334             }
9335             if ( pm.getProperties().size() != 3 ) {
9336                 return false;
9337             }
9338             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9339                 return false;
9340             }
9341             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9342                 return false;
9343             }
9344             if ( pm.getProperties().size() != 3 ) {
9345                 return false;
9346             }
9347             pm.removeProperty( "dimensions:diameter" );
9348             if ( pm.getProperties().size() != 2 ) {
9349                 return false;
9350             }
9351             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
9352                 return false;
9353             }
9354             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9355                 return false;
9356             }
9357         }
9358         catch ( final Exception e ) {
9359             e.printStackTrace( System.out );
9360             return false;
9361         }
9362         return true;
9363     }
9364
9365     private static boolean testProteinId() {
9366         try {
9367             final ProteinId id1 = new ProteinId( "a" );
9368             final ProteinId id2 = new ProteinId( "a" );
9369             final ProteinId id3 = new ProteinId( "A" );
9370             final ProteinId id4 = new ProteinId( "b" );
9371             if ( !id1.equals( id1 ) ) {
9372                 return false;
9373             }
9374             if ( id1.getId().equals( "x" ) ) {
9375                 return false;
9376             }
9377             if ( id1.getId().equals( null ) ) {
9378                 return false;
9379             }
9380             if ( !id1.equals( id2 ) ) {
9381                 return false;
9382             }
9383             if ( id1.equals( id3 ) ) {
9384                 return false;
9385             }
9386             if ( id1.hashCode() != id1.hashCode() ) {
9387                 return false;
9388             }
9389             if ( id1.hashCode() != id2.hashCode() ) {
9390                 return false;
9391             }
9392             if ( id1.hashCode() == id3.hashCode() ) {
9393                 return false;
9394             }
9395             if ( id1.compareTo( id1 ) != 0 ) {
9396                 return false;
9397             }
9398             if ( id1.compareTo( id2 ) != 0 ) {
9399                 return false;
9400             }
9401             if ( id1.compareTo( id3 ) != 0 ) {
9402                 return false;
9403             }
9404             if ( id1.compareTo( id4 ) >= 0 ) {
9405                 return false;
9406             }
9407             if ( id4.compareTo( id1 ) <= 0 ) {
9408                 return false;
9409             }
9410             if ( !id4.getId().equals( "b" ) ) {
9411                 return false;
9412             }
9413             final ProteinId id5 = new ProteinId( " C " );
9414             if ( !id5.getId().equals( "C" ) ) {
9415                 return false;
9416             }
9417             if ( id5.equals( id1 ) ) {
9418                 return false;
9419             }
9420         }
9421         catch ( final Exception e ) {
9422             e.printStackTrace( System.out );
9423             return false;
9424         }
9425         return true;
9426     }
9427
9428     private static boolean testReIdMethods() {
9429         try {
9430             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9431             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
9432             final long count = PhylogenyNode.getNodeCount();
9433             p.levelOrderReID();
9434             if ( p.getNode( "r" ).getId() != count ) {
9435                 return false;
9436             }
9437             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
9438                 return false;
9439             }
9440             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
9441                 return false;
9442             }
9443             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
9444                 return false;
9445             }
9446             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
9447                 return false;
9448             }
9449             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
9450                 return false;
9451             }
9452             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
9453                 return false;
9454             }
9455             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
9456                 return false;
9457             }
9458             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
9459                 return false;
9460             }
9461             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
9462                 return false;
9463             }
9464             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
9465                 return false;
9466             }
9467             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
9468                 return false;
9469             }
9470             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
9471                 return false;
9472             }
9473             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
9474                 return false;
9475             }
9476             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
9477                 return false;
9478             }
9479         }
9480         catch ( final Exception e ) {
9481             e.printStackTrace( System.out );
9482             return false;
9483         }
9484         return true;
9485     }
9486
9487     private static boolean testRerooting() {
9488         try {
9489             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9490             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",
9491                                                  new NHXParser() )[ 0 ];
9492             if ( !t1.isRooted() ) {
9493                 return false;
9494             }
9495             t1.reRoot( t1.getNode( "D" ) );
9496             t1.reRoot( t1.getNode( "CD" ) );
9497             t1.reRoot( t1.getNode( "A" ) );
9498             t1.reRoot( t1.getNode( "B" ) );
9499             t1.reRoot( t1.getNode( "AB" ) );
9500             t1.reRoot( t1.getNode( "D" ) );
9501             t1.reRoot( t1.getNode( "C" ) );
9502             t1.reRoot( t1.getNode( "CD" ) );
9503             t1.reRoot( t1.getNode( "A" ) );
9504             t1.reRoot( t1.getNode( "B" ) );
9505             t1.reRoot( t1.getNode( "AB" ) );
9506             t1.reRoot( t1.getNode( "D" ) );
9507             t1.reRoot( t1.getNode( "D" ) );
9508             t1.reRoot( t1.getNode( "C" ) );
9509             t1.reRoot( t1.getNode( "A" ) );
9510             t1.reRoot( t1.getNode( "B" ) );
9511             t1.reRoot( t1.getNode( "AB" ) );
9512             t1.reRoot( t1.getNode( "C" ) );
9513             t1.reRoot( t1.getNode( "D" ) );
9514             t1.reRoot( t1.getNode( "CD" ) );
9515             t1.reRoot( t1.getNode( "D" ) );
9516             t1.reRoot( t1.getNode( "A" ) );
9517             t1.reRoot( t1.getNode( "B" ) );
9518             t1.reRoot( t1.getNode( "AB" ) );
9519             t1.reRoot( t1.getNode( "C" ) );
9520             t1.reRoot( t1.getNode( "D" ) );
9521             t1.reRoot( t1.getNode( "CD" ) );
9522             t1.reRoot( t1.getNode( "D" ) );
9523             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
9524                 return false;
9525             }
9526             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
9527                 return false;
9528             }
9529             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
9530                 return false;
9531             }
9532             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
9533                 return false;
9534             }
9535             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
9536                 return false;
9537             }
9538             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
9539                 return false;
9540             }
9541             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",
9542                                                  new NHXParser() )[ 0 ];
9543             t2.reRoot( t2.getNode( "A" ) );
9544             t2.reRoot( t2.getNode( "D" ) );
9545             t2.reRoot( t2.getNode( "ABC" ) );
9546             t2.reRoot( t2.getNode( "A" ) );
9547             t2.reRoot( t2.getNode( "B" ) );
9548             t2.reRoot( t2.getNode( "D" ) );
9549             t2.reRoot( t2.getNode( "C" ) );
9550             t2.reRoot( t2.getNode( "ABC" ) );
9551             t2.reRoot( t2.getNode( "A" ) );
9552             t2.reRoot( t2.getNode( "B" ) );
9553             t2.reRoot( t2.getNode( "AB" ) );
9554             t2.reRoot( t2.getNode( "AB" ) );
9555             t2.reRoot( t2.getNode( "D" ) );
9556             t2.reRoot( t2.getNode( "C" ) );
9557             t2.reRoot( t2.getNode( "B" ) );
9558             t2.reRoot( t2.getNode( "AB" ) );
9559             t2.reRoot( t2.getNode( "D" ) );
9560             t2.reRoot( t2.getNode( "D" ) );
9561             t2.reRoot( t2.getNode( "ABC" ) );
9562             t2.reRoot( t2.getNode( "A" ) );
9563             t2.reRoot( t2.getNode( "B" ) );
9564             t2.reRoot( t2.getNode( "AB" ) );
9565             t2.reRoot( t2.getNode( "D" ) );
9566             t2.reRoot( t2.getNode( "C" ) );
9567             t2.reRoot( t2.getNode( "ABC" ) );
9568             t2.reRoot( t2.getNode( "A" ) );
9569             t2.reRoot( t2.getNode( "B" ) );
9570             t2.reRoot( t2.getNode( "AB" ) );
9571             t2.reRoot( t2.getNode( "D" ) );
9572             t2.reRoot( t2.getNode( "D" ) );
9573             t2.reRoot( t2.getNode( "C" ) );
9574             t2.reRoot( t2.getNode( "A" ) );
9575             t2.reRoot( t2.getNode( "B" ) );
9576             t2.reRoot( t2.getNode( "AB" ) );
9577             t2.reRoot( t2.getNode( "C" ) );
9578             t2.reRoot( t2.getNode( "D" ) );
9579             t2.reRoot( t2.getNode( "ABC" ) );
9580             t2.reRoot( t2.getNode( "D" ) );
9581             t2.reRoot( t2.getNode( "A" ) );
9582             t2.reRoot( t2.getNode( "B" ) );
9583             t2.reRoot( t2.getNode( "AB" ) );
9584             t2.reRoot( t2.getNode( "C" ) );
9585             t2.reRoot( t2.getNode( "D" ) );
9586             t2.reRoot( t2.getNode( "ABC" ) );
9587             t2.reRoot( t2.getNode( "D" ) );
9588             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9589                 return false;
9590             }
9591             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9592                 return false;
9593             }
9594             t2.reRoot( t2.getNode( "ABC" ) );
9595             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9596                 return false;
9597             }
9598             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9599                 return false;
9600             }
9601             t2.reRoot( t2.getNode( "AB" ) );
9602             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9603                 return false;
9604             }
9605             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9606                 return false;
9607             }
9608             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9609                 return false;
9610             }
9611             t2.reRoot( t2.getNode( "AB" ) );
9612             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9613                 return false;
9614             }
9615             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9616                 return false;
9617             }
9618             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9619                 return false;
9620             }
9621             t2.reRoot( t2.getNode( "D" ) );
9622             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9623                 return false;
9624             }
9625             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9626                 return false;
9627             }
9628             t2.reRoot( t2.getNode( "ABC" ) );
9629             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9630                 return false;
9631             }
9632             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9633                 return false;
9634             }
9635             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
9636                                                  new NHXParser() )[ 0 ];
9637             t3.reRoot( t3.getNode( "B" ) );
9638             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9639                 return false;
9640             }
9641             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9642                 return false;
9643             }
9644             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9645                 return false;
9646             }
9647             t3.reRoot( t3.getNode( "B" ) );
9648             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9649                 return false;
9650             }
9651             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9652                 return false;
9653             }
9654             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9655                 return false;
9656             }
9657             t3.reRoot( t3.getRoot() );
9658             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9659                 return false;
9660             }
9661             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9662                 return false;
9663             }
9664             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9665                 return false;
9666             }
9667         }
9668         catch ( final Exception e ) {
9669             e.printStackTrace( System.out );
9670             return false;
9671         }
9672         return true;
9673     }
9674
9675     private static boolean testSDIse() {
9676         try {
9677             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9678             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9679             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9680             gene1.setRooted( true );
9681             species1.setRooted( true );
9682             final SDI sdi = new SDI( gene1, species1 );
9683             if ( !gene1.getRoot().isDuplication() ) {
9684                 return false;
9685             }
9686             final Phylogeny species2 = factory
9687                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9688                              new NHXParser() )[ 0 ];
9689             final Phylogeny gene2 = factory
9690                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9691                              new NHXParser() )[ 0 ];
9692             species2.setRooted( true );
9693             gene2.setRooted( true );
9694             final SDI sdi2 = new SDI( gene2, species2 );
9695             if ( sdi2.getDuplicationsSum() != 0 ) {
9696                 return false;
9697             }
9698             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9699                 return false;
9700             }
9701             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9702                 return false;
9703             }
9704             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9705                 return false;
9706             }
9707             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9708                 return false;
9709             }
9710             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9711                 return false;
9712             }
9713             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9714                 return false;
9715             }
9716             final Phylogeny species3 = factory
9717                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9718                              new NHXParser() )[ 0 ];
9719             final Phylogeny gene3 = factory
9720                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9721                              new NHXParser() )[ 0 ];
9722             species3.setRooted( true );
9723             gene3.setRooted( true );
9724             final SDI sdi3 = new SDI( gene3, species3 );
9725             if ( sdi3.getDuplicationsSum() != 1 ) {
9726                 return false;
9727             }
9728             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9729                 return false;
9730             }
9731             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9732                 return false;
9733             }
9734             final Phylogeny species4 = factory
9735                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9736                              new NHXParser() )[ 0 ];
9737             final Phylogeny gene4 = factory
9738                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9739                              new NHXParser() )[ 0 ];
9740             species4.setRooted( true );
9741             gene4.setRooted( true );
9742             final SDI sdi4 = new SDI( gene4, species4 );
9743             if ( sdi4.getDuplicationsSum() != 1 ) {
9744                 return false;
9745             }
9746             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9747                 return false;
9748             }
9749             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9750                 return false;
9751             }
9752             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9753                 return false;
9754             }
9755             if ( species4.getNumberOfExternalNodes() != 6 ) {
9756                 return false;
9757             }
9758             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9759                 return false;
9760             }
9761             final Phylogeny species5 = factory
9762                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9763                              new NHXParser() )[ 0 ];
9764             final Phylogeny gene5 = factory
9765                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9766                              new NHXParser() )[ 0 ];
9767             species5.setRooted( true );
9768             gene5.setRooted( true );
9769             final SDI sdi5 = new SDI( gene5, species5 );
9770             if ( sdi5.getDuplicationsSum() != 2 ) {
9771                 return false;
9772             }
9773             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9774                 return false;
9775             }
9776             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9777                 return false;
9778             }
9779             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9780                 return false;
9781             }
9782             if ( species5.getNumberOfExternalNodes() != 6 ) {
9783                 return false;
9784             }
9785             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9786                 return false;
9787             }
9788             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9789             // Conjecture for Comparing Molecular Phylogenies"
9790             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9791             final Phylogeny species6 = factory
9792                     .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,"
9793                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9794                              new NHXParser() )[ 0 ];
9795             final Phylogeny gene6 = factory
9796                     .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,"
9797                                      + "((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,"
9798                                      + "(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;",
9799                              new NHXParser() )[ 0 ];
9800             species6.setRooted( true );
9801             gene6.setRooted( true );
9802             final SDI sdi6 = new SDI( gene6, species6 );
9803             if ( sdi6.getDuplicationsSum() != 3 ) {
9804                 return false;
9805             }
9806             if ( !gene6.getNode( "r" ).isDuplication() ) {
9807                 return false;
9808             }
9809             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9810                 return false;
9811             }
9812             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9813                 return false;
9814             }
9815             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9816                 return false;
9817             }
9818             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9819                 return false;
9820             }
9821             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9822                 return false;
9823             }
9824             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9825                 return false;
9826             }
9827             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9828                 return false;
9829             }
9830             sdi6.computeMappingCostL();
9831             if ( sdi6.computeMappingCostL() != 17 ) {
9832                 return false;
9833             }
9834             if ( species6.getNumberOfExternalNodes() != 9 ) {
9835                 return false;
9836             }
9837             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9838                 return false;
9839             }
9840             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9841                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9842                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9843                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9844                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9845             species7.setRooted( true );
9846             final Phylogeny gene7_1 = Test
9847                     .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])" );
9848             gene7_1.setRooted( true );
9849             final SDI sdi7 = new SDI( gene7_1, species7 );
9850             if ( sdi7.getDuplicationsSum() != 0 ) {
9851                 return false;
9852             }
9853             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9854                 return false;
9855             }
9856             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9857                 return false;
9858             }
9859             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9860                 return false;
9861             }
9862             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9863                 return false;
9864             }
9865             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9866                 return false;
9867             }
9868             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9869                 return false;
9870             }
9871             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9872                 return false;
9873             }
9874             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9875                 return false;
9876             }
9877             final Phylogeny gene7_2 = Test
9878                     .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])" );
9879             gene7_2.setRooted( true );
9880             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9881             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9882                 return false;
9883             }
9884             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9885                 return false;
9886             }
9887             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9888                 return false;
9889             }
9890             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9891                 return false;
9892             }
9893             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9894                 return false;
9895             }
9896             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9897                 return false;
9898             }
9899             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9900                 return false;
9901             }
9902             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9903                 return false;
9904             }
9905             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9906                 return false;
9907             }
9908             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9909                 return false;
9910             }
9911         }
9912         catch ( final Exception e ) {
9913             return false;
9914         }
9915         return true;
9916     }
9917
9918     private static boolean testSDIunrooted() {
9919         try {
9920             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9921             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9922             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9923             final Iterator<PhylogenyBranch> iter = l.iterator();
9924             PhylogenyBranch br = iter.next();
9925             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9926                 return false;
9927             }
9928             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9929                 return false;
9930             }
9931             br = iter.next();
9932             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9933                 return false;
9934             }
9935             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9936                 return false;
9937             }
9938             br = iter.next();
9939             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9940                 return false;
9941             }
9942             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9943                 return false;
9944             }
9945             br = iter.next();
9946             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9947                 return false;
9948             }
9949             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9950                 return false;
9951             }
9952             br = iter.next();
9953             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9954                 return false;
9955             }
9956             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9957                 return false;
9958             }
9959             br = iter.next();
9960             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9961                 return false;
9962             }
9963             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9964                 return false;
9965             }
9966             br = iter.next();
9967             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9968                 return false;
9969             }
9970             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9971                 return false;
9972             }
9973             br = iter.next();
9974             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9975                 return false;
9976             }
9977             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9978                 return false;
9979             }
9980             br = iter.next();
9981             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9982                 return false;
9983             }
9984             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9985                 return false;
9986             }
9987             br = iter.next();
9988             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9989                 return false;
9990             }
9991             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9992                 return false;
9993             }
9994             br = iter.next();
9995             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9996                 return false;
9997             }
9998             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9999                 return false;
10000             }
10001             br = iter.next();
10002             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10003                 return false;
10004             }
10005             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10006                 return false;
10007             }
10008             br = iter.next();
10009             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10010                 return false;
10011             }
10012             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10013                 return false;
10014             }
10015             br = iter.next();
10016             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10017                 return false;
10018             }
10019             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10020                 return false;
10021             }
10022             br = iter.next();
10023             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10024                 return false;
10025             }
10026             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10027                 return false;
10028             }
10029             if ( iter.hasNext() ) {
10030                 return false;
10031             }
10032             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10033             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10034             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10035             br = iter1.next();
10036             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10037                 return false;
10038             }
10039             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10040                 return false;
10041             }
10042             br = iter1.next();
10043             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10044                 return false;
10045             }
10046             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10047                 return false;
10048             }
10049             br = iter1.next();
10050             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10051                 return false;
10052             }
10053             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10054                 return false;
10055             }
10056             if ( iter1.hasNext() ) {
10057                 return false;
10058             }
10059             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10060             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10061             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10062             br = iter2.next();
10063             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10064                 return false;
10065             }
10066             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10067                 return false;
10068             }
10069             br = iter2.next();
10070             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10071                 return false;
10072             }
10073             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10074                 return false;
10075             }
10076             br = iter2.next();
10077             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10078                 return false;
10079             }
10080             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10081                 return false;
10082             }
10083             if ( iter2.hasNext() ) {
10084                 return false;
10085             }
10086             final Phylogeny species0 = factory
10087                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10088                              new NHXParser() )[ 0 ];
10089             final Phylogeny gene1 = factory
10090                     .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])",
10091                              new NHXParser() )[ 0 ];
10092             species0.setRooted( true );
10093             gene1.setRooted( true );
10094             final SDIR sdi_unrooted = new SDIR();
10095             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10096             if ( sdi_unrooted.getCount() != 1 ) {
10097                 return false;
10098             }
10099             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10100                 return false;
10101             }
10102             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10103                 return false;
10104             }
10105             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10106                 return false;
10107             }
10108             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10109                 return false;
10110             }
10111             final Phylogeny gene2 = factory
10112                     .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])",
10113                              new NHXParser() )[ 0 ];
10114             gene2.setRooted( true );
10115             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10116             if ( sdi_unrooted.getCount() != 1 ) {
10117                 return false;
10118             }
10119             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10120                 return false;
10121             }
10122             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10123                 return false;
10124             }
10125             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10126                 return false;
10127             }
10128             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10129                 return false;
10130             }
10131             final Phylogeny species6 = factory
10132                     .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,"
10133                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10134                              new NHXParser() )[ 0 ];
10135             final Phylogeny gene6 = factory
10136                     .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],"
10137                                      + "(((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],"
10138                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10139                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10140                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10141                              new NHXParser() )[ 0 ];
10142             species6.setRooted( true );
10143             gene6.setRooted( true );
10144             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10145             if ( sdi_unrooted.getCount() != 1 ) {
10146                 return false;
10147             }
10148             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10149                 return false;
10150             }
10151             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10152                 return false;
10153             }
10154             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10155                 return false;
10156             }
10157             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10158                 return false;
10159             }
10160             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10161                 return false;
10162             }
10163             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10164                 return false;
10165             }
10166             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10167                 return false;
10168             }
10169             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10170                 return false;
10171             }
10172             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10173                 return false;
10174             }
10175             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10176                 return false;
10177             }
10178             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10179                 return false;
10180             }
10181             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10182                 return false;
10183             }
10184             p6 = null;
10185             final Phylogeny species7 = factory
10186                     .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,"
10187                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10188                              new NHXParser() )[ 0 ];
10189             final Phylogeny gene7 = factory
10190                     .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],"
10191                                      + "(((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],"
10192                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10193                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10194                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10195                              new NHXParser() )[ 0 ];
10196             species7.setRooted( true );
10197             gene7.setRooted( true );
10198             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10199             if ( sdi_unrooted.getCount() != 1 ) {
10200                 return false;
10201             }
10202             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10203                 return false;
10204             }
10205             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10206                 return false;
10207             }
10208             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10209                 return false;
10210             }
10211             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10212                 return false;
10213             }
10214             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10215                 return false;
10216             }
10217             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10218                 return false;
10219             }
10220             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10221                 return false;
10222             }
10223             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10224                 return false;
10225             }
10226             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10227                 return false;
10228             }
10229             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10230                 return false;
10231             }
10232             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10233                 return false;
10234             }
10235             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10236                 return false;
10237             }
10238             p7 = null;
10239             final Phylogeny species8 = factory
10240                     .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,"
10241                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10242                              new NHXParser() )[ 0 ];
10243             final Phylogeny gene8 = factory
10244                     .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],"
10245                                      + "(((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],"
10246                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10247                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10248                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10249                              new NHXParser() )[ 0 ];
10250             species8.setRooted( true );
10251             gene8.setRooted( true );
10252             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10253             if ( sdi_unrooted.getCount() != 1 ) {
10254                 return false;
10255             }
10256             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10257                 return false;
10258             }
10259             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10260                 return false;
10261             }
10262             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10263                 return false;
10264             }
10265             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10266                 return false;
10267             }
10268             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10269                 return false;
10270             }
10271             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10272                 return false;
10273             }
10274             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10275                 return false;
10276             }
10277             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10278                 return false;
10279             }
10280             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10281                 return false;
10282             }
10283             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10284                 return false;
10285             }
10286             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10287                 return false;
10288             }
10289             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10290                 return false;
10291             }
10292             p8 = null;
10293         }
10294         catch ( final Exception e ) {
10295             e.printStackTrace( System.out );
10296             return false;
10297         }
10298         return true;
10299     }
10300
10301     private static boolean testSequenceDbWsTools1() {
10302         try {
10303             final PhylogenyNode n = new PhylogenyNode();
10304             n.setName( "NP_001025424" );
10305             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10306             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10307                     || !acc.getValue().equals( "NP_001025424" ) ) {
10308                 return false;
10309             }
10310             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10311             acc = SequenceDbWsTools.obtainSeqAccession( n );
10312             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10313                     || !acc.getValue().equals( "NP_001025424" ) ) {
10314                 return false;
10315             }
10316             n.setName( "NP_001025424.1" );
10317             acc = SequenceDbWsTools.obtainSeqAccession( n );
10318             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10319                     || !acc.getValue().equals( "NP_001025424" ) ) {
10320                 return false;
10321             }
10322             n.setName( "NM_001030253" );
10323             acc = SequenceDbWsTools.obtainSeqAccession( n );
10324             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10325                     || !acc.getValue().equals( "NM_001030253" ) ) {
10326                 return false;
10327             }
10328             n.setName( "BCL2_HUMAN" );
10329             acc = SequenceDbWsTools.obtainSeqAccession( n );
10330             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10331                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10332                 System.out.println( acc.toString() );
10333                 return false;
10334             }
10335             n.setName( "P10415" );
10336             acc = SequenceDbWsTools.obtainSeqAccession( n );
10337             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10338                     || !acc.getValue().equals( "P10415" ) ) {
10339                 System.out.println( acc.toString() );
10340                 return false;
10341             }
10342             n.setName( " P10415 " );
10343             acc = SequenceDbWsTools.obtainSeqAccession( n );
10344             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10345                     || !acc.getValue().equals( "P10415" ) ) {
10346                 System.out.println( acc.toString() );
10347                 return false;
10348             }
10349             n.setName( "_P10415|" );
10350             acc = SequenceDbWsTools.obtainSeqAccession( n );
10351             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10352                     || !acc.getValue().equals( "P10415" ) ) {
10353                 System.out.println( acc.toString() );
10354                 return false;
10355             }
10356             n.setName( "AY695820" );
10357             acc = SequenceDbWsTools.obtainSeqAccession( n );
10358             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10359                     || !acc.getValue().equals( "AY695820" ) ) {
10360                 System.out.println( acc.toString() );
10361                 return false;
10362             }
10363             n.setName( "_AY695820_" );
10364             acc = SequenceDbWsTools.obtainSeqAccession( n );
10365             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10366                     || !acc.getValue().equals( "AY695820" ) ) {
10367                 System.out.println( acc.toString() );
10368                 return false;
10369             }
10370             n.setName( "AAA59452" );
10371             acc = SequenceDbWsTools.obtainSeqAccession( n );
10372             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10373                     || !acc.getValue().equals( "AAA59452" ) ) {
10374                 System.out.println( acc.toString() );
10375                 return false;
10376             }
10377             n.setName( "_AAA59452_" );
10378             acc = SequenceDbWsTools.obtainSeqAccession( n );
10379             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10380                     || !acc.getValue().equals( "AAA59452" ) ) {
10381                 System.out.println( acc.toString() );
10382                 return false;
10383             }
10384             n.setName( "AAA59452.1" );
10385             acc = SequenceDbWsTools.obtainSeqAccession( n );
10386             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10387                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10388                 System.out.println( acc.toString() );
10389                 return false;
10390             }
10391             n.setName( "_AAA59452.1_" );
10392             acc = SequenceDbWsTools.obtainSeqAccession( n );
10393             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10394                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10395                 System.out.println( acc.toString() );
10396                 return false;
10397             }
10398             n.setName( "GI:94894583" );
10399             acc = SequenceDbWsTools.obtainSeqAccession( n );
10400             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10401                     || !acc.getValue().equals( "94894583" ) ) {
10402                 System.out.println( acc.toString() );
10403                 return false;
10404             }
10405             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10406             acc = SequenceDbWsTools.obtainSeqAccession( n );
10407             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10408                     || !acc.getValue().equals( "71845847" ) ) {
10409                 System.out.println( acc.toString() );
10410                 return false;
10411             }
10412             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10413             acc = SequenceDbWsTools.obtainSeqAccession( n );
10414             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10415                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
10416                 System.out.println( acc.toString() );
10417                 return false;
10418             }
10419         }
10420         catch ( final Exception e ) {
10421             return false;
10422         }
10423         return true;
10424     }
10425
10426     private static boolean testSequenceDbWsTools2() {
10427         try {
10428             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
10429             SequenceDbWsTools.obtainSeqInformation( n1 );
10430             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10431                 return false;
10432             }
10433             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10434                 return false;
10435             }
10436             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10437                 return false;
10438             }
10439             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
10440                 return false;
10441             }
10442             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
10443             SequenceDbWsTools.obtainSeqInformation( n2 );
10444             if ( !n2.getNodeData().getSequence().getName()
10445                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
10446                 return false;
10447             }
10448             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10449                 return false;
10450             }
10451             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10452                 return false;
10453             }
10454             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
10455                 return false;
10456             }
10457             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
10458             SequenceDbWsTools.obtainSeqInformation( n3 );
10459             if ( !n3.getNodeData().getSequence().getName()
10460                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
10461                 return false;
10462             }
10463             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
10464                 return false;
10465             }
10466             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10467                 return false;
10468             }
10469             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
10470                 return false;
10471             }
10472         }
10473         catch ( final IOException e ) {
10474             System.out.println();
10475             System.out.println( "the following might be due to absence internet connection:" );
10476             e.printStackTrace( System.out );
10477             return true;
10478         }
10479         catch ( final Exception e ) {
10480             e.printStackTrace();
10481             return false;
10482         }
10483         return true;
10484     }
10485
10486     private static boolean testSequenceIdParsing() {
10487         try {
10488             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
10489             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10490                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10491                 if ( id != null ) {
10492                     System.out.println( "value   =" + id.getValue() );
10493                     System.out.println( "provider=" + id.getSource() );
10494                 }
10495                 return false;
10496             }
10497             //
10498             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
10499             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10500                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10501                 if ( id != null ) {
10502                     System.out.println( "value   =" + id.getValue() );
10503                     System.out.println( "provider=" + id.getSource() );
10504                 }
10505                 return false;
10506             }
10507             //
10508             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
10509             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10510                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10511                 if ( id != null ) {
10512                     System.out.println( "value   =" + id.getValue() );
10513                     System.out.println( "provider=" + id.getSource() );
10514                 }
10515                 return false;
10516             }
10517             // 
10518             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
10519             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10520                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
10521                 if ( id != null ) {
10522                     System.out.println( "value   =" + id.getValue() );
10523                     System.out.println( "provider=" + id.getSource() );
10524                 }
10525                 return false;
10526             }
10527             // 
10528             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
10529             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10530                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
10531                 if ( id != null ) {
10532                     System.out.println( "value   =" + id.getValue() );
10533                     System.out.println( "provider=" + id.getSource() );
10534                 }
10535                 return false;
10536             }
10537             // 
10538             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
10539             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10540                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
10541                 if ( id != null ) {
10542                     System.out.println( "value   =" + id.getValue() );
10543                     System.out.println( "provider=" + id.getSource() );
10544                 }
10545                 return false;
10546             }
10547             // 
10548             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
10549             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10550                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
10551                 if ( id != null ) {
10552                     System.out.println( "value   =" + id.getValue() );
10553                     System.out.println( "provider=" + id.getSource() );
10554                 }
10555                 return false;
10556             }
10557             // 
10558             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
10559             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10560                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10561                 if ( id != null ) {
10562                     System.out.println( "value   =" + id.getValue() );
10563                     System.out.println( "provider=" + id.getSource() );
10564                 }
10565                 return false;
10566             }
10567             // 
10568             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
10569             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10570                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10571                 if ( id != null ) {
10572                     System.out.println( "value   =" + id.getValue() );
10573                     System.out.println( "provider=" + id.getSource() );
10574                 }
10575                 return false;
10576             }
10577             // 
10578             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
10579             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10580                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
10581                 if ( id != null ) {
10582                     System.out.println( "value   =" + id.getValue() );
10583                     System.out.println( "provider=" + id.getSource() );
10584                 }
10585                 return false;
10586             }
10587             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
10588             if ( id != null ) {
10589                 System.out.println( "value   =" + id.getValue() );
10590                 System.out.println( "provider=" + id.getSource() );
10591                 return false;
10592             }
10593         }
10594         catch ( final Exception e ) {
10595             e.printStackTrace( System.out );
10596             return false;
10597         }
10598         return true;
10599     }
10600
10601     private static boolean testSequenceWriter() {
10602         try {
10603             final String n = ForesterUtil.LINE_SEPARATOR;
10604             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
10605                 return false;
10606             }
10607             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
10608                 return false;
10609             }
10610             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
10611                 return false;
10612             }
10613             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
10614                 return false;
10615             }
10616             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
10617                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
10618                 return false;
10619             }
10620             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
10621                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
10622                 return false;
10623             }
10624         }
10625         catch ( final Exception e ) {
10626             e.printStackTrace();
10627             return false;
10628         }
10629         return true;
10630     }
10631
10632     private static boolean testSpecies() {
10633         try {
10634             final Species s1 = new BasicSpecies( "a" );
10635             final Species s2 = new BasicSpecies( "a" );
10636             final Species s3 = new BasicSpecies( "A" );
10637             final Species s4 = new BasicSpecies( "b" );
10638             if ( !s1.equals( s1 ) ) {
10639                 return false;
10640             }
10641             if ( s1.getSpeciesId().equals( "x" ) ) {
10642                 return false;
10643             }
10644             if ( s1.getSpeciesId().equals( null ) ) {
10645                 return false;
10646             }
10647             if ( !s1.equals( s2 ) ) {
10648                 return false;
10649             }
10650             if ( s1.equals( s3 ) ) {
10651                 return false;
10652             }
10653             if ( s1.hashCode() != s1.hashCode() ) {
10654                 return false;
10655             }
10656             if ( s1.hashCode() != s2.hashCode() ) {
10657                 return false;
10658             }
10659             if ( s1.hashCode() == s3.hashCode() ) {
10660                 return false;
10661             }
10662             if ( s1.compareTo( s1 ) != 0 ) {
10663                 return false;
10664             }
10665             if ( s1.compareTo( s2 ) != 0 ) {
10666                 return false;
10667             }
10668             if ( s1.compareTo( s3 ) != 0 ) {
10669                 return false;
10670             }
10671             if ( s1.compareTo( s4 ) >= 0 ) {
10672                 return false;
10673             }
10674             if ( s4.compareTo( s1 ) <= 0 ) {
10675                 return false;
10676             }
10677             if ( !s4.getSpeciesId().equals( "b" ) ) {
10678                 return false;
10679             }
10680             final Species s5 = new BasicSpecies( " C " );
10681             if ( !s5.getSpeciesId().equals( "C" ) ) {
10682                 return false;
10683             }
10684             if ( s5.equals( s1 ) ) {
10685                 return false;
10686             }
10687         }
10688         catch ( final Exception e ) {
10689             e.printStackTrace( System.out );
10690             return false;
10691         }
10692         return true;
10693     }
10694
10695     private static boolean testSplit() {
10696         try {
10697             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10698             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10699             //Archaeopteryx.createApplication( p0 );
10700             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10701             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10702             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10703             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10704             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10705             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10706             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10707             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10708             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10709             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10710             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
10711             // System.out.println( s0.toString() );
10712             //
10713             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10714             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10715             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10716             if ( s0.match( query_nodes ) ) {
10717                 return false;
10718             }
10719             query_nodes = new HashSet<PhylogenyNode>();
10720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10727             if ( !s0.match( query_nodes ) ) {
10728                 return false;
10729             }
10730             //
10731             query_nodes = new HashSet<PhylogenyNode>();
10732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10735             if ( !s0.match( query_nodes ) ) {
10736                 return false;
10737             }
10738             //
10739             query_nodes = new HashSet<PhylogenyNode>();
10740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10741             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10743             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10744             if ( !s0.match( query_nodes ) ) {
10745                 return false;
10746             }
10747             //
10748             query_nodes = new HashSet<PhylogenyNode>();
10749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10753             if ( !s0.match( query_nodes ) ) {
10754                 return false;
10755             }
10756             //
10757             query_nodes = new HashSet<PhylogenyNode>();
10758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10759             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10761             if ( !s0.match( query_nodes ) ) {
10762                 return false;
10763             }
10764             //
10765             query_nodes = new HashSet<PhylogenyNode>();
10766             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10767             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10768             if ( !s0.match( query_nodes ) ) {
10769                 return false;
10770             }
10771             //
10772             query_nodes = new HashSet<PhylogenyNode>();
10773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10775             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10776             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10777             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10778             if ( !s0.match( query_nodes ) ) {
10779                 return false;
10780             }
10781             //
10782             query_nodes = new HashSet<PhylogenyNode>();
10783             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10785             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10786             if ( !s0.match( query_nodes ) ) {
10787                 return false;
10788             }
10789             //
10790             query_nodes = new HashSet<PhylogenyNode>();
10791             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10793             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10794             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10795             if ( !s0.match( query_nodes ) ) {
10796                 return false;
10797             }
10798             //
10799             query_nodes = new HashSet<PhylogenyNode>();
10800             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10801             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10802             if ( s0.match( query_nodes ) ) {
10803                 return false;
10804             }
10805             //
10806             query_nodes = new HashSet<PhylogenyNode>();
10807             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10808             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10809             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10810             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10811             if ( s0.match( query_nodes ) ) {
10812                 return false;
10813             }
10814             //
10815             query_nodes = new HashSet<PhylogenyNode>();
10816             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10817             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10818             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10819             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10821             if ( s0.match( query_nodes ) ) {
10822                 return false;
10823             }
10824             //
10825             query_nodes = new HashSet<PhylogenyNode>();
10826             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10827             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10829             if ( s0.match( query_nodes ) ) {
10830                 return false;
10831             }
10832             //
10833             query_nodes = new HashSet<PhylogenyNode>();
10834             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10835             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10836             if ( s0.match( query_nodes ) ) {
10837                 return false;
10838             }
10839             //
10840             query_nodes = new HashSet<PhylogenyNode>();
10841             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10843             if ( s0.match( query_nodes ) ) {
10844                 return false;
10845             }
10846             //
10847             query_nodes = new HashSet<PhylogenyNode>();
10848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10850             if ( s0.match( query_nodes ) ) {
10851                 return false;
10852             }
10853             //
10854             query_nodes = new HashSet<PhylogenyNode>();
10855             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10857             if ( s0.match( query_nodes ) ) {
10858                 return false;
10859             }
10860             //
10861             query_nodes = new HashSet<PhylogenyNode>();
10862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10864             if ( s0.match( query_nodes ) ) {
10865                 return false;
10866             }
10867             //
10868             query_nodes = new HashSet<PhylogenyNode>();
10869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10871             if ( s0.match( query_nodes ) ) {
10872                 return false;
10873             }
10874             //
10875             query_nodes = new HashSet<PhylogenyNode>();
10876             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10879             if ( s0.match( query_nodes ) ) {
10880                 return false;
10881             }
10882             //
10883             query_nodes = new HashSet<PhylogenyNode>();
10884             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10887             if ( s0.match( query_nodes ) ) {
10888                 return false;
10889             }
10890             //
10891             query_nodes = new HashSet<PhylogenyNode>();
10892             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10893             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10895             if ( s0.match( query_nodes ) ) {
10896                 return false;
10897             }
10898             //
10899             query_nodes = new HashSet<PhylogenyNode>();
10900             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10901             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10902             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10903             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10904             if ( s0.match( query_nodes ) ) {
10905                 return false;
10906             }
10907             /////////
10908             //            query_nodes = new HashSet<PhylogenyNode>();
10909             //            query_nodes.add( new PhylogenyNode( "X" ) );
10910             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10911             //            query_nodes.add( new PhylogenyNode( "A" ) );
10912             //            query_nodes.add( new PhylogenyNode( "B" ) );
10913             //            query_nodes.add( new PhylogenyNode( "C" ) );
10914             //            query_nodes.add( new PhylogenyNode( "D" ) );
10915             //            query_nodes.add( new PhylogenyNode( "E" ) );
10916             //            query_nodes.add( new PhylogenyNode( "F" ) );
10917             //            query_nodes.add( new PhylogenyNode( "G" ) );
10918             //            if ( !s0.match( query_nodes ) ) {
10919             //                return false;
10920             //            }
10921             //            query_nodes = new HashSet<PhylogenyNode>();
10922             //            query_nodes.add( new PhylogenyNode( "X" ) );
10923             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10924             //            query_nodes.add( new PhylogenyNode( "A" ) );
10925             //            query_nodes.add( new PhylogenyNode( "B" ) );
10926             //            query_nodes.add( new PhylogenyNode( "C" ) );
10927             //            if ( !s0.match( query_nodes ) ) {
10928             //                return false;
10929             //            }
10930             //            //
10931             //            query_nodes = new HashSet<PhylogenyNode>();
10932             //            query_nodes.add( new PhylogenyNode( "X" ) );
10933             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10934             //            query_nodes.add( new PhylogenyNode( "D" ) );
10935             //            query_nodes.add( new PhylogenyNode( "E" ) );
10936             //            query_nodes.add( new PhylogenyNode( "F" ) );
10937             //            query_nodes.add( new PhylogenyNode( "G" ) );
10938             //            if ( !s0.match( query_nodes ) ) {
10939             //                return false;
10940             //            }
10941             //            //
10942             //            query_nodes = new HashSet<PhylogenyNode>();
10943             //            query_nodes.add( new PhylogenyNode( "X" ) );
10944             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10945             //            query_nodes.add( new PhylogenyNode( "A" ) );
10946             //            query_nodes.add( new PhylogenyNode( "B" ) );
10947             //            query_nodes.add( new PhylogenyNode( "C" ) );
10948             //            query_nodes.add( new PhylogenyNode( "D" ) );
10949             //            if ( !s0.match( query_nodes ) ) {
10950             //                return false;
10951             //            }
10952             //            //
10953             //            query_nodes = new HashSet<PhylogenyNode>();
10954             //            query_nodes.add( new PhylogenyNode( "X" ) );
10955             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10956             //            query_nodes.add( new PhylogenyNode( "E" ) );
10957             //            query_nodes.add( new PhylogenyNode( "F" ) );
10958             //            query_nodes.add( new PhylogenyNode( "G" ) );
10959             //            if ( !s0.match( query_nodes ) ) {
10960             //                return false;
10961             //            }
10962             //            //
10963             //            query_nodes = new HashSet<PhylogenyNode>();
10964             //            query_nodes.add( new PhylogenyNode( "X" ) );
10965             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10966             //            query_nodes.add( new PhylogenyNode( "F" ) );
10967             //            query_nodes.add( new PhylogenyNode( "G" ) );
10968             //            if ( !s0.match( query_nodes ) ) {
10969             //                return false;
10970             //            }
10971             //
10972             query_nodes = new HashSet<PhylogenyNode>();
10973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10974             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10977             if ( s0.match( query_nodes ) ) {
10978                 return false;
10979             }
10980             //
10981             query_nodes = new HashSet<PhylogenyNode>();
10982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10983             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10984             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10985             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10986             if ( s0.match( query_nodes ) ) {
10987                 return false;
10988             }
10989             ///////////////////////////
10990             //
10991             query_nodes = new HashSet<PhylogenyNode>();
10992             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10995             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10996             if ( s0.match( query_nodes ) ) {
10997                 return false;
10998             }
10999             //
11000             query_nodes = new HashSet<PhylogenyNode>();
11001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11004             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11005             if ( s0.match( query_nodes ) ) {
11006                 return false;
11007             }
11008             //
11009             query_nodes = new HashSet<PhylogenyNode>();
11010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11014             if ( s0.match( query_nodes ) ) {
11015                 return false;
11016             }
11017             //
11018             query_nodes = new HashSet<PhylogenyNode>();
11019             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11023             if ( s0.match( query_nodes ) ) {
11024                 return false;
11025             }
11026             //
11027             query_nodes = new HashSet<PhylogenyNode>();
11028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11032             if ( s0.match( query_nodes ) ) {
11033                 return false;
11034             }
11035             //
11036             query_nodes = new HashSet<PhylogenyNode>();
11037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11040             if ( s0.match( query_nodes ) ) {
11041                 return false;
11042             }
11043             //
11044             query_nodes = new HashSet<PhylogenyNode>();
11045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11050             if ( s0.match( query_nodes ) ) {
11051                 return false;
11052             }
11053             //
11054             query_nodes = new HashSet<PhylogenyNode>();
11055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11057             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11058             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11059             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11060             if ( s0.match( query_nodes ) ) {
11061                 return false;
11062             }
11063             //
11064             query_nodes = new HashSet<PhylogenyNode>();
11065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11066             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11067             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11068             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11069             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11070             if ( s0.match( query_nodes ) ) {
11071                 return false;
11072             }
11073             //
11074             query_nodes = new HashSet<PhylogenyNode>();
11075             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11076             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11077             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11078             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11079             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11080             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11081             if ( s0.match( query_nodes ) ) {
11082                 return false;
11083             }
11084         }
11085         catch ( final Exception e ) {
11086             e.printStackTrace();
11087             return false;
11088         }
11089         return true;
11090     }
11091
11092     private static boolean testSplitStrict() {
11093         try {
11094             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11095             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11096             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11097             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11098             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11099             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11100             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11101             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11102             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11103             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11104             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11105             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11108             if ( s0.match( query_nodes ) ) {
11109                 return false;
11110             }
11111             query_nodes = new HashSet<PhylogenyNode>();
11112             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11113             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11115             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11116             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11117             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11118             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11119             if ( !s0.match( query_nodes ) ) {
11120                 return false;
11121             }
11122             //
11123             query_nodes = new HashSet<PhylogenyNode>();
11124             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11125             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11126             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11127             if ( !s0.match( query_nodes ) ) {
11128                 return false;
11129             }
11130             //
11131             query_nodes = new HashSet<PhylogenyNode>();
11132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11133             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11134             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11135             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11136             if ( !s0.match( query_nodes ) ) {
11137                 return false;
11138             }
11139             //
11140             query_nodes = new HashSet<PhylogenyNode>();
11141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11143             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11144             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11145             if ( !s0.match( query_nodes ) ) {
11146                 return false;
11147             }
11148             //
11149             query_nodes = new HashSet<PhylogenyNode>();
11150             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11151             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11152             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11153             if ( !s0.match( query_nodes ) ) {
11154                 return false;
11155             }
11156             //
11157             query_nodes = new HashSet<PhylogenyNode>();
11158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11159             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11160             if ( !s0.match( query_nodes ) ) {
11161                 return false;
11162             }
11163             //
11164             query_nodes = new HashSet<PhylogenyNode>();
11165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11167             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11168             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11169             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11170             if ( !s0.match( query_nodes ) ) {
11171                 return false;
11172             }
11173             //
11174             query_nodes = new HashSet<PhylogenyNode>();
11175             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11176             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11177             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11178             if ( !s0.match( query_nodes ) ) {
11179                 return false;
11180             }
11181             //
11182             query_nodes = new HashSet<PhylogenyNode>();
11183             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11184             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11185             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11186             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11187             if ( !s0.match( query_nodes ) ) {
11188                 return false;
11189             }
11190             //
11191             query_nodes = new HashSet<PhylogenyNode>();
11192             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11193             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11194             if ( s0.match( query_nodes ) ) {
11195                 return false;
11196             }
11197             //
11198             query_nodes = new HashSet<PhylogenyNode>();
11199             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11200             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11201             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11202             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11203             if ( s0.match( query_nodes ) ) {
11204                 return false;
11205             }
11206             //
11207             query_nodes = new HashSet<PhylogenyNode>();
11208             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11209             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11210             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11211             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11212             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11213             if ( s0.match( query_nodes ) ) {
11214                 return false;
11215             }
11216             //
11217             query_nodes = new HashSet<PhylogenyNode>();
11218             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11219             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11220             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11221             if ( s0.match( query_nodes ) ) {
11222                 return false;
11223             }
11224             //
11225             query_nodes = new HashSet<PhylogenyNode>();
11226             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11227             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11228             if ( s0.match( query_nodes ) ) {
11229                 return false;
11230             }
11231             //
11232             query_nodes = new HashSet<PhylogenyNode>();
11233             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11234             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11235             if ( s0.match( query_nodes ) ) {
11236                 return false;
11237             }
11238             //
11239             query_nodes = new HashSet<PhylogenyNode>();
11240             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11241             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11242             if ( s0.match( query_nodes ) ) {
11243                 return false;
11244             }
11245             //
11246             query_nodes = new HashSet<PhylogenyNode>();
11247             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11248             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11249             if ( s0.match( query_nodes ) ) {
11250                 return false;
11251             }
11252             //
11253             query_nodes = new HashSet<PhylogenyNode>();
11254             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11255             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11256             if ( s0.match( query_nodes ) ) {
11257                 return false;
11258             }
11259             //
11260             query_nodes = new HashSet<PhylogenyNode>();
11261             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11262             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11263             if ( s0.match( query_nodes ) ) {
11264                 return false;
11265             }
11266             //
11267             query_nodes = new HashSet<PhylogenyNode>();
11268             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11269             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11270             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11271             if ( s0.match( query_nodes ) ) {
11272                 return false;
11273             }
11274             //
11275             query_nodes = new HashSet<PhylogenyNode>();
11276             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11277             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11278             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11279             if ( s0.match( query_nodes ) ) {
11280                 return false;
11281             }
11282             //
11283             query_nodes = new HashSet<PhylogenyNode>();
11284             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11285             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11286             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11287             if ( s0.match( query_nodes ) ) {
11288                 return false;
11289             }
11290             //
11291             query_nodes = new HashSet<PhylogenyNode>();
11292             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11293             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11294             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11295             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11296             if ( s0.match( query_nodes ) ) {
11297                 return false;
11298             }
11299         }
11300         catch ( final Exception e ) {
11301             e.printStackTrace();
11302             return false;
11303         }
11304         return true;
11305     }
11306
11307     private static boolean testSubtreeDeletion() {
11308         try {
11309             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11310             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11311             t1.deleteSubtree( t1.getNode( "A" ), false );
11312             if ( t1.getNumberOfExternalNodes() != 5 ) {
11313                 return false;
11314             }
11315             t1.toNewHampshireX();
11316             t1.deleteSubtree( t1.getNode( "E" ), false );
11317             if ( t1.getNumberOfExternalNodes() != 4 ) {
11318                 return false;
11319             }
11320             t1.toNewHampshireX();
11321             t1.deleteSubtree( t1.getNode( "F" ), false );
11322             if ( t1.getNumberOfExternalNodes() != 3 ) {
11323                 return false;
11324             }
11325             t1.toNewHampshireX();
11326             t1.deleteSubtree( t1.getNode( "D" ), false );
11327             t1.toNewHampshireX();
11328             if ( t1.getNumberOfExternalNodes() != 3 ) {
11329                 return false;
11330             }
11331             t1.deleteSubtree( t1.getNode( "def" ), false );
11332             t1.toNewHampshireX();
11333             if ( t1.getNumberOfExternalNodes() != 2 ) {
11334                 return false;
11335             }
11336             t1.deleteSubtree( t1.getNode( "B" ), false );
11337             t1.toNewHampshireX();
11338             if ( t1.getNumberOfExternalNodes() != 1 ) {
11339                 return false;
11340             }
11341             t1.deleteSubtree( t1.getNode( "C" ), false );
11342             t1.toNewHampshireX();
11343             if ( t1.getNumberOfExternalNodes() != 1 ) {
11344                 return false;
11345             }
11346             t1.deleteSubtree( t1.getNode( "abc" ), false );
11347             t1.toNewHampshireX();
11348             if ( t1.getNumberOfExternalNodes() != 1 ) {
11349                 return false;
11350             }
11351             t1.deleteSubtree( t1.getNode( "r" ), false );
11352             if ( t1.getNumberOfExternalNodes() != 0 ) {
11353                 return false;
11354             }
11355             if ( !t1.isEmpty() ) {
11356                 return false;
11357             }
11358             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11359             t2.deleteSubtree( t2.getNode( "A" ), false );
11360             t2.toNewHampshireX();
11361             if ( t2.getNumberOfExternalNodes() != 5 ) {
11362                 return false;
11363             }
11364             t2.deleteSubtree( t2.getNode( "abc" ), false );
11365             t2.toNewHampshireX();
11366             if ( t2.getNumberOfExternalNodes() != 3 ) {
11367                 return false;
11368             }
11369             t2.deleteSubtree( t2.getNode( "def" ), false );
11370             t2.toNewHampshireX();
11371             if ( t2.getNumberOfExternalNodes() != 1 ) {
11372                 return false;
11373             }
11374         }
11375         catch ( final Exception e ) {
11376             e.printStackTrace( System.out );
11377             return false;
11378         }
11379         return true;
11380     }
11381
11382     private static boolean testSupportCount() {
11383         try {
11384             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11385             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
11386             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
11387                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
11388                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
11389                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
11390                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
11391                                                               new NHXParser() );
11392             SupportCount.count( t0_1, phylogenies_1, true, false );
11393             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
11394             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
11395                                                                       + "(((((A,B),C),D),E),((F,G),X))"
11396                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
11397                                                                       + "(((((A,B),C),D),E),(F,G))"
11398                                                                       + "(((((A,B),C),D),E),(F,G))"
11399                                                                       + "(((((A,B),C),D),E),(F,G))"
11400                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
11401                                                                       + "(((((A,B),C),D),E),(F,G))"
11402                                                                       + "((((((A,B),C),D),E),F),G)"
11403                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
11404                                                               new NHXParser() );
11405             SupportCount.count( t0_2, phylogenies_2, true, false );
11406             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
11407             while ( it.hasNext() ) {
11408                 final PhylogenyNode n = it.next();
11409                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
11410                     return false;
11411                 }
11412             }
11413             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
11414             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
11415                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
11416             SupportCount.count( t0_3, phylogenies_3, true, false );
11417             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
11418             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
11419                 return false;
11420             }
11421             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
11422                 return false;
11423             }
11424             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
11425                 return false;
11426             }
11427             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
11428                 return false;
11429             }
11430             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
11431                 return false;
11432             }
11433             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
11434                 return false;
11435             }
11436             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
11437                 return false;
11438             }
11439             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
11440                 return false;
11441             }
11442             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
11443                 return false;
11444             }
11445             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
11446                 return false;
11447             }
11448             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11449             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
11450                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
11451             SupportCount.count( t0_4, phylogenies_4, true, false );
11452             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
11453             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
11454                 return false;
11455             }
11456             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
11457                 return false;
11458             }
11459             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
11460                 return false;
11461             }
11462             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
11463                 return false;
11464             }
11465             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
11466                 return false;
11467             }
11468             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
11469                 return false;
11470             }
11471             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
11472                 return false;
11473             }
11474             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
11475                 return false;
11476             }
11477             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
11478                 return false;
11479             }
11480             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
11481                 return false;
11482             }
11483             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11484             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11485             double d = SupportCount.compare( b1, a, true, true, true );
11486             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
11487                 return false;
11488             }
11489             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11490             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11491             d = SupportCount.compare( b2, a, true, true, true );
11492             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
11493                 return false;
11494             }
11495             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11496             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
11497             d = SupportCount.compare( b3, a, true, true, true );
11498             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
11499                 return false;
11500             }
11501             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
11502             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
11503             d = SupportCount.compare( b4, a, true, true, false );
11504             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
11505                 return false;
11506             }
11507         }
11508         catch ( final Exception e ) {
11509             e.printStackTrace( System.out );
11510             return false;
11511         }
11512         return true;
11513     }
11514
11515     private static boolean testSupportTransfer() {
11516         try {
11517             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11518             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)",
11519                                                  new NHXParser() )[ 0 ];
11520             final Phylogeny p2 = factory
11521                     .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 ];
11522             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
11523                 return false;
11524             }
11525             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
11526                 return false;
11527             }
11528             support_transfer.moveBranchLengthsToBootstrap( p1 );
11529             support_transfer.transferSupportValues( p1, p2 );
11530             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
11531                 return false;
11532             }
11533             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
11534                 return false;
11535             }
11536             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
11537                 return false;
11538             }
11539             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
11540                 return false;
11541             }
11542             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
11543                 return false;
11544             }
11545             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
11546                 return false;
11547             }
11548             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
11549                 return false;
11550             }
11551             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
11552                 return false;
11553             }
11554         }
11555         catch ( final Exception e ) {
11556             e.printStackTrace( System.out );
11557             return false;
11558         }
11559         return true;
11560     }
11561
11562     private static boolean testTaxonomyExtraction() {
11563         try {
11564             final PhylogenyNode n0 = PhylogenyNode
11565                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11566             if ( n0.getNodeData().isHasTaxonomy() ) {
11567                 return false;
11568             }
11569             final PhylogenyNode n1 = PhylogenyNode
11570                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11571             if ( n1.getNodeData().isHasTaxonomy() ) {
11572                 System.out.println( n1.toString() );
11573                 return false;
11574             }
11575             final PhylogenyNode n2x = PhylogenyNode
11576                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11577             if ( n2x.getNodeData().isHasTaxonomy() ) {
11578                 return false;
11579             }
11580             final PhylogenyNode n3 = PhylogenyNode
11581                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11582             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11583                 System.out.println( n3.toString() );
11584                 return false;
11585             }
11586             final PhylogenyNode n4 = PhylogenyNode
11587                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11588             if ( n4.getNodeData().isHasTaxonomy() ) {
11589                 System.out.println( n4.toString() );
11590                 return false;
11591             }
11592             final PhylogenyNode n5 = PhylogenyNode
11593                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11594             if ( n5.getNodeData().isHasTaxonomy() ) {
11595                 System.out.println( n5.toString() );
11596                 return false;
11597             }
11598             final PhylogenyNode n6 = PhylogenyNode
11599                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11600             if ( n6.getNodeData().isHasTaxonomy() ) {
11601                 System.out.println( n6.toString() );
11602                 return false;
11603             }
11604             final PhylogenyNode n7 = PhylogenyNode
11605                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11606             if ( n7.getNodeData().isHasTaxonomy() ) {
11607                 System.out.println( n7.toString() );
11608                 return false;
11609             }
11610             final PhylogenyNode n8 = PhylogenyNode
11611                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11612             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11613                 System.out.println( n8.toString() );
11614                 return false;
11615             }
11616             final PhylogenyNode n9 = PhylogenyNode
11617                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11618             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11619                 System.out.println( n9.toString() );
11620                 return false;
11621             }
11622             final PhylogenyNode n10x = PhylogenyNode
11623                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11624             if ( n10x.getNodeData().isHasTaxonomy() ) {
11625                 System.out.println( n10x.toString() );
11626                 return false;
11627             }
11628             final PhylogenyNode n10xx = PhylogenyNode
11629                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11630             if ( n10xx.getNodeData().isHasTaxonomy() ) {
11631                 System.out.println( n10xx.toString() );
11632                 return false;
11633             }
11634             final PhylogenyNode n10 = PhylogenyNode
11635                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11636             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
11637                 System.out.println( n10.toString() );
11638                 return false;
11639             }
11640             final PhylogenyNode n11 = PhylogenyNode
11641                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11642             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11643                 System.out.println( n11.toString() );
11644                 return false;
11645             }
11646             final PhylogenyNode n12 = PhylogenyNode
11647                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
11648                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11649             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11650                 System.out.println( n12.toString() );
11651                 return false;
11652             }
11653             final PhylogenyNode n13 = PhylogenyNode
11654                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11655             if ( n13.getNodeData().isHasTaxonomy() ) {
11656                 System.out.println( n13.toString() );
11657                 return false;
11658             }
11659         }
11660         catch ( final Exception e ) {
11661             e.printStackTrace( System.out );
11662             return false;
11663         }
11664         return true;
11665     }
11666
11667     private static boolean testTreeCopy() {
11668         try {
11669             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
11670             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
11671             final Phylogeny t1 = t0.copy();
11672             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
11673                 return false;
11674             }
11675             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11676                 return false;
11677             }
11678             t0.deleteSubtree( t0.getNode( "c" ), true );
11679             t0.deleteSubtree( t0.getNode( "a" ), true );
11680             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
11681             t0.getNode( "b" ).setName( "Bee" );
11682             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
11683                 return false;
11684             }
11685             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11686                 return false;
11687             }
11688             t0.deleteSubtree( t0.getNode( "e" ), true );
11689             t0.deleteSubtree( t0.getNode( "Bee" ), true );
11690             t0.deleteSubtree( t0.getNode( "d" ), true );
11691             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11692                 return false;
11693             }
11694         }
11695         catch ( final Exception e ) {
11696             e.printStackTrace();
11697             return false;
11698         }
11699         return true;
11700     }
11701
11702     private static boolean testTreeMethods() {
11703         try {
11704             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11705             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
11706             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
11707             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
11708                 System.out.println( t0.toNewHampshireX() );
11709                 return false;
11710             }
11711             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
11712             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
11713             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
11714                 return false;
11715             }
11716             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
11717                 return false;
11718             }
11719             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
11720                 return false;
11721             }
11722         }
11723         catch ( final Exception e ) {
11724             e.printStackTrace( System.out );
11725             return false;
11726         }
11727         return true;
11728     }
11729
11730     private static boolean testUniprotEntryRetrieval() {
11731         try {
11732             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
11733             if ( !entry.getAccession().equals( "P12345" ) ) {
11734                 return false;
11735             }
11736             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
11737                 return false;
11738             }
11739             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
11740                 return false;
11741             }
11742             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
11743                 return false;
11744             }
11745             if ( !entry.getGeneName().equals( "GOT2" ) ) {
11746                 return false;
11747             }
11748             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
11749                 return false;
11750             }
11751         }
11752         catch ( final IOException e ) {
11753             System.out.println();
11754             System.out.println( "the following might be due to absence internet connection:" );
11755             e.printStackTrace( System.out );
11756             return true;
11757         }
11758         catch ( final Exception e ) {
11759             return false;
11760         }
11761         return true;
11762     }
11763
11764     private static boolean testUniprotTaxonomySearch() {
11765         try {
11766             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
11767                                                                                                  10 );
11768             if ( results.size() != 1 ) {
11769                 return false;
11770             }
11771             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11772                 return false;
11773             }
11774             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11775                 return false;
11776             }
11777             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11778                 return false;
11779             }
11780             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11781                 return false;
11782             }
11783             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11784                 return false;
11785             }
11786             results = null;
11787             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
11788             if ( results.size() != 1 ) {
11789                 return false;
11790             }
11791             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11792                 return false;
11793             }
11794             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11795                 return false;
11796             }
11797             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11798                 return false;
11799             }
11800             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11801                 return false;
11802             }
11803             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11804                 return false;
11805             }
11806             results = null;
11807             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
11808             if ( results.size() != 1 ) {
11809                 return false;
11810             }
11811             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11812                 return false;
11813             }
11814             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11815                 return false;
11816             }
11817             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11818                 return false;
11819             }
11820             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11821                 return false;
11822             }
11823             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11824                 return false;
11825             }
11826             results = null;
11827             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
11828             if ( results.size() != 1 ) {
11829                 return false;
11830             }
11831             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11832                 return false;
11833             }
11834             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11835                 return false;
11836             }
11837             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11838                 return false;
11839             }
11840             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11841                 return false;
11842             }
11843             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11844                 return false;
11845             }
11846             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
11847                 return false;
11848             }
11849             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
11850                 return false;
11851             }
11852             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11853                     .equals( "Nematostella vectensis" ) ) {
11854                 System.out.println( results.get( 0 ).getLineage() );
11855                 return false;
11856             }
11857             //
11858             results = null;
11859             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
11860             if ( results.size() != 1 ) {
11861                 return false;
11862             }
11863             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11864                 return false;
11865             }
11866             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11867                 return false;
11868             }
11869             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11870                 return false;
11871             }
11872             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11873                 return false;
11874             }
11875             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11876                 return false;
11877             }
11878             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11879                     .equals( "Xenopus tropicalis" ) ) {
11880                 System.out.println( results.get( 0 ).getLineage() );
11881                 return false;
11882             }
11883             //
11884             results = null;
11885             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
11886             if ( results.size() != 1 ) {
11887                 return false;
11888             }
11889             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11890                 return false;
11891             }
11892             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11893                 return false;
11894             }
11895             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11896                 return false;
11897             }
11898             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11899                 return false;
11900             }
11901             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11902                 return false;
11903             }
11904             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11905                     .equals( "Xenopus tropicalis" ) ) {
11906                 System.out.println( results.get( 0 ).getLineage() );
11907                 return false;
11908             }
11909             //
11910             results = null;
11911             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
11912             if ( results.size() != 1 ) {
11913                 return false;
11914             }
11915             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11916                 return false;
11917             }
11918             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11919                 return false;
11920             }
11921             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11922                 return false;
11923             }
11924             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11925                 return false;
11926             }
11927             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11928                 return false;
11929             }
11930             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11931                     .equals( "Xenopus tropicalis" ) ) {
11932                 System.out.println( results.get( 0 ).getLineage() );
11933                 return false;
11934             }
11935         }
11936         catch ( final IOException e ) {
11937             System.out.println();
11938             System.out.println( "the following might be due to absence internet connection:" );
11939             e.printStackTrace( System.out );
11940             return true;
11941         }
11942         catch ( final Exception e ) {
11943             return false;
11944         }
11945         return true;
11946     }
11947
11948     private static boolean testWabiTxSearch() {
11949         try {
11950             String result = "";
11951             result = TxSearch.searchSimple( "nematostella" );
11952             result = TxSearch.getTxId( "nematostella" );
11953             if ( !result.equals( "45350" ) ) {
11954                 return false;
11955             }
11956             result = TxSearch.getTxName( "45350" );
11957             if ( !result.equals( "Nematostella" ) ) {
11958                 return false;
11959             }
11960             result = TxSearch.getTxId( "nematostella vectensis" );
11961             if ( !result.equals( "45351" ) ) {
11962                 return false;
11963             }
11964             result = TxSearch.getTxName( "45351" );
11965             if ( !result.equals( "Nematostella vectensis" ) ) {
11966                 return false;
11967             }
11968             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11969             if ( !result.equals( "536089" ) ) {
11970                 return false;
11971             }
11972             result = TxSearch.getTxName( "536089" );
11973             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11974                 return false;
11975             }
11976             final List<String> queries = new ArrayList<String>();
11977             queries.add( "Campylobacter coli" );
11978             queries.add( "Escherichia coli" );
11979             queries.add( "Arabidopsis" );
11980             queries.add( "Trichoplax" );
11981             queries.add( "Samanea saman" );
11982             queries.add( "Kluyveromyces marxianus" );
11983             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11984             queries.add( "Bornavirus parrot/PDD/2008" );
11985             final List<RANKS> ranks = new ArrayList<RANKS>();
11986             ranks.add( RANKS.SUPERKINGDOM );
11987             ranks.add( RANKS.KINGDOM );
11988             ranks.add( RANKS.FAMILY );
11989             ranks.add( RANKS.GENUS );
11990             ranks.add( RANKS.TRIBE );
11991             result = TxSearch.searchLineage( queries, ranks );
11992             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11993             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11994         }
11995         catch ( final Exception e ) {
11996             System.out.println();
11997             System.out.println( "the following might be due to absence internet connection:" );
11998             e.printStackTrace( System.out );
11999             return false;
12000         }
12001         return true;
12002     }
12003 }