ed1daa10831644a3dfe37c83ee094907b5dedfc9
[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             System.out.print( "MAFFT (external program): " );
925             if ( Test.testMafft( path ) ) {
926                 System.out.println( "OK." );
927                 succeeded++;
928             }
929             else {
930                 System.out.println( "failed [will not count towards failed tests]" );
931             }
932         }
933         //----
934         System.out.print( "Next nodes with collapsed: " );
935         if ( Test.testNextNodeWithCollapsing() ) {
936             System.out.println( "OK." );
937             succeeded++;
938         }
939         else {
940             System.out.println( "failed." );
941             failed++;
942         }
943         System.out.print( "Simple MSA quality: " );
944         if ( Test.testMsaQualityMethod() ) {
945             System.out.println( "OK." );
946             succeeded++;
947         }
948         else {
949             System.out.println( "failed." );
950             failed++;
951         }
952         System.out.print( "NHX parsing from URL: " );
953         if ( Test.testNHXparsingFromURL() ) {
954             System.out.println( "OK." );
955             succeeded++;
956         }
957         else {
958             System.out.println( "failed." );
959             failed++;
960         }
961         System.out.println();
962         final Runtime rt = java.lang.Runtime.getRuntime();
963         final long free_memory = rt.freeMemory() / 1000000;
964         final long total_memory = rt.totalMemory() / 1000000;
965         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
966                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
967         System.out.println();
968         System.out.println( "Successful tests: " + succeeded );
969         System.out.println( "Failed     tests: " + failed );
970         System.out.println();
971         if ( failed < 1 ) {
972             System.out.println( "OK." );
973         }
974         else {
975             System.out.println( "Not OK." );
976         }
977     }
978
979     public static boolean testEngulfingOverlapRemoval() {
980         try {
981             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
982             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
983             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
984             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
985             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
986             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
987             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
988             final List<Boolean> covered = new ArrayList<Boolean>();
989             covered.add( true ); // 0
990             covered.add( false ); // 1
991             covered.add( true ); // 2
992             covered.add( false ); // 3
993             covered.add( true ); // 4
994             covered.add( true ); // 5
995             covered.add( false ); // 6
996             covered.add( true ); // 7
997             covered.add( true ); // 8
998             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
999                 return false;
1000             }
1001             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1002                 return false;
1003             }
1004             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1005                 return false;
1006             }
1007             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1008                 return false;
1009             }
1010             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1011                 return false;
1012             }
1013             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1014                 return false;
1015             }
1016             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1017                 return false;
1018             }
1019             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1020             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1021             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1022             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1023             abc.addProteinDomain( a );
1024             abc.addProteinDomain( b );
1025             abc.addProteinDomain( c );
1026             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1027             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1028             if ( abc.getNumberOfProteinDomains() != 3 ) {
1029                 return false;
1030             }
1031             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1032                 return false;
1033             }
1034             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1035                 return false;
1036             }
1037             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1038                 return false;
1039             }
1040             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1041                 return false;
1042             }
1043             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1044             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1045             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1046             final Protein def = new BasicProtein( "def", "nemve", 0 );
1047             def.addProteinDomain( d );
1048             def.addProteinDomain( e );
1049             def.addProteinDomain( f );
1050             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1051             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1052             if ( def.getNumberOfProteinDomains() != 3 ) {
1053                 return false;
1054             }
1055             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1056                 return false;
1057             }
1058             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1059                 return false;
1060             }
1061             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1062                 return false;
1063             }
1064             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1065                 return false;
1066             }
1067             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1068                 return false;
1069             }
1070         }
1071         catch ( final Exception e ) {
1072             e.printStackTrace( System.out );
1073             return false;
1074         }
1075         return true;
1076     }
1077
1078     public static final boolean testNHXparsingFromURL() {
1079         try {
1080             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1081             final URL u = new URL( s );
1082             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1083             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1084             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1085                 return false;
1086             }
1087             if ( !phys[ 0 ].toNewHampshire().equals( "((a,b),c);" ) ) {
1088                 System.out.println( phys[ 0 ].toNewHampshire() );
1089                 return false;
1090             }
1091             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1092             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1093                 return false;
1094             }
1095             if ( !phys2[ 0 ].toNewHampshire().equals( "((a,b),c);" ) ) {
1096                 System.out.println( phys2[ 0 ].toNewHampshire() );
1097                 return false;
1098             }
1099             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1100             final NHXParser p = new NHXParser();
1101             final URL u2 = new URL( s );
1102             p.setSource( u2 );
1103             if ( !p.hasNext() ) {
1104                 return false;
1105             }
1106             if ( !p.next().toNewHampshire().equals( "((a,b),c);" ) ) {
1107                 return false;
1108             }
1109             if ( p.hasNext() ) {
1110                 return false;
1111             }
1112             if ( p.next() != null ) {
1113                 return false;
1114             }
1115             if ( p.hasNext() ) {
1116                 return false;
1117             }
1118             if ( p.next() != null ) {
1119                 return false;
1120             }
1121             p.reset();
1122             if ( !p.hasNext() ) {
1123                 return false;
1124             }
1125             if ( !p.next().toNewHampshire().equals( "((a,b),c);" ) ) {
1126                 return false;
1127             }
1128             if ( p.hasNext() ) {
1129                 return false;
1130             }
1131             if ( p.next() != null ) {
1132                 return false;
1133             }
1134             if ( p.hasNext() ) {
1135                 return false;
1136             }
1137             if ( p.next() != null ) {
1138                 return false;
1139             }
1140             p.reset();
1141             if ( !p.hasNext() ) {
1142                 return false;
1143             }
1144         }
1145         catch ( final Exception e ) {
1146             e.printStackTrace();
1147         }
1148         return true;
1149     }
1150
1151     public static boolean testOverlapRemoval() {
1152         try {
1153             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1154             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1155             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1156             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1157             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1158             final List<Boolean> covered = new ArrayList<Boolean>();
1159             covered.add( true ); // 0
1160             covered.add( false ); // 1
1161             covered.add( true ); // 2
1162             covered.add( false ); // 3
1163             covered.add( true ); // 4
1164             covered.add( true ); // 5
1165             covered.add( false ); // 6
1166             covered.add( true ); // 7
1167             covered.add( true ); // 8
1168             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1169                 return false;
1170             }
1171             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1172                 return false;
1173             }
1174             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1175                 return false;
1176             }
1177             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1178                 return false;
1179             }
1180             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1181                 return false;
1182             }
1183             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1184             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1185             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1186             ab.addProteinDomain( a );
1187             ab.addProteinDomain( b );
1188             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1189             if ( ab.getNumberOfProteinDomains() != 2 ) {
1190                 return false;
1191             }
1192             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1193                 return false;
1194             }
1195             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1196                 return false;
1197             }
1198             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1199             if ( ab.getNumberOfProteinDomains() != 2 ) {
1200                 return false;
1201             }
1202             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1203                 return false;
1204             }
1205             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1206             final Domain d = new BasicDomain( "d",
1207                                               ( short ) 10000,
1208                                               ( short ) 10500,
1209                                               ( short ) 1,
1210                                               ( short ) 1,
1211                                               0.0000001,
1212                                               1 );
1213             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1214             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1215             cde.addProteinDomain( c );
1216             cde.addProteinDomain( d );
1217             cde.addProteinDomain( e );
1218             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1219             if ( cde.getNumberOfProteinDomains() != 3 ) {
1220                 return false;
1221             }
1222             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1223                 return false;
1224             }
1225             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1226             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1227             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1228             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1229             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1230             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1231             fghi.addProteinDomain( f );
1232             fghi.addProteinDomain( g );
1233             fghi.addProteinDomain( h );
1234             fghi.addProteinDomain( i );
1235             fghi.addProteinDomain( i );
1236             fghi.addProteinDomain( i );
1237             fghi.addProteinDomain( i2 );
1238             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1239             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1240                 return false;
1241             }
1242             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1243                 return false;
1244             }
1245             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1246                 return false;
1247             }
1248             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1249             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1250                 return false;
1251             }
1252             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1253                 return false;
1254             }
1255             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1256             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1257             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1258             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1259             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1260             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1261             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1262             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1263             jklm.addProteinDomain( j );
1264             jklm.addProteinDomain( k );
1265             jklm.addProteinDomain( l );
1266             jklm.addProteinDomain( m );
1267             jklm.addProteinDomain( m0 );
1268             jklm.addProteinDomain( m1 );
1269             jklm.addProteinDomain( m2 );
1270             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1271             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1272                 return false;
1273             }
1274             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1275                 return false;
1276             }
1277             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1278                 return false;
1279             }
1280             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1281             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1282                 return false;
1283             }
1284             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1285                 return false;
1286             }
1287             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1288             final Protein od = new BasicProtein( "od", "varanus", 0 );
1289             od.addProteinDomain( only );
1290             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1291             if ( od.getNumberOfProteinDomains() != 1 ) {
1292                 return false;
1293             }
1294             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1295                 return false;
1296             }
1297         }
1298         catch ( final Exception e ) {
1299             e.printStackTrace( System.out );
1300             return false;
1301         }
1302         return true;
1303     }
1304
1305     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1306         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1307         return p;
1308     }
1309
1310     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1311         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1312     }
1313
1314     private static boolean testAminoAcidSequence() {
1315         try {
1316             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1317             if ( aa1.getLength() != 13 ) {
1318                 return false;
1319             }
1320             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1321                 return false;
1322             }
1323             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1324                 return false;
1325             }
1326             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1327                 return false;
1328             }
1329             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1330             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1331                 return false;
1332             }
1333             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1334             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1335                 return false;
1336             }
1337             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1338             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1339                 return false;
1340             }
1341         }
1342         catch ( final Exception e ) {
1343             e.printStackTrace();
1344             return false;
1345         }
1346         return true;
1347     }
1348
1349     private static boolean testBasicDomain() {
1350         try {
1351             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1352             if ( !pd.getDomainId().equals( "id" ) ) {
1353                 return false;
1354             }
1355             if ( pd.getNumber() != 1 ) {
1356                 return false;
1357             }
1358             if ( pd.getTotalCount() != 4 ) {
1359                 return false;
1360             }
1361             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1362                 return false;
1363             }
1364             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1365             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1366             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1367             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1368             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1369             if ( !a1.equals( a1 ) ) {
1370                 return false;
1371             }
1372             if ( !a1.equals( a1_copy ) ) {
1373                 return false;
1374             }
1375             if ( !a1.equals( a1_equal ) ) {
1376                 return false;
1377             }
1378             if ( !a1.equals( a2 ) ) {
1379                 return false;
1380             }
1381             if ( a1.equals( a3 ) ) {
1382                 return false;
1383             }
1384             if ( a1.compareTo( a1 ) != 0 ) {
1385                 return false;
1386             }
1387             if ( a1.compareTo( a1_copy ) != 0 ) {
1388                 return false;
1389             }
1390             if ( a1.compareTo( a1_equal ) != 0 ) {
1391                 return false;
1392             }
1393             if ( a1.compareTo( a2 ) != 0 ) {
1394                 return false;
1395             }
1396             if ( a1.compareTo( a3 ) == 0 ) {
1397                 return false;
1398             }
1399         }
1400         catch ( final Exception e ) {
1401             e.printStackTrace( System.out );
1402             return false;
1403         }
1404         return true;
1405     }
1406
1407     private static boolean testBasicNodeMethods() {
1408         try {
1409             if ( PhylogenyNode.getNodeCount() != 0 ) {
1410                 return false;
1411             }
1412             final PhylogenyNode n1 = new PhylogenyNode();
1413             final PhylogenyNode n2 = PhylogenyNode
1414                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1415             final PhylogenyNode n3 = PhylogenyNode
1416                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1417             final PhylogenyNode n4 = PhylogenyNode
1418                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1419             if ( n1.isHasAssignedEvent() ) {
1420                 return false;
1421             }
1422             if ( PhylogenyNode.getNodeCount() != 4 ) {
1423                 return false;
1424             }
1425             if ( n3.getIndicator() != 0 ) {
1426                 return false;
1427             }
1428             if ( n3.getNumberOfExternalNodes() != 1 ) {
1429                 return false;
1430             }
1431             if ( !n3.isExternal() ) {
1432                 return false;
1433             }
1434             if ( !n3.isRoot() ) {
1435                 return false;
1436             }
1437             if ( !n4.getName().equals( "n4" ) ) {
1438                 return false;
1439             }
1440         }
1441         catch ( final Exception e ) {
1442             e.printStackTrace( System.out );
1443             return false;
1444         }
1445         return true;
1446     }
1447
1448     private static boolean testBasicPhyloXMLparsing() {
1449         try {
1450             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1451             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1452             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1453                                                               xml_parser );
1454             if ( xml_parser.getErrorCount() > 0 ) {
1455                 System.out.println( xml_parser.getErrorMessages().toString() );
1456                 return false;
1457             }
1458             if ( phylogenies_0.length != 4 ) {
1459                 return false;
1460             }
1461             final Phylogeny t1 = phylogenies_0[ 0 ];
1462             final Phylogeny t2 = phylogenies_0[ 1 ];
1463             final Phylogeny t3 = phylogenies_0[ 2 ];
1464             final Phylogeny t4 = phylogenies_0[ 3 ];
1465             if ( t1.getNumberOfExternalNodes() != 1 ) {
1466                 return false;
1467             }
1468             if ( !t1.isRooted() ) {
1469                 return false;
1470             }
1471             if ( t1.isRerootable() ) {
1472                 return false;
1473             }
1474             if ( !t1.getType().equals( "gene_tree" ) ) {
1475                 return false;
1476             }
1477             if ( t2.getNumberOfExternalNodes() != 2 ) {
1478                 return false;
1479             }
1480             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1481                 return false;
1482             }
1483             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1484                 return false;
1485             }
1486             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1487                 return false;
1488             }
1489             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1490                 return false;
1491             }
1492             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1493                 return false;
1494             }
1495             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1496                 return false;
1497             }
1498             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1499                     .startsWith( "actgtgggggt" ) ) {
1500                 return false;
1501             }
1502             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1503                     .startsWith( "ctgtgatgcat" ) ) {
1504                 return false;
1505             }
1506             if ( t3.getNumberOfExternalNodes() != 4 ) {
1507                 return false;
1508             }
1509             if ( !t1.getName().equals( "t1" ) ) {
1510                 return false;
1511             }
1512             if ( !t2.getName().equals( "t2" ) ) {
1513                 return false;
1514             }
1515             if ( !t3.getName().equals( "t3" ) ) {
1516                 return false;
1517             }
1518             if ( !t4.getName().equals( "t4" ) ) {
1519                 return false;
1520             }
1521             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1522                 return false;
1523             }
1524             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1525                 return false;
1526             }
1527             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1528                 return false;
1529             }
1530             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1531                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1532                 return false;
1533             }
1534             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1535                 return false;
1536             }
1537             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1538                 return false;
1539             }
1540             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1541                 return false;
1542             }
1543             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1544                     .equals( "apoptosis" ) ) {
1545                 return false;
1546             }
1547             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1548                     .equals( "GO:0006915" ) ) {
1549                 return false;
1550             }
1551             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1552                     .equals( "UniProtKB" ) ) {
1553                 return false;
1554             }
1555             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1556                     .equals( "experimental" ) ) {
1557                 return false;
1558             }
1559             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1560                     .equals( "function" ) ) {
1561                 return false;
1562             }
1563             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1564                     .getValue() != 1 ) {
1565                 return false;
1566             }
1567             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1568                     .getType().equals( "ml" ) ) {
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 ) ).getProperties()
1576                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1577                 return false;
1578             }
1579             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1580                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1581                 return false;
1582             }
1583             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1584                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1585                 return false;
1586             }
1587             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1588                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1589                 return false;
1590             }
1591             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1592                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1593                 return false;
1594             }
1595             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1596                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1597                 return false;
1598             }
1599             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1600                     .equals( "GO:0005829" ) ) {
1601                 return false;
1602             }
1603             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1604                     .equals( "intracellular organelle" ) ) {
1605                 return false;
1606             }
1607             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1608                 return false;
1609             }
1610             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1611                     .equals( "UniProt link" ) ) ) {
1612                 return false;
1613             }
1614             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1615                 return false;
1616             }
1617             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1618             if ( x.size() != 4 ) {
1619                 return false;
1620             }
1621             int c = 0;
1622             for( final Accession acc : x ) {
1623                 if ( c == 0 ) {
1624                     if ( !acc.getSource().equals( "KEGG" ) ) {
1625                         return false;
1626                     }
1627                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1628                         return false;
1629                     }
1630                 }
1631                 c++;
1632             }
1633         }
1634         catch ( final Exception e ) {
1635             e.printStackTrace( System.out );
1636             return false;
1637         }
1638         return true;
1639     }
1640
1641     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1642         try {
1643             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1644             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1645             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1646                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1647             }
1648             else {
1649                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1650             }
1651             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1652                                                               xml_parser );
1653             if ( xml_parser.getErrorCount() > 0 ) {
1654                 System.out.println( xml_parser.getErrorMessages().toString() );
1655                 return false;
1656             }
1657             if ( phylogenies_0.length != 4 ) {
1658                 return false;
1659             }
1660             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1661             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1662             if ( phylogenies_t1.length != 1 ) {
1663                 return false;
1664             }
1665             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1666             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1667                 return false;
1668             }
1669             if ( !t1_rt.isRooted() ) {
1670                 return false;
1671             }
1672             if ( t1_rt.isRerootable() ) {
1673                 return false;
1674             }
1675             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1676                 return false;
1677             }
1678             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1679             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1680             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1681             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1682                 return false;
1683             }
1684             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1685                 return false;
1686             }
1687             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1688                 return false;
1689             }
1690             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1691                 return false;
1692             }
1693             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1694                     .startsWith( "actgtgggggt" ) ) {
1695                 return false;
1696             }
1697             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1698                     .startsWith( "ctgtgatgcat" ) ) {
1699                 return false;
1700             }
1701             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1702             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1703             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1704             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1705             if ( phylogenies_1.length != 1 ) {
1706                 return false;
1707             }
1708             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1709             if ( !t3_rt.getName().equals( "t3" ) ) {
1710                 return false;
1711             }
1712             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1713                 return false;
1714             }
1715             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1716                 return false;
1717             }
1718             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1719                 return false;
1720             }
1721             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1722                 return false;
1723             }
1724             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1725                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1726                 return false;
1727             }
1728             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1729                 return false;
1730             }
1731             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1732                 return false;
1733             }
1734             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1735                     .equals( "UniProtKB" ) ) {
1736                 return false;
1737             }
1738             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1739                     .equals( "apoptosis" ) ) {
1740                 return false;
1741             }
1742             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1743                     .equals( "GO:0006915" ) ) {
1744                 return false;
1745             }
1746             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1747                     .equals( "UniProtKB" ) ) {
1748                 return false;
1749             }
1750             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1751                     .equals( "experimental" ) ) {
1752                 return false;
1753             }
1754             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1755                     .equals( "function" ) ) {
1756                 return false;
1757             }
1758             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1759                     .getValue() != 1 ) {
1760                 return false;
1761             }
1762             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1763                     .getType().equals( "ml" ) ) {
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 ) ).getProperties()
1771                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1772                 return false;
1773             }
1774             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1775                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1776                 return false;
1777             }
1778             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1779                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1780                 return false;
1781             }
1782             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1783                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1784                 return false;
1785             }
1786             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1787                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1788                 return false;
1789             }
1790             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1791                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1792                 return false;
1793             }
1794             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1795                     .equals( "GO:0005829" ) ) {
1796                 return false;
1797             }
1798             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1799                     .equals( "intracellular organelle" ) ) {
1800                 return false;
1801             }
1802             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1803                 return false;
1804             }
1805             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1806                     .equals( "UniProt link" ) ) ) {
1807                 return false;
1808             }
1809             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1810                 return false;
1811             }
1812             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1813                 return false;
1814             }
1815             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1816                     .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." ) ) ) {
1817                 return false;
1818             }
1819             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1820                 return false;
1821             }
1822             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1823                 return false;
1824             }
1825             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1826                 return false;
1827             }
1828             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1829                 return false;
1830             }
1831             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1832                     .equals( "ncbi" ) ) {
1833                 return false;
1834             }
1835             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1836                 return false;
1837             }
1838             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1839                     .getName().equals( "B" ) ) {
1840                 return false;
1841             }
1842             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1843                     .getFrom() != 21 ) {
1844                 return false;
1845             }
1846             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1847                 return false;
1848             }
1849             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1850                     .getLength() != 24 ) {
1851                 return false;
1852             }
1853             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1854                     .getConfidence() != 2144 ) {
1855                 return false;
1856             }
1857             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1858                     .equals( "pfam" ) ) {
1859                 return false;
1860             }
1861             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1862                 return false;
1863             }
1864             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1865                 return false;
1866             }
1867             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1868                 return false;
1869             }
1870             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1871                 return false;
1872             }
1873             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1874             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1875                 return false;
1876             }
1877             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1878                 return false;
1879             }
1880             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1881                 return false;
1882             }
1883             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1884                 return false;
1885             }
1886             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1887                 return false;
1888             }
1889             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1890                 return false;
1891             }
1892             if ( taxbb.getSynonyms().size() != 2 ) {
1893                 return false;
1894             }
1895             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1896                 return false;
1897             }
1898             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1899                 return false;
1900             }
1901             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1902                 return false;
1903             }
1904             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1905                 return false;
1906             }
1907             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1908                 return false;
1909             }
1910             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1911                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1912                 return false;
1913             }
1914             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1915                 return false;
1916             }
1917             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1918                 return false;
1919             }
1920             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1921                 return false;
1922             }
1923             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1924                 return false;
1925             }
1926             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1927                 return false;
1928             }
1929             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1930                 return false;
1931             }
1932             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1933                 return false;
1934             }
1935             //
1936             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1937                 return false;
1938             }
1939             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1940                     .equalsIgnoreCase( "435" ) ) {
1941                 return false;
1942             }
1943             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1944                 return false;
1945             }
1946             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1947                     .equalsIgnoreCase( "443.7" ) ) {
1948                 return false;
1949             }
1950             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1951                 return false;
1952             }
1953             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1954                 return false;
1955             }
1956             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1957                     .equalsIgnoreCase( "433" ) ) {
1958                 return false;
1959             }
1960             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
1961                     .getCrossReferences();
1962             if ( x.size() != 4 ) {
1963                 return false;
1964             }
1965             int c = 0;
1966             for( final Accession acc : x ) {
1967                 if ( c == 0 ) {
1968                     if ( !acc.getSource().equals( "KEGG" ) ) {
1969                         return false;
1970                     }
1971                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1972                         return false;
1973                     }
1974                 }
1975                 c++;
1976             }
1977         }
1978         catch ( final Exception e ) {
1979             e.printStackTrace( System.out );
1980             return false;
1981         }
1982         return true;
1983     }
1984
1985     private static boolean testBasicPhyloXMLparsingValidating() {
1986         try {
1987             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1988             PhyloXmlParser xml_parser = null;
1989             try {
1990                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1991             }
1992             catch ( final Exception e ) {
1993                 // Do nothing -- means were not running from jar.
1994             }
1995             if ( xml_parser == null ) {
1996                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
1997                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1998                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1999                 }
2000                 else {
2001                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2002                 }
2003             }
2004             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2005                                                               xml_parser );
2006             if ( xml_parser.getErrorCount() > 0 ) {
2007                 System.out.println( xml_parser.getErrorMessages().toString() );
2008                 return false;
2009             }
2010             if ( phylogenies_0.length != 4 ) {
2011                 return false;
2012             }
2013             final Phylogeny t1 = phylogenies_0[ 0 ];
2014             final Phylogeny t2 = phylogenies_0[ 1 ];
2015             final Phylogeny t3 = phylogenies_0[ 2 ];
2016             final Phylogeny t4 = phylogenies_0[ 3 ];
2017             if ( !t1.getName().equals( "t1" ) ) {
2018                 return false;
2019             }
2020             if ( !t2.getName().equals( "t2" ) ) {
2021                 return false;
2022             }
2023             if ( !t3.getName().equals( "t3" ) ) {
2024                 return false;
2025             }
2026             if ( !t4.getName().equals( "t4" ) ) {
2027                 return false;
2028             }
2029             if ( t1.getNumberOfExternalNodes() != 1 ) {
2030                 return false;
2031             }
2032             if ( t2.getNumberOfExternalNodes() != 2 ) {
2033                 return false;
2034             }
2035             if ( t3.getNumberOfExternalNodes() != 4 ) {
2036                 return false;
2037             }
2038             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2039             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2040             if ( xml_parser.getErrorCount() > 0 ) {
2041                 System.out.println( "errors:" );
2042                 System.out.println( xml_parser.getErrorMessages().toString() );
2043                 return false;
2044             }
2045             if ( phylogenies_1.length != 4 ) {
2046                 return false;
2047             }
2048             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2049                                                               xml_parser );
2050             if ( xml_parser.getErrorCount() > 0 ) {
2051                 System.out.println( "errors:" );
2052                 System.out.println( xml_parser.getErrorMessages().toString() );
2053                 return false;
2054             }
2055             if ( phylogenies_2.length != 1 ) {
2056                 return false;
2057             }
2058             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2059                 return false;
2060             }
2061             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2062                                                               xml_parser );
2063             if ( xml_parser.getErrorCount() > 0 ) {
2064                 System.out.println( xml_parser.getErrorMessages().toString() );
2065                 return false;
2066             }
2067             if ( phylogenies_3.length != 2 ) {
2068                 return false;
2069             }
2070             final Phylogeny a = phylogenies_3[ 0 ];
2071             if ( !a.getName().equals( "tree 4" ) ) {
2072                 return false;
2073             }
2074             if ( a.getNumberOfExternalNodes() != 3 ) {
2075                 return false;
2076             }
2077             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2078                 return false;
2079             }
2080             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2081                 return false;
2082             }
2083             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2084                                                               xml_parser );
2085             if ( xml_parser.getErrorCount() > 0 ) {
2086                 System.out.println( xml_parser.getErrorMessages().toString() );
2087                 return false;
2088             }
2089             if ( phylogenies_4.length != 1 ) {
2090                 return false;
2091             }
2092             final Phylogeny s = phylogenies_4[ 0 ];
2093             if ( s.getNumberOfExternalNodes() != 6 ) {
2094                 return false;
2095             }
2096             s.getNode( "first" );
2097             s.getNode( "<>" );
2098             s.getNode( "\"<a'b&c'd\">\"" );
2099             s.getNode( "'''\"" );
2100             s.getNode( "\"\"\"" );
2101             s.getNode( "dick & doof" );
2102         }
2103         catch ( final Exception e ) {
2104             e.printStackTrace( System.out );
2105             return false;
2106         }
2107         return true;
2108     }
2109
2110     private static boolean testBasicProtein() {
2111         try {
2112             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2113             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2114             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2115             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2116             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2117             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2118             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2119             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2120             p0.addProteinDomain( y );
2121             p0.addProteinDomain( e );
2122             p0.addProteinDomain( b );
2123             p0.addProteinDomain( c );
2124             p0.addProteinDomain( d );
2125             p0.addProteinDomain( a );
2126             p0.addProteinDomain( x );
2127             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2128                 return false;
2129             }
2130             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2131                 return false;
2132             }
2133             //
2134             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2135             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2136             aa0.addProteinDomain( a1 );
2137             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2138                 return false;
2139             }
2140             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2141                 return false;
2142             }
2143             //
2144             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2145             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2146             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2147             aa1.addProteinDomain( a11 );
2148             aa1.addProteinDomain( a12 );
2149             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2150                 return false;
2151             }
2152             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2153                 return false;
2154             }
2155             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2156             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2157                 return false;
2158             }
2159             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2160                 return false;
2161             }
2162             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2163                 return false;
2164             }
2165             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2166             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2167                 return false;
2168             }
2169             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2170                 return false;
2171             }
2172             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2173                 return false;
2174             }
2175             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2176                 return false;
2177             }
2178             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2179             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2180                 return false;
2181             }
2182             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2183                 return false;
2184             }
2185             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2186                 return false;
2187             }
2188             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2189                 return false;
2190             }
2191             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2192             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2193                 return false;
2194             }
2195             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2196                 return false;
2197             }
2198             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2199                 return false;
2200             }
2201             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2202                 return false;
2203             }
2204             //
2205             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2206             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2207             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2208             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2209             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2210             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2211             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2212             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2213             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2214             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2215             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2216             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2217             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2218             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2219             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2220             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2221             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2222             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2223             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2224             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2225             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2226             p00.addProteinDomain( y0 );
2227             p00.addProteinDomain( e0 );
2228             p00.addProteinDomain( b0 );
2229             p00.addProteinDomain( c0 );
2230             p00.addProteinDomain( d0 );
2231             p00.addProteinDomain( a0 );
2232             p00.addProteinDomain( x0 );
2233             p00.addProteinDomain( y1 );
2234             p00.addProteinDomain( y2 );
2235             p00.addProteinDomain( y3 );
2236             p00.addProteinDomain( e1 );
2237             p00.addProteinDomain( e2 );
2238             p00.addProteinDomain( e3 );
2239             p00.addProteinDomain( e4 );
2240             p00.addProteinDomain( e5 );
2241             p00.addProteinDomain( z0 );
2242             p00.addProteinDomain( z1 );
2243             p00.addProteinDomain( z2 );
2244             p00.addProteinDomain( zz0 );
2245             p00.addProteinDomain( zz1 );
2246             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2247                 return false;
2248             }
2249             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2250                 return false;
2251             }
2252             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2253                 return false;
2254             }
2255             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2256                 return false;
2257             }
2258             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" ) ) {
2259                 return false;
2260             }
2261             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2262             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2263             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2264             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2265             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2266             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2267             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2268             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2269             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2270             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2271             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2272             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2273             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2274             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2275             p.addProteinDomain( B15 );
2276             p.addProteinDomain( C50 );
2277             p.addProteinDomain( A60 );
2278             p.addProteinDomain( A30 );
2279             p.addProteinDomain( C70 );
2280             p.addProteinDomain( B35 );
2281             p.addProteinDomain( B40 );
2282             p.addProteinDomain( A0 );
2283             p.addProteinDomain( A10 );
2284             p.addProteinDomain( A20 );
2285             p.addProteinDomain( B25 );
2286             p.addProteinDomain( D80 );
2287             List<String> domains_ids = new ArrayList<String>();
2288             domains_ids.add( "A" );
2289             domains_ids.add( "B" );
2290             domains_ids.add( "C" );
2291             if ( !p.contains( domains_ids, false ) ) {
2292                 return false;
2293             }
2294             if ( !p.contains( domains_ids, true ) ) {
2295                 return false;
2296             }
2297             domains_ids.add( "X" );
2298             if ( p.contains( domains_ids, false ) ) {
2299                 return false;
2300             }
2301             if ( p.contains( domains_ids, true ) ) {
2302                 return false;
2303             }
2304             domains_ids = new ArrayList<String>();
2305             domains_ids.add( "A" );
2306             domains_ids.add( "C" );
2307             domains_ids.add( "D" );
2308             if ( !p.contains( domains_ids, false ) ) {
2309                 return false;
2310             }
2311             if ( !p.contains( domains_ids, true ) ) {
2312                 return false;
2313             }
2314             domains_ids = new ArrayList<String>();
2315             domains_ids.add( "A" );
2316             domains_ids.add( "D" );
2317             domains_ids.add( "C" );
2318             if ( !p.contains( domains_ids, false ) ) {
2319                 return false;
2320             }
2321             if ( p.contains( domains_ids, true ) ) {
2322                 return false;
2323             }
2324             domains_ids = new ArrayList<String>();
2325             domains_ids.add( "A" );
2326             domains_ids.add( "A" );
2327             domains_ids.add( "B" );
2328             if ( !p.contains( domains_ids, false ) ) {
2329                 return false;
2330             }
2331             if ( !p.contains( domains_ids, true ) ) {
2332                 return false;
2333             }
2334             domains_ids = new ArrayList<String>();
2335             domains_ids.add( "A" );
2336             domains_ids.add( "A" );
2337             domains_ids.add( "A" );
2338             domains_ids.add( "B" );
2339             domains_ids.add( "B" );
2340             if ( !p.contains( domains_ids, false ) ) {
2341                 return false;
2342             }
2343             if ( !p.contains( domains_ids, true ) ) {
2344                 return false;
2345             }
2346             domains_ids = new ArrayList<String>();
2347             domains_ids.add( "A" );
2348             domains_ids.add( "A" );
2349             domains_ids.add( "B" );
2350             domains_ids.add( "A" );
2351             domains_ids.add( "B" );
2352             domains_ids.add( "B" );
2353             domains_ids.add( "A" );
2354             domains_ids.add( "B" );
2355             domains_ids.add( "C" );
2356             domains_ids.add( "A" );
2357             domains_ids.add( "C" );
2358             domains_ids.add( "D" );
2359             if ( !p.contains( domains_ids, false ) ) {
2360                 return false;
2361             }
2362             if ( p.contains( domains_ids, true ) ) {
2363                 return false;
2364             }
2365         }
2366         catch ( final Exception e ) {
2367             e.printStackTrace( System.out );
2368             return false;
2369         }
2370         return true;
2371     }
2372
2373     private static boolean testBasicTable() {
2374         try {
2375             final BasicTable<String> t0 = new BasicTable<String>();
2376             if ( t0.getNumberOfColumns() != 0 ) {
2377                 return false;
2378             }
2379             if ( t0.getNumberOfRows() != 0 ) {
2380                 return false;
2381             }
2382             t0.setValue( 3, 2, "23" );
2383             t0.setValue( 10, 1, "error" );
2384             t0.setValue( 10, 1, "110" );
2385             t0.setValue( 9, 1, "19" );
2386             t0.setValue( 1, 10, "101" );
2387             t0.setValue( 10, 10, "1010" );
2388             t0.setValue( 100, 10, "10100" );
2389             t0.setValue( 0, 0, "00" );
2390             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2391                 return false;
2392             }
2393             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2394                 return false;
2395             }
2396             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2397                 return false;
2398             }
2399             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2400                 return false;
2401             }
2402             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2403                 return false;
2404             }
2405             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2406                 return false;
2407             }
2408             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2409                 return false;
2410             }
2411             if ( t0.getNumberOfColumns() != 101 ) {
2412                 return false;
2413             }
2414             if ( t0.getNumberOfRows() != 11 ) {
2415                 return false;
2416             }
2417             if ( t0.getValueAsString( 49, 4 ) != null ) {
2418                 return false;
2419             }
2420             final String l = ForesterUtil.getLineSeparator();
2421             final StringBuffer source = new StringBuffer();
2422             source.append( "" + l );
2423             source.append( "# 1 1 1 1 1 1 1 1" + l );
2424             source.append( " 00 01 02 03" + l );
2425             source.append( "   10 11 12 13  " + l );
2426             source.append( "20 21 22 23 " + l );
2427             source.append( "    30  31    32 33" + l );
2428             source.append( "40 41 42 43" + l );
2429             source.append( "  # 1 1 1 1 1 " + l );
2430             source.append( "50 51 52 53 54" + l );
2431             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2432             if ( t1.getNumberOfColumns() != 5 ) {
2433                 return false;
2434             }
2435             if ( t1.getNumberOfRows() != 6 ) {
2436                 return false;
2437             }
2438             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2439                 return false;
2440             }
2441             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2442                 return false;
2443             }
2444             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2445                 return false;
2446             }
2447             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2448                 return false;
2449             }
2450             final StringBuffer source1 = new StringBuffer();
2451             source1.append( "" + l );
2452             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2453             source1.append( " 00; 01 ;02;03" + l );
2454             source1.append( "   10; 11; 12; 13  " + l );
2455             source1.append( "20; 21; 22; 23 " + l );
2456             source1.append( "    30;  31;    32; 33" + l );
2457             source1.append( "40;41;42;43" + l );
2458             source1.append( "  # 1 1 1 1 1 " + l );
2459             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2460             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2461             if ( t2.getNumberOfColumns() != 5 ) {
2462                 return false;
2463             }
2464             if ( t2.getNumberOfRows() != 6 ) {
2465                 return false;
2466             }
2467             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2468                 return false;
2469             }
2470             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2471                 return false;
2472             }
2473             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2474                 return false;
2475             }
2476             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2477                 return false;
2478             }
2479             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2480                 return false;
2481             }
2482             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2483                 return false;
2484             }
2485             final StringBuffer source2 = new StringBuffer();
2486             source2.append( "" + l );
2487             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2488             source2.append( " 00; 01 ;02;03" + l );
2489             source2.append( "   10; 11; 12; 13  " + l );
2490             source2.append( "20; 21; 22; 23 " + l );
2491             source2.append( "                     " + l );
2492             source2.append( "    30;  31;    32; 33" + l );
2493             source2.append( "40;41;42;43" + l );
2494             source2.append( "  comment: 1 1 1 1 1 " + l );
2495             source2.append( ";;;50  ;   52; 53;;54   " + l );
2496             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2497                                                                         ';',
2498                                                                         false,
2499                                                                         false,
2500                                                                         "comment:",
2501                                                                         false );
2502             if ( tl.size() != 2 ) {
2503                 return false;
2504             }
2505             final BasicTable<String> t3 = tl.get( 0 );
2506             final BasicTable<String> t4 = tl.get( 1 );
2507             if ( t3.getNumberOfColumns() != 4 ) {
2508                 return false;
2509             }
2510             if ( t3.getNumberOfRows() != 3 ) {
2511                 return false;
2512             }
2513             if ( t4.getNumberOfColumns() != 4 ) {
2514                 return false;
2515             }
2516             if ( t4.getNumberOfRows() != 3 ) {
2517                 return false;
2518             }
2519             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2520                 return false;
2521             }
2522             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2523                 return false;
2524             }
2525         }
2526         catch ( final Exception e ) {
2527             e.printStackTrace( System.out );
2528             return false;
2529         }
2530         return true;
2531     }
2532
2533     private static boolean testBasicTolXMLparsing() {
2534         try {
2535             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2536             final TolParser parser = new TolParser();
2537             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2538             if ( parser.getErrorCount() > 0 ) {
2539                 System.out.println( parser.getErrorMessages().toString() );
2540                 return false;
2541             }
2542             if ( phylogenies_0.length != 1 ) {
2543                 return false;
2544             }
2545             final Phylogeny t1 = phylogenies_0[ 0 ];
2546             if ( t1.getNumberOfExternalNodes() != 5 ) {
2547                 return false;
2548             }
2549             if ( !t1.isRooted() ) {
2550                 return false;
2551             }
2552             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2553                 return false;
2554             }
2555             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2556                 return false;
2557             }
2558             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2559                 return false;
2560             }
2561             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2562                 return false;
2563             }
2564             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2565             if ( parser.getErrorCount() > 0 ) {
2566                 System.out.println( parser.getErrorMessages().toString() );
2567                 return false;
2568             }
2569             if ( phylogenies_1.length != 1 ) {
2570                 return false;
2571             }
2572             final Phylogeny t2 = phylogenies_1[ 0 ];
2573             if ( t2.getNumberOfExternalNodes() != 664 ) {
2574                 return false;
2575             }
2576             if ( !t2.isRooted() ) {
2577                 return false;
2578             }
2579             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2580                 return false;
2581             }
2582             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2583                 return false;
2584             }
2585             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2586                 return false;
2587             }
2588             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2589                 return false;
2590             }
2591             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2592                 return false;
2593             }
2594             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2595                     .equals( "Aquifex" ) ) {
2596                 return false;
2597             }
2598             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2599             if ( parser.getErrorCount() > 0 ) {
2600                 System.out.println( parser.getErrorMessages().toString() );
2601                 return false;
2602             }
2603             if ( phylogenies_2.length != 1 ) {
2604                 return false;
2605             }
2606             final Phylogeny t3 = phylogenies_2[ 0 ];
2607             if ( t3.getNumberOfExternalNodes() != 184 ) {
2608                 return false;
2609             }
2610             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2611                 return false;
2612             }
2613             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2614                 return false;
2615             }
2616             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2617                 return false;
2618             }
2619             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2620             if ( parser.getErrorCount() > 0 ) {
2621                 System.out.println( parser.getErrorMessages().toString() );
2622                 return false;
2623             }
2624             if ( phylogenies_3.length != 1 ) {
2625                 return false;
2626             }
2627             final Phylogeny t4 = phylogenies_3[ 0 ];
2628             if ( t4.getNumberOfExternalNodes() != 1 ) {
2629                 return false;
2630             }
2631             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2632                 return false;
2633             }
2634             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2635                 return false;
2636             }
2637             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2638                 return false;
2639             }
2640             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2641             if ( parser.getErrorCount() > 0 ) {
2642                 System.out.println( parser.getErrorMessages().toString() );
2643                 return false;
2644             }
2645             if ( phylogenies_4.length != 1 ) {
2646                 return false;
2647             }
2648             final Phylogeny t5 = phylogenies_4[ 0 ];
2649             if ( t5.getNumberOfExternalNodes() != 13 ) {
2650                 return false;
2651             }
2652             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2653                 return false;
2654             }
2655             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2656                 return false;
2657             }
2658             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2659                 return false;
2660             }
2661         }
2662         catch ( final Exception e ) {
2663             e.printStackTrace( System.out );
2664             return false;
2665         }
2666         return true;
2667     }
2668
2669     private static boolean testBasicTreeMethods() {
2670         try {
2671             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2672             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2673             if ( t2.getNumberOfExternalNodes() != 4 ) {
2674                 return false;
2675             }
2676             if ( t2.getHeight() != 8.5 ) {
2677                 return false;
2678             }
2679             if ( !t2.isCompletelyBinary() ) {
2680                 return false;
2681             }
2682             if ( t2.isEmpty() ) {
2683                 return false;
2684             }
2685             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2686             if ( t3.getNumberOfExternalNodes() != 5 ) {
2687                 return false;
2688             }
2689             if ( t3.getHeight() != 11 ) {
2690                 return false;
2691             }
2692             if ( t3.isCompletelyBinary() ) {
2693                 return false;
2694             }
2695             final PhylogenyNode n = t3.getNode( "ABC" );
2696             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 ];
2697             if ( t4.getNumberOfExternalNodes() != 9 ) {
2698                 return false;
2699             }
2700             if ( t4.getHeight() != 11 ) {
2701                 return false;
2702             }
2703             if ( t4.isCompletelyBinary() ) {
2704                 return false;
2705             }
2706             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)" );
2707             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2708             if ( t5.getNumberOfExternalNodes() != 8 ) {
2709                 return false;
2710             }
2711             if ( t5.getHeight() != 15 ) {
2712                 return false;
2713             }
2714             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)" );
2715             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2716             if ( t6.getHeight() != 15 ) {
2717                 return false;
2718             }
2719             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)" );
2720             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2721             if ( t7.getHeight() != 15 ) {
2722                 return false;
2723             }
2724             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)" );
2725             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2726             if ( t8.getNumberOfExternalNodes() != 10 ) {
2727                 return false;
2728             }
2729             if ( t8.getHeight() != 15 ) {
2730                 return false;
2731             }
2732             final char[] a9 = new char[] { 'a' };
2733             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2734             if ( t9.getHeight() != 0 ) {
2735                 return false;
2736             }
2737             final char[] a10 = new char[] { 'a', ':', '6' };
2738             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2739             if ( t10.getHeight() != 6 ) {
2740                 return false;
2741             }
2742         }
2743         catch ( final Exception e ) {
2744             e.printStackTrace( System.out );
2745             return false;
2746         }
2747         return true;
2748     }
2749
2750     private static boolean testConfidenceAssessor() {
2751         try {
2752             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2753             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2754             final Phylogeny[] ev0 = factory
2755                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2756                              new NHXParser() );
2757             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2758             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2759                 return false;
2760             }
2761             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2762                 return false;
2763             }
2764             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2765             final Phylogeny[] ev1 = factory
2766                     .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)));",
2767                              new NHXParser() );
2768             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2769             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2770                 return false;
2771             }
2772             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2773                 return false;
2774             }
2775             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2776             final Phylogeny[] ev_b = factory
2777                     .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",
2778                              new NHXParser() );
2779             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2780             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2781                 return false;
2782             }
2783             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2784                 return false;
2785             }
2786             //
2787             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2788             final Phylogeny[] ev1x = factory
2789                     .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)));",
2790                              new NHXParser() );
2791             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2792             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2793                 return false;
2794             }
2795             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2796                 return false;
2797             }
2798             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2799             final Phylogeny[] ev_bx = factory
2800                     .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",
2801                              new NHXParser() );
2802             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2803             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2804                 return false;
2805             }
2806             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2807                 return false;
2808             }
2809             //
2810             final Phylogeny[] t2 = factory
2811                     .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);",
2812                              new NHXParser() );
2813             final Phylogeny[] ev2 = factory
2814                     .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);",
2815                              new NHXParser() );
2816             for( final Phylogeny target : t2 ) {
2817                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2818             }
2819             //
2820             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2821                                                  new NHXParser() )[ 0 ];
2822             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2823             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2824             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2825                 return false;
2826             }
2827             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2828                 return false;
2829             }
2830             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2831                 return false;
2832             }
2833         }
2834         catch ( final Exception e ) {
2835             e.printStackTrace();
2836             return false;
2837         }
2838         return true;
2839     }
2840
2841     private static boolean testCopyOfNodeData() {
2842         try {
2843             final PhylogenyNode n1 = PhylogenyNode
2844                     .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]" );
2845             final PhylogenyNode n2 = n1.copyNodeData();
2846             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2847                 return false;
2848             }
2849         }
2850         catch ( final Exception e ) {
2851             e.printStackTrace();
2852             return false;
2853         }
2854         return true;
2855     }
2856
2857     private static boolean testCreateBalancedPhylogeny() {
2858         try {
2859             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2860             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2861                 return false;
2862             }
2863             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2864                 return false;
2865             }
2866             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2867             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2868                 return false;
2869             }
2870             if ( p1.getNumberOfExternalNodes() != 100 ) {
2871                 return false;
2872             }
2873         }
2874         catch ( final Exception e ) {
2875             e.printStackTrace();
2876             return false;
2877         }
2878         return true;
2879     }
2880
2881     private static boolean testCreateUriForSeqWeb() {
2882         try {
2883             final PhylogenyNode n = new PhylogenyNode();
2884             n.setName( "tr|B3RJ64" );
2885             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2886                 return false;
2887             }
2888             n.setName( "B0LM41_HUMAN" );
2889             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2890                 return false;
2891             }
2892             n.setName( "NP_001025424" );
2893             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2894                 return false;
2895             }
2896             n.setName( "_NM_001030253-" );
2897             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2898                 return false;
2899             }
2900             n.setName( "XM_002122186" );
2901             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2902                 return false;
2903             }
2904             n.setName( "dgh_AAA34956_gdg" );
2905             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2906                 return false;
2907             }
2908             n.setName( "AAA34956" );
2909             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2910                 return false;
2911             }
2912             n.setName( "GI:394892" );
2913             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2914                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2915                 return false;
2916             }
2917             n.setName( "gi_394892" );
2918             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2919                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2920                 return false;
2921             }
2922             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2923             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2924                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2925                 return false;
2926             }
2927             n.setName( "P12345" );
2928             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2929                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2930                 return false;
2931             }
2932             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
2933             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2934                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2935                 return false;
2936             }
2937         }
2938         catch ( final Exception e ) {
2939             e.printStackTrace( System.out );
2940             return false;
2941         }
2942         return true;
2943     }
2944
2945     private static boolean testDataObjects() {
2946         try {
2947             final Confidence s0 = new Confidence();
2948             final Confidence s1 = new Confidence();
2949             if ( !s0.isEqual( s1 ) ) {
2950                 return false;
2951             }
2952             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2953             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2954             if ( s2.isEqual( s1 ) ) {
2955                 return false;
2956             }
2957             if ( !s2.isEqual( s3 ) ) {
2958                 return false;
2959             }
2960             final Confidence s4 = ( Confidence ) s3.copy();
2961             if ( !s4.isEqual( s3 ) ) {
2962                 return false;
2963             }
2964             s3.asSimpleText();
2965             s3.asText();
2966             // Taxonomy
2967             // ----------
2968             final Taxonomy t1 = new Taxonomy();
2969             final Taxonomy t2 = new Taxonomy();
2970             final Taxonomy t3 = new Taxonomy();
2971             final Taxonomy t4 = new Taxonomy();
2972             final Taxonomy t5 = new Taxonomy();
2973             t1.setIdentifier( new Identifier( "ecoli" ) );
2974             t1.setTaxonomyCode( "ECOLI" );
2975             t1.setScientificName( "E. coli" );
2976             t1.setCommonName( "coli" );
2977             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2978             if ( !t1.isEqual( t0 ) ) {
2979                 return false;
2980             }
2981             t2.setIdentifier( new Identifier( "ecoli" ) );
2982             t2.setTaxonomyCode( "OTHER" );
2983             t2.setScientificName( "what" );
2984             t2.setCommonName( "something" );
2985             if ( !t1.isEqual( t2 ) ) {
2986                 return false;
2987             }
2988             t2.setIdentifier( new Identifier( "nemve" ) );
2989             if ( t1.isEqual( t2 ) ) {
2990                 return false;
2991             }
2992             t1.setIdentifier( null );
2993             t3.setTaxonomyCode( "ECOLI" );
2994             t3.setScientificName( "what" );
2995             t3.setCommonName( "something" );
2996             if ( !t1.isEqual( t3 ) ) {
2997                 return false;
2998             }
2999             t1.setIdentifier( null );
3000             t1.setTaxonomyCode( "" );
3001             t4.setScientificName( "E. ColI" );
3002             t4.setCommonName( "something" );
3003             if ( !t1.isEqual( t4 ) ) {
3004                 return false;
3005             }
3006             t4.setScientificName( "B. subtilis" );
3007             t4.setCommonName( "something" );
3008             if ( t1.isEqual( t4 ) ) {
3009                 return false;
3010             }
3011             t1.setIdentifier( null );
3012             t1.setTaxonomyCode( "" );
3013             t1.setScientificName( "" );
3014             t5.setCommonName( "COLI" );
3015             if ( !t1.isEqual( t5 ) ) {
3016                 return false;
3017             }
3018             t5.setCommonName( "vibrio" );
3019             if ( t1.isEqual( t5 ) ) {
3020                 return false;
3021             }
3022             // Identifier
3023             // ----------
3024             final Identifier id0 = new Identifier( "123", "pfam" );
3025             final Identifier id1 = ( Identifier ) id0.copy();
3026             if ( !id1.isEqual( id1 ) ) {
3027                 return false;
3028             }
3029             if ( !id1.isEqual( id0 ) ) {
3030                 return false;
3031             }
3032             if ( !id0.isEqual( id1 ) ) {
3033                 return false;
3034             }
3035             id1.asSimpleText();
3036             id1.asText();
3037             // ProteinDomain
3038             // ---------------
3039             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3040             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3041             if ( !pd1.isEqual( pd1 ) ) {
3042                 return false;
3043             }
3044             if ( !pd1.isEqual( pd0 ) ) {
3045                 return false;
3046             }
3047             pd1.asSimpleText();
3048             pd1.asText();
3049             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3050             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3051             if ( !pd3.isEqual( pd3 ) ) {
3052                 return false;
3053             }
3054             if ( !pd2.isEqual( pd3 ) ) {
3055                 return false;
3056             }
3057             if ( !pd0.isEqual( pd3 ) ) {
3058                 return false;
3059             }
3060             pd3.asSimpleText();
3061             pd3.asText();
3062             // DomainArchitecture
3063             // ------------------
3064             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3065             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3066             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3067             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3068             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3069             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3070             domains0.add( d2 );
3071             domains0.add( d0 );
3072             domains0.add( d3 );
3073             domains0.add( d1 );
3074             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3075             if ( ds0.getNumberOfDomains() != 4 ) {
3076                 return false;
3077             }
3078             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3079             if ( !ds0.isEqual( ds0 ) ) {
3080                 return false;
3081             }
3082             if ( !ds0.isEqual( ds1 ) ) {
3083                 return false;
3084             }
3085             if ( ds1.getNumberOfDomains() != 4 ) {
3086                 return false;
3087             }
3088             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3089             domains1.add( d1 );
3090             domains1.add( d2 );
3091             domains1.add( d4 );
3092             domains1.add( d0 );
3093             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3094             if ( ds0.isEqual( ds2 ) ) {
3095                 return false;
3096             }
3097             ds1.asSimpleText();
3098             ds1.asText();
3099             ds1.toNHX();
3100             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3101             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3102                 System.out.println( ds3.toNHX() );
3103                 return false;
3104             }
3105             if ( ds3.getNumberOfDomains() != 3 ) {
3106                 return false;
3107             }
3108             // Event
3109             // -----
3110             final Event e1 = new Event( Event.EventType.fusion );
3111             if ( e1.isDuplication() ) {
3112                 return false;
3113             }
3114             if ( !e1.isFusion() ) {
3115                 return false;
3116             }
3117             if ( !e1.asText().toString().equals( "fusion" ) ) {
3118                 return false;
3119             }
3120             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3121                 return false;
3122             }
3123             final Event e11 = new Event( Event.EventType.fusion );
3124             if ( !e11.isEqual( e1 ) ) {
3125                 return false;
3126             }
3127             if ( !e11.toNHX().toString().equals( "" ) ) {
3128                 return false;
3129             }
3130             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3131             if ( e2.isDuplication() ) {
3132                 return false;
3133             }
3134             if ( !e2.isSpeciationOrDuplication() ) {
3135                 return false;
3136             }
3137             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3138                 return false;
3139             }
3140             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3141                 return false;
3142             }
3143             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3144                 return false;
3145             }
3146             if ( e11.isEqual( e2 ) ) {
3147                 return false;
3148             }
3149             final Event e2c = ( Event ) e2.copy();
3150             if ( !e2c.isEqual( e2 ) ) {
3151                 return false;
3152             }
3153             Event e3 = new Event( 1, 2, 3 );
3154             if ( e3.isDuplication() ) {
3155                 return false;
3156             }
3157             if ( e3.isSpeciation() ) {
3158                 return false;
3159             }
3160             if ( e3.isGeneLoss() ) {
3161                 return false;
3162             }
3163             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3164                 return false;
3165             }
3166             final Event e3c = ( Event ) e3.copy();
3167             final Event e3cc = ( Event ) e3c.copy();
3168             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3169                 return false;
3170             }
3171             e3 = null;
3172             if ( !e3c.isEqual( e3cc ) ) {
3173                 return false;
3174             }
3175             Event e4 = new Event( 1, 2, 3 );
3176             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3177                 return false;
3178             }
3179             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3180                 return false;
3181             }
3182             final Event e4c = ( Event ) e4.copy();
3183             e4 = null;
3184             final Event e4cc = ( Event ) e4c.copy();
3185             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3186                 return false;
3187             }
3188             if ( !e4c.isEqual( e4cc ) ) {
3189                 return false;
3190             }
3191             final Event e5 = new Event();
3192             if ( !e5.isUnassigned() ) {
3193                 return false;
3194             }
3195             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3196                 return false;
3197             }
3198             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3199                 return false;
3200             }
3201             final Event e6 = new Event( 1, 0, 0 );
3202             if ( !e6.asText().toString().equals( "duplication" ) ) {
3203                 return false;
3204             }
3205             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3206                 return false;
3207             }
3208             final Event e7 = new Event( 0, 1, 0 );
3209             if ( !e7.asText().toString().equals( "speciation" ) ) {
3210                 return false;
3211             }
3212             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3213                 return false;
3214             }
3215             final Event e8 = new Event( 0, 0, 1 );
3216             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3217                 return false;
3218             }
3219             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3220                 return false;
3221             }
3222         }
3223         catch ( final Exception e ) {
3224             e.printStackTrace( System.out );
3225             return false;
3226         }
3227         return true;
3228     }
3229
3230     private static boolean testDeletionOfExternalNodes() {
3231         try {
3232             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3233             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3234             final PhylogenyWriter w = new PhylogenyWriter();
3235             if ( t0.isEmpty() ) {
3236                 return false;
3237             }
3238             if ( t0.getNumberOfExternalNodes() != 1 ) {
3239                 return false;
3240             }
3241             t0.deleteSubtree( t0.getNode( "A" ), false );
3242             if ( t0.getNumberOfExternalNodes() != 0 ) {
3243                 return false;
3244             }
3245             if ( !t0.isEmpty() ) {
3246                 return false;
3247             }
3248             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3249             if ( t1.getNumberOfExternalNodes() != 2 ) {
3250                 return false;
3251             }
3252             t1.deleteSubtree( t1.getNode( "A" ), false );
3253             if ( t1.getNumberOfExternalNodes() != 1 ) {
3254                 return false;
3255             }
3256             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3257                 return false;
3258             }
3259             t1.deleteSubtree( t1.getNode( "B" ), false );
3260             if ( t1.getNumberOfExternalNodes() != 1 ) {
3261                 return false;
3262             }
3263             t1.deleteSubtree( t1.getNode( "r" ), false );
3264             if ( !t1.isEmpty() ) {
3265                 return false;
3266             }
3267             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3268             if ( t2.getNumberOfExternalNodes() != 3 ) {
3269                 return false;
3270             }
3271             t2.deleteSubtree( t2.getNode( "B" ), false );
3272             if ( t2.getNumberOfExternalNodes() != 2 ) {
3273                 return false;
3274             }
3275             t2.toNewHampshireX();
3276             PhylogenyNode n = t2.getNode( "A" );
3277             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3278                 return false;
3279             }
3280             t2.deleteSubtree( t2.getNode( "A" ), false );
3281             if ( t2.getNumberOfExternalNodes() != 2 ) {
3282                 return false;
3283             }
3284             t2.deleteSubtree( t2.getNode( "C" ), true );
3285             if ( t2.getNumberOfExternalNodes() != 1 ) {
3286                 return false;
3287             }
3288             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3289             if ( t3.getNumberOfExternalNodes() != 4 ) {
3290                 return false;
3291             }
3292             t3.deleteSubtree( t3.getNode( "B" ), true );
3293             if ( t3.getNumberOfExternalNodes() != 3 ) {
3294                 return false;
3295             }
3296             n = t3.getNode( "A" );
3297             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3298                 return false;
3299             }
3300             n = n.getNextExternalNode();
3301             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3302                 return false;
3303             }
3304             t3.deleteSubtree( t3.getNode( "A" ), true );
3305             if ( t3.getNumberOfExternalNodes() != 2 ) {
3306                 return false;
3307             }
3308             n = t3.getNode( "C" );
3309             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3310                 return false;
3311             }
3312             t3.deleteSubtree( t3.getNode( "C" ), true );
3313             if ( t3.getNumberOfExternalNodes() != 1 ) {
3314                 return false;
3315             }
3316             t3.deleteSubtree( t3.getNode( "D" ), true );
3317             if ( t3.getNumberOfExternalNodes() != 0 ) {
3318                 return false;
3319             }
3320             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3321             if ( t4.getNumberOfExternalNodes() != 6 ) {
3322                 return false;
3323             }
3324             t4.deleteSubtree( t4.getNode( "B2" ), true );
3325             if ( t4.getNumberOfExternalNodes() != 5 ) {
3326                 return false;
3327             }
3328             String s = w.toNewHampshire( t4, false, true ).toString();
3329             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3330                 return false;
3331             }
3332             t4.deleteSubtree( t4.getNode( "B11" ), true );
3333             if ( t4.getNumberOfExternalNodes() != 4 ) {
3334                 return false;
3335             }
3336             t4.deleteSubtree( t4.getNode( "C" ), true );
3337             if ( t4.getNumberOfExternalNodes() != 3 ) {
3338                 return false;
3339             }
3340             n = t4.getNode( "A" );
3341             n = n.getNextExternalNode();
3342             if ( !n.getName().equals( "B12" ) ) {
3343                 return false;
3344             }
3345             n = n.getNextExternalNode();
3346             if ( !n.getName().equals( "D" ) ) {
3347                 return false;
3348             }
3349             s = w.toNewHampshire( t4, false, true ).toString();
3350             if ( !s.equals( "((A,B12),D);" ) ) {
3351                 return false;
3352             }
3353             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3354             t5.deleteSubtree( t5.getNode( "A" ), true );
3355             if ( t5.getNumberOfExternalNodes() != 5 ) {
3356                 return false;
3357             }
3358             s = w.toNewHampshire( t5, false, true ).toString();
3359             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3360                 return false;
3361             }
3362             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3363             t6.deleteSubtree( t6.getNode( "B11" ), true );
3364             if ( t6.getNumberOfExternalNodes() != 5 ) {
3365                 return false;
3366             }
3367             s = w.toNewHampshire( t6, false, false ).toString();
3368             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3369                 return false;
3370             }
3371             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3372             t7.deleteSubtree( t7.getNode( "B12" ), true );
3373             if ( t7.getNumberOfExternalNodes() != 5 ) {
3374                 return false;
3375             }
3376             s = w.toNewHampshire( t7, false, true ).toString();
3377             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3378                 return false;
3379             }
3380             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3381             t8.deleteSubtree( t8.getNode( "B2" ), true );
3382             if ( t8.getNumberOfExternalNodes() != 5 ) {
3383                 return false;
3384             }
3385             s = w.toNewHampshire( t8, false, false ).toString();
3386             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3387                 return false;
3388             }
3389             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3390             t9.deleteSubtree( t9.getNode( "C" ), true );
3391             if ( t9.getNumberOfExternalNodes() != 5 ) {
3392                 return false;
3393             }
3394             s = w.toNewHampshire( t9, false, true ).toString();
3395             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3396                 return false;
3397             }
3398             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3399             t10.deleteSubtree( t10.getNode( "D" ), true );
3400             if ( t10.getNumberOfExternalNodes() != 5 ) {
3401                 return false;
3402             }
3403             s = w.toNewHampshire( t10, false, true ).toString();
3404             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3405                 return false;
3406             }
3407             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3408             t11.deleteSubtree( t11.getNode( "A" ), true );
3409             if ( t11.getNumberOfExternalNodes() != 2 ) {
3410                 return false;
3411             }
3412             s = w.toNewHampshire( t11, false, true ).toString();
3413             if ( !s.equals( "(B,C);" ) ) {
3414                 return false;
3415             }
3416             t11.deleteSubtree( t11.getNode( "C" ), true );
3417             if ( t11.getNumberOfExternalNodes() != 1 ) {
3418                 return false;
3419             }
3420             s = w.toNewHampshire( t11, false, false ).toString();
3421             if ( !s.equals( "B;" ) ) {
3422                 return false;
3423             }
3424             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3425             t12.deleteSubtree( t12.getNode( "B2" ), true );
3426             if ( t12.getNumberOfExternalNodes() != 8 ) {
3427                 return false;
3428             }
3429             s = w.toNewHampshire( t12, false, true ).toString();
3430             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3431                 return false;
3432             }
3433             t12.deleteSubtree( t12.getNode( "B3" ), true );
3434             if ( t12.getNumberOfExternalNodes() != 7 ) {
3435                 return false;
3436             }
3437             s = w.toNewHampshire( t12, false, true ).toString();
3438             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3439                 return false;
3440             }
3441             t12.deleteSubtree( t12.getNode( "C3" ), true );
3442             if ( t12.getNumberOfExternalNodes() != 6 ) {
3443                 return false;
3444             }
3445             s = w.toNewHampshire( t12, false, true ).toString();
3446             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3447                 return false;
3448             }
3449             t12.deleteSubtree( t12.getNode( "A1" ), true );
3450             if ( t12.getNumberOfExternalNodes() != 5 ) {
3451                 return false;
3452             }
3453             s = w.toNewHampshire( t12, false, true ).toString();
3454             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3455                 return false;
3456             }
3457             t12.deleteSubtree( t12.getNode( "B1" ), true );
3458             if ( t12.getNumberOfExternalNodes() != 4 ) {
3459                 return false;
3460             }
3461             s = w.toNewHampshire( t12, false, true ).toString();
3462             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3463                 return false;
3464             }
3465             t12.deleteSubtree( t12.getNode( "A3" ), true );
3466             if ( t12.getNumberOfExternalNodes() != 3 ) {
3467                 return false;
3468             }
3469             s = w.toNewHampshire( t12, false, true ).toString();
3470             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3471                 return false;
3472             }
3473             t12.deleteSubtree( t12.getNode( "A2" ), true );
3474             if ( t12.getNumberOfExternalNodes() != 2 ) {
3475                 return false;
3476             }
3477             s = w.toNewHampshire( t12, false, true ).toString();
3478             if ( !s.equals( "(C1,C2);" ) ) {
3479                 return false;
3480             }
3481             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3482             t13.deleteSubtree( t13.getNode( "D" ), true );
3483             if ( t13.getNumberOfExternalNodes() != 4 ) {
3484                 return false;
3485             }
3486             s = w.toNewHampshire( t13, false, true ).toString();
3487             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3488                 return false;
3489             }
3490             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3491             t14.deleteSubtree( t14.getNode( "E" ), true );
3492             if ( t14.getNumberOfExternalNodes() != 5 ) {
3493                 return false;
3494             }
3495             s = w.toNewHampshire( t14, false, true ).toString();
3496             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3497                 return false;
3498             }
3499             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3500             t15.deleteSubtree( t15.getNode( "B2" ), true );
3501             if ( t15.getNumberOfExternalNodes() != 11 ) {
3502                 return false;
3503             }
3504             t15.deleteSubtree( t15.getNode( "B1" ), true );
3505             if ( t15.getNumberOfExternalNodes() != 10 ) {
3506                 return false;
3507             }
3508             t15.deleteSubtree( t15.getNode( "B3" ), true );
3509             if ( t15.getNumberOfExternalNodes() != 9 ) {
3510                 return false;
3511             }
3512             t15.deleteSubtree( t15.getNode( "B4" ), true );
3513             if ( t15.getNumberOfExternalNodes() != 8 ) {
3514                 return false;
3515             }
3516             t15.deleteSubtree( t15.getNode( "A1" ), true );
3517             if ( t15.getNumberOfExternalNodes() != 7 ) {
3518                 return false;
3519             }
3520             t15.deleteSubtree( t15.getNode( "C4" ), true );
3521             if ( t15.getNumberOfExternalNodes() != 6 ) {
3522                 return false;
3523             }
3524         }
3525         catch ( final Exception e ) {
3526             e.printStackTrace( System.out );
3527             return false;
3528         }
3529         return true;
3530     }
3531
3532     private static boolean testDescriptiveStatistics() {
3533         try {
3534             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3535             dss1.addValue( 82 );
3536             dss1.addValue( 78 );
3537             dss1.addValue( 70 );
3538             dss1.addValue( 58 );
3539             dss1.addValue( 42 );
3540             if ( dss1.getN() != 5 ) {
3541                 return false;
3542             }
3543             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3544                 return false;
3545             }
3546             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3547                 return false;
3548             }
3549             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3550                 return false;
3551             }
3552             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3553                 return false;
3554             }
3555             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3556                 return false;
3557             }
3558             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3559                 return false;
3560             }
3561             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3562                 return false;
3563             }
3564             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3565                 return false;
3566             }
3567             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3568                 return false;
3569             }
3570             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3571                 return false;
3572             }
3573             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3574                 return false;
3575             }
3576             dss1.addValue( 123 );
3577             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3578                 return false;
3579             }
3580             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3581                 return false;
3582             }
3583             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3584                 return false;
3585             }
3586             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3587             dss2.addValue( -1.85 );
3588             dss2.addValue( 57.5 );
3589             dss2.addValue( 92.78 );
3590             dss2.addValue( 57.78 );
3591             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3592                 return false;
3593             }
3594             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3595                 return false;
3596             }
3597             final double[] a = dss2.getDataAsDoubleArray();
3598             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3599                 return false;
3600             }
3601             dss2.addValue( -100 );
3602             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3603                 return false;
3604             }
3605             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3606                 return false;
3607             }
3608             final double[] ds = new double[ 14 ];
3609             ds[ 0 ] = 34;
3610             ds[ 1 ] = 23;
3611             ds[ 2 ] = 1;
3612             ds[ 3 ] = 32;
3613             ds[ 4 ] = 11;
3614             ds[ 5 ] = 2;
3615             ds[ 6 ] = 12;
3616             ds[ 7 ] = 33;
3617             ds[ 8 ] = 13;
3618             ds[ 9 ] = 22;
3619             ds[ 10 ] = 21;
3620             ds[ 11 ] = 35;
3621             ds[ 12 ] = 24;
3622             ds[ 13 ] = 31;
3623             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3624             if ( bins.length != 4 ) {
3625                 return false;
3626             }
3627             if ( bins[ 0 ] != 2 ) {
3628                 return false;
3629             }
3630             if ( bins[ 1 ] != 3 ) {
3631                 return false;
3632             }
3633             if ( bins[ 2 ] != 4 ) {
3634                 return false;
3635             }
3636             if ( bins[ 3 ] != 5 ) {
3637                 return false;
3638             }
3639             final double[] ds1 = new double[ 9 ];
3640             ds1[ 0 ] = 10.0;
3641             ds1[ 1 ] = 19.0;
3642             ds1[ 2 ] = 9.999;
3643             ds1[ 3 ] = 0.0;
3644             ds1[ 4 ] = 39.9;
3645             ds1[ 5 ] = 39.999;
3646             ds1[ 6 ] = 30.0;
3647             ds1[ 7 ] = 19.999;
3648             ds1[ 8 ] = 30.1;
3649             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3650             if ( bins1.length != 4 ) {
3651                 return false;
3652             }
3653             if ( bins1[ 0 ] != 2 ) {
3654                 return false;
3655             }
3656             if ( bins1[ 1 ] != 3 ) {
3657                 return false;
3658             }
3659             if ( bins1[ 2 ] != 0 ) {
3660                 return false;
3661             }
3662             if ( bins1[ 3 ] != 4 ) {
3663                 return false;
3664             }
3665             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3666             if ( bins1_1.length != 3 ) {
3667                 return false;
3668             }
3669             if ( bins1_1[ 0 ] != 3 ) {
3670                 return false;
3671             }
3672             if ( bins1_1[ 1 ] != 2 ) {
3673                 return false;
3674             }
3675             if ( bins1_1[ 2 ] != 4 ) {
3676                 return false;
3677             }
3678             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3679             if ( bins1_2.length != 3 ) {
3680                 return false;
3681             }
3682             if ( bins1_2[ 0 ] != 2 ) {
3683                 return false;
3684             }
3685             if ( bins1_2[ 1 ] != 2 ) {
3686                 return false;
3687             }
3688             if ( bins1_2[ 2 ] != 2 ) {
3689                 return false;
3690             }
3691             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3692             dss3.addValue( 1 );
3693             dss3.addValue( 1 );
3694             dss3.addValue( 1 );
3695             dss3.addValue( 2 );
3696             dss3.addValue( 3 );
3697             dss3.addValue( 4 );
3698             dss3.addValue( 5 );
3699             dss3.addValue( 5 );
3700             dss3.addValue( 5 );
3701             dss3.addValue( 6 );
3702             dss3.addValue( 7 );
3703             dss3.addValue( 8 );
3704             dss3.addValue( 9 );
3705             dss3.addValue( 10 );
3706             dss3.addValue( 10 );
3707             dss3.addValue( 10 );
3708             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3709             histo.toStringBuffer( 10, '=', 40, 5 );
3710             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3711         }
3712         catch ( final Exception e ) {
3713             e.printStackTrace( System.out );
3714             return false;
3715         }
3716         return true;
3717     }
3718
3719     private static boolean testDir( final String file ) {
3720         try {
3721             final File f = new File( file );
3722             if ( !f.exists() ) {
3723                 return false;
3724             }
3725             if ( !f.isDirectory() ) {
3726                 return false;
3727             }
3728             if ( !f.canRead() ) {
3729                 return false;
3730             }
3731         }
3732         catch ( final Exception e ) {
3733             return false;
3734         }
3735         return true;
3736     }
3737
3738     private static boolean testEbiEntryRetrieval() {
3739         try {
3740             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3741             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3742                 System.out.println( entry.getAccession() );
3743                 return false;
3744             }
3745             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3746                 System.out.println( entry.getTaxonomyScientificName() );
3747                 return false;
3748             }
3749             if ( !entry.getSequenceName()
3750                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3751                 System.out.println( entry.getSequenceName() );
3752                 return false;
3753             }
3754             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3755             //     System.out.println( entry.getSequenceSymbol() );
3756             //     return false;
3757             // }
3758             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3759                 System.out.println( entry.getGeneName() );
3760                 return false;
3761             }
3762             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3763                 System.out.println( entry.getTaxonomyIdentifier() );
3764                 return false;
3765             }
3766             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3767                 System.out.println( entry.getAnnotations().first().getRefValue() );
3768                 return false;
3769             }
3770             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3771                 System.out.println( entry.getAnnotations().first().getRefSource() );
3772                 return false;
3773             }
3774             if ( entry.getCrossReferences().size() != 5 ) {
3775                 return false;
3776             }
3777             //
3778             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3779             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3780                 return false;
3781             }
3782             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3783                 System.out.println( entry1.getTaxonomyScientificName() );
3784                 return false;
3785             }
3786             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3787                 System.out.println( entry1.getSequenceName() );
3788                 return false;
3789             }
3790             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3791                 System.out.println( entry1.getTaxonomyIdentifier() );
3792                 return false;
3793             }
3794             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3795                 System.out.println( entry1.getGeneName() );
3796                 return false;
3797             }
3798             if ( entry1.getCrossReferences().size() != 6 ) {
3799                 return false;
3800             }
3801             //
3802             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3803             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3804                 return false;
3805             }
3806             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3807                 System.out.println( entry2.getTaxonomyScientificName() );
3808                 return false;
3809             }
3810             if ( !entry2.getSequenceName()
3811                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3812                 System.out.println( entry2.getSequenceName() );
3813                 return false;
3814             }
3815             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3816                 System.out.println( entry2.getTaxonomyIdentifier() );
3817                 return false;
3818             }
3819             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3820                 System.out.println( entry2.getGeneName() );
3821                 return false;
3822             }
3823             if ( entry2.getCrossReferences().size() != 3 ) {
3824                 return false;
3825             }
3826             //
3827             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3828             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3829                 return false;
3830             }
3831             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3832                 System.out.println( entry3.getTaxonomyScientificName() );
3833                 return false;
3834             }
3835             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3836                 System.out.println( entry3.getSequenceName() );
3837                 return false;
3838             }
3839             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3840                 System.out.println( entry3.getTaxonomyIdentifier() );
3841                 return false;
3842             }
3843             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3844                 System.out.println( entry3.getSequenceSymbol() );
3845                 return false;
3846             }
3847             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
3848                 return false;
3849             }
3850             if ( entry3.getCrossReferences().size() != 8 ) {
3851                 return false;
3852             }
3853             //
3854             //
3855             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
3856             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
3857                 return false;
3858             }
3859             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3860                 System.out.println( entry4.getTaxonomyScientificName() );
3861                 return false;
3862             }
3863             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
3864                 System.out.println( entry4.getSequenceName() );
3865                 return false;
3866             }
3867             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
3868                 System.out.println( entry4.getTaxonomyIdentifier() );
3869                 return false;
3870             }
3871             if ( !entry4.getGeneName().equals( "ras" ) ) {
3872                 System.out.println( entry4.getGeneName() );
3873                 return false;
3874             }
3875             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
3876             //     System.out.println( entry4.getChromosome() );
3877             //     return false;
3878             // }
3879             // if ( !entry4.getMap().equals( "ras" ) ) {
3880             //     System.out.println( entry4.getMap() );
3881             //     return false;
3882             // }
3883             //TODO FIXME gi...
3884             //
3885             //TODO fails:
3886             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
3887             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
3888             //                return false;
3889             //            }
3890             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
3891             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
3892                 return false;
3893             }
3894             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
3895                 System.out.println( entry5.getTaxonomyScientificName() );
3896                 return false;
3897             }
3898             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
3899                 System.out.println( entry5.getSequenceName() );
3900                 return false;
3901             }
3902             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
3903                 System.out.println( entry5.getTaxonomyIdentifier() );
3904                 return false;
3905             }
3906         }
3907         catch ( final IOException e ) {
3908             System.out.println();
3909             System.out.println( "the following might be due to absence internet connection:" );
3910             e.printStackTrace( System.out );
3911             return true;
3912         }
3913         catch ( final Exception e ) {
3914             e.printStackTrace();
3915             return false;
3916         }
3917         return true;
3918     }
3919
3920     private static boolean testExternalNodeRelatedMethods() {
3921         try {
3922             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3923             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3924             PhylogenyNode n = t1.getNode( "A" );
3925             n = n.getNextExternalNode();
3926             if ( !n.getName().equals( "B" ) ) {
3927                 return false;
3928             }
3929             n = n.getNextExternalNode();
3930             if ( !n.getName().equals( "C" ) ) {
3931                 return false;
3932             }
3933             n = n.getNextExternalNode();
3934             if ( !n.getName().equals( "D" ) ) {
3935                 return false;
3936             }
3937             n = t1.getNode( "B" );
3938             while ( !n.isLastExternalNode() ) {
3939                 n = n.getNextExternalNode();
3940             }
3941             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3942             n = t2.getNode( "A" );
3943             n = n.getNextExternalNode();
3944             if ( !n.getName().equals( "B" ) ) {
3945                 return false;
3946             }
3947             n = n.getNextExternalNode();
3948             if ( !n.getName().equals( "C" ) ) {
3949                 return false;
3950             }
3951             n = n.getNextExternalNode();
3952             if ( !n.getName().equals( "D" ) ) {
3953                 return false;
3954             }
3955             n = t2.getNode( "B" );
3956             while ( !n.isLastExternalNode() ) {
3957                 n = n.getNextExternalNode();
3958             }
3959             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3960             n = t3.getNode( "A" );
3961             n = n.getNextExternalNode();
3962             if ( !n.getName().equals( "B" ) ) {
3963                 return false;
3964             }
3965             n = n.getNextExternalNode();
3966             if ( !n.getName().equals( "C" ) ) {
3967                 return false;
3968             }
3969             n = n.getNextExternalNode();
3970             if ( !n.getName().equals( "D" ) ) {
3971                 return false;
3972             }
3973             n = n.getNextExternalNode();
3974             if ( !n.getName().equals( "E" ) ) {
3975                 return false;
3976             }
3977             n = n.getNextExternalNode();
3978             if ( !n.getName().equals( "F" ) ) {
3979                 return false;
3980             }
3981             n = n.getNextExternalNode();
3982             if ( !n.getName().equals( "G" ) ) {
3983                 return false;
3984             }
3985             n = n.getNextExternalNode();
3986             if ( !n.getName().equals( "H" ) ) {
3987                 return false;
3988             }
3989             n = t3.getNode( "B" );
3990             while ( !n.isLastExternalNode() ) {
3991                 n = n.getNextExternalNode();
3992             }
3993             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3994             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3995                 final PhylogenyNode node = iter.next();
3996             }
3997             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3998             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3999                 final PhylogenyNode node = iter.next();
4000             }
4001             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4002             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4003             if ( !iter.next().getName().equals( "A" ) ) {
4004                 return false;
4005             }
4006             if ( !iter.next().getName().equals( "B" ) ) {
4007                 return false;
4008             }
4009             if ( !iter.next().getName().equals( "C" ) ) {
4010                 return false;
4011             }
4012             if ( !iter.next().getName().equals( "D" ) ) {
4013                 return false;
4014             }
4015             if ( !iter.next().getName().equals( "E" ) ) {
4016                 return false;
4017             }
4018             if ( !iter.next().getName().equals( "F" ) ) {
4019                 return false;
4020             }
4021             if ( iter.hasNext() ) {
4022                 return false;
4023             }
4024         }
4025         catch ( final Exception e ) {
4026             e.printStackTrace( System.out );
4027             return false;
4028         }
4029         return true;
4030     }
4031
4032     private static boolean testExtractSNFromNodeName() {
4033         try {
4034             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4035                 return false;
4036             }
4037             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
4038                     .equals( "Mus musculus musculus" ) ) {
4039                 return false;
4040             }
4041             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
4042                     .equals( "Mus musculus musculus" ) ) {
4043                 return false;
4044             }
4045             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
4046                 return false;
4047             }
4048             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
4049                     .equals( "Mus musculus" ) ) {
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 testExtractTaxonomyCodeFromNodeName() {
4061         try {
4062             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4063                 return false;
4064             }
4065             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4066                     .equals( "SOYBN" ) ) {
4067                 return false;
4068             }
4069             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4070                     .equals( "ARATH" ) ) {
4071                 return false;
4072             }
4073             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4074                     .equals( "ARATH" ) ) {
4075                 return false;
4076             }
4077             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4078                 return false;
4079             }
4080             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4081                 return false;
4082             }
4083             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4084                 return false;
4085             }
4086             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4087                     .equals( "SOYBN" ) ) {
4088                 return false;
4089             }
4090             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4091                     .equals( "SOYBN" ) ) {
4092                 return false;
4093             }
4094             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4095                     .equals( "SOYBN" ) ) {
4096                 return false;
4097             }
4098             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4099                     .equals( "SOYBN" ) ) {
4100                 return false;
4101             }
4102             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4103                     .equals( "SOYBN" ) ) {
4104                 return false;
4105             }
4106             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4107                     .equals( "SOYBN" ) ) {
4108                 return false;
4109             }
4110             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4111                     .equals( "SOYBN" ) ) {
4112                 return false;
4113             }
4114             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4115                     .equals( "SOYBN" ) ) {
4116                 return false;
4117             }
4118             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4119                 return false;
4120             }
4121             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4122                     .equals( "SOYBN" ) ) {
4123                 return false;
4124             }
4125             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4126                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4127                 return false;
4128             }
4129             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4130                     .equals( "9YX45" ) ) {
4131                 return false;
4132             }
4133             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4134                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4135                     .equals( "MOUSE" ) ) {
4136                 return false;
4137             }
4138             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4139                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4140                     .equals( "MOUSE" ) ) {
4141                 return false;
4142             }
4143             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4144                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4145                     .equals( "MOUSE" ) ) {
4146                 return false;
4147             }
4148             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4149                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4150                 return false;
4151             }
4152             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4153                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4154                 return false;
4155             }
4156             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4157                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4158                 return false;
4159             }
4160             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4161                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4162                 return false;
4163             }
4164             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4165                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4166                 return false;
4167             }
4168             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4169                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4170                 return false;
4171             }
4172             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4173                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4174                 return false;
4175             }
4176             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4177                     .equals( "RAT" ) ) {
4178                 return false;
4179             }
4180             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4181                     .equals( "PIG" ) ) {
4182                 return false;
4183             }
4184             if ( !ParserUtils
4185                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4186                     .equals( "MOUSE" ) ) {
4187                 return false;
4188             }
4189             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4190                     .equals( "MOUSE" ) ) {
4191                 return false;
4192             }
4193             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4194                 return false;
4195             }
4196         }
4197         catch ( final Exception e ) {
4198             e.printStackTrace( System.out );
4199             return false;
4200         }
4201         return true;
4202     }
4203
4204     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4205         try {
4206             PhylogenyNode n = new PhylogenyNode();
4207             n.setName( "tr|B3RJ64" );
4208             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4209                 return false;
4210             }
4211             n.setName( "tr.B3RJ64" );
4212             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4213                 return false;
4214             }
4215             n.setName( "tr=B3RJ64" );
4216             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4217                 return false;
4218             }
4219             n.setName( "tr-B3RJ64" );
4220             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4221                 return false;
4222             }
4223             n.setName( "tr/B3RJ64" );
4224             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4225                 return false;
4226             }
4227             n.setName( "tr\\B3RJ64" );
4228             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4229                 return false;
4230             }
4231             n.setName( "tr_B3RJ64" );
4232             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4233                 return false;
4234             }
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_tr|B3RJ64_sp|123 " );
4252             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4253                 return false;
4254             }
4255             n.setName( "B3RJ64" );
4256             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4257                 return false;
4258             }
4259             n.setName( "sp|B3RJ64" );
4260             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4261                 return false;
4262             }
4263             n.setName( "sp|B3RJ64C" );
4264             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4265                 return false;
4266             }
4267             n.setName( "sp B3RJ64" );
4268             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4269                 return false;
4270             }
4271             n.setName( "sp|B3RJ6X" );
4272             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4273                 return false;
4274             }
4275             n.setName( "sp|B3RJ6" );
4276             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4277                 return false;
4278             }
4279             n.setName( "K1PYK7_CRAGI" );
4280             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4281                 return false;
4282             }
4283             n.setName( "K1PYK7_PEA" );
4284             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4285                 return false;
4286             }
4287             n.setName( "K1PYK7_RAT" );
4288             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4289                 return false;
4290             }
4291             n.setName( "K1PYK7_PIG" );
4292             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4293                 return false;
4294             }
4295             n.setName( "~K1PYK7_PIG~" );
4296             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4297                 return false;
4298             }
4299             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4300             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4301                 return false;
4302             }
4303             n.setName( "K1PYKX_CRAGI" );
4304             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4305                 return false;
4306             }
4307             n.setName( "XXXXX_CRAGI" );
4308             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4309                 return false;
4310             }
4311             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4312             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4313                 return false;
4314             }
4315             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4316             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4317                 return false;
4318             }
4319             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4320             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4321                 return false;
4322             }
4323             n = new PhylogenyNode();
4324             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4325             seq.setSymbol( "K1PYK7_CRAGI" );
4326             n.getNodeData().addSequence( seq );
4327             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4328                 return false;
4329             }
4330             seq.setSymbol( "tr|B3RJ64" );
4331             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4332                 return false;
4333             }
4334             n = new PhylogenyNode();
4335             seq = new org.forester.phylogeny.data.Sequence();
4336             seq.setName( "K1PYK7_CRAGI" );
4337             n.getNodeData().addSequence( seq );
4338             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4339                 return false;
4340             }
4341             seq.setName( "tr|B3RJ64" );
4342             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4343                 return false;
4344             }
4345             n = new PhylogenyNode();
4346             seq = new org.forester.phylogeny.data.Sequence();
4347             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4348             n.getNodeData().addSequence( seq );
4349             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4350                 return false;
4351             }
4352             n = new PhylogenyNode();
4353             seq = new org.forester.phylogeny.data.Sequence();
4354             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4355             n.getNodeData().addSequence( seq );
4356             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4357                 return false;
4358             }
4359             //
4360             n = new PhylogenyNode();
4361             n.setName( "ACP19736" );
4362             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4363                 return false;
4364             }
4365             n = new PhylogenyNode();
4366             n.setName( "|ACP19736|" );
4367             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4368                 return false;
4369             }
4370         }
4371         catch ( final Exception e ) {
4372             e.printStackTrace( System.out );
4373             return false;
4374         }
4375         return true;
4376     }
4377
4378     private static boolean testFastaParser() {
4379         try {
4380             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4381                 return false;
4382             }
4383             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4384                 return false;
4385             }
4386             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4387             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4388                 return false;
4389             }
4390             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4391                 return false;
4392             }
4393             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4394                 return false;
4395             }
4396             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4397                 return false;
4398             }
4399             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4400                 return false;
4401             }
4402             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4403                 return false;
4404             }
4405         }
4406         catch ( final Exception e ) {
4407             e.printStackTrace();
4408             return false;
4409         }
4410         return true;
4411     }
4412
4413     private static boolean testGenbankAccessorParsing() {
4414         //The format for GenBank Accession numbers are:
4415         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4416         //Protein:    3 letters + 5 numerals
4417         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4418         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4419             return false;
4420         }
4421         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4422             return false;
4423         }
4424         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4425             return false;
4426         }
4427         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4428             return false;
4429         }
4430         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4431             return false;
4432         }
4433         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4434             return false;
4435         }
4436         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4437             return false;
4438         }
4439         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4440             return false;
4441         }
4442         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4443             return false;
4444         }
4445         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4446             return false;
4447         }
4448         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4449             return false;
4450         }
4451         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4452             return false;
4453         }
4454         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4455             return false;
4456         }
4457         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4458             return false;
4459         }
4460         return true;
4461     }
4462
4463     private static boolean testGeneralMsaParser() {
4464         try {
4465             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4466             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4467             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4468             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4469             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4470             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4471             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4472             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4473             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4474                 return false;
4475             }
4476             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4477                 return false;
4478             }
4479             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4480                 return false;
4481             }
4482             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4483                 return false;
4484             }
4485             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4486                 return false;
4487             }
4488             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4489                 return false;
4490             }
4491             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4492                 return false;
4493             }
4494             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4495                 return false;
4496             }
4497             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4498                 return false;
4499             }
4500             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4501                 return false;
4502             }
4503             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4504                 return false;
4505             }
4506             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4507                 return false;
4508             }
4509             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4510             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4511                 return false;
4512             }
4513             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4514                 return false;
4515             }
4516             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4517                 return false;
4518             }
4519             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4520             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4521                 return false;
4522             }
4523             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4524                 return false;
4525             }
4526             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4527                 return false;
4528             }
4529             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4530             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4531                 return false;
4532             }
4533             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4534                 return false;
4535             }
4536             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4537                 return false;
4538             }
4539         }
4540         catch ( final Exception e ) {
4541             e.printStackTrace();
4542             return false;
4543         }
4544         return true;
4545     }
4546
4547     private static boolean testGeneralTable() {
4548         try {
4549             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4550             t0.setValue( 3, 2, "23" );
4551             t0.setValue( 10, 1, "error" );
4552             t0.setValue( 10, 1, "110" );
4553             t0.setValue( 9, 1, "19" );
4554             t0.setValue( 1, 10, "101" );
4555             t0.setValue( 10, 10, "1010" );
4556             t0.setValue( 100, 10, "10100" );
4557             t0.setValue( 0, 0, "00" );
4558             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4559                 return false;
4560             }
4561             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4562                 return false;
4563             }
4564             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4565                 return false;
4566             }
4567             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4568                 return false;
4569             }
4570             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4571                 return false;
4572             }
4573             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4574                 return false;
4575             }
4576             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4577                 return false;
4578             }
4579             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4580                 return false;
4581             }
4582             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4583                 return false;
4584             }
4585             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4586             t1.setValue( "3", "2", "23" );
4587             t1.setValue( "10", "1", "error" );
4588             t1.setValue( "10", "1", "110" );
4589             t1.setValue( "9", "1", "19" );
4590             t1.setValue( "1", "10", "101" );
4591             t1.setValue( "10", "10", "1010" );
4592             t1.setValue( "100", "10", "10100" );
4593             t1.setValue( "0", "0", "00" );
4594             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4595             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4596                 return false;
4597             }
4598             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4599                 return false;
4600             }
4601             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4602                 return false;
4603             }
4604             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4605                 return false;
4606             }
4607             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4608                 return false;
4609             }
4610             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4611                 return false;
4612             }
4613             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4614                 return false;
4615             }
4616             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4617                 return false;
4618             }
4619             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4620                 return false;
4621             }
4622             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4623                 return false;
4624             }
4625         }
4626         catch ( final Exception e ) {
4627             e.printStackTrace( System.out );
4628             return false;
4629         }
4630         return true;
4631     }
4632
4633     private static boolean testGetDistance() {
4634         try {
4635             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4636             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",
4637                                                  new NHXParser() )[ 0 ];
4638             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4639                 return false;
4640             }
4641             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4642                 return false;
4643             }
4644             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4645                 return false;
4646             }
4647             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4648                 return false;
4649             }
4650             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4651                 return false;
4652             }
4653             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4654                 return false;
4655             }
4656             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4657                 return false;
4658             }
4659             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4660                 return false;
4661             }
4662             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4663                 return false;
4664             }
4665             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4666                 return false;
4667             }
4668             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4669                 return false;
4670             }
4671             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4672                 return false;
4673             }
4674             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4675                 return false;
4676             }
4677             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4678                 return false;
4679             }
4680             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4681                 return false;
4682             }
4683             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4684                 return false;
4685             }
4686             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4687                 return false;
4688             }
4689             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4690                 return false;
4691             }
4692             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4693                 return false;
4694             }
4695             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4696                 return false;
4697             }
4698             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4699                 return false;
4700             }
4701             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4702                 return false;
4703             }
4704             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4705                 return false;
4706             }
4707             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4708                 return false;
4709             }
4710             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4711                 return false;
4712             }
4713             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4714                 return false;
4715             }
4716             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4717                 return false;
4718             }
4719             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4720                 return false;
4721             }
4722             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4723                 return false;
4724             }
4725             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4726                 return false;
4727             }
4728             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4729                 return false;
4730             }
4731             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",
4732                                                  new NHXParser() )[ 0 ];
4733             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4734                 return false;
4735             }
4736             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4737                 return false;
4738             }
4739             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4740                 return false;
4741             }
4742             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4743                 return false;
4744             }
4745             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4746                 return false;
4747             }
4748             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4749                 return false;
4750             }
4751             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4752                 return false;
4753             }
4754             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4755                 return false;
4756             }
4757             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4758                 return false;
4759             }
4760             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4761                 return false;
4762             }
4763             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4764                 return false;
4765             }
4766         }
4767         catch ( final Exception e ) {
4768             e.printStackTrace( System.out );
4769             return false;
4770         }
4771         return true;
4772     }
4773
4774     private static boolean testGetLCA() {
4775         try {
4776             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4777             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4778                                                  new NHXParser() )[ 0 ];
4779             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4780             if ( !A.getName().equals( "A" ) ) {
4781                 return false;
4782             }
4783             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4784             if ( !gh.getName().equals( "gh" ) ) {
4785                 return false;
4786             }
4787             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4788             if ( !ab.getName().equals( "ab" ) ) {
4789                 return false;
4790             }
4791             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4792             if ( !ab2.getName().equals( "ab" ) ) {
4793                 return false;
4794             }
4795             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4796             if ( !gh2.getName().equals( "gh" ) ) {
4797                 return false;
4798             }
4799             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4800             if ( !gh3.getName().equals( "gh" ) ) {
4801                 return false;
4802             }
4803             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4804             if ( !abc.getName().equals( "abc" ) ) {
4805                 return false;
4806             }
4807             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4808             if ( !abc2.getName().equals( "abc" ) ) {
4809                 return false;
4810             }
4811             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4812             if ( !abcd.getName().equals( "abcd" ) ) {
4813                 return false;
4814             }
4815             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4816             if ( !abcd2.getName().equals( "abcd" ) ) {
4817                 return false;
4818             }
4819             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4820             if ( !abcdef.getName().equals( "abcdef" ) ) {
4821                 return false;
4822             }
4823             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4824             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4825                 return false;
4826             }
4827             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4828             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4829                 return false;
4830             }
4831             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4832             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4833                 return false;
4834             }
4835             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4836             if ( !abcde.getName().equals( "abcde" ) ) {
4837                 return false;
4838             }
4839             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4840             if ( !abcde2.getName().equals( "abcde" ) ) {
4841                 return false;
4842             }
4843             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4844             if ( !r.getName().equals( "abcdefgh" ) ) {
4845                 return false;
4846             }
4847             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4848             if ( !r2.getName().equals( "abcdefgh" ) ) {
4849                 return false;
4850             }
4851             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4852             if ( !r3.getName().equals( "abcdefgh" ) ) {
4853                 return false;
4854             }
4855             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4856             if ( !abcde3.getName().equals( "abcde" ) ) {
4857                 return false;
4858             }
4859             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4860             if ( !abcde4.getName().equals( "abcde" ) ) {
4861                 return false;
4862             }
4863             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4864             if ( !ab3.getName().equals( "ab" ) ) {
4865                 return false;
4866             }
4867             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4868             if ( !ab4.getName().equals( "ab" ) ) {
4869                 return false;
4870             }
4871             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4872             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4873             if ( !cd.getName().equals( "cd" ) ) {
4874                 return false;
4875             }
4876             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4877             if ( !cd2.getName().equals( "cd" ) ) {
4878                 return false;
4879             }
4880             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4881             if ( !cde.getName().equals( "cde" ) ) {
4882                 return false;
4883             }
4884             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4885             if ( !cde2.getName().equals( "cde" ) ) {
4886                 return false;
4887             }
4888             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4889             if ( !cdef.getName().equals( "cdef" ) ) {
4890                 return false;
4891             }
4892             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4893             if ( !cdef2.getName().equals( "cdef" ) ) {
4894                 return false;
4895             }
4896             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4897             if ( !cdef3.getName().equals( "cdef" ) ) {
4898                 return false;
4899             }
4900             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4901             if ( !rt.getName().equals( "r" ) ) {
4902                 return false;
4903             }
4904             final Phylogeny p3 = factory
4905                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4906                              new NHXParser() )[ 0 ];
4907             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4908             if ( !bc_3.getName().equals( "bc" ) ) {
4909                 return false;
4910             }
4911             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4912             if ( !ac_3.getName().equals( "abc" ) ) {
4913                 return false;
4914             }
4915             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4916             if ( !ad_3.getName().equals( "abcde" ) ) {
4917                 return false;
4918             }
4919             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4920             if ( !af_3.getName().equals( "abcdef" ) ) {
4921                 return false;
4922             }
4923             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4924             if ( !ag_3.getName().equals( "" ) ) {
4925                 return false;
4926             }
4927             if ( !ag_3.isRoot() ) {
4928                 return false;
4929             }
4930             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4931             if ( !al_3.getName().equals( "" ) ) {
4932                 return false;
4933             }
4934             if ( !al_3.isRoot() ) {
4935                 return false;
4936             }
4937             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4938             if ( !kl_3.getName().equals( "" ) ) {
4939                 return false;
4940             }
4941             if ( !kl_3.isRoot() ) {
4942                 return false;
4943             }
4944             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4945             if ( !fl_3.getName().equals( "" ) ) {
4946                 return false;
4947             }
4948             if ( !fl_3.isRoot() ) {
4949                 return false;
4950             }
4951             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4952             if ( !gk_3.getName().equals( "ghijk" ) ) {
4953                 return false;
4954             }
4955             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4956             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4957             if ( !r_4.getName().equals( "r" ) ) {
4958                 return false;
4959             }
4960             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4961             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4962             if ( !r_5.getName().equals( "root" ) ) {
4963                 return false;
4964             }
4965             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4966             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4967             if ( !r_6.getName().equals( "rot" ) ) {
4968                 return false;
4969             }
4970             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4971             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4972             if ( !r_7.getName().equals( "rott" ) ) {
4973                 return false;
4974             }
4975         }
4976         catch ( final Exception e ) {
4977             e.printStackTrace( System.out );
4978             return false;
4979         }
4980         return true;
4981     }
4982
4983     private static boolean testGetLCA2() {
4984         try {
4985             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4986             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
4987             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
4988             PhylogenyMethods.preOrderReId( p_a );
4989             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
4990                                                                                               p_a.getNode( "a" ) );
4991             if ( !p_a_1.getName().equals( "a" ) ) {
4992                 return false;
4993             }
4994             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
4995             PhylogenyMethods.preOrderReId( p_b );
4996             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
4997                                                                                               p_b.getNode( "a" ) );
4998             if ( !p_b_1.getName().equals( "b" ) ) {
4999                 return false;
5000             }
5001             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5002                                                                                               p_b.getNode( "b" ) );
5003             if ( !p_b_2.getName().equals( "b" ) ) {
5004                 return false;
5005             }
5006             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5007             PhylogenyMethods.preOrderReId( p_c );
5008             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5009                                                                                               p_c.getNode( "a" ) );
5010             if ( !p_c_1.getName().equals( "b" ) ) {
5011                 return false;
5012             }
5013             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5014                                                                                               p_c.getNode( "c" ) );
5015             if ( !p_c_2.getName().equals( "c" ) ) {
5016                 System.out.println( p_c_2.getName() );
5017                 System.exit( -1 );
5018                 return false;
5019             }
5020             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5021                                                                                               p_c.getNode( "b" ) );
5022             if ( !p_c_3.getName().equals( "b" ) ) {
5023                 return false;
5024             }
5025             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5026                                                                                               p_c.getNode( "a" ) );
5027             if ( !p_c_4.getName().equals( "c" ) ) {
5028                 return false;
5029             }
5030             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5031                                                  new NHXParser() )[ 0 ];
5032             PhylogenyMethods.preOrderReId( p1 );
5033             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5034                                                                                           p1.getNode( "A" ) );
5035             if ( !A.getName().equals( "A" ) ) {
5036                 return false;
5037             }
5038             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5039                                                                                            p1.getNode( "gh" ) );
5040             if ( !gh.getName().equals( "gh" ) ) {
5041                 return false;
5042             }
5043             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5044                                                                                            p1.getNode( "B" ) );
5045             if ( !ab.getName().equals( "ab" ) ) {
5046                 return false;
5047             }
5048             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5049                                                                                             p1.getNode( "A" ) );
5050             if ( !ab2.getName().equals( "ab" ) ) {
5051                 return false;
5052             }
5053             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5054                                                                                             p1.getNode( "G" ) );
5055             if ( !gh2.getName().equals( "gh" ) ) {
5056                 return false;
5057             }
5058             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5059                                                                                             p1.getNode( "H" ) );
5060             if ( !gh3.getName().equals( "gh" ) ) {
5061                 return false;
5062             }
5063             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5064                                                                                             p1.getNode( "A" ) );
5065             if ( !abc.getName().equals( "abc" ) ) {
5066                 return false;
5067             }
5068             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5069                                                                                              p1.getNode( "C" ) );
5070             if ( !abc2.getName().equals( "abc" ) ) {
5071                 return false;
5072             }
5073             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5074                                                                                              p1.getNode( "D" ) );
5075             if ( !abcd.getName().equals( "abcd" ) ) {
5076                 return false;
5077             }
5078             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5079                                                                                               p1.getNode( "A" ) );
5080             if ( !abcd2.getName().equals( "abcd" ) ) {
5081                 return false;
5082             }
5083             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5084                                                                                                p1.getNode( "F" ) );
5085             if ( !abcdef.getName().equals( "abcdef" ) ) {
5086                 return false;
5087             }
5088             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5089                                                                                                 p1.getNode( "A" ) );
5090             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5091                 return false;
5092             }
5093             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5094                                                                                                 p1.getNode( "F" ) );
5095             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5096                 return false;
5097             }
5098             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5099                                                                                                 p1.getNode( "ab" ) );
5100             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5101                 return false;
5102             }
5103             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5104                                                                                               p1.getNode( "E" ) );
5105             if ( !abcde.getName().equals( "abcde" ) ) {
5106                 return false;
5107             }
5108             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5109                                                                                                p1.getNode( "A" ) );
5110             if ( !abcde2.getName().equals( "abcde" ) ) {
5111                 return false;
5112             }
5113             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5114                                                                                           p1.getNode( "abcdefgh" ) );
5115             if ( !r.getName().equals( "abcdefgh" ) ) {
5116                 return false;
5117             }
5118             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5119                                                                                            p1.getNode( "H" ) );
5120             if ( !r2.getName().equals( "abcdefgh" ) ) {
5121                 return false;
5122             }
5123             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5124                                                                                            p1.getNode( "A" ) );
5125             if ( !r3.getName().equals( "abcdefgh" ) ) {
5126                 return false;
5127             }
5128             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5129                                                                                                p1.getNode( "abcde" ) );
5130             if ( !abcde3.getName().equals( "abcde" ) ) {
5131                 return false;
5132             }
5133             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5134                                                                                                p1.getNode( "E" ) );
5135             if ( !abcde4.getName().equals( "abcde" ) ) {
5136                 return false;
5137             }
5138             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5139                                                                                             p1.getNode( "B" ) );
5140             if ( !ab3.getName().equals( "ab" ) ) {
5141                 return false;
5142             }
5143             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5144                                                                                             p1.getNode( "ab" ) );
5145             if ( !ab4.getName().equals( "ab" ) ) {
5146                 return false;
5147             }
5148             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5149             PhylogenyMethods.preOrderReId( p2 );
5150             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5151                                                                                            p2.getNode( "d" ) );
5152             if ( !cd.getName().equals( "cd" ) ) {
5153                 return false;
5154             }
5155             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5156                                                                                             p2.getNode( "c" ) );
5157             if ( !cd2.getName().equals( "cd" ) ) {
5158                 return false;
5159             }
5160             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5161                                                                                             p2.getNode( "e" ) );
5162             if ( !cde.getName().equals( "cde" ) ) {
5163                 return false;
5164             }
5165             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5166                                                                                              p2.getNode( "c" ) );
5167             if ( !cde2.getName().equals( "cde" ) ) {
5168                 return false;
5169             }
5170             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5171                                                                                              p2.getNode( "f" ) );
5172             if ( !cdef.getName().equals( "cdef" ) ) {
5173                 return false;
5174             }
5175             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5176                                                                                               p2.getNode( "f" ) );
5177             if ( !cdef2.getName().equals( "cdef" ) ) {
5178                 return false;
5179             }
5180             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5181                                                                                               p2.getNode( "d" ) );
5182             if ( !cdef3.getName().equals( "cdef" ) ) {
5183                 return false;
5184             }
5185             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5186                                                                                            p2.getNode( "a" ) );
5187             if ( !rt.getName().equals( "r" ) ) {
5188                 return false;
5189             }
5190             final Phylogeny p3 = factory
5191                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5192                              new NHXParser() )[ 0 ];
5193             PhylogenyMethods.preOrderReId( p3 );
5194             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5195                                                                                              p3.getNode( "c" ) );
5196             if ( !bc_3.getName().equals( "bc" ) ) {
5197                 return false;
5198             }
5199             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5200                                                                                              p3.getNode( "c" ) );
5201             if ( !ac_3.getName().equals( "abc" ) ) {
5202                 return false;
5203             }
5204             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5205                                                                                              p3.getNode( "d" ) );
5206             if ( !ad_3.getName().equals( "abcde" ) ) {
5207                 return false;
5208             }
5209             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5210                                                                                              p3.getNode( "f" ) );
5211             if ( !af_3.getName().equals( "abcdef" ) ) {
5212                 return false;
5213             }
5214             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5215                                                                                              p3.getNode( "g" ) );
5216             if ( !ag_3.getName().equals( "" ) ) {
5217                 return false;
5218             }
5219             if ( !ag_3.isRoot() ) {
5220                 return false;
5221             }
5222             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5223                                                                                              p3.getNode( "l" ) );
5224             if ( !al_3.getName().equals( "" ) ) {
5225                 return false;
5226             }
5227             if ( !al_3.isRoot() ) {
5228                 return false;
5229             }
5230             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5231                                                                                              p3.getNode( "l" ) );
5232             if ( !kl_3.getName().equals( "" ) ) {
5233                 return false;
5234             }
5235             if ( !kl_3.isRoot() ) {
5236                 return false;
5237             }
5238             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5239                                                                                              p3.getNode( "l" ) );
5240             if ( !fl_3.getName().equals( "" ) ) {
5241                 return false;
5242             }
5243             if ( !fl_3.isRoot() ) {
5244                 return false;
5245             }
5246             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5247                                                                                              p3.getNode( "k" ) );
5248             if ( !gk_3.getName().equals( "ghijk" ) ) {
5249                 return false;
5250             }
5251             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5252             PhylogenyMethods.preOrderReId( p4 );
5253             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5254                                                                                             p4.getNode( "c" ) );
5255             if ( !r_4.getName().equals( "r" ) ) {
5256                 return false;
5257             }
5258             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5259             PhylogenyMethods.preOrderReId( p5 );
5260             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5261                                                                                             p5.getNode( "c" ) );
5262             if ( !r_5.getName().equals( "root" ) ) {
5263                 return false;
5264             }
5265             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5266             PhylogenyMethods.preOrderReId( p6 );
5267             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5268                                                                                             p6.getNode( "a" ) );
5269             if ( !r_6.getName().equals( "rot" ) ) {
5270                 return false;
5271             }
5272             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5273             PhylogenyMethods.preOrderReId( p7 );
5274             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5275                                                                                             p7.getNode( "e" ) );
5276             if ( !r_7.getName().equals( "rott" ) ) {
5277                 return false;
5278             }
5279             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5280                                                                                              p7.getNode( "a" ) );
5281             if ( !r_71.getName().equals( "rott" ) ) {
5282                 return false;
5283             }
5284             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5285                                                                                              p7.getNode( "rott" ) );
5286             if ( !r_72.getName().equals( "rott" ) ) {
5287                 return false;
5288             }
5289             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5290                                                                                              p7.getNode( "a" ) );
5291             if ( !r_73.getName().equals( "rott" ) ) {
5292                 return false;
5293             }
5294             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5295                                                                                              p7.getNode( "rott" ) );
5296             if ( !r_74.getName().equals( "rott" ) ) {
5297                 return false;
5298             }
5299             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5300                                                                                              p7.getNode( "e" ) );
5301             if ( !r_75.getName().equals( "e" ) ) {
5302                 return false;
5303             }
5304         }
5305         catch ( final Exception e ) {
5306             e.printStackTrace( System.out );
5307             return false;
5308         }
5309         return true;
5310     }
5311
5312     private static boolean testHmmscanOutputParser() {
5313         final String test_dir = Test.PATH_TO_TEST_DATA;
5314         try {
5315             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5316                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5317             parser1.parse();
5318             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5319                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5320             final List<Protein> proteins = parser2.parse();
5321             if ( parser2.getProteinsEncountered() != 4 ) {
5322                 return false;
5323             }
5324             if ( proteins.size() != 4 ) {
5325                 return false;
5326             }
5327             if ( parser2.getDomainsEncountered() != 69 ) {
5328                 return false;
5329             }
5330             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5331                 return false;
5332             }
5333             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5334                 return false;
5335             }
5336             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5337                 return false;
5338             }
5339             final Protein p1 = proteins.get( 0 );
5340             if ( p1.getNumberOfProteinDomains() != 15 ) {
5341                 return false;
5342             }
5343             if ( p1.getLength() != 850 ) {
5344                 return false;
5345             }
5346             final Protein p2 = proteins.get( 1 );
5347             if ( p2.getNumberOfProteinDomains() != 51 ) {
5348                 return false;
5349             }
5350             if ( p2.getLength() != 1291 ) {
5351                 return false;
5352             }
5353             final Protein p3 = proteins.get( 2 );
5354             if ( p3.getNumberOfProteinDomains() != 2 ) {
5355                 return false;
5356             }
5357             final Protein p4 = proteins.get( 3 );
5358             if ( p4.getNumberOfProteinDomains() != 1 ) {
5359                 return false;
5360             }
5361             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5362                 return false;
5363             }
5364             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5365                 return false;
5366             }
5367             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5368                 return false;
5369             }
5370             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5371                 return false;
5372             }
5373             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5374                 return false;
5375             }
5376             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5377                 return false;
5378             }
5379             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5380                 return false;
5381             }
5382         }
5383         catch ( final Exception e ) {
5384             e.printStackTrace( System.out );
5385             return false;
5386         }
5387         return true;
5388     }
5389
5390     private static boolean testLastExternalNodeMethods() {
5391         try {
5392             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5393             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5394             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5395             final PhylogenyNode n1 = t0.getNode( "A" );
5396             if ( n1.isLastExternalNode() ) {
5397                 return false;
5398             }
5399             final PhylogenyNode n2 = t0.getNode( "B" );
5400             if ( n2.isLastExternalNode() ) {
5401                 return false;
5402             }
5403             final PhylogenyNode n3 = t0.getNode( "C" );
5404             if ( n3.isLastExternalNode() ) {
5405                 return false;
5406             }
5407             final PhylogenyNode n4 = t0.getNode( "D" );
5408             if ( !n4.isLastExternalNode() ) {
5409                 return false;
5410             }
5411         }
5412         catch ( final Exception e ) {
5413             e.printStackTrace( System.out );
5414             return false;
5415         }
5416         return true;
5417     }
5418
5419     private static boolean testLevelOrderIterator() {
5420         try {
5421             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5422             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5423             PhylogenyNodeIterator it0;
5424             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5425                 it0.next();
5426             }
5427             for( it0.reset(); it0.hasNext(); ) {
5428                 it0.next();
5429             }
5430             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5431             if ( !it.next().getName().equals( "r" ) ) {
5432                 return false;
5433             }
5434             if ( !it.next().getName().equals( "ab" ) ) {
5435                 return false;
5436             }
5437             if ( !it.next().getName().equals( "cd" ) ) {
5438                 return false;
5439             }
5440             if ( !it.next().getName().equals( "A" ) ) {
5441                 return false;
5442             }
5443             if ( !it.next().getName().equals( "B" ) ) {
5444                 return false;
5445             }
5446             if ( !it.next().getName().equals( "C" ) ) {
5447                 return false;
5448             }
5449             if ( !it.next().getName().equals( "D" ) ) {
5450                 return false;
5451             }
5452             if ( it.hasNext() ) {
5453                 return false;
5454             }
5455             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",
5456                                                  new NHXParser() )[ 0 ];
5457             PhylogenyNodeIterator it2;
5458             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5459                 it2.next();
5460             }
5461             for( it2.reset(); it2.hasNext(); ) {
5462                 it2.next();
5463             }
5464             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5465             if ( !it3.next().getName().equals( "r" ) ) {
5466                 return false;
5467             }
5468             if ( !it3.next().getName().equals( "abc" ) ) {
5469                 return false;
5470             }
5471             if ( !it3.next().getName().equals( "defg" ) ) {
5472                 return false;
5473             }
5474             if ( !it3.next().getName().equals( "A" ) ) {
5475                 return false;
5476             }
5477             if ( !it3.next().getName().equals( "B" ) ) {
5478                 return false;
5479             }
5480             if ( !it3.next().getName().equals( "C" ) ) {
5481                 return false;
5482             }
5483             if ( !it3.next().getName().equals( "D" ) ) {
5484                 return false;
5485             }
5486             if ( !it3.next().getName().equals( "E" ) ) {
5487                 return false;
5488             }
5489             if ( !it3.next().getName().equals( "F" ) ) {
5490                 return false;
5491             }
5492             if ( !it3.next().getName().equals( "G" ) ) {
5493                 return false;
5494             }
5495             if ( !it3.next().getName().equals( "1" ) ) {
5496                 return false;
5497             }
5498             if ( !it3.next().getName().equals( "2" ) ) {
5499                 return false;
5500             }
5501             if ( !it3.next().getName().equals( "3" ) ) {
5502                 return false;
5503             }
5504             if ( !it3.next().getName().equals( "4" ) ) {
5505                 return false;
5506             }
5507             if ( !it3.next().getName().equals( "5" ) ) {
5508                 return false;
5509             }
5510             if ( !it3.next().getName().equals( "6" ) ) {
5511                 return false;
5512             }
5513             if ( !it3.next().getName().equals( "f1" ) ) {
5514                 return false;
5515             }
5516             if ( !it3.next().getName().equals( "f2" ) ) {
5517                 return false;
5518             }
5519             if ( !it3.next().getName().equals( "f3" ) ) {
5520                 return false;
5521             }
5522             if ( !it3.next().getName().equals( "a" ) ) {
5523                 return false;
5524             }
5525             if ( !it3.next().getName().equals( "b" ) ) {
5526                 return false;
5527             }
5528             if ( !it3.next().getName().equals( "f21" ) ) {
5529                 return false;
5530             }
5531             if ( !it3.next().getName().equals( "X" ) ) {
5532                 return false;
5533             }
5534             if ( !it3.next().getName().equals( "Y" ) ) {
5535                 return false;
5536             }
5537             if ( !it3.next().getName().equals( "Z" ) ) {
5538                 return false;
5539             }
5540             if ( it3.hasNext() ) {
5541                 return false;
5542             }
5543             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5544             PhylogenyNodeIterator it4;
5545             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5546                 it4.next();
5547             }
5548             for( it4.reset(); it4.hasNext(); ) {
5549                 it4.next();
5550             }
5551             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5552             if ( !it5.next().getName().equals( "r" ) ) {
5553                 return false;
5554             }
5555             if ( !it5.next().getName().equals( "A" ) ) {
5556                 return false;
5557             }
5558             if ( !it5.next().getName().equals( "B" ) ) {
5559                 return false;
5560             }
5561             if ( !it5.next().getName().equals( "C" ) ) {
5562                 return false;
5563             }
5564             if ( !it5.next().getName().equals( "D" ) ) {
5565                 return false;
5566             }
5567             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5568             PhylogenyNodeIterator it6;
5569             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5570                 it6.next();
5571             }
5572             for( it6.reset(); it6.hasNext(); ) {
5573                 it6.next();
5574             }
5575             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5576             if ( !it7.next().getName().equals( "A" ) ) {
5577                 return false;
5578             }
5579             if ( it.hasNext() ) {
5580                 return false;
5581             }
5582         }
5583         catch ( final Exception e ) {
5584             e.printStackTrace( System.out );
5585             return false;
5586         }
5587         return true;
5588     }
5589
5590     private static boolean testMafft( final String path ) {
5591         try {
5592             final List<String> opts = new ArrayList<String>();
5593             opts.add( "--maxiterate" );
5594             opts.add( "1000" );
5595             opts.add( "--localpair" );
5596             opts.add( "--quiet" );
5597             Msa msa = null;
5598             final MsaInferrer mafft = Mafft.createInstance( path );
5599             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5600             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5601                 return false;
5602             }
5603             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5604                 return false;
5605             }
5606         }
5607         catch ( final Exception e ) {
5608             e.printStackTrace( System.out );
5609             return false;
5610         }
5611         return true;
5612     }
5613
5614     private static boolean testMidpointrooting() {
5615         try {
5616             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5617             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5618             PhylogenyMethods.midpointRoot( t0 );
5619             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5620                 return false;
5621             }
5622             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5623                 return false;
5624             }
5625             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5626                            1 ) ) {
5627                 return false;
5628             }
5629             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",
5630                                                  new NHXParser() )[ 0 ];
5631             if ( !t1.isRooted() ) {
5632                 return false;
5633             }
5634             PhylogenyMethods.midpointRoot( t1 );
5635             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5636                 return false;
5637             }
5638             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5639                 return false;
5640             }
5641             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5642                 return false;
5643             }
5644             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5645                 return false;
5646             }
5647             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5648                 return false;
5649             }
5650             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5651                 return false;
5652             }
5653             t1.reRoot( t1.getNode( "A" ) );
5654             PhylogenyMethods.midpointRoot( t1 );
5655             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5656                 return false;
5657             }
5658             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5659                 return false;
5660             }
5661             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5662                 return false;
5663             }
5664             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5665                 return false;
5666             }
5667             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5668                 System.exit( -1 );
5669                 return false;
5670             }
5671             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5672                 return false;
5673             }
5674         }
5675         catch ( final Exception e ) {
5676             e.printStackTrace( System.out );
5677             return false;
5678         }
5679         return true;
5680     }
5681
5682     private static boolean testMsaQualityMethod() {
5683         try {
5684             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5685             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5686             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5687             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5688             final List<Sequence> l = new ArrayList<Sequence>();
5689             l.add( s0 );
5690             l.add( s1 );
5691             l.add( s2 );
5692             l.add( s3 );
5693             final Msa msa = BasicMsa.createInstance( l );
5694             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5695                 return false;
5696             }
5697             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5698                 return false;
5699             }
5700             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5701                 return false;
5702             }
5703             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5704                 return false;
5705             }
5706         }
5707         catch ( final Exception e ) {
5708             e.printStackTrace( System.out );
5709             return false;
5710         }
5711         return true;
5712     }
5713
5714     private static boolean testNextNodeWithCollapsing() {
5715         try {
5716             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5717             PhylogenyNode n;
5718             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5719             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5720             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5721             t0.getNode( "cd" ).setCollapse( true );
5722             t0.getNode( "cde" ).setCollapse( true );
5723             n = t0.getFirstExternalNode();
5724             while ( n != null ) {
5725                 ext.add( n );
5726                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5727             }
5728             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5729                 return false;
5730             }
5731             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5732                 return false;
5733             }
5734             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5735                 return false;
5736             }
5737             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5738                 return false;
5739             }
5740             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5741                 return false;
5742             }
5743             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5744                 return false;
5745             }
5746             ext.clear();
5747             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5748             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5749             t1.getNode( "ab" ).setCollapse( true );
5750             t1.getNode( "cd" ).setCollapse( true );
5751             t1.getNode( "cde" ).setCollapse( true );
5752             n = t1.getNode( "ab" );
5753             ext = new ArrayList<PhylogenyNode>();
5754             while ( n != null ) {
5755                 ext.add( n );
5756                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5757             }
5758             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5759                 return false;
5760             }
5761             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5762                 return false;
5763             }
5764             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5765                 return false;
5766             }
5767             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5768                 return false;
5769             }
5770             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5771                 return false;
5772             }
5773             //
5774             //
5775             ext.clear();
5776             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5777             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5778             t2.getNode( "ab" ).setCollapse( true );
5779             t2.getNode( "cd" ).setCollapse( true );
5780             t2.getNode( "cde" ).setCollapse( true );
5781             t2.getNode( "c" ).setCollapse( true );
5782             t2.getNode( "d" ).setCollapse( true );
5783             t2.getNode( "e" ).setCollapse( true );
5784             t2.getNode( "gh" ).setCollapse( true );
5785             n = t2.getNode( "ab" );
5786             ext = new ArrayList<PhylogenyNode>();
5787             while ( n != null ) {
5788                 ext.add( n );
5789                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5790             }
5791             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5792                 return false;
5793             }
5794             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5795                 return false;
5796             }
5797             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5798                 return false;
5799             }
5800             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5801                 return false;
5802             }
5803             //
5804             //
5805             ext.clear();
5806             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5807             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5808             t3.getNode( "ab" ).setCollapse( true );
5809             t3.getNode( "cd" ).setCollapse( true );
5810             t3.getNode( "cde" ).setCollapse( true );
5811             t3.getNode( "c" ).setCollapse( true );
5812             t3.getNode( "d" ).setCollapse( true );
5813             t3.getNode( "e" ).setCollapse( true );
5814             t3.getNode( "gh" ).setCollapse( true );
5815             t3.getNode( "fgh" ).setCollapse( true );
5816             n = t3.getNode( "ab" );
5817             ext = new ArrayList<PhylogenyNode>();
5818             while ( n != null ) {
5819                 ext.add( n );
5820                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5821             }
5822             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5823                 return false;
5824             }
5825             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5826                 return false;
5827             }
5828             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5829                 return false;
5830             }
5831             //
5832             //
5833             ext.clear();
5834             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5835             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5836             t4.getNode( "ab" ).setCollapse( true );
5837             t4.getNode( "cd" ).setCollapse( true );
5838             t4.getNode( "cde" ).setCollapse( true );
5839             t4.getNode( "c" ).setCollapse( true );
5840             t4.getNode( "d" ).setCollapse( true );
5841             t4.getNode( "e" ).setCollapse( true );
5842             t4.getNode( "gh" ).setCollapse( true );
5843             t4.getNode( "fgh" ).setCollapse( true );
5844             t4.getNode( "abcdefgh" ).setCollapse( true );
5845             n = t4.getNode( "abcdefgh" );
5846             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5847                 return false;
5848             }
5849             //
5850             //
5851             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5852             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5853             ext.clear();
5854             n = t5.getFirstExternalNode();
5855             while ( n != null ) {
5856                 ext.add( n );
5857                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5858             }
5859             if ( ext.size() != 8 ) {
5860                 return false;
5861             }
5862             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5863                 return false;
5864             }
5865             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5866                 return false;
5867             }
5868             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5869                 return false;
5870             }
5871             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5872                 return false;
5873             }
5874             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5875                 return false;
5876             }
5877             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5878                 return false;
5879             }
5880             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5881                 return false;
5882             }
5883             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5884                 return false;
5885             }
5886             //
5887             //
5888             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5889             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5890             ext.clear();
5891             t6.getNode( "ab" ).setCollapse( true );
5892             n = t6.getNode( "ab" );
5893             while ( n != null ) {
5894                 ext.add( n );
5895                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5896             }
5897             if ( ext.size() != 7 ) {
5898                 return false;
5899             }
5900             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5901                 return false;
5902             }
5903             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5904                 return false;
5905             }
5906             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5907                 return false;
5908             }
5909             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5910                 return false;
5911             }
5912             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5913                 return false;
5914             }
5915             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5916                 return false;
5917             }
5918             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5919                 return false;
5920             }
5921             //
5922             //
5923             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5924             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5925             ext.clear();
5926             t7.getNode( "cd" ).setCollapse( true );
5927             n = t7.getNode( "a" );
5928             while ( n != null ) {
5929                 ext.add( n );
5930                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5931             }
5932             if ( ext.size() != 7 ) {
5933                 return false;
5934             }
5935             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5936                 return false;
5937             }
5938             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5939                 return false;
5940             }
5941             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5942                 return false;
5943             }
5944             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5945                 return false;
5946             }
5947             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5948                 return false;
5949             }
5950             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5951                 return false;
5952             }
5953             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5954                 return false;
5955             }
5956             //
5957             //
5958             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5959             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5960             ext.clear();
5961             t8.getNode( "cd" ).setCollapse( true );
5962             t8.getNode( "c" ).setCollapse( true );
5963             t8.getNode( "d" ).setCollapse( true );
5964             n = t8.getNode( "a" );
5965             while ( n != null ) {
5966                 ext.add( n );
5967                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5968             }
5969             if ( ext.size() != 7 ) {
5970                 return false;
5971             }
5972             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5973                 return false;
5974             }
5975             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5976                 return false;
5977             }
5978             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5979                 System.out.println( "2 fail" );
5980                 return false;
5981             }
5982             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5983                 return false;
5984             }
5985             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5986                 return false;
5987             }
5988             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5989                 return false;
5990             }
5991             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5992                 return false;
5993             }
5994             //
5995             //
5996             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5997             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
5998             ext.clear();
5999             t9.getNode( "gh" ).setCollapse( true );
6000             n = t9.getNode( "a" );
6001             while ( n != null ) {
6002                 ext.add( n );
6003                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6004             }
6005             if ( ext.size() != 7 ) {
6006                 return false;
6007             }
6008             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6009                 return false;
6010             }
6011             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6012                 return false;
6013             }
6014             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6015                 return false;
6016             }
6017             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6018                 return false;
6019             }
6020             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6021                 return false;
6022             }
6023             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6024                 return false;
6025             }
6026             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6027                 return false;
6028             }
6029             //
6030             //
6031             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6032             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6033             ext.clear();
6034             t10.getNode( "gh" ).setCollapse( true );
6035             t10.getNode( "g" ).setCollapse( true );
6036             t10.getNode( "h" ).setCollapse( true );
6037             n = t10.getNode( "a" );
6038             while ( n != null ) {
6039                 ext.add( n );
6040                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6041             }
6042             if ( ext.size() != 7 ) {
6043                 return false;
6044             }
6045             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6046                 return false;
6047             }
6048             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6049                 return false;
6050             }
6051             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6052                 return false;
6053             }
6054             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6055                 return false;
6056             }
6057             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6058                 return false;
6059             }
6060             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6061                 return false;
6062             }
6063             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6064                 return false;
6065             }
6066             //
6067             //
6068             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6069             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6070             ext.clear();
6071             t11.getNode( "gh" ).setCollapse( true );
6072             t11.getNode( "fgh" ).setCollapse( true );
6073             n = t11.getNode( "a" );
6074             while ( n != null ) {
6075                 ext.add( n );
6076                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6077             }
6078             if ( ext.size() != 6 ) {
6079                 return false;
6080             }
6081             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6082                 return false;
6083             }
6084             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6085                 return false;
6086             }
6087             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6088                 return false;
6089             }
6090             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6091                 return false;
6092             }
6093             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6094                 return false;
6095             }
6096             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6097                 return false;
6098             }
6099             //
6100             //
6101             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6102             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6103             ext.clear();
6104             t12.getNode( "gh" ).setCollapse( true );
6105             t12.getNode( "fgh" ).setCollapse( true );
6106             t12.getNode( "g" ).setCollapse( true );
6107             t12.getNode( "h" ).setCollapse( true );
6108             t12.getNode( "f" ).setCollapse( true );
6109             n = t12.getNode( "a" );
6110             while ( n != null ) {
6111                 ext.add( n );
6112                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6113             }
6114             if ( ext.size() != 6 ) {
6115                 return false;
6116             }
6117             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6118                 return false;
6119             }
6120             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6121                 return false;
6122             }
6123             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6124                 return false;
6125             }
6126             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6127                 return false;
6128             }
6129             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6130                 return false;
6131             }
6132             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6133                 return false;
6134             }
6135             //
6136             //
6137             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6138             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6139             ext.clear();
6140             t13.getNode( "ab" ).setCollapse( true );
6141             t13.getNode( "b" ).setCollapse( true );
6142             t13.getNode( "fgh" ).setCollapse( true );
6143             t13.getNode( "gh" ).setCollapse( true );
6144             n = t13.getNode( "ab" );
6145             while ( n != null ) {
6146                 ext.add( n );
6147                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6148             }
6149             if ( ext.size() != 5 ) {
6150                 return false;
6151             }
6152             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6153                 return false;
6154             }
6155             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6156                 return false;
6157             }
6158             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6159                 return false;
6160             }
6161             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6162                 return false;
6163             }
6164             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6165                 return false;
6166             }
6167             //
6168             //
6169             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6170             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6171             ext.clear();
6172             t14.getNode( "ab" ).setCollapse( true );
6173             t14.getNode( "a" ).setCollapse( true );
6174             t14.getNode( "fgh" ).setCollapse( true );
6175             t14.getNode( "gh" ).setCollapse( true );
6176             n = t14.getNode( "ab" );
6177             while ( n != null ) {
6178                 ext.add( n );
6179                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6180             }
6181             if ( ext.size() != 5 ) {
6182                 return false;
6183             }
6184             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6185                 return false;
6186             }
6187             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6188                 return false;
6189             }
6190             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6191                 return false;
6192             }
6193             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6194                 return false;
6195             }
6196             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6197                 return false;
6198             }
6199             //
6200             //
6201             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" );
6202             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6203             ext.clear();
6204             t15.getNode( "ab" ).setCollapse( true );
6205             t15.getNode( "a" ).setCollapse( true );
6206             t15.getNode( "fgh" ).setCollapse( true );
6207             t15.getNode( "gh" ).setCollapse( true );
6208             n = t15.getNode( "ab" );
6209             while ( n != null ) {
6210                 ext.add( n );
6211                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6212             }
6213             if ( ext.size() != 6 ) {
6214                 return false;
6215             }
6216             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6217                 return false;
6218             }
6219             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6220                 return false;
6221             }
6222             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6223                 return false;
6224             }
6225             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6226                 return false;
6227             }
6228             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6229                 return false;
6230             }
6231             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6232                 return false;
6233             }
6234             //
6235             //
6236             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" );
6237             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6238             ext.clear();
6239             t16.getNode( "ab" ).setCollapse( true );
6240             t16.getNode( "a" ).setCollapse( true );
6241             t16.getNode( "fgh" ).setCollapse( true );
6242             t16.getNode( "gh" ).setCollapse( true );
6243             t16.getNode( "cd" ).setCollapse( true );
6244             t16.getNode( "cde" ).setCollapse( true );
6245             t16.getNode( "d" ).setCollapse( true );
6246             t16.getNode( "x" ).setCollapse( true );
6247             n = t16.getNode( "ab" );
6248             while ( n != null ) {
6249                 ext.add( n );
6250                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6251             }
6252             if ( ext.size() != 4 ) {
6253                 return false;
6254             }
6255             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6256                 return false;
6257             }
6258             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6259                 return false;
6260             }
6261             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6262                 return false;
6263             }
6264             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6265                 return false;
6266             }
6267         }
6268         catch ( final Exception e ) {
6269             e.printStackTrace( System.out );
6270             return false;
6271         }
6272         return true;
6273     }
6274
6275     private static boolean testNexusCharactersParsing() {
6276         try {
6277             final NexusCharactersParser parser = new NexusCharactersParser();
6278             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6279             parser.parse();
6280             String[] labels = parser.getCharStateLabels();
6281             if ( labels.length != 7 ) {
6282                 return false;
6283             }
6284             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6285                 return false;
6286             }
6287             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6288                 return false;
6289             }
6290             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6291                 return false;
6292             }
6293             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6294                 return false;
6295             }
6296             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6297                 return false;
6298             }
6299             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6300                 return false;
6301             }
6302             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6303                 return false;
6304             }
6305             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6306             parser.parse();
6307             labels = parser.getCharStateLabels();
6308             if ( labels.length != 7 ) {
6309                 return false;
6310             }
6311             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6312                 return false;
6313             }
6314             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6315                 return false;
6316             }
6317             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6318                 return false;
6319             }
6320             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6321                 return false;
6322             }
6323             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6324                 return false;
6325             }
6326             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6327                 return false;
6328             }
6329             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6330                 return false;
6331             }
6332         }
6333         catch ( final Exception e ) {
6334             e.printStackTrace( System.out );
6335             return false;
6336         }
6337         return true;
6338     }
6339
6340     private static boolean testNexusMatrixParsing() {
6341         try {
6342             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6343             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6344             parser.parse();
6345             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6346             if ( m.getNumberOfCharacters() != 9 ) {
6347                 return false;
6348             }
6349             if ( m.getNumberOfIdentifiers() != 5 ) {
6350                 return false;
6351             }
6352             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6353                 return false;
6354             }
6355             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6356                 return false;
6357             }
6358             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6359                 return false;
6360             }
6361             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6362                 return false;
6363             }
6364             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6365                 return false;
6366             }
6367             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6368                 return false;
6369             }
6370             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6371                 return false;
6372             }
6373             //            if ( labels.length != 7 ) {
6374             //                return false;
6375             //            }
6376             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6377             //                return false;
6378             //            }
6379             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6380             //                return false;
6381             //            }
6382             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6383             //                return false;
6384             //            }
6385             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6386             //                return false;
6387             //            }
6388             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6389             //                return false;
6390             //            }
6391             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6392             //                return false;
6393             //            }
6394             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6395             //                return false;
6396             //            }
6397             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6398             //            parser.parse();
6399             //            labels = parser.getCharStateLabels();
6400             //            if ( labels.length != 7 ) {
6401             //                return false;
6402             //            }
6403             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6404             //                return false;
6405             //            }
6406             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6407             //                return false;
6408             //            }
6409             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6410             //                return false;
6411             //            }
6412             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6413             //                return false;
6414             //            }
6415             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6416             //                return false;
6417             //            }
6418             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6419             //                return false;
6420             //            }
6421             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6422             //                return false;
6423             //            }
6424         }
6425         catch ( final Exception e ) {
6426             e.printStackTrace( System.out );
6427             return false;
6428         }
6429         return true;
6430     }
6431
6432     private static boolean testNexusTreeParsing() {
6433         try {
6434             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6435             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6436             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6437             if ( phylogenies.length != 1 ) {
6438                 return false;
6439             }
6440             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6441                 return false;
6442             }
6443             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6444                 return false;
6445             }
6446             phylogenies = null;
6447             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6448             if ( phylogenies.length != 1 ) {
6449                 return false;
6450             }
6451             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6452                 return false;
6453             }
6454             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6455                 return false;
6456             }
6457             phylogenies = null;
6458             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6459             if ( phylogenies.length != 1 ) {
6460                 return false;
6461             }
6462             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6463                 return false;
6464             }
6465             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6466                 return false;
6467             }
6468             if ( phylogenies[ 0 ].isRooted() ) {
6469                 return false;
6470             }
6471             phylogenies = null;
6472             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6473             if ( phylogenies.length != 18 ) {
6474                 return false;
6475             }
6476             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6477                 return false;
6478             }
6479             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6480                 return false;
6481             }
6482             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6483                 return false;
6484             }
6485             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6486                 return false;
6487             }
6488             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6489                 return false;
6490             }
6491             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6492                 return false;
6493             }
6494             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6495                 return false;
6496             }
6497             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6498                 return false;
6499             }
6500             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6501                 return false;
6502             }
6503             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6504                 return false;
6505             }
6506             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6507                 return false;
6508             }
6509             if ( phylogenies[ 8 ].isRooted() ) {
6510                 return false;
6511             }
6512             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6513                 return false;
6514             }
6515             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6516                 return false;
6517             }
6518             if ( !phylogenies[ 9 ].isRooted() ) {
6519                 return false;
6520             }
6521             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6522                 return false;
6523             }
6524             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6525                 return false;
6526             }
6527             if ( !phylogenies[ 10 ].isRooted() ) {
6528                 return false;
6529             }
6530             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6531                 return false;
6532             }
6533             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6534                 return false;
6535             }
6536             if ( phylogenies[ 11 ].isRooted() ) {
6537                 return false;
6538             }
6539             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6540                 return false;
6541             }
6542             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6543                 return false;
6544             }
6545             if ( !phylogenies[ 12 ].isRooted() ) {
6546                 return false;
6547             }
6548             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6549                 return false;
6550             }
6551             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6552                 return false;
6553             }
6554             if ( !phylogenies[ 13 ].isRooted() ) {
6555                 return false;
6556             }
6557             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6558                 return false;
6559             }
6560             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6561                 return false;
6562             }
6563             if ( !phylogenies[ 14 ].isRooted() ) {
6564                 return false;
6565             }
6566             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6567                 return false;
6568             }
6569             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6570                 return false;
6571             }
6572             if ( phylogenies[ 15 ].isRooted() ) {
6573                 return false;
6574             }
6575             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6576                 return false;
6577             }
6578             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6579                 return false;
6580             }
6581             if ( !phylogenies[ 16 ].isRooted() ) {
6582                 return false;
6583             }
6584             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6585                 return false;
6586             }
6587             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6588                 return false;
6589             }
6590             if ( phylogenies[ 17 ].isRooted() ) {
6591                 return false;
6592             }
6593             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6594                 return false;
6595             }
6596         }
6597         catch ( final Exception e ) {
6598             e.printStackTrace( System.out );
6599             return false;
6600         }
6601         return true;
6602     }
6603
6604     private static boolean testNexusTreeParsingIterating() {
6605         try {
6606             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6607             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6608             if ( !p.hasNext() ) {
6609                 return false;
6610             }
6611             Phylogeny phy = p.next();
6612             if ( phy == null ) {
6613                 return false;
6614             }
6615             if ( phy.getNumberOfExternalNodes() != 25 ) {
6616                 return false;
6617             }
6618             if ( !phy.getName().equals( "" ) ) {
6619                 return false;
6620             }
6621             if ( p.hasNext() ) {
6622                 return false;
6623             }
6624             phy = p.next();
6625             if ( phy != null ) {
6626                 return false;
6627             }
6628             //
6629             p.reset();
6630             if ( !p.hasNext() ) {
6631                 return false;
6632             }
6633             phy = p.next();
6634             if ( phy == null ) {
6635                 return false;
6636             }
6637             if ( phy.getNumberOfExternalNodes() != 25 ) {
6638                 return false;
6639             }
6640             if ( !phy.getName().equals( "" ) ) {
6641                 return false;
6642             }
6643             if ( p.hasNext() ) {
6644                 return false;
6645             }
6646             phy = p.next();
6647             if ( phy != null ) {
6648                 return false;
6649             }
6650             ////
6651             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6652             if ( !p.hasNext() ) {
6653                 return false;
6654             }
6655             phy = p.next();
6656             if ( phy == null ) {
6657                 return false;
6658             }
6659             if ( phy.getNumberOfExternalNodes() != 10 ) {
6660                 return false;
6661             }
6662             if ( !phy.getName().equals( "name" ) ) {
6663                 return false;
6664             }
6665             if ( p.hasNext() ) {
6666                 return false;
6667             }
6668             phy = p.next();
6669             if ( phy != null ) {
6670                 return false;
6671             }
6672             //
6673             p.reset();
6674             if ( !p.hasNext() ) {
6675                 return false;
6676             }
6677             phy = p.next();
6678             if ( phy == null ) {
6679                 return false;
6680             }
6681             if ( phy.getNumberOfExternalNodes() != 10 ) {
6682                 return false;
6683             }
6684             if ( !phy.getName().equals( "name" ) ) {
6685                 return false;
6686             }
6687             if ( p.hasNext() ) {
6688                 return false;
6689             }
6690             phy = p.next();
6691             if ( phy != null ) {
6692                 return false;
6693             }
6694             ////
6695             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6696             if ( !p.hasNext() ) {
6697                 return false;
6698             }
6699             phy = p.next();
6700             if ( phy == null ) {
6701                 return false;
6702             }
6703             if ( phy.getNumberOfExternalNodes() != 3 ) {
6704                 return false;
6705             }
6706             if ( !phy.getName().equals( "" ) ) {
6707                 return false;
6708             }
6709             if ( phy.isRooted() ) {
6710                 return false;
6711             }
6712             if ( p.hasNext() ) {
6713                 return false;
6714             }
6715             phy = p.next();
6716             if ( phy != null ) {
6717                 return false;
6718             }
6719             //
6720             p.reset();
6721             if ( !p.hasNext() ) {
6722                 return false;
6723             }
6724             phy = p.next();
6725             if ( phy == null ) {
6726                 return false;
6727             }
6728             if ( phy.getNumberOfExternalNodes() != 3 ) {
6729                 return false;
6730             }
6731             if ( !phy.getName().equals( "" ) ) {
6732                 return false;
6733             }
6734             if ( p.hasNext() ) {
6735                 return false;
6736             }
6737             phy = p.next();
6738             if ( phy != null ) {
6739                 return false;
6740             }
6741             ////
6742             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6743             //            if ( phylogenies.length != 18 ) {
6744             //                return false;
6745             //            }
6746             //0
6747             if ( !p.hasNext() ) {
6748                 return false;
6749             }
6750             phy = p.next();
6751             if ( phy == null ) {
6752                 return false;
6753             }
6754             if ( phy.getNumberOfExternalNodes() != 10 ) {
6755                 return false;
6756             }
6757             if ( !phy.getName().equals( "tree 0" ) ) {
6758                 return false;
6759             }
6760             //1
6761             if ( !p.hasNext() ) {
6762                 return false;
6763             }
6764             phy = p.next();
6765             if ( phy == null ) {
6766                 return false;
6767             }
6768             if ( phy.getNumberOfExternalNodes() != 10 ) {
6769                 return false;
6770             }
6771             if ( !phy.getName().equals( "tree 1" ) ) {
6772                 return false;
6773             }
6774             //2
6775             if ( !p.hasNext() ) {
6776                 return false;
6777             }
6778             phy = p.next();
6779             if ( phy == null ) {
6780                 return false;
6781             }
6782             if ( phy.getNumberOfExternalNodes() != 3 ) {
6783                 return false;
6784             }
6785             if ( !phy.getName().equals( "" ) ) {
6786                 return false;
6787             }
6788             if ( phy.isRooted() ) {
6789                 return false;
6790             }
6791             //3
6792             if ( !p.hasNext() ) {
6793                 return false;
6794             }
6795             phy = p.next();
6796             if ( phy == null ) {
6797                 return false;
6798             }
6799             if ( phy.getNumberOfExternalNodes() != 4 ) {
6800                 return false;
6801             }
6802             if ( !phy.getName().equals( "" ) ) {
6803                 return false;
6804             }
6805             if ( !phy.isRooted() ) {
6806                 return false;
6807             }
6808             //4
6809             if ( !p.hasNext() ) {
6810                 return false;
6811             }
6812             phy = p.next();
6813             if ( phy == null ) {
6814                 return false;
6815             }
6816             if ( phy.getNumberOfExternalNodes() != 5 ) {
6817                 System.out.println( phy.getNumberOfExternalNodes() );
6818                 return false;
6819             }
6820             if ( !phy.getName().equals( "" ) ) {
6821                 return false;
6822             }
6823             if ( !phy.isRooted() ) {
6824                 return false;
6825             }
6826             //5
6827             if ( !p.hasNext() ) {
6828                 return false;
6829             }
6830             phy = p.next();
6831             if ( phy == null ) {
6832                 return false;
6833             }
6834             if ( phy.getNumberOfExternalNodes() != 3 ) {
6835                 return false;
6836             }
6837             if ( !phy.getName().equals( "" ) ) {
6838                 return false;
6839             }
6840             if ( phy.isRooted() ) {
6841                 return false;
6842             }
6843             //6
6844             if ( !p.hasNext() ) {
6845                 return false;
6846             }
6847             phy = p.next();
6848             if ( phy == null ) {
6849                 return false;
6850             }
6851             if ( phy.getNumberOfExternalNodes() != 2 ) {
6852                 return false;
6853             }
6854             if ( !phy.getName().equals( "" ) ) {
6855                 return false;
6856             }
6857             if ( !phy.isRooted() ) {
6858                 return false;
6859             }
6860             //7
6861             if ( !p.hasNext() ) {
6862                 return false;
6863             }
6864             phy = p.next();
6865             if ( phy.getNumberOfExternalNodes() != 3 ) {
6866                 return false;
6867             }
6868             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6869                 return false;
6870             }
6871             if ( !phy.isRooted() ) {
6872                 return false;
6873             }
6874             //8
6875             if ( !p.hasNext() ) {
6876                 return false;
6877             }
6878             phy = p.next();
6879             if ( phy.getNumberOfExternalNodes() != 3 ) {
6880                 return false;
6881             }
6882             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6883                 return false;
6884             }
6885             if ( !phy.getName().equals( "tree 8" ) ) {
6886                 return false;
6887             }
6888             //9
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),cc);" ) ) {
6897                 return false;
6898             }
6899             if ( !phy.getName().equals( "tree 9" ) ) {
6900                 return false;
6901             }
6902             //10
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( "((a,b),c);" ) ) {
6911                 return false;
6912             }
6913             if ( !phy.getName().equals( "tree 10" ) ) {
6914                 return false;
6915             }
6916             if ( !phy.isRooted() ) {
6917                 return false;
6918             }
6919             //11
6920             if ( !p.hasNext() ) {
6921                 return false;
6922             }
6923             phy = p.next();
6924             if ( phy.getNumberOfExternalNodes() != 3 ) {
6925                 return false;
6926             }
6927             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6928                 return false;
6929             }
6930             if ( !phy.getName().equals( "tree 11" ) ) {
6931                 return false;
6932             }
6933             if ( phy.isRooted() ) {
6934                 return false;
6935             }
6936             //12
6937             if ( !p.hasNext() ) {
6938                 return false;
6939             }
6940             phy = p.next();
6941             if ( phy.getNumberOfExternalNodes() != 3 ) {
6942                 return false;
6943             }
6944             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6945                 return false;
6946             }
6947             if ( !phy.getName().equals( "tree 12" ) ) {
6948                 return false;
6949             }
6950             if ( !phy.isRooted() ) {
6951                 return false;
6952             }
6953             //13
6954             if ( !p.hasNext() ) {
6955                 return false;
6956             }
6957             phy = p.next();
6958             if ( phy.getNumberOfExternalNodes() != 3 ) {
6959                 return false;
6960             }
6961             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6962                 return false;
6963             }
6964             if ( !phy.getName().equals( "tree 13" ) ) {
6965                 return false;
6966             }
6967             if ( !phy.isRooted() ) {
6968                 return false;
6969             }
6970             //14
6971             if ( !p.hasNext() ) {
6972                 return false;
6973             }
6974             phy = p.next();
6975             if ( phy.getNumberOfExternalNodes() != 10 ) {
6976                 System.out.println( phy.getNumberOfExternalNodes() );
6977                 return false;
6978             }
6979             if ( !phy
6980                     .toNewHampshire()
6981                     .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;" ) ) {
6982                 System.out.println( phy.toNewHampshire() );
6983                 return false;
6984             }
6985             if ( !phy.getName().equals( "tree 14" ) ) {
6986                 return false;
6987             }
6988             if ( !phy.isRooted() ) {
6989                 return false;
6990             }
6991             //15
6992             if ( !p.hasNext() ) {
6993                 return false;
6994             }
6995             phy = p.next();
6996             if ( phy.getNumberOfExternalNodes() != 10 ) {
6997                 System.out.println( phy.getNumberOfExternalNodes() );
6998                 return false;
6999             }
7000             if ( !phy
7001                     .toNewHampshire()
7002                     .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;" ) ) {
7003                 System.out.println( phy.toNewHampshire() );
7004                 return false;
7005             }
7006             if ( !phy.getName().equals( "tree 15" ) ) {
7007                 return false;
7008             }
7009             if ( phy.isRooted() ) {
7010                 return false;
7011             }
7012             //16
7013             if ( !p.hasNext() ) {
7014                 return false;
7015             }
7016             phy = p.next();
7017             if ( phy.getNumberOfExternalNodes() != 10 ) {
7018                 System.out.println( phy.getNumberOfExternalNodes() );
7019                 return false;
7020             }
7021             if ( !phy
7022                     .toNewHampshire()
7023                     .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;" ) ) {
7024                 System.out.println( phy.toNewHampshire() );
7025                 return false;
7026             }
7027             if ( !phy.getName().equals( "tree 16" ) ) {
7028                 return false;
7029             }
7030             if ( !phy.isRooted() ) {
7031                 return false;
7032             }
7033             //17
7034             if ( !p.hasNext() ) {
7035                 return false;
7036             }
7037             phy = p.next();
7038             if ( phy.getNumberOfExternalNodes() != 10 ) {
7039                 System.out.println( phy.getNumberOfExternalNodes() );
7040                 return false;
7041             }
7042             if ( !phy
7043                     .toNewHampshire()
7044                     .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;" ) ) {
7045                 System.out.println( phy.toNewHampshire() );
7046                 return false;
7047             }
7048             if ( !phy.getName().equals( "tree 17" ) ) {
7049                 return false;
7050             }
7051             if ( phy.isRooted() ) {
7052                 return false;
7053             }
7054             //
7055             if ( p.hasNext() ) {
7056                 return false;
7057             }
7058             phy = p.next();
7059             if ( phy != null ) {
7060                 return false;
7061             }
7062             p.reset();
7063             //0
7064             if ( !p.hasNext() ) {
7065                 return false;
7066             }
7067             phy = p.next();
7068             if ( phy == null ) {
7069                 return false;
7070             }
7071             if ( phy.getNumberOfExternalNodes() != 10 ) {
7072                 return false;
7073             }
7074             if ( !phy.getName().equals( "tree 0" ) ) {
7075                 return false;
7076             }
7077             //1
7078             if ( !p.hasNext() ) {
7079                 return false;
7080             }
7081             phy = p.next();
7082             if ( phy == null ) {
7083                 return false;
7084             }
7085             if ( phy.getNumberOfExternalNodes() != 10 ) {
7086                 return false;
7087             }
7088             if ( !phy.getName().equals( "tree 1" ) ) {
7089                 return false;
7090             }
7091             //2
7092             if ( !p.hasNext() ) {
7093                 return false;
7094             }
7095             phy = p.next();
7096             if ( phy == null ) {
7097                 return false;
7098             }
7099             if ( phy.getNumberOfExternalNodes() != 3 ) {
7100                 return false;
7101             }
7102             if ( !phy.getName().equals( "" ) ) {
7103                 return false;
7104             }
7105             if ( phy.isRooted() ) {
7106                 return false;
7107             }
7108             //3
7109             if ( !p.hasNext() ) {
7110                 return false;
7111             }
7112             phy = p.next();
7113             if ( phy == null ) {
7114                 return false;
7115             }
7116             if ( phy.getNumberOfExternalNodes() != 4 ) {
7117                 return false;
7118             }
7119             if ( !phy.getName().equals( "" ) ) {
7120                 return false;
7121             }
7122             if ( !phy.isRooted() ) {
7123                 return false;
7124             }
7125             //4
7126             if ( !p.hasNext() ) {
7127                 return false;
7128             }
7129             phy = p.next();
7130             if ( phy == null ) {
7131                 return false;
7132             }
7133             if ( phy.getNumberOfExternalNodes() != 5 ) {
7134                 System.out.println( phy.getNumberOfExternalNodes() );
7135                 return false;
7136             }
7137             if ( !phy.getName().equals( "" ) ) {
7138                 return false;
7139             }
7140             if ( !phy.isRooted() ) {
7141                 return false;
7142             }
7143             //5
7144             if ( !p.hasNext() ) {
7145                 return false;
7146             }
7147             phy = p.next();
7148             if ( phy == null ) {
7149                 return false;
7150             }
7151             if ( phy.getNumberOfExternalNodes() != 3 ) {
7152                 return false;
7153             }
7154             if ( !phy.getName().equals( "" ) ) {
7155                 return false;
7156             }
7157             if ( phy.isRooted() ) {
7158                 return false;
7159             }
7160         }
7161         catch ( final Exception e ) {
7162             e.printStackTrace( System.out );
7163             return false;
7164         }
7165         return true;
7166     }
7167
7168     private static boolean testNexusTreeParsingTranslating() {
7169         try {
7170             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7171             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7172             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7173             if ( phylogenies.length != 1 ) {
7174                 return false;
7175             }
7176             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7177                 return false;
7178             }
7179             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7180                 return false;
7181             }
7182             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7183                 return false;
7184             }
7185             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7186                 return false;
7187             }
7188             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7189                     .equals( "Aranaeus" ) ) {
7190                 return false;
7191             }
7192             phylogenies = null;
7193             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7194             if ( phylogenies.length != 3 ) {
7195                 return false;
7196             }
7197             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7198                 return false;
7199             }
7200             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7201                 return false;
7202             }
7203             if ( phylogenies[ 0 ].isRooted() ) {
7204                 return false;
7205             }
7206             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7207                 return false;
7208             }
7209             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7210                 return false;
7211             }
7212             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7213                     .equals( "Aranaeus" ) ) {
7214                 return false;
7215             }
7216             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7217                 return false;
7218             }
7219             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7220                 return false;
7221             }
7222             if ( phylogenies[ 1 ].isRooted() ) {
7223                 return false;
7224             }
7225             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7226                 return false;
7227             }
7228             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7229                 return false;
7230             }
7231             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7232                     .equals( "Aranaeus" ) ) {
7233                 return false;
7234             }
7235             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7236                 return false;
7237             }
7238             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7239                 return false;
7240             }
7241             if ( !phylogenies[ 2 ].isRooted() ) {
7242                 return false;
7243             }
7244             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7245                 return false;
7246             }
7247             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7248                 return false;
7249             }
7250             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7251                     .equals( "Aranaeus" ) ) {
7252                 return false;
7253             }
7254             phylogenies = null;
7255             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7256             if ( phylogenies.length != 3 ) {
7257                 return false;
7258             }
7259             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7260                 return false;
7261             }
7262             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7263                 return false;
7264             }
7265             if ( phylogenies[ 0 ].isRooted() ) {
7266                 return false;
7267             }
7268             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7269                 return false;
7270             }
7271             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7272                 return false;
7273             }
7274             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7275                     .equals( "Aranaeus" ) ) {
7276                 return false;
7277             }
7278             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7279                 return false;
7280             }
7281             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7282                 return false;
7283             }
7284             if ( phylogenies[ 1 ].isRooted() ) {
7285                 return false;
7286             }
7287             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7288                 return false;
7289             }
7290             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7291                 return false;
7292             }
7293             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7294                     .equals( "Aranaeus" ) ) {
7295                 return false;
7296             }
7297             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7298                 return false;
7299             }
7300             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7301                 return false;
7302             }
7303             if ( !phylogenies[ 2 ].isRooted() ) {
7304                 return false;
7305             }
7306             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7307                 return false;
7308             }
7309             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7310                 return false;
7311             }
7312             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7313                     .equals( "Aranaeus" ) ) {
7314                 return false;
7315             }
7316         }
7317         catch ( final Exception e ) {
7318             e.printStackTrace( System.out );
7319             return false;
7320         }
7321         return true;
7322     }
7323
7324     private static boolean testNHParsing() {
7325         try {
7326             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7327             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7328             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7329                 return false;
7330             }
7331             final NHXParser nhxp = new NHXParser();
7332             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7333             nhxp.setReplaceUnderscores( true );
7334             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7335             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
7336                 return false;
7337             }
7338             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
7339                 return false;
7340             }
7341             final Phylogeny p1b = factory
7342                     .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 ",
7343                              new NHXParser() )[ 0 ];
7344             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7345                 return false;
7346             }
7347             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7348                 return false;
7349             }
7350             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7351             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7352             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7353             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7354             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7355             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7356             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7357             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7358             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7359             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7360             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7361                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7362                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7363                                                     new NHXParser() );
7364             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7365                 return false;
7366             }
7367             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7368                 return false;
7369             }
7370             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7371                 return false;
7372             }
7373             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7374                 return false;
7375             }
7376             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7377             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7378             final String p16_S = "((A,B),C)";
7379             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7380             if ( p16.length != 1 ) {
7381                 return false;
7382             }
7383             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
7384                 return false;
7385             }
7386             final String p17_S = "(C,(A,B))";
7387             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
7388             if ( p17.length != 1 ) {
7389                 return false;
7390             }
7391             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7392                 return false;
7393             }
7394             final String p18_S = "((A,B),(C,D))";
7395             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7396             if ( p18.length != 1 ) {
7397                 return false;
7398             }
7399             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7400                 return false;
7401             }
7402             final String p19_S = "(((A,B),C),D)";
7403             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7404             if ( p19.length != 1 ) {
7405                 return false;
7406             }
7407             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7408                 return false;
7409             }
7410             final String p20_S = "(A,(B,(C,D)))";
7411             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7412             if ( p20.length != 1 ) {
7413                 return false;
7414             }
7415             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7416                 return false;
7417             }
7418             final String p21_S = "(A,(B,(C,(D,E))))";
7419             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7420             if ( p21.length != 1 ) {
7421                 return false;
7422             }
7423             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7424                 return false;
7425             }
7426             final String p22_S = "((((A,B),C),D),E)";
7427             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7428             if ( p22.length != 1 ) {
7429                 return false;
7430             }
7431             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7432                 return false;
7433             }
7434             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7435             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7436             if ( p23.length != 1 ) {
7437                 System.out.println( "xl=" + p23.length );
7438                 System.exit( -1 );
7439                 return false;
7440             }
7441             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7442                 return false;
7443             }
7444             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7445             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7446             if ( p24.length != 1 ) {
7447                 return false;
7448             }
7449             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7450                 return false;
7451             }
7452             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7453             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7454             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7455             if ( p241.length != 2 ) {
7456                 return false;
7457             }
7458             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7459                 return false;
7460             }
7461             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7462                 return false;
7463             }
7464             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7465                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7466                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7467                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7468                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7469                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7470                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7471                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7472             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7473             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7474                 return false;
7475             }
7476             final String p26_S = "(A,B)ab";
7477             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7478             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7479                 return false;
7480             }
7481             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7482             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7483             if ( p27s.length != 1 ) {
7484                 System.out.println( "xxl=" + p27s.length );
7485                 System.exit( -1 );
7486                 return false;
7487             }
7488             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7489                 System.out.println( p27s[ 0 ].toNewHampshireX() );
7490                 System.exit( -1 );
7491                 return false;
7492             }
7493             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7494                                                     new NHXParser() );
7495             if ( p27.length != 1 ) {
7496                 System.out.println( "yl=" + p27.length );
7497                 System.exit( -1 );
7498                 return false;
7499             }
7500             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7501                 System.out.println( p27[ 0 ].toNewHampshireX() );
7502                 System.exit( -1 );
7503                 return false;
7504             }
7505             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7506             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7507             final String p28_S3 = "(A,B)ab";
7508             final String p28_S4 = "((((A,B),C),D),;E;)";
7509             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7510                                                     new NHXParser() );
7511             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7512                 return false;
7513             }
7514             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7515                 return false;
7516             }
7517             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7518                 return false;
7519             }
7520             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7521                 return false;
7522             }
7523             if ( p28.length != 4 ) {
7524                 return false;
7525             }
7526             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";
7527             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
7528             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
7529                 return false;
7530             }
7531             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";
7532             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
7533             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
7534                 return false;
7535             }
7536             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
7537             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
7538             if ( ( p32.length != 0 ) ) {
7539                 return false;
7540             }
7541             final String p33_S = "A";
7542             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
7543             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
7544                 return false;
7545             }
7546             final String p34_S = "B;";
7547             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
7548             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
7549                 return false;
7550             }
7551             final String p35_S = "B:0.2";
7552             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7553             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7554                 return false;
7555             }
7556             final String p36_S = "(A)";
7557             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7558             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7559                 return false;
7560             }
7561             final String p37_S = "((A))";
7562             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7563             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7564                 return false;
7565             }
7566             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7567             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7568             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7569                 return false;
7570             }
7571             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7572             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7573             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7574                 return false;
7575             }
7576             final String p40_S = "(A,B,C)";
7577             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7578             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7579                 return false;
7580             }
7581             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7582             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7583             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7584                 return false;
7585             }
7586             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7587             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7588             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7589                 return false;
7590             }
7591             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)";
7592             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7593             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7594                 return false;
7595             }
7596             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)))";
7597             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7598             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7599                 return false;
7600             }
7601             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7602             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7603             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7604                 return false;
7605             }
7606             final String p46_S = "";
7607             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7608             if ( p46.length != 0 ) {
7609                 return false;
7610             }
7611             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7612             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7613                 return false;
7614             }
7615             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7616             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7617                 return false;
7618             }
7619             final Phylogeny p49 = factory
7620                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7621                              new NHXParser() )[ 0 ];
7622             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7623                 return false;
7624             }
7625             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7626             if ( p50.getNode( "A" ) == null ) {
7627                 return false;
7628             }
7629             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7630                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7631                 return false;
7632             }
7633             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7634                 return false;
7635             }
7636             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7637                     .equals( "((A,B)88:2.0,C);" ) ) {
7638                 return false;
7639             }
7640             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7641             if ( p51.getNode( "A(A" ) == null ) {
7642                 return false;
7643             }
7644             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7645             if ( p52.getNode( "A(A" ) == null ) {
7646                 return false;
7647             }
7648             final Phylogeny p53 = factory
7649                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7650                              new NHXParser() )[ 0 ];
7651             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7652                 return false;
7653             }
7654             // 
7655             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7656             if ( p54.getNode( "A" ) == null ) {
7657                 return false;
7658             }
7659             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7660                     .equals( "((A,B)[88],C);" ) ) {
7661                 return false;
7662             }
7663         }
7664         catch ( final Exception e ) {
7665             e.printStackTrace( System.out );
7666             return false;
7667         }
7668         return true;
7669     }
7670
7671     private static boolean testNHParsingIter() {
7672         try {
7673             final String p0_str = "(A,B);";
7674             final NHXParser p = new NHXParser();
7675             p.setSource( p0_str );
7676             if ( !p.hasNext() ) {
7677                 return false;
7678             }
7679             final Phylogeny p0 = p.next();
7680             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7681                 System.out.println( p0.toNewHampshire() );
7682                 return false;
7683             }
7684             if ( p.hasNext() ) {
7685                 return false;
7686             }
7687             if ( p.next() != null ) {
7688                 return false;
7689             }
7690             //
7691             final String p00_str = "(A,B)root;";
7692             p.setSource( p00_str );
7693             final Phylogeny p00 = p.next();
7694             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7695                 System.out.println( p00.toNewHampshire() );
7696                 return false;
7697             }
7698             //
7699             final String p000_str = "A;";
7700             p.setSource( p000_str );
7701             final Phylogeny p000 = p.next();
7702             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7703                 System.out.println( p000.toNewHampshire() );
7704                 return false;
7705             }
7706             //
7707             final String p0000_str = "A";
7708             p.setSource( p0000_str );
7709             final Phylogeny p0000 = p.next();
7710             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7711                 System.out.println( p0000.toNewHampshire() );
7712                 return false;
7713             }
7714             //
7715             p.setSource( "(A)" );
7716             final Phylogeny p00000 = p.next();
7717             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7718                 System.out.println( p00000.toNewHampshire() );
7719                 return false;
7720             }
7721             //
7722             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7723             p.setSource( p1_str );
7724             if ( !p.hasNext() ) {
7725                 return false;
7726             }
7727             final Phylogeny p1_0 = p.next();
7728             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7729                 System.out.println( p1_0.toNewHampshire() );
7730                 return false;
7731             }
7732             if ( !p.hasNext() ) {
7733                 return false;
7734             }
7735             final Phylogeny p1_1 = p.next();
7736             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7737                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7738                 return false;
7739             }
7740             if ( !p.hasNext() ) {
7741                 return false;
7742             }
7743             final Phylogeny p1_2 = p.next();
7744             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7745                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7746                 return false;
7747             }
7748             if ( !p.hasNext() ) {
7749                 return false;
7750             }
7751             final Phylogeny p1_3 = p.next();
7752             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7753                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7754                 return false;
7755             }
7756             if ( p.hasNext() ) {
7757                 return false;
7758             }
7759             if ( p.next() != null ) {
7760                 return false;
7761             }
7762             //
7763             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7764             p.setSource( p2_str );
7765             if ( !p.hasNext() ) {
7766                 return false;
7767             }
7768             Phylogeny p2_0 = p.next();
7769             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7770                 System.out.println( p2_0.toNewHampshire() );
7771                 return false;
7772             }
7773             if ( !p.hasNext() ) {
7774                 return false;
7775             }
7776             Phylogeny p2_1 = p.next();
7777             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7778                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7779                 return false;
7780             }
7781             if ( !p.hasNext() ) {
7782                 return false;
7783             }
7784             Phylogeny p2_2 = p.next();
7785             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7786                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7787                 return false;
7788             }
7789             if ( !p.hasNext() ) {
7790                 return false;
7791             }
7792             Phylogeny p2_3 = p.next();
7793             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7794                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7795                 return false;
7796             }
7797             if ( !p.hasNext() ) {
7798                 return false;
7799             }
7800             Phylogeny p2_4 = p.next();
7801             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7802                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7803                 return false;
7804             }
7805             if ( p.hasNext() ) {
7806                 return false;
7807             }
7808             if ( p.next() != null ) {
7809                 return false;
7810             }
7811             ////
7812             p.reset();
7813             if ( !p.hasNext() ) {
7814                 return false;
7815             }
7816             p2_0 = p.next();
7817             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7818                 System.out.println( p2_0.toNewHampshire() );
7819                 return false;
7820             }
7821             if ( !p.hasNext() ) {
7822                 return false;
7823             }
7824             p2_1 = p.next();
7825             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7826                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7827                 return false;
7828             }
7829             if ( !p.hasNext() ) {
7830                 return false;
7831             }
7832             p2_2 = p.next();
7833             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7834                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7835                 return false;
7836             }
7837             if ( !p.hasNext() ) {
7838                 return false;
7839             }
7840             p2_3 = p.next();
7841             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7842                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7843                 return false;
7844             }
7845             if ( !p.hasNext() ) {
7846                 return false;
7847             }
7848             p2_4 = p.next();
7849             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7850                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7851                 return false;
7852             }
7853             if ( p.hasNext() ) {
7854                 return false;
7855             }
7856             if ( p.next() != null ) {
7857                 return false;
7858             }
7859             //
7860             final String p3_str = "((A,B),C)abc";
7861             p.setSource( p3_str );
7862             if ( !p.hasNext() ) {
7863                 return false;
7864             }
7865             final Phylogeny p3_0 = p.next();
7866             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7867                 return false;
7868             }
7869             if ( p.hasNext() ) {
7870                 return false;
7871             }
7872             if ( p.next() != null ) {
7873                 return false;
7874             }
7875             //
7876             final String p4_str = "((A,B)ab,C)abc";
7877             p.setSource( p4_str );
7878             if ( !p.hasNext() ) {
7879                 return false;
7880             }
7881             final Phylogeny p4_0 = p.next();
7882             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7883                 return false;
7884             }
7885             if ( p.hasNext() ) {
7886                 return false;
7887             }
7888             if ( p.next() != null ) {
7889                 return false;
7890             }
7891             //
7892             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7893             p.setSource( p5_str );
7894             if ( !p.hasNext() ) {
7895                 return false;
7896             }
7897             final Phylogeny p5_0 = p.next();
7898             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7899                 return false;
7900             }
7901             if ( p.hasNext() ) {
7902                 return false;
7903             }
7904             if ( p.next() != null ) {
7905                 return false;
7906             }
7907             //
7908             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7909             p.setSource( p6_str );
7910             if ( !p.hasNext() ) {
7911                 return false;
7912             }
7913             Phylogeny p6_0 = p.next();
7914             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7915                 return false;
7916             }
7917             if ( p.hasNext() ) {
7918                 return false;
7919             }
7920             if ( p.next() != null ) {
7921                 return false;
7922             }
7923             p.reset();
7924             if ( !p.hasNext() ) {
7925                 return false;
7926             }
7927             p6_0 = p.next();
7928             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7929                 return false;
7930             }
7931             if ( p.hasNext() ) {
7932                 return false;
7933             }
7934             if ( p.next() != null ) {
7935                 return false;
7936             }
7937             //
7938             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7939             p.setSource( p7_str );
7940             if ( !p.hasNext() ) {
7941                 return false;
7942             }
7943             Phylogeny p7_0 = p.next();
7944             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7945                 return false;
7946             }
7947             if ( p.hasNext() ) {
7948                 return false;
7949             }
7950             if ( p.next() != null ) {
7951                 return false;
7952             }
7953             p.reset();
7954             if ( !p.hasNext() ) {
7955                 return false;
7956             }
7957             p7_0 = p.next();
7958             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7959                 return false;
7960             }
7961             if ( p.hasNext() ) {
7962                 return false;
7963             }
7964             if ( p.next() != null ) {
7965                 return false;
7966             }
7967             //
7968             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7969             p.setSource( p8_str );
7970             if ( !p.hasNext() ) {
7971                 return false;
7972             }
7973             Phylogeny p8_0 = p.next();
7974             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7975                 return false;
7976             }
7977             if ( !p.hasNext() ) {
7978                 return false;
7979             }
7980             if ( !p.hasNext() ) {
7981                 return false;
7982             }
7983             Phylogeny p8_1 = p.next();
7984             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7985                 return false;
7986             }
7987             if ( p.hasNext() ) {
7988                 return false;
7989             }
7990             if ( p.next() != null ) {
7991                 return false;
7992             }
7993             p.reset();
7994             if ( !p.hasNext() ) {
7995                 return false;
7996             }
7997             p8_0 = p.next();
7998             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7999                 return false;
8000             }
8001             if ( !p.hasNext() ) {
8002                 return false;
8003             }
8004             p8_1 = p.next();
8005             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8006                 return false;
8007             }
8008             if ( p.hasNext() ) {
8009                 return false;
8010             }
8011             if ( p.next() != null ) {
8012                 return false;
8013             }
8014             p.reset();
8015             //
8016             p.setSource( "" );
8017             if ( p.hasNext() ) {
8018                 return false;
8019             }
8020             //
8021             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8022             if ( !p.hasNext() ) {
8023                 return false;
8024             }
8025             Phylogeny p_27 = p.next();
8026             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8027                 System.out.println( p_27.toNewHampshireX() );
8028                 System.exit( -1 );
8029                 return false;
8030             }
8031             if ( p.hasNext() ) {
8032                 return false;
8033             }
8034             if ( p.next() != null ) {
8035                 return false;
8036             }
8037             p.reset();
8038             if ( !p.hasNext() ) {
8039                 return false;
8040             }
8041             p_27 = p.next();
8042             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8043                 System.out.println( p_27.toNewHampshireX() );
8044                 System.exit( -1 );
8045                 return false;
8046             }
8047             if ( p.hasNext() ) {
8048                 return false;
8049             }
8050             if ( p.next() != null ) {
8051                 return false;
8052             }
8053             //
8054             final String p30_str = "(A,B);(C,D)";
8055             final NHXParser p30 = new NHXParser();
8056             p30.setSource( p30_str );
8057             if ( !p30.hasNext() ) {
8058                 return false;
8059             }
8060             Phylogeny phy30 = p30.next();
8061             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8062                 System.out.println( phy30.toNewHampshire() );
8063                 return false;
8064             }
8065             if ( !p30.hasNext() ) {
8066                 return false;
8067             }
8068             Phylogeny phy301 = p30.next();
8069             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8070                 System.out.println( phy301.toNewHampshire() );
8071                 return false;
8072             }
8073             if ( p30.hasNext() ) {
8074                 return false;
8075             }
8076             if ( p30.hasNext() ) {
8077                 return false;
8078             }
8079             if ( p30.next() != null ) {
8080                 return false;
8081             }
8082             if ( p30.next() != null ) {
8083                 return false;
8084             }
8085             p30.reset();
8086             if ( !p30.hasNext() ) {
8087                 return false;
8088             }
8089             phy30 = p30.next();
8090             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8091                 System.out.println( phy30.toNewHampshire() );
8092                 return false;
8093             }
8094             if ( !p30.hasNext() ) {
8095                 return false;
8096             }
8097             phy301 = p30.next();
8098             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8099                 System.out.println( phy301.toNewHampshire() );
8100                 return false;
8101             }
8102             if ( p30.hasNext() ) {
8103                 return false;
8104             }
8105             if ( p30.hasNext() ) {
8106                 return false;
8107             }
8108             if ( p30.next() != null ) {
8109                 return false;
8110             }
8111             if ( p30.next() != null ) {
8112                 return false;
8113             }
8114         }
8115         catch ( final Exception e ) {
8116             e.printStackTrace( System.out );
8117             return false;
8118         }
8119         return true;
8120     }
8121
8122     private static boolean testNHXconversion() {
8123         try {
8124             final PhylogenyNode n1 = new PhylogenyNode();
8125             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8126             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8127             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8128             final PhylogenyNode n5 = PhylogenyNode
8129                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8130             final PhylogenyNode n6 = PhylogenyNode
8131                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8132             if ( !n1.toNewHampshireX().equals( "" ) ) {
8133                 return false;
8134             }
8135             if ( !n2.toNewHampshireX().equals( "" ) ) {
8136                 return false;
8137             }
8138             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8139                 return false;
8140             }
8141             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8142                 return false;
8143             }
8144             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8145                 return false;
8146             }
8147             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8148                 System.out.println( n6.toNewHampshireX() );
8149                 return false;
8150             }
8151         }
8152         catch ( final Exception e ) {
8153             e.printStackTrace( System.out );
8154             return false;
8155         }
8156         return true;
8157     }
8158
8159     private static boolean testNHXNodeParsing() {
8160         try {
8161             final PhylogenyNode n1 = new PhylogenyNode();
8162             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8163             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8164             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8165             final PhylogenyNode n5 = PhylogenyNode
8166                     .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]" );
8167             if ( !n3.getName().equals( "n3" ) ) {
8168                 return false;
8169             }
8170             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8171                 return false;
8172             }
8173             if ( n3.isDuplication() ) {
8174                 return false;
8175             }
8176             if ( n3.isHasAssignedEvent() ) {
8177                 return false;
8178             }
8179             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8180                 return false;
8181             }
8182             if ( !n4.getName().equals( "n4" ) ) {
8183                 return false;
8184             }
8185             if ( n4.getDistanceToParent() != 0.01 ) {
8186                 return false;
8187             }
8188             if ( !n5.getName().equals( "n5" ) ) {
8189                 return false;
8190             }
8191             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8192                 return false;
8193             }
8194             if ( n5.getDistanceToParent() != 0.1 ) {
8195                 return false;
8196             }
8197             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8198                 return false;
8199             }
8200             if ( !n5.isDuplication() ) {
8201                 return false;
8202             }
8203             if ( !n5.isHasAssignedEvent() ) {
8204                 return false;
8205             }
8206             final PhylogenyNode n8 = PhylogenyNode
8207                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8208                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8209             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8210                 return false;
8211             }
8212             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8213                 return false;
8214             }
8215             final PhylogenyNode n9 = PhylogenyNode
8216                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8217                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8218             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8219                 return false;
8220             }
8221             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8222                 return false;
8223             }
8224             final PhylogenyNode n10 = PhylogenyNode
8225                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8226             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8227                 return false;
8228             }
8229             final PhylogenyNode n20 = PhylogenyNode
8230                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8231             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8232                 return false;
8233             }
8234             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8235                 return false;
8236             }
8237             final PhylogenyNode n20x = PhylogenyNode
8238                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8239             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8240                 return false;
8241             }
8242             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8243                 return false;
8244             }
8245             final PhylogenyNode n20xx = PhylogenyNode
8246                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8247             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8248                 return false;
8249             }
8250             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8251                 return false;
8252             }
8253             final PhylogenyNode n20xxx = PhylogenyNode
8254                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8255             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8256                 return false;
8257             }
8258             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8259                 return false;
8260             }
8261             final PhylogenyNode n20xxxx = PhylogenyNode
8262                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8263             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8264                 return false;
8265             }
8266             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8267                 return false;
8268             }
8269             final PhylogenyNode n21 = PhylogenyNode
8270                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8271             if ( !n21.getName().equals( "N21_PIG" ) ) {
8272                 return false;
8273             }
8274             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8275                 return false;
8276             }
8277             final PhylogenyNode n21x = PhylogenyNode
8278                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8279             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8280                 return false;
8281             }
8282             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8283                 return false;
8284             }
8285             final PhylogenyNode n22 = PhylogenyNode
8286                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8287             if ( !n22.getName().equals( "n22/PIG" ) ) {
8288                 return false;
8289             }
8290             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8291                 return false;
8292             }
8293             final PhylogenyNode n23 = PhylogenyNode
8294                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8295             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8296                 return false;
8297             }
8298             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8299                 return false;
8300             }
8301             final PhylogenyNode a = PhylogenyNode
8302                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8303             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8304                 return false;
8305             }
8306             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8307                 return false;
8308             }
8309             final PhylogenyNode c1 = PhylogenyNode
8310                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8311                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8312             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8313                 return false;
8314             }
8315             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8316                 return false;
8317             }
8318             final PhylogenyNode c2 = PhylogenyNode
8319                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8320                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8321             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8322                 return false;
8323             }
8324             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
8325                 return false;
8326             }
8327             final PhylogenyNode e3 = PhylogenyNode
8328                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8329             if ( !e3.getName().equals( "n10_RAT~" ) ) {
8330                 return false;
8331             }
8332             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
8333                 return false;
8334             }
8335             final PhylogenyNode n11 = PhylogenyNode
8336                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
8337                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8338             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
8339                 return false;
8340             }
8341             if ( n11.getDistanceToParent() != 0.4 ) {
8342                 return false;
8343             }
8344             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
8345                 return false;
8346             }
8347             final PhylogenyNode n12 = PhylogenyNode
8348                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
8349                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8350             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
8351                 return false;
8352             }
8353             if ( n12.getDistanceToParent() != 0.4 ) {
8354                 return false;
8355             }
8356             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
8357                 return false;
8358             }
8359             final PhylogenyNode o = PhylogenyNode
8360                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8361             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
8362                 return false;
8363             }
8364             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
8365                 return false;
8366             }
8367             if ( n1.getName().compareTo( "" ) != 0 ) {
8368                 return false;
8369             }
8370             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8371                 return false;
8372             }
8373             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8374                 return false;
8375             }
8376             if ( n2.getName().compareTo( "" ) != 0 ) {
8377                 return false;
8378             }
8379             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8380                 return false;
8381             }
8382             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8383                 return false;
8384             }
8385             final PhylogenyNode n00 = PhylogenyNode
8386                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
8387             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
8388                 return false;
8389             }
8390             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
8391                 return false;
8392             }
8393             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
8394             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
8395                 return false;
8396             }
8397             final PhylogenyNode n13 = PhylogenyNode
8398                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8399             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
8400                 return false;
8401             }
8402             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
8403                 return false;
8404             }
8405             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8406                 return false;
8407             }
8408             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8409                 return false;
8410             }
8411             final PhylogenyNode n14 = PhylogenyNode
8412                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8413             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
8414                 return false;
8415             }
8416             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
8417                 return false;
8418             }
8419             final PhylogenyNode n15 = PhylogenyNode
8420                     .createInstanceFromNhxString( "something_wicked[123]",
8421                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8422             if ( !n15.getName().equals( "something_wicked" ) ) {
8423                 return false;
8424             }
8425             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
8426                 return false;
8427             }
8428             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
8429                 return false;
8430             }
8431             final PhylogenyNode n16 = PhylogenyNode
8432                     .createInstanceFromNhxString( "something_wicked2[9]",
8433                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8434             if ( !n16.getName().equals( "something_wicked2" ) ) {
8435                 return false;
8436             }
8437             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
8438                 return false;
8439             }
8440             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
8441                 return false;
8442             }
8443             final PhylogenyNode n17 = PhylogenyNode
8444                     .createInstanceFromNhxString( "something_wicked3[a]",
8445                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8446             if ( !n17.getName().equals( "something_wicked3" ) ) {
8447                 return false;
8448             }
8449             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
8450                 return false;
8451             }
8452             final PhylogenyNode n18 = PhylogenyNode
8453                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8454             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8455                 return false;
8456             }
8457             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8458                 return false;
8459             }
8460             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8461                 return false;
8462             }
8463             final PhylogenyNode n19 = PhylogenyNode
8464                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8465             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
8466                 return false;
8467             }
8468             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8469                 return false;
8470             }
8471             final PhylogenyNode n30 = PhylogenyNode
8472                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
8473                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8474             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
8475                 return false;
8476             }
8477             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8478                 return false;
8479             }
8480             final PhylogenyNode n31 = PhylogenyNode
8481                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
8482                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8483             if ( n31.getNodeData().isHasTaxonomy() ) {
8484                 return false;
8485             }
8486             final PhylogenyNode n32 = PhylogenyNode
8487                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8488             if ( n32.getNodeData().isHasTaxonomy() ) {
8489                 return false;
8490             }
8491             final PhylogenyNode n40 = PhylogenyNode
8492                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8493             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8494                 return false;
8495             }
8496             final PhylogenyNode n41 = PhylogenyNode
8497                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8498             if ( n41.getNodeData().isHasTaxonomy() ) {
8499                 return false;
8500             }
8501             final PhylogenyNode n42 = PhylogenyNode
8502                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8503             if ( n42.getNodeData().isHasTaxonomy() ) {
8504                 return false;
8505             }
8506             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
8507                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
8508             if ( n43.getNodeData().isHasTaxonomy() ) {
8509                 return false;
8510             }
8511             final PhylogenyNode n44 = PhylogenyNode
8512                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8513             if ( n44.getNodeData().isHasTaxonomy() ) {
8514                 return false;
8515             }
8516         }
8517         catch ( final Exception e ) {
8518             e.printStackTrace( System.out );
8519             return false;
8520         }
8521         return true;
8522     }
8523
8524     private static boolean testNHXParsing() {
8525         try {
8526             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8527             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
8528             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
8529                 return false;
8530             }
8531             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]";
8532             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
8533             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8534                 return false;
8535             }
8536             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]";
8537             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
8538             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
8539                 return false;
8540             }
8541             final Phylogeny[] p3 = factory
8542                     .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]",
8543                              new NHXParser() );
8544             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8545                 return false;
8546             }
8547             final Phylogeny[] p4 = factory
8548                     .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(]",
8549                              new NHXParser() );
8550             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8551                 return false;
8552             }
8553             final Phylogeny[] p5 = factory
8554                     .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(((]",
8555                              new NHXParser() );
8556             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8557                 return false;
8558             }
8559             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)";
8560             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)";
8561             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
8562             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
8563                 return false;
8564             }
8565             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)))";
8566             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)))";
8567             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
8568             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
8569                 return false;
8570             }
8571             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])   ))[,,, ])))))))";
8572             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
8573             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
8574             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
8575                 return false;
8576             }
8577             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
8578             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8579                 return false;
8580             }
8581             final Phylogeny p10 = factory
8582                     .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]",
8583                              new NHXParser() )[ 0 ];
8584             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8585                 return false;
8586             }
8587         }
8588         catch ( final Exception e ) {
8589             e.printStackTrace( System.out );
8590             return false;
8591         }
8592         return true;
8593     }
8594
8595     private static boolean testNHXParsingMB() {
8596         try {
8597             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8598             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
8599                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8600                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8601                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8602                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8603                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8604                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8605                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8606                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
8607             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
8608                 return false;
8609             }
8610             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
8611                 return false;
8612             }
8613             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8614                            0.1100000000000000e+00 ) ) {
8615                 return false;
8616             }
8617             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8618                 return false;
8619             }
8620             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8621                 return false;
8622             }
8623             final Phylogeny p2 = factory
8624                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8625                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8626                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8627                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8628                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8629                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8630                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8631                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8632                                      + "7.369400000000000e-02}])",
8633                              new NHXParser() )[ 0 ];
8634             if ( p2.getNode( "1" ) == null ) {
8635                 return false;
8636             }
8637             if ( p2.getNode( "2" ) == null ) {
8638                 return false;
8639             }
8640         }
8641         catch ( final Exception e ) {
8642             e.printStackTrace( System.out );
8643             System.exit( -1 );
8644             return false;
8645         }
8646         return true;
8647     }
8648
8649     private static boolean testNHXParsingQuotes() {
8650         try {
8651             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8652             final NHXParser p = new NHXParser();
8653             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8654             if ( phylogenies_0.length != 5 ) {
8655                 return false;
8656             }
8657             final Phylogeny phy = phylogenies_0[ 4 ];
8658             if ( phy.getNumberOfExternalNodes() != 7 ) {
8659                 return false;
8660             }
8661             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8662                 return false;
8663             }
8664             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8665                 return false;
8666             }
8667             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8668                     .getScientificName().equals( "hsapiens" ) ) {
8669                 return false;
8670             }
8671             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8672                 return false;
8673             }
8674             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8675                 return false;
8676             }
8677             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8678                 return false;
8679             }
8680             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8681                 return false;
8682             }
8683             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8684                 return false;
8685             }
8686             final NHXParser p1p = new NHXParser();
8687             p1p.setIgnoreQuotes( true );
8688             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8689             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8690                 return false;
8691             }
8692             final NHXParser p2p = new NHXParser();
8693             p1p.setIgnoreQuotes( false );
8694             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8695             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8696                 return false;
8697             }
8698             final NHXParser p3p = new NHXParser();
8699             p3p.setIgnoreQuotes( false );
8700             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8701             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8702                 return false;
8703             }
8704             final NHXParser p4p = new NHXParser();
8705             p4p.setIgnoreQuotes( false );
8706             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8707             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8708                 return false;
8709             }
8710             final Phylogeny p10 = factory
8711                     .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]",
8712                              new NHXParser() )[ 0 ];
8713             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]";
8714             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8715                 return false;
8716             }
8717             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8718             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8719                 return false;
8720             }
8721             //
8722             final Phylogeny p12 = factory
8723                     .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]",
8724                              new NHXParser() )[ 0 ];
8725             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]";
8726             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8727                 return false;
8728             }
8729             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8730             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8731                 return false;
8732             }
8733             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;";
8734             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8735                 return false;
8736             }
8737             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8738             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8739                 return false;
8740             }
8741         }
8742         catch ( final Exception e ) {
8743             e.printStackTrace( System.out );
8744             return false;
8745         }
8746         return true;
8747     }
8748
8749     private static boolean testNodeRemoval() {
8750         try {
8751             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8752             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8753             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8754             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8755                 return false;
8756             }
8757             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8758             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8759             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8760                 return false;
8761             }
8762             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8763             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8764             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8765                 return false;
8766             }
8767         }
8768         catch ( final Exception e ) {
8769             e.printStackTrace( System.out );
8770             return false;
8771         }
8772         return true;
8773     }
8774
8775     private static boolean testPhylogenyBranch() {
8776         try {
8777             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8778             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8779             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8780             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8781             if ( !a1b1.equals( a1b1 ) ) {
8782                 return false;
8783             }
8784             if ( !a1b1.equals( b1a1 ) ) {
8785                 return false;
8786             }
8787             if ( !b1a1.equals( a1b1 ) ) {
8788                 return false;
8789             }
8790             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8791             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8792             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8793             if ( a1_b1.equals( b1_a1 ) ) {
8794                 return false;
8795             }
8796             if ( a1_b1.equals( a1_b1_ ) ) {
8797                 return false;
8798             }
8799             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8800             if ( !a1_b1.equals( b1_a1_ ) ) {
8801                 return false;
8802             }
8803             if ( a1_b1_.equals( b1_a1_ ) ) {
8804                 return false;
8805             }
8806             if ( !a1_b1_.equals( b1_a1 ) ) {
8807                 return false;
8808             }
8809         }
8810         catch ( final Exception e ) {
8811             e.printStackTrace( System.out );
8812             return false;
8813         }
8814         return true;
8815     }
8816
8817     private static boolean testPhyloXMLparsingOfDistributionElement() {
8818         try {
8819             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8820             PhyloXmlParser xml_parser = null;
8821             try {
8822                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8823             }
8824             catch ( final Exception e ) {
8825                 // Do nothing -- means were not running from jar.
8826             }
8827             if ( xml_parser == null ) {
8828                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
8829                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8830                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8831                 }
8832                 else {
8833                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8834                 }
8835             }
8836             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8837                                                               xml_parser );
8838             if ( xml_parser.getErrorCount() > 0 ) {
8839                 System.out.println( xml_parser.getErrorMessages().toString() );
8840                 return false;
8841             }
8842             if ( phylogenies_0.length != 1 ) {
8843                 return false;
8844             }
8845             final Phylogeny t1 = phylogenies_0[ 0 ];
8846             PhylogenyNode n = null;
8847             Distribution d = null;
8848             n = t1.getNode( "root node" );
8849             if ( !n.getNodeData().isHasDistribution() ) {
8850                 return false;
8851             }
8852             if ( n.getNodeData().getDistributions().size() != 1 ) {
8853                 return false;
8854             }
8855             d = n.getNodeData().getDistribution();
8856             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8857                 return false;
8858             }
8859             if ( d.getPoints().size() != 1 ) {
8860                 return false;
8861             }
8862             if ( d.getPolygons() != null ) {
8863                 return false;
8864             }
8865             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8866                 return false;
8867             }
8868             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8869                 return false;
8870             }
8871             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8872                 return false;
8873             }
8874             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8875                 return false;
8876             }
8877             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8878                 return false;
8879             }
8880             n = t1.getNode( "node a" );
8881             if ( !n.getNodeData().isHasDistribution() ) {
8882                 return false;
8883             }
8884             if ( n.getNodeData().getDistributions().size() != 2 ) {
8885                 return false;
8886             }
8887             d = n.getNodeData().getDistribution( 1 );
8888             if ( !d.getDesc().equals( "San Diego" ) ) {
8889                 return false;
8890             }
8891             if ( d.getPoints().size() != 1 ) {
8892                 return false;
8893             }
8894             if ( d.getPolygons() != null ) {
8895                 return false;
8896             }
8897             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8898                 return false;
8899             }
8900             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8901                 return false;
8902             }
8903             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8904                 return false;
8905             }
8906             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8907                 return false;
8908             }
8909             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8910                 return false;
8911             }
8912             n = t1.getNode( "node bb" );
8913             if ( !n.getNodeData().isHasDistribution() ) {
8914                 return false;
8915             }
8916             if ( n.getNodeData().getDistributions().size() != 1 ) {
8917                 return false;
8918             }
8919             d = n.getNodeData().getDistribution( 0 );
8920             if ( d.getPoints().size() != 3 ) {
8921                 return false;
8922             }
8923             if ( d.getPolygons().size() != 2 ) {
8924                 return false;
8925             }
8926             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8927                 return false;
8928             }
8929             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8930                 return false;
8931             }
8932             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8933                 return false;
8934             }
8935             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8936                 return false;
8937             }
8938             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8939                 return false;
8940             }
8941             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8942                 return false;
8943             }
8944             Polygon p = d.getPolygons().get( 0 );
8945             if ( p.getPoints().size() != 3 ) {
8946                 return false;
8947             }
8948             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8949                 return false;
8950             }
8951             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8952                 return false;
8953             }
8954             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8955                 return false;
8956             }
8957             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8958                 return false;
8959             }
8960             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8961                 return false;
8962             }
8963             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8964                 return false;
8965             }
8966             p = d.getPolygons().get( 1 );
8967             if ( p.getPoints().size() != 3 ) {
8968                 return false;
8969             }
8970             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8971                 return false;
8972             }
8973             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8974                 return false;
8975             }
8976             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8977                 return false;
8978             }
8979             // Roundtrip:
8980             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
8981             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
8982             if ( rt.length != 1 ) {
8983                 return false;
8984             }
8985             final Phylogeny t1_rt = rt[ 0 ];
8986             n = t1_rt.getNode( "root node" );
8987             if ( !n.getNodeData().isHasDistribution() ) {
8988                 return false;
8989             }
8990             if ( n.getNodeData().getDistributions().size() != 1 ) {
8991                 return false;
8992             }
8993             d = n.getNodeData().getDistribution();
8994             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8995                 return false;
8996             }
8997             if ( d.getPoints().size() != 1 ) {
8998                 return false;
8999             }
9000             if ( d.getPolygons() != null ) {
9001                 return false;
9002             }
9003             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9004                 return false;
9005             }
9006             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9007                 return false;
9008             }
9009             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9010                 return false;
9011             }
9012             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9013                 return false;
9014             }
9015             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9016                 return false;
9017             }
9018             n = t1_rt.getNode( "node a" );
9019             if ( !n.getNodeData().isHasDistribution() ) {
9020                 return false;
9021             }
9022             if ( n.getNodeData().getDistributions().size() != 2 ) {
9023                 return false;
9024             }
9025             d = n.getNodeData().getDistribution( 1 );
9026             if ( !d.getDesc().equals( "San Diego" ) ) {
9027                 return false;
9028             }
9029             if ( d.getPoints().size() != 1 ) {
9030                 return false;
9031             }
9032             if ( d.getPolygons() != null ) {
9033                 return false;
9034             }
9035             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9036                 return false;
9037             }
9038             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9039                 return false;
9040             }
9041             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9042                 return false;
9043             }
9044             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9045                 return false;
9046             }
9047             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9048                 return false;
9049             }
9050             n = t1_rt.getNode( "node bb" );
9051             if ( !n.getNodeData().isHasDistribution() ) {
9052                 return false;
9053             }
9054             if ( n.getNodeData().getDistributions().size() != 1 ) {
9055                 return false;
9056             }
9057             d = n.getNodeData().getDistribution( 0 );
9058             if ( d.getPoints().size() != 3 ) {
9059                 return false;
9060             }
9061             if ( d.getPolygons().size() != 2 ) {
9062                 return false;
9063             }
9064             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9065                 return false;
9066             }
9067             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9068                 return false;
9069             }
9070             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9071                 return false;
9072             }
9073             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9074                 return false;
9075             }
9076             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9077                 return false;
9078             }
9079             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9080                 return false;
9081             }
9082             p = d.getPolygons().get( 0 );
9083             if ( p.getPoints().size() != 3 ) {
9084                 return false;
9085             }
9086             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9087                 return false;
9088             }
9089             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9090                 return false;
9091             }
9092             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9093                 return false;
9094             }
9095             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9096                 return false;
9097             }
9098             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9099                 return false;
9100             }
9101             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9102                 return false;
9103             }
9104             p = d.getPolygons().get( 1 );
9105             if ( p.getPoints().size() != 3 ) {
9106                 return false;
9107             }
9108             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9109                 return false;
9110             }
9111             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9112                 return false;
9113             }
9114             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9115                 return false;
9116             }
9117         }
9118         catch ( final Exception e ) {
9119             e.printStackTrace( System.out );
9120             return false;
9121         }
9122         return true;
9123     }
9124
9125     private static boolean testPostOrderIterator() {
9126         try {
9127             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9128             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9129             PhylogenyNodeIterator it0;
9130             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9131                 it0.next();
9132             }
9133             for( it0.reset(); it0.hasNext(); ) {
9134                 it0.next();
9135             }
9136             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9137             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9138             if ( !it.next().getName().equals( "A" ) ) {
9139                 return false;
9140             }
9141             if ( !it.next().getName().equals( "B" ) ) {
9142                 return false;
9143             }
9144             if ( !it.next().getName().equals( "ab" ) ) {
9145                 return false;
9146             }
9147             if ( !it.next().getName().equals( "C" ) ) {
9148                 return false;
9149             }
9150             if ( !it.next().getName().equals( "D" ) ) {
9151                 return false;
9152             }
9153             if ( !it.next().getName().equals( "cd" ) ) {
9154                 return false;
9155             }
9156             if ( !it.next().getName().equals( "abcd" ) ) {
9157                 return false;
9158             }
9159             if ( !it.next().getName().equals( "E" ) ) {
9160                 return false;
9161             }
9162             if ( !it.next().getName().equals( "F" ) ) {
9163                 return false;
9164             }
9165             if ( !it.next().getName().equals( "ef" ) ) {
9166                 return false;
9167             }
9168             if ( !it.next().getName().equals( "G" ) ) {
9169                 return false;
9170             }
9171             if ( !it.next().getName().equals( "H" ) ) {
9172                 return false;
9173             }
9174             if ( !it.next().getName().equals( "gh" ) ) {
9175                 return false;
9176             }
9177             if ( !it.next().getName().equals( "efgh" ) ) {
9178                 return false;
9179             }
9180             if ( !it.next().getName().equals( "r" ) ) {
9181                 return false;
9182             }
9183             if ( it.hasNext() ) {
9184                 return false;
9185             }
9186         }
9187         catch ( final Exception e ) {
9188             e.printStackTrace( System.out );
9189             return false;
9190         }
9191         return true;
9192     }
9193
9194     private static boolean testPreOrderIterator() {
9195         try {
9196             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9197             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9198             PhylogenyNodeIterator it0;
9199             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9200                 it0.next();
9201             }
9202             for( it0.reset(); it0.hasNext(); ) {
9203                 it0.next();
9204             }
9205             PhylogenyNodeIterator it = t0.iteratorPreorder();
9206             if ( !it.next().getName().equals( "r" ) ) {
9207                 return false;
9208             }
9209             if ( !it.next().getName().equals( "ab" ) ) {
9210                 return false;
9211             }
9212             if ( !it.next().getName().equals( "A" ) ) {
9213                 return false;
9214             }
9215             if ( !it.next().getName().equals( "B" ) ) {
9216                 return false;
9217             }
9218             if ( !it.next().getName().equals( "cd" ) ) {
9219                 return false;
9220             }
9221             if ( !it.next().getName().equals( "C" ) ) {
9222                 return false;
9223             }
9224             if ( !it.next().getName().equals( "D" ) ) {
9225                 return false;
9226             }
9227             if ( it.hasNext() ) {
9228                 return false;
9229             }
9230             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9231             it = t1.iteratorPreorder();
9232             if ( !it.next().getName().equals( "r" ) ) {
9233                 return false;
9234             }
9235             if ( !it.next().getName().equals( "abcd" ) ) {
9236                 return false;
9237             }
9238             if ( !it.next().getName().equals( "ab" ) ) {
9239                 return false;
9240             }
9241             if ( !it.next().getName().equals( "A" ) ) {
9242                 return false;
9243             }
9244             if ( !it.next().getName().equals( "B" ) ) {
9245                 return false;
9246             }
9247             if ( !it.next().getName().equals( "cd" ) ) {
9248                 return false;
9249             }
9250             if ( !it.next().getName().equals( "C" ) ) {
9251                 return false;
9252             }
9253             if ( !it.next().getName().equals( "D" ) ) {
9254                 return false;
9255             }
9256             if ( !it.next().getName().equals( "efgh" ) ) {
9257                 return false;
9258             }
9259             if ( !it.next().getName().equals( "ef" ) ) {
9260                 return false;
9261             }
9262             if ( !it.next().getName().equals( "E" ) ) {
9263                 return false;
9264             }
9265             if ( !it.next().getName().equals( "F" ) ) {
9266                 return false;
9267             }
9268             if ( !it.next().getName().equals( "gh" ) ) {
9269                 return false;
9270             }
9271             if ( !it.next().getName().equals( "G" ) ) {
9272                 return false;
9273             }
9274             if ( !it.next().getName().equals( "H" ) ) {
9275                 return false;
9276             }
9277             if ( it.hasNext() ) {
9278                 return false;
9279             }
9280         }
9281         catch ( final Exception e ) {
9282             e.printStackTrace( System.out );
9283             return false;
9284         }
9285         return true;
9286     }
9287
9288     private static boolean testPropertiesMap() {
9289         try {
9290             final PropertiesMap pm = new PropertiesMap();
9291             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9292             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9293             final Property p2 = new Property( "something:else",
9294                                               "?",
9295                                               "improbable:research",
9296                                               "xsd:decimal",
9297                                               AppliesTo.NODE );
9298             pm.addProperty( p0 );
9299             pm.addProperty( p1 );
9300             pm.addProperty( p2 );
9301             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9302                 return false;
9303             }
9304             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9305                 return false;
9306             }
9307             if ( pm.getProperties().size() != 3 ) {
9308                 return false;
9309             }
9310             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9311                 return false;
9312             }
9313             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9314                 return false;
9315             }
9316             if ( pm.getProperties().size() != 3 ) {
9317                 return false;
9318             }
9319             pm.removeProperty( "dimensions:diameter" );
9320             if ( pm.getProperties().size() != 2 ) {
9321                 return false;
9322             }
9323             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
9324                 return false;
9325             }
9326             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9327                 return false;
9328             }
9329         }
9330         catch ( final Exception e ) {
9331             e.printStackTrace( System.out );
9332             return false;
9333         }
9334         return true;
9335     }
9336
9337     private static boolean testProteinId() {
9338         try {
9339             final ProteinId id1 = new ProteinId( "a" );
9340             final ProteinId id2 = new ProteinId( "a" );
9341             final ProteinId id3 = new ProteinId( "A" );
9342             final ProteinId id4 = new ProteinId( "b" );
9343             if ( !id1.equals( id1 ) ) {
9344                 return false;
9345             }
9346             if ( id1.getId().equals( "x" ) ) {
9347                 return false;
9348             }
9349             if ( id1.getId().equals( null ) ) {
9350                 return false;
9351             }
9352             if ( !id1.equals( id2 ) ) {
9353                 return false;
9354             }
9355             if ( id1.equals( id3 ) ) {
9356                 return false;
9357             }
9358             if ( id1.hashCode() != id1.hashCode() ) {
9359                 return false;
9360             }
9361             if ( id1.hashCode() != id2.hashCode() ) {
9362                 return false;
9363             }
9364             if ( id1.hashCode() == id3.hashCode() ) {
9365                 return false;
9366             }
9367             if ( id1.compareTo( id1 ) != 0 ) {
9368                 return false;
9369             }
9370             if ( id1.compareTo( id2 ) != 0 ) {
9371                 return false;
9372             }
9373             if ( id1.compareTo( id3 ) != 0 ) {
9374                 return false;
9375             }
9376             if ( id1.compareTo( id4 ) >= 0 ) {
9377                 return false;
9378             }
9379             if ( id4.compareTo( id1 ) <= 0 ) {
9380                 return false;
9381             }
9382             if ( !id4.getId().equals( "b" ) ) {
9383                 return false;
9384             }
9385             final ProteinId id5 = new ProteinId( " C " );
9386             if ( !id5.getId().equals( "C" ) ) {
9387                 return false;
9388             }
9389             if ( id5.equals( id1 ) ) {
9390                 return false;
9391             }
9392         }
9393         catch ( final Exception e ) {
9394             e.printStackTrace( System.out );
9395             return false;
9396         }
9397         return true;
9398     }
9399
9400     private static boolean testReIdMethods() {
9401         try {
9402             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9403             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
9404             final long count = PhylogenyNode.getNodeCount();
9405             p.levelOrderReID();
9406             if ( p.getNode( "r" ).getId() != count ) {
9407                 return false;
9408             }
9409             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
9410                 return false;
9411             }
9412             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
9413                 return false;
9414             }
9415             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
9416                 return false;
9417             }
9418             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
9419                 return false;
9420             }
9421             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
9422                 return false;
9423             }
9424             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
9425                 return false;
9426             }
9427             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
9428                 return false;
9429             }
9430             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
9431                 return false;
9432             }
9433             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
9434                 return false;
9435             }
9436             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
9437                 return false;
9438             }
9439             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
9440                 return false;
9441             }
9442             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
9443                 return false;
9444             }
9445             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
9446                 return false;
9447             }
9448             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
9449                 return false;
9450             }
9451         }
9452         catch ( final Exception e ) {
9453             e.printStackTrace( System.out );
9454             return false;
9455         }
9456         return true;
9457     }
9458
9459     private static boolean testRerooting() {
9460         try {
9461             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9462             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",
9463                                                  new NHXParser() )[ 0 ];
9464             if ( !t1.isRooted() ) {
9465                 return false;
9466             }
9467             t1.reRoot( t1.getNode( "D" ) );
9468             t1.reRoot( t1.getNode( "CD" ) );
9469             t1.reRoot( t1.getNode( "A" ) );
9470             t1.reRoot( t1.getNode( "B" ) );
9471             t1.reRoot( t1.getNode( "AB" ) );
9472             t1.reRoot( t1.getNode( "D" ) );
9473             t1.reRoot( t1.getNode( "C" ) );
9474             t1.reRoot( t1.getNode( "CD" ) );
9475             t1.reRoot( t1.getNode( "A" ) );
9476             t1.reRoot( t1.getNode( "B" ) );
9477             t1.reRoot( t1.getNode( "AB" ) );
9478             t1.reRoot( t1.getNode( "D" ) );
9479             t1.reRoot( t1.getNode( "D" ) );
9480             t1.reRoot( t1.getNode( "C" ) );
9481             t1.reRoot( t1.getNode( "A" ) );
9482             t1.reRoot( t1.getNode( "B" ) );
9483             t1.reRoot( t1.getNode( "AB" ) );
9484             t1.reRoot( t1.getNode( "C" ) );
9485             t1.reRoot( t1.getNode( "D" ) );
9486             t1.reRoot( t1.getNode( "CD" ) );
9487             t1.reRoot( t1.getNode( "D" ) );
9488             t1.reRoot( t1.getNode( "A" ) );
9489             t1.reRoot( t1.getNode( "B" ) );
9490             t1.reRoot( t1.getNode( "AB" ) );
9491             t1.reRoot( t1.getNode( "C" ) );
9492             t1.reRoot( t1.getNode( "D" ) );
9493             t1.reRoot( t1.getNode( "CD" ) );
9494             t1.reRoot( t1.getNode( "D" ) );
9495             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
9496                 return false;
9497             }
9498             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
9499                 return false;
9500             }
9501             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
9502                 return false;
9503             }
9504             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
9505                 return false;
9506             }
9507             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
9508                 return false;
9509             }
9510             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
9511                 return false;
9512             }
9513             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",
9514                                                  new NHXParser() )[ 0 ];
9515             t2.reRoot( t2.getNode( "A" ) );
9516             t2.reRoot( t2.getNode( "D" ) );
9517             t2.reRoot( t2.getNode( "ABC" ) );
9518             t2.reRoot( t2.getNode( "A" ) );
9519             t2.reRoot( t2.getNode( "B" ) );
9520             t2.reRoot( t2.getNode( "D" ) );
9521             t2.reRoot( t2.getNode( "C" ) );
9522             t2.reRoot( t2.getNode( "ABC" ) );
9523             t2.reRoot( t2.getNode( "A" ) );
9524             t2.reRoot( t2.getNode( "B" ) );
9525             t2.reRoot( t2.getNode( "AB" ) );
9526             t2.reRoot( t2.getNode( "AB" ) );
9527             t2.reRoot( t2.getNode( "D" ) );
9528             t2.reRoot( t2.getNode( "C" ) );
9529             t2.reRoot( t2.getNode( "B" ) );
9530             t2.reRoot( t2.getNode( "AB" ) );
9531             t2.reRoot( t2.getNode( "D" ) );
9532             t2.reRoot( t2.getNode( "D" ) );
9533             t2.reRoot( t2.getNode( "ABC" ) );
9534             t2.reRoot( t2.getNode( "A" ) );
9535             t2.reRoot( t2.getNode( "B" ) );
9536             t2.reRoot( t2.getNode( "AB" ) );
9537             t2.reRoot( t2.getNode( "D" ) );
9538             t2.reRoot( t2.getNode( "C" ) );
9539             t2.reRoot( t2.getNode( "ABC" ) );
9540             t2.reRoot( t2.getNode( "A" ) );
9541             t2.reRoot( t2.getNode( "B" ) );
9542             t2.reRoot( t2.getNode( "AB" ) );
9543             t2.reRoot( t2.getNode( "D" ) );
9544             t2.reRoot( t2.getNode( "D" ) );
9545             t2.reRoot( t2.getNode( "C" ) );
9546             t2.reRoot( t2.getNode( "A" ) );
9547             t2.reRoot( t2.getNode( "B" ) );
9548             t2.reRoot( t2.getNode( "AB" ) );
9549             t2.reRoot( t2.getNode( "C" ) );
9550             t2.reRoot( t2.getNode( "D" ) );
9551             t2.reRoot( t2.getNode( "ABC" ) );
9552             t2.reRoot( t2.getNode( "D" ) );
9553             t2.reRoot( t2.getNode( "A" ) );
9554             t2.reRoot( t2.getNode( "B" ) );
9555             t2.reRoot( t2.getNode( "AB" ) );
9556             t2.reRoot( t2.getNode( "C" ) );
9557             t2.reRoot( t2.getNode( "D" ) );
9558             t2.reRoot( t2.getNode( "ABC" ) );
9559             t2.reRoot( t2.getNode( "D" ) );
9560             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9561                 return false;
9562             }
9563             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9564                 return false;
9565             }
9566             t2.reRoot( t2.getNode( "ABC" ) );
9567             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9568                 return false;
9569             }
9570             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9571                 return false;
9572             }
9573             t2.reRoot( t2.getNode( "AB" ) );
9574             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9575                 return false;
9576             }
9577             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9578                 return false;
9579             }
9580             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9581                 return false;
9582             }
9583             t2.reRoot( t2.getNode( "AB" ) );
9584             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9585                 return false;
9586             }
9587             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9588                 return false;
9589             }
9590             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9591                 return false;
9592             }
9593             t2.reRoot( t2.getNode( "D" ) );
9594             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9595                 return false;
9596             }
9597             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9598                 return false;
9599             }
9600             t2.reRoot( t2.getNode( "ABC" ) );
9601             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9602                 return false;
9603             }
9604             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9605                 return false;
9606             }
9607             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
9608                                                  new NHXParser() )[ 0 ];
9609             t3.reRoot( t3.getNode( "B" ) );
9610             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9611                 return false;
9612             }
9613             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9614                 return false;
9615             }
9616             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9617                 return false;
9618             }
9619             t3.reRoot( t3.getNode( "B" ) );
9620             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9621                 return false;
9622             }
9623             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9624                 return false;
9625             }
9626             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9627                 return false;
9628             }
9629             t3.reRoot( t3.getRoot() );
9630             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9631                 return false;
9632             }
9633             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9634                 return false;
9635             }
9636             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9637                 return false;
9638             }
9639         }
9640         catch ( final Exception e ) {
9641             e.printStackTrace( System.out );
9642             return false;
9643         }
9644         return true;
9645     }
9646
9647     private static boolean testSDIse() {
9648         try {
9649             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9650             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9651             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9652             gene1.setRooted( true );
9653             species1.setRooted( true );
9654             final SDI sdi = new SDI( gene1, species1 );
9655             if ( !gene1.getRoot().isDuplication() ) {
9656                 return false;
9657             }
9658             final Phylogeny species2 = factory
9659                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9660                              new NHXParser() )[ 0 ];
9661             final Phylogeny gene2 = factory
9662                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9663                              new NHXParser() )[ 0 ];
9664             species2.setRooted( true );
9665             gene2.setRooted( true );
9666             final SDI sdi2 = new SDI( gene2, species2 );
9667             if ( sdi2.getDuplicationsSum() != 0 ) {
9668                 return false;
9669             }
9670             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9671                 return false;
9672             }
9673             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9674                 return false;
9675             }
9676             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9677                 return false;
9678             }
9679             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9680                 return false;
9681             }
9682             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9683                 return false;
9684             }
9685             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9686                 return false;
9687             }
9688             final Phylogeny species3 = factory
9689                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9690                              new NHXParser() )[ 0 ];
9691             final Phylogeny gene3 = factory
9692                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9693                              new NHXParser() )[ 0 ];
9694             species3.setRooted( true );
9695             gene3.setRooted( true );
9696             final SDI sdi3 = new SDI( gene3, species3 );
9697             if ( sdi3.getDuplicationsSum() != 1 ) {
9698                 return false;
9699             }
9700             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9701                 return false;
9702             }
9703             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9704                 return false;
9705             }
9706             final Phylogeny species4 = factory
9707                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9708                              new NHXParser() )[ 0 ];
9709             final Phylogeny gene4 = factory
9710                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9711                              new NHXParser() )[ 0 ];
9712             species4.setRooted( true );
9713             gene4.setRooted( true );
9714             final SDI sdi4 = new SDI( gene4, species4 );
9715             if ( sdi4.getDuplicationsSum() != 1 ) {
9716                 return false;
9717             }
9718             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9719                 return false;
9720             }
9721             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9722                 return false;
9723             }
9724             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9725                 return false;
9726             }
9727             if ( species4.getNumberOfExternalNodes() != 6 ) {
9728                 return false;
9729             }
9730             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9731                 return false;
9732             }
9733             final Phylogeny species5 = factory
9734                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9735                              new NHXParser() )[ 0 ];
9736             final Phylogeny gene5 = factory
9737                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9738                              new NHXParser() )[ 0 ];
9739             species5.setRooted( true );
9740             gene5.setRooted( true );
9741             final SDI sdi5 = new SDI( gene5, species5 );
9742             if ( sdi5.getDuplicationsSum() != 2 ) {
9743                 return false;
9744             }
9745             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9746                 return false;
9747             }
9748             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9749                 return false;
9750             }
9751             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9752                 return false;
9753             }
9754             if ( species5.getNumberOfExternalNodes() != 6 ) {
9755                 return false;
9756             }
9757             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9758                 return false;
9759             }
9760             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9761             // Conjecture for Comparing Molecular Phylogenies"
9762             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9763             final Phylogeny species6 = factory
9764                     .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,"
9765                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9766                              new NHXParser() )[ 0 ];
9767             final Phylogeny gene6 = factory
9768                     .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,"
9769                                      + "((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,"
9770                                      + "(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;",
9771                              new NHXParser() )[ 0 ];
9772             species6.setRooted( true );
9773             gene6.setRooted( true );
9774             final SDI sdi6 = new SDI( gene6, species6 );
9775             if ( sdi6.getDuplicationsSum() != 3 ) {
9776                 return false;
9777             }
9778             if ( !gene6.getNode( "r" ).isDuplication() ) {
9779                 return false;
9780             }
9781             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9782                 return false;
9783             }
9784             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9785                 return false;
9786             }
9787             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9788                 return false;
9789             }
9790             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9791                 return false;
9792             }
9793             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9794                 return false;
9795             }
9796             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9797                 return false;
9798             }
9799             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9800                 return false;
9801             }
9802             sdi6.computeMappingCostL();
9803             if ( sdi6.computeMappingCostL() != 17 ) {
9804                 return false;
9805             }
9806             if ( species6.getNumberOfExternalNodes() != 9 ) {
9807                 return false;
9808             }
9809             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9810                 return false;
9811             }
9812             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9813                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9814                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9815                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9816                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9817             species7.setRooted( true );
9818             final Phylogeny gene7_1 = Test
9819                     .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])" );
9820             gene7_1.setRooted( true );
9821             final SDI sdi7 = new SDI( gene7_1, species7 );
9822             if ( sdi7.getDuplicationsSum() != 0 ) {
9823                 return false;
9824             }
9825             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9826                 return false;
9827             }
9828             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9829                 return false;
9830             }
9831             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9832                 return false;
9833             }
9834             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9835                 return false;
9836             }
9837             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9838                 return false;
9839             }
9840             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9841                 return false;
9842             }
9843             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9844                 return false;
9845             }
9846             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9847                 return false;
9848             }
9849             final Phylogeny gene7_2 = Test
9850                     .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])" );
9851             gene7_2.setRooted( true );
9852             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9853             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9854                 return false;
9855             }
9856             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9857                 return false;
9858             }
9859             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9860                 return false;
9861             }
9862             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9863                 return false;
9864             }
9865             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9866                 return false;
9867             }
9868             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9869                 return false;
9870             }
9871             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9872                 return false;
9873             }
9874             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9875                 return false;
9876             }
9877             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9878                 return false;
9879             }
9880             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9881                 return false;
9882             }
9883         }
9884         catch ( final Exception e ) {
9885             return false;
9886         }
9887         return true;
9888     }
9889
9890     private static boolean testSDIunrooted() {
9891         try {
9892             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9893             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9894             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9895             final Iterator<PhylogenyBranch> iter = l.iterator();
9896             PhylogenyBranch br = iter.next();
9897             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9898                 return false;
9899             }
9900             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9901                 return false;
9902             }
9903             br = iter.next();
9904             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9905                 return false;
9906             }
9907             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9908                 return false;
9909             }
9910             br = iter.next();
9911             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9912                 return false;
9913             }
9914             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9915                 return false;
9916             }
9917             br = iter.next();
9918             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9919                 return false;
9920             }
9921             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9922                 return false;
9923             }
9924             br = iter.next();
9925             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9926                 return false;
9927             }
9928             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9929                 return false;
9930             }
9931             br = iter.next();
9932             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9933                 return false;
9934             }
9935             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9936                 return false;
9937             }
9938             br = iter.next();
9939             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9940                 return false;
9941             }
9942             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9943                 return false;
9944             }
9945             br = iter.next();
9946             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9947                 return false;
9948             }
9949             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9950                 return false;
9951             }
9952             br = iter.next();
9953             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9954                 return false;
9955             }
9956             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9957                 return false;
9958             }
9959             br = iter.next();
9960             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9961                 return false;
9962             }
9963             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9964                 return false;
9965             }
9966             br = iter.next();
9967             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9968                 return false;
9969             }
9970             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9971                 return false;
9972             }
9973             br = iter.next();
9974             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
9975                 return false;
9976             }
9977             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
9978                 return false;
9979             }
9980             br = iter.next();
9981             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9982                 return false;
9983             }
9984             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9985                 return false;
9986             }
9987             br = iter.next();
9988             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
9989                 return false;
9990             }
9991             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
9992                 return false;
9993             }
9994             br = iter.next();
9995             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
9996                 return false;
9997             }
9998             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
9999                 return false;
10000             }
10001             if ( iter.hasNext() ) {
10002                 return false;
10003             }
10004             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10005             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10006             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10007             br = iter1.next();
10008             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10009                 return false;
10010             }
10011             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10012                 return false;
10013             }
10014             br = iter1.next();
10015             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10016                 return false;
10017             }
10018             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10019                 return false;
10020             }
10021             br = iter1.next();
10022             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10023                 return false;
10024             }
10025             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10026                 return false;
10027             }
10028             if ( iter1.hasNext() ) {
10029                 return false;
10030             }
10031             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10032             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10033             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10034             br = iter2.next();
10035             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10036                 return false;
10037             }
10038             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10039                 return false;
10040             }
10041             br = iter2.next();
10042             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10043                 return false;
10044             }
10045             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10046                 return false;
10047             }
10048             br = iter2.next();
10049             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10050                 return false;
10051             }
10052             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10053                 return false;
10054             }
10055             if ( iter2.hasNext() ) {
10056                 return false;
10057             }
10058             final Phylogeny species0 = factory
10059                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10060                              new NHXParser() )[ 0 ];
10061             final Phylogeny gene1 = factory
10062                     .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])",
10063                              new NHXParser() )[ 0 ];
10064             species0.setRooted( true );
10065             gene1.setRooted( true );
10066             final SDIR sdi_unrooted = new SDIR();
10067             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10068             if ( sdi_unrooted.getCount() != 1 ) {
10069                 return false;
10070             }
10071             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10072                 return false;
10073             }
10074             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10075                 return false;
10076             }
10077             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10078                 return false;
10079             }
10080             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10081                 return false;
10082             }
10083             final Phylogeny gene2 = factory
10084                     .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])",
10085                              new NHXParser() )[ 0 ];
10086             gene2.setRooted( true );
10087             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10088             if ( sdi_unrooted.getCount() != 1 ) {
10089                 return false;
10090             }
10091             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10092                 return false;
10093             }
10094             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10095                 return false;
10096             }
10097             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10098                 return false;
10099             }
10100             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10101                 return false;
10102             }
10103             final Phylogeny species6 = factory
10104                     .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,"
10105                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10106                              new NHXParser() )[ 0 ];
10107             final Phylogeny gene6 = factory
10108                     .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],"
10109                                      + "(((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],"
10110                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10111                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10112                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10113                              new NHXParser() )[ 0 ];
10114             species6.setRooted( true );
10115             gene6.setRooted( true );
10116             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10117             if ( sdi_unrooted.getCount() != 1 ) {
10118                 return false;
10119             }
10120             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10121                 return false;
10122             }
10123             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10124                 return false;
10125             }
10126             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10127                 return false;
10128             }
10129             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10130                 return false;
10131             }
10132             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10133                 return false;
10134             }
10135             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10136                 return false;
10137             }
10138             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10139                 return false;
10140             }
10141             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10142                 return false;
10143             }
10144             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10145                 return false;
10146             }
10147             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10148                 return false;
10149             }
10150             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10151                 return false;
10152             }
10153             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10154                 return false;
10155             }
10156             p6 = null;
10157             final Phylogeny species7 = factory
10158                     .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,"
10159                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10160                              new NHXParser() )[ 0 ];
10161             final Phylogeny gene7 = factory
10162                     .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],"
10163                                      + "(((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],"
10164                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10165                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10166                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10167                              new NHXParser() )[ 0 ];
10168             species7.setRooted( true );
10169             gene7.setRooted( true );
10170             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10171             if ( sdi_unrooted.getCount() != 1 ) {
10172                 return false;
10173             }
10174             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10175                 return false;
10176             }
10177             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10178                 return false;
10179             }
10180             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10181                 return false;
10182             }
10183             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10184                 return false;
10185             }
10186             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10187                 return false;
10188             }
10189             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10190                 return false;
10191             }
10192             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10193                 return false;
10194             }
10195             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10196                 return false;
10197             }
10198             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10199                 return false;
10200             }
10201             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10202                 return false;
10203             }
10204             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10205                 return false;
10206             }
10207             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10208                 return false;
10209             }
10210             p7 = null;
10211             final Phylogeny species8 = factory
10212                     .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,"
10213                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10214                              new NHXParser() )[ 0 ];
10215             final Phylogeny gene8 = factory
10216                     .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],"
10217                                      + "(((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],"
10218                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10219                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10220                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10221                              new NHXParser() )[ 0 ];
10222             species8.setRooted( true );
10223             gene8.setRooted( true );
10224             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10225             if ( sdi_unrooted.getCount() != 1 ) {
10226                 return false;
10227             }
10228             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10229                 return false;
10230             }
10231             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10232                 return false;
10233             }
10234             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10235                 return false;
10236             }
10237             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10238                 return false;
10239             }
10240             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10241                 return false;
10242             }
10243             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10244                 return false;
10245             }
10246             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10247                 return false;
10248             }
10249             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10250                 return false;
10251             }
10252             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10253                 return false;
10254             }
10255             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10256                 return false;
10257             }
10258             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10259                 return false;
10260             }
10261             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10262                 return false;
10263             }
10264             p8 = null;
10265         }
10266         catch ( final Exception e ) {
10267             e.printStackTrace( System.out );
10268             return false;
10269         }
10270         return true;
10271     }
10272
10273     private static boolean testSequenceDbWsTools1() {
10274         try {
10275             final PhylogenyNode n = new PhylogenyNode();
10276             n.setName( "NP_001025424" );
10277             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10278             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10279                     || !acc.getValue().equals( "NP_001025424" ) ) {
10280                 return false;
10281             }
10282             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10283             acc = SequenceDbWsTools.obtainSeqAccession( n );
10284             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10285                     || !acc.getValue().equals( "NP_001025424" ) ) {
10286                 return false;
10287             }
10288             n.setName( "NP_001025424.1" );
10289             acc = SequenceDbWsTools.obtainSeqAccession( n );
10290             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10291                     || !acc.getValue().equals( "NP_001025424" ) ) {
10292                 return false;
10293             }
10294             n.setName( "NM_001030253" );
10295             acc = SequenceDbWsTools.obtainSeqAccession( n );
10296             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10297                     || !acc.getValue().equals( "NM_001030253" ) ) {
10298                 return false;
10299             }
10300             n.setName( "BCL2_HUMAN" );
10301             acc = SequenceDbWsTools.obtainSeqAccession( n );
10302             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10303                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10304                 System.out.println( acc.toString() );
10305                 return false;
10306             }
10307             n.setName( "P10415" );
10308             acc = SequenceDbWsTools.obtainSeqAccession( n );
10309             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10310                     || !acc.getValue().equals( "P10415" ) ) {
10311                 System.out.println( acc.toString() );
10312                 return false;
10313             }
10314             n.setName( " P10415 " );
10315             acc = SequenceDbWsTools.obtainSeqAccession( n );
10316             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10317                     || !acc.getValue().equals( "P10415" ) ) {
10318                 System.out.println( acc.toString() );
10319                 return false;
10320             }
10321             n.setName( "_P10415|" );
10322             acc = SequenceDbWsTools.obtainSeqAccession( n );
10323             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10324                     || !acc.getValue().equals( "P10415" ) ) {
10325                 System.out.println( acc.toString() );
10326                 return false;
10327             }
10328             n.setName( "AY695820" );
10329             acc = SequenceDbWsTools.obtainSeqAccession( n );
10330             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10331                     || !acc.getValue().equals( "AY695820" ) ) {
10332                 System.out.println( acc.toString() );
10333                 return false;
10334             }
10335             n.setName( "_AY695820_" );
10336             acc = SequenceDbWsTools.obtainSeqAccession( n );
10337             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10338                     || !acc.getValue().equals( "AY695820" ) ) {
10339                 System.out.println( acc.toString() );
10340                 return false;
10341             }
10342             n.setName( "AAA59452" );
10343             acc = SequenceDbWsTools.obtainSeqAccession( n );
10344             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10345                     || !acc.getValue().equals( "AAA59452" ) ) {
10346                 System.out.println( acc.toString() );
10347                 return false;
10348             }
10349             n.setName( "_AAA59452_" );
10350             acc = SequenceDbWsTools.obtainSeqAccession( n );
10351             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10352                     || !acc.getValue().equals( "AAA59452" ) ) {
10353                 System.out.println( acc.toString() );
10354                 return false;
10355             }
10356             n.setName( "AAA59452.1" );
10357             acc = SequenceDbWsTools.obtainSeqAccession( n );
10358             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10359                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10360                 System.out.println( acc.toString() );
10361                 return false;
10362             }
10363             n.setName( "_AAA59452.1_" );
10364             acc = SequenceDbWsTools.obtainSeqAccession( n );
10365             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10366                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10367                 System.out.println( acc.toString() );
10368                 return false;
10369             }
10370             n.setName( "GI:94894583" );
10371             acc = SequenceDbWsTools.obtainSeqAccession( n );
10372             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10373                     || !acc.getValue().equals( "94894583" ) ) {
10374                 System.out.println( acc.toString() );
10375                 return false;
10376             }
10377             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10378             acc = SequenceDbWsTools.obtainSeqAccession( n );
10379             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10380                     || !acc.getValue().equals( "71845847" ) ) {
10381                 System.out.println( acc.toString() );
10382                 return false;
10383             }
10384             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10385             acc = SequenceDbWsTools.obtainSeqAccession( n );
10386             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10387                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
10388                 System.out.println( acc.toString() );
10389                 return false;
10390             }
10391         }
10392         catch ( final Exception e ) {
10393             return false;
10394         }
10395         return true;
10396     }
10397
10398     private static boolean testSequenceDbWsTools2() {
10399         try {
10400             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
10401             SequenceDbWsTools.obtainSeqInformation( n1 );
10402             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10403                 return false;
10404             }
10405             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10406                 return false;
10407             }
10408             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10409                 return false;
10410             }
10411             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
10412                 return false;
10413             }
10414             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
10415             SequenceDbWsTools.obtainSeqInformation( n2 );
10416             if ( !n2.getNodeData().getSequence().getName()
10417                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
10418                 return false;
10419             }
10420             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10421                 return false;
10422             }
10423             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10424                 return false;
10425             }
10426             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
10427                 return false;
10428             }
10429             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
10430             SequenceDbWsTools.obtainSeqInformation( n3 );
10431             if ( !n3.getNodeData().getSequence().getName()
10432                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
10433                 return false;
10434             }
10435             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
10436                 return false;
10437             }
10438             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10439                 return false;
10440             }
10441             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
10442                 return false;
10443             }
10444         }
10445         catch ( final IOException e ) {
10446             System.out.println();
10447             System.out.println( "the following might be due to absence internet connection:" );
10448             e.printStackTrace( System.out );
10449             return true;
10450         }
10451         catch ( final Exception e ) {
10452             e.printStackTrace();
10453             return false;
10454         }
10455         return true;
10456     }
10457
10458     private static boolean testSequenceIdParsing() {
10459         try {
10460             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
10461             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10462                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10463                 if ( id != null ) {
10464                     System.out.println( "value   =" + id.getValue() );
10465                     System.out.println( "provider=" + id.getSource() );
10466                 }
10467                 return false;
10468             }
10469             //
10470             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
10471             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10472                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10473                 if ( id != null ) {
10474                     System.out.println( "value   =" + id.getValue() );
10475                     System.out.println( "provider=" + id.getSource() );
10476                 }
10477                 return false;
10478             }
10479             //
10480             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
10481             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10482                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10483                 if ( id != null ) {
10484                     System.out.println( "value   =" + id.getValue() );
10485                     System.out.println( "provider=" + id.getSource() );
10486                 }
10487                 return false;
10488             }
10489             // 
10490             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
10491             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10492                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
10493                 if ( id != null ) {
10494                     System.out.println( "value   =" + id.getValue() );
10495                     System.out.println( "provider=" + id.getSource() );
10496                 }
10497                 return false;
10498             }
10499             // 
10500             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
10501             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10502                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
10503                 if ( id != null ) {
10504                     System.out.println( "value   =" + id.getValue() );
10505                     System.out.println( "provider=" + id.getSource() );
10506                 }
10507                 return false;
10508             }
10509             // 
10510             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
10511             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10512                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
10513                 if ( id != null ) {
10514                     System.out.println( "value   =" + id.getValue() );
10515                     System.out.println( "provider=" + id.getSource() );
10516                 }
10517                 return false;
10518             }
10519             // 
10520             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
10521             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10522                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
10523                 if ( id != null ) {
10524                     System.out.println( "value   =" + id.getValue() );
10525                     System.out.println( "provider=" + id.getSource() );
10526                 }
10527                 return false;
10528             }
10529             // 
10530             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
10531             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10532                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10533                 if ( id != null ) {
10534                     System.out.println( "value   =" + id.getValue() );
10535                     System.out.println( "provider=" + id.getSource() );
10536                 }
10537                 return false;
10538             }
10539             // 
10540             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
10541             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10542                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10543                 if ( id != null ) {
10544                     System.out.println( "value   =" + id.getValue() );
10545                     System.out.println( "provider=" + id.getSource() );
10546                 }
10547                 return false;
10548             }
10549             // 
10550             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
10551             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10552                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
10553                 if ( id != null ) {
10554                     System.out.println( "value   =" + id.getValue() );
10555                     System.out.println( "provider=" + id.getSource() );
10556                 }
10557                 return false;
10558             }
10559             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
10560             if ( id != null ) {
10561                 System.out.println( "value   =" + id.getValue() );
10562                 System.out.println( "provider=" + id.getSource() );
10563                 return false;
10564             }
10565         }
10566         catch ( final Exception e ) {
10567             e.printStackTrace( System.out );
10568             return false;
10569         }
10570         return true;
10571     }
10572
10573     private static boolean testSequenceWriter() {
10574         try {
10575             final String n = ForesterUtil.LINE_SEPARATOR;
10576             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
10577                 return false;
10578             }
10579             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
10580                 return false;
10581             }
10582             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
10583                 return false;
10584             }
10585             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
10586                 return false;
10587             }
10588             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
10589                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
10590                 return false;
10591             }
10592             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
10593                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
10594                 return false;
10595             }
10596         }
10597         catch ( final Exception e ) {
10598             e.printStackTrace();
10599             return false;
10600         }
10601         return true;
10602     }
10603
10604     private static boolean testSpecies() {
10605         try {
10606             final Species s1 = new BasicSpecies( "a" );
10607             final Species s2 = new BasicSpecies( "a" );
10608             final Species s3 = new BasicSpecies( "A" );
10609             final Species s4 = new BasicSpecies( "b" );
10610             if ( !s1.equals( s1 ) ) {
10611                 return false;
10612             }
10613             if ( s1.getSpeciesId().equals( "x" ) ) {
10614                 return false;
10615             }
10616             if ( s1.getSpeciesId().equals( null ) ) {
10617                 return false;
10618             }
10619             if ( !s1.equals( s2 ) ) {
10620                 return false;
10621             }
10622             if ( s1.equals( s3 ) ) {
10623                 return false;
10624             }
10625             if ( s1.hashCode() != s1.hashCode() ) {
10626                 return false;
10627             }
10628             if ( s1.hashCode() != s2.hashCode() ) {
10629                 return false;
10630             }
10631             if ( s1.hashCode() == s3.hashCode() ) {
10632                 return false;
10633             }
10634             if ( s1.compareTo( s1 ) != 0 ) {
10635                 return false;
10636             }
10637             if ( s1.compareTo( s2 ) != 0 ) {
10638                 return false;
10639             }
10640             if ( s1.compareTo( s3 ) != 0 ) {
10641                 return false;
10642             }
10643             if ( s1.compareTo( s4 ) >= 0 ) {
10644                 return false;
10645             }
10646             if ( s4.compareTo( s1 ) <= 0 ) {
10647                 return false;
10648             }
10649             if ( !s4.getSpeciesId().equals( "b" ) ) {
10650                 return false;
10651             }
10652             final Species s5 = new BasicSpecies( " C " );
10653             if ( !s5.getSpeciesId().equals( "C" ) ) {
10654                 return false;
10655             }
10656             if ( s5.equals( s1 ) ) {
10657                 return false;
10658             }
10659         }
10660         catch ( final Exception e ) {
10661             e.printStackTrace( System.out );
10662             return false;
10663         }
10664         return true;
10665     }
10666
10667     private static boolean testSplit() {
10668         try {
10669             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10670             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10671             //Archaeopteryx.createApplication( p0 );
10672             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10673             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10674             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10675             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10676             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10677             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10678             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10679             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10680             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10681             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10682             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
10683             // System.out.println( s0.toString() );
10684             //
10685             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10688             if ( s0.match( query_nodes ) ) {
10689                 return false;
10690             }
10691             query_nodes = new HashSet<PhylogenyNode>();
10692             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10693             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10694             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10695             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10699             if ( !s0.match( query_nodes ) ) {
10700                 return false;
10701             }
10702             //
10703             query_nodes = new HashSet<PhylogenyNode>();
10704             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10705             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10707             if ( !s0.match( query_nodes ) ) {
10708                 return false;
10709             }
10710             //
10711             query_nodes = new HashSet<PhylogenyNode>();
10712             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10713             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10714             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10715             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10716             if ( !s0.match( query_nodes ) ) {
10717                 return false;
10718             }
10719             //
10720             query_nodes = new HashSet<PhylogenyNode>();
10721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10725             if ( !s0.match( query_nodes ) ) {
10726                 return false;
10727             }
10728             //
10729             query_nodes = new HashSet<PhylogenyNode>();
10730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10733             if ( !s0.match( query_nodes ) ) {
10734                 return false;
10735             }
10736             //
10737             query_nodes = new HashSet<PhylogenyNode>();
10738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10740             if ( !s0.match( query_nodes ) ) {
10741                 return false;
10742             }
10743             //
10744             query_nodes = new HashSet<PhylogenyNode>();
10745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10750             if ( !s0.match( query_nodes ) ) {
10751                 return false;
10752             }
10753             //
10754             query_nodes = new HashSet<PhylogenyNode>();
10755             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10756             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10758             if ( !s0.match( query_nodes ) ) {
10759                 return false;
10760             }
10761             //
10762             query_nodes = new HashSet<PhylogenyNode>();
10763             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10764             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10765             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10766             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10767             if ( !s0.match( query_nodes ) ) {
10768                 return false;
10769             }
10770             //
10771             query_nodes = new HashSet<PhylogenyNode>();
10772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10774             if ( s0.match( query_nodes ) ) {
10775                 return false;
10776             }
10777             //
10778             query_nodes = new HashSet<PhylogenyNode>();
10779             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10781             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10782             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10783             if ( s0.match( query_nodes ) ) {
10784                 return false;
10785             }
10786             //
10787             query_nodes = new HashSet<PhylogenyNode>();
10788             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10789             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10790             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10791             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10793             if ( s0.match( query_nodes ) ) {
10794                 return false;
10795             }
10796             //
10797             query_nodes = new HashSet<PhylogenyNode>();
10798             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10799             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10800             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10801             if ( s0.match( query_nodes ) ) {
10802                 return false;
10803             }
10804             //
10805             query_nodes = new HashSet<PhylogenyNode>();
10806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10807             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10808             if ( s0.match( query_nodes ) ) {
10809                 return false;
10810             }
10811             //
10812             query_nodes = new HashSet<PhylogenyNode>();
10813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10815             if ( s0.match( query_nodes ) ) {
10816                 return false;
10817             }
10818             //
10819             query_nodes = new HashSet<PhylogenyNode>();
10820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10822             if ( s0.match( query_nodes ) ) {
10823                 return false;
10824             }
10825             //
10826             query_nodes = new HashSet<PhylogenyNode>();
10827             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
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( "F" ) );
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( "G" ) );
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( "F" ) );
10850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10851             if ( s0.match( query_nodes ) ) {
10852                 return false;
10853             }
10854             //
10855             query_nodes = new HashSet<PhylogenyNode>();
10856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10858             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10859             if ( s0.match( query_nodes ) ) {
10860                 return false;
10861             }
10862             //
10863             query_nodes = new HashSet<PhylogenyNode>();
10864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10867             if ( s0.match( query_nodes ) ) {
10868                 return false;
10869             }
10870             //
10871             query_nodes = new HashSet<PhylogenyNode>();
10872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10874             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10875             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10876             if ( s0.match( query_nodes ) ) {
10877                 return false;
10878             }
10879             /////////
10880             //            query_nodes = new HashSet<PhylogenyNode>();
10881             //            query_nodes.add( new PhylogenyNode( "X" ) );
10882             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10883             //            query_nodes.add( new PhylogenyNode( "A" ) );
10884             //            query_nodes.add( new PhylogenyNode( "B" ) );
10885             //            query_nodes.add( new PhylogenyNode( "C" ) );
10886             //            query_nodes.add( new PhylogenyNode( "D" ) );
10887             //            query_nodes.add( new PhylogenyNode( "E" ) );
10888             //            query_nodes.add( new PhylogenyNode( "F" ) );
10889             //            query_nodes.add( new PhylogenyNode( "G" ) );
10890             //            if ( !s0.match( query_nodes ) ) {
10891             //                return false;
10892             //            }
10893             //            query_nodes = new HashSet<PhylogenyNode>();
10894             //            query_nodes.add( new PhylogenyNode( "X" ) );
10895             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10896             //            query_nodes.add( new PhylogenyNode( "A" ) );
10897             //            query_nodes.add( new PhylogenyNode( "B" ) );
10898             //            query_nodes.add( new PhylogenyNode( "C" ) );
10899             //            if ( !s0.match( query_nodes ) ) {
10900             //                return false;
10901             //            }
10902             //            //
10903             //            query_nodes = new HashSet<PhylogenyNode>();
10904             //            query_nodes.add( new PhylogenyNode( "X" ) );
10905             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10906             //            query_nodes.add( new PhylogenyNode( "D" ) );
10907             //            query_nodes.add( new PhylogenyNode( "E" ) );
10908             //            query_nodes.add( new PhylogenyNode( "F" ) );
10909             //            query_nodes.add( new PhylogenyNode( "G" ) );
10910             //            if ( !s0.match( query_nodes ) ) {
10911             //                return false;
10912             //            }
10913             //            //
10914             //            query_nodes = new HashSet<PhylogenyNode>();
10915             //            query_nodes.add( new PhylogenyNode( "X" ) );
10916             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10917             //            query_nodes.add( new PhylogenyNode( "A" ) );
10918             //            query_nodes.add( new PhylogenyNode( "B" ) );
10919             //            query_nodes.add( new PhylogenyNode( "C" ) );
10920             //            query_nodes.add( new PhylogenyNode( "D" ) );
10921             //            if ( !s0.match( query_nodes ) ) {
10922             //                return false;
10923             //            }
10924             //            //
10925             //            query_nodes = new HashSet<PhylogenyNode>();
10926             //            query_nodes.add( new PhylogenyNode( "X" ) );
10927             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10928             //            query_nodes.add( new PhylogenyNode( "E" ) );
10929             //            query_nodes.add( new PhylogenyNode( "F" ) );
10930             //            query_nodes.add( new PhylogenyNode( "G" ) );
10931             //            if ( !s0.match( query_nodes ) ) {
10932             //                return false;
10933             //            }
10934             //            //
10935             //            query_nodes = new HashSet<PhylogenyNode>();
10936             //            query_nodes.add( new PhylogenyNode( "X" ) );
10937             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10938             //            query_nodes.add( new PhylogenyNode( "F" ) );
10939             //            query_nodes.add( new PhylogenyNode( "G" ) );
10940             //            if ( !s0.match( query_nodes ) ) {
10941             //                return false;
10942             //            }
10943             //
10944             query_nodes = new HashSet<PhylogenyNode>();
10945             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10947             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10949             if ( s0.match( query_nodes ) ) {
10950                 return false;
10951             }
10952             //
10953             query_nodes = new HashSet<PhylogenyNode>();
10954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10958             if ( s0.match( query_nodes ) ) {
10959                 return false;
10960             }
10961             ///////////////////////////
10962             //
10963             query_nodes = new HashSet<PhylogenyNode>();
10964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10967             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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( "A" ) );
10976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
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( "C" ) );
10986             if ( s0.match( query_nodes ) ) {
10987                 return false;
10988             }
10989             //
10990             query_nodes = new HashSet<PhylogenyNode>();
10991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10992             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10995             if ( s0.match( query_nodes ) ) {
10996                 return false;
10997             }
10998             //
10999             query_nodes = new HashSet<PhylogenyNode>();
11000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11004             if ( s0.match( query_nodes ) ) {
11005                 return false;
11006             }
11007             //
11008             query_nodes = new HashSet<PhylogenyNode>();
11009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11012             if ( s0.match( query_nodes ) ) {
11013                 return false;
11014             }
11015             //
11016             query_nodes = new HashSet<PhylogenyNode>();
11017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11018             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11019             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11022             if ( s0.match( query_nodes ) ) {
11023                 return false;
11024             }
11025             //
11026             query_nodes = new HashSet<PhylogenyNode>();
11027             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11032             if ( s0.match( query_nodes ) ) {
11033                 return false;
11034             }
11035             //
11036             query_nodes = new HashSet<PhylogenyNode>();
11037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11041             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11042             if ( s0.match( query_nodes ) ) {
11043                 return false;
11044             }
11045             //
11046             query_nodes = new HashSet<PhylogenyNode>();
11047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11049             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11050             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11051             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11052             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11053             if ( s0.match( query_nodes ) ) {
11054                 return false;
11055             }
11056         }
11057         catch ( final Exception e ) {
11058             e.printStackTrace();
11059             return false;
11060         }
11061         return true;
11062     }
11063
11064     private static boolean testSplitStrict() {
11065         try {
11066             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11067             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11068             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11069             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11070             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11071             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11072             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11073             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11074             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11075             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11076             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11077             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11078             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11079             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11080             if ( s0.match( query_nodes ) ) {
11081                 return false;
11082             }
11083             query_nodes = new HashSet<PhylogenyNode>();
11084             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11085             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11086             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11087             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11089             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11090             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11091             if ( !s0.match( query_nodes ) ) {
11092                 return false;
11093             }
11094             //
11095             query_nodes = new HashSet<PhylogenyNode>();
11096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11098             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11099             if ( !s0.match( query_nodes ) ) {
11100                 return false;
11101             }
11102             //
11103             query_nodes = new HashSet<PhylogenyNode>();
11104             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11105             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11108             if ( !s0.match( query_nodes ) ) {
11109                 return false;
11110             }
11111             //
11112             query_nodes = new HashSet<PhylogenyNode>();
11113             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11115             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11116             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11117             if ( !s0.match( query_nodes ) ) {
11118                 return false;
11119             }
11120             //
11121             query_nodes = new HashSet<PhylogenyNode>();
11122             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11123             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11124             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11125             if ( !s0.match( query_nodes ) ) {
11126                 return false;
11127             }
11128             //
11129             query_nodes = new HashSet<PhylogenyNode>();
11130             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11131             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11132             if ( !s0.match( query_nodes ) ) {
11133                 return false;
11134             }
11135             //
11136             query_nodes = new HashSet<PhylogenyNode>();
11137             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11138             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11139             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11142             if ( !s0.match( query_nodes ) ) {
11143                 return false;
11144             }
11145             //
11146             query_nodes = new HashSet<PhylogenyNode>();
11147             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11148             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11149             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11150             if ( !s0.match( query_nodes ) ) {
11151                 return false;
11152             }
11153             //
11154             query_nodes = new HashSet<PhylogenyNode>();
11155             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11156             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11159             if ( !s0.match( query_nodes ) ) {
11160                 return false;
11161             }
11162             //
11163             query_nodes = new HashSet<PhylogenyNode>();
11164             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11166             if ( s0.match( query_nodes ) ) {
11167                 return false;
11168             }
11169             //
11170             query_nodes = new HashSet<PhylogenyNode>();
11171             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11172             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11173             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11174             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11175             if ( s0.match( query_nodes ) ) {
11176                 return false;
11177             }
11178             //
11179             query_nodes = new HashSet<PhylogenyNode>();
11180             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11181             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11182             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11183             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11184             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11185             if ( s0.match( query_nodes ) ) {
11186                 return false;
11187             }
11188             //
11189             query_nodes = new HashSet<PhylogenyNode>();
11190             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11191             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11192             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11193             if ( s0.match( query_nodes ) ) {
11194                 return false;
11195             }
11196             //
11197             query_nodes = new HashSet<PhylogenyNode>();
11198             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11199             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11200             if ( s0.match( query_nodes ) ) {
11201                 return false;
11202             }
11203             //
11204             query_nodes = new HashSet<PhylogenyNode>();
11205             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11206             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11207             if ( s0.match( query_nodes ) ) {
11208                 return false;
11209             }
11210             //
11211             query_nodes = new HashSet<PhylogenyNode>();
11212             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11213             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11214             if ( s0.match( query_nodes ) ) {
11215                 return false;
11216             }
11217             //
11218             query_nodes = new HashSet<PhylogenyNode>();
11219             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11220             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
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( "F" ) );
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( "G" ) );
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( "F" ) );
11242             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11243             if ( s0.match( query_nodes ) ) {
11244                 return false;
11245             }
11246             //
11247             query_nodes = new HashSet<PhylogenyNode>();
11248             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11249             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11250             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11251             if ( s0.match( query_nodes ) ) {
11252                 return false;
11253             }
11254             //
11255             query_nodes = new HashSet<PhylogenyNode>();
11256             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11257             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11258             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11259             if ( s0.match( query_nodes ) ) {
11260                 return false;
11261             }
11262             //
11263             query_nodes = new HashSet<PhylogenyNode>();
11264             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11265             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11266             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11267             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11268             if ( s0.match( query_nodes ) ) {
11269                 return false;
11270             }
11271         }
11272         catch ( final Exception e ) {
11273             e.printStackTrace();
11274             return false;
11275         }
11276         return true;
11277     }
11278
11279     private static boolean testSubtreeDeletion() {
11280         try {
11281             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11282             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11283             t1.deleteSubtree( t1.getNode( "A" ), false );
11284             if ( t1.getNumberOfExternalNodes() != 5 ) {
11285                 return false;
11286             }
11287             t1.toNewHampshireX();
11288             t1.deleteSubtree( t1.getNode( "E" ), false );
11289             if ( t1.getNumberOfExternalNodes() != 4 ) {
11290                 return false;
11291             }
11292             t1.toNewHampshireX();
11293             t1.deleteSubtree( t1.getNode( "F" ), false );
11294             if ( t1.getNumberOfExternalNodes() != 3 ) {
11295                 return false;
11296             }
11297             t1.toNewHampshireX();
11298             t1.deleteSubtree( t1.getNode( "D" ), false );
11299             t1.toNewHampshireX();
11300             if ( t1.getNumberOfExternalNodes() != 3 ) {
11301                 return false;
11302             }
11303             t1.deleteSubtree( t1.getNode( "def" ), false );
11304             t1.toNewHampshireX();
11305             if ( t1.getNumberOfExternalNodes() != 2 ) {
11306                 return false;
11307             }
11308             t1.deleteSubtree( t1.getNode( "B" ), false );
11309             t1.toNewHampshireX();
11310             if ( t1.getNumberOfExternalNodes() != 1 ) {
11311                 return false;
11312             }
11313             t1.deleteSubtree( t1.getNode( "C" ), false );
11314             t1.toNewHampshireX();
11315             if ( t1.getNumberOfExternalNodes() != 1 ) {
11316                 return false;
11317             }
11318             t1.deleteSubtree( t1.getNode( "abc" ), false );
11319             t1.toNewHampshireX();
11320             if ( t1.getNumberOfExternalNodes() != 1 ) {
11321                 return false;
11322             }
11323             t1.deleteSubtree( t1.getNode( "r" ), false );
11324             if ( t1.getNumberOfExternalNodes() != 0 ) {
11325                 return false;
11326             }
11327             if ( !t1.isEmpty() ) {
11328                 return false;
11329             }
11330             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11331             t2.deleteSubtree( t2.getNode( "A" ), false );
11332             t2.toNewHampshireX();
11333             if ( t2.getNumberOfExternalNodes() != 5 ) {
11334                 return false;
11335             }
11336             t2.deleteSubtree( t2.getNode( "abc" ), false );
11337             t2.toNewHampshireX();
11338             if ( t2.getNumberOfExternalNodes() != 3 ) {
11339                 return false;
11340             }
11341             t2.deleteSubtree( t2.getNode( "def" ), false );
11342             t2.toNewHampshireX();
11343             if ( t2.getNumberOfExternalNodes() != 1 ) {
11344                 return false;
11345             }
11346         }
11347         catch ( final Exception e ) {
11348             e.printStackTrace( System.out );
11349             return false;
11350         }
11351         return true;
11352     }
11353
11354     private static boolean testSupportCount() {
11355         try {
11356             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11357             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
11358             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
11359                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
11360                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
11361                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
11362                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
11363                                                               new NHXParser() );
11364             SupportCount.count( t0_1, phylogenies_1, true, false );
11365             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
11366             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
11367                                                                       + "(((((A,B),C),D),E),((F,G),X))"
11368                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
11369                                                                       + "(((((A,B),C),D),E),(F,G))"
11370                                                                       + "(((((A,B),C),D),E),(F,G))"
11371                                                                       + "(((((A,B),C),D),E),(F,G))"
11372                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
11373                                                                       + "(((((A,B),C),D),E),(F,G))"
11374                                                                       + "((((((A,B),C),D),E),F),G)"
11375                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
11376                                                               new NHXParser() );
11377             SupportCount.count( t0_2, phylogenies_2, true, false );
11378             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
11379             while ( it.hasNext() ) {
11380                 final PhylogenyNode n = it.next();
11381                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
11382                     return false;
11383                 }
11384             }
11385             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
11386             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
11387                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
11388             SupportCount.count( t0_3, phylogenies_3, true, false );
11389             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
11390             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
11391                 return false;
11392             }
11393             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
11394                 return false;
11395             }
11396             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
11397                 return false;
11398             }
11399             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
11400                 return false;
11401             }
11402             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
11403                 return false;
11404             }
11405             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
11406                 return false;
11407             }
11408             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
11409                 return false;
11410             }
11411             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
11412                 return false;
11413             }
11414             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
11415                 return false;
11416             }
11417             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
11418                 return false;
11419             }
11420             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11421             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
11422                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
11423             SupportCount.count( t0_4, phylogenies_4, true, false );
11424             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
11425             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
11426                 return false;
11427             }
11428             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
11429                 return false;
11430             }
11431             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
11432                 return false;
11433             }
11434             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
11435                 return false;
11436             }
11437             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
11438                 return false;
11439             }
11440             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
11441                 return false;
11442             }
11443             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
11444                 return false;
11445             }
11446             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
11447                 return false;
11448             }
11449             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
11450                 return false;
11451             }
11452             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
11453                 return false;
11454             }
11455             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11456             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11457             double d = SupportCount.compare( b1, a, true, true, true );
11458             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
11459                 return false;
11460             }
11461             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11462             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11463             d = SupportCount.compare( b2, a, true, true, true );
11464             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
11465                 return false;
11466             }
11467             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11468             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
11469             d = SupportCount.compare( b3, a, true, true, true );
11470             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
11471                 return false;
11472             }
11473             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
11474             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
11475             d = SupportCount.compare( b4, a, true, true, false );
11476             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
11477                 return false;
11478             }
11479         }
11480         catch ( final Exception e ) {
11481             e.printStackTrace( System.out );
11482             return false;
11483         }
11484         return true;
11485     }
11486
11487     private static boolean testSupportTransfer() {
11488         try {
11489             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11490             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)",
11491                                                  new NHXParser() )[ 0 ];
11492             final Phylogeny p2 = factory
11493                     .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 ];
11494             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
11495                 return false;
11496             }
11497             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
11498                 return false;
11499             }
11500             support_transfer.moveBranchLengthsToBootstrap( p1 );
11501             support_transfer.transferSupportValues( p1, p2 );
11502             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
11503                 return false;
11504             }
11505             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
11506                 return false;
11507             }
11508             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
11509                 return false;
11510             }
11511             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
11512                 return false;
11513             }
11514             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
11515                 return false;
11516             }
11517             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
11518                 return false;
11519             }
11520             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
11521                 return false;
11522             }
11523             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
11524                 return false;
11525             }
11526         }
11527         catch ( final Exception e ) {
11528             e.printStackTrace( System.out );
11529             return false;
11530         }
11531         return true;
11532     }
11533
11534     private static boolean testTaxonomyExtraction() {
11535         try {
11536             final PhylogenyNode n0 = PhylogenyNode
11537                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11538             if ( n0.getNodeData().isHasTaxonomy() ) {
11539                 return false;
11540             }
11541             final PhylogenyNode n1 = PhylogenyNode
11542                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11543             if ( n1.getNodeData().isHasTaxonomy() ) {
11544                 System.out.println( n1.toString() );
11545                 return false;
11546             }
11547             final PhylogenyNode n2x = PhylogenyNode
11548                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11549             if ( n2x.getNodeData().isHasTaxonomy() ) {
11550                 return false;
11551             }
11552             final PhylogenyNode n3 = PhylogenyNode
11553                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11554             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11555                 System.out.println( n3.toString() );
11556                 return false;
11557             }
11558             final PhylogenyNode n4 = PhylogenyNode
11559                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11560             if ( n4.getNodeData().isHasTaxonomy() ) {
11561                 System.out.println( n4.toString() );
11562                 return false;
11563             }
11564             final PhylogenyNode n5 = PhylogenyNode
11565                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11566             if ( n5.getNodeData().isHasTaxonomy() ) {
11567                 System.out.println( n5.toString() );
11568                 return false;
11569             }
11570             final PhylogenyNode n6 = PhylogenyNode
11571                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11572             if ( n6.getNodeData().isHasTaxonomy() ) {
11573                 System.out.println( n6.toString() );
11574                 return false;
11575             }
11576             final PhylogenyNode n7 = PhylogenyNode
11577                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11578             if ( n7.getNodeData().isHasTaxonomy() ) {
11579                 System.out.println( n7.toString() );
11580                 return false;
11581             }
11582             final PhylogenyNode n8 = PhylogenyNode
11583                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11584             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11585                 System.out.println( n8.toString() );
11586                 return false;
11587             }
11588             final PhylogenyNode n9 = PhylogenyNode
11589                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11590             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11591                 System.out.println( n9.toString() );
11592                 return false;
11593             }
11594             final PhylogenyNode n10x = PhylogenyNode
11595                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11596             if ( n10x.getNodeData().isHasTaxonomy() ) {
11597                 System.out.println( n10x.toString() );
11598                 return false;
11599             }
11600             final PhylogenyNode n10xx = PhylogenyNode
11601                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11602             if ( n10xx.getNodeData().isHasTaxonomy() ) {
11603                 System.out.println( n10xx.toString() );
11604                 return false;
11605             }
11606             final PhylogenyNode n10 = PhylogenyNode
11607                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11608             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
11609                 System.out.println( n10.toString() );
11610                 return false;
11611             }
11612             final PhylogenyNode n11 = PhylogenyNode
11613                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11614             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11615                 System.out.println( n11.toString() );
11616                 return false;
11617             }
11618             final PhylogenyNode n12 = PhylogenyNode
11619                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
11620                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11621             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11622                 System.out.println( n12.toString() );
11623                 return false;
11624             }
11625             final PhylogenyNode n13 = PhylogenyNode
11626                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11627             if ( n13.getNodeData().isHasTaxonomy() ) {
11628                 System.out.println( n13.toString() );
11629                 return false;
11630             }
11631         }
11632         catch ( final Exception e ) {
11633             e.printStackTrace( System.out );
11634             return false;
11635         }
11636         return true;
11637     }
11638
11639     private static boolean testTreeCopy() {
11640         try {
11641             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
11642             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
11643             final Phylogeny t1 = t0.copy();
11644             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
11645                 return false;
11646             }
11647             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11648                 return false;
11649             }
11650             t0.deleteSubtree( t0.getNode( "c" ), true );
11651             t0.deleteSubtree( t0.getNode( "a" ), true );
11652             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
11653             t0.getNode( "b" ).setName( "Bee" );
11654             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
11655                 return false;
11656             }
11657             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11658                 return false;
11659             }
11660             t0.deleteSubtree( t0.getNode( "e" ), true );
11661             t0.deleteSubtree( t0.getNode( "Bee" ), true );
11662             t0.deleteSubtree( t0.getNode( "d" ), true );
11663             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11664                 return false;
11665             }
11666         }
11667         catch ( final Exception e ) {
11668             e.printStackTrace();
11669             return false;
11670         }
11671         return true;
11672     }
11673
11674     private static boolean testTreeMethods() {
11675         try {
11676             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11677             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
11678             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
11679             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
11680                 System.out.println( t0.toNewHampshireX() );
11681                 return false;
11682             }
11683             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
11684             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
11685             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
11686                 return false;
11687             }
11688             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
11689                 return false;
11690             }
11691             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
11692                 return false;
11693             }
11694         }
11695         catch ( final Exception e ) {
11696             e.printStackTrace( System.out );
11697             return false;
11698         }
11699         return true;
11700     }
11701
11702     private static boolean testUniprotEntryRetrieval() {
11703         try {
11704             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
11705             if ( !entry.getAccession().equals( "P12345" ) ) {
11706                 return false;
11707             }
11708             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
11709                 return false;
11710             }
11711             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
11712                 return false;
11713             }
11714             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
11715                 return false;
11716             }
11717             if ( !entry.getGeneName().equals( "GOT2" ) ) {
11718                 return false;
11719             }
11720             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
11721                 return false;
11722             }
11723         }
11724         catch ( final IOException e ) {
11725             System.out.println();
11726             System.out.println( "the following might be due to absence internet connection:" );
11727             e.printStackTrace( System.out );
11728             return true;
11729         }
11730         catch ( final Exception e ) {
11731             return false;
11732         }
11733         return true;
11734     }
11735
11736     private static boolean testUniprotTaxonomySearch() {
11737         try {
11738             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
11739                                                                                                  10 );
11740             if ( results.size() != 1 ) {
11741                 return false;
11742             }
11743             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11744                 return false;
11745             }
11746             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11747                 return false;
11748             }
11749             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11750                 return false;
11751             }
11752             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11753                 return false;
11754             }
11755             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11756                 return false;
11757             }
11758             results = null;
11759             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
11760             if ( results.size() != 1 ) {
11761                 return false;
11762             }
11763             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11764                 return false;
11765             }
11766             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11767                 return false;
11768             }
11769             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11770                 return false;
11771             }
11772             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11773                 return false;
11774             }
11775             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11776                 return false;
11777             }
11778             results = null;
11779             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
11780             if ( results.size() != 1 ) {
11781                 return false;
11782             }
11783             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11784                 return false;
11785             }
11786             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11787                 return false;
11788             }
11789             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11790                 return false;
11791             }
11792             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11793                 return false;
11794             }
11795             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11796                 return false;
11797             }
11798             results = null;
11799             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
11800             if ( results.size() != 1 ) {
11801                 return false;
11802             }
11803             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11804                 return false;
11805             }
11806             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11807                 return false;
11808             }
11809             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11810                 return false;
11811             }
11812             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11813                 return false;
11814             }
11815             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11816                 return false;
11817             }
11818             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
11819                 return false;
11820             }
11821             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
11822                 return false;
11823             }
11824             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11825                     .equals( "Nematostella vectensis" ) ) {
11826                 System.out.println( results.get( 0 ).getLineage() );
11827                 return false;
11828             }
11829             //
11830             results = null;
11831             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
11832             if ( results.size() != 1 ) {
11833                 return false;
11834             }
11835             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11836                 return false;
11837             }
11838             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11839                 return false;
11840             }
11841             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11842                 return false;
11843             }
11844             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11845                 return false;
11846             }
11847             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11848                 return false;
11849             }
11850             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11851                     .equals( "Xenopus tropicalis" ) ) {
11852                 System.out.println( results.get( 0 ).getLineage() );
11853                 return false;
11854             }
11855             //
11856             results = null;
11857             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
11858             if ( results.size() != 1 ) {
11859                 return false;
11860             }
11861             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11862                 return false;
11863             }
11864             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11865                 return false;
11866             }
11867             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11868                 return false;
11869             }
11870             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11871                 return false;
11872             }
11873             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11874                 return false;
11875             }
11876             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11877                     .equals( "Xenopus tropicalis" ) ) {
11878                 System.out.println( results.get( 0 ).getLineage() );
11879                 return false;
11880             }
11881             //
11882             results = null;
11883             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
11884             if ( results.size() != 1 ) {
11885                 return false;
11886             }
11887             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11888                 return false;
11889             }
11890             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11891                 return false;
11892             }
11893             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11894                 return false;
11895             }
11896             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11897                 return false;
11898             }
11899             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11900                 return false;
11901             }
11902             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11903                     .equals( "Xenopus tropicalis" ) ) {
11904                 System.out.println( results.get( 0 ).getLineage() );
11905                 return false;
11906             }
11907         }
11908         catch ( final IOException e ) {
11909             System.out.println();
11910             System.out.println( "the following might be due to absence internet connection:" );
11911             e.printStackTrace( System.out );
11912             return true;
11913         }
11914         catch ( final Exception e ) {
11915             return false;
11916         }
11917         return true;
11918     }
11919
11920     private static boolean testWabiTxSearch() {
11921         try {
11922             String result = "";
11923             result = TxSearch.searchSimple( "nematostella" );
11924             result = TxSearch.getTxId( "nematostella" );
11925             if ( !result.equals( "45350" ) ) {
11926                 return false;
11927             }
11928             result = TxSearch.getTxName( "45350" );
11929             if ( !result.equals( "Nematostella" ) ) {
11930                 return false;
11931             }
11932             result = TxSearch.getTxId( "nematostella vectensis" );
11933             if ( !result.equals( "45351" ) ) {
11934                 return false;
11935             }
11936             result = TxSearch.getTxName( "45351" );
11937             if ( !result.equals( "Nematostella vectensis" ) ) {
11938                 return false;
11939             }
11940             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11941             if ( !result.equals( "536089" ) ) {
11942                 return false;
11943             }
11944             result = TxSearch.getTxName( "536089" );
11945             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11946                 return false;
11947             }
11948             final List<String> queries = new ArrayList<String>();
11949             queries.add( "Campylobacter coli" );
11950             queries.add( "Escherichia coli" );
11951             queries.add( "Arabidopsis" );
11952             queries.add( "Trichoplax" );
11953             queries.add( "Samanea saman" );
11954             queries.add( "Kluyveromyces marxianus" );
11955             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11956             queries.add( "Bornavirus parrot/PDD/2008" );
11957             final List<RANKS> ranks = new ArrayList<RANKS>();
11958             ranks.add( RANKS.SUPERKINGDOM );
11959             ranks.add( RANKS.KINGDOM );
11960             ranks.add( RANKS.FAMILY );
11961             ranks.add( RANKS.GENUS );
11962             ranks.add( RANKS.TRIBE );
11963             result = TxSearch.searchLineage( queries, ranks );
11964             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11965             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11966         }
11967         catch ( final Exception e ) {
11968             System.out.println();
11969             System.out.println( "the following might be due to absence internet connection:" );
11970             e.printStackTrace( System.out );
11971             return false;
11972         }
11973         return true;
11974     }
11975 }