729d5b83dbf1184d2614646442a3704f25dbd17d
[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.print( "phyloXML parsing from URL: " );
962         if ( Test.testPhyloXMLparsingFromURL() ) {
963             System.out.println( "OK." );
964             succeeded++;
965         }
966         else {
967             System.out.println( "failed." );
968             failed++;
969         }
970         System.out.println();
971         final Runtime rt = java.lang.Runtime.getRuntime();
972         final long free_memory = rt.freeMemory() / 1000000;
973         final long total_memory = rt.totalMemory() / 1000000;
974         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
975                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
976         System.out.println();
977         System.out.println( "Successful tests: " + succeeded );
978         System.out.println( "Failed     tests: " + failed );
979         System.out.println();
980         if ( failed < 1 ) {
981             System.out.println( "OK." );
982         }
983         else {
984             System.out.println( "Not OK." );
985         }
986     }
987
988     public static boolean testEngulfingOverlapRemoval() {
989         try {
990             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
991             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
992             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
993             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
994             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
995             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
996             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
997             final List<Boolean> covered = new ArrayList<Boolean>();
998             covered.add( true ); // 0
999             covered.add( false ); // 1
1000             covered.add( true ); // 2
1001             covered.add( false ); // 3
1002             covered.add( true ); // 4
1003             covered.add( true ); // 5
1004             covered.add( false ); // 6
1005             covered.add( true ); // 7
1006             covered.add( true ); // 8
1007             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1008                 return false;
1009             }
1010             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1011                 return false;
1012             }
1013             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1014                 return false;
1015             }
1016             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1017                 return false;
1018             }
1019             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1020                 return false;
1021             }
1022             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1023                 return false;
1024             }
1025             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1026                 return false;
1027             }
1028             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1029             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1030             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1031             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1032             abc.addProteinDomain( a );
1033             abc.addProteinDomain( b );
1034             abc.addProteinDomain( c );
1035             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1036             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1037             if ( abc.getNumberOfProteinDomains() != 3 ) {
1038                 return false;
1039             }
1040             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1041                 return false;
1042             }
1043             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1044                 return false;
1045             }
1046             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1047                 return false;
1048             }
1049             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1050                 return false;
1051             }
1052             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1053             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1054             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1055             final Protein def = new BasicProtein( "def", "nemve", 0 );
1056             def.addProteinDomain( d );
1057             def.addProteinDomain( e );
1058             def.addProteinDomain( f );
1059             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1060             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1061             if ( def.getNumberOfProteinDomains() != 3 ) {
1062                 return false;
1063             }
1064             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1065                 return false;
1066             }
1067             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1068                 return false;
1069             }
1070             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1071                 return false;
1072             }
1073             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1074                 return false;
1075             }
1076             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1077                 return false;
1078             }
1079         }
1080         catch ( final Exception e ) {
1081             e.printStackTrace( System.out );
1082             return false;
1083         }
1084         return true;
1085     }
1086
1087     public static final boolean testPhyloXMLparsingFromURL() {
1088         try {
1089             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1090             final URL u = new URL( s );
1091             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1092             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1093             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1094                 return false;
1095             }
1096         }
1097         catch ( final Exception e ) {
1098             e.printStackTrace();
1099         }
1100         return true;
1101     }
1102
1103     public static final boolean testNHXparsingFromURL() {
1104         try {
1105             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1106             final URL u = new URL( s );
1107             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1108             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1109             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1110                 return false;
1111             }
1112             if ( !phys[ 0 ].toNewHampshire().equals( "((a,b),c);" ) ) {
1113                 System.out.println( phys[ 0 ].toNewHampshire() );
1114                 return false;
1115             }
1116             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1117             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
1118                 return false;
1119             }
1120             if ( !phys2[ 0 ].toNewHampshire().equals( "((a,b),c);" ) ) {
1121                 System.out.println( phys2[ 0 ].toNewHampshire() );
1122                 return false;
1123             }
1124             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1125             final NHXParser p = new NHXParser();
1126             final URL u2 = new URL( s );
1127             p.setSource( u2 );
1128             if ( !p.hasNext() ) {
1129                 return false;
1130             }
1131             if ( !p.next().toNewHampshire().equals( "((a,b),c);" ) ) {
1132                 return false;
1133             }
1134             if ( p.hasNext() ) {
1135                 return false;
1136             }
1137             if ( p.next() != null ) {
1138                 return false;
1139             }
1140             if ( p.hasNext() ) {
1141                 return false;
1142             }
1143             if ( p.next() != null ) {
1144                 return false;
1145             }
1146             p.reset();
1147             if ( !p.hasNext() ) {
1148                 return false;
1149             }
1150             if ( !p.next().toNewHampshire().equals( "((a,b),c);" ) ) {
1151                 return false;
1152             }
1153             if ( p.hasNext() ) {
1154                 return false;
1155             }
1156             if ( p.next() != null ) {
1157                 return false;
1158             }
1159             if ( p.hasNext() ) {
1160                 return false;
1161             }
1162             if ( p.next() != null ) {
1163                 return false;
1164             }
1165             p.reset();
1166             if ( !p.hasNext() ) {
1167                 return false;
1168             }
1169         }
1170         catch ( final Exception e ) {
1171             e.printStackTrace();
1172         }
1173         return true;
1174     }
1175
1176     public static boolean testOverlapRemoval() {
1177         try {
1178             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1179             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1180             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1181             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1182             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1183             final List<Boolean> covered = new ArrayList<Boolean>();
1184             covered.add( true ); // 0
1185             covered.add( false ); // 1
1186             covered.add( true ); // 2
1187             covered.add( false ); // 3
1188             covered.add( true ); // 4
1189             covered.add( true ); // 5
1190             covered.add( false ); // 6
1191             covered.add( true ); // 7
1192             covered.add( true ); // 8
1193             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1194                 return false;
1195             }
1196             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1197                 return false;
1198             }
1199             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1200                 return false;
1201             }
1202             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1203                 return false;
1204             }
1205             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1206                 return false;
1207             }
1208             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1209             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1210             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1211             ab.addProteinDomain( a );
1212             ab.addProteinDomain( b );
1213             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1214             if ( ab.getNumberOfProteinDomains() != 2 ) {
1215                 return false;
1216             }
1217             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1218                 return false;
1219             }
1220             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1221                 return false;
1222             }
1223             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1224             if ( ab.getNumberOfProteinDomains() != 2 ) {
1225                 return false;
1226             }
1227             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1228                 return false;
1229             }
1230             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1231             final Domain d = new BasicDomain( "d",
1232                                               ( short ) 10000,
1233                                               ( short ) 10500,
1234                                               ( short ) 1,
1235                                               ( short ) 1,
1236                                               0.0000001,
1237                                               1 );
1238             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1239             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1240             cde.addProteinDomain( c );
1241             cde.addProteinDomain( d );
1242             cde.addProteinDomain( e );
1243             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1244             if ( cde.getNumberOfProteinDomains() != 3 ) {
1245                 return false;
1246             }
1247             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1248                 return false;
1249             }
1250             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1251             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1252             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1253             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1254             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1255             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1256             fghi.addProteinDomain( f );
1257             fghi.addProteinDomain( g );
1258             fghi.addProteinDomain( h );
1259             fghi.addProteinDomain( i );
1260             fghi.addProteinDomain( i );
1261             fghi.addProteinDomain( i );
1262             fghi.addProteinDomain( i2 );
1263             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1264             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1265                 return false;
1266             }
1267             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1268                 return false;
1269             }
1270             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1271                 return false;
1272             }
1273             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1274             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1275                 return false;
1276             }
1277             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1278                 return false;
1279             }
1280             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1281             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1282             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1283             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1284             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1285             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1286             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1287             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1288             jklm.addProteinDomain( j );
1289             jklm.addProteinDomain( k );
1290             jklm.addProteinDomain( l );
1291             jklm.addProteinDomain( m );
1292             jklm.addProteinDomain( m0 );
1293             jklm.addProteinDomain( m1 );
1294             jklm.addProteinDomain( m2 );
1295             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1296             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1297                 return false;
1298             }
1299             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1300                 return false;
1301             }
1302             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1303                 return false;
1304             }
1305             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1306             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1307                 return false;
1308             }
1309             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1310                 return false;
1311             }
1312             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1313             final Protein od = new BasicProtein( "od", "varanus", 0 );
1314             od.addProteinDomain( only );
1315             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1316             if ( od.getNumberOfProteinDomains() != 1 ) {
1317                 return false;
1318             }
1319             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1320                 return false;
1321             }
1322         }
1323         catch ( final Exception e ) {
1324             e.printStackTrace( System.out );
1325             return false;
1326         }
1327         return true;
1328     }
1329
1330     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1331         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1332         return p;
1333     }
1334
1335     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1336         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1337     }
1338
1339     private static boolean testAminoAcidSequence() {
1340         try {
1341             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1342             if ( aa1.getLength() != 13 ) {
1343                 return false;
1344             }
1345             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1346                 return false;
1347             }
1348             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1349                 return false;
1350             }
1351             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1352                 return false;
1353             }
1354             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1355             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1356                 return false;
1357             }
1358             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1359             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1360                 return false;
1361             }
1362             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1363             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1364                 return false;
1365             }
1366         }
1367         catch ( final Exception e ) {
1368             e.printStackTrace();
1369             return false;
1370         }
1371         return true;
1372     }
1373
1374     private static boolean testBasicDomain() {
1375         try {
1376             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1377             if ( !pd.getDomainId().equals( "id" ) ) {
1378                 return false;
1379             }
1380             if ( pd.getNumber() != 1 ) {
1381                 return false;
1382             }
1383             if ( pd.getTotalCount() != 4 ) {
1384                 return false;
1385             }
1386             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1387                 return false;
1388             }
1389             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1390             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1391             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1392             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1393             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1394             if ( !a1.equals( a1 ) ) {
1395                 return false;
1396             }
1397             if ( !a1.equals( a1_copy ) ) {
1398                 return false;
1399             }
1400             if ( !a1.equals( a1_equal ) ) {
1401                 return false;
1402             }
1403             if ( !a1.equals( a2 ) ) {
1404                 return false;
1405             }
1406             if ( a1.equals( a3 ) ) {
1407                 return false;
1408             }
1409             if ( a1.compareTo( a1 ) != 0 ) {
1410                 return false;
1411             }
1412             if ( a1.compareTo( a1_copy ) != 0 ) {
1413                 return false;
1414             }
1415             if ( a1.compareTo( a1_equal ) != 0 ) {
1416                 return false;
1417             }
1418             if ( a1.compareTo( a2 ) != 0 ) {
1419                 return false;
1420             }
1421             if ( a1.compareTo( a3 ) == 0 ) {
1422                 return false;
1423             }
1424         }
1425         catch ( final Exception e ) {
1426             e.printStackTrace( System.out );
1427             return false;
1428         }
1429         return true;
1430     }
1431
1432     private static boolean testBasicNodeMethods() {
1433         try {
1434             if ( PhylogenyNode.getNodeCount() != 0 ) {
1435                 return false;
1436             }
1437             final PhylogenyNode n1 = new PhylogenyNode();
1438             final PhylogenyNode n2 = PhylogenyNode
1439                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1440             final PhylogenyNode n3 = PhylogenyNode
1441                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1442             final PhylogenyNode n4 = PhylogenyNode
1443                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1444             if ( n1.isHasAssignedEvent() ) {
1445                 return false;
1446             }
1447             if ( PhylogenyNode.getNodeCount() != 4 ) {
1448                 return false;
1449             }
1450             if ( n3.getIndicator() != 0 ) {
1451                 return false;
1452             }
1453             if ( n3.getNumberOfExternalNodes() != 1 ) {
1454                 return false;
1455             }
1456             if ( !n3.isExternal() ) {
1457                 return false;
1458             }
1459             if ( !n3.isRoot() ) {
1460                 return false;
1461             }
1462             if ( !n4.getName().equals( "n4" ) ) {
1463                 return false;
1464             }
1465         }
1466         catch ( final Exception e ) {
1467             e.printStackTrace( System.out );
1468             return false;
1469         }
1470         return true;
1471     }
1472
1473     private static boolean testBasicPhyloXMLparsing() {
1474         try {
1475             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1476             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1477             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1478                                                               xml_parser );
1479             if ( xml_parser.getErrorCount() > 0 ) {
1480                 System.out.println( xml_parser.getErrorMessages().toString() );
1481                 return false;
1482             }
1483             if ( phylogenies_0.length != 4 ) {
1484                 return false;
1485             }
1486             final Phylogeny t1 = phylogenies_0[ 0 ];
1487             final Phylogeny t2 = phylogenies_0[ 1 ];
1488             final Phylogeny t3 = phylogenies_0[ 2 ];
1489             final Phylogeny t4 = phylogenies_0[ 3 ];
1490             if ( t1.getNumberOfExternalNodes() != 1 ) {
1491                 return false;
1492             }
1493             if ( !t1.isRooted() ) {
1494                 return false;
1495             }
1496             if ( t1.isRerootable() ) {
1497                 return false;
1498             }
1499             if ( !t1.getType().equals( "gene_tree" ) ) {
1500                 return false;
1501             }
1502             if ( t2.getNumberOfExternalNodes() != 2 ) {
1503                 return false;
1504             }
1505             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1506                 return false;
1507             }
1508             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1509                 return false;
1510             }
1511             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1512                 return false;
1513             }
1514             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1515                 return false;
1516             }
1517             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1518                 return false;
1519             }
1520             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1521                 return false;
1522             }
1523             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1524                     .startsWith( "actgtgggggt" ) ) {
1525                 return false;
1526             }
1527             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1528                     .startsWith( "ctgtgatgcat" ) ) {
1529                 return false;
1530             }
1531             if ( t3.getNumberOfExternalNodes() != 4 ) {
1532                 return false;
1533             }
1534             if ( !t1.getName().equals( "t1" ) ) {
1535                 return false;
1536             }
1537             if ( !t2.getName().equals( "t2" ) ) {
1538                 return false;
1539             }
1540             if ( !t3.getName().equals( "t3" ) ) {
1541                 return false;
1542             }
1543             if ( !t4.getName().equals( "t4" ) ) {
1544                 return false;
1545             }
1546             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1547                 return false;
1548             }
1549             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1550                 return false;
1551             }
1552             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1553                 return false;
1554             }
1555             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1556                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1557                 return false;
1558             }
1559             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1560                 return false;
1561             }
1562             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1563                 return false;
1564             }
1565             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1566                 return false;
1567             }
1568             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1569                     .equals( "apoptosis" ) ) {
1570                 return false;
1571             }
1572             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1573                     .equals( "GO:0006915" ) ) {
1574                 return false;
1575             }
1576             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1577                     .equals( "UniProtKB" ) ) {
1578                 return false;
1579             }
1580             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1581                     .equals( "experimental" ) ) {
1582                 return false;
1583             }
1584             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1585                     .equals( "function" ) ) {
1586                 return false;
1587             }
1588             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1589                     .getValue() != 1 ) {
1590                 return false;
1591             }
1592             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1593                     .getType().equals( "ml" ) ) {
1594                 return false;
1595             }
1596             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1597                     .equals( "apoptosis" ) ) {
1598                 return false;
1599             }
1600             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1601                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1602                 return false;
1603             }
1604             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1605                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1606                 return false;
1607             }
1608             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1609                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1610                 return false;
1611             }
1612             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1613                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1614                 return false;
1615             }
1616             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1617                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1618                 return false;
1619             }
1620             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1621                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1622                 return false;
1623             }
1624             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1625                     .equals( "GO:0005829" ) ) {
1626                 return false;
1627             }
1628             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1629                     .equals( "intracellular organelle" ) ) {
1630                 return false;
1631             }
1632             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1633                 return false;
1634             }
1635             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1636                     .equals( "UniProt link" ) ) ) {
1637                 return false;
1638             }
1639             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1640                 return false;
1641             }
1642             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1643             if ( x.size() != 4 ) {
1644                 return false;
1645             }
1646             int c = 0;
1647             for( final Accession acc : x ) {
1648                 if ( c == 0 ) {
1649                     if ( !acc.getSource().equals( "KEGG" ) ) {
1650                         return false;
1651                     }
1652                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1653                         return false;
1654                     }
1655                 }
1656                 c++;
1657             }
1658         }
1659         catch ( final Exception e ) {
1660             e.printStackTrace( System.out );
1661             return false;
1662         }
1663         return true;
1664     }
1665
1666     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1667         try {
1668             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1669             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1670             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1671                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1672             }
1673             else {
1674                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1675             }
1676             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1677                                                               xml_parser );
1678             if ( xml_parser.getErrorCount() > 0 ) {
1679                 System.out.println( xml_parser.getErrorMessages().toString() );
1680                 return false;
1681             }
1682             if ( phylogenies_0.length != 4 ) {
1683                 return false;
1684             }
1685             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1686             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1687             if ( phylogenies_t1.length != 1 ) {
1688                 return false;
1689             }
1690             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1691             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1692                 return false;
1693             }
1694             if ( !t1_rt.isRooted() ) {
1695                 return false;
1696             }
1697             if ( t1_rt.isRerootable() ) {
1698                 return false;
1699             }
1700             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1701                 return false;
1702             }
1703             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1704             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1705             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1706             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1707                 return false;
1708             }
1709             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1710                 return false;
1711             }
1712             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1713                 return false;
1714             }
1715             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1716                 return false;
1717             }
1718             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1719                     .startsWith( "actgtgggggt" ) ) {
1720                 return false;
1721             }
1722             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1723                     .startsWith( "ctgtgatgcat" ) ) {
1724                 return false;
1725             }
1726             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1727             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1728             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1729             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1730             if ( phylogenies_1.length != 1 ) {
1731                 return false;
1732             }
1733             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1734             if ( !t3_rt.getName().equals( "t3" ) ) {
1735                 return false;
1736             }
1737             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1738                 return false;
1739             }
1740             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1741                 return false;
1742             }
1743             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1744                 return false;
1745             }
1746             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1747                 return false;
1748             }
1749             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1750                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1751                 return false;
1752             }
1753             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1754                 return false;
1755             }
1756             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1757                 return false;
1758             }
1759             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1760                     .equals( "UniProtKB" ) ) {
1761                 return false;
1762             }
1763             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1764                     .equals( "apoptosis" ) ) {
1765                 return false;
1766             }
1767             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1768                     .equals( "GO:0006915" ) ) {
1769                 return false;
1770             }
1771             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1772                     .equals( "UniProtKB" ) ) {
1773                 return false;
1774             }
1775             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1776                     .equals( "experimental" ) ) {
1777                 return false;
1778             }
1779             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1780                     .equals( "function" ) ) {
1781                 return false;
1782             }
1783             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1784                     .getValue() != 1 ) {
1785                 return false;
1786             }
1787             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1788                     .getType().equals( "ml" ) ) {
1789                 return false;
1790             }
1791             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1792                     .equals( "apoptosis" ) ) {
1793                 return false;
1794             }
1795             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1796                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1797                 return false;
1798             }
1799             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1800                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1801                 return false;
1802             }
1803             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1804                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1805                 return false;
1806             }
1807             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1808                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1809                 return false;
1810             }
1811             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1812                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1813                 return false;
1814             }
1815             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1816                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1817                 return false;
1818             }
1819             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1820                     .equals( "GO:0005829" ) ) {
1821                 return false;
1822             }
1823             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1824                     .equals( "intracellular organelle" ) ) {
1825                 return false;
1826             }
1827             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1828                 return false;
1829             }
1830             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1831                     .equals( "UniProt link" ) ) ) {
1832                 return false;
1833             }
1834             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1835                 return false;
1836             }
1837             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1838                 return false;
1839             }
1840             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1841                     .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." ) ) ) {
1842                 return false;
1843             }
1844             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1845                 return false;
1846             }
1847             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1848                 return false;
1849             }
1850             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1851                 return false;
1852             }
1853             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1854                 return false;
1855             }
1856             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1857                     .equals( "ncbi" ) ) {
1858                 return false;
1859             }
1860             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1861                 return false;
1862             }
1863             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1864                     .getName().equals( "B" ) ) {
1865                 return false;
1866             }
1867             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1868                     .getFrom() != 21 ) {
1869                 return false;
1870             }
1871             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1872                 return false;
1873             }
1874             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1875                     .getLength() != 24 ) {
1876                 return false;
1877             }
1878             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1879                     .getConfidence() != 2144 ) {
1880                 return false;
1881             }
1882             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1883                     .equals( "pfam" ) ) {
1884                 return false;
1885             }
1886             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1887                 return false;
1888             }
1889             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1890                 return false;
1891             }
1892             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1893                 return false;
1894             }
1895             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1896                 return false;
1897             }
1898             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1899             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1900                 return false;
1901             }
1902             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1903                 return false;
1904             }
1905             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1906                 return false;
1907             }
1908             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1909                 return false;
1910             }
1911             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1912                 return false;
1913             }
1914             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1915                 return false;
1916             }
1917             if ( taxbb.getSynonyms().size() != 2 ) {
1918                 return false;
1919             }
1920             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1921                 return false;
1922             }
1923             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1924                 return false;
1925             }
1926             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1927                 return false;
1928             }
1929             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1930                 return false;
1931             }
1932             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1933                 return false;
1934             }
1935             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1936                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1937                 return false;
1938             }
1939             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1940                 return false;
1941             }
1942             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1943                 return false;
1944             }
1945             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1946                 return false;
1947             }
1948             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1949                 return false;
1950             }
1951             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1952                 return false;
1953             }
1954             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1955                 return false;
1956             }
1957             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1958                 return false;
1959             }
1960             //
1961             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1962                 return false;
1963             }
1964             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1965                     .equalsIgnoreCase( "435" ) ) {
1966                 return false;
1967             }
1968             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1969                 return false;
1970             }
1971             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1972                     .equalsIgnoreCase( "443.7" ) ) {
1973                 return false;
1974             }
1975             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1976                 return false;
1977             }
1978             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1979                 return false;
1980             }
1981             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1982                     .equalsIgnoreCase( "433" ) ) {
1983                 return false;
1984             }
1985             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
1986                     .getCrossReferences();
1987             if ( x.size() != 4 ) {
1988                 return false;
1989             }
1990             int c = 0;
1991             for( final Accession acc : x ) {
1992                 if ( c == 0 ) {
1993                     if ( !acc.getSource().equals( "KEGG" ) ) {
1994                         return false;
1995                     }
1996                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1997                         return false;
1998                     }
1999                 }
2000                 c++;
2001             }
2002         }
2003         catch ( final Exception e ) {
2004             e.printStackTrace( System.out );
2005             return false;
2006         }
2007         return true;
2008     }
2009
2010     private static boolean testBasicPhyloXMLparsingValidating() {
2011         try {
2012             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2013             PhyloXmlParser xml_parser = null;
2014             try {
2015                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2016             }
2017             catch ( final Exception e ) {
2018                 // Do nothing -- means were not running from jar.
2019             }
2020             if ( xml_parser == null ) {
2021                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2022                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2023                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2024                 }
2025                 else {
2026                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2027                 }
2028             }
2029             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2030                                                               xml_parser );
2031             if ( xml_parser.getErrorCount() > 0 ) {
2032                 System.out.println( xml_parser.getErrorMessages().toString() );
2033                 return false;
2034             }
2035             if ( phylogenies_0.length != 4 ) {
2036                 return false;
2037             }
2038             final Phylogeny t1 = phylogenies_0[ 0 ];
2039             final Phylogeny t2 = phylogenies_0[ 1 ];
2040             final Phylogeny t3 = phylogenies_0[ 2 ];
2041             final Phylogeny t4 = phylogenies_0[ 3 ];
2042             if ( !t1.getName().equals( "t1" ) ) {
2043                 return false;
2044             }
2045             if ( !t2.getName().equals( "t2" ) ) {
2046                 return false;
2047             }
2048             if ( !t3.getName().equals( "t3" ) ) {
2049                 return false;
2050             }
2051             if ( !t4.getName().equals( "t4" ) ) {
2052                 return false;
2053             }
2054             if ( t1.getNumberOfExternalNodes() != 1 ) {
2055                 return false;
2056             }
2057             if ( t2.getNumberOfExternalNodes() != 2 ) {
2058                 return false;
2059             }
2060             if ( t3.getNumberOfExternalNodes() != 4 ) {
2061                 return false;
2062             }
2063             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2064             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2065             if ( xml_parser.getErrorCount() > 0 ) {
2066                 System.out.println( "errors:" );
2067                 System.out.println( xml_parser.getErrorMessages().toString() );
2068                 return false;
2069             }
2070             if ( phylogenies_1.length != 4 ) {
2071                 return false;
2072             }
2073             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2074                                                               xml_parser );
2075             if ( xml_parser.getErrorCount() > 0 ) {
2076                 System.out.println( "errors:" );
2077                 System.out.println( xml_parser.getErrorMessages().toString() );
2078                 return false;
2079             }
2080             if ( phylogenies_2.length != 1 ) {
2081                 return false;
2082             }
2083             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2084                 return false;
2085             }
2086             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2087                                                               xml_parser );
2088             if ( xml_parser.getErrorCount() > 0 ) {
2089                 System.out.println( xml_parser.getErrorMessages().toString() );
2090                 return false;
2091             }
2092             if ( phylogenies_3.length != 2 ) {
2093                 return false;
2094             }
2095             final Phylogeny a = phylogenies_3[ 0 ];
2096             if ( !a.getName().equals( "tree 4" ) ) {
2097                 return false;
2098             }
2099             if ( a.getNumberOfExternalNodes() != 3 ) {
2100                 return false;
2101             }
2102             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2103                 return false;
2104             }
2105             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2106                 return false;
2107             }
2108             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2109                                                               xml_parser );
2110             if ( xml_parser.getErrorCount() > 0 ) {
2111                 System.out.println( xml_parser.getErrorMessages().toString() );
2112                 return false;
2113             }
2114             if ( phylogenies_4.length != 1 ) {
2115                 return false;
2116             }
2117             final Phylogeny s = phylogenies_4[ 0 ];
2118             if ( s.getNumberOfExternalNodes() != 6 ) {
2119                 return false;
2120             }
2121             s.getNode( "first" );
2122             s.getNode( "<>" );
2123             s.getNode( "\"<a'b&c'd\">\"" );
2124             s.getNode( "'''\"" );
2125             s.getNode( "\"\"\"" );
2126             s.getNode( "dick & doof" );
2127         }
2128         catch ( final Exception e ) {
2129             e.printStackTrace( System.out );
2130             return false;
2131         }
2132         return true;
2133     }
2134
2135     private static boolean testBasicProtein() {
2136         try {
2137             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2138             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2139             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2140             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2141             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2142             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2143             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2144             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2145             p0.addProteinDomain( y );
2146             p0.addProteinDomain( e );
2147             p0.addProteinDomain( b );
2148             p0.addProteinDomain( c );
2149             p0.addProteinDomain( d );
2150             p0.addProteinDomain( a );
2151             p0.addProteinDomain( x );
2152             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2153                 return false;
2154             }
2155             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2156                 return false;
2157             }
2158             //
2159             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2160             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2161             aa0.addProteinDomain( a1 );
2162             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2163                 return false;
2164             }
2165             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2166                 return false;
2167             }
2168             //
2169             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2170             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2171             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2172             aa1.addProteinDomain( a11 );
2173             aa1.addProteinDomain( a12 );
2174             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2175                 return false;
2176             }
2177             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2178                 return false;
2179             }
2180             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2181             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2182                 return false;
2183             }
2184             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2185                 return false;
2186             }
2187             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2188                 return false;
2189             }
2190             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2191             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2192                 return false;
2193             }
2194             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2195                 return false;
2196             }
2197             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2198                 return false;
2199             }
2200             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2201                 return false;
2202             }
2203             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2204             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2205                 return false;
2206             }
2207             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2208                 return false;
2209             }
2210             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2211                 return false;
2212             }
2213             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2214                 return false;
2215             }
2216             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2217             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2218                 return false;
2219             }
2220             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2221                 return false;
2222             }
2223             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2224                 return false;
2225             }
2226             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2227                 return false;
2228             }
2229             //
2230             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2231             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2232             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2233             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2234             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2235             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2236             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2237             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2238             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2239             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2240             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2241             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2242             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2243             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2244             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2245             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2246             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2247             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2248             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2249             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2250             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2251             p00.addProteinDomain( y0 );
2252             p00.addProteinDomain( e0 );
2253             p00.addProteinDomain( b0 );
2254             p00.addProteinDomain( c0 );
2255             p00.addProteinDomain( d0 );
2256             p00.addProteinDomain( a0 );
2257             p00.addProteinDomain( x0 );
2258             p00.addProteinDomain( y1 );
2259             p00.addProteinDomain( y2 );
2260             p00.addProteinDomain( y3 );
2261             p00.addProteinDomain( e1 );
2262             p00.addProteinDomain( e2 );
2263             p00.addProteinDomain( e3 );
2264             p00.addProteinDomain( e4 );
2265             p00.addProteinDomain( e5 );
2266             p00.addProteinDomain( z0 );
2267             p00.addProteinDomain( z1 );
2268             p00.addProteinDomain( z2 );
2269             p00.addProteinDomain( zz0 );
2270             p00.addProteinDomain( zz1 );
2271             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2272                 return false;
2273             }
2274             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2275                 return false;
2276             }
2277             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2278                 return false;
2279             }
2280             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2281                 return false;
2282             }
2283             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" ) ) {
2284                 return false;
2285             }
2286             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2287             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2288             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2289             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2290             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2291             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2292             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2293             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2294             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2295             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2296             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2297             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2298             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2299             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2300             p.addProteinDomain( B15 );
2301             p.addProteinDomain( C50 );
2302             p.addProteinDomain( A60 );
2303             p.addProteinDomain( A30 );
2304             p.addProteinDomain( C70 );
2305             p.addProteinDomain( B35 );
2306             p.addProteinDomain( B40 );
2307             p.addProteinDomain( A0 );
2308             p.addProteinDomain( A10 );
2309             p.addProteinDomain( A20 );
2310             p.addProteinDomain( B25 );
2311             p.addProteinDomain( D80 );
2312             List<String> domains_ids = new ArrayList<String>();
2313             domains_ids.add( "A" );
2314             domains_ids.add( "B" );
2315             domains_ids.add( "C" );
2316             if ( !p.contains( domains_ids, false ) ) {
2317                 return false;
2318             }
2319             if ( !p.contains( domains_ids, true ) ) {
2320                 return false;
2321             }
2322             domains_ids.add( "X" );
2323             if ( p.contains( domains_ids, false ) ) {
2324                 return false;
2325             }
2326             if ( p.contains( domains_ids, true ) ) {
2327                 return false;
2328             }
2329             domains_ids = new ArrayList<String>();
2330             domains_ids.add( "A" );
2331             domains_ids.add( "C" );
2332             domains_ids.add( "D" );
2333             if ( !p.contains( domains_ids, false ) ) {
2334                 return false;
2335             }
2336             if ( !p.contains( domains_ids, true ) ) {
2337                 return false;
2338             }
2339             domains_ids = new ArrayList<String>();
2340             domains_ids.add( "A" );
2341             domains_ids.add( "D" );
2342             domains_ids.add( "C" );
2343             if ( !p.contains( domains_ids, false ) ) {
2344                 return false;
2345             }
2346             if ( p.contains( domains_ids, true ) ) {
2347                 return false;
2348             }
2349             domains_ids = new ArrayList<String>();
2350             domains_ids.add( "A" );
2351             domains_ids.add( "A" );
2352             domains_ids.add( "B" );
2353             if ( !p.contains( domains_ids, false ) ) {
2354                 return false;
2355             }
2356             if ( !p.contains( domains_ids, true ) ) {
2357                 return false;
2358             }
2359             domains_ids = new ArrayList<String>();
2360             domains_ids.add( "A" );
2361             domains_ids.add( "A" );
2362             domains_ids.add( "A" );
2363             domains_ids.add( "B" );
2364             domains_ids.add( "B" );
2365             if ( !p.contains( domains_ids, false ) ) {
2366                 return false;
2367             }
2368             if ( !p.contains( domains_ids, true ) ) {
2369                 return false;
2370             }
2371             domains_ids = new ArrayList<String>();
2372             domains_ids.add( "A" );
2373             domains_ids.add( "A" );
2374             domains_ids.add( "B" );
2375             domains_ids.add( "A" );
2376             domains_ids.add( "B" );
2377             domains_ids.add( "B" );
2378             domains_ids.add( "A" );
2379             domains_ids.add( "B" );
2380             domains_ids.add( "C" );
2381             domains_ids.add( "A" );
2382             domains_ids.add( "C" );
2383             domains_ids.add( "D" );
2384             if ( !p.contains( domains_ids, false ) ) {
2385                 return false;
2386             }
2387             if ( p.contains( domains_ids, true ) ) {
2388                 return false;
2389             }
2390         }
2391         catch ( final Exception e ) {
2392             e.printStackTrace( System.out );
2393             return false;
2394         }
2395         return true;
2396     }
2397
2398     private static boolean testBasicTable() {
2399         try {
2400             final BasicTable<String> t0 = new BasicTable<String>();
2401             if ( t0.getNumberOfColumns() != 0 ) {
2402                 return false;
2403             }
2404             if ( t0.getNumberOfRows() != 0 ) {
2405                 return false;
2406             }
2407             t0.setValue( 3, 2, "23" );
2408             t0.setValue( 10, 1, "error" );
2409             t0.setValue( 10, 1, "110" );
2410             t0.setValue( 9, 1, "19" );
2411             t0.setValue( 1, 10, "101" );
2412             t0.setValue( 10, 10, "1010" );
2413             t0.setValue( 100, 10, "10100" );
2414             t0.setValue( 0, 0, "00" );
2415             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2416                 return false;
2417             }
2418             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2419                 return false;
2420             }
2421             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2422                 return false;
2423             }
2424             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2425                 return false;
2426             }
2427             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2428                 return false;
2429             }
2430             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2431                 return false;
2432             }
2433             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2434                 return false;
2435             }
2436             if ( t0.getNumberOfColumns() != 101 ) {
2437                 return false;
2438             }
2439             if ( t0.getNumberOfRows() != 11 ) {
2440                 return false;
2441             }
2442             if ( t0.getValueAsString( 49, 4 ) != null ) {
2443                 return false;
2444             }
2445             final String l = ForesterUtil.getLineSeparator();
2446             final StringBuffer source = new StringBuffer();
2447             source.append( "" + l );
2448             source.append( "# 1 1 1 1 1 1 1 1" + l );
2449             source.append( " 00 01 02 03" + l );
2450             source.append( "   10 11 12 13  " + l );
2451             source.append( "20 21 22 23 " + l );
2452             source.append( "    30  31    32 33" + l );
2453             source.append( "40 41 42 43" + l );
2454             source.append( "  # 1 1 1 1 1 " + l );
2455             source.append( "50 51 52 53 54" + l );
2456             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2457             if ( t1.getNumberOfColumns() != 5 ) {
2458                 return false;
2459             }
2460             if ( t1.getNumberOfRows() != 6 ) {
2461                 return false;
2462             }
2463             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2464                 return false;
2465             }
2466             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2467                 return false;
2468             }
2469             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2470                 return false;
2471             }
2472             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2473                 return false;
2474             }
2475             final StringBuffer source1 = new StringBuffer();
2476             source1.append( "" + l );
2477             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2478             source1.append( " 00; 01 ;02;03" + l );
2479             source1.append( "   10; 11; 12; 13  " + l );
2480             source1.append( "20; 21; 22; 23 " + l );
2481             source1.append( "    30;  31;    32; 33" + l );
2482             source1.append( "40;41;42;43" + l );
2483             source1.append( "  # 1 1 1 1 1 " + l );
2484             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2485             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2486             if ( t2.getNumberOfColumns() != 5 ) {
2487                 return false;
2488             }
2489             if ( t2.getNumberOfRows() != 6 ) {
2490                 return false;
2491             }
2492             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2493                 return false;
2494             }
2495             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2496                 return false;
2497             }
2498             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2499                 return false;
2500             }
2501             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2502                 return false;
2503             }
2504             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2505                 return false;
2506             }
2507             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2508                 return false;
2509             }
2510             final StringBuffer source2 = new StringBuffer();
2511             source2.append( "" + l );
2512             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2513             source2.append( " 00; 01 ;02;03" + l );
2514             source2.append( "   10; 11; 12; 13  " + l );
2515             source2.append( "20; 21; 22; 23 " + l );
2516             source2.append( "                     " + l );
2517             source2.append( "    30;  31;    32; 33" + l );
2518             source2.append( "40;41;42;43" + l );
2519             source2.append( "  comment: 1 1 1 1 1 " + l );
2520             source2.append( ";;;50  ;   52; 53;;54   " + l );
2521             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2522                                                                         ';',
2523                                                                         false,
2524                                                                         false,
2525                                                                         "comment:",
2526                                                                         false );
2527             if ( tl.size() != 2 ) {
2528                 return false;
2529             }
2530             final BasicTable<String> t3 = tl.get( 0 );
2531             final BasicTable<String> t4 = tl.get( 1 );
2532             if ( t3.getNumberOfColumns() != 4 ) {
2533                 return false;
2534             }
2535             if ( t3.getNumberOfRows() != 3 ) {
2536                 return false;
2537             }
2538             if ( t4.getNumberOfColumns() != 4 ) {
2539                 return false;
2540             }
2541             if ( t4.getNumberOfRows() != 3 ) {
2542                 return false;
2543             }
2544             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2545                 return false;
2546             }
2547             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2548                 return false;
2549             }
2550         }
2551         catch ( final Exception e ) {
2552             e.printStackTrace( System.out );
2553             return false;
2554         }
2555         return true;
2556     }
2557
2558     private static boolean testBasicTolXMLparsing() {
2559         try {
2560             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2561             final TolParser parser = new TolParser();
2562             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2563             if ( parser.getErrorCount() > 0 ) {
2564                 System.out.println( parser.getErrorMessages().toString() );
2565                 return false;
2566             }
2567             if ( phylogenies_0.length != 1 ) {
2568                 return false;
2569             }
2570             final Phylogeny t1 = phylogenies_0[ 0 ];
2571             if ( t1.getNumberOfExternalNodes() != 5 ) {
2572                 return false;
2573             }
2574             if ( !t1.isRooted() ) {
2575                 return false;
2576             }
2577             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2578                 return false;
2579             }
2580             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2581                 return false;
2582             }
2583             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2584                 return false;
2585             }
2586             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2587                 return false;
2588             }
2589             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2590             if ( parser.getErrorCount() > 0 ) {
2591                 System.out.println( parser.getErrorMessages().toString() );
2592                 return false;
2593             }
2594             if ( phylogenies_1.length != 1 ) {
2595                 return false;
2596             }
2597             final Phylogeny t2 = phylogenies_1[ 0 ];
2598             if ( t2.getNumberOfExternalNodes() != 664 ) {
2599                 return false;
2600             }
2601             if ( !t2.isRooted() ) {
2602                 return false;
2603             }
2604             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2605                 return false;
2606             }
2607             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2608                 return false;
2609             }
2610             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2611                 return false;
2612             }
2613             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2614                 return false;
2615             }
2616             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2617                 return false;
2618             }
2619             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2620                     .equals( "Aquifex" ) ) {
2621                 return false;
2622             }
2623             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2624             if ( parser.getErrorCount() > 0 ) {
2625                 System.out.println( parser.getErrorMessages().toString() );
2626                 return false;
2627             }
2628             if ( phylogenies_2.length != 1 ) {
2629                 return false;
2630             }
2631             final Phylogeny t3 = phylogenies_2[ 0 ];
2632             if ( t3.getNumberOfExternalNodes() != 184 ) {
2633                 return false;
2634             }
2635             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2636                 return false;
2637             }
2638             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2639                 return false;
2640             }
2641             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2642                 return false;
2643             }
2644             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2645             if ( parser.getErrorCount() > 0 ) {
2646                 System.out.println( parser.getErrorMessages().toString() );
2647                 return false;
2648             }
2649             if ( phylogenies_3.length != 1 ) {
2650                 return false;
2651             }
2652             final Phylogeny t4 = phylogenies_3[ 0 ];
2653             if ( t4.getNumberOfExternalNodes() != 1 ) {
2654                 return false;
2655             }
2656             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2657                 return false;
2658             }
2659             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2660                 return false;
2661             }
2662             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2663                 return false;
2664             }
2665             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2666             if ( parser.getErrorCount() > 0 ) {
2667                 System.out.println( parser.getErrorMessages().toString() );
2668                 return false;
2669             }
2670             if ( phylogenies_4.length != 1 ) {
2671                 return false;
2672             }
2673             final Phylogeny t5 = phylogenies_4[ 0 ];
2674             if ( t5.getNumberOfExternalNodes() != 13 ) {
2675                 return false;
2676             }
2677             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2678                 return false;
2679             }
2680             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2681                 return false;
2682             }
2683             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2684                 return false;
2685             }
2686         }
2687         catch ( final Exception e ) {
2688             e.printStackTrace( System.out );
2689             return false;
2690         }
2691         return true;
2692     }
2693
2694     private static boolean testBasicTreeMethods() {
2695         try {
2696             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2697             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2698             if ( t2.getNumberOfExternalNodes() != 4 ) {
2699                 return false;
2700             }
2701             if ( t2.getHeight() != 8.5 ) {
2702                 return false;
2703             }
2704             if ( !t2.isCompletelyBinary() ) {
2705                 return false;
2706             }
2707             if ( t2.isEmpty() ) {
2708                 return false;
2709             }
2710             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2711             if ( t3.getNumberOfExternalNodes() != 5 ) {
2712                 return false;
2713             }
2714             if ( t3.getHeight() != 11 ) {
2715                 return false;
2716             }
2717             if ( t3.isCompletelyBinary() ) {
2718                 return false;
2719             }
2720             final PhylogenyNode n = t3.getNode( "ABC" );
2721             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 ];
2722             if ( t4.getNumberOfExternalNodes() != 9 ) {
2723                 return false;
2724             }
2725             if ( t4.getHeight() != 11 ) {
2726                 return false;
2727             }
2728             if ( t4.isCompletelyBinary() ) {
2729                 return false;
2730             }
2731             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)" );
2732             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2733             if ( t5.getNumberOfExternalNodes() != 8 ) {
2734                 return false;
2735             }
2736             if ( t5.getHeight() != 15 ) {
2737                 return false;
2738             }
2739             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)" );
2740             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2741             if ( t6.getHeight() != 15 ) {
2742                 return false;
2743             }
2744             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)" );
2745             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2746             if ( t7.getHeight() != 15 ) {
2747                 return false;
2748             }
2749             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)" );
2750             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2751             if ( t8.getNumberOfExternalNodes() != 10 ) {
2752                 return false;
2753             }
2754             if ( t8.getHeight() != 15 ) {
2755                 return false;
2756             }
2757             final char[] a9 = new char[] { 'a' };
2758             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2759             if ( t9.getHeight() != 0 ) {
2760                 return false;
2761             }
2762             final char[] a10 = new char[] { 'a', ':', '6' };
2763             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2764             if ( t10.getHeight() != 6 ) {
2765                 return false;
2766             }
2767         }
2768         catch ( final Exception e ) {
2769             e.printStackTrace( System.out );
2770             return false;
2771         }
2772         return true;
2773     }
2774
2775     private static boolean testConfidenceAssessor() {
2776         try {
2777             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2778             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2779             final Phylogeny[] ev0 = factory
2780                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2781                              new NHXParser() );
2782             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2783             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2784                 return false;
2785             }
2786             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2787                 return false;
2788             }
2789             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2790             final Phylogeny[] ev1 = factory
2791                     .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)));",
2792                              new NHXParser() );
2793             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2794             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2795                 return false;
2796             }
2797             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2798                 return false;
2799             }
2800             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2801             final Phylogeny[] ev_b = factory
2802                     .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",
2803                              new NHXParser() );
2804             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2805             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2806                 return false;
2807             }
2808             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2809                 return false;
2810             }
2811             //
2812             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2813             final Phylogeny[] ev1x = factory
2814                     .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)));",
2815                              new NHXParser() );
2816             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2817             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2818                 return false;
2819             }
2820             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2821                 return false;
2822             }
2823             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2824             final Phylogeny[] ev_bx = factory
2825                     .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",
2826                              new NHXParser() );
2827             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2828             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2829                 return false;
2830             }
2831             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2832                 return false;
2833             }
2834             //
2835             final Phylogeny[] t2 = factory
2836                     .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);",
2837                              new NHXParser() );
2838             final Phylogeny[] ev2 = factory
2839                     .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);",
2840                              new NHXParser() );
2841             for( final Phylogeny target : t2 ) {
2842                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2843             }
2844             //
2845             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2846                                                  new NHXParser() )[ 0 ];
2847             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2848             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2849             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2850                 return false;
2851             }
2852             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2853                 return false;
2854             }
2855             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2856                 return false;
2857             }
2858         }
2859         catch ( final Exception e ) {
2860             e.printStackTrace();
2861             return false;
2862         }
2863         return true;
2864     }
2865
2866     private static boolean testCopyOfNodeData() {
2867         try {
2868             final PhylogenyNode n1 = PhylogenyNode
2869                     .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]" );
2870             final PhylogenyNode n2 = n1.copyNodeData();
2871             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2872                 return false;
2873             }
2874         }
2875         catch ( final Exception e ) {
2876             e.printStackTrace();
2877             return false;
2878         }
2879         return true;
2880     }
2881
2882     private static boolean testCreateBalancedPhylogeny() {
2883         try {
2884             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2885             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2886                 return false;
2887             }
2888             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2889                 return false;
2890             }
2891             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2892             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2893                 return false;
2894             }
2895             if ( p1.getNumberOfExternalNodes() != 100 ) {
2896                 return false;
2897             }
2898         }
2899         catch ( final Exception e ) {
2900             e.printStackTrace();
2901             return false;
2902         }
2903         return true;
2904     }
2905
2906     private static boolean testCreateUriForSeqWeb() {
2907         try {
2908             final PhylogenyNode n = new PhylogenyNode();
2909             n.setName( "tr|B3RJ64" );
2910             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2911                 return false;
2912             }
2913             n.setName( "B0LM41_HUMAN" );
2914             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2915                 return false;
2916             }
2917             n.setName( "NP_001025424" );
2918             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2919                 return false;
2920             }
2921             n.setName( "_NM_001030253-" );
2922             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2923                 return false;
2924             }
2925             n.setName( "XM_002122186" );
2926             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2927                 return false;
2928             }
2929             n.setName( "dgh_AAA34956_gdg" );
2930             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2931                 return false;
2932             }
2933             n.setName( "AAA34956" );
2934             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2935                 return false;
2936             }
2937             n.setName( "GI:394892" );
2938             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2939                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2940                 return false;
2941             }
2942             n.setName( "gi_394892" );
2943             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2944                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2945                 return false;
2946             }
2947             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2948             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2949                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2950                 return false;
2951             }
2952             n.setName( "P12345" );
2953             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2954                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2955                 return false;
2956             }
2957             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
2958             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2959                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2960                 return false;
2961             }
2962         }
2963         catch ( final Exception e ) {
2964             e.printStackTrace( System.out );
2965             return false;
2966         }
2967         return true;
2968     }
2969
2970     private static boolean testDataObjects() {
2971         try {
2972             final Confidence s0 = new Confidence();
2973             final Confidence s1 = new Confidence();
2974             if ( !s0.isEqual( s1 ) ) {
2975                 return false;
2976             }
2977             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2978             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2979             if ( s2.isEqual( s1 ) ) {
2980                 return false;
2981             }
2982             if ( !s2.isEqual( s3 ) ) {
2983                 return false;
2984             }
2985             final Confidence s4 = ( Confidence ) s3.copy();
2986             if ( !s4.isEqual( s3 ) ) {
2987                 return false;
2988             }
2989             s3.asSimpleText();
2990             s3.asText();
2991             // Taxonomy
2992             // ----------
2993             final Taxonomy t1 = new Taxonomy();
2994             final Taxonomy t2 = new Taxonomy();
2995             final Taxonomy t3 = new Taxonomy();
2996             final Taxonomy t4 = new Taxonomy();
2997             final Taxonomy t5 = new Taxonomy();
2998             t1.setIdentifier( new Identifier( "ecoli" ) );
2999             t1.setTaxonomyCode( "ECOLI" );
3000             t1.setScientificName( "E. coli" );
3001             t1.setCommonName( "coli" );
3002             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3003             if ( !t1.isEqual( t0 ) ) {
3004                 return false;
3005             }
3006             t2.setIdentifier( new Identifier( "ecoli" ) );
3007             t2.setTaxonomyCode( "OTHER" );
3008             t2.setScientificName( "what" );
3009             t2.setCommonName( "something" );
3010             if ( !t1.isEqual( t2 ) ) {
3011                 return false;
3012             }
3013             t2.setIdentifier( new Identifier( "nemve" ) );
3014             if ( t1.isEqual( t2 ) ) {
3015                 return false;
3016             }
3017             t1.setIdentifier( null );
3018             t3.setTaxonomyCode( "ECOLI" );
3019             t3.setScientificName( "what" );
3020             t3.setCommonName( "something" );
3021             if ( !t1.isEqual( t3 ) ) {
3022                 return false;
3023             }
3024             t1.setIdentifier( null );
3025             t1.setTaxonomyCode( "" );
3026             t4.setScientificName( "E. ColI" );
3027             t4.setCommonName( "something" );
3028             if ( !t1.isEqual( t4 ) ) {
3029                 return false;
3030             }
3031             t4.setScientificName( "B. subtilis" );
3032             t4.setCommonName( "something" );
3033             if ( t1.isEqual( t4 ) ) {
3034                 return false;
3035             }
3036             t1.setIdentifier( null );
3037             t1.setTaxonomyCode( "" );
3038             t1.setScientificName( "" );
3039             t5.setCommonName( "COLI" );
3040             if ( !t1.isEqual( t5 ) ) {
3041                 return false;
3042             }
3043             t5.setCommonName( "vibrio" );
3044             if ( t1.isEqual( t5 ) ) {
3045                 return false;
3046             }
3047             // Identifier
3048             // ----------
3049             final Identifier id0 = new Identifier( "123", "pfam" );
3050             final Identifier id1 = ( Identifier ) id0.copy();
3051             if ( !id1.isEqual( id1 ) ) {
3052                 return false;
3053             }
3054             if ( !id1.isEqual( id0 ) ) {
3055                 return false;
3056             }
3057             if ( !id0.isEqual( id1 ) ) {
3058                 return false;
3059             }
3060             id1.asSimpleText();
3061             id1.asText();
3062             // ProteinDomain
3063             // ---------------
3064             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3065             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3066             if ( !pd1.isEqual( pd1 ) ) {
3067                 return false;
3068             }
3069             if ( !pd1.isEqual( pd0 ) ) {
3070                 return false;
3071             }
3072             pd1.asSimpleText();
3073             pd1.asText();
3074             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3075             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3076             if ( !pd3.isEqual( pd3 ) ) {
3077                 return false;
3078             }
3079             if ( !pd2.isEqual( pd3 ) ) {
3080                 return false;
3081             }
3082             if ( !pd0.isEqual( pd3 ) ) {
3083                 return false;
3084             }
3085             pd3.asSimpleText();
3086             pd3.asText();
3087             // DomainArchitecture
3088             // ------------------
3089             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3090             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3091             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3092             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3093             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3094             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3095             domains0.add( d2 );
3096             domains0.add( d0 );
3097             domains0.add( d3 );
3098             domains0.add( d1 );
3099             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3100             if ( ds0.getNumberOfDomains() != 4 ) {
3101                 return false;
3102             }
3103             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3104             if ( !ds0.isEqual( ds0 ) ) {
3105                 return false;
3106             }
3107             if ( !ds0.isEqual( ds1 ) ) {
3108                 return false;
3109             }
3110             if ( ds1.getNumberOfDomains() != 4 ) {
3111                 return false;
3112             }
3113             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3114             domains1.add( d1 );
3115             domains1.add( d2 );
3116             domains1.add( d4 );
3117             domains1.add( d0 );
3118             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3119             if ( ds0.isEqual( ds2 ) ) {
3120                 return false;
3121             }
3122             ds1.asSimpleText();
3123             ds1.asText();
3124             ds1.toNHX();
3125             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3126             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3127                 System.out.println( ds3.toNHX() );
3128                 return false;
3129             }
3130             if ( ds3.getNumberOfDomains() != 3 ) {
3131                 return false;
3132             }
3133             // Event
3134             // -----
3135             final Event e1 = new Event( Event.EventType.fusion );
3136             if ( e1.isDuplication() ) {
3137                 return false;
3138             }
3139             if ( !e1.isFusion() ) {
3140                 return false;
3141             }
3142             if ( !e1.asText().toString().equals( "fusion" ) ) {
3143                 return false;
3144             }
3145             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3146                 return false;
3147             }
3148             final Event e11 = new Event( Event.EventType.fusion );
3149             if ( !e11.isEqual( e1 ) ) {
3150                 return false;
3151             }
3152             if ( !e11.toNHX().toString().equals( "" ) ) {
3153                 return false;
3154             }
3155             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3156             if ( e2.isDuplication() ) {
3157                 return false;
3158             }
3159             if ( !e2.isSpeciationOrDuplication() ) {
3160                 return false;
3161             }
3162             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3163                 return false;
3164             }
3165             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3166                 return false;
3167             }
3168             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3169                 return false;
3170             }
3171             if ( e11.isEqual( e2 ) ) {
3172                 return false;
3173             }
3174             final Event e2c = ( Event ) e2.copy();
3175             if ( !e2c.isEqual( e2 ) ) {
3176                 return false;
3177             }
3178             Event e3 = new Event( 1, 2, 3 );
3179             if ( e3.isDuplication() ) {
3180                 return false;
3181             }
3182             if ( e3.isSpeciation() ) {
3183                 return false;
3184             }
3185             if ( e3.isGeneLoss() ) {
3186                 return false;
3187             }
3188             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3189                 return false;
3190             }
3191             final Event e3c = ( Event ) e3.copy();
3192             final Event e3cc = ( Event ) e3c.copy();
3193             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3194                 return false;
3195             }
3196             e3 = null;
3197             if ( !e3c.isEqual( e3cc ) ) {
3198                 return false;
3199             }
3200             Event e4 = new Event( 1, 2, 3 );
3201             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3202                 return false;
3203             }
3204             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3205                 return false;
3206             }
3207             final Event e4c = ( Event ) e4.copy();
3208             e4 = null;
3209             final Event e4cc = ( Event ) e4c.copy();
3210             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3211                 return false;
3212             }
3213             if ( !e4c.isEqual( e4cc ) ) {
3214                 return false;
3215             }
3216             final Event e5 = new Event();
3217             if ( !e5.isUnassigned() ) {
3218                 return false;
3219             }
3220             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3221                 return false;
3222             }
3223             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3224                 return false;
3225             }
3226             final Event e6 = new Event( 1, 0, 0 );
3227             if ( !e6.asText().toString().equals( "duplication" ) ) {
3228                 return false;
3229             }
3230             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3231                 return false;
3232             }
3233             final Event e7 = new Event( 0, 1, 0 );
3234             if ( !e7.asText().toString().equals( "speciation" ) ) {
3235                 return false;
3236             }
3237             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3238                 return false;
3239             }
3240             final Event e8 = new Event( 0, 0, 1 );
3241             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3242                 return false;
3243             }
3244             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3245                 return false;
3246             }
3247         }
3248         catch ( final Exception e ) {
3249             e.printStackTrace( System.out );
3250             return false;
3251         }
3252         return true;
3253     }
3254
3255     private static boolean testDeletionOfExternalNodes() {
3256         try {
3257             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3258             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3259             final PhylogenyWriter w = new PhylogenyWriter();
3260             if ( t0.isEmpty() ) {
3261                 return false;
3262             }
3263             if ( t0.getNumberOfExternalNodes() != 1 ) {
3264                 return false;
3265             }
3266             t0.deleteSubtree( t0.getNode( "A" ), false );
3267             if ( t0.getNumberOfExternalNodes() != 0 ) {
3268                 return false;
3269             }
3270             if ( !t0.isEmpty() ) {
3271                 return false;
3272             }
3273             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3274             if ( t1.getNumberOfExternalNodes() != 2 ) {
3275                 return false;
3276             }
3277             t1.deleteSubtree( t1.getNode( "A" ), false );
3278             if ( t1.getNumberOfExternalNodes() != 1 ) {
3279                 return false;
3280             }
3281             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3282                 return false;
3283             }
3284             t1.deleteSubtree( t1.getNode( "B" ), false );
3285             if ( t1.getNumberOfExternalNodes() != 1 ) {
3286                 return false;
3287             }
3288             t1.deleteSubtree( t1.getNode( "r" ), false );
3289             if ( !t1.isEmpty() ) {
3290                 return false;
3291             }
3292             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3293             if ( t2.getNumberOfExternalNodes() != 3 ) {
3294                 return false;
3295             }
3296             t2.deleteSubtree( t2.getNode( "B" ), false );
3297             if ( t2.getNumberOfExternalNodes() != 2 ) {
3298                 return false;
3299             }
3300             t2.toNewHampshireX();
3301             PhylogenyNode n = t2.getNode( "A" );
3302             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3303                 return false;
3304             }
3305             t2.deleteSubtree( t2.getNode( "A" ), false );
3306             if ( t2.getNumberOfExternalNodes() != 2 ) {
3307                 return false;
3308             }
3309             t2.deleteSubtree( t2.getNode( "C" ), true );
3310             if ( t2.getNumberOfExternalNodes() != 1 ) {
3311                 return false;
3312             }
3313             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3314             if ( t3.getNumberOfExternalNodes() != 4 ) {
3315                 return false;
3316             }
3317             t3.deleteSubtree( t3.getNode( "B" ), true );
3318             if ( t3.getNumberOfExternalNodes() != 3 ) {
3319                 return false;
3320             }
3321             n = t3.getNode( "A" );
3322             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3323                 return false;
3324             }
3325             n = n.getNextExternalNode();
3326             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3327                 return false;
3328             }
3329             t3.deleteSubtree( t3.getNode( "A" ), true );
3330             if ( t3.getNumberOfExternalNodes() != 2 ) {
3331                 return false;
3332             }
3333             n = t3.getNode( "C" );
3334             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3335                 return false;
3336             }
3337             t3.deleteSubtree( t3.getNode( "C" ), true );
3338             if ( t3.getNumberOfExternalNodes() != 1 ) {
3339                 return false;
3340             }
3341             t3.deleteSubtree( t3.getNode( "D" ), true );
3342             if ( t3.getNumberOfExternalNodes() != 0 ) {
3343                 return false;
3344             }
3345             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3346             if ( t4.getNumberOfExternalNodes() != 6 ) {
3347                 return false;
3348             }
3349             t4.deleteSubtree( t4.getNode( "B2" ), true );
3350             if ( t4.getNumberOfExternalNodes() != 5 ) {
3351                 return false;
3352             }
3353             String s = w.toNewHampshire( t4, false, true ).toString();
3354             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3355                 return false;
3356             }
3357             t4.deleteSubtree( t4.getNode( "B11" ), true );
3358             if ( t4.getNumberOfExternalNodes() != 4 ) {
3359                 return false;
3360             }
3361             t4.deleteSubtree( t4.getNode( "C" ), true );
3362             if ( t4.getNumberOfExternalNodes() != 3 ) {
3363                 return false;
3364             }
3365             n = t4.getNode( "A" );
3366             n = n.getNextExternalNode();
3367             if ( !n.getName().equals( "B12" ) ) {
3368                 return false;
3369             }
3370             n = n.getNextExternalNode();
3371             if ( !n.getName().equals( "D" ) ) {
3372                 return false;
3373             }
3374             s = w.toNewHampshire( t4, false, true ).toString();
3375             if ( !s.equals( "((A,B12),D);" ) ) {
3376                 return false;
3377             }
3378             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3379             t5.deleteSubtree( t5.getNode( "A" ), true );
3380             if ( t5.getNumberOfExternalNodes() != 5 ) {
3381                 return false;
3382             }
3383             s = w.toNewHampshire( t5, false, true ).toString();
3384             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3385                 return false;
3386             }
3387             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3388             t6.deleteSubtree( t6.getNode( "B11" ), true );
3389             if ( t6.getNumberOfExternalNodes() != 5 ) {
3390                 return false;
3391             }
3392             s = w.toNewHampshire( t6, false, false ).toString();
3393             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3394                 return false;
3395             }
3396             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3397             t7.deleteSubtree( t7.getNode( "B12" ), true );
3398             if ( t7.getNumberOfExternalNodes() != 5 ) {
3399                 return false;
3400             }
3401             s = w.toNewHampshire( t7, false, true ).toString();
3402             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3403                 return false;
3404             }
3405             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3406             t8.deleteSubtree( t8.getNode( "B2" ), true );
3407             if ( t8.getNumberOfExternalNodes() != 5 ) {
3408                 return false;
3409             }
3410             s = w.toNewHampshire( t8, false, false ).toString();
3411             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3412                 return false;
3413             }
3414             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3415             t9.deleteSubtree( t9.getNode( "C" ), true );
3416             if ( t9.getNumberOfExternalNodes() != 5 ) {
3417                 return false;
3418             }
3419             s = w.toNewHampshire( t9, false, true ).toString();
3420             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3421                 return false;
3422             }
3423             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3424             t10.deleteSubtree( t10.getNode( "D" ), true );
3425             if ( t10.getNumberOfExternalNodes() != 5 ) {
3426                 return false;
3427             }
3428             s = w.toNewHampshire( t10, false, true ).toString();
3429             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3430                 return false;
3431             }
3432             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3433             t11.deleteSubtree( t11.getNode( "A" ), true );
3434             if ( t11.getNumberOfExternalNodes() != 2 ) {
3435                 return false;
3436             }
3437             s = w.toNewHampshire( t11, false, true ).toString();
3438             if ( !s.equals( "(B,C);" ) ) {
3439                 return false;
3440             }
3441             t11.deleteSubtree( t11.getNode( "C" ), true );
3442             if ( t11.getNumberOfExternalNodes() != 1 ) {
3443                 return false;
3444             }
3445             s = w.toNewHampshire( t11, false, false ).toString();
3446             if ( !s.equals( "B;" ) ) {
3447                 return false;
3448             }
3449             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3450             t12.deleteSubtree( t12.getNode( "B2" ), true );
3451             if ( t12.getNumberOfExternalNodes() != 8 ) {
3452                 return false;
3453             }
3454             s = w.toNewHampshire( t12, false, true ).toString();
3455             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3456                 return false;
3457             }
3458             t12.deleteSubtree( t12.getNode( "B3" ), true );
3459             if ( t12.getNumberOfExternalNodes() != 7 ) {
3460                 return false;
3461             }
3462             s = w.toNewHampshire( t12, false, true ).toString();
3463             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3464                 return false;
3465             }
3466             t12.deleteSubtree( t12.getNode( "C3" ), true );
3467             if ( t12.getNumberOfExternalNodes() != 6 ) {
3468                 return false;
3469             }
3470             s = w.toNewHampshire( t12, false, true ).toString();
3471             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3472                 return false;
3473             }
3474             t12.deleteSubtree( t12.getNode( "A1" ), true );
3475             if ( t12.getNumberOfExternalNodes() != 5 ) {
3476                 return false;
3477             }
3478             s = w.toNewHampshire( t12, false, true ).toString();
3479             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3480                 return false;
3481             }
3482             t12.deleteSubtree( t12.getNode( "B1" ), true );
3483             if ( t12.getNumberOfExternalNodes() != 4 ) {
3484                 return false;
3485             }
3486             s = w.toNewHampshire( t12, false, true ).toString();
3487             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3488                 return false;
3489             }
3490             t12.deleteSubtree( t12.getNode( "A3" ), true );
3491             if ( t12.getNumberOfExternalNodes() != 3 ) {
3492                 return false;
3493             }
3494             s = w.toNewHampshire( t12, false, true ).toString();
3495             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3496                 return false;
3497             }
3498             t12.deleteSubtree( t12.getNode( "A2" ), true );
3499             if ( t12.getNumberOfExternalNodes() != 2 ) {
3500                 return false;
3501             }
3502             s = w.toNewHampshire( t12, false, true ).toString();
3503             if ( !s.equals( "(C1,C2);" ) ) {
3504                 return false;
3505             }
3506             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3507             t13.deleteSubtree( t13.getNode( "D" ), true );
3508             if ( t13.getNumberOfExternalNodes() != 4 ) {
3509                 return false;
3510             }
3511             s = w.toNewHampshire( t13, false, true ).toString();
3512             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3513                 return false;
3514             }
3515             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3516             t14.deleteSubtree( t14.getNode( "E" ), true );
3517             if ( t14.getNumberOfExternalNodes() != 5 ) {
3518                 return false;
3519             }
3520             s = w.toNewHampshire( t14, false, true ).toString();
3521             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3522                 return false;
3523             }
3524             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3525             t15.deleteSubtree( t15.getNode( "B2" ), true );
3526             if ( t15.getNumberOfExternalNodes() != 11 ) {
3527                 return false;
3528             }
3529             t15.deleteSubtree( t15.getNode( "B1" ), true );
3530             if ( t15.getNumberOfExternalNodes() != 10 ) {
3531                 return false;
3532             }
3533             t15.deleteSubtree( t15.getNode( "B3" ), true );
3534             if ( t15.getNumberOfExternalNodes() != 9 ) {
3535                 return false;
3536             }
3537             t15.deleteSubtree( t15.getNode( "B4" ), true );
3538             if ( t15.getNumberOfExternalNodes() != 8 ) {
3539                 return false;
3540             }
3541             t15.deleteSubtree( t15.getNode( "A1" ), true );
3542             if ( t15.getNumberOfExternalNodes() != 7 ) {
3543                 return false;
3544             }
3545             t15.deleteSubtree( t15.getNode( "C4" ), true );
3546             if ( t15.getNumberOfExternalNodes() != 6 ) {
3547                 return false;
3548             }
3549         }
3550         catch ( final Exception e ) {
3551             e.printStackTrace( System.out );
3552             return false;
3553         }
3554         return true;
3555     }
3556
3557     private static boolean testDescriptiveStatistics() {
3558         try {
3559             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3560             dss1.addValue( 82 );
3561             dss1.addValue( 78 );
3562             dss1.addValue( 70 );
3563             dss1.addValue( 58 );
3564             dss1.addValue( 42 );
3565             if ( dss1.getN() != 5 ) {
3566                 return false;
3567             }
3568             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3569                 return false;
3570             }
3571             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3572                 return false;
3573             }
3574             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3575                 return false;
3576             }
3577             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3578                 return false;
3579             }
3580             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3581                 return false;
3582             }
3583             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3584                 return false;
3585             }
3586             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3587                 return false;
3588             }
3589             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3590                 return false;
3591             }
3592             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3593                 return false;
3594             }
3595             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3596                 return false;
3597             }
3598             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3599                 return false;
3600             }
3601             dss1.addValue( 123 );
3602             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3603                 return false;
3604             }
3605             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3606                 return false;
3607             }
3608             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3609                 return false;
3610             }
3611             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3612             dss2.addValue( -1.85 );
3613             dss2.addValue( 57.5 );
3614             dss2.addValue( 92.78 );
3615             dss2.addValue( 57.78 );
3616             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3617                 return false;
3618             }
3619             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3620                 return false;
3621             }
3622             final double[] a = dss2.getDataAsDoubleArray();
3623             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3624                 return false;
3625             }
3626             dss2.addValue( -100 );
3627             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3628                 return false;
3629             }
3630             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3631                 return false;
3632             }
3633             final double[] ds = new double[ 14 ];
3634             ds[ 0 ] = 34;
3635             ds[ 1 ] = 23;
3636             ds[ 2 ] = 1;
3637             ds[ 3 ] = 32;
3638             ds[ 4 ] = 11;
3639             ds[ 5 ] = 2;
3640             ds[ 6 ] = 12;
3641             ds[ 7 ] = 33;
3642             ds[ 8 ] = 13;
3643             ds[ 9 ] = 22;
3644             ds[ 10 ] = 21;
3645             ds[ 11 ] = 35;
3646             ds[ 12 ] = 24;
3647             ds[ 13 ] = 31;
3648             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3649             if ( bins.length != 4 ) {
3650                 return false;
3651             }
3652             if ( bins[ 0 ] != 2 ) {
3653                 return false;
3654             }
3655             if ( bins[ 1 ] != 3 ) {
3656                 return false;
3657             }
3658             if ( bins[ 2 ] != 4 ) {
3659                 return false;
3660             }
3661             if ( bins[ 3 ] != 5 ) {
3662                 return false;
3663             }
3664             final double[] ds1 = new double[ 9 ];
3665             ds1[ 0 ] = 10.0;
3666             ds1[ 1 ] = 19.0;
3667             ds1[ 2 ] = 9.999;
3668             ds1[ 3 ] = 0.0;
3669             ds1[ 4 ] = 39.9;
3670             ds1[ 5 ] = 39.999;
3671             ds1[ 6 ] = 30.0;
3672             ds1[ 7 ] = 19.999;
3673             ds1[ 8 ] = 30.1;
3674             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3675             if ( bins1.length != 4 ) {
3676                 return false;
3677             }
3678             if ( bins1[ 0 ] != 2 ) {
3679                 return false;
3680             }
3681             if ( bins1[ 1 ] != 3 ) {
3682                 return false;
3683             }
3684             if ( bins1[ 2 ] != 0 ) {
3685                 return false;
3686             }
3687             if ( bins1[ 3 ] != 4 ) {
3688                 return false;
3689             }
3690             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3691             if ( bins1_1.length != 3 ) {
3692                 return false;
3693             }
3694             if ( bins1_1[ 0 ] != 3 ) {
3695                 return false;
3696             }
3697             if ( bins1_1[ 1 ] != 2 ) {
3698                 return false;
3699             }
3700             if ( bins1_1[ 2 ] != 4 ) {
3701                 return false;
3702             }
3703             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3704             if ( bins1_2.length != 3 ) {
3705                 return false;
3706             }
3707             if ( bins1_2[ 0 ] != 2 ) {
3708                 return false;
3709             }
3710             if ( bins1_2[ 1 ] != 2 ) {
3711                 return false;
3712             }
3713             if ( bins1_2[ 2 ] != 2 ) {
3714                 return false;
3715             }
3716             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3717             dss3.addValue( 1 );
3718             dss3.addValue( 1 );
3719             dss3.addValue( 1 );
3720             dss3.addValue( 2 );
3721             dss3.addValue( 3 );
3722             dss3.addValue( 4 );
3723             dss3.addValue( 5 );
3724             dss3.addValue( 5 );
3725             dss3.addValue( 5 );
3726             dss3.addValue( 6 );
3727             dss3.addValue( 7 );
3728             dss3.addValue( 8 );
3729             dss3.addValue( 9 );
3730             dss3.addValue( 10 );
3731             dss3.addValue( 10 );
3732             dss3.addValue( 10 );
3733             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3734             histo.toStringBuffer( 10, '=', 40, 5 );
3735             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3736         }
3737         catch ( final Exception e ) {
3738             e.printStackTrace( System.out );
3739             return false;
3740         }
3741         return true;
3742     }
3743
3744     private static boolean testDir( final String file ) {
3745         try {
3746             final File f = new File( file );
3747             if ( !f.exists() ) {
3748                 return false;
3749             }
3750             if ( !f.isDirectory() ) {
3751                 return false;
3752             }
3753             if ( !f.canRead() ) {
3754                 return false;
3755             }
3756         }
3757         catch ( final Exception e ) {
3758             return false;
3759         }
3760         return true;
3761     }
3762
3763     private static boolean testEbiEntryRetrieval() {
3764         try {
3765             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3766             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3767                 System.out.println( entry.getAccession() );
3768                 return false;
3769             }
3770             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3771                 System.out.println( entry.getTaxonomyScientificName() );
3772                 return false;
3773             }
3774             if ( !entry.getSequenceName()
3775                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3776                 System.out.println( entry.getSequenceName() );
3777                 return false;
3778             }
3779             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3780             //     System.out.println( entry.getSequenceSymbol() );
3781             //     return false;
3782             // }
3783             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3784                 System.out.println( entry.getGeneName() );
3785                 return false;
3786             }
3787             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3788                 System.out.println( entry.getTaxonomyIdentifier() );
3789                 return false;
3790             }
3791             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3792                 System.out.println( entry.getAnnotations().first().getRefValue() );
3793                 return false;
3794             }
3795             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3796                 System.out.println( entry.getAnnotations().first().getRefSource() );
3797                 return false;
3798             }
3799             if ( entry.getCrossReferences().size() != 5 ) {
3800                 return false;
3801             }
3802             //
3803             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3804             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3805                 return false;
3806             }
3807             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3808                 System.out.println( entry1.getTaxonomyScientificName() );
3809                 return false;
3810             }
3811             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3812                 System.out.println( entry1.getSequenceName() );
3813                 return false;
3814             }
3815             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3816                 System.out.println( entry1.getTaxonomyIdentifier() );
3817                 return false;
3818             }
3819             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3820                 System.out.println( entry1.getGeneName() );
3821                 return false;
3822             }
3823             if ( entry1.getCrossReferences().size() != 6 ) {
3824                 return false;
3825             }
3826             //
3827             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3828             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3829                 return false;
3830             }
3831             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3832                 System.out.println( entry2.getTaxonomyScientificName() );
3833                 return false;
3834             }
3835             if ( !entry2.getSequenceName()
3836                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3837                 System.out.println( entry2.getSequenceName() );
3838                 return false;
3839             }
3840             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3841                 System.out.println( entry2.getTaxonomyIdentifier() );
3842                 return false;
3843             }
3844             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3845                 System.out.println( entry2.getGeneName() );
3846                 return false;
3847             }
3848             if ( entry2.getCrossReferences().size() != 3 ) {
3849                 return false;
3850             }
3851             //
3852             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3853             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3854                 return false;
3855             }
3856             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3857                 System.out.println( entry3.getTaxonomyScientificName() );
3858                 return false;
3859             }
3860             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3861                 System.out.println( entry3.getSequenceName() );
3862                 return false;
3863             }
3864             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3865                 System.out.println( entry3.getTaxonomyIdentifier() );
3866                 return false;
3867             }
3868             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3869                 System.out.println( entry3.getSequenceSymbol() );
3870                 return false;
3871             }
3872             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
3873                 return false;
3874             }
3875             if ( entry3.getCrossReferences().size() != 8 ) {
3876                 return false;
3877             }
3878             //
3879             //
3880             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
3881             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
3882                 return false;
3883             }
3884             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3885                 System.out.println( entry4.getTaxonomyScientificName() );
3886                 return false;
3887             }
3888             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
3889                 System.out.println( entry4.getSequenceName() );
3890                 return false;
3891             }
3892             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
3893                 System.out.println( entry4.getTaxonomyIdentifier() );
3894                 return false;
3895             }
3896             if ( !entry4.getGeneName().equals( "ras" ) ) {
3897                 System.out.println( entry4.getGeneName() );
3898                 return false;
3899             }
3900             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
3901             //     System.out.println( entry4.getChromosome() );
3902             //     return false;
3903             // }
3904             // if ( !entry4.getMap().equals( "ras" ) ) {
3905             //     System.out.println( entry4.getMap() );
3906             //     return false;
3907             // }
3908             //TODO FIXME gi...
3909             //
3910             //TODO fails:
3911             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
3912             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
3913             //                return false;
3914             //            }
3915             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
3916             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
3917                 return false;
3918             }
3919             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
3920                 System.out.println( entry5.getTaxonomyScientificName() );
3921                 return false;
3922             }
3923             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
3924                 System.out.println( entry5.getSequenceName() );
3925                 return false;
3926             }
3927             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
3928                 System.out.println( entry5.getTaxonomyIdentifier() );
3929                 return false;
3930             }
3931         }
3932         catch ( final IOException e ) {
3933             System.out.println();
3934             System.out.println( "the following might be due to absence internet connection:" );
3935             e.printStackTrace( System.out );
3936             return true;
3937         }
3938         catch ( final Exception e ) {
3939             e.printStackTrace();
3940             return false;
3941         }
3942         return true;
3943     }
3944
3945     private static boolean testExternalNodeRelatedMethods() {
3946         try {
3947             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3948             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3949             PhylogenyNode n = t1.getNode( "A" );
3950             n = n.getNextExternalNode();
3951             if ( !n.getName().equals( "B" ) ) {
3952                 return false;
3953             }
3954             n = n.getNextExternalNode();
3955             if ( !n.getName().equals( "C" ) ) {
3956                 return false;
3957             }
3958             n = n.getNextExternalNode();
3959             if ( !n.getName().equals( "D" ) ) {
3960                 return false;
3961             }
3962             n = t1.getNode( "B" );
3963             while ( !n.isLastExternalNode() ) {
3964                 n = n.getNextExternalNode();
3965             }
3966             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3967             n = t2.getNode( "A" );
3968             n = n.getNextExternalNode();
3969             if ( !n.getName().equals( "B" ) ) {
3970                 return false;
3971             }
3972             n = n.getNextExternalNode();
3973             if ( !n.getName().equals( "C" ) ) {
3974                 return false;
3975             }
3976             n = n.getNextExternalNode();
3977             if ( !n.getName().equals( "D" ) ) {
3978                 return false;
3979             }
3980             n = t2.getNode( "B" );
3981             while ( !n.isLastExternalNode() ) {
3982                 n = n.getNextExternalNode();
3983             }
3984             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3985             n = t3.getNode( "A" );
3986             n = n.getNextExternalNode();
3987             if ( !n.getName().equals( "B" ) ) {
3988                 return false;
3989             }
3990             n = n.getNextExternalNode();
3991             if ( !n.getName().equals( "C" ) ) {
3992                 return false;
3993             }
3994             n = n.getNextExternalNode();
3995             if ( !n.getName().equals( "D" ) ) {
3996                 return false;
3997             }
3998             n = n.getNextExternalNode();
3999             if ( !n.getName().equals( "E" ) ) {
4000                 return false;
4001             }
4002             n = n.getNextExternalNode();
4003             if ( !n.getName().equals( "F" ) ) {
4004                 return false;
4005             }
4006             n = n.getNextExternalNode();
4007             if ( !n.getName().equals( "G" ) ) {
4008                 return false;
4009             }
4010             n = n.getNextExternalNode();
4011             if ( !n.getName().equals( "H" ) ) {
4012                 return false;
4013             }
4014             n = t3.getNode( "B" );
4015             while ( !n.isLastExternalNode() ) {
4016                 n = n.getNextExternalNode();
4017             }
4018             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4019             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4020                 final PhylogenyNode node = iter.next();
4021             }
4022             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4023             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4024                 final PhylogenyNode node = iter.next();
4025             }
4026             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4027             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4028             if ( !iter.next().getName().equals( "A" ) ) {
4029                 return false;
4030             }
4031             if ( !iter.next().getName().equals( "B" ) ) {
4032                 return false;
4033             }
4034             if ( !iter.next().getName().equals( "C" ) ) {
4035                 return false;
4036             }
4037             if ( !iter.next().getName().equals( "D" ) ) {
4038                 return false;
4039             }
4040             if ( !iter.next().getName().equals( "E" ) ) {
4041                 return false;
4042             }
4043             if ( !iter.next().getName().equals( "F" ) ) {
4044                 return false;
4045             }
4046             if ( iter.hasNext() ) {
4047                 return false;
4048             }
4049         }
4050         catch ( final Exception e ) {
4051             e.printStackTrace( System.out );
4052             return false;
4053         }
4054         return true;
4055     }
4056
4057     private static boolean testExtractSNFromNodeName() {
4058         try {
4059             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4060                 return false;
4061             }
4062             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
4063                     .equals( "Mus musculus musculus" ) ) {
4064                 return false;
4065             }
4066             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
4067                     .equals( "Mus musculus musculus" ) ) {
4068                 return false;
4069             }
4070             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
4071                 return false;
4072             }
4073             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
4074                     .equals( "Mus musculus" ) ) {
4075                 return false;
4076             }
4077         }
4078         catch ( final Exception e ) {
4079             e.printStackTrace( System.out );
4080             return false;
4081         }
4082         return true;
4083     }
4084
4085     private static boolean testExtractTaxonomyCodeFromNodeName() {
4086         try {
4087             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4088                 return false;
4089             }
4090             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4091                     .equals( "SOYBN" ) ) {
4092                 return false;
4093             }
4094             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4095                     .equals( "ARATH" ) ) {
4096                 return false;
4097             }
4098             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4099                     .equals( "ARATH" ) ) {
4100                 return false;
4101             }
4102             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4103                 return false;
4104             }
4105             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4106                 return false;
4107             }
4108             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4109                 return false;
4110             }
4111             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4112                     .equals( "SOYBN" ) ) {
4113                 return false;
4114             }
4115             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4116                     .equals( "SOYBN" ) ) {
4117                 return false;
4118             }
4119             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4120                     .equals( "SOYBN" ) ) {
4121                 return false;
4122             }
4123             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4124                     .equals( "SOYBN" ) ) {
4125                 return false;
4126             }
4127             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4128                     .equals( "SOYBN" ) ) {
4129                 return false;
4130             }
4131             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4132                     .equals( "SOYBN" ) ) {
4133                 return false;
4134             }
4135             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4136                     .equals( "SOYBN" ) ) {
4137                 return false;
4138             }
4139             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4140                     .equals( "SOYBN" ) ) {
4141                 return false;
4142             }
4143             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4144                 return false;
4145             }
4146             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4147                     .equals( "SOYBN" ) ) {
4148                 return false;
4149             }
4150             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4151                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4152                 return false;
4153             }
4154             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4155                     .equals( "9YX45" ) ) {
4156                 return false;
4157             }
4158             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4159                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4160                     .equals( "MOUSE" ) ) {
4161                 return false;
4162             }
4163             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4164                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4165                     .equals( "MOUSE" ) ) {
4166                 return false;
4167             }
4168             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4169                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4170                     .equals( "MOUSE" ) ) {
4171                 return false;
4172             }
4173             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4174                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4175                 return false;
4176             }
4177             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4178                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4179                 return false;
4180             }
4181             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4182                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4183                 return false;
4184             }
4185             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4186                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4187                 return false;
4188             }
4189             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4190                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4191                 return false;
4192             }
4193             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4194                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4195                 return false;
4196             }
4197             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4198                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4199                 return false;
4200             }
4201             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4202                     .equals( "RAT" ) ) {
4203                 return false;
4204             }
4205             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4206                     .equals( "PIG" ) ) {
4207                 return false;
4208             }
4209             if ( !ParserUtils
4210                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4211                     .equals( "MOUSE" ) ) {
4212                 return false;
4213             }
4214             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4215                     .equals( "MOUSE" ) ) {
4216                 return false;
4217             }
4218             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4219                 return false;
4220             }
4221         }
4222         catch ( final Exception e ) {
4223             e.printStackTrace( System.out );
4224             return false;
4225         }
4226         return true;
4227     }
4228
4229     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4230         try {
4231             PhylogenyNode n = new PhylogenyNode();
4232             n.setName( "tr|B3RJ64" );
4233             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4234                 return false;
4235             }
4236             n.setName( "tr.B3RJ64" );
4237             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4238                 return false;
4239             }
4240             n.setName( "tr=B3RJ64" );
4241             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4242                 return false;
4243             }
4244             n.setName( "tr-B3RJ64" );
4245             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4246                 return false;
4247             }
4248             n.setName( "tr/B3RJ64" );
4249             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4250                 return false;
4251             }
4252             n.setName( "tr\\B3RJ64" );
4253             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4254                 return false;
4255             }
4256             n.setName( "tr_B3RJ64" );
4257             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4258                 return false;
4259             }
4260             n.setName( " tr|B3RJ64 " );
4261             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4262                 return false;
4263             }
4264             n.setName( "-tr|B3RJ64-" );
4265             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4266                 return false;
4267             }
4268             n.setName( "-tr=B3RJ64-" );
4269             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4270                 return false;
4271             }
4272             n.setName( "_tr=B3RJ64_" );
4273             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4274                 return false;
4275             }
4276             n.setName( " tr_tr|B3RJ64_sp|123 " );
4277             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4278                 return false;
4279             }
4280             n.setName( "B3RJ64" );
4281             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4282                 return false;
4283             }
4284             n.setName( "sp|B3RJ64" );
4285             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4286                 return false;
4287             }
4288             n.setName( "sp|B3RJ64C" );
4289             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4290                 return false;
4291             }
4292             n.setName( "sp B3RJ64" );
4293             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4294                 return false;
4295             }
4296             n.setName( "sp|B3RJ6X" );
4297             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4298                 return false;
4299             }
4300             n.setName( "sp|B3RJ6" );
4301             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4302                 return false;
4303             }
4304             n.setName( "K1PYK7_CRAGI" );
4305             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4306                 return false;
4307             }
4308             n.setName( "K1PYK7_PEA" );
4309             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4310                 return false;
4311             }
4312             n.setName( "K1PYK7_RAT" );
4313             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4314                 return false;
4315             }
4316             n.setName( "K1PYK7_PIG" );
4317             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4318                 return false;
4319             }
4320             n.setName( "~K1PYK7_PIG~" );
4321             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4322                 return false;
4323             }
4324             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4325             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4326                 return false;
4327             }
4328             n.setName( "K1PYKX_CRAGI" );
4329             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4330                 return false;
4331             }
4332             n.setName( "XXXXX_CRAGI" );
4333             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4334                 return false;
4335             }
4336             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4337             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4338                 return false;
4339             }
4340             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4341             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4342                 return false;
4343             }
4344             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4345             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4346                 return false;
4347             }
4348             n = new PhylogenyNode();
4349             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4350             seq.setSymbol( "K1PYK7_CRAGI" );
4351             n.getNodeData().addSequence( seq );
4352             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4353                 return false;
4354             }
4355             seq.setSymbol( "tr|B3RJ64" );
4356             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4357                 return false;
4358             }
4359             n = new PhylogenyNode();
4360             seq = new org.forester.phylogeny.data.Sequence();
4361             seq.setName( "K1PYK7_CRAGI" );
4362             n.getNodeData().addSequence( seq );
4363             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4364                 return false;
4365             }
4366             seq.setName( "tr|B3RJ64" );
4367             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4368                 return false;
4369             }
4370             n = new PhylogenyNode();
4371             seq = new org.forester.phylogeny.data.Sequence();
4372             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4373             n.getNodeData().addSequence( seq );
4374             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4375                 return false;
4376             }
4377             n = new PhylogenyNode();
4378             seq = new org.forester.phylogeny.data.Sequence();
4379             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4380             n.getNodeData().addSequence( seq );
4381             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4382                 return false;
4383             }
4384             //
4385             n = new PhylogenyNode();
4386             n.setName( "ACP19736" );
4387             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4388                 return false;
4389             }
4390             n = new PhylogenyNode();
4391             n.setName( "|ACP19736|" );
4392             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4393                 return false;
4394             }
4395         }
4396         catch ( final Exception e ) {
4397             e.printStackTrace( System.out );
4398             return false;
4399         }
4400         return true;
4401     }
4402
4403     private static boolean testFastaParser() {
4404         try {
4405             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4406                 return false;
4407             }
4408             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4409                 return false;
4410             }
4411             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4412             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4413                 return false;
4414             }
4415             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4416                 return false;
4417             }
4418             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4419                 return false;
4420             }
4421             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4422                 return false;
4423             }
4424             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4425                 return false;
4426             }
4427             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4428                 return false;
4429             }
4430         }
4431         catch ( final Exception e ) {
4432             e.printStackTrace();
4433             return false;
4434         }
4435         return true;
4436     }
4437
4438     private static boolean testGenbankAccessorParsing() {
4439         //The format for GenBank Accession numbers are:
4440         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4441         //Protein:    3 letters + 5 numerals
4442         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4443         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4444             return false;
4445         }
4446         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4447             return false;
4448         }
4449         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4450             return false;
4451         }
4452         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4453             return false;
4454         }
4455         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4456             return false;
4457         }
4458         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4459             return false;
4460         }
4461         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4462             return false;
4463         }
4464         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4465             return false;
4466         }
4467         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4468             return false;
4469         }
4470         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4471             return false;
4472         }
4473         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4474             return false;
4475         }
4476         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4477             return false;
4478         }
4479         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4480             return false;
4481         }
4482         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4483             return false;
4484         }
4485         return true;
4486     }
4487
4488     private static boolean testGeneralMsaParser() {
4489         try {
4490             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4491             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4492             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4493             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4494             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4495             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4496             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4497             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4498             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4499                 return false;
4500             }
4501             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4502                 return false;
4503             }
4504             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4505                 return false;
4506             }
4507             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4508                 return false;
4509             }
4510             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4511                 return false;
4512             }
4513             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4514                 return false;
4515             }
4516             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4517                 return false;
4518             }
4519             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4520                 return false;
4521             }
4522             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4523                 return false;
4524             }
4525             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4526                 return false;
4527             }
4528             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4529                 return false;
4530             }
4531             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4532                 return false;
4533             }
4534             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4535             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4536                 return false;
4537             }
4538             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4539                 return false;
4540             }
4541             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4542                 return false;
4543             }
4544             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4545             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4546                 return false;
4547             }
4548             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4549                 return false;
4550             }
4551             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4552                 return false;
4553             }
4554             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4555             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4556                 return false;
4557             }
4558             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4559                 return false;
4560             }
4561             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4562                 return false;
4563             }
4564         }
4565         catch ( final Exception e ) {
4566             e.printStackTrace();
4567             return false;
4568         }
4569         return true;
4570     }
4571
4572     private static boolean testGeneralTable() {
4573         try {
4574             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4575             t0.setValue( 3, 2, "23" );
4576             t0.setValue( 10, 1, "error" );
4577             t0.setValue( 10, 1, "110" );
4578             t0.setValue( 9, 1, "19" );
4579             t0.setValue( 1, 10, "101" );
4580             t0.setValue( 10, 10, "1010" );
4581             t0.setValue( 100, 10, "10100" );
4582             t0.setValue( 0, 0, "00" );
4583             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4584                 return false;
4585             }
4586             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4587                 return false;
4588             }
4589             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4590                 return false;
4591             }
4592             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4593                 return false;
4594             }
4595             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4596                 return false;
4597             }
4598             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4599                 return false;
4600             }
4601             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4602                 return false;
4603             }
4604             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4605                 return false;
4606             }
4607             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4608                 return false;
4609             }
4610             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4611             t1.setValue( "3", "2", "23" );
4612             t1.setValue( "10", "1", "error" );
4613             t1.setValue( "10", "1", "110" );
4614             t1.setValue( "9", "1", "19" );
4615             t1.setValue( "1", "10", "101" );
4616             t1.setValue( "10", "10", "1010" );
4617             t1.setValue( "100", "10", "10100" );
4618             t1.setValue( "0", "0", "00" );
4619             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4620             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4621                 return false;
4622             }
4623             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4624                 return false;
4625             }
4626             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4627                 return false;
4628             }
4629             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4630                 return false;
4631             }
4632             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4633                 return false;
4634             }
4635             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4636                 return false;
4637             }
4638             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4639                 return false;
4640             }
4641             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4642                 return false;
4643             }
4644             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4645                 return false;
4646             }
4647             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4648                 return false;
4649             }
4650         }
4651         catch ( final Exception e ) {
4652             e.printStackTrace( System.out );
4653             return false;
4654         }
4655         return true;
4656     }
4657
4658     private static boolean testGetDistance() {
4659         try {
4660             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4661             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",
4662                                                  new NHXParser() )[ 0 ];
4663             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4664                 return false;
4665             }
4666             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4667                 return false;
4668             }
4669             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4670                 return false;
4671             }
4672             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4673                 return false;
4674             }
4675             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4676                 return false;
4677             }
4678             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4679                 return false;
4680             }
4681             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4682                 return false;
4683             }
4684             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4685                 return false;
4686             }
4687             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4688                 return false;
4689             }
4690             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4691                 return false;
4692             }
4693             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4694                 return false;
4695             }
4696             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4697                 return false;
4698             }
4699             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4700                 return false;
4701             }
4702             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4703                 return false;
4704             }
4705             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4706                 return false;
4707             }
4708             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4709                 return false;
4710             }
4711             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4712                 return false;
4713             }
4714             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4715                 return false;
4716             }
4717             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4718                 return false;
4719             }
4720             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4721                 return false;
4722             }
4723             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4724                 return false;
4725             }
4726             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4727                 return false;
4728             }
4729             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4730                 return false;
4731             }
4732             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4733                 return false;
4734             }
4735             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4736                 return false;
4737             }
4738             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4739                 return false;
4740             }
4741             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4742                 return false;
4743             }
4744             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4745                 return false;
4746             }
4747             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4748                 return false;
4749             }
4750             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4751                 return false;
4752             }
4753             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4754                 return false;
4755             }
4756             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",
4757                                                  new NHXParser() )[ 0 ];
4758             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4759                 return false;
4760             }
4761             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4762                 return false;
4763             }
4764             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4765                 return false;
4766             }
4767             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4768                 return false;
4769             }
4770             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4771                 return false;
4772             }
4773             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4774                 return false;
4775             }
4776             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4777                 return false;
4778             }
4779             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4780                 return false;
4781             }
4782             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4783                 return false;
4784             }
4785             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4786                 return false;
4787             }
4788             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4789                 return false;
4790             }
4791         }
4792         catch ( final Exception e ) {
4793             e.printStackTrace( System.out );
4794             return false;
4795         }
4796         return true;
4797     }
4798
4799     private static boolean testGetLCA() {
4800         try {
4801             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4802             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4803                                                  new NHXParser() )[ 0 ];
4804             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4805             if ( !A.getName().equals( "A" ) ) {
4806                 return false;
4807             }
4808             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4809             if ( !gh.getName().equals( "gh" ) ) {
4810                 return false;
4811             }
4812             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4813             if ( !ab.getName().equals( "ab" ) ) {
4814                 return false;
4815             }
4816             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4817             if ( !ab2.getName().equals( "ab" ) ) {
4818                 return false;
4819             }
4820             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4821             if ( !gh2.getName().equals( "gh" ) ) {
4822                 return false;
4823             }
4824             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4825             if ( !gh3.getName().equals( "gh" ) ) {
4826                 return false;
4827             }
4828             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4829             if ( !abc.getName().equals( "abc" ) ) {
4830                 return false;
4831             }
4832             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4833             if ( !abc2.getName().equals( "abc" ) ) {
4834                 return false;
4835             }
4836             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4837             if ( !abcd.getName().equals( "abcd" ) ) {
4838                 return false;
4839             }
4840             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4841             if ( !abcd2.getName().equals( "abcd" ) ) {
4842                 return false;
4843             }
4844             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4845             if ( !abcdef.getName().equals( "abcdef" ) ) {
4846                 return false;
4847             }
4848             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4849             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4850                 return false;
4851             }
4852             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4853             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4854                 return false;
4855             }
4856             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4857             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4858                 return false;
4859             }
4860             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4861             if ( !abcde.getName().equals( "abcde" ) ) {
4862                 return false;
4863             }
4864             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4865             if ( !abcde2.getName().equals( "abcde" ) ) {
4866                 return false;
4867             }
4868             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4869             if ( !r.getName().equals( "abcdefgh" ) ) {
4870                 return false;
4871             }
4872             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4873             if ( !r2.getName().equals( "abcdefgh" ) ) {
4874                 return false;
4875             }
4876             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4877             if ( !r3.getName().equals( "abcdefgh" ) ) {
4878                 return false;
4879             }
4880             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4881             if ( !abcde3.getName().equals( "abcde" ) ) {
4882                 return false;
4883             }
4884             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4885             if ( !abcde4.getName().equals( "abcde" ) ) {
4886                 return false;
4887             }
4888             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4889             if ( !ab3.getName().equals( "ab" ) ) {
4890                 return false;
4891             }
4892             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4893             if ( !ab4.getName().equals( "ab" ) ) {
4894                 return false;
4895             }
4896             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4897             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4898             if ( !cd.getName().equals( "cd" ) ) {
4899                 return false;
4900             }
4901             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4902             if ( !cd2.getName().equals( "cd" ) ) {
4903                 return false;
4904             }
4905             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4906             if ( !cde.getName().equals( "cde" ) ) {
4907                 return false;
4908             }
4909             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4910             if ( !cde2.getName().equals( "cde" ) ) {
4911                 return false;
4912             }
4913             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4914             if ( !cdef.getName().equals( "cdef" ) ) {
4915                 return false;
4916             }
4917             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4918             if ( !cdef2.getName().equals( "cdef" ) ) {
4919                 return false;
4920             }
4921             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4922             if ( !cdef3.getName().equals( "cdef" ) ) {
4923                 return false;
4924             }
4925             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4926             if ( !rt.getName().equals( "r" ) ) {
4927                 return false;
4928             }
4929             final Phylogeny p3 = factory
4930                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4931                              new NHXParser() )[ 0 ];
4932             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4933             if ( !bc_3.getName().equals( "bc" ) ) {
4934                 return false;
4935             }
4936             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4937             if ( !ac_3.getName().equals( "abc" ) ) {
4938                 return false;
4939             }
4940             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4941             if ( !ad_3.getName().equals( "abcde" ) ) {
4942                 return false;
4943             }
4944             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4945             if ( !af_3.getName().equals( "abcdef" ) ) {
4946                 return false;
4947             }
4948             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4949             if ( !ag_3.getName().equals( "" ) ) {
4950                 return false;
4951             }
4952             if ( !ag_3.isRoot() ) {
4953                 return false;
4954             }
4955             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4956             if ( !al_3.getName().equals( "" ) ) {
4957                 return false;
4958             }
4959             if ( !al_3.isRoot() ) {
4960                 return false;
4961             }
4962             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4963             if ( !kl_3.getName().equals( "" ) ) {
4964                 return false;
4965             }
4966             if ( !kl_3.isRoot() ) {
4967                 return false;
4968             }
4969             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4970             if ( !fl_3.getName().equals( "" ) ) {
4971                 return false;
4972             }
4973             if ( !fl_3.isRoot() ) {
4974                 return false;
4975             }
4976             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4977             if ( !gk_3.getName().equals( "ghijk" ) ) {
4978                 return false;
4979             }
4980             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4981             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4982             if ( !r_4.getName().equals( "r" ) ) {
4983                 return false;
4984             }
4985             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4986             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4987             if ( !r_5.getName().equals( "root" ) ) {
4988                 return false;
4989             }
4990             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4991             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4992             if ( !r_6.getName().equals( "rot" ) ) {
4993                 return false;
4994             }
4995             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4996             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4997             if ( !r_7.getName().equals( "rott" ) ) {
4998                 return false;
4999             }
5000         }
5001         catch ( final Exception e ) {
5002             e.printStackTrace( System.out );
5003             return false;
5004         }
5005         return true;
5006     }
5007
5008     private static boolean testGetLCA2() {
5009         try {
5010             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5011             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5012             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5013             PhylogenyMethods.preOrderReId( p_a );
5014             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5015                                                                                               p_a.getNode( "a" ) );
5016             if ( !p_a_1.getName().equals( "a" ) ) {
5017                 return false;
5018             }
5019             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5020             PhylogenyMethods.preOrderReId( p_b );
5021             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5022                                                                                               p_b.getNode( "a" ) );
5023             if ( !p_b_1.getName().equals( "b" ) ) {
5024                 return false;
5025             }
5026             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5027                                                                                               p_b.getNode( "b" ) );
5028             if ( !p_b_2.getName().equals( "b" ) ) {
5029                 return false;
5030             }
5031             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5032             PhylogenyMethods.preOrderReId( p_c );
5033             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5034                                                                                               p_c.getNode( "a" ) );
5035             if ( !p_c_1.getName().equals( "b" ) ) {
5036                 return false;
5037             }
5038             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5039                                                                                               p_c.getNode( "c" ) );
5040             if ( !p_c_2.getName().equals( "c" ) ) {
5041                 System.out.println( p_c_2.getName() );
5042                 System.exit( -1 );
5043                 return false;
5044             }
5045             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5046                                                                                               p_c.getNode( "b" ) );
5047             if ( !p_c_3.getName().equals( "b" ) ) {
5048                 return false;
5049             }
5050             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5051                                                                                               p_c.getNode( "a" ) );
5052             if ( !p_c_4.getName().equals( "c" ) ) {
5053                 return false;
5054             }
5055             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5056                                                  new NHXParser() )[ 0 ];
5057             PhylogenyMethods.preOrderReId( p1 );
5058             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5059                                                                                           p1.getNode( "A" ) );
5060             if ( !A.getName().equals( "A" ) ) {
5061                 return false;
5062             }
5063             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5064                                                                                            p1.getNode( "gh" ) );
5065             if ( !gh.getName().equals( "gh" ) ) {
5066                 return false;
5067             }
5068             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5069                                                                                            p1.getNode( "B" ) );
5070             if ( !ab.getName().equals( "ab" ) ) {
5071                 return false;
5072             }
5073             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5074                                                                                             p1.getNode( "A" ) );
5075             if ( !ab2.getName().equals( "ab" ) ) {
5076                 return false;
5077             }
5078             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5079                                                                                             p1.getNode( "G" ) );
5080             if ( !gh2.getName().equals( "gh" ) ) {
5081                 return false;
5082             }
5083             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5084                                                                                             p1.getNode( "H" ) );
5085             if ( !gh3.getName().equals( "gh" ) ) {
5086                 return false;
5087             }
5088             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5089                                                                                             p1.getNode( "A" ) );
5090             if ( !abc.getName().equals( "abc" ) ) {
5091                 return false;
5092             }
5093             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5094                                                                                              p1.getNode( "C" ) );
5095             if ( !abc2.getName().equals( "abc" ) ) {
5096                 return false;
5097             }
5098             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5099                                                                                              p1.getNode( "D" ) );
5100             if ( !abcd.getName().equals( "abcd" ) ) {
5101                 return false;
5102             }
5103             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5104                                                                                               p1.getNode( "A" ) );
5105             if ( !abcd2.getName().equals( "abcd" ) ) {
5106                 return false;
5107             }
5108             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5109                                                                                                p1.getNode( "F" ) );
5110             if ( !abcdef.getName().equals( "abcdef" ) ) {
5111                 return false;
5112             }
5113             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5114                                                                                                 p1.getNode( "A" ) );
5115             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5116                 return false;
5117             }
5118             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5119                                                                                                 p1.getNode( "F" ) );
5120             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5121                 return false;
5122             }
5123             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5124                                                                                                 p1.getNode( "ab" ) );
5125             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5126                 return false;
5127             }
5128             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5129                                                                                               p1.getNode( "E" ) );
5130             if ( !abcde.getName().equals( "abcde" ) ) {
5131                 return false;
5132             }
5133             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5134                                                                                                p1.getNode( "A" ) );
5135             if ( !abcde2.getName().equals( "abcde" ) ) {
5136                 return false;
5137             }
5138             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5139                                                                                           p1.getNode( "abcdefgh" ) );
5140             if ( !r.getName().equals( "abcdefgh" ) ) {
5141                 return false;
5142             }
5143             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5144                                                                                            p1.getNode( "H" ) );
5145             if ( !r2.getName().equals( "abcdefgh" ) ) {
5146                 return false;
5147             }
5148             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5149                                                                                            p1.getNode( "A" ) );
5150             if ( !r3.getName().equals( "abcdefgh" ) ) {
5151                 return false;
5152             }
5153             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5154                                                                                                p1.getNode( "abcde" ) );
5155             if ( !abcde3.getName().equals( "abcde" ) ) {
5156                 return false;
5157             }
5158             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5159                                                                                                p1.getNode( "E" ) );
5160             if ( !abcde4.getName().equals( "abcde" ) ) {
5161                 return false;
5162             }
5163             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5164                                                                                             p1.getNode( "B" ) );
5165             if ( !ab3.getName().equals( "ab" ) ) {
5166                 return false;
5167             }
5168             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5169                                                                                             p1.getNode( "ab" ) );
5170             if ( !ab4.getName().equals( "ab" ) ) {
5171                 return false;
5172             }
5173             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5174             PhylogenyMethods.preOrderReId( p2 );
5175             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5176                                                                                            p2.getNode( "d" ) );
5177             if ( !cd.getName().equals( "cd" ) ) {
5178                 return false;
5179             }
5180             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5181                                                                                             p2.getNode( "c" ) );
5182             if ( !cd2.getName().equals( "cd" ) ) {
5183                 return false;
5184             }
5185             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5186                                                                                             p2.getNode( "e" ) );
5187             if ( !cde.getName().equals( "cde" ) ) {
5188                 return false;
5189             }
5190             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5191                                                                                              p2.getNode( "c" ) );
5192             if ( !cde2.getName().equals( "cde" ) ) {
5193                 return false;
5194             }
5195             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5196                                                                                              p2.getNode( "f" ) );
5197             if ( !cdef.getName().equals( "cdef" ) ) {
5198                 return false;
5199             }
5200             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5201                                                                                               p2.getNode( "f" ) );
5202             if ( !cdef2.getName().equals( "cdef" ) ) {
5203                 return false;
5204             }
5205             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5206                                                                                               p2.getNode( "d" ) );
5207             if ( !cdef3.getName().equals( "cdef" ) ) {
5208                 return false;
5209             }
5210             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5211                                                                                            p2.getNode( "a" ) );
5212             if ( !rt.getName().equals( "r" ) ) {
5213                 return false;
5214             }
5215             final Phylogeny p3 = factory
5216                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5217                              new NHXParser() )[ 0 ];
5218             PhylogenyMethods.preOrderReId( p3 );
5219             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5220                                                                                              p3.getNode( "c" ) );
5221             if ( !bc_3.getName().equals( "bc" ) ) {
5222                 return false;
5223             }
5224             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5225                                                                                              p3.getNode( "c" ) );
5226             if ( !ac_3.getName().equals( "abc" ) ) {
5227                 return false;
5228             }
5229             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5230                                                                                              p3.getNode( "d" ) );
5231             if ( !ad_3.getName().equals( "abcde" ) ) {
5232                 return false;
5233             }
5234             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5235                                                                                              p3.getNode( "f" ) );
5236             if ( !af_3.getName().equals( "abcdef" ) ) {
5237                 return false;
5238             }
5239             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5240                                                                                              p3.getNode( "g" ) );
5241             if ( !ag_3.getName().equals( "" ) ) {
5242                 return false;
5243             }
5244             if ( !ag_3.isRoot() ) {
5245                 return false;
5246             }
5247             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5248                                                                                              p3.getNode( "l" ) );
5249             if ( !al_3.getName().equals( "" ) ) {
5250                 return false;
5251             }
5252             if ( !al_3.isRoot() ) {
5253                 return false;
5254             }
5255             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5256                                                                                              p3.getNode( "l" ) );
5257             if ( !kl_3.getName().equals( "" ) ) {
5258                 return false;
5259             }
5260             if ( !kl_3.isRoot() ) {
5261                 return false;
5262             }
5263             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5264                                                                                              p3.getNode( "l" ) );
5265             if ( !fl_3.getName().equals( "" ) ) {
5266                 return false;
5267             }
5268             if ( !fl_3.isRoot() ) {
5269                 return false;
5270             }
5271             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5272                                                                                              p3.getNode( "k" ) );
5273             if ( !gk_3.getName().equals( "ghijk" ) ) {
5274                 return false;
5275             }
5276             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5277             PhylogenyMethods.preOrderReId( p4 );
5278             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5279                                                                                             p4.getNode( "c" ) );
5280             if ( !r_4.getName().equals( "r" ) ) {
5281                 return false;
5282             }
5283             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5284             PhylogenyMethods.preOrderReId( p5 );
5285             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5286                                                                                             p5.getNode( "c" ) );
5287             if ( !r_5.getName().equals( "root" ) ) {
5288                 return false;
5289             }
5290             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5291             PhylogenyMethods.preOrderReId( p6 );
5292             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5293                                                                                             p6.getNode( "a" ) );
5294             if ( !r_6.getName().equals( "rot" ) ) {
5295                 return false;
5296             }
5297             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5298             PhylogenyMethods.preOrderReId( p7 );
5299             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5300                                                                                             p7.getNode( "e" ) );
5301             if ( !r_7.getName().equals( "rott" ) ) {
5302                 return false;
5303             }
5304             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5305                                                                                              p7.getNode( "a" ) );
5306             if ( !r_71.getName().equals( "rott" ) ) {
5307                 return false;
5308             }
5309             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5310                                                                                              p7.getNode( "rott" ) );
5311             if ( !r_72.getName().equals( "rott" ) ) {
5312                 return false;
5313             }
5314             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5315                                                                                              p7.getNode( "a" ) );
5316             if ( !r_73.getName().equals( "rott" ) ) {
5317                 return false;
5318             }
5319             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5320                                                                                              p7.getNode( "rott" ) );
5321             if ( !r_74.getName().equals( "rott" ) ) {
5322                 return false;
5323             }
5324             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5325                                                                                              p7.getNode( "e" ) );
5326             if ( !r_75.getName().equals( "e" ) ) {
5327                 return false;
5328             }
5329         }
5330         catch ( final Exception e ) {
5331             e.printStackTrace( System.out );
5332             return false;
5333         }
5334         return true;
5335     }
5336
5337     private static boolean testHmmscanOutputParser() {
5338         final String test_dir = Test.PATH_TO_TEST_DATA;
5339         try {
5340             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5341                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5342             parser1.parse();
5343             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5344                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5345             final List<Protein> proteins = parser2.parse();
5346             if ( parser2.getProteinsEncountered() != 4 ) {
5347                 return false;
5348             }
5349             if ( proteins.size() != 4 ) {
5350                 return false;
5351             }
5352             if ( parser2.getDomainsEncountered() != 69 ) {
5353                 return false;
5354             }
5355             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5356                 return false;
5357             }
5358             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5359                 return false;
5360             }
5361             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5362                 return false;
5363             }
5364             final Protein p1 = proteins.get( 0 );
5365             if ( p1.getNumberOfProteinDomains() != 15 ) {
5366                 return false;
5367             }
5368             if ( p1.getLength() != 850 ) {
5369                 return false;
5370             }
5371             final Protein p2 = proteins.get( 1 );
5372             if ( p2.getNumberOfProteinDomains() != 51 ) {
5373                 return false;
5374             }
5375             if ( p2.getLength() != 1291 ) {
5376                 return false;
5377             }
5378             final Protein p3 = proteins.get( 2 );
5379             if ( p3.getNumberOfProteinDomains() != 2 ) {
5380                 return false;
5381             }
5382             final Protein p4 = proteins.get( 3 );
5383             if ( p4.getNumberOfProteinDomains() != 1 ) {
5384                 return false;
5385             }
5386             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5387                 return false;
5388             }
5389             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5390                 return false;
5391             }
5392             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5393                 return false;
5394             }
5395             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5396                 return false;
5397             }
5398             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5399                 return false;
5400             }
5401             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5402                 return false;
5403             }
5404             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5405                 return false;
5406             }
5407         }
5408         catch ( final Exception e ) {
5409             e.printStackTrace( System.out );
5410             return false;
5411         }
5412         return true;
5413     }
5414
5415     private static boolean testLastExternalNodeMethods() {
5416         try {
5417             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5418             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5419             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5420             final PhylogenyNode n1 = t0.getNode( "A" );
5421             if ( n1.isLastExternalNode() ) {
5422                 return false;
5423             }
5424             final PhylogenyNode n2 = t0.getNode( "B" );
5425             if ( n2.isLastExternalNode() ) {
5426                 return false;
5427             }
5428             final PhylogenyNode n3 = t0.getNode( "C" );
5429             if ( n3.isLastExternalNode() ) {
5430                 return false;
5431             }
5432             final PhylogenyNode n4 = t0.getNode( "D" );
5433             if ( !n4.isLastExternalNode() ) {
5434                 return false;
5435             }
5436         }
5437         catch ( final Exception e ) {
5438             e.printStackTrace( System.out );
5439             return false;
5440         }
5441         return true;
5442     }
5443
5444     private static boolean testLevelOrderIterator() {
5445         try {
5446             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5447             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5448             PhylogenyNodeIterator it0;
5449             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5450                 it0.next();
5451             }
5452             for( it0.reset(); it0.hasNext(); ) {
5453                 it0.next();
5454             }
5455             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5456             if ( !it.next().getName().equals( "r" ) ) {
5457                 return false;
5458             }
5459             if ( !it.next().getName().equals( "ab" ) ) {
5460                 return false;
5461             }
5462             if ( !it.next().getName().equals( "cd" ) ) {
5463                 return false;
5464             }
5465             if ( !it.next().getName().equals( "A" ) ) {
5466                 return false;
5467             }
5468             if ( !it.next().getName().equals( "B" ) ) {
5469                 return false;
5470             }
5471             if ( !it.next().getName().equals( "C" ) ) {
5472                 return false;
5473             }
5474             if ( !it.next().getName().equals( "D" ) ) {
5475                 return false;
5476             }
5477             if ( it.hasNext() ) {
5478                 return false;
5479             }
5480             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",
5481                                                  new NHXParser() )[ 0 ];
5482             PhylogenyNodeIterator it2;
5483             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5484                 it2.next();
5485             }
5486             for( it2.reset(); it2.hasNext(); ) {
5487                 it2.next();
5488             }
5489             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5490             if ( !it3.next().getName().equals( "r" ) ) {
5491                 return false;
5492             }
5493             if ( !it3.next().getName().equals( "abc" ) ) {
5494                 return false;
5495             }
5496             if ( !it3.next().getName().equals( "defg" ) ) {
5497                 return false;
5498             }
5499             if ( !it3.next().getName().equals( "A" ) ) {
5500                 return false;
5501             }
5502             if ( !it3.next().getName().equals( "B" ) ) {
5503                 return false;
5504             }
5505             if ( !it3.next().getName().equals( "C" ) ) {
5506                 return false;
5507             }
5508             if ( !it3.next().getName().equals( "D" ) ) {
5509                 return false;
5510             }
5511             if ( !it3.next().getName().equals( "E" ) ) {
5512                 return false;
5513             }
5514             if ( !it3.next().getName().equals( "F" ) ) {
5515                 return false;
5516             }
5517             if ( !it3.next().getName().equals( "G" ) ) {
5518                 return false;
5519             }
5520             if ( !it3.next().getName().equals( "1" ) ) {
5521                 return false;
5522             }
5523             if ( !it3.next().getName().equals( "2" ) ) {
5524                 return false;
5525             }
5526             if ( !it3.next().getName().equals( "3" ) ) {
5527                 return false;
5528             }
5529             if ( !it3.next().getName().equals( "4" ) ) {
5530                 return false;
5531             }
5532             if ( !it3.next().getName().equals( "5" ) ) {
5533                 return false;
5534             }
5535             if ( !it3.next().getName().equals( "6" ) ) {
5536                 return false;
5537             }
5538             if ( !it3.next().getName().equals( "f1" ) ) {
5539                 return false;
5540             }
5541             if ( !it3.next().getName().equals( "f2" ) ) {
5542                 return false;
5543             }
5544             if ( !it3.next().getName().equals( "f3" ) ) {
5545                 return false;
5546             }
5547             if ( !it3.next().getName().equals( "a" ) ) {
5548                 return false;
5549             }
5550             if ( !it3.next().getName().equals( "b" ) ) {
5551                 return false;
5552             }
5553             if ( !it3.next().getName().equals( "f21" ) ) {
5554                 return false;
5555             }
5556             if ( !it3.next().getName().equals( "X" ) ) {
5557                 return false;
5558             }
5559             if ( !it3.next().getName().equals( "Y" ) ) {
5560                 return false;
5561             }
5562             if ( !it3.next().getName().equals( "Z" ) ) {
5563                 return false;
5564             }
5565             if ( it3.hasNext() ) {
5566                 return false;
5567             }
5568             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5569             PhylogenyNodeIterator it4;
5570             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5571                 it4.next();
5572             }
5573             for( it4.reset(); it4.hasNext(); ) {
5574                 it4.next();
5575             }
5576             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5577             if ( !it5.next().getName().equals( "r" ) ) {
5578                 return false;
5579             }
5580             if ( !it5.next().getName().equals( "A" ) ) {
5581                 return false;
5582             }
5583             if ( !it5.next().getName().equals( "B" ) ) {
5584                 return false;
5585             }
5586             if ( !it5.next().getName().equals( "C" ) ) {
5587                 return false;
5588             }
5589             if ( !it5.next().getName().equals( "D" ) ) {
5590                 return false;
5591             }
5592             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5593             PhylogenyNodeIterator it6;
5594             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5595                 it6.next();
5596             }
5597             for( it6.reset(); it6.hasNext(); ) {
5598                 it6.next();
5599             }
5600             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5601             if ( !it7.next().getName().equals( "A" ) ) {
5602                 return false;
5603             }
5604             if ( it.hasNext() ) {
5605                 return false;
5606             }
5607         }
5608         catch ( final Exception e ) {
5609             e.printStackTrace( System.out );
5610             return false;
5611         }
5612         return true;
5613     }
5614
5615     private static boolean testMafft( final String path ) {
5616         try {
5617             final List<String> opts = new ArrayList<String>();
5618             opts.add( "--maxiterate" );
5619             opts.add( "1000" );
5620             opts.add( "--localpair" );
5621             opts.add( "--quiet" );
5622             Msa msa = null;
5623             final MsaInferrer mafft = Mafft.createInstance( path );
5624             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5625             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5626                 return false;
5627             }
5628             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5629                 return false;
5630             }
5631         }
5632         catch ( final Exception e ) {
5633             e.printStackTrace( System.out );
5634             return false;
5635         }
5636         return true;
5637     }
5638
5639     private static boolean testMidpointrooting() {
5640         try {
5641             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5642             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5643             PhylogenyMethods.midpointRoot( t0 );
5644             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5645                 return false;
5646             }
5647             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5648                 return false;
5649             }
5650             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5651                            1 ) ) {
5652                 return false;
5653             }
5654             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",
5655                                                  new NHXParser() )[ 0 ];
5656             if ( !t1.isRooted() ) {
5657                 return false;
5658             }
5659             PhylogenyMethods.midpointRoot( t1 );
5660             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5661                 return false;
5662             }
5663             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5664                 return false;
5665             }
5666             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5667                 return false;
5668             }
5669             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5670                 return false;
5671             }
5672             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5673                 return false;
5674             }
5675             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5676                 return false;
5677             }
5678             t1.reRoot( t1.getNode( "A" ) );
5679             PhylogenyMethods.midpointRoot( t1 );
5680             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5681                 return false;
5682             }
5683             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5684                 return false;
5685             }
5686             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5687                 return false;
5688             }
5689             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5690                 return false;
5691             }
5692             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5693                 System.exit( -1 );
5694                 return false;
5695             }
5696             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5697                 return false;
5698             }
5699         }
5700         catch ( final Exception e ) {
5701             e.printStackTrace( System.out );
5702             return false;
5703         }
5704         return true;
5705     }
5706
5707     private static boolean testMsaQualityMethod() {
5708         try {
5709             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5710             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5711             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5712             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5713             final List<Sequence> l = new ArrayList<Sequence>();
5714             l.add( s0 );
5715             l.add( s1 );
5716             l.add( s2 );
5717             l.add( s3 );
5718             final Msa msa = BasicMsa.createInstance( l );
5719             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5720                 return false;
5721             }
5722             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5723                 return false;
5724             }
5725             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5726                 return false;
5727             }
5728             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5729                 return false;
5730             }
5731         }
5732         catch ( final Exception e ) {
5733             e.printStackTrace( System.out );
5734             return false;
5735         }
5736         return true;
5737     }
5738
5739     private static boolean testNextNodeWithCollapsing() {
5740         try {
5741             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5742             PhylogenyNode n;
5743             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5744             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5745             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5746             t0.getNode( "cd" ).setCollapse( true );
5747             t0.getNode( "cde" ).setCollapse( true );
5748             n = t0.getFirstExternalNode();
5749             while ( n != null ) {
5750                 ext.add( n );
5751                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5752             }
5753             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5754                 return false;
5755             }
5756             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5757                 return false;
5758             }
5759             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5760                 return false;
5761             }
5762             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5763                 return false;
5764             }
5765             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5766                 return false;
5767             }
5768             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5769                 return false;
5770             }
5771             ext.clear();
5772             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5773             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5774             t1.getNode( "ab" ).setCollapse( true );
5775             t1.getNode( "cd" ).setCollapse( true );
5776             t1.getNode( "cde" ).setCollapse( true );
5777             n = t1.getNode( "ab" );
5778             ext = new ArrayList<PhylogenyNode>();
5779             while ( n != null ) {
5780                 ext.add( n );
5781                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5782             }
5783             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5784                 return false;
5785             }
5786             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5787                 return false;
5788             }
5789             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5790                 return false;
5791             }
5792             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5793                 return false;
5794             }
5795             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5796                 return false;
5797             }
5798             //
5799             //
5800             ext.clear();
5801             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5802             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5803             t2.getNode( "ab" ).setCollapse( true );
5804             t2.getNode( "cd" ).setCollapse( true );
5805             t2.getNode( "cde" ).setCollapse( true );
5806             t2.getNode( "c" ).setCollapse( true );
5807             t2.getNode( "d" ).setCollapse( true );
5808             t2.getNode( "e" ).setCollapse( true );
5809             t2.getNode( "gh" ).setCollapse( true );
5810             n = t2.getNode( "ab" );
5811             ext = new ArrayList<PhylogenyNode>();
5812             while ( n != null ) {
5813                 ext.add( n );
5814                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5815             }
5816             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5817                 return false;
5818             }
5819             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5820                 return false;
5821             }
5822             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5823                 return false;
5824             }
5825             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5826                 return false;
5827             }
5828             //
5829             //
5830             ext.clear();
5831             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5832             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5833             t3.getNode( "ab" ).setCollapse( true );
5834             t3.getNode( "cd" ).setCollapse( true );
5835             t3.getNode( "cde" ).setCollapse( true );
5836             t3.getNode( "c" ).setCollapse( true );
5837             t3.getNode( "d" ).setCollapse( true );
5838             t3.getNode( "e" ).setCollapse( true );
5839             t3.getNode( "gh" ).setCollapse( true );
5840             t3.getNode( "fgh" ).setCollapse( true );
5841             n = t3.getNode( "ab" );
5842             ext = new ArrayList<PhylogenyNode>();
5843             while ( n != null ) {
5844                 ext.add( n );
5845                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5846             }
5847             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5848                 return false;
5849             }
5850             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5851                 return false;
5852             }
5853             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5854                 return false;
5855             }
5856             //
5857             //
5858             ext.clear();
5859             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5860             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5861             t4.getNode( "ab" ).setCollapse( true );
5862             t4.getNode( "cd" ).setCollapse( true );
5863             t4.getNode( "cde" ).setCollapse( true );
5864             t4.getNode( "c" ).setCollapse( true );
5865             t4.getNode( "d" ).setCollapse( true );
5866             t4.getNode( "e" ).setCollapse( true );
5867             t4.getNode( "gh" ).setCollapse( true );
5868             t4.getNode( "fgh" ).setCollapse( true );
5869             t4.getNode( "abcdefgh" ).setCollapse( true );
5870             n = t4.getNode( "abcdefgh" );
5871             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5872                 return false;
5873             }
5874             //
5875             //
5876             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5877             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5878             ext.clear();
5879             n = t5.getFirstExternalNode();
5880             while ( n != null ) {
5881                 ext.add( n );
5882                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5883             }
5884             if ( ext.size() != 8 ) {
5885                 return false;
5886             }
5887             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5888                 return false;
5889             }
5890             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5891                 return false;
5892             }
5893             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5894                 return false;
5895             }
5896             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5897                 return false;
5898             }
5899             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5900                 return false;
5901             }
5902             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5903                 return false;
5904             }
5905             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5906                 return false;
5907             }
5908             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5909                 return false;
5910             }
5911             //
5912             //
5913             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5914             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5915             ext.clear();
5916             t6.getNode( "ab" ).setCollapse( true );
5917             n = t6.getNode( "ab" );
5918             while ( n != null ) {
5919                 ext.add( n );
5920                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5921             }
5922             if ( ext.size() != 7 ) {
5923                 return false;
5924             }
5925             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5926                 return false;
5927             }
5928             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5929                 return false;
5930             }
5931             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5932                 return false;
5933             }
5934             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5935                 return false;
5936             }
5937             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5938                 return false;
5939             }
5940             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5941                 return false;
5942             }
5943             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5944                 return false;
5945             }
5946             //
5947             //
5948             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5949             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5950             ext.clear();
5951             t7.getNode( "cd" ).setCollapse( true );
5952             n = t7.getNode( "a" );
5953             while ( n != null ) {
5954                 ext.add( n );
5955                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5956             }
5957             if ( ext.size() != 7 ) {
5958                 return false;
5959             }
5960             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5961                 return false;
5962             }
5963             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5964                 return false;
5965             }
5966             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5967                 return false;
5968             }
5969             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5970                 return false;
5971             }
5972             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5973                 return false;
5974             }
5975             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5976                 return false;
5977             }
5978             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5979                 return false;
5980             }
5981             //
5982             //
5983             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5984             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5985             ext.clear();
5986             t8.getNode( "cd" ).setCollapse( true );
5987             t8.getNode( "c" ).setCollapse( true );
5988             t8.getNode( "d" ).setCollapse( true );
5989             n = t8.getNode( "a" );
5990             while ( n != null ) {
5991                 ext.add( n );
5992                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5993             }
5994             if ( ext.size() != 7 ) {
5995                 return false;
5996             }
5997             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5998                 return false;
5999             }
6000             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6001                 return false;
6002             }
6003             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6004                 System.out.println( "2 fail" );
6005                 return false;
6006             }
6007             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6008                 return false;
6009             }
6010             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6011                 return false;
6012             }
6013             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6014                 return false;
6015             }
6016             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6017                 return false;
6018             }
6019             //
6020             //
6021             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6022             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6023             ext.clear();
6024             t9.getNode( "gh" ).setCollapse( true );
6025             n = t9.getNode( "a" );
6026             while ( n != null ) {
6027                 ext.add( n );
6028                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6029             }
6030             if ( ext.size() != 7 ) {
6031                 return false;
6032             }
6033             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6034                 return false;
6035             }
6036             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6037                 return false;
6038             }
6039             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6040                 return false;
6041             }
6042             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6043                 return false;
6044             }
6045             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6046                 return false;
6047             }
6048             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6049                 return false;
6050             }
6051             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6052                 return false;
6053             }
6054             //
6055             //
6056             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6057             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6058             ext.clear();
6059             t10.getNode( "gh" ).setCollapse( true );
6060             t10.getNode( "g" ).setCollapse( true );
6061             t10.getNode( "h" ).setCollapse( true );
6062             n = t10.getNode( "a" );
6063             while ( n != null ) {
6064                 ext.add( n );
6065                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6066             }
6067             if ( ext.size() != 7 ) {
6068                 return false;
6069             }
6070             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6071                 return false;
6072             }
6073             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6074                 return false;
6075             }
6076             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6077                 return false;
6078             }
6079             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6080                 return false;
6081             }
6082             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6083                 return false;
6084             }
6085             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6086                 return false;
6087             }
6088             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6089                 return false;
6090             }
6091             //
6092             //
6093             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6094             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6095             ext.clear();
6096             t11.getNode( "gh" ).setCollapse( true );
6097             t11.getNode( "fgh" ).setCollapse( true );
6098             n = t11.getNode( "a" );
6099             while ( n != null ) {
6100                 ext.add( n );
6101                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6102             }
6103             if ( ext.size() != 6 ) {
6104                 return false;
6105             }
6106             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6107                 return false;
6108             }
6109             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6110                 return false;
6111             }
6112             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6113                 return false;
6114             }
6115             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6116                 return false;
6117             }
6118             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6119                 return false;
6120             }
6121             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6122                 return false;
6123             }
6124             //
6125             //
6126             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6127             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6128             ext.clear();
6129             t12.getNode( "gh" ).setCollapse( true );
6130             t12.getNode( "fgh" ).setCollapse( true );
6131             t12.getNode( "g" ).setCollapse( true );
6132             t12.getNode( "h" ).setCollapse( true );
6133             t12.getNode( "f" ).setCollapse( true );
6134             n = t12.getNode( "a" );
6135             while ( n != null ) {
6136                 ext.add( n );
6137                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6138             }
6139             if ( ext.size() != 6 ) {
6140                 return false;
6141             }
6142             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6143                 return false;
6144             }
6145             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6146                 return false;
6147             }
6148             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6149                 return false;
6150             }
6151             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6152                 return false;
6153             }
6154             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6155                 return false;
6156             }
6157             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6158                 return false;
6159             }
6160             //
6161             //
6162             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6163             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6164             ext.clear();
6165             t13.getNode( "ab" ).setCollapse( true );
6166             t13.getNode( "b" ).setCollapse( true );
6167             t13.getNode( "fgh" ).setCollapse( true );
6168             t13.getNode( "gh" ).setCollapse( true );
6169             n = t13.getNode( "ab" );
6170             while ( n != null ) {
6171                 ext.add( n );
6172                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6173             }
6174             if ( ext.size() != 5 ) {
6175                 return false;
6176             }
6177             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6178                 return false;
6179             }
6180             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6181                 return false;
6182             }
6183             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6184                 return false;
6185             }
6186             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6187                 return false;
6188             }
6189             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6190                 return false;
6191             }
6192             //
6193             //
6194             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6195             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6196             ext.clear();
6197             t14.getNode( "ab" ).setCollapse( true );
6198             t14.getNode( "a" ).setCollapse( true );
6199             t14.getNode( "fgh" ).setCollapse( true );
6200             t14.getNode( "gh" ).setCollapse( true );
6201             n = t14.getNode( "ab" );
6202             while ( n != null ) {
6203                 ext.add( n );
6204                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6205             }
6206             if ( ext.size() != 5 ) {
6207                 return false;
6208             }
6209             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6210                 return false;
6211             }
6212             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6213                 return false;
6214             }
6215             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6216                 return false;
6217             }
6218             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6219                 return false;
6220             }
6221             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6222                 return false;
6223             }
6224             //
6225             //
6226             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" );
6227             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6228             ext.clear();
6229             t15.getNode( "ab" ).setCollapse( true );
6230             t15.getNode( "a" ).setCollapse( true );
6231             t15.getNode( "fgh" ).setCollapse( true );
6232             t15.getNode( "gh" ).setCollapse( true );
6233             n = t15.getNode( "ab" );
6234             while ( n != null ) {
6235                 ext.add( n );
6236                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6237             }
6238             if ( ext.size() != 6 ) {
6239                 return false;
6240             }
6241             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6242                 return false;
6243             }
6244             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6245                 return false;
6246             }
6247             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6248                 return false;
6249             }
6250             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6251                 return false;
6252             }
6253             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6254                 return false;
6255             }
6256             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6257                 return false;
6258             }
6259             //
6260             //
6261             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" );
6262             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6263             ext.clear();
6264             t16.getNode( "ab" ).setCollapse( true );
6265             t16.getNode( "a" ).setCollapse( true );
6266             t16.getNode( "fgh" ).setCollapse( true );
6267             t16.getNode( "gh" ).setCollapse( true );
6268             t16.getNode( "cd" ).setCollapse( true );
6269             t16.getNode( "cde" ).setCollapse( true );
6270             t16.getNode( "d" ).setCollapse( true );
6271             t16.getNode( "x" ).setCollapse( true );
6272             n = t16.getNode( "ab" );
6273             while ( n != null ) {
6274                 ext.add( n );
6275                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6276             }
6277             if ( ext.size() != 4 ) {
6278                 return false;
6279             }
6280             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6281                 return false;
6282             }
6283             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6284                 return false;
6285             }
6286             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6287                 return false;
6288             }
6289             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6290                 return false;
6291             }
6292         }
6293         catch ( final Exception e ) {
6294             e.printStackTrace( System.out );
6295             return false;
6296         }
6297         return true;
6298     }
6299
6300     private static boolean testNexusCharactersParsing() {
6301         try {
6302             final NexusCharactersParser parser = new NexusCharactersParser();
6303             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6304             parser.parse();
6305             String[] labels = parser.getCharStateLabels();
6306             if ( labels.length != 7 ) {
6307                 return false;
6308             }
6309             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6310                 return false;
6311             }
6312             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6313                 return false;
6314             }
6315             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6316                 return false;
6317             }
6318             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6319                 return false;
6320             }
6321             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6322                 return false;
6323             }
6324             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6325                 return false;
6326             }
6327             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6328                 return false;
6329             }
6330             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6331             parser.parse();
6332             labels = parser.getCharStateLabels();
6333             if ( labels.length != 7 ) {
6334                 return false;
6335             }
6336             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6337                 return false;
6338             }
6339             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6340                 return false;
6341             }
6342             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6343                 return false;
6344             }
6345             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6346                 return false;
6347             }
6348             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6349                 return false;
6350             }
6351             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6352                 return false;
6353             }
6354             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6355                 return false;
6356             }
6357         }
6358         catch ( final Exception e ) {
6359             e.printStackTrace( System.out );
6360             return false;
6361         }
6362         return true;
6363     }
6364
6365     private static boolean testNexusMatrixParsing() {
6366         try {
6367             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6368             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6369             parser.parse();
6370             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6371             if ( m.getNumberOfCharacters() != 9 ) {
6372                 return false;
6373             }
6374             if ( m.getNumberOfIdentifiers() != 5 ) {
6375                 return false;
6376             }
6377             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6378                 return false;
6379             }
6380             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6381                 return false;
6382             }
6383             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6384                 return false;
6385             }
6386             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6387                 return false;
6388             }
6389             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6390                 return false;
6391             }
6392             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6393                 return false;
6394             }
6395             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6396                 return false;
6397             }
6398             //            if ( labels.length != 7 ) {
6399             //                return false;
6400             //            }
6401             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6402             //                return false;
6403             //            }
6404             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6405             //                return false;
6406             //            }
6407             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6408             //                return false;
6409             //            }
6410             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6411             //                return false;
6412             //            }
6413             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6414             //                return false;
6415             //            }
6416             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6417             //                return false;
6418             //            }
6419             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6420             //                return false;
6421             //            }
6422             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6423             //            parser.parse();
6424             //            labels = parser.getCharStateLabels();
6425             //            if ( labels.length != 7 ) {
6426             //                return false;
6427             //            }
6428             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6429             //                return false;
6430             //            }
6431             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6432             //                return false;
6433             //            }
6434             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6435             //                return false;
6436             //            }
6437             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6438             //                return false;
6439             //            }
6440             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6441             //                return false;
6442             //            }
6443             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6444             //                return false;
6445             //            }
6446             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6447             //                return false;
6448             //            }
6449         }
6450         catch ( final Exception e ) {
6451             e.printStackTrace( System.out );
6452             return false;
6453         }
6454         return true;
6455     }
6456
6457     private static boolean testNexusTreeParsing() {
6458         try {
6459             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6460             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6461             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6462             if ( phylogenies.length != 1 ) {
6463                 return false;
6464             }
6465             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6466                 return false;
6467             }
6468             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6469                 return false;
6470             }
6471             phylogenies = null;
6472             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6473             if ( phylogenies.length != 1 ) {
6474                 return false;
6475             }
6476             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6477                 return false;
6478             }
6479             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6480                 return false;
6481             }
6482             phylogenies = null;
6483             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6484             if ( phylogenies.length != 1 ) {
6485                 return false;
6486             }
6487             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6488                 return false;
6489             }
6490             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6491                 return false;
6492             }
6493             if ( phylogenies[ 0 ].isRooted() ) {
6494                 return false;
6495             }
6496             phylogenies = null;
6497             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6498             if ( phylogenies.length != 18 ) {
6499                 return false;
6500             }
6501             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6502                 return false;
6503             }
6504             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6505                 return false;
6506             }
6507             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6508                 return false;
6509             }
6510             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6511                 return false;
6512             }
6513             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6514                 return false;
6515             }
6516             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6517                 return false;
6518             }
6519             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6520                 return false;
6521             }
6522             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6523                 return false;
6524             }
6525             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6526                 return false;
6527             }
6528             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6529                 return false;
6530             }
6531             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6532                 return false;
6533             }
6534             if ( phylogenies[ 8 ].isRooted() ) {
6535                 return false;
6536             }
6537             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6538                 return false;
6539             }
6540             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6541                 return false;
6542             }
6543             if ( !phylogenies[ 9 ].isRooted() ) {
6544                 return false;
6545             }
6546             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6547                 return false;
6548             }
6549             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6550                 return false;
6551             }
6552             if ( !phylogenies[ 10 ].isRooted() ) {
6553                 return false;
6554             }
6555             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6556                 return false;
6557             }
6558             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6559                 return false;
6560             }
6561             if ( phylogenies[ 11 ].isRooted() ) {
6562                 return false;
6563             }
6564             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6565                 return false;
6566             }
6567             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6568                 return false;
6569             }
6570             if ( !phylogenies[ 12 ].isRooted() ) {
6571                 return false;
6572             }
6573             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6574                 return false;
6575             }
6576             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6577                 return false;
6578             }
6579             if ( !phylogenies[ 13 ].isRooted() ) {
6580                 return false;
6581             }
6582             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6583                 return false;
6584             }
6585             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6586                 return false;
6587             }
6588             if ( !phylogenies[ 14 ].isRooted() ) {
6589                 return false;
6590             }
6591             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6592                 return false;
6593             }
6594             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6595                 return false;
6596             }
6597             if ( phylogenies[ 15 ].isRooted() ) {
6598                 return false;
6599             }
6600             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6601                 return false;
6602             }
6603             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6604                 return false;
6605             }
6606             if ( !phylogenies[ 16 ].isRooted() ) {
6607                 return false;
6608             }
6609             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6610                 return false;
6611             }
6612             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6613                 return false;
6614             }
6615             if ( phylogenies[ 17 ].isRooted() ) {
6616                 return false;
6617             }
6618             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6619                 return false;
6620             }
6621         }
6622         catch ( final Exception e ) {
6623             e.printStackTrace( System.out );
6624             return false;
6625         }
6626         return true;
6627     }
6628
6629     private static boolean testNexusTreeParsingIterating() {
6630         try {
6631             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6632             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6633             if ( !p.hasNext() ) {
6634                 return false;
6635             }
6636             Phylogeny phy = p.next();
6637             if ( phy == null ) {
6638                 return false;
6639             }
6640             if ( phy.getNumberOfExternalNodes() != 25 ) {
6641                 return false;
6642             }
6643             if ( !phy.getName().equals( "" ) ) {
6644                 return false;
6645             }
6646             if ( p.hasNext() ) {
6647                 return false;
6648             }
6649             phy = p.next();
6650             if ( phy != null ) {
6651                 return false;
6652             }
6653             //
6654             p.reset();
6655             if ( !p.hasNext() ) {
6656                 return false;
6657             }
6658             phy = p.next();
6659             if ( phy == null ) {
6660                 return false;
6661             }
6662             if ( phy.getNumberOfExternalNodes() != 25 ) {
6663                 return false;
6664             }
6665             if ( !phy.getName().equals( "" ) ) {
6666                 return false;
6667             }
6668             if ( p.hasNext() ) {
6669                 return false;
6670             }
6671             phy = p.next();
6672             if ( phy != null ) {
6673                 return false;
6674             }
6675             ////
6676             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6677             if ( !p.hasNext() ) {
6678                 return false;
6679             }
6680             phy = p.next();
6681             if ( phy == null ) {
6682                 return false;
6683             }
6684             if ( phy.getNumberOfExternalNodes() != 10 ) {
6685                 return false;
6686             }
6687             if ( !phy.getName().equals( "name" ) ) {
6688                 return false;
6689             }
6690             if ( p.hasNext() ) {
6691                 return false;
6692             }
6693             phy = p.next();
6694             if ( phy != null ) {
6695                 return false;
6696             }
6697             //
6698             p.reset();
6699             if ( !p.hasNext() ) {
6700                 return false;
6701             }
6702             phy = p.next();
6703             if ( phy == null ) {
6704                 return false;
6705             }
6706             if ( phy.getNumberOfExternalNodes() != 10 ) {
6707                 return false;
6708             }
6709             if ( !phy.getName().equals( "name" ) ) {
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.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
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 ( phy.isRooted() ) {
6735                 return false;
6736             }
6737             if ( p.hasNext() ) {
6738                 return false;
6739             }
6740             phy = p.next();
6741             if ( phy != null ) {
6742                 return false;
6743             }
6744             //
6745             p.reset();
6746             if ( !p.hasNext() ) {
6747                 return false;
6748             }
6749             phy = p.next();
6750             if ( phy == null ) {
6751                 return false;
6752             }
6753             if ( phy.getNumberOfExternalNodes() != 3 ) {
6754                 return false;
6755             }
6756             if ( !phy.getName().equals( "" ) ) {
6757                 return false;
6758             }
6759             if ( p.hasNext() ) {
6760                 return false;
6761             }
6762             phy = p.next();
6763             if ( phy != null ) {
6764                 return false;
6765             }
6766             ////
6767             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6768             //            if ( phylogenies.length != 18 ) {
6769             //                return false;
6770             //            }
6771             //0
6772             if ( !p.hasNext() ) {
6773                 return false;
6774             }
6775             phy = p.next();
6776             if ( phy == null ) {
6777                 return false;
6778             }
6779             if ( phy.getNumberOfExternalNodes() != 10 ) {
6780                 return false;
6781             }
6782             if ( !phy.getName().equals( "tree 0" ) ) {
6783                 return false;
6784             }
6785             //1
6786             if ( !p.hasNext() ) {
6787                 return false;
6788             }
6789             phy = p.next();
6790             if ( phy == null ) {
6791                 return false;
6792             }
6793             if ( phy.getNumberOfExternalNodes() != 10 ) {
6794                 return false;
6795             }
6796             if ( !phy.getName().equals( "tree 1" ) ) {
6797                 return false;
6798             }
6799             //2
6800             if ( !p.hasNext() ) {
6801                 return false;
6802             }
6803             phy = p.next();
6804             if ( phy == null ) {
6805                 return false;
6806             }
6807             if ( phy.getNumberOfExternalNodes() != 3 ) {
6808                 return false;
6809             }
6810             if ( !phy.getName().equals( "" ) ) {
6811                 return false;
6812             }
6813             if ( phy.isRooted() ) {
6814                 return false;
6815             }
6816             //3
6817             if ( !p.hasNext() ) {
6818                 return false;
6819             }
6820             phy = p.next();
6821             if ( phy == null ) {
6822                 return false;
6823             }
6824             if ( phy.getNumberOfExternalNodes() != 4 ) {
6825                 return false;
6826             }
6827             if ( !phy.getName().equals( "" ) ) {
6828                 return false;
6829             }
6830             if ( !phy.isRooted() ) {
6831                 return false;
6832             }
6833             //4
6834             if ( !p.hasNext() ) {
6835                 return false;
6836             }
6837             phy = p.next();
6838             if ( phy == null ) {
6839                 return false;
6840             }
6841             if ( phy.getNumberOfExternalNodes() != 5 ) {
6842                 System.out.println( phy.getNumberOfExternalNodes() );
6843                 return false;
6844             }
6845             if ( !phy.getName().equals( "" ) ) {
6846                 return false;
6847             }
6848             if ( !phy.isRooted() ) {
6849                 return false;
6850             }
6851             //5
6852             if ( !p.hasNext() ) {
6853                 return false;
6854             }
6855             phy = p.next();
6856             if ( phy == null ) {
6857                 return false;
6858             }
6859             if ( phy.getNumberOfExternalNodes() != 3 ) {
6860                 return false;
6861             }
6862             if ( !phy.getName().equals( "" ) ) {
6863                 return false;
6864             }
6865             if ( phy.isRooted() ) {
6866                 return false;
6867             }
6868             //6
6869             if ( !p.hasNext() ) {
6870                 return false;
6871             }
6872             phy = p.next();
6873             if ( phy == null ) {
6874                 return false;
6875             }
6876             if ( phy.getNumberOfExternalNodes() != 2 ) {
6877                 return false;
6878             }
6879             if ( !phy.getName().equals( "" ) ) {
6880                 return false;
6881             }
6882             if ( !phy.isRooted() ) {
6883                 return false;
6884             }
6885             //7
6886             if ( !p.hasNext() ) {
6887                 return false;
6888             }
6889             phy = p.next();
6890             if ( phy.getNumberOfExternalNodes() != 3 ) {
6891                 return false;
6892             }
6893             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6894                 return false;
6895             }
6896             if ( !phy.isRooted() ) {
6897                 return false;
6898             }
6899             //8
6900             if ( !p.hasNext() ) {
6901                 return false;
6902             }
6903             phy = p.next();
6904             if ( phy.getNumberOfExternalNodes() != 3 ) {
6905                 return false;
6906             }
6907             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6908                 return false;
6909             }
6910             if ( !phy.getName().equals( "tree 8" ) ) {
6911                 return false;
6912             }
6913             //9
6914             if ( !p.hasNext() ) {
6915                 return false;
6916             }
6917             phy = p.next();
6918             if ( phy.getNumberOfExternalNodes() != 3 ) {
6919                 return false;
6920             }
6921             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6922                 return false;
6923             }
6924             if ( !phy.getName().equals( "tree 9" ) ) {
6925                 return false;
6926             }
6927             //10
6928             if ( !p.hasNext() ) {
6929                 return false;
6930             }
6931             phy = p.next();
6932             if ( phy.getNumberOfExternalNodes() != 3 ) {
6933                 return false;
6934             }
6935             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6936                 return false;
6937             }
6938             if ( !phy.getName().equals( "tree 10" ) ) {
6939                 return false;
6940             }
6941             if ( !phy.isRooted() ) {
6942                 return false;
6943             }
6944             //11
6945             if ( !p.hasNext() ) {
6946                 return false;
6947             }
6948             phy = p.next();
6949             if ( phy.getNumberOfExternalNodes() != 3 ) {
6950                 return false;
6951             }
6952             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6953                 return false;
6954             }
6955             if ( !phy.getName().equals( "tree 11" ) ) {
6956                 return false;
6957             }
6958             if ( phy.isRooted() ) {
6959                 return false;
6960             }
6961             //12
6962             if ( !p.hasNext() ) {
6963                 return false;
6964             }
6965             phy = p.next();
6966             if ( phy.getNumberOfExternalNodes() != 3 ) {
6967                 return false;
6968             }
6969             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6970                 return false;
6971             }
6972             if ( !phy.getName().equals( "tree 12" ) ) {
6973                 return false;
6974             }
6975             if ( !phy.isRooted() ) {
6976                 return false;
6977             }
6978             //13
6979             if ( !p.hasNext() ) {
6980                 return false;
6981             }
6982             phy = p.next();
6983             if ( phy.getNumberOfExternalNodes() != 3 ) {
6984                 return false;
6985             }
6986             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6987                 return false;
6988             }
6989             if ( !phy.getName().equals( "tree 13" ) ) {
6990                 return false;
6991             }
6992             if ( !phy.isRooted() ) {
6993                 return false;
6994             }
6995             //14
6996             if ( !p.hasNext() ) {
6997                 return false;
6998             }
6999             phy = p.next();
7000             if ( phy.getNumberOfExternalNodes() != 10 ) {
7001                 System.out.println( phy.getNumberOfExternalNodes() );
7002                 return false;
7003             }
7004             if ( !phy
7005                     .toNewHampshire()
7006                     .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;" ) ) {
7007                 System.out.println( phy.toNewHampshire() );
7008                 return false;
7009             }
7010             if ( !phy.getName().equals( "tree 14" ) ) {
7011                 return false;
7012             }
7013             if ( !phy.isRooted() ) {
7014                 return false;
7015             }
7016             //15
7017             if ( !p.hasNext() ) {
7018                 return false;
7019             }
7020             phy = p.next();
7021             if ( phy.getNumberOfExternalNodes() != 10 ) {
7022                 System.out.println( phy.getNumberOfExternalNodes() );
7023                 return false;
7024             }
7025             if ( !phy
7026                     .toNewHampshire()
7027                     .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;" ) ) {
7028                 System.out.println( phy.toNewHampshire() );
7029                 return false;
7030             }
7031             if ( !phy.getName().equals( "tree 15" ) ) {
7032                 return false;
7033             }
7034             if ( phy.isRooted() ) {
7035                 return false;
7036             }
7037             //16
7038             if ( !p.hasNext() ) {
7039                 return false;
7040             }
7041             phy = p.next();
7042             if ( phy.getNumberOfExternalNodes() != 10 ) {
7043                 System.out.println( phy.getNumberOfExternalNodes() );
7044                 return false;
7045             }
7046             if ( !phy
7047                     .toNewHampshire()
7048                     .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;" ) ) {
7049                 System.out.println( phy.toNewHampshire() );
7050                 return false;
7051             }
7052             if ( !phy.getName().equals( "tree 16" ) ) {
7053                 return false;
7054             }
7055             if ( !phy.isRooted() ) {
7056                 return false;
7057             }
7058             //17
7059             if ( !p.hasNext() ) {
7060                 return false;
7061             }
7062             phy = p.next();
7063             if ( phy.getNumberOfExternalNodes() != 10 ) {
7064                 System.out.println( phy.getNumberOfExternalNodes() );
7065                 return false;
7066             }
7067             if ( !phy
7068                     .toNewHampshire()
7069                     .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;" ) ) {
7070                 System.out.println( phy.toNewHampshire() );
7071                 return false;
7072             }
7073             if ( !phy.getName().equals( "tree 17" ) ) {
7074                 return false;
7075             }
7076             if ( phy.isRooted() ) {
7077                 return false;
7078             }
7079             //
7080             if ( p.hasNext() ) {
7081                 return false;
7082             }
7083             phy = p.next();
7084             if ( phy != null ) {
7085                 return false;
7086             }
7087             p.reset();
7088             //0
7089             if ( !p.hasNext() ) {
7090                 return false;
7091             }
7092             phy = p.next();
7093             if ( phy == null ) {
7094                 return false;
7095             }
7096             if ( phy.getNumberOfExternalNodes() != 10 ) {
7097                 return false;
7098             }
7099             if ( !phy.getName().equals( "tree 0" ) ) {
7100                 return false;
7101             }
7102             //1
7103             if ( !p.hasNext() ) {
7104                 return false;
7105             }
7106             phy = p.next();
7107             if ( phy == null ) {
7108                 return false;
7109             }
7110             if ( phy.getNumberOfExternalNodes() != 10 ) {
7111                 return false;
7112             }
7113             if ( !phy.getName().equals( "tree 1" ) ) {
7114                 return false;
7115             }
7116             //2
7117             if ( !p.hasNext() ) {
7118                 return false;
7119             }
7120             phy = p.next();
7121             if ( phy == null ) {
7122                 return false;
7123             }
7124             if ( phy.getNumberOfExternalNodes() != 3 ) {
7125                 return false;
7126             }
7127             if ( !phy.getName().equals( "" ) ) {
7128                 return false;
7129             }
7130             if ( phy.isRooted() ) {
7131                 return false;
7132             }
7133             //3
7134             if ( !p.hasNext() ) {
7135                 return false;
7136             }
7137             phy = p.next();
7138             if ( phy == null ) {
7139                 return false;
7140             }
7141             if ( phy.getNumberOfExternalNodes() != 4 ) {
7142                 return false;
7143             }
7144             if ( !phy.getName().equals( "" ) ) {
7145                 return false;
7146             }
7147             if ( !phy.isRooted() ) {
7148                 return false;
7149             }
7150             //4
7151             if ( !p.hasNext() ) {
7152                 return false;
7153             }
7154             phy = p.next();
7155             if ( phy == null ) {
7156                 return false;
7157             }
7158             if ( phy.getNumberOfExternalNodes() != 5 ) {
7159                 System.out.println( phy.getNumberOfExternalNodes() );
7160                 return false;
7161             }
7162             if ( !phy.getName().equals( "" ) ) {
7163                 return false;
7164             }
7165             if ( !phy.isRooted() ) {
7166                 return false;
7167             }
7168             //5
7169             if ( !p.hasNext() ) {
7170                 return false;
7171             }
7172             phy = p.next();
7173             if ( phy == null ) {
7174                 return false;
7175             }
7176             if ( phy.getNumberOfExternalNodes() != 3 ) {
7177                 return false;
7178             }
7179             if ( !phy.getName().equals( "" ) ) {
7180                 return false;
7181             }
7182             if ( phy.isRooted() ) {
7183                 return false;
7184             }
7185         }
7186         catch ( final Exception e ) {
7187             e.printStackTrace( System.out );
7188             return false;
7189         }
7190         return true;
7191     }
7192
7193     private static boolean testNexusTreeParsingTranslating() {
7194         try {
7195             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7196             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7197             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7198             if ( phylogenies.length != 1 ) {
7199                 return false;
7200             }
7201             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7202                 return false;
7203             }
7204             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7205                 return false;
7206             }
7207             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7208                 return false;
7209             }
7210             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7211                 return false;
7212             }
7213             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7214                     .equals( "Aranaeus" ) ) {
7215                 return false;
7216             }
7217             phylogenies = null;
7218             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7219             if ( phylogenies.length != 3 ) {
7220                 return false;
7221             }
7222             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7223                 return false;
7224             }
7225             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7226                 return false;
7227             }
7228             if ( phylogenies[ 0 ].isRooted() ) {
7229                 return false;
7230             }
7231             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7232                 return false;
7233             }
7234             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7235                 return false;
7236             }
7237             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7238                     .equals( "Aranaeus" ) ) {
7239                 return false;
7240             }
7241             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7242                 return false;
7243             }
7244             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7245                 return false;
7246             }
7247             if ( phylogenies[ 1 ].isRooted() ) {
7248                 return false;
7249             }
7250             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7251                 return false;
7252             }
7253             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7254                 return false;
7255             }
7256             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7257                     .equals( "Aranaeus" ) ) {
7258                 return false;
7259             }
7260             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7261                 return false;
7262             }
7263             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7264                 return false;
7265             }
7266             if ( !phylogenies[ 2 ].isRooted() ) {
7267                 return false;
7268             }
7269             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7270                 return false;
7271             }
7272             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7273                 return false;
7274             }
7275             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7276                     .equals( "Aranaeus" ) ) {
7277                 return false;
7278             }
7279             phylogenies = null;
7280             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7281             if ( phylogenies.length != 3 ) {
7282                 return false;
7283             }
7284             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7285                 return false;
7286             }
7287             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7288                 return false;
7289             }
7290             if ( phylogenies[ 0 ].isRooted() ) {
7291                 return false;
7292             }
7293             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7294                 return false;
7295             }
7296             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7297                 return false;
7298             }
7299             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7300                     .equals( "Aranaeus" ) ) {
7301                 return false;
7302             }
7303             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7304                 return false;
7305             }
7306             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7307                 return false;
7308             }
7309             if ( phylogenies[ 1 ].isRooted() ) {
7310                 return false;
7311             }
7312             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7313                 return false;
7314             }
7315             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7316                 return false;
7317             }
7318             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7319                     .equals( "Aranaeus" ) ) {
7320                 return false;
7321             }
7322             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7323                 return false;
7324             }
7325             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7326                 return false;
7327             }
7328             if ( !phylogenies[ 2 ].isRooted() ) {
7329                 return false;
7330             }
7331             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7332                 return false;
7333             }
7334             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7335                 return false;
7336             }
7337             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7338                     .equals( "Aranaeus" ) ) {
7339                 return false;
7340             }
7341         }
7342         catch ( final Exception e ) {
7343             e.printStackTrace( System.out );
7344             return false;
7345         }
7346         return true;
7347     }
7348
7349     private static boolean testNHParsing() {
7350         try {
7351             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7352             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7353             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7354                 return false;
7355             }
7356             final NHXParser nhxp = new NHXParser();
7357             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7358             nhxp.setReplaceUnderscores( true );
7359             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7360             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
7361                 return false;
7362             }
7363             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
7364                 return false;
7365             }
7366             final Phylogeny p1b = factory
7367                     .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 ",
7368                              new NHXParser() )[ 0 ];
7369             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7370                 return false;
7371             }
7372             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7373                 return false;
7374             }
7375             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7376             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7377             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7378             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7379             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7380             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7381             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7382             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7383             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7384             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7385             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7386                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7387                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7388                                                     new NHXParser() );
7389             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7390                 return false;
7391             }
7392             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7393                 return false;
7394             }
7395             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7396                 return false;
7397             }
7398             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7399                 return false;
7400             }
7401             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7402             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7403             final String p16_S = "((A,B),C)";
7404             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7405             if ( p16.length != 1 ) {
7406                 return false;
7407             }
7408             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
7409                 return false;
7410             }
7411             final String p17_S = "(C,(A,B))";
7412             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
7413             if ( p17.length != 1 ) {
7414                 return false;
7415             }
7416             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7417                 return false;
7418             }
7419             final String p18_S = "((A,B),(C,D))";
7420             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7421             if ( p18.length != 1 ) {
7422                 return false;
7423             }
7424             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7425                 return false;
7426             }
7427             final String p19_S = "(((A,B),C),D)";
7428             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7429             if ( p19.length != 1 ) {
7430                 return false;
7431             }
7432             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7433                 return false;
7434             }
7435             final String p20_S = "(A,(B,(C,D)))";
7436             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7437             if ( p20.length != 1 ) {
7438                 return false;
7439             }
7440             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7441                 return false;
7442             }
7443             final String p21_S = "(A,(B,(C,(D,E))))";
7444             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7445             if ( p21.length != 1 ) {
7446                 return false;
7447             }
7448             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7449                 return false;
7450             }
7451             final String p22_S = "((((A,B),C),D),E)";
7452             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7453             if ( p22.length != 1 ) {
7454                 return false;
7455             }
7456             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7457                 return false;
7458             }
7459             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7460             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7461             if ( p23.length != 1 ) {
7462                 System.out.println( "xl=" + p23.length );
7463                 System.exit( -1 );
7464                 return false;
7465             }
7466             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7467                 return false;
7468             }
7469             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7470             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7471             if ( p24.length != 1 ) {
7472                 return false;
7473             }
7474             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7475                 return false;
7476             }
7477             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7478             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7479             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7480             if ( p241.length != 2 ) {
7481                 return false;
7482             }
7483             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7484                 return false;
7485             }
7486             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7487                 return false;
7488             }
7489             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7490                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7491                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7492                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7493                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7494                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7495                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7496                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7497             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7498             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7499                 return false;
7500             }
7501             final String p26_S = "(A,B)ab";
7502             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7503             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7504                 return false;
7505             }
7506             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7507             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7508             if ( p27s.length != 1 ) {
7509                 System.out.println( "xxl=" + p27s.length );
7510                 System.exit( -1 );
7511                 return false;
7512             }
7513             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7514                 System.out.println( p27s[ 0 ].toNewHampshireX() );
7515                 System.exit( -1 );
7516                 return false;
7517             }
7518             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7519                                                     new NHXParser() );
7520             if ( p27.length != 1 ) {
7521                 System.out.println( "yl=" + p27.length );
7522                 System.exit( -1 );
7523                 return false;
7524             }
7525             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7526                 System.out.println( p27[ 0 ].toNewHampshireX() );
7527                 System.exit( -1 );
7528                 return false;
7529             }
7530             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7531             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7532             final String p28_S3 = "(A,B)ab";
7533             final String p28_S4 = "((((A,B),C),D),;E;)";
7534             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7535                                                     new NHXParser() );
7536             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7537                 return false;
7538             }
7539             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7540                 return false;
7541             }
7542             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7543                 return false;
7544             }
7545             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7546                 return false;
7547             }
7548             if ( p28.length != 4 ) {
7549                 return false;
7550             }
7551             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";
7552             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
7553             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
7554                 return false;
7555             }
7556             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";
7557             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
7558             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
7559                 return false;
7560             }
7561             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
7562             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
7563             if ( ( p32.length != 0 ) ) {
7564                 return false;
7565             }
7566             final String p33_S = "A";
7567             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
7568             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
7569                 return false;
7570             }
7571             final String p34_S = "B;";
7572             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
7573             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
7574                 return false;
7575             }
7576             final String p35_S = "B:0.2";
7577             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7578             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7579                 return false;
7580             }
7581             final String p36_S = "(A)";
7582             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7583             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7584                 return false;
7585             }
7586             final String p37_S = "((A))";
7587             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7588             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7589                 return false;
7590             }
7591             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7592             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7593             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7594                 return false;
7595             }
7596             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7597             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7598             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7599                 return false;
7600             }
7601             final String p40_S = "(A,B,C)";
7602             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7603             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7604                 return false;
7605             }
7606             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7607             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7608             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7609                 return false;
7610             }
7611             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7612             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7613             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7614                 return false;
7615             }
7616             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)";
7617             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7618             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7619                 return false;
7620             }
7621             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)))";
7622             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7623             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7624                 return false;
7625             }
7626             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7627             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7628             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7629                 return false;
7630             }
7631             final String p46_S = "";
7632             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7633             if ( p46.length != 0 ) {
7634                 return false;
7635             }
7636             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7637             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7638                 return false;
7639             }
7640             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7641             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7642                 return false;
7643             }
7644             final Phylogeny p49 = factory
7645                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7646                              new NHXParser() )[ 0 ];
7647             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7648                 return false;
7649             }
7650             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7651             if ( p50.getNode( "A" ) == null ) {
7652                 return false;
7653             }
7654             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7655                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7656                 return false;
7657             }
7658             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7659                 return false;
7660             }
7661             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7662                     .equals( "((A,B)88:2.0,C);" ) ) {
7663                 return false;
7664             }
7665             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7666             if ( p51.getNode( "A(A" ) == null ) {
7667                 return false;
7668             }
7669             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7670             if ( p52.getNode( "A(A" ) == null ) {
7671                 return false;
7672             }
7673             final Phylogeny p53 = factory
7674                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7675                              new NHXParser() )[ 0 ];
7676             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7677                 return false;
7678             }
7679             // 
7680             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7681             if ( p54.getNode( "A" ) == null ) {
7682                 return false;
7683             }
7684             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7685                     .equals( "((A,B)[88],C);" ) ) {
7686                 return false;
7687             }
7688         }
7689         catch ( final Exception e ) {
7690             e.printStackTrace( System.out );
7691             return false;
7692         }
7693         return true;
7694     }
7695
7696     private static boolean testNHParsingIter() {
7697         try {
7698             final String p0_str = "(A,B);";
7699             final NHXParser p = new NHXParser();
7700             p.setSource( p0_str );
7701             if ( !p.hasNext() ) {
7702                 return false;
7703             }
7704             final Phylogeny p0 = p.next();
7705             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7706                 System.out.println( p0.toNewHampshire() );
7707                 return false;
7708             }
7709             if ( p.hasNext() ) {
7710                 return false;
7711             }
7712             if ( p.next() != null ) {
7713                 return false;
7714             }
7715             //
7716             final String p00_str = "(A,B)root;";
7717             p.setSource( p00_str );
7718             final Phylogeny p00 = p.next();
7719             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7720                 System.out.println( p00.toNewHampshire() );
7721                 return false;
7722             }
7723             //
7724             final String p000_str = "A;";
7725             p.setSource( p000_str );
7726             final Phylogeny p000 = p.next();
7727             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7728                 System.out.println( p000.toNewHampshire() );
7729                 return false;
7730             }
7731             //
7732             final String p0000_str = "A";
7733             p.setSource( p0000_str );
7734             final Phylogeny p0000 = p.next();
7735             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7736                 System.out.println( p0000.toNewHampshire() );
7737                 return false;
7738             }
7739             //
7740             p.setSource( "(A)" );
7741             final Phylogeny p00000 = p.next();
7742             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7743                 System.out.println( p00000.toNewHampshire() );
7744                 return false;
7745             }
7746             //
7747             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7748             p.setSource( p1_str );
7749             if ( !p.hasNext() ) {
7750                 return false;
7751             }
7752             final Phylogeny p1_0 = p.next();
7753             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7754                 System.out.println( p1_0.toNewHampshire() );
7755                 return false;
7756             }
7757             if ( !p.hasNext() ) {
7758                 return false;
7759             }
7760             final Phylogeny p1_1 = p.next();
7761             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7762                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7763                 return false;
7764             }
7765             if ( !p.hasNext() ) {
7766                 return false;
7767             }
7768             final Phylogeny p1_2 = p.next();
7769             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7770                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7771                 return false;
7772             }
7773             if ( !p.hasNext() ) {
7774                 return false;
7775             }
7776             final Phylogeny p1_3 = p.next();
7777             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7778                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7779                 return false;
7780             }
7781             if ( p.hasNext() ) {
7782                 return false;
7783             }
7784             if ( p.next() != null ) {
7785                 return false;
7786             }
7787             //
7788             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7789             p.setSource( p2_str );
7790             if ( !p.hasNext() ) {
7791                 return false;
7792             }
7793             Phylogeny p2_0 = p.next();
7794             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7795                 System.out.println( p2_0.toNewHampshire() );
7796                 return false;
7797             }
7798             if ( !p.hasNext() ) {
7799                 return false;
7800             }
7801             Phylogeny p2_1 = p.next();
7802             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7803                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7804                 return false;
7805             }
7806             if ( !p.hasNext() ) {
7807                 return false;
7808             }
7809             Phylogeny p2_2 = p.next();
7810             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7811                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7812                 return false;
7813             }
7814             if ( !p.hasNext() ) {
7815                 return false;
7816             }
7817             Phylogeny p2_3 = p.next();
7818             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7819                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7820                 return false;
7821             }
7822             if ( !p.hasNext() ) {
7823                 return false;
7824             }
7825             Phylogeny p2_4 = p.next();
7826             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7827                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7828                 return false;
7829             }
7830             if ( p.hasNext() ) {
7831                 return false;
7832             }
7833             if ( p.next() != null ) {
7834                 return false;
7835             }
7836             ////
7837             p.reset();
7838             if ( !p.hasNext() ) {
7839                 return false;
7840             }
7841             p2_0 = p.next();
7842             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7843                 System.out.println( p2_0.toNewHampshire() );
7844                 return false;
7845             }
7846             if ( !p.hasNext() ) {
7847                 return false;
7848             }
7849             p2_1 = p.next();
7850             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7851                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7852                 return false;
7853             }
7854             if ( !p.hasNext() ) {
7855                 return false;
7856             }
7857             p2_2 = p.next();
7858             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7859                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7860                 return false;
7861             }
7862             if ( !p.hasNext() ) {
7863                 return false;
7864             }
7865             p2_3 = p.next();
7866             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7867                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7868                 return false;
7869             }
7870             if ( !p.hasNext() ) {
7871                 return false;
7872             }
7873             p2_4 = p.next();
7874             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7875                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7876                 return false;
7877             }
7878             if ( p.hasNext() ) {
7879                 return false;
7880             }
7881             if ( p.next() != null ) {
7882                 return false;
7883             }
7884             //
7885             final String p3_str = "((A,B),C)abc";
7886             p.setSource( p3_str );
7887             if ( !p.hasNext() ) {
7888                 return false;
7889             }
7890             final Phylogeny p3_0 = p.next();
7891             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7892                 return false;
7893             }
7894             if ( p.hasNext() ) {
7895                 return false;
7896             }
7897             if ( p.next() != null ) {
7898                 return false;
7899             }
7900             //
7901             final String p4_str = "((A,B)ab,C)abc";
7902             p.setSource( p4_str );
7903             if ( !p.hasNext() ) {
7904                 return false;
7905             }
7906             final Phylogeny p4_0 = p.next();
7907             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7908                 return false;
7909             }
7910             if ( p.hasNext() ) {
7911                 return false;
7912             }
7913             if ( p.next() != null ) {
7914                 return false;
7915             }
7916             //
7917             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7918             p.setSource( p5_str );
7919             if ( !p.hasNext() ) {
7920                 return false;
7921             }
7922             final Phylogeny p5_0 = p.next();
7923             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7924                 return false;
7925             }
7926             if ( p.hasNext() ) {
7927                 return false;
7928             }
7929             if ( p.next() != null ) {
7930                 return false;
7931             }
7932             //
7933             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7934             p.setSource( p6_str );
7935             if ( !p.hasNext() ) {
7936                 return false;
7937             }
7938             Phylogeny p6_0 = p.next();
7939             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7940                 return false;
7941             }
7942             if ( p.hasNext() ) {
7943                 return false;
7944             }
7945             if ( p.next() != null ) {
7946                 return false;
7947             }
7948             p.reset();
7949             if ( !p.hasNext() ) {
7950                 return false;
7951             }
7952             p6_0 = p.next();
7953             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7954                 return false;
7955             }
7956             if ( p.hasNext() ) {
7957                 return false;
7958             }
7959             if ( p.next() != null ) {
7960                 return false;
7961             }
7962             //
7963             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7964             p.setSource( p7_str );
7965             if ( !p.hasNext() ) {
7966                 return false;
7967             }
7968             Phylogeny p7_0 = p.next();
7969             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7970                 return false;
7971             }
7972             if ( p.hasNext() ) {
7973                 return false;
7974             }
7975             if ( p.next() != null ) {
7976                 return false;
7977             }
7978             p.reset();
7979             if ( !p.hasNext() ) {
7980                 return false;
7981             }
7982             p7_0 = p.next();
7983             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7984                 return false;
7985             }
7986             if ( p.hasNext() ) {
7987                 return false;
7988             }
7989             if ( p.next() != null ) {
7990                 return false;
7991             }
7992             //
7993             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7994             p.setSource( p8_str );
7995             if ( !p.hasNext() ) {
7996                 return false;
7997             }
7998             Phylogeny p8_0 = p.next();
7999             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8000                 return false;
8001             }
8002             if ( !p.hasNext() ) {
8003                 return false;
8004             }
8005             if ( !p.hasNext() ) {
8006                 return false;
8007             }
8008             Phylogeny p8_1 = p.next();
8009             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8010                 return false;
8011             }
8012             if ( p.hasNext() ) {
8013                 return false;
8014             }
8015             if ( p.next() != null ) {
8016                 return false;
8017             }
8018             p.reset();
8019             if ( !p.hasNext() ) {
8020                 return false;
8021             }
8022             p8_0 = p.next();
8023             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8024                 return false;
8025             }
8026             if ( !p.hasNext() ) {
8027                 return false;
8028             }
8029             p8_1 = p.next();
8030             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8031                 return false;
8032             }
8033             if ( p.hasNext() ) {
8034                 return false;
8035             }
8036             if ( p.next() != null ) {
8037                 return false;
8038             }
8039             p.reset();
8040             //
8041             p.setSource( "" );
8042             if ( p.hasNext() ) {
8043                 return false;
8044             }
8045             //
8046             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8047             if ( !p.hasNext() ) {
8048                 return false;
8049             }
8050             Phylogeny p_27 = p.next();
8051             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8052                 System.out.println( p_27.toNewHampshireX() );
8053                 System.exit( -1 );
8054                 return false;
8055             }
8056             if ( p.hasNext() ) {
8057                 return false;
8058             }
8059             if ( p.next() != null ) {
8060                 return false;
8061             }
8062             p.reset();
8063             if ( !p.hasNext() ) {
8064                 return false;
8065             }
8066             p_27 = p.next();
8067             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8068                 System.out.println( p_27.toNewHampshireX() );
8069                 System.exit( -1 );
8070                 return false;
8071             }
8072             if ( p.hasNext() ) {
8073                 return false;
8074             }
8075             if ( p.next() != null ) {
8076                 return false;
8077             }
8078             //
8079             final String p30_str = "(A,B);(C,D)";
8080             final NHXParser p30 = new NHXParser();
8081             p30.setSource( p30_str );
8082             if ( !p30.hasNext() ) {
8083                 return false;
8084             }
8085             Phylogeny phy30 = p30.next();
8086             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8087                 System.out.println( phy30.toNewHampshire() );
8088                 return false;
8089             }
8090             if ( !p30.hasNext() ) {
8091                 return false;
8092             }
8093             Phylogeny phy301 = p30.next();
8094             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8095                 System.out.println( phy301.toNewHampshire() );
8096                 return false;
8097             }
8098             if ( p30.hasNext() ) {
8099                 return false;
8100             }
8101             if ( p30.hasNext() ) {
8102                 return false;
8103             }
8104             if ( p30.next() != null ) {
8105                 return false;
8106             }
8107             if ( p30.next() != null ) {
8108                 return false;
8109             }
8110             p30.reset();
8111             if ( !p30.hasNext() ) {
8112                 return false;
8113             }
8114             phy30 = p30.next();
8115             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8116                 System.out.println( phy30.toNewHampshire() );
8117                 return false;
8118             }
8119             if ( !p30.hasNext() ) {
8120                 return false;
8121             }
8122             phy301 = p30.next();
8123             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8124                 System.out.println( phy301.toNewHampshire() );
8125                 return false;
8126             }
8127             if ( p30.hasNext() ) {
8128                 return false;
8129             }
8130             if ( p30.hasNext() ) {
8131                 return false;
8132             }
8133             if ( p30.next() != null ) {
8134                 return false;
8135             }
8136             if ( p30.next() != null ) {
8137                 return false;
8138             }
8139         }
8140         catch ( final Exception e ) {
8141             e.printStackTrace( System.out );
8142             return false;
8143         }
8144         return true;
8145     }
8146
8147     private static boolean testNHXconversion() {
8148         try {
8149             final PhylogenyNode n1 = new PhylogenyNode();
8150             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8151             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8152             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8153             final PhylogenyNode n5 = PhylogenyNode
8154                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8155             final PhylogenyNode n6 = PhylogenyNode
8156                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8157             if ( !n1.toNewHampshireX().equals( "" ) ) {
8158                 return false;
8159             }
8160             if ( !n2.toNewHampshireX().equals( "" ) ) {
8161                 return false;
8162             }
8163             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8164                 return false;
8165             }
8166             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8167                 return false;
8168             }
8169             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8170                 return false;
8171             }
8172             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8173                 System.out.println( n6.toNewHampshireX() );
8174                 return false;
8175             }
8176         }
8177         catch ( final Exception e ) {
8178             e.printStackTrace( System.out );
8179             return false;
8180         }
8181         return true;
8182     }
8183
8184     private static boolean testNHXNodeParsing() {
8185         try {
8186             final PhylogenyNode n1 = new PhylogenyNode();
8187             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8188             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8189             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8190             final PhylogenyNode n5 = PhylogenyNode
8191                     .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]" );
8192             if ( !n3.getName().equals( "n3" ) ) {
8193                 return false;
8194             }
8195             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8196                 return false;
8197             }
8198             if ( n3.isDuplication() ) {
8199                 return false;
8200             }
8201             if ( n3.isHasAssignedEvent() ) {
8202                 return false;
8203             }
8204             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8205                 return false;
8206             }
8207             if ( !n4.getName().equals( "n4" ) ) {
8208                 return false;
8209             }
8210             if ( n4.getDistanceToParent() != 0.01 ) {
8211                 return false;
8212             }
8213             if ( !n5.getName().equals( "n5" ) ) {
8214                 return false;
8215             }
8216             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8217                 return false;
8218             }
8219             if ( n5.getDistanceToParent() != 0.1 ) {
8220                 return false;
8221             }
8222             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8223                 return false;
8224             }
8225             if ( !n5.isDuplication() ) {
8226                 return false;
8227             }
8228             if ( !n5.isHasAssignedEvent() ) {
8229                 return false;
8230             }
8231             final PhylogenyNode n8 = PhylogenyNode
8232                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8233                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8234             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8235                 return false;
8236             }
8237             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8238                 return false;
8239             }
8240             final PhylogenyNode n9 = PhylogenyNode
8241                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8242                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8243             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8244                 return false;
8245             }
8246             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8247                 return false;
8248             }
8249             final PhylogenyNode n10 = PhylogenyNode
8250                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8251             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8252                 return false;
8253             }
8254             final PhylogenyNode n20 = PhylogenyNode
8255                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8256             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8257                 return false;
8258             }
8259             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8260                 return false;
8261             }
8262             final PhylogenyNode n20x = PhylogenyNode
8263                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8264             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8265                 return false;
8266             }
8267             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8268                 return false;
8269             }
8270             final PhylogenyNode n20xx = PhylogenyNode
8271                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8272             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8273                 return false;
8274             }
8275             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8276                 return false;
8277             }
8278             final PhylogenyNode n20xxx = PhylogenyNode
8279                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8280             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8281                 return false;
8282             }
8283             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8284                 return false;
8285             }
8286             final PhylogenyNode n20xxxx = PhylogenyNode
8287                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8288             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8289                 return false;
8290             }
8291             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8292                 return false;
8293             }
8294             final PhylogenyNode n21 = PhylogenyNode
8295                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8296             if ( !n21.getName().equals( "N21_PIG" ) ) {
8297                 return false;
8298             }
8299             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8300                 return false;
8301             }
8302             final PhylogenyNode n21x = PhylogenyNode
8303                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8304             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8305                 return false;
8306             }
8307             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8308                 return false;
8309             }
8310             final PhylogenyNode n22 = PhylogenyNode
8311                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8312             if ( !n22.getName().equals( "n22/PIG" ) ) {
8313                 return false;
8314             }
8315             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8316                 return false;
8317             }
8318             final PhylogenyNode n23 = PhylogenyNode
8319                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8320             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8321                 return false;
8322             }
8323             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8324                 return false;
8325             }
8326             final PhylogenyNode a = PhylogenyNode
8327                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8328             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8329                 return false;
8330             }
8331             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8332                 return false;
8333             }
8334             final PhylogenyNode c1 = PhylogenyNode
8335                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8336                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8337             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8338                 return false;
8339             }
8340             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8341                 return false;
8342             }
8343             final PhylogenyNode c2 = PhylogenyNode
8344                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8345                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8346             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8347                 return false;
8348             }
8349             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
8350                 return false;
8351             }
8352             final PhylogenyNode e3 = PhylogenyNode
8353                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8354             if ( !e3.getName().equals( "n10_RAT~" ) ) {
8355                 return false;
8356             }
8357             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
8358                 return false;
8359             }
8360             final PhylogenyNode n11 = PhylogenyNode
8361                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
8362                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8363             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
8364                 return false;
8365             }
8366             if ( n11.getDistanceToParent() != 0.4 ) {
8367                 return false;
8368             }
8369             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
8370                 return false;
8371             }
8372             final PhylogenyNode n12 = PhylogenyNode
8373                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
8374                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8375             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
8376                 return false;
8377             }
8378             if ( n12.getDistanceToParent() != 0.4 ) {
8379                 return false;
8380             }
8381             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
8382                 return false;
8383             }
8384             final PhylogenyNode o = PhylogenyNode
8385                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8386             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
8387                 return false;
8388             }
8389             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
8390                 return false;
8391             }
8392             if ( n1.getName().compareTo( "" ) != 0 ) {
8393                 return false;
8394             }
8395             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8396                 return false;
8397             }
8398             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8399                 return false;
8400             }
8401             if ( n2.getName().compareTo( "" ) != 0 ) {
8402                 return false;
8403             }
8404             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8405                 return false;
8406             }
8407             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8408                 return false;
8409             }
8410             final PhylogenyNode n00 = PhylogenyNode
8411                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
8412             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
8413                 return false;
8414             }
8415             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
8416                 return false;
8417             }
8418             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
8419             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
8420                 return false;
8421             }
8422             final PhylogenyNode n13 = PhylogenyNode
8423                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8424             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
8425                 return false;
8426             }
8427             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
8428                 return false;
8429             }
8430             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8431                 return false;
8432             }
8433             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8434                 return false;
8435             }
8436             final PhylogenyNode n14 = PhylogenyNode
8437                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8438             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
8439                 return false;
8440             }
8441             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
8442                 return false;
8443             }
8444             final PhylogenyNode n15 = PhylogenyNode
8445                     .createInstanceFromNhxString( "something_wicked[123]",
8446                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8447             if ( !n15.getName().equals( "something_wicked" ) ) {
8448                 return false;
8449             }
8450             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
8451                 return false;
8452             }
8453             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
8454                 return false;
8455             }
8456             final PhylogenyNode n16 = PhylogenyNode
8457                     .createInstanceFromNhxString( "something_wicked2[9]",
8458                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8459             if ( !n16.getName().equals( "something_wicked2" ) ) {
8460                 return false;
8461             }
8462             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
8463                 return false;
8464             }
8465             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
8466                 return false;
8467             }
8468             final PhylogenyNode n17 = PhylogenyNode
8469                     .createInstanceFromNhxString( "something_wicked3[a]",
8470                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8471             if ( !n17.getName().equals( "something_wicked3" ) ) {
8472                 return false;
8473             }
8474             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
8475                 return false;
8476             }
8477             final PhylogenyNode n18 = PhylogenyNode
8478                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8479             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8480                 return false;
8481             }
8482             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8483                 return false;
8484             }
8485             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8486                 return false;
8487             }
8488             final PhylogenyNode n19 = PhylogenyNode
8489                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8490             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
8491                 return false;
8492             }
8493             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8494                 return false;
8495             }
8496             final PhylogenyNode n30 = PhylogenyNode
8497                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
8498                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8499             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
8500                 return false;
8501             }
8502             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8503                 return false;
8504             }
8505             final PhylogenyNode n31 = PhylogenyNode
8506                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
8507                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8508             if ( n31.getNodeData().isHasTaxonomy() ) {
8509                 return false;
8510             }
8511             final PhylogenyNode n32 = PhylogenyNode
8512                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8513             if ( n32.getNodeData().isHasTaxonomy() ) {
8514                 return false;
8515             }
8516             final PhylogenyNode n40 = PhylogenyNode
8517                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8518             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8519                 return false;
8520             }
8521             final PhylogenyNode n41 = PhylogenyNode
8522                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8523             if ( n41.getNodeData().isHasTaxonomy() ) {
8524                 return false;
8525             }
8526             final PhylogenyNode n42 = PhylogenyNode
8527                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8528             if ( n42.getNodeData().isHasTaxonomy() ) {
8529                 return false;
8530             }
8531             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
8532                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
8533             if ( n43.getNodeData().isHasTaxonomy() ) {
8534                 return false;
8535             }
8536             final PhylogenyNode n44 = PhylogenyNode
8537                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8538             if ( n44.getNodeData().isHasTaxonomy() ) {
8539                 return false;
8540             }
8541         }
8542         catch ( final Exception e ) {
8543             e.printStackTrace( System.out );
8544             return false;
8545         }
8546         return true;
8547     }
8548
8549     private static boolean testNHXParsing() {
8550         try {
8551             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8552             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
8553             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
8554                 return false;
8555             }
8556             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]";
8557             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
8558             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8559                 return false;
8560             }
8561             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]";
8562             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
8563             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
8564                 return false;
8565             }
8566             final Phylogeny[] p3 = factory
8567                     .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]",
8568                              new NHXParser() );
8569             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8570                 return false;
8571             }
8572             final Phylogeny[] p4 = factory
8573                     .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(]",
8574                              new NHXParser() );
8575             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8576                 return false;
8577             }
8578             final Phylogeny[] p5 = factory
8579                     .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(((]",
8580                              new NHXParser() );
8581             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8582                 return false;
8583             }
8584             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)";
8585             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)";
8586             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
8587             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
8588                 return false;
8589             }
8590             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)))";
8591             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)))";
8592             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
8593             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
8594                 return false;
8595             }
8596             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])   ))[,,, ])))))))";
8597             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
8598             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
8599             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
8600                 return false;
8601             }
8602             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
8603             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8604                 return false;
8605             }
8606             final Phylogeny p10 = factory
8607                     .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]",
8608                              new NHXParser() )[ 0 ];
8609             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8610                 return false;
8611             }
8612         }
8613         catch ( final Exception e ) {
8614             e.printStackTrace( System.out );
8615             return false;
8616         }
8617         return true;
8618     }
8619
8620     private static boolean testNHXParsingMB() {
8621         try {
8622             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8623             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
8624                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8625                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8626                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8627                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8628                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8629                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8630                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8631                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
8632             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
8633                 return false;
8634             }
8635             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
8636                 return false;
8637             }
8638             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8639                            0.1100000000000000e+00 ) ) {
8640                 return false;
8641             }
8642             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8643                 return false;
8644             }
8645             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8646                 return false;
8647             }
8648             final Phylogeny p2 = factory
8649                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8650                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8651                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8652                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8653                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8654                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8655                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8656                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8657                                      + "7.369400000000000e-02}])",
8658                              new NHXParser() )[ 0 ];
8659             if ( p2.getNode( "1" ) == null ) {
8660                 return false;
8661             }
8662             if ( p2.getNode( "2" ) == null ) {
8663                 return false;
8664             }
8665         }
8666         catch ( final Exception e ) {
8667             e.printStackTrace( System.out );
8668             System.exit( -1 );
8669             return false;
8670         }
8671         return true;
8672     }
8673
8674     private static boolean testNHXParsingQuotes() {
8675         try {
8676             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8677             final NHXParser p = new NHXParser();
8678             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8679             if ( phylogenies_0.length != 5 ) {
8680                 return false;
8681             }
8682             final Phylogeny phy = phylogenies_0[ 4 ];
8683             if ( phy.getNumberOfExternalNodes() != 7 ) {
8684                 return false;
8685             }
8686             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8687                 return false;
8688             }
8689             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8690                 return false;
8691             }
8692             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8693                     .getScientificName().equals( "hsapiens" ) ) {
8694                 return false;
8695             }
8696             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8697                 return false;
8698             }
8699             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8700                 return false;
8701             }
8702             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8703                 return false;
8704             }
8705             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8706                 return false;
8707             }
8708             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8709                 return false;
8710             }
8711             final NHXParser p1p = new NHXParser();
8712             p1p.setIgnoreQuotes( true );
8713             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8714             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8715                 return false;
8716             }
8717             final NHXParser p2p = new NHXParser();
8718             p1p.setIgnoreQuotes( false );
8719             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8720             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8721                 return false;
8722             }
8723             final NHXParser p3p = new NHXParser();
8724             p3p.setIgnoreQuotes( false );
8725             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8726             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8727                 return false;
8728             }
8729             final NHXParser p4p = new NHXParser();
8730             p4p.setIgnoreQuotes( false );
8731             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8732             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8733                 return false;
8734             }
8735             final Phylogeny p10 = factory
8736                     .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]",
8737                              new NHXParser() )[ 0 ];
8738             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]";
8739             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8740                 return false;
8741             }
8742             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8743             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8744                 return false;
8745             }
8746             //
8747             final Phylogeny p12 = factory
8748                     .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]",
8749                              new NHXParser() )[ 0 ];
8750             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]";
8751             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8752                 return false;
8753             }
8754             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8755             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8756                 return false;
8757             }
8758             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;";
8759             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8760                 return false;
8761             }
8762             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8763             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8764                 return false;
8765             }
8766         }
8767         catch ( final Exception e ) {
8768             e.printStackTrace( System.out );
8769             return false;
8770         }
8771         return true;
8772     }
8773
8774     private static boolean testNodeRemoval() {
8775         try {
8776             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8777             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8778             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8779             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8780                 return false;
8781             }
8782             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8783             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8784             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8785                 return false;
8786             }
8787             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8788             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8789             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8790                 return false;
8791             }
8792         }
8793         catch ( final Exception e ) {
8794             e.printStackTrace( System.out );
8795             return false;
8796         }
8797         return true;
8798     }
8799
8800     private static boolean testPhylogenyBranch() {
8801         try {
8802             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8803             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8804             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8805             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8806             if ( !a1b1.equals( a1b1 ) ) {
8807                 return false;
8808             }
8809             if ( !a1b1.equals( b1a1 ) ) {
8810                 return false;
8811             }
8812             if ( !b1a1.equals( a1b1 ) ) {
8813                 return false;
8814             }
8815             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8816             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8817             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8818             if ( a1_b1.equals( b1_a1 ) ) {
8819                 return false;
8820             }
8821             if ( a1_b1.equals( a1_b1_ ) ) {
8822                 return false;
8823             }
8824             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8825             if ( !a1_b1.equals( b1_a1_ ) ) {
8826                 return false;
8827             }
8828             if ( a1_b1_.equals( b1_a1_ ) ) {
8829                 return false;
8830             }
8831             if ( !a1_b1_.equals( b1_a1 ) ) {
8832                 return false;
8833             }
8834         }
8835         catch ( final Exception e ) {
8836             e.printStackTrace( System.out );
8837             return false;
8838         }
8839         return true;
8840     }
8841
8842     private static boolean testPhyloXMLparsingOfDistributionElement() {
8843         try {
8844             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8845             PhyloXmlParser xml_parser = null;
8846             try {
8847                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8848             }
8849             catch ( final Exception e ) {
8850                 // Do nothing -- means were not running from jar.
8851             }
8852             if ( xml_parser == null ) {
8853                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
8854                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8855                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8856                 }
8857                 else {
8858                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8859                 }
8860             }
8861             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8862                                                               xml_parser );
8863             if ( xml_parser.getErrorCount() > 0 ) {
8864                 System.out.println( xml_parser.getErrorMessages().toString() );
8865                 return false;
8866             }
8867             if ( phylogenies_0.length != 1 ) {
8868                 return false;
8869             }
8870             final Phylogeny t1 = phylogenies_0[ 0 ];
8871             PhylogenyNode n = null;
8872             Distribution d = null;
8873             n = t1.getNode( "root node" );
8874             if ( !n.getNodeData().isHasDistribution() ) {
8875                 return false;
8876             }
8877             if ( n.getNodeData().getDistributions().size() != 1 ) {
8878                 return false;
8879             }
8880             d = n.getNodeData().getDistribution();
8881             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8882                 return false;
8883             }
8884             if ( d.getPoints().size() != 1 ) {
8885                 return false;
8886             }
8887             if ( d.getPolygons() != null ) {
8888                 return false;
8889             }
8890             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8891                 return false;
8892             }
8893             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8894                 return false;
8895             }
8896             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8897                 return false;
8898             }
8899             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8900                 return false;
8901             }
8902             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8903                 return false;
8904             }
8905             n = t1.getNode( "node a" );
8906             if ( !n.getNodeData().isHasDistribution() ) {
8907                 return false;
8908             }
8909             if ( n.getNodeData().getDistributions().size() != 2 ) {
8910                 return false;
8911             }
8912             d = n.getNodeData().getDistribution( 1 );
8913             if ( !d.getDesc().equals( "San Diego" ) ) {
8914                 return false;
8915             }
8916             if ( d.getPoints().size() != 1 ) {
8917                 return false;
8918             }
8919             if ( d.getPolygons() != null ) {
8920                 return false;
8921             }
8922             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8923                 return false;
8924             }
8925             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8926                 return false;
8927             }
8928             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8929                 return false;
8930             }
8931             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8932                 return false;
8933             }
8934             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8935                 return false;
8936             }
8937             n = t1.getNode( "node bb" );
8938             if ( !n.getNodeData().isHasDistribution() ) {
8939                 return false;
8940             }
8941             if ( n.getNodeData().getDistributions().size() != 1 ) {
8942                 return false;
8943             }
8944             d = n.getNodeData().getDistribution( 0 );
8945             if ( d.getPoints().size() != 3 ) {
8946                 return false;
8947             }
8948             if ( d.getPolygons().size() != 2 ) {
8949                 return false;
8950             }
8951             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8952                 return false;
8953             }
8954             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8955                 return false;
8956             }
8957             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8958                 return false;
8959             }
8960             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8961                 return false;
8962             }
8963             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8964                 return false;
8965             }
8966             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8967                 return false;
8968             }
8969             Polygon p = d.getPolygons().get( 0 );
8970             if ( p.getPoints().size() != 3 ) {
8971                 return false;
8972             }
8973             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8974                 return false;
8975             }
8976             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8977                 return false;
8978             }
8979             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8980                 return false;
8981             }
8982             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8983                 return false;
8984             }
8985             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8986                 return false;
8987             }
8988             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8989                 return false;
8990             }
8991             p = d.getPolygons().get( 1 );
8992             if ( p.getPoints().size() != 3 ) {
8993                 return false;
8994             }
8995             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8996                 return false;
8997             }
8998             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8999                 return false;
9000             }
9001             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9002                 return false;
9003             }
9004             // Roundtrip:
9005             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9006             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9007             if ( rt.length != 1 ) {
9008                 return false;
9009             }
9010             final Phylogeny t1_rt = rt[ 0 ];
9011             n = t1_rt.getNode( "root node" );
9012             if ( !n.getNodeData().isHasDistribution() ) {
9013                 return false;
9014             }
9015             if ( n.getNodeData().getDistributions().size() != 1 ) {
9016                 return false;
9017             }
9018             d = n.getNodeData().getDistribution();
9019             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9020                 return false;
9021             }
9022             if ( d.getPoints().size() != 1 ) {
9023                 return false;
9024             }
9025             if ( d.getPolygons() != null ) {
9026                 return false;
9027             }
9028             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9029                 return false;
9030             }
9031             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9032                 return false;
9033             }
9034             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9035                 return false;
9036             }
9037             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9038                 return false;
9039             }
9040             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9041                 return false;
9042             }
9043             n = t1_rt.getNode( "node a" );
9044             if ( !n.getNodeData().isHasDistribution() ) {
9045                 return false;
9046             }
9047             if ( n.getNodeData().getDistributions().size() != 2 ) {
9048                 return false;
9049             }
9050             d = n.getNodeData().getDistribution( 1 );
9051             if ( !d.getDesc().equals( "San Diego" ) ) {
9052                 return false;
9053             }
9054             if ( d.getPoints().size() != 1 ) {
9055                 return false;
9056             }
9057             if ( d.getPolygons() != null ) {
9058                 return false;
9059             }
9060             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9061                 return false;
9062             }
9063             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9064                 return false;
9065             }
9066             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9067                 return false;
9068             }
9069             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9070                 return false;
9071             }
9072             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9073                 return false;
9074             }
9075             n = t1_rt.getNode( "node bb" );
9076             if ( !n.getNodeData().isHasDistribution() ) {
9077                 return false;
9078             }
9079             if ( n.getNodeData().getDistributions().size() != 1 ) {
9080                 return false;
9081             }
9082             d = n.getNodeData().getDistribution( 0 );
9083             if ( d.getPoints().size() != 3 ) {
9084                 return false;
9085             }
9086             if ( d.getPolygons().size() != 2 ) {
9087                 return false;
9088             }
9089             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9090                 return false;
9091             }
9092             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9093                 return false;
9094             }
9095             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9096                 return false;
9097             }
9098             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9099                 return false;
9100             }
9101             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9102                 return false;
9103             }
9104             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9105                 return false;
9106             }
9107             p = d.getPolygons().get( 0 );
9108             if ( p.getPoints().size() != 3 ) {
9109                 return false;
9110             }
9111             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9112                 return false;
9113             }
9114             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9115                 return false;
9116             }
9117             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9118                 return false;
9119             }
9120             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9121                 return false;
9122             }
9123             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9124                 return false;
9125             }
9126             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9127                 return false;
9128             }
9129             p = d.getPolygons().get( 1 );
9130             if ( p.getPoints().size() != 3 ) {
9131                 return false;
9132             }
9133             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9134                 return false;
9135             }
9136             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9137                 return false;
9138             }
9139             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9140                 return false;
9141             }
9142         }
9143         catch ( final Exception e ) {
9144             e.printStackTrace( System.out );
9145             return false;
9146         }
9147         return true;
9148     }
9149
9150     private static boolean testPostOrderIterator() {
9151         try {
9152             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9153             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9154             PhylogenyNodeIterator it0;
9155             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9156                 it0.next();
9157             }
9158             for( it0.reset(); it0.hasNext(); ) {
9159                 it0.next();
9160             }
9161             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9162             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9163             if ( !it.next().getName().equals( "A" ) ) {
9164                 return false;
9165             }
9166             if ( !it.next().getName().equals( "B" ) ) {
9167                 return false;
9168             }
9169             if ( !it.next().getName().equals( "ab" ) ) {
9170                 return false;
9171             }
9172             if ( !it.next().getName().equals( "C" ) ) {
9173                 return false;
9174             }
9175             if ( !it.next().getName().equals( "D" ) ) {
9176                 return false;
9177             }
9178             if ( !it.next().getName().equals( "cd" ) ) {
9179                 return false;
9180             }
9181             if ( !it.next().getName().equals( "abcd" ) ) {
9182                 return false;
9183             }
9184             if ( !it.next().getName().equals( "E" ) ) {
9185                 return false;
9186             }
9187             if ( !it.next().getName().equals( "F" ) ) {
9188                 return false;
9189             }
9190             if ( !it.next().getName().equals( "ef" ) ) {
9191                 return false;
9192             }
9193             if ( !it.next().getName().equals( "G" ) ) {
9194                 return false;
9195             }
9196             if ( !it.next().getName().equals( "H" ) ) {
9197                 return false;
9198             }
9199             if ( !it.next().getName().equals( "gh" ) ) {
9200                 return false;
9201             }
9202             if ( !it.next().getName().equals( "efgh" ) ) {
9203                 return false;
9204             }
9205             if ( !it.next().getName().equals( "r" ) ) {
9206                 return false;
9207             }
9208             if ( it.hasNext() ) {
9209                 return false;
9210             }
9211         }
9212         catch ( final Exception e ) {
9213             e.printStackTrace( System.out );
9214             return false;
9215         }
9216         return true;
9217     }
9218
9219     private static boolean testPreOrderIterator() {
9220         try {
9221             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9222             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9223             PhylogenyNodeIterator it0;
9224             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9225                 it0.next();
9226             }
9227             for( it0.reset(); it0.hasNext(); ) {
9228                 it0.next();
9229             }
9230             PhylogenyNodeIterator it = t0.iteratorPreorder();
9231             if ( !it.next().getName().equals( "r" ) ) {
9232                 return false;
9233             }
9234             if ( !it.next().getName().equals( "ab" ) ) {
9235                 return false;
9236             }
9237             if ( !it.next().getName().equals( "A" ) ) {
9238                 return false;
9239             }
9240             if ( !it.next().getName().equals( "B" ) ) {
9241                 return false;
9242             }
9243             if ( !it.next().getName().equals( "cd" ) ) {
9244                 return false;
9245             }
9246             if ( !it.next().getName().equals( "C" ) ) {
9247                 return false;
9248             }
9249             if ( !it.next().getName().equals( "D" ) ) {
9250                 return false;
9251             }
9252             if ( it.hasNext() ) {
9253                 return false;
9254             }
9255             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9256             it = t1.iteratorPreorder();
9257             if ( !it.next().getName().equals( "r" ) ) {
9258                 return false;
9259             }
9260             if ( !it.next().getName().equals( "abcd" ) ) {
9261                 return false;
9262             }
9263             if ( !it.next().getName().equals( "ab" ) ) {
9264                 return false;
9265             }
9266             if ( !it.next().getName().equals( "A" ) ) {
9267                 return false;
9268             }
9269             if ( !it.next().getName().equals( "B" ) ) {
9270                 return false;
9271             }
9272             if ( !it.next().getName().equals( "cd" ) ) {
9273                 return false;
9274             }
9275             if ( !it.next().getName().equals( "C" ) ) {
9276                 return false;
9277             }
9278             if ( !it.next().getName().equals( "D" ) ) {
9279                 return false;
9280             }
9281             if ( !it.next().getName().equals( "efgh" ) ) {
9282                 return false;
9283             }
9284             if ( !it.next().getName().equals( "ef" ) ) {
9285                 return false;
9286             }
9287             if ( !it.next().getName().equals( "E" ) ) {
9288                 return false;
9289             }
9290             if ( !it.next().getName().equals( "F" ) ) {
9291                 return false;
9292             }
9293             if ( !it.next().getName().equals( "gh" ) ) {
9294                 return false;
9295             }
9296             if ( !it.next().getName().equals( "G" ) ) {
9297                 return false;
9298             }
9299             if ( !it.next().getName().equals( "H" ) ) {
9300                 return false;
9301             }
9302             if ( it.hasNext() ) {
9303                 return false;
9304             }
9305         }
9306         catch ( final Exception e ) {
9307             e.printStackTrace( System.out );
9308             return false;
9309         }
9310         return true;
9311     }
9312
9313     private static boolean testPropertiesMap() {
9314         try {
9315             final PropertiesMap pm = new PropertiesMap();
9316             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9317             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9318             final Property p2 = new Property( "something:else",
9319                                               "?",
9320                                               "improbable:research",
9321                                               "xsd:decimal",
9322                                               AppliesTo.NODE );
9323             pm.addProperty( p0 );
9324             pm.addProperty( p1 );
9325             pm.addProperty( p2 );
9326             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9327                 return false;
9328             }
9329             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9330                 return false;
9331             }
9332             if ( pm.getProperties().size() != 3 ) {
9333                 return false;
9334             }
9335             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9336                 return false;
9337             }
9338             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9339                 return false;
9340             }
9341             if ( pm.getProperties().size() != 3 ) {
9342                 return false;
9343             }
9344             pm.removeProperty( "dimensions:diameter" );
9345             if ( pm.getProperties().size() != 2 ) {
9346                 return false;
9347             }
9348             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
9349                 return false;
9350             }
9351             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9352                 return false;
9353             }
9354         }
9355         catch ( final Exception e ) {
9356             e.printStackTrace( System.out );
9357             return false;
9358         }
9359         return true;
9360     }
9361
9362     private static boolean testProteinId() {
9363         try {
9364             final ProteinId id1 = new ProteinId( "a" );
9365             final ProteinId id2 = new ProteinId( "a" );
9366             final ProteinId id3 = new ProteinId( "A" );
9367             final ProteinId id4 = new ProteinId( "b" );
9368             if ( !id1.equals( id1 ) ) {
9369                 return false;
9370             }
9371             if ( id1.getId().equals( "x" ) ) {
9372                 return false;
9373             }
9374             if ( id1.getId().equals( null ) ) {
9375                 return false;
9376             }
9377             if ( !id1.equals( id2 ) ) {
9378                 return false;
9379             }
9380             if ( id1.equals( id3 ) ) {
9381                 return false;
9382             }
9383             if ( id1.hashCode() != id1.hashCode() ) {
9384                 return false;
9385             }
9386             if ( id1.hashCode() != id2.hashCode() ) {
9387                 return false;
9388             }
9389             if ( id1.hashCode() == id3.hashCode() ) {
9390                 return false;
9391             }
9392             if ( id1.compareTo( id1 ) != 0 ) {
9393                 return false;
9394             }
9395             if ( id1.compareTo( id2 ) != 0 ) {
9396                 return false;
9397             }
9398             if ( id1.compareTo( id3 ) != 0 ) {
9399                 return false;
9400             }
9401             if ( id1.compareTo( id4 ) >= 0 ) {
9402                 return false;
9403             }
9404             if ( id4.compareTo( id1 ) <= 0 ) {
9405                 return false;
9406             }
9407             if ( !id4.getId().equals( "b" ) ) {
9408                 return false;
9409             }
9410             final ProteinId id5 = new ProteinId( " C " );
9411             if ( !id5.getId().equals( "C" ) ) {
9412                 return false;
9413             }
9414             if ( id5.equals( id1 ) ) {
9415                 return false;
9416             }
9417         }
9418         catch ( final Exception e ) {
9419             e.printStackTrace( System.out );
9420             return false;
9421         }
9422         return true;
9423     }
9424
9425     private static boolean testReIdMethods() {
9426         try {
9427             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9428             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
9429             final long count = PhylogenyNode.getNodeCount();
9430             p.levelOrderReID();
9431             if ( p.getNode( "r" ).getId() != count ) {
9432                 return false;
9433             }
9434             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
9435                 return false;
9436             }
9437             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
9438                 return false;
9439             }
9440             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
9441                 return false;
9442             }
9443             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
9444                 return false;
9445             }
9446             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
9447                 return false;
9448             }
9449             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
9450                 return false;
9451             }
9452             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
9453                 return false;
9454             }
9455             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
9456                 return false;
9457             }
9458             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
9459                 return false;
9460             }
9461             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
9462                 return false;
9463             }
9464             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
9465                 return false;
9466             }
9467             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
9468                 return false;
9469             }
9470             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
9471                 return false;
9472             }
9473             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
9474                 return false;
9475             }
9476         }
9477         catch ( final Exception e ) {
9478             e.printStackTrace( System.out );
9479             return false;
9480         }
9481         return true;
9482     }
9483
9484     private static boolean testRerooting() {
9485         try {
9486             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9487             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",
9488                                                  new NHXParser() )[ 0 ];
9489             if ( !t1.isRooted() ) {
9490                 return false;
9491             }
9492             t1.reRoot( t1.getNode( "D" ) );
9493             t1.reRoot( t1.getNode( "CD" ) );
9494             t1.reRoot( t1.getNode( "A" ) );
9495             t1.reRoot( t1.getNode( "B" ) );
9496             t1.reRoot( t1.getNode( "AB" ) );
9497             t1.reRoot( t1.getNode( "D" ) );
9498             t1.reRoot( t1.getNode( "C" ) );
9499             t1.reRoot( t1.getNode( "CD" ) );
9500             t1.reRoot( t1.getNode( "A" ) );
9501             t1.reRoot( t1.getNode( "B" ) );
9502             t1.reRoot( t1.getNode( "AB" ) );
9503             t1.reRoot( t1.getNode( "D" ) );
9504             t1.reRoot( t1.getNode( "D" ) );
9505             t1.reRoot( t1.getNode( "C" ) );
9506             t1.reRoot( t1.getNode( "A" ) );
9507             t1.reRoot( t1.getNode( "B" ) );
9508             t1.reRoot( t1.getNode( "AB" ) );
9509             t1.reRoot( t1.getNode( "C" ) );
9510             t1.reRoot( t1.getNode( "D" ) );
9511             t1.reRoot( t1.getNode( "CD" ) );
9512             t1.reRoot( t1.getNode( "D" ) );
9513             t1.reRoot( t1.getNode( "A" ) );
9514             t1.reRoot( t1.getNode( "B" ) );
9515             t1.reRoot( t1.getNode( "AB" ) );
9516             t1.reRoot( t1.getNode( "C" ) );
9517             t1.reRoot( t1.getNode( "D" ) );
9518             t1.reRoot( t1.getNode( "CD" ) );
9519             t1.reRoot( t1.getNode( "D" ) );
9520             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
9521                 return false;
9522             }
9523             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
9524                 return false;
9525             }
9526             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
9527                 return false;
9528             }
9529             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
9530                 return false;
9531             }
9532             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
9533                 return false;
9534             }
9535             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
9536                 return false;
9537             }
9538             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",
9539                                                  new NHXParser() )[ 0 ];
9540             t2.reRoot( t2.getNode( "A" ) );
9541             t2.reRoot( t2.getNode( "D" ) );
9542             t2.reRoot( t2.getNode( "ABC" ) );
9543             t2.reRoot( t2.getNode( "A" ) );
9544             t2.reRoot( t2.getNode( "B" ) );
9545             t2.reRoot( t2.getNode( "D" ) );
9546             t2.reRoot( t2.getNode( "C" ) );
9547             t2.reRoot( t2.getNode( "ABC" ) );
9548             t2.reRoot( t2.getNode( "A" ) );
9549             t2.reRoot( t2.getNode( "B" ) );
9550             t2.reRoot( t2.getNode( "AB" ) );
9551             t2.reRoot( t2.getNode( "AB" ) );
9552             t2.reRoot( t2.getNode( "D" ) );
9553             t2.reRoot( t2.getNode( "C" ) );
9554             t2.reRoot( t2.getNode( "B" ) );
9555             t2.reRoot( t2.getNode( "AB" ) );
9556             t2.reRoot( t2.getNode( "D" ) );
9557             t2.reRoot( t2.getNode( "D" ) );
9558             t2.reRoot( t2.getNode( "ABC" ) );
9559             t2.reRoot( t2.getNode( "A" ) );
9560             t2.reRoot( t2.getNode( "B" ) );
9561             t2.reRoot( t2.getNode( "AB" ) );
9562             t2.reRoot( t2.getNode( "D" ) );
9563             t2.reRoot( t2.getNode( "C" ) );
9564             t2.reRoot( t2.getNode( "ABC" ) );
9565             t2.reRoot( t2.getNode( "A" ) );
9566             t2.reRoot( t2.getNode( "B" ) );
9567             t2.reRoot( t2.getNode( "AB" ) );
9568             t2.reRoot( t2.getNode( "D" ) );
9569             t2.reRoot( t2.getNode( "D" ) );
9570             t2.reRoot( t2.getNode( "C" ) );
9571             t2.reRoot( t2.getNode( "A" ) );
9572             t2.reRoot( t2.getNode( "B" ) );
9573             t2.reRoot( t2.getNode( "AB" ) );
9574             t2.reRoot( t2.getNode( "C" ) );
9575             t2.reRoot( t2.getNode( "D" ) );
9576             t2.reRoot( t2.getNode( "ABC" ) );
9577             t2.reRoot( t2.getNode( "D" ) );
9578             t2.reRoot( t2.getNode( "A" ) );
9579             t2.reRoot( t2.getNode( "B" ) );
9580             t2.reRoot( t2.getNode( "AB" ) );
9581             t2.reRoot( t2.getNode( "C" ) );
9582             t2.reRoot( t2.getNode( "D" ) );
9583             t2.reRoot( t2.getNode( "ABC" ) );
9584             t2.reRoot( t2.getNode( "D" ) );
9585             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9586                 return false;
9587             }
9588             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9589                 return false;
9590             }
9591             t2.reRoot( t2.getNode( "ABC" ) );
9592             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9593                 return false;
9594             }
9595             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9596                 return false;
9597             }
9598             t2.reRoot( t2.getNode( "AB" ) );
9599             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9600                 return false;
9601             }
9602             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9603                 return false;
9604             }
9605             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9606                 return false;
9607             }
9608             t2.reRoot( t2.getNode( "AB" ) );
9609             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9610                 return false;
9611             }
9612             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9613                 return false;
9614             }
9615             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9616                 return false;
9617             }
9618             t2.reRoot( t2.getNode( "D" ) );
9619             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9620                 return false;
9621             }
9622             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9623                 return false;
9624             }
9625             t2.reRoot( t2.getNode( "ABC" ) );
9626             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9627                 return false;
9628             }
9629             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9630                 return false;
9631             }
9632             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
9633                                                  new NHXParser() )[ 0 ];
9634             t3.reRoot( t3.getNode( "B" ) );
9635             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9636                 return false;
9637             }
9638             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9639                 return false;
9640             }
9641             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9642                 return false;
9643             }
9644             t3.reRoot( t3.getNode( "B" ) );
9645             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9646                 return false;
9647             }
9648             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9649                 return false;
9650             }
9651             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9652                 return false;
9653             }
9654             t3.reRoot( t3.getRoot() );
9655             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9656                 return false;
9657             }
9658             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9659                 return false;
9660             }
9661             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9662                 return false;
9663             }
9664         }
9665         catch ( final Exception e ) {
9666             e.printStackTrace( System.out );
9667             return false;
9668         }
9669         return true;
9670     }
9671
9672     private static boolean testSDIse() {
9673         try {
9674             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9675             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9676             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9677             gene1.setRooted( true );
9678             species1.setRooted( true );
9679             final SDI sdi = new SDI( gene1, species1 );
9680             if ( !gene1.getRoot().isDuplication() ) {
9681                 return false;
9682             }
9683             final Phylogeny species2 = factory
9684                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9685                              new NHXParser() )[ 0 ];
9686             final Phylogeny gene2 = factory
9687                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9688                              new NHXParser() )[ 0 ];
9689             species2.setRooted( true );
9690             gene2.setRooted( true );
9691             final SDI sdi2 = new SDI( gene2, species2 );
9692             if ( sdi2.getDuplicationsSum() != 0 ) {
9693                 return false;
9694             }
9695             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9696                 return false;
9697             }
9698             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9699                 return false;
9700             }
9701             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9702                 return false;
9703             }
9704             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9705                 return false;
9706             }
9707             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9708                 return false;
9709             }
9710             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9711                 return false;
9712             }
9713             final Phylogeny species3 = factory
9714                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9715                              new NHXParser() )[ 0 ];
9716             final Phylogeny gene3 = factory
9717                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9718                              new NHXParser() )[ 0 ];
9719             species3.setRooted( true );
9720             gene3.setRooted( true );
9721             final SDI sdi3 = new SDI( gene3, species3 );
9722             if ( sdi3.getDuplicationsSum() != 1 ) {
9723                 return false;
9724             }
9725             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9726                 return false;
9727             }
9728             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9729                 return false;
9730             }
9731             final Phylogeny species4 = factory
9732                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9733                              new NHXParser() )[ 0 ];
9734             final Phylogeny gene4 = factory
9735                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9736                              new NHXParser() )[ 0 ];
9737             species4.setRooted( true );
9738             gene4.setRooted( true );
9739             final SDI sdi4 = new SDI( gene4, species4 );
9740             if ( sdi4.getDuplicationsSum() != 1 ) {
9741                 return false;
9742             }
9743             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9744                 return false;
9745             }
9746             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9747                 return false;
9748             }
9749             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9750                 return false;
9751             }
9752             if ( species4.getNumberOfExternalNodes() != 6 ) {
9753                 return false;
9754             }
9755             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9756                 return false;
9757             }
9758             final Phylogeny species5 = factory
9759                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9760                              new NHXParser() )[ 0 ];
9761             final Phylogeny gene5 = factory
9762                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9763                              new NHXParser() )[ 0 ];
9764             species5.setRooted( true );
9765             gene5.setRooted( true );
9766             final SDI sdi5 = new SDI( gene5, species5 );
9767             if ( sdi5.getDuplicationsSum() != 2 ) {
9768                 return false;
9769             }
9770             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9771                 return false;
9772             }
9773             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9774                 return false;
9775             }
9776             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9777                 return false;
9778             }
9779             if ( species5.getNumberOfExternalNodes() != 6 ) {
9780                 return false;
9781             }
9782             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9783                 return false;
9784             }
9785             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9786             // Conjecture for Comparing Molecular Phylogenies"
9787             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9788             final Phylogeny species6 = factory
9789                     .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,"
9790                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9791                              new NHXParser() )[ 0 ];
9792             final Phylogeny gene6 = factory
9793                     .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,"
9794                                      + "((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,"
9795                                      + "(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;",
9796                              new NHXParser() )[ 0 ];
9797             species6.setRooted( true );
9798             gene6.setRooted( true );
9799             final SDI sdi6 = new SDI( gene6, species6 );
9800             if ( sdi6.getDuplicationsSum() != 3 ) {
9801                 return false;
9802             }
9803             if ( !gene6.getNode( "r" ).isDuplication() ) {
9804                 return false;
9805             }
9806             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9807                 return false;
9808             }
9809             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9810                 return false;
9811             }
9812             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9813                 return false;
9814             }
9815             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9816                 return false;
9817             }
9818             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9819                 return false;
9820             }
9821             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9822                 return false;
9823             }
9824             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9825                 return false;
9826             }
9827             sdi6.computeMappingCostL();
9828             if ( sdi6.computeMappingCostL() != 17 ) {
9829                 return false;
9830             }
9831             if ( species6.getNumberOfExternalNodes() != 9 ) {
9832                 return false;
9833             }
9834             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9835                 return false;
9836             }
9837             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9838                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9839                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9840                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9841                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9842             species7.setRooted( true );
9843             final Phylogeny gene7_1 = Test
9844                     .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])" );
9845             gene7_1.setRooted( true );
9846             final SDI sdi7 = new SDI( gene7_1, species7 );
9847             if ( sdi7.getDuplicationsSum() != 0 ) {
9848                 return false;
9849             }
9850             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9851                 return false;
9852             }
9853             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9854                 return false;
9855             }
9856             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9857                 return false;
9858             }
9859             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9860                 return false;
9861             }
9862             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9863                 return false;
9864             }
9865             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9866                 return false;
9867             }
9868             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9869                 return false;
9870             }
9871             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9872                 return false;
9873             }
9874             final Phylogeny gene7_2 = Test
9875                     .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])" );
9876             gene7_2.setRooted( true );
9877             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9878             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9879                 return false;
9880             }
9881             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9882                 return false;
9883             }
9884             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9885                 return false;
9886             }
9887             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9888                 return false;
9889             }
9890             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9891                 return false;
9892             }
9893             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9894                 return false;
9895             }
9896             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9897                 return false;
9898             }
9899             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9900                 return false;
9901             }
9902             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9903                 return false;
9904             }
9905             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9906                 return false;
9907             }
9908         }
9909         catch ( final Exception e ) {
9910             return false;
9911         }
9912         return true;
9913     }
9914
9915     private static boolean testSDIunrooted() {
9916         try {
9917             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9918             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9919             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9920             final Iterator<PhylogenyBranch> iter = l.iterator();
9921             PhylogenyBranch br = iter.next();
9922             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9923                 return false;
9924             }
9925             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9926                 return false;
9927             }
9928             br = iter.next();
9929             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9930                 return false;
9931             }
9932             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9933                 return false;
9934             }
9935             br = iter.next();
9936             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9937                 return false;
9938             }
9939             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9940                 return false;
9941             }
9942             br = iter.next();
9943             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9944                 return false;
9945             }
9946             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9947                 return false;
9948             }
9949             br = iter.next();
9950             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9951                 return false;
9952             }
9953             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9954                 return false;
9955             }
9956             br = iter.next();
9957             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9958                 return false;
9959             }
9960             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9961                 return false;
9962             }
9963             br = iter.next();
9964             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9965                 return false;
9966             }
9967             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9968                 return false;
9969             }
9970             br = iter.next();
9971             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9972                 return false;
9973             }
9974             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9975                 return false;
9976             }
9977             br = iter.next();
9978             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9979                 return false;
9980             }
9981             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9982                 return false;
9983             }
9984             br = iter.next();
9985             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9986                 return false;
9987             }
9988             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9989                 return false;
9990             }
9991             br = iter.next();
9992             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9993                 return false;
9994             }
9995             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9996                 return false;
9997             }
9998             br = iter.next();
9999             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10000                 return false;
10001             }
10002             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10003                 return false;
10004             }
10005             br = iter.next();
10006             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10007                 return false;
10008             }
10009             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10010                 return false;
10011             }
10012             br = iter.next();
10013             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10014                 return false;
10015             }
10016             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10017                 return false;
10018             }
10019             br = iter.next();
10020             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10021                 return false;
10022             }
10023             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10024                 return false;
10025             }
10026             if ( iter.hasNext() ) {
10027                 return false;
10028             }
10029             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10030             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10031             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10032             br = iter1.next();
10033             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10034                 return false;
10035             }
10036             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10037                 return false;
10038             }
10039             br = iter1.next();
10040             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10041                 return false;
10042             }
10043             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10044                 return false;
10045             }
10046             br = iter1.next();
10047             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10048                 return false;
10049             }
10050             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10051                 return false;
10052             }
10053             if ( iter1.hasNext() ) {
10054                 return false;
10055             }
10056             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10057             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10058             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10059             br = iter2.next();
10060             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10061                 return false;
10062             }
10063             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10064                 return false;
10065             }
10066             br = iter2.next();
10067             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10068                 return false;
10069             }
10070             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10071                 return false;
10072             }
10073             br = iter2.next();
10074             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10075                 return false;
10076             }
10077             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10078                 return false;
10079             }
10080             if ( iter2.hasNext() ) {
10081                 return false;
10082             }
10083             final Phylogeny species0 = factory
10084                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10085                              new NHXParser() )[ 0 ];
10086             final Phylogeny gene1 = factory
10087                     .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])",
10088                              new NHXParser() )[ 0 ];
10089             species0.setRooted( true );
10090             gene1.setRooted( true );
10091             final SDIR sdi_unrooted = new SDIR();
10092             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10093             if ( sdi_unrooted.getCount() != 1 ) {
10094                 return false;
10095             }
10096             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10097                 return false;
10098             }
10099             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10100                 return false;
10101             }
10102             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10103                 return false;
10104             }
10105             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10106                 return false;
10107             }
10108             final Phylogeny gene2 = factory
10109                     .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])",
10110                              new NHXParser() )[ 0 ];
10111             gene2.setRooted( true );
10112             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10113             if ( sdi_unrooted.getCount() != 1 ) {
10114                 return false;
10115             }
10116             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10117                 return false;
10118             }
10119             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10120                 return false;
10121             }
10122             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10123                 return false;
10124             }
10125             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10126                 return false;
10127             }
10128             final Phylogeny species6 = factory
10129                     .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,"
10130                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10131                              new NHXParser() )[ 0 ];
10132             final Phylogeny gene6 = factory
10133                     .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],"
10134                                      + "(((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],"
10135                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10136                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10137                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10138                              new NHXParser() )[ 0 ];
10139             species6.setRooted( true );
10140             gene6.setRooted( true );
10141             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10142             if ( sdi_unrooted.getCount() != 1 ) {
10143                 return false;
10144             }
10145             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10146                 return false;
10147             }
10148             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10149                 return false;
10150             }
10151             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10152                 return false;
10153             }
10154             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10155                 return false;
10156             }
10157             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10158                 return false;
10159             }
10160             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10161                 return false;
10162             }
10163             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10164                 return false;
10165             }
10166             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10167                 return false;
10168             }
10169             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10170                 return false;
10171             }
10172             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10173                 return false;
10174             }
10175             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10176                 return false;
10177             }
10178             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10179                 return false;
10180             }
10181             p6 = null;
10182             final Phylogeny species7 = factory
10183                     .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,"
10184                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10185                              new NHXParser() )[ 0 ];
10186             final Phylogeny gene7 = factory
10187                     .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],"
10188                                      + "(((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],"
10189                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10190                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10191                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10192                              new NHXParser() )[ 0 ];
10193             species7.setRooted( true );
10194             gene7.setRooted( true );
10195             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10196             if ( sdi_unrooted.getCount() != 1 ) {
10197                 return false;
10198             }
10199             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10200                 return false;
10201             }
10202             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10203                 return false;
10204             }
10205             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10206                 return false;
10207             }
10208             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10209                 return false;
10210             }
10211             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10212                 return false;
10213             }
10214             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10215                 return false;
10216             }
10217             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10218                 return false;
10219             }
10220             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10221                 return false;
10222             }
10223             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10224                 return false;
10225             }
10226             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10227                 return false;
10228             }
10229             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10230                 return false;
10231             }
10232             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10233                 return false;
10234             }
10235             p7 = null;
10236             final Phylogeny species8 = factory
10237                     .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,"
10238                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10239                              new NHXParser() )[ 0 ];
10240             final Phylogeny gene8 = factory
10241                     .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],"
10242                                      + "(((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],"
10243                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10244                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10245                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10246                              new NHXParser() )[ 0 ];
10247             species8.setRooted( true );
10248             gene8.setRooted( true );
10249             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10250             if ( sdi_unrooted.getCount() != 1 ) {
10251                 return false;
10252             }
10253             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10254                 return false;
10255             }
10256             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10257                 return false;
10258             }
10259             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10260                 return false;
10261             }
10262             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10263                 return false;
10264             }
10265             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10266                 return false;
10267             }
10268             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10269                 return false;
10270             }
10271             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10272                 return false;
10273             }
10274             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10275                 return false;
10276             }
10277             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10278                 return false;
10279             }
10280             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10281                 return false;
10282             }
10283             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10284                 return false;
10285             }
10286             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10287                 return false;
10288             }
10289             p8 = null;
10290         }
10291         catch ( final Exception e ) {
10292             e.printStackTrace( System.out );
10293             return false;
10294         }
10295         return true;
10296     }
10297
10298     private static boolean testSequenceDbWsTools1() {
10299         try {
10300             final PhylogenyNode n = new PhylogenyNode();
10301             n.setName( "NP_001025424" );
10302             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10303             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10304                     || !acc.getValue().equals( "NP_001025424" ) ) {
10305                 return false;
10306             }
10307             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10308             acc = SequenceDbWsTools.obtainSeqAccession( n );
10309             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10310                     || !acc.getValue().equals( "NP_001025424" ) ) {
10311                 return false;
10312             }
10313             n.setName( "NP_001025424.1" );
10314             acc = SequenceDbWsTools.obtainSeqAccession( n );
10315             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10316                     || !acc.getValue().equals( "NP_001025424" ) ) {
10317                 return false;
10318             }
10319             n.setName( "NM_001030253" );
10320             acc = SequenceDbWsTools.obtainSeqAccession( n );
10321             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10322                     || !acc.getValue().equals( "NM_001030253" ) ) {
10323                 return false;
10324             }
10325             n.setName( "BCL2_HUMAN" );
10326             acc = SequenceDbWsTools.obtainSeqAccession( n );
10327             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10328                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10329                 System.out.println( acc.toString() );
10330                 return false;
10331             }
10332             n.setName( "P10415" );
10333             acc = SequenceDbWsTools.obtainSeqAccession( n );
10334             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10335                     || !acc.getValue().equals( "P10415" ) ) {
10336                 System.out.println( acc.toString() );
10337                 return false;
10338             }
10339             n.setName( " P10415 " );
10340             acc = SequenceDbWsTools.obtainSeqAccession( n );
10341             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10342                     || !acc.getValue().equals( "P10415" ) ) {
10343                 System.out.println( acc.toString() );
10344                 return false;
10345             }
10346             n.setName( "_P10415|" );
10347             acc = SequenceDbWsTools.obtainSeqAccession( n );
10348             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10349                     || !acc.getValue().equals( "P10415" ) ) {
10350                 System.out.println( acc.toString() );
10351                 return false;
10352             }
10353             n.setName( "AY695820" );
10354             acc = SequenceDbWsTools.obtainSeqAccession( n );
10355             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10356                     || !acc.getValue().equals( "AY695820" ) ) {
10357                 System.out.println( acc.toString() );
10358                 return false;
10359             }
10360             n.setName( "_AY695820_" );
10361             acc = SequenceDbWsTools.obtainSeqAccession( n );
10362             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10363                     || !acc.getValue().equals( "AY695820" ) ) {
10364                 System.out.println( acc.toString() );
10365                 return false;
10366             }
10367             n.setName( "AAA59452" );
10368             acc = SequenceDbWsTools.obtainSeqAccession( n );
10369             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10370                     || !acc.getValue().equals( "AAA59452" ) ) {
10371                 System.out.println( acc.toString() );
10372                 return false;
10373             }
10374             n.setName( "_AAA59452_" );
10375             acc = SequenceDbWsTools.obtainSeqAccession( n );
10376             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10377                     || !acc.getValue().equals( "AAA59452" ) ) {
10378                 System.out.println( acc.toString() );
10379                 return false;
10380             }
10381             n.setName( "AAA59452.1" );
10382             acc = SequenceDbWsTools.obtainSeqAccession( n );
10383             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10384                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10385                 System.out.println( acc.toString() );
10386                 return false;
10387             }
10388             n.setName( "_AAA59452.1_" );
10389             acc = SequenceDbWsTools.obtainSeqAccession( n );
10390             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10391                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10392                 System.out.println( acc.toString() );
10393                 return false;
10394             }
10395             n.setName( "GI:94894583" );
10396             acc = SequenceDbWsTools.obtainSeqAccession( n );
10397             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10398                     || !acc.getValue().equals( "94894583" ) ) {
10399                 System.out.println( acc.toString() );
10400                 return false;
10401             }
10402             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10403             acc = SequenceDbWsTools.obtainSeqAccession( n );
10404             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10405                     || !acc.getValue().equals( "71845847" ) ) {
10406                 System.out.println( acc.toString() );
10407                 return false;
10408             }
10409             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10410             acc = SequenceDbWsTools.obtainSeqAccession( n );
10411             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10412                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
10413                 System.out.println( acc.toString() );
10414                 return false;
10415             }
10416         }
10417         catch ( final Exception e ) {
10418             return false;
10419         }
10420         return true;
10421     }
10422
10423     private static boolean testSequenceDbWsTools2() {
10424         try {
10425             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
10426             SequenceDbWsTools.obtainSeqInformation( n1 );
10427             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10428                 return false;
10429             }
10430             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10431                 return false;
10432             }
10433             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10434                 return false;
10435             }
10436             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
10437                 return false;
10438             }
10439             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
10440             SequenceDbWsTools.obtainSeqInformation( n2 );
10441             if ( !n2.getNodeData().getSequence().getName()
10442                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
10443                 return false;
10444             }
10445             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10446                 return false;
10447             }
10448             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10449                 return false;
10450             }
10451             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
10452                 return false;
10453             }
10454             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
10455             SequenceDbWsTools.obtainSeqInformation( n3 );
10456             if ( !n3.getNodeData().getSequence().getName()
10457                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
10458                 return false;
10459             }
10460             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
10461                 return false;
10462             }
10463             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10464                 return false;
10465             }
10466             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
10467                 return false;
10468             }
10469         }
10470         catch ( final IOException e ) {
10471             System.out.println();
10472             System.out.println( "the following might be due to absence internet connection:" );
10473             e.printStackTrace( System.out );
10474             return true;
10475         }
10476         catch ( final Exception e ) {
10477             e.printStackTrace();
10478             return false;
10479         }
10480         return true;
10481     }
10482
10483     private static boolean testSequenceIdParsing() {
10484         try {
10485             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
10486             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10487                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10488                 if ( id != null ) {
10489                     System.out.println( "value   =" + id.getValue() );
10490                     System.out.println( "provider=" + id.getSource() );
10491                 }
10492                 return false;
10493             }
10494             //
10495             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
10496             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10497                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10498                 if ( id != null ) {
10499                     System.out.println( "value   =" + id.getValue() );
10500                     System.out.println( "provider=" + id.getSource() );
10501                 }
10502                 return false;
10503             }
10504             //
10505             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
10506             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10507                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10508                 if ( id != null ) {
10509                     System.out.println( "value   =" + id.getValue() );
10510                     System.out.println( "provider=" + id.getSource() );
10511                 }
10512                 return false;
10513             }
10514             // 
10515             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
10516             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10517                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
10518                 if ( id != null ) {
10519                     System.out.println( "value   =" + id.getValue() );
10520                     System.out.println( "provider=" + id.getSource() );
10521                 }
10522                 return false;
10523             }
10524             // 
10525             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
10526             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10527                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
10528                 if ( id != null ) {
10529                     System.out.println( "value   =" + id.getValue() );
10530                     System.out.println( "provider=" + id.getSource() );
10531                 }
10532                 return false;
10533             }
10534             // 
10535             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
10536             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10537                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
10538                 if ( id != null ) {
10539                     System.out.println( "value   =" + id.getValue() );
10540                     System.out.println( "provider=" + id.getSource() );
10541                 }
10542                 return false;
10543             }
10544             // 
10545             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
10546             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10547                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
10548                 if ( id != null ) {
10549                     System.out.println( "value   =" + id.getValue() );
10550                     System.out.println( "provider=" + id.getSource() );
10551                 }
10552                 return false;
10553             }
10554             // 
10555             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
10556             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10557                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10558                 if ( id != null ) {
10559                     System.out.println( "value   =" + id.getValue() );
10560                     System.out.println( "provider=" + id.getSource() );
10561                 }
10562                 return false;
10563             }
10564             // 
10565             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
10566             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10567                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10568                 if ( id != null ) {
10569                     System.out.println( "value   =" + id.getValue() );
10570                     System.out.println( "provider=" + id.getSource() );
10571                 }
10572                 return false;
10573             }
10574             // 
10575             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
10576             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10577                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
10578                 if ( id != null ) {
10579                     System.out.println( "value   =" + id.getValue() );
10580                     System.out.println( "provider=" + id.getSource() );
10581                 }
10582                 return false;
10583             }
10584             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
10585             if ( id != null ) {
10586                 System.out.println( "value   =" + id.getValue() );
10587                 System.out.println( "provider=" + id.getSource() );
10588                 return false;
10589             }
10590         }
10591         catch ( final Exception e ) {
10592             e.printStackTrace( System.out );
10593             return false;
10594         }
10595         return true;
10596     }
10597
10598     private static boolean testSequenceWriter() {
10599         try {
10600             final String n = ForesterUtil.LINE_SEPARATOR;
10601             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
10602                 return false;
10603             }
10604             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
10605                 return false;
10606             }
10607             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
10608                 return false;
10609             }
10610             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
10611                 return false;
10612             }
10613             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
10614                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
10615                 return false;
10616             }
10617             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
10618                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
10619                 return false;
10620             }
10621         }
10622         catch ( final Exception e ) {
10623             e.printStackTrace();
10624             return false;
10625         }
10626         return true;
10627     }
10628
10629     private static boolean testSpecies() {
10630         try {
10631             final Species s1 = new BasicSpecies( "a" );
10632             final Species s2 = new BasicSpecies( "a" );
10633             final Species s3 = new BasicSpecies( "A" );
10634             final Species s4 = new BasicSpecies( "b" );
10635             if ( !s1.equals( s1 ) ) {
10636                 return false;
10637             }
10638             if ( s1.getSpeciesId().equals( "x" ) ) {
10639                 return false;
10640             }
10641             if ( s1.getSpeciesId().equals( null ) ) {
10642                 return false;
10643             }
10644             if ( !s1.equals( s2 ) ) {
10645                 return false;
10646             }
10647             if ( s1.equals( s3 ) ) {
10648                 return false;
10649             }
10650             if ( s1.hashCode() != s1.hashCode() ) {
10651                 return false;
10652             }
10653             if ( s1.hashCode() != s2.hashCode() ) {
10654                 return false;
10655             }
10656             if ( s1.hashCode() == s3.hashCode() ) {
10657                 return false;
10658             }
10659             if ( s1.compareTo( s1 ) != 0 ) {
10660                 return false;
10661             }
10662             if ( s1.compareTo( s2 ) != 0 ) {
10663                 return false;
10664             }
10665             if ( s1.compareTo( s3 ) != 0 ) {
10666                 return false;
10667             }
10668             if ( s1.compareTo( s4 ) >= 0 ) {
10669                 return false;
10670             }
10671             if ( s4.compareTo( s1 ) <= 0 ) {
10672                 return false;
10673             }
10674             if ( !s4.getSpeciesId().equals( "b" ) ) {
10675                 return false;
10676             }
10677             final Species s5 = new BasicSpecies( " C " );
10678             if ( !s5.getSpeciesId().equals( "C" ) ) {
10679                 return false;
10680             }
10681             if ( s5.equals( s1 ) ) {
10682                 return false;
10683             }
10684         }
10685         catch ( final Exception e ) {
10686             e.printStackTrace( System.out );
10687             return false;
10688         }
10689         return true;
10690     }
10691
10692     private static boolean testSplit() {
10693         try {
10694             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10695             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10696             //Archaeopteryx.createApplication( p0 );
10697             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10698             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10699             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10700             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10701             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10702             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10703             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10704             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10705             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10706             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10707             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
10708             // System.out.println( s0.toString() );
10709             //
10710             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10712             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10713             if ( s0.match( query_nodes ) ) {
10714                 return false;
10715             }
10716             query_nodes = new HashSet<PhylogenyNode>();
10717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10718             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10719             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10724             if ( !s0.match( query_nodes ) ) {
10725                 return false;
10726             }
10727             //
10728             query_nodes = new HashSet<PhylogenyNode>();
10729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10731             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10732             if ( !s0.match( query_nodes ) ) {
10733                 return false;
10734             }
10735             //
10736             query_nodes = new HashSet<PhylogenyNode>();
10737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10741             if ( !s0.match( query_nodes ) ) {
10742                 return false;
10743             }
10744             //
10745             query_nodes = new HashSet<PhylogenyNode>();
10746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10750             if ( !s0.match( query_nodes ) ) {
10751                 return false;
10752             }
10753             //
10754             query_nodes = new HashSet<PhylogenyNode>();
10755             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10756             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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             if ( !s0.match( query_nodes ) ) {
10766                 return false;
10767             }
10768             //
10769             query_nodes = new HashSet<PhylogenyNode>();
10770             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10771             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10775             if ( !s0.match( query_nodes ) ) {
10776                 return false;
10777             }
10778             //
10779             query_nodes = new HashSet<PhylogenyNode>();
10780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10781             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10782             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
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             if ( !s0.match( query_nodes ) ) {
10793                 return false;
10794             }
10795             //
10796             query_nodes = new HashSet<PhylogenyNode>();
10797             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10798             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10799             if ( s0.match( query_nodes ) ) {
10800                 return false;
10801             }
10802             //
10803             query_nodes = new HashSet<PhylogenyNode>();
10804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10807             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10808             if ( s0.match( query_nodes ) ) {
10809                 return false;
10810             }
10811             //
10812             query_nodes = new HashSet<PhylogenyNode>();
10813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10815             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10816             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10817             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10818             if ( s0.match( query_nodes ) ) {
10819                 return false;
10820             }
10821             //
10822             query_nodes = new HashSet<PhylogenyNode>();
10823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10824             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10825             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10826             if ( s0.match( query_nodes ) ) {
10827                 return false;
10828             }
10829             //
10830             query_nodes = new HashSet<PhylogenyNode>();
10831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10833             if ( s0.match( query_nodes ) ) {
10834                 return false;
10835             }
10836             //
10837             query_nodes = new HashSet<PhylogenyNode>();
10838             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10840             if ( s0.match( query_nodes ) ) {
10841                 return false;
10842             }
10843             //
10844             query_nodes = new HashSet<PhylogenyNode>();
10845             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10846             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10847             if ( s0.match( query_nodes ) ) {
10848                 return false;
10849             }
10850             //
10851             query_nodes = new HashSet<PhylogenyNode>();
10852             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10853             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10854             if ( s0.match( query_nodes ) ) {
10855                 return false;
10856             }
10857             //
10858             query_nodes = new HashSet<PhylogenyNode>();
10859             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10860             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10861             if ( s0.match( query_nodes ) ) {
10862                 return false;
10863             }
10864             //
10865             query_nodes = new HashSet<PhylogenyNode>();
10866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10867             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10868             if ( s0.match( query_nodes ) ) {
10869                 return false;
10870             }
10871             //
10872             query_nodes = new HashSet<PhylogenyNode>();
10873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10874             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
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( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10882             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10883             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10884             if ( s0.match( query_nodes ) ) {
10885                 return false;
10886             }
10887             //
10888             query_nodes = new HashSet<PhylogenyNode>();
10889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10892             if ( s0.match( query_nodes ) ) {
10893                 return false;
10894             }
10895             //
10896             query_nodes = new HashSet<PhylogenyNode>();
10897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10900             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10901             if ( s0.match( query_nodes ) ) {
10902                 return false;
10903             }
10904             /////////
10905             //            query_nodes = new HashSet<PhylogenyNode>();
10906             //            query_nodes.add( new PhylogenyNode( "X" ) );
10907             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10908             //            query_nodes.add( new PhylogenyNode( "A" ) );
10909             //            query_nodes.add( new PhylogenyNode( "B" ) );
10910             //            query_nodes.add( new PhylogenyNode( "C" ) );
10911             //            query_nodes.add( new PhylogenyNode( "D" ) );
10912             //            query_nodes.add( new PhylogenyNode( "E" ) );
10913             //            query_nodes.add( new PhylogenyNode( "F" ) );
10914             //            query_nodes.add( new PhylogenyNode( "G" ) );
10915             //            if ( !s0.match( query_nodes ) ) {
10916             //                return false;
10917             //            }
10918             //            query_nodes = new HashSet<PhylogenyNode>();
10919             //            query_nodes.add( new PhylogenyNode( "X" ) );
10920             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10921             //            query_nodes.add( new PhylogenyNode( "A" ) );
10922             //            query_nodes.add( new PhylogenyNode( "B" ) );
10923             //            query_nodes.add( new PhylogenyNode( "C" ) );
10924             //            if ( !s0.match( query_nodes ) ) {
10925             //                return false;
10926             //            }
10927             //            //
10928             //            query_nodes = new HashSet<PhylogenyNode>();
10929             //            query_nodes.add( new PhylogenyNode( "X" ) );
10930             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10931             //            query_nodes.add( new PhylogenyNode( "D" ) );
10932             //            query_nodes.add( new PhylogenyNode( "E" ) );
10933             //            query_nodes.add( new PhylogenyNode( "F" ) );
10934             //            query_nodes.add( new PhylogenyNode( "G" ) );
10935             //            if ( !s0.match( query_nodes ) ) {
10936             //                return false;
10937             //            }
10938             //            //
10939             //            query_nodes = new HashSet<PhylogenyNode>();
10940             //            query_nodes.add( new PhylogenyNode( "X" ) );
10941             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10942             //            query_nodes.add( new PhylogenyNode( "A" ) );
10943             //            query_nodes.add( new PhylogenyNode( "B" ) );
10944             //            query_nodes.add( new PhylogenyNode( "C" ) );
10945             //            query_nodes.add( new PhylogenyNode( "D" ) );
10946             //            if ( !s0.match( query_nodes ) ) {
10947             //                return false;
10948             //            }
10949             //            //
10950             //            query_nodes = new HashSet<PhylogenyNode>();
10951             //            query_nodes.add( new PhylogenyNode( "X" ) );
10952             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10953             //            query_nodes.add( new PhylogenyNode( "E" ) );
10954             //            query_nodes.add( new PhylogenyNode( "F" ) );
10955             //            query_nodes.add( new PhylogenyNode( "G" ) );
10956             //            if ( !s0.match( query_nodes ) ) {
10957             //                return false;
10958             //            }
10959             //            //
10960             //            query_nodes = new HashSet<PhylogenyNode>();
10961             //            query_nodes.add( new PhylogenyNode( "X" ) );
10962             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10963             //            query_nodes.add( new PhylogenyNode( "F" ) );
10964             //            query_nodes.add( new PhylogenyNode( "G" ) );
10965             //            if ( !s0.match( query_nodes ) ) {
10966             //                return false;
10967             //            }
10968             //
10969             query_nodes = new HashSet<PhylogenyNode>();
10970             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10971             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10972             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10974             if ( s0.match( query_nodes ) ) {
10975                 return false;
10976             }
10977             //
10978             query_nodes = new HashSet<PhylogenyNode>();
10979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10981             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10982             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10983             if ( s0.match( query_nodes ) ) {
10984                 return false;
10985             }
10986             ///////////////////////////
10987             //
10988             query_nodes = new HashSet<PhylogenyNode>();
10989             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10992             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10993             if ( s0.match( query_nodes ) ) {
10994                 return false;
10995             }
10996             //
10997             query_nodes = new HashSet<PhylogenyNode>();
10998             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10999             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11002             if ( s0.match( query_nodes ) ) {
11003                 return false;
11004             }
11005             //
11006             query_nodes = new HashSet<PhylogenyNode>();
11007             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11011             if ( s0.match( query_nodes ) ) {
11012                 return false;
11013             }
11014             //
11015             query_nodes = new HashSet<PhylogenyNode>();
11016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11018             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11019             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11020             if ( s0.match( query_nodes ) ) {
11021                 return false;
11022             }
11023             //
11024             query_nodes = new HashSet<PhylogenyNode>();
11025             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11026             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11027             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11029             if ( s0.match( query_nodes ) ) {
11030                 return false;
11031             }
11032             //
11033             query_nodes = new HashSet<PhylogenyNode>();
11034             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11035             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11036             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11037             if ( s0.match( query_nodes ) ) {
11038                 return false;
11039             }
11040             //
11041             query_nodes = new HashSet<PhylogenyNode>();
11042             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11043             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11044             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11047             if ( s0.match( query_nodes ) ) {
11048                 return false;
11049             }
11050             //
11051             query_nodes = new HashSet<PhylogenyNode>();
11052             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11053             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11056             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11057             if ( s0.match( query_nodes ) ) {
11058                 return false;
11059             }
11060             //
11061             query_nodes = new HashSet<PhylogenyNode>();
11062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11063             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11064             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11066             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11067             if ( s0.match( query_nodes ) ) {
11068                 return false;
11069             }
11070             //
11071             query_nodes = new HashSet<PhylogenyNode>();
11072             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11074             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11075             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11076             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11077             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11078             if ( s0.match( query_nodes ) ) {
11079                 return false;
11080             }
11081         }
11082         catch ( final Exception e ) {
11083             e.printStackTrace();
11084             return false;
11085         }
11086         return true;
11087     }
11088
11089     private static boolean testSplitStrict() {
11090         try {
11091             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11092             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11093             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11094             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11095             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11096             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11097             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11098             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11099             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11100             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11101             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11102             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11103             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11104             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11105             if ( s0.match( query_nodes ) ) {
11106                 return false;
11107             }
11108             query_nodes = new HashSet<PhylogenyNode>();
11109             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11110             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11111             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11112             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11113             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11115             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11116             if ( !s0.match( query_nodes ) ) {
11117                 return false;
11118             }
11119             //
11120             query_nodes = new HashSet<PhylogenyNode>();
11121             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11122             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11123             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11124             if ( !s0.match( query_nodes ) ) {
11125                 return false;
11126             }
11127             //
11128             query_nodes = new HashSet<PhylogenyNode>();
11129             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11130             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11131             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11132             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11133             if ( !s0.match( query_nodes ) ) {
11134                 return false;
11135             }
11136             //
11137             query_nodes = new HashSet<PhylogenyNode>();
11138             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11139             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11140             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11141             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11142             if ( !s0.match( query_nodes ) ) {
11143                 return false;
11144             }
11145             //
11146             query_nodes = new HashSet<PhylogenyNode>();
11147             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11148             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11149             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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             if ( !s0.match( query_nodes ) ) {
11158                 return false;
11159             }
11160             //
11161             query_nodes = new HashSet<PhylogenyNode>();
11162             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11163             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11164             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11167             if ( !s0.match( query_nodes ) ) {
11168                 return false;
11169             }
11170             //
11171             query_nodes = new HashSet<PhylogenyNode>();
11172             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11173             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11174             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
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             if ( !s0.match( query_nodes ) ) {
11185                 return false;
11186             }
11187             //
11188             query_nodes = new HashSet<PhylogenyNode>();
11189             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11190             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11191             if ( s0.match( query_nodes ) ) {
11192                 return false;
11193             }
11194             //
11195             query_nodes = new HashSet<PhylogenyNode>();
11196             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11197             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11198             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11199             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11200             if ( s0.match( query_nodes ) ) {
11201                 return false;
11202             }
11203             //
11204             query_nodes = new HashSet<PhylogenyNode>();
11205             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11206             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11207             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11208             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11209             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11210             if ( s0.match( query_nodes ) ) {
11211                 return false;
11212             }
11213             //
11214             query_nodes = new HashSet<PhylogenyNode>();
11215             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11216             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11217             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11218             if ( s0.match( query_nodes ) ) {
11219                 return false;
11220             }
11221             //
11222             query_nodes = new HashSet<PhylogenyNode>();
11223             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11224             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11225             if ( s0.match( query_nodes ) ) {
11226                 return false;
11227             }
11228             //
11229             query_nodes = new HashSet<PhylogenyNode>();
11230             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11232             if ( s0.match( query_nodes ) ) {
11233                 return false;
11234             }
11235             //
11236             query_nodes = new HashSet<PhylogenyNode>();
11237             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11238             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11239             if ( s0.match( query_nodes ) ) {
11240                 return false;
11241             }
11242             //
11243             query_nodes = new HashSet<PhylogenyNode>();
11244             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11245             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11246             if ( s0.match( query_nodes ) ) {
11247                 return false;
11248             }
11249             //
11250             query_nodes = new HashSet<PhylogenyNode>();
11251             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11252             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11253             if ( s0.match( query_nodes ) ) {
11254                 return false;
11255             }
11256             //
11257             query_nodes = new HashSet<PhylogenyNode>();
11258             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11259             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11260             if ( s0.match( query_nodes ) ) {
11261                 return false;
11262             }
11263             //
11264             query_nodes = new HashSet<PhylogenyNode>();
11265             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11266             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11267             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11268             if ( s0.match( query_nodes ) ) {
11269                 return false;
11270             }
11271             //
11272             query_nodes = new HashSet<PhylogenyNode>();
11273             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11274             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11275             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11276             if ( s0.match( query_nodes ) ) {
11277                 return false;
11278             }
11279             //
11280             query_nodes = new HashSet<PhylogenyNode>();
11281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11282             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11283             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11284             if ( s0.match( query_nodes ) ) {
11285                 return false;
11286             }
11287             //
11288             query_nodes = new HashSet<PhylogenyNode>();
11289             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11292             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11293             if ( s0.match( query_nodes ) ) {
11294                 return false;
11295             }
11296         }
11297         catch ( final Exception e ) {
11298             e.printStackTrace();
11299             return false;
11300         }
11301         return true;
11302     }
11303
11304     private static boolean testSubtreeDeletion() {
11305         try {
11306             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11307             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11308             t1.deleteSubtree( t1.getNode( "A" ), false );
11309             if ( t1.getNumberOfExternalNodes() != 5 ) {
11310                 return false;
11311             }
11312             t1.toNewHampshireX();
11313             t1.deleteSubtree( t1.getNode( "E" ), false );
11314             if ( t1.getNumberOfExternalNodes() != 4 ) {
11315                 return false;
11316             }
11317             t1.toNewHampshireX();
11318             t1.deleteSubtree( t1.getNode( "F" ), false );
11319             if ( t1.getNumberOfExternalNodes() != 3 ) {
11320                 return false;
11321             }
11322             t1.toNewHampshireX();
11323             t1.deleteSubtree( t1.getNode( "D" ), false );
11324             t1.toNewHampshireX();
11325             if ( t1.getNumberOfExternalNodes() != 3 ) {
11326                 return false;
11327             }
11328             t1.deleteSubtree( t1.getNode( "def" ), false );
11329             t1.toNewHampshireX();
11330             if ( t1.getNumberOfExternalNodes() != 2 ) {
11331                 return false;
11332             }
11333             t1.deleteSubtree( t1.getNode( "B" ), false );
11334             t1.toNewHampshireX();
11335             if ( t1.getNumberOfExternalNodes() != 1 ) {
11336                 return false;
11337             }
11338             t1.deleteSubtree( t1.getNode( "C" ), false );
11339             t1.toNewHampshireX();
11340             if ( t1.getNumberOfExternalNodes() != 1 ) {
11341                 return false;
11342             }
11343             t1.deleteSubtree( t1.getNode( "abc" ), false );
11344             t1.toNewHampshireX();
11345             if ( t1.getNumberOfExternalNodes() != 1 ) {
11346                 return false;
11347             }
11348             t1.deleteSubtree( t1.getNode( "r" ), false );
11349             if ( t1.getNumberOfExternalNodes() != 0 ) {
11350                 return false;
11351             }
11352             if ( !t1.isEmpty() ) {
11353                 return false;
11354             }
11355             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11356             t2.deleteSubtree( t2.getNode( "A" ), false );
11357             t2.toNewHampshireX();
11358             if ( t2.getNumberOfExternalNodes() != 5 ) {
11359                 return false;
11360             }
11361             t2.deleteSubtree( t2.getNode( "abc" ), false );
11362             t2.toNewHampshireX();
11363             if ( t2.getNumberOfExternalNodes() != 3 ) {
11364                 return false;
11365             }
11366             t2.deleteSubtree( t2.getNode( "def" ), false );
11367             t2.toNewHampshireX();
11368             if ( t2.getNumberOfExternalNodes() != 1 ) {
11369                 return false;
11370             }
11371         }
11372         catch ( final Exception e ) {
11373             e.printStackTrace( System.out );
11374             return false;
11375         }
11376         return true;
11377     }
11378
11379     private static boolean testSupportCount() {
11380         try {
11381             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11382             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
11383             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
11384                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
11385                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
11386                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
11387                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
11388                                                               new NHXParser() );
11389             SupportCount.count( t0_1, phylogenies_1, true, false );
11390             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
11391             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
11392                                                                       + "(((((A,B),C),D),E),((F,G),X))"
11393                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
11394                                                                       + "(((((A,B),C),D),E),(F,G))"
11395                                                                       + "(((((A,B),C),D),E),(F,G))"
11396                                                                       + "(((((A,B),C),D),E),(F,G))"
11397                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
11398                                                                       + "(((((A,B),C),D),E),(F,G))"
11399                                                                       + "((((((A,B),C),D),E),F),G)"
11400                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
11401                                                               new NHXParser() );
11402             SupportCount.count( t0_2, phylogenies_2, true, false );
11403             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
11404             while ( it.hasNext() ) {
11405                 final PhylogenyNode n = it.next();
11406                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
11407                     return false;
11408                 }
11409             }
11410             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
11411             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
11412                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
11413             SupportCount.count( t0_3, phylogenies_3, true, false );
11414             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
11415             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
11416                 return false;
11417             }
11418             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
11419                 return false;
11420             }
11421             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
11422                 return false;
11423             }
11424             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
11425                 return false;
11426             }
11427             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
11428                 return false;
11429             }
11430             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
11431                 return false;
11432             }
11433             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
11434                 return false;
11435             }
11436             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
11437                 return false;
11438             }
11439             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
11440                 return false;
11441             }
11442             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
11443                 return false;
11444             }
11445             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11446             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
11447                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
11448             SupportCount.count( t0_4, phylogenies_4, true, false );
11449             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
11450             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
11451                 return false;
11452             }
11453             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
11454                 return false;
11455             }
11456             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
11457                 return false;
11458             }
11459             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
11460                 return false;
11461             }
11462             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
11463                 return false;
11464             }
11465             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
11466                 return false;
11467             }
11468             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
11469                 return false;
11470             }
11471             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
11472                 return false;
11473             }
11474             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
11475                 return false;
11476             }
11477             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
11478                 return false;
11479             }
11480             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11481             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11482             double d = SupportCount.compare( b1, a, true, true, true );
11483             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
11484                 return false;
11485             }
11486             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11487             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11488             d = SupportCount.compare( b2, a, true, true, true );
11489             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
11490                 return false;
11491             }
11492             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11493             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
11494             d = SupportCount.compare( b3, a, true, true, true );
11495             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
11496                 return false;
11497             }
11498             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
11499             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
11500             d = SupportCount.compare( b4, a, true, true, false );
11501             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
11502                 return false;
11503             }
11504         }
11505         catch ( final Exception e ) {
11506             e.printStackTrace( System.out );
11507             return false;
11508         }
11509         return true;
11510     }
11511
11512     private static boolean testSupportTransfer() {
11513         try {
11514             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11515             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)",
11516                                                  new NHXParser() )[ 0 ];
11517             final Phylogeny p2 = factory
11518                     .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 ];
11519             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
11520                 return false;
11521             }
11522             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
11523                 return false;
11524             }
11525             support_transfer.moveBranchLengthsToBootstrap( p1 );
11526             support_transfer.transferSupportValues( p1, p2 );
11527             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
11528                 return false;
11529             }
11530             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
11531                 return false;
11532             }
11533             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
11534                 return false;
11535             }
11536             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
11537                 return false;
11538             }
11539             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
11540                 return false;
11541             }
11542             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
11543                 return false;
11544             }
11545             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
11546                 return false;
11547             }
11548             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
11549                 return false;
11550             }
11551         }
11552         catch ( final Exception e ) {
11553             e.printStackTrace( System.out );
11554             return false;
11555         }
11556         return true;
11557     }
11558
11559     private static boolean testTaxonomyExtraction() {
11560         try {
11561             final PhylogenyNode n0 = PhylogenyNode
11562                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11563             if ( n0.getNodeData().isHasTaxonomy() ) {
11564                 return false;
11565             }
11566             final PhylogenyNode n1 = PhylogenyNode
11567                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11568             if ( n1.getNodeData().isHasTaxonomy() ) {
11569                 System.out.println( n1.toString() );
11570                 return false;
11571             }
11572             final PhylogenyNode n2x = PhylogenyNode
11573                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11574             if ( n2x.getNodeData().isHasTaxonomy() ) {
11575                 return false;
11576             }
11577             final PhylogenyNode n3 = PhylogenyNode
11578                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11579             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11580                 System.out.println( n3.toString() );
11581                 return false;
11582             }
11583             final PhylogenyNode n4 = PhylogenyNode
11584                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11585             if ( n4.getNodeData().isHasTaxonomy() ) {
11586                 System.out.println( n4.toString() );
11587                 return false;
11588             }
11589             final PhylogenyNode n5 = PhylogenyNode
11590                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11591             if ( n5.getNodeData().isHasTaxonomy() ) {
11592                 System.out.println( n5.toString() );
11593                 return false;
11594             }
11595             final PhylogenyNode n6 = PhylogenyNode
11596                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11597             if ( n6.getNodeData().isHasTaxonomy() ) {
11598                 System.out.println( n6.toString() );
11599                 return false;
11600             }
11601             final PhylogenyNode n7 = PhylogenyNode
11602                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11603             if ( n7.getNodeData().isHasTaxonomy() ) {
11604                 System.out.println( n7.toString() );
11605                 return false;
11606             }
11607             final PhylogenyNode n8 = PhylogenyNode
11608                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11609             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11610                 System.out.println( n8.toString() );
11611                 return false;
11612             }
11613             final PhylogenyNode n9 = PhylogenyNode
11614                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11615             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11616                 System.out.println( n9.toString() );
11617                 return false;
11618             }
11619             final PhylogenyNode n10x = PhylogenyNode
11620                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11621             if ( n10x.getNodeData().isHasTaxonomy() ) {
11622                 System.out.println( n10x.toString() );
11623                 return false;
11624             }
11625             final PhylogenyNode n10xx = PhylogenyNode
11626                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11627             if ( n10xx.getNodeData().isHasTaxonomy() ) {
11628                 System.out.println( n10xx.toString() );
11629                 return false;
11630             }
11631             final PhylogenyNode n10 = PhylogenyNode
11632                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11633             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
11634                 System.out.println( n10.toString() );
11635                 return false;
11636             }
11637             final PhylogenyNode n11 = PhylogenyNode
11638                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11639             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11640                 System.out.println( n11.toString() );
11641                 return false;
11642             }
11643             final PhylogenyNode n12 = PhylogenyNode
11644                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
11645                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11646             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11647                 System.out.println( n12.toString() );
11648                 return false;
11649             }
11650             final PhylogenyNode n13 = PhylogenyNode
11651                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11652             if ( n13.getNodeData().isHasTaxonomy() ) {
11653                 System.out.println( n13.toString() );
11654                 return false;
11655             }
11656         }
11657         catch ( final Exception e ) {
11658             e.printStackTrace( System.out );
11659             return false;
11660         }
11661         return true;
11662     }
11663
11664     private static boolean testTreeCopy() {
11665         try {
11666             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
11667             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
11668             final Phylogeny t1 = t0.copy();
11669             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
11670                 return false;
11671             }
11672             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11673                 return false;
11674             }
11675             t0.deleteSubtree( t0.getNode( "c" ), true );
11676             t0.deleteSubtree( t0.getNode( "a" ), true );
11677             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
11678             t0.getNode( "b" ).setName( "Bee" );
11679             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
11680                 return false;
11681             }
11682             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11683                 return false;
11684             }
11685             t0.deleteSubtree( t0.getNode( "e" ), true );
11686             t0.deleteSubtree( t0.getNode( "Bee" ), true );
11687             t0.deleteSubtree( t0.getNode( "d" ), true );
11688             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
11689                 return false;
11690             }
11691         }
11692         catch ( final Exception e ) {
11693             e.printStackTrace();
11694             return false;
11695         }
11696         return true;
11697     }
11698
11699     private static boolean testTreeMethods() {
11700         try {
11701             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11702             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
11703             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
11704             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
11705                 System.out.println( t0.toNewHampshireX() );
11706                 return false;
11707             }
11708             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
11709             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
11710             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
11711                 return false;
11712             }
11713             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
11714                 return false;
11715             }
11716             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
11717                 return false;
11718             }
11719         }
11720         catch ( final Exception e ) {
11721             e.printStackTrace( System.out );
11722             return false;
11723         }
11724         return true;
11725     }
11726
11727     private static boolean testUniprotEntryRetrieval() {
11728         try {
11729             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
11730             if ( !entry.getAccession().equals( "P12345" ) ) {
11731                 return false;
11732             }
11733             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
11734                 return false;
11735             }
11736             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
11737                 return false;
11738             }
11739             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
11740                 return false;
11741             }
11742             if ( !entry.getGeneName().equals( "GOT2" ) ) {
11743                 return false;
11744             }
11745             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
11746                 return false;
11747             }
11748         }
11749         catch ( final IOException e ) {
11750             System.out.println();
11751             System.out.println( "the following might be due to absence internet connection:" );
11752             e.printStackTrace( System.out );
11753             return true;
11754         }
11755         catch ( final Exception e ) {
11756             return false;
11757         }
11758         return true;
11759     }
11760
11761     private static boolean testUniprotTaxonomySearch() {
11762         try {
11763             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
11764                                                                                                  10 );
11765             if ( results.size() != 1 ) {
11766                 return false;
11767             }
11768             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11769                 return false;
11770             }
11771             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11772                 return false;
11773             }
11774             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11775                 return false;
11776             }
11777             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11778                 return false;
11779             }
11780             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11781                 return false;
11782             }
11783             results = null;
11784             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
11785             if ( results.size() != 1 ) {
11786                 return false;
11787             }
11788             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11789                 return false;
11790             }
11791             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11792                 return false;
11793             }
11794             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11795                 return false;
11796             }
11797             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11798                 return false;
11799             }
11800             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11801                 return false;
11802             }
11803             results = null;
11804             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
11805             if ( results.size() != 1 ) {
11806                 return false;
11807             }
11808             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11809                 return false;
11810             }
11811             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11812                 return false;
11813             }
11814             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11815                 return false;
11816             }
11817             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11818                 return false;
11819             }
11820             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11821                 return false;
11822             }
11823             results = null;
11824             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
11825             if ( results.size() != 1 ) {
11826                 return false;
11827             }
11828             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11829                 return false;
11830             }
11831             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11832                 return false;
11833             }
11834             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11835                 return false;
11836             }
11837             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11838                 return false;
11839             }
11840             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11841                 return false;
11842             }
11843             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
11844                 return false;
11845             }
11846             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
11847                 return false;
11848             }
11849             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11850                     .equals( "Nematostella vectensis" ) ) {
11851                 System.out.println( results.get( 0 ).getLineage() );
11852                 return false;
11853             }
11854             //
11855             results = null;
11856             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
11857             if ( results.size() != 1 ) {
11858                 return false;
11859             }
11860             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11861                 return false;
11862             }
11863             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11864                 return false;
11865             }
11866             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11867                 return false;
11868             }
11869             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11870                 return false;
11871             }
11872             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11873                 return false;
11874             }
11875             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11876                     .equals( "Xenopus tropicalis" ) ) {
11877                 System.out.println( results.get( 0 ).getLineage() );
11878                 return false;
11879             }
11880             //
11881             results = null;
11882             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
11883             if ( results.size() != 1 ) {
11884                 return false;
11885             }
11886             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11887                 return false;
11888             }
11889             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11890                 return false;
11891             }
11892             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11893                 return false;
11894             }
11895             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11896                 return false;
11897             }
11898             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11899                 return false;
11900             }
11901             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11902                     .equals( "Xenopus tropicalis" ) ) {
11903                 System.out.println( results.get( 0 ).getLineage() );
11904                 return false;
11905             }
11906             //
11907             results = null;
11908             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
11909             if ( results.size() != 1 ) {
11910                 return false;
11911             }
11912             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11913                 return false;
11914             }
11915             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11916                 return false;
11917             }
11918             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11919                 return false;
11920             }
11921             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11922                 return false;
11923             }
11924             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11925                 return false;
11926             }
11927             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11928                     .equals( "Xenopus tropicalis" ) ) {
11929                 System.out.println( results.get( 0 ).getLineage() );
11930                 return false;
11931             }
11932         }
11933         catch ( final IOException e ) {
11934             System.out.println();
11935             System.out.println( "the following might be due to absence internet connection:" );
11936             e.printStackTrace( System.out );
11937             return true;
11938         }
11939         catch ( final Exception e ) {
11940             return false;
11941         }
11942         return true;
11943     }
11944
11945     private static boolean testWabiTxSearch() {
11946         try {
11947             String result = "";
11948             result = TxSearch.searchSimple( "nematostella" );
11949             result = TxSearch.getTxId( "nematostella" );
11950             if ( !result.equals( "45350" ) ) {
11951                 return false;
11952             }
11953             result = TxSearch.getTxName( "45350" );
11954             if ( !result.equals( "Nematostella" ) ) {
11955                 return false;
11956             }
11957             result = TxSearch.getTxId( "nematostella vectensis" );
11958             if ( !result.equals( "45351" ) ) {
11959                 return false;
11960             }
11961             result = TxSearch.getTxName( "45351" );
11962             if ( !result.equals( "Nematostella vectensis" ) ) {
11963                 return false;
11964             }
11965             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11966             if ( !result.equals( "536089" ) ) {
11967                 return false;
11968             }
11969             result = TxSearch.getTxName( "536089" );
11970             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11971                 return false;
11972             }
11973             final List<String> queries = new ArrayList<String>();
11974             queries.add( "Campylobacter coli" );
11975             queries.add( "Escherichia coli" );
11976             queries.add( "Arabidopsis" );
11977             queries.add( "Trichoplax" );
11978             queries.add( "Samanea saman" );
11979             queries.add( "Kluyveromyces marxianus" );
11980             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11981             queries.add( "Bornavirus parrot/PDD/2008" );
11982             final List<RANKS> ranks = new ArrayList<RANKS>();
11983             ranks.add( RANKS.SUPERKINGDOM );
11984             ranks.add( RANKS.KINGDOM );
11985             ranks.add( RANKS.FAMILY );
11986             ranks.add( RANKS.GENUS );
11987             ranks.add( RANKS.TRIBE );
11988             result = TxSearch.searchLineage( queries, ranks );
11989             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11990             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11991         }
11992         catch ( final Exception e ) {
11993             System.out.println();
11994             System.out.println( "the following might be due to absence internet connection:" );
11995             e.printStackTrace( System.out );
11996             return false;
11997         }
11998         return true;
11999     }
12000 }